]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/ukboot: Save application exit status to tctx
authorMichalis Pappas <michalis@unikraft.io>
Sat, 29 Mar 2025 08:31:10 +0000 (09:31 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Wed, 30 Apr 2025 10:07:29 +0000 (10:07 +0000)
Update calls to do_main() to save the return value to unikraft's
term context. If UKBOOT_MAINTHREAD is selected, the status code
will be set via the main thread's exit path.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1633

lib/ukboot/boot.c

index b0c14d8511e5bdd175d28f0c70d0eb99debda158..c585fdd4e693a7c986b517dde93d8831abc7c02d 100644 (file)
@@ -114,7 +114,7 @@ int main(int argc, char *argv[]) __weak;
 static inline int do_main(int argc, char *argv[]);
 
 #if CONFIG_LIBUKBOOT_MAINTHREAD
-static __noreturn void main_thread(void *);
+static __noreturn void main_thread(void *, void *);
 static void main_thread_dtor(struct uk_thread *m);
 struct uk_semaphore main_sema;
 #endif /* CONFIG_LIBUKBOOT_MAINTHREAD */
@@ -369,8 +369,8 @@ void uk_boot_entry(void)
 
 #if CONFIG_LIBUKBOOT_MAINTHREAD
        /* Start main thread (will block on semaphore) */
-       m = uk_sched_thread_create_fn1(s, main_thread,
-                                      &ictx,
+       m = uk_sched_thread_create_fn2(s, main_thread,
+                                      &ictx, &tctx,
                                       0x0 /* default stack size */,
                                       0x0 /* default auxiliary stack size */,
                                       false, false,
@@ -414,14 +414,16 @@ void uk_boot_entry(void)
        fflush(stdout);
 
 #if !CONFIG_LIBUKBOOT_MAINTHREAD
-       do_main(ictx.cmdline.argc, ictx.cmdline.argv);
+       tctx.exit_code = do_main(ictx.cmdline.argc, ictx.cmdline.argv);
        tctx.target = UKPLAT_HALT;
 
 #else /* CONFIG_LIBUKBOOT_MAINTHREAD */
        /* Unblock main thread (will execute main()) */
        uk_semaphore_up(&main_sema);
 
-       /* Block execution of "init" until we receive the first request */
+       /* Block execution of "init" until we receive the first request.
+        * The exit code will be set by the main thread.
+        */
        tctx.target = uk_boot_shutdown_barrier();
 #endif /* CONFIG_LIBUKBOOT_MAINTHREAD */
 
@@ -446,6 +448,8 @@ exit:
                (*init_entry->term)(&tctx);
        }
 
+       uk_pr_debug("Unikraft terminates with exit status %d (target: %d)\n",
+                   tctx.exit_code, tctx.target);
        ukplat_terminate(tctx.target); /* does not return */
 }
 
@@ -514,15 +518,18 @@ static inline int do_main(int argc, char *argv[])
 
 #if CONFIG_LIBUKBOOT_MAINTHREAD
 /* Pass ictx so that inittab handlers can update args */
-static __noreturn void main_thread(void *ictx)
+static __noreturn void main_thread(void *a0, void *a1)
 {
+       struct uk_init_ctx *ictx = (struct uk_init_ctx *)a0;
+       struct uk_term_ctx *tctx = (struct uk_term_ctx *)a1;
+
        UK_ASSERT(ictx);
+       UK_ASSERT(tctx);
 
        /* block until we are allowed to execute main() */
        uk_semaphore_down(&main_sema);
 
-       do_main(((struct uk_init_ctx *)ictx)->cmdline.argc,
-               ((struct uk_init_ctx *)ictx)->cmdline.argv);
+       tctx->exit_code = do_main(ictx->cmdline.argc, ictx->cmdline.argv);
 
 #if !CONFIG_LIBUKBOOT_MAINTHREAD_NOHALT
        /* NOTE: The scheduler's garbage collector would also initiate a