Skip to content

Commit

Permalink
i#1569 AArch64: Implement exchanging app's TLS.
Browse files Browse the repository at this point in the history
Use the inline function write_thread_register on both ARM and AARCH64.

Review-URL: https://codereview.appspot.com/300510043
  • Loading branch information
egrimley-arm committed Jul 1, 2016
1 parent 860f4e2 commit 067a239
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions core/unix/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ os_swap_context(dcontext_t *dcontext, bool to_app, dr_state_flags_t flags)
void
os_swap_context_go_native(dcontext_t *dcontext, dr_state_flags_t flags)
{
#ifdef ARM
#ifdef AARCHXX
/* FIXME i#1582: remove this routine once os_should_swap_state()
* is not disabled and we can actually call
* os_swap_context_go_native() safely from multiple places.
Expand Down Expand Up @@ -5963,7 +5963,7 @@ os_switch_seg_to_context(dcontext_t *dcontext, reg_id_t seg, bool to_app)
return false;
}
ASSERT(BOOLS_MATCH(to_app, os_using_app_state(dcontext)));
#elif defined(ARM)
#elif defined(AARCHXX)
os_thread_data_t *ostd = (os_thread_data_t *)dcontext->os_field;
ASSERT(INTERNAL_OPTION(private_loader));
if (to_app) {
Expand All @@ -5987,7 +5987,7 @@ os_switch_seg_to_context(dcontext_t *dcontext, reg_id_t seg, bool to_app)
*app_lib_tls_swap_slot = dr_tls_base;
LOG(THREAD, LOG_LOADER, 2, "%s: switching to %s, setting coproc reg to 0x%x\n",
__FUNCTION__, (to_app ? "app" : "dr"), os_tls->app_lib_tls_base);
res = dynamorio_syscall(SYS_set_tls, 1, os_tls->app_lib_tls_base) == 0;
res = write_thread_register(os_tls->app_lib_tls_base);
} else {
/* Restore the app's TLS slot that we used for storing DR's TLS base,
* and put DR's TLS base back to privlib's TLS slot.
Expand All @@ -6006,7 +6006,7 @@ os_switch_seg_to_context(dcontext_t *dcontext, reg_id_t seg, bool to_app)
LOG(THREAD, LOG_LOADER, 2, "%s: switching to %s, setting coproc reg to 0x%x\n",
__FUNCTION__, (to_app ? "app" : "dr"),
ostd->priv_lib_tls_base);
res = dynamorio_syscall(SYS_set_tls, 1, ostd->priv_lib_tls_base) == 0;
res = write_thread_register(ostd->priv_lib_tls_base);
}
LOG(THREAD, LOG_LOADER, 2,
"%s %s: set_tls swap success=%d for thread "TIDFMT"\n",
Expand Down
2 changes: 2 additions & 0 deletions core/unix/os_exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,10 @@ get_clone_record_dstack(void *record);
reg_t
get_clone_record_stolen_value(void *record);

# ifndef AARCH64
uint /* dr_isa_mode_t but we have a header ordering problem */
get_clone_record_isa_mode(void *record);
# endif

void
set_thread_register_from_clone_record(void *record);
Expand Down
9 changes: 2 additions & 7 deletions core/unix/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,8 @@ set_thread_register_from_clone_record(void *record)
* thread did not setup TLS for the child, and we need clear the
* thread register.
*/
if (((clone_record_t *)record)->app_lib_tls_base != NULL) {
#ifdef AARCH64
write_thread_register(0);
#else
dynamorio_syscall(SYS_set_tls, 1, NULL);
#endif
}
if (((clone_record_t *)record)->app_lib_tls_base != NULL)
write_thread_register(NULL);
}

void
Expand Down
12 changes: 10 additions & 2 deletions core/unix/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#define _OS_TLS_H_ 1

#include "os_private.h" /* ASM_XAX */
#if defined(ARM) && defined(LINUX)
# include "include/syscall.h" /* SYS_set_tls */
#endif

/* We support 3 different methods of creating a segment (see os_tls_init()) */
typedef enum {
Expand Down Expand Up @@ -161,11 +164,16 @@ read_thread_register(reg_id_t reg)
return sel;
}

#ifdef AARCH64
static inline void
#ifdef AARCHXX
static inline bool
write_thread_register(void *val)
{
# ifdef AARCH64
asm volatile("msr tpidr_el0, %0" : : "r"(val));
return true;
# else
return (dynamorio_syscall(SYS_set_tls, 1, val) == 0);
# endif
}
#endif

Expand Down
7 changes: 1 addition & 6 deletions core/unix/tls_linux_aarchxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,7 @@ tls_thread_init(os_local_state_t *os_tls, byte *segment)
LOG(GLOBAL, LOG_THREADS, 2,
"tls_thread_init: cur priv lib tls base is "PFX"\n",
os_tls->os_seg_info.priv_lib_tls_base);
#ifdef AARCH64
asm volatile("msr tpidr_el0, %0" : :
"r"(os_tls->os_seg_info.priv_lib_tls_base));
#else
dynamorio_syscall(SYS_set_tls, 1, os_tls->os_seg_info.priv_lib_tls_base);
#endif
write_thread_register(os_tls->os_seg_info.priv_lib_tls_base);
ASSERT(get_segment_base(TLS_REG_LIB) == os_tls->os_seg_info.priv_lib_tls_base);
ASSERT(*get_dr_tls_base_addr() == NULL);
*get_dr_tls_base_addr() = segment;
Expand Down

0 comments on commit 067a239

Please sign in to comment.