]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-process: Create PID1 from the thread passed in init
authorMichalis Pappas <michalis@unikraft.io>
Wed, 26 Mar 2025 04:47:09 +0000 (05:47 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Thu, 17 Apr 2025 12:41:44 +0000 (12:41 +0000)
Update the instantiation of INIT_PID to use the thread passed in the
init context. This allows excluding unikraft's init thread from the
process when libukboot creates a separate thread for main().

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

lib/posix-process/process.c
lib/posix-process/process.h

index fec17e2c5b6aa0efb532b3e0bada2c62325c6d22..1f303a076b01fead891a3c04f08e04b13789721f 100644 (file)
@@ -41,6 +41,8 @@
 #include <uk/config.h>
 #include <uk/syscall.h>
 
+struct uk_thread *pprocess_thread_main;
+
 #if CONFIG_LIBPOSIX_PROCESS_PIDS
 #include <uk/bitmap.h>
 #include <uk/list.h>
@@ -484,11 +486,26 @@ void uk_posix_process_kill(struct uk_thread *thread)
 }
 
 #if CONFIG_LIBPOSIX_PROCESS_INIT_PIDS
-static int posix_process_init(struct uk_init_ctx *ictx __unused)
+static int posix_process_init(struct uk_init_ctx *ictx)
 {
+       struct uk_thread *t;
+
+       UK_ASSERT(ictx);
+
+       /* If ictx->tmain in set, main() executes on a
+        * separate uk_thread. Instantiate PID_INIT from
+        * that thread, and set pprocess_thread_main, as
+        * we will need that information later.
+        */
+       if (ictx->tmain) {
+               t = ictx->tmain;
+               pprocess_thread_main = ictx->tmain;
+       } else {
+               t = uk_thread_current();
+       }
+
        /* Create a POSIX process without parent ("init" process) */
-       return uk_posix_process_create(uk_alloc_get_default(),
-                                      uk_thread_current(), NULL);
+       return uk_posix_process_create(uk_alloc_get_default(), t, NULL);
 }
 
 uk_late_initcall(posix_process_init, 0x0);
index d214a8e3f3de4e1e22c770c6f8e70331c5745731..10ae276aa8e0f67302602e186d9af5a3e493d69e 100644 (file)
@@ -46,6 +46,8 @@
 
 #define TIDMAP_SIZE (CONFIG_LIBPOSIX_PROCESS_MAX_PID + 1)
 
+extern struct uk_thread *pprocess_thread_main;
+
 /* Notice: The RUNNING state is not necessarily in sync with the state
  * of the underlying uk_thread (may be blocked by the scheduler).
  * On the other hand, the BLOCKED state implies that the underlying