Browse Source

[LibOS] Rename shim_get_tls() to shim_get_tcb() for consistency

Isaku Yamahata 4 years ago
parent
commit
d51f84f547

+ 9 - 9
LibOS/shim/include/shim_internal.h

@@ -44,10 +44,10 @@
 /* important macros and static inline functions */
 static inline unsigned int get_cur_tid(void)
 {
-    return shim_get_tls()->tid;
+    return shim_get_tcb()->tid;
 }
 
-#define PAL_NATIVE_ERRNO        (shim_get_tls()->pal_errno)
+#define PAL_NATIVE_ERRNO        (shim_get_tcb()->pal_errno)
 
 #define INTERNAL_TID_BASE       ((IDTYPE) 1 << (sizeof(IDTYPE) * 8 - 1))
 
@@ -177,7 +177,7 @@ void syscall_wrapper_after_syscalldb(void);
 #define SHIM_ARG_TYPE long
 
 #ifdef PROFILE
-# define ENTER_TIME     shim_get_tls()->context.enter_time
+# define ENTER_TIME     shim_get_tcb()->context.enter_time
 # define BEGIN_SYSCALL_PROFILE()        \
     do { ENTER_TIME = GET_PROFILE_INTERVAL(); } while (0)
 # define END_SYSCALL_PROFILE(name)      \
@@ -195,7 +195,7 @@ void syscall_wrapper_after_syscalldb(void);
 void check_stack_hook (void);
 
 static inline int64_t get_cur_preempt (void) {
-    shim_tcb_t* tcb = shim_get_tls();
+    shim_tcb_t* tcb = shim_get_tcb();
     assert(tcb);
     return atomic_read(&tcb->context.preempt);
 }
@@ -474,7 +474,7 @@ static inline int64_t __disable_preempt (shim_tcb_t * tcb)
 
 static inline void disable_preempt (shim_tcb_t * tcb)
 {
-    if (!tcb && !(tcb = shim_get_tls()))
+    if (!tcb && !(tcb = shim_get_tcb()))
         return;
 
     __disable_preempt(tcb);
@@ -493,7 +493,7 @@ void __handle_signal (shim_tcb_t * tcb, int sig);
 
 static inline void enable_preempt (shim_tcb_t * tcb)
 {
-    if (!tcb && !(tcb = shim_get_tls()))
+    if (!tcb && !(tcb = shim_get_tcb()))
         return;
 
     int64_t preempt = atomic_read(&tcb->context.preempt);
@@ -542,7 +542,7 @@ static void lock(struct shim_lock* l)
     if (!lock_enabled || !l->lock)
         return;
 
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t * tcb = shim_get_tcb();
     disable_preempt(tcb);
 
 #if DEBUG_LOCK == 1
@@ -567,7 +567,7 @@ static inline void unlock(struct shim_lock* l)
     if (!lock_enabled || !l->lock)
         return;
 
-    shim_tcb_t* tcb = shim_get_tls();
+    shim_tcb_t* tcb = shim_get_tcb();
 
 #if DEBUG_LOCK == 1
     debug("unlock(%s=%p) %s:%d\n", name, l, file, line);
@@ -583,7 +583,7 @@ static inline bool locked(struct shim_lock* l)
     if (!lock_enabled || !l->lock)
         return false;
 
-    shim_tcb_t* tcb = shim_get_tls();
+    shim_tcb_t* tcb = shim_get_tcb();
     return tcb->tid == l->owner;
 }
 

+ 3 - 3
LibOS/shim/include/shim_thread.h

@@ -122,14 +122,14 @@ int init_thread (void);
 static inline struct shim_thread * shim_thread_self(void)
 {
     /* TODO: optimize to use single movq %gs:<offset> */
-    shim_tcb_t * shim_tcb = shim_get_tls();
+    shim_tcb_t * shim_tcb = shim_get_tcb();
     return shim_tcb->tp;
 }
 
 static inline struct shim_thread * save_shim_thread_self(struct shim_thread * __self)
 {
     /* TODO: optimize to use single movq %gs:<offset> */
-    shim_tcb_t * shim_tcb = shim_get_tls();
+    shim_tcb_t * shim_tcb = shim_get_tcb();
     shim_tcb->tp = __self;
     return __self;
 }
@@ -181,7 +181,7 @@ static inline
 __attribute__((always_inline))
 void set_cur_thread (struct shim_thread * thread)
 {
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t * tcb = shim_get_tcb();
     IDTYPE tid = 0;
 
     if (thread) {

+ 1 - 1
LibOS/shim/include/shim_tls.h

@@ -74,7 +74,7 @@ struct shim_tcb {
 
 void init_tcb (shim_tcb_t * tcb);
 
-static inline shim_tcb_t * shim_get_tls(void)
+static inline shim_tcb_t * shim_get_tcb(void)
 {
     PAL_TCB * tcb = pal_get_tcb();
     return (shim_tcb_t*)tcb->libos_tcb;

+ 6 - 6
LibOS/shim/src/bookkeep/shim_signal.c

@@ -152,7 +152,7 @@ void __store_context (shim_tcb_t * tcb, PAL_CONTEXT * pal_context,
 
 void deliver_signal (siginfo_t * info, PAL_CONTEXT * context)
 {
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t * tcb = shim_get_tcb();
     assert(tcb);
 
     // Signals should not be delivered before the user process starts
@@ -247,7 +247,7 @@ static void arithmetic_error_upcall (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * c
 
 static void memfault_upcall (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 {
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t * tcb = shim_get_tcb();
     assert(tcb);
 
     if (tcb->test_range.cont_addr && arg
@@ -362,7 +362,7 @@ bool test_user_memory (void * addr, size_t size, bool write)
 
     /* Non-SGX path: check if [addr, addr+size) is addressable by touching
      * a byte of each page; invalid access will be caught in memfault_upcall */
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t * tcb = shim_get_tcb();
     assert(tcb && tcb->tp);
     __disable_preempt(tcb);
 
@@ -433,7 +433,7 @@ bool test_user_string (const char * addr)
 
     /* Non-SGX path: check if [addr, addr+size) is addressable by touching
      * a byte of each page; invalid access will be caught in memfault_upcall. */
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t * tcb = shim_get_tcb();
     assert(tcb && tcb->tp);
     __disable_preempt(tcb);
 
@@ -565,7 +565,7 @@ static void resume_upcall (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 {
     __UNUSED(arg);
     __UNUSED(context);
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t * tcb = shim_get_tcb();
     if (!tcb || !tcb->tp)
         return;
 
@@ -718,7 +718,7 @@ void __handle_signal (shim_tcb_t * tcb, int sig)
 
 void handle_signal (void)
 {
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t * tcb = shim_get_tcb();
     assert(tcb);
 
     struct shim_thread * thread = (struct shim_thread *) tcb->tp;

+ 5 - 5
LibOS/shim/src/bookkeep/shim_thread.c

@@ -104,7 +104,7 @@ struct shim_thread * __get_cur_thread (void)
 
 shim_tcb_t * __get_cur_tcb (void)
 {
-    return shim_get_tls();
+    return shim_get_tcb();
 }
 
 IDTYPE get_pid (void)
@@ -766,8 +766,8 @@ BEGIN_RS_FUNC(running_thread)
         thread->pal_handle = handle;
     } else {
         if (thread->shim_tcb) {
-            memcpy(shim_get_tls(), thread->shim_tcb, sizeof(shim_tcb_t));
-            thread->shim_tcb = shim_get_tls();
+            memcpy(shim_get_tcb(), thread->shim_tcb, sizeof(shim_tcb_t));
+            thread->shim_tcb = shim_get_tcb();
         }
         debug_setbuf(thread->shim_tcb, false);
         unsigned long fs_base = thread->fs_base;
@@ -775,7 +775,7 @@ BEGIN_RS_FUNC(running_thread)
         if (fs_base) {
             shim_tcb_t * tcb = thread->shim_tcb;
             assert(tcb->context.regs && tcb->context.regs->rsp);
-            tcb->debug_buf = shim_get_tls()->debug_buf;
+            tcb->debug_buf = shim_get_tcb()->debug_buf;
             init_fs_base(fs_base, thread);
             /* Temporarily disable preemption until the thread resumes. */
             __disable_preempt(tcb);
@@ -791,7 +791,7 @@ BEGIN_RS_FUNC(running_thread)
              * shim_tcb = NULL
              * in_vm = false
              */
-            thread->shim_tcb = shim_get_tls();
+            thread->shim_tcb = shim_get_tcb();
             init_tcb(thread->shim_tcb);
             set_cur_thread(thread);
         }

+ 1 - 1
LibOS/shim/src/elf/shim_rtld.c

@@ -1608,7 +1608,7 @@ noreturn void execute_elf_object(struct shim_handle* exec, int* argcp, const cha
     ElfW(Addr) entry = interp_map ? interp_map->l_entry : exec_map->l_entry;
 
     /* Ready to start execution, re-enable preemption. */
-    shim_tcb_t* tcb = shim_get_tls();
+    shim_tcb_t* tcb = shim_get_tcb();
     __enable_preempt(tcb);
 
 #if defined(__x86_64__)

+ 1 - 1
LibOS/shim/src/ipc/shim_ipc_helper.c

@@ -793,7 +793,7 @@ static void shim_ipc_helper_prepare(void* arg) {
 
     unsigned long fs_base = 0;
     init_fs_base(fs_base, self);
-    debug_setbuf(shim_get_tls(), true);
+    debug_setbuf(shim_get_tcb(), true);
 
     lock(&ipc_helper_lock);
     bool notme = (self != ipc_helper_thread);

+ 1 - 1
LibOS/shim/src/shim_async.c

@@ -146,7 +146,7 @@ static void shim_async_helper(void * arg) {
 
     unsigned long fs_base = 0;
     init_fs_base(fs_base, self);
-    debug_setbuf(shim_get_tls(), true);
+    debug_setbuf(shim_get_tcb(), true);
 
     lock(&async_helper_lock);
     bool notme = (self != async_helper_thread);

+ 1 - 1
LibOS/shim/src/shim_checkpoint.c

@@ -1301,7 +1301,7 @@ void restore_context (struct shim_context * context)
     *(unsigned long*) (regs.rsp - RED_ZONE_SIZE - 8) = regs.rip;
 
     /* Ready to resume execution, re-enable preemption. */
-    shim_tcb_t * tcb = shim_get_tls();
+    shim_tcb_t * tcb = shim_get_tcb();
     __enable_preempt(tcb);
 
     memset(context, 0, sizeof(struct shim_context));

+ 8 - 8
LibOS/shim/src/shim_init.c

@@ -59,9 +59,9 @@ static void handle_failure (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
     __UNUSED(context);
     if ((arg <= PAL_ERROR_NATIVE_COUNT) || (arg >= PAL_ERROR_CRYPTO_START &&
         arg <= PAL_ERROR_CRYPTO_END))
-        shim_get_tls()->pal_errno = arg;
+        shim_get_tcb()->pal_errno = arg;
     else
-        shim_get_tls()->pal_errno = PAL_ERROR_DENIED;
+        shim_get_tcb()->pal_errno = PAL_ERROR_DENIED;
 }
 
 noreturn void __abort(void) {
@@ -208,7 +208,7 @@ void init_tcb (shim_tcb_t * tcb)
 /* This function is used to allocate tls before interpreter start running */
 void init_fs_base (unsigned long fs_base, struct shim_thread * thread)
 {
-    shim_tcb_t * shim_tcb = shim_get_tls();
+    shim_tcb_t * shim_tcb = shim_get_tcb();
     init_tcb(shim_tcb);
 
     if (thread) {
@@ -227,7 +227,7 @@ void init_fs_base (unsigned long fs_base, struct shim_thread * thread)
 
 void update_fs_base (unsigned long fs_base)
 {
-    shim_tcb_t * shim_tcb = shim_get_tls();
+    shim_tcb_t * shim_tcb = shim_get_tcb();
 
     struct shim_thread * thread = shim_tcb->tp;
     if (thread) {
@@ -677,9 +677,9 @@ noreturn void* shim_init (int argc, void * args)
     /* create the initial TCB, shim can not be run without a tcb */
     unsigned long fs_base = 0;
     init_fs_base(fs_base, NULL);
-    __disable_preempt(shim_get_tls()); // Temporarily disable preemption for delaying any signal
+    __disable_preempt(shim_get_tcb()); // Temporarily disable preemption for delaying any signal
                                        // that arrives during initialization
-    debug_setbuf(shim_get_tls(), true);
+    debug_setbuf(shim_get_tcb(), true);
 
 #ifdef PROFILE
     unsigned long begin_time = GET_PROFILE_INTERVAL();
@@ -809,7 +809,7 @@ noreturn void* shim_init (int argc, void * args)
     if (thread_start_event)
         DkEventSet(thread_start_event);
 
-    shim_tcb_t * cur_tcb = shim_get_tls();
+    shim_tcb_t * cur_tcb = shim_get_tcb();
     struct shim_thread * cur_thread = (struct shim_thread *) cur_tcb->tp;
 
     if (cur_tcb->context.regs && cur_tcb->context.regs->rsp) {
@@ -1156,7 +1156,7 @@ int shim_clean (int err)
 
 #ifdef PROFILE
     if (ENTER_TIME) {
-        switch (shim_get_tls()->context.orig_rax) {
+        switch (shim_get_tcb()->context.orig_rax) {
             case __NR_exit_group:
                 SAVE_PROFILE_INTERVAL_SINCE(syscall_exit_group, ENTER_TIME);
                 break;

+ 1 - 1
LibOS/shim/src/sys/shim_exec.c

@@ -214,7 +214,7 @@ static int shim_do_execve_rtld (struct shim_handle * hdl, const char ** argv,
     if ((ret = init_stack(argv, envp, &new_argcp, &new_argp, &new_auxp)) < 0)
         return ret;
 
-    __disable_preempt(shim_get_tls()); // Temporarily disable preemption
+    __disable_preempt(shim_get_tcb()); // Temporarily disable preemption
                                        // during execve().
     SAVE_PROFILE_INTERVAL(alloc_new_stack_for_exec);
 

+ 1 - 1
LibOS/shim/src/sys/shim_migrate.c

@@ -261,7 +261,7 @@ int shim_do_checkpoint(const char* filename) {
     if (ret < 0)
         return ret;
 
-    shim_tcb_t* tcb = shim_get_tls();
+    shim_tcb_t* tcb = shim_get_tcb();
     assert(tcb && tcb->tp);
     struct shim_signal signal;
     __store_context(tcb, NULL, &signal);

+ 1 - 1
LibOS/shim/src/sys/shim_sigaction.c

@@ -163,7 +163,7 @@ int shim_do_sigaltstack (const stack_t * ss, stack_t * oss)
     if (oss)
         *oss = *cur_ss;
 
-    void * sp = (void *)shim_get_tls()->context.regs->rsp;
+    void * sp = (void *)shim_get_tcb()->context.regs->rsp;
     /* check if thread is currently executing on an active altstack */
     if (!(cur_ss->ss_flags & SS_DISABLE) &&
         sp &&

+ 3 - 3
LibOS/shim/src/utils/printf.c

@@ -64,7 +64,7 @@ static int debug_fputch(void* f, int ch, void* b) {
 
 void debug_puts(const char* str) {
     int len               = strlen(str);
-    struct debug_buf* buf = shim_get_tls()->debug_buf;
+    struct debug_buf* buf = shim_get_tcb()->debug_buf;
 
     while (len) {
         int rem     = DEBUGBUF_SIZE - 4 - buf->end;
@@ -95,11 +95,11 @@ void debug_puts(const char* str) {
 }
 
 void debug_putch(int ch) {
-    debug_fputch(NULL, ch, shim_get_tls()->debug_buf);
+    debug_fputch(NULL, ch, shim_get_tcb()->debug_buf);
 }
 
 void debug_vprintf(const char* fmt, va_list ap) {
-    vfprintfmt((void*)debug_fputch, NULL, shim_get_tls()->debug_buf, fmt, ap);
+    vfprintfmt((void*)debug_fputch, NULL, shim_get_tcb()->debug_buf, fmt, ap);
 }
 
 void debug_printf(const char* fmt, ...) {