From 6a364d086643c1b4dbb650d5c069c1d1111425de Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 6 Feb 2022 20:30:44 +0000 Subject: [PATCH] Added a (disabled) implementation of dbg_log() --- photon/libc/sys/horizon/init.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/photon/libc/sys/horizon/init.c b/photon/libc/sys/horizon/init.c index 99bfeb2..5ab7631 100644 --- a/photon/libc/sys/horizon/init.c +++ b/photon/libc/sys/horizon/init.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -13,7 +14,22 @@ #include "__heap.h" #include "__fio.h" +#if 1 #define dbg_log(...) +#else +static void dbg_log(const char *format, ...) +{ + char buf[1024]; + + va_list arg; + va_start(arg, format); + + int r = vsnprintf(buf, sizeof buf, format, arg); + va_end(arg); + + mx_console_write(buf, r); +} +#endif static const char **environ = NULL; @@ -166,13 +182,22 @@ static void init_stdio(mx_bootstrap_handle_t *handles, size_t nhandles) } __fio_init(0, 1, 2); + dbg_log("** photon: stdio init finished\n"); } int __crt_init(mx_handle_t bootstrap) { + dbg_log("reading bootstrap message from %x\n", bootstrap); + mx_signals_t sig = 0; + mx_object_wait(bootstrap, MX_TUNNEL_READABLE, 0, &sig); + if (!(sig & MX_TUNNEL_READABLE)) { + dbg_log("no bootstrap message!\n"); + } + size_t msg_size = 0; size_t nr_handles = 0; mx_status_t status = mx_tunnel_read(bootstrap, NULL, 0, NULL, 0, &msg_size, &nr_handles); + dbg_log("read bootstrap message\n"); if (status != MX_OK) { /* TODO replace with a better error handler */ @@ -211,6 +236,7 @@ int __crt_init(mx_handle_t bootstrap) init_stdio(start_handles, nr_handles); + dbg_log("calling main\n"); int ret = main(msg->args_num, argv); __crt_run_atexit();