Skip to content

Commit

Permalink
i#3526: Apply i#2089 scheme to client threads.
Browse files Browse the repository at this point in the history
When creating client threads, we still attempted to invalidate the thread's TLS by writing
a null selector to its segment register. In 64-bit mode, this seemed to work most of the
time because presumably Intel and AMD are then zero'ing out the upper 32-bit of the hidden
segment's base. Intel describes this in Vol. 3A 3.4.4, although not completely clear.

This patch applies the same scheme introduced and described in #2089.

Before this patch, the test code_api|client.thread ran into all kinds of assertions,
because the client thread interfered with the parent's TLS. These failures are now gone.

Fixes #3526
Issue: #2089
  • Loading branch information
Hendrik Greving committed Apr 10, 2019
1 parent 361f644 commit ab1bf60
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 0 additions & 2 deletions core/arch/x86/x86.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,6 @@ GLOBAL_LABEL(dynamorio_clone:)
# endif
cmp REG_XAX, 0
jne dynamorio_clone_parent
/* avoid conflicts w/ parent's TLS by clearing our reg now */
mov SEG_TLS, ax
pop REG_XCX
call REG_XCX
/* shouldn't return */
Expand Down
2 changes: 2 additions & 0 deletions core/unix/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -3719,9 +3719,11 @@ dr_create_client_thread(void (*func)(void *param), void *arg)
# endif
LOG(THREAD, LOG_ALL, 1, "dr_create_client_thread xsp=" PFX " dstack=" PFX "\n", xsp,
get_clone_record_dstack(crec));
os_clone_pre(dcontext);
thread_id_t newpid =
dynamorio_clone(flags, xsp, NULL, IF_X86_ELSE(IF_X64_ELSE(NULL, &desc), NULL),
NULL, client_thread_run);
os_clone_post(dcontext);
/* i#501 switch to app's tls before creating client thread */
if (IF_CLIENT_INTERFACE_ELSE(INTERNAL_OPTION(private_loader), false))
os_switch_lib_tls(dcontext, false /*to dr*/);
Expand Down

0 comments on commit ab1bf60

Please sign in to comment.