From 0d099c275d2c306f001c366ff912c7d9c6f045ef Mon Sep 17 00:00:00 2001 From: Michalis Pappas Date: Mon, 13 Nov 2023 19:21:12 +0100 Subject: [PATCH] lib/posix-process: Add helpers for current process and thread Add uk_pprocess_current() uk_pthread_current() helpers. For now these are part of the private API. Checkpatch-Ignore: GLOBAL_INITIALISERS Signed-off-by: Michalis Pappas Reviewed-by: Ioan-Teodor Teugea Reviewed-by: Sergiu Moga Reviewed-by: Andrei Tatar Approved-by: Andrei Tatar GitHub-Closes: #1248 --- lib/posix-process/process.c | 2 +- lib/posix-process/process.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/posix-process/process.c b/lib/posix-process/process.c index 14ae6eda2..12a19c33c 100644 --- a/lib/posix-process/process.c +++ b/lib/posix-process/process.c @@ -70,7 +70,7 @@ struct posix_process *pid_process[TIDMAP_SIZE]; /** * Thread-local posix_thread reference */ -static __uk_tls struct posix_thread *pthread_self = NULL; +__uk_tls struct posix_thread *pthread_self = NULL; /** * Helpers to find and reserve a `pid_t` diff --git a/lib/posix-process/process.h b/lib/posix-process/process.h index 8816ec262..44c2c07f8 100644 --- a/lib/posix-process/process.h +++ b/lib/posix-process/process.h @@ -89,6 +89,8 @@ struct posix_thread { extern struct posix_process *pid_process[TIDMAP_SIZE]; +extern __uk_tls struct posix_thread *pthread_self; + #define uk_pprocess_foreach(_p) \ for (int _j = 1, _i = 0; _i != ARRAY_SIZE(pid_process); \ _j = !_j, _i++) \ @@ -99,6 +101,12 @@ extern struct posix_process *pid_process[TIDMAP_SIZE]; uk_list_for_each_entry_safe((_pthread), (_pthreadn), \ &(_proc)->threads, thread_list_entry) +#define uk_pthread_current() \ + uk_thread_uktls_var(uk_thread_current(), pthread_self) + +#define uk_pprocess_current() \ + uk_pthread_current()->process + #if CONFIG_LIBPOSIX_PROCESS_PIDS struct posix_process *pid2pprocess(pid_t pid); struct uk_thread *tid2ukthread(pid_t tid); -- 2.39.5