Skip to content

Commit

Permalink
i#975 static DR: rename create_thread to avoid name conflicts
Browse files Browse the repository at this point in the history
On Windows we have no solution to hide non-exported symbols in
dynamorio_static like we do on Linux.  In our own tests the only conflict
is create_thread.  We rename the core's to our_create_thread.  We have yet
to find a great solution to this general issue on Windows.

Review-URL: https://codereview.appspot.com/307150044
  • Loading branch information
derekbruening committed Aug 31, 2016
1 parent 4f22203 commit 4f70937
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
8 changes: 4 additions & 4 deletions core/nudge.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "nudge.h"

#ifdef WINDOWS
# include "ntdll.h" /* for create_thread(), nt_free_virtual_memory() */
# include "ntdll.h" /* for our_create_thread(), nt_free_virtual_memory() */
# include "os_exports.h" /* for detach_helper(), get_stack_bounds() */
# include "drmarker.h"
#else
Expand Down Expand Up @@ -514,9 +514,9 @@ nudge_internal(process_id_t pid, uint nudge_action_mask,
nudge_target = marker.dr_generic_nudge_target;
}

hthread = create_thread(hproc, IF_X64_ELSE(true, false), nudge_target,
NULL, &nudge_arg, sizeof(nudge_arg_t),
15*PAGE_SIZE, 12*PAGE_SIZE, false, NULL);
hthread = our_create_thread(hproc, IF_X64_ELSE(true, false), nudge_target,
NULL, &nudge_arg, sizeof(nudge_arg_t),
15*PAGE_SIZE, 12*PAGE_SIZE, false, NULL);
ASSERT(hthread != INVALID_HANDLE_VALUE);
if (hthread == INVALID_HANDLE_VALUE)
return DR_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion core/win32/callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -3116,7 +3116,7 @@ intercept_new_thread(CONTEXT *cxt)
if (is_client) {
ASSERT(is_on_dstack(dcontext, (byte *)cxt->CXT_XSP));
/* PR 210591: hide our threads from DllMain by not executing rest
* of Ldr init code and going straight to target. create_thread()
* of Ldr init code and going straight to target. our_create_thread()
* already set up the arg in cxt.
*/
nt_continue(cxt);
Expand Down
23 changes: 12 additions & 11 deletions core/win32/ntdll.c
Original file line number Diff line number Diff line change
Expand Up @@ -4428,11 +4428,11 @@ create_process(wchar_t *exe, wchar_t *cmdline)
NTPRINT("create_process: created section and process\n");

/* FIXME : if thread returns from its EntryPoint function will crash because
* create_thread skips the kernel32 ThreadStartThunk */
* our_create_thread skips the kernel32 ThreadStartThunk */
/* FIXME : need to know whether target process is 32bit or 64bit, for now
* assume 32bit. */
hthread = create_thread(hProcess, false, sii.EntryPoint, NULL, NULL, 0,
sii.StackReserve, sii.StackCommit, TRUE, &tid);
hthread = our_create_thread(hProcess, false, sii.EntryPoint, NULL, NULL, 0,
sii.StackReserve, sii.StackCommit, TRUE, &tid);

if (hthread == INVALID_HANDLE_VALUE) {
NTPRINT("create_process: failed to create thread\n");
Expand Down Expand Up @@ -4492,7 +4492,7 @@ create_process(wchar_t *exe, wchar_t *cmdline)
* arg.
*/
/* returns INVALID_HANDLE_VALUE on error */
HANDLE
static HANDLE
create_thread_common(HANDLE hProcess, bool target_64bit, void *start_addr,
void *arg, const void *arg_buf, size_t arg_buf_size,
USER_STACK *stack, bool suspended, thread_id_t *tid)
Expand Down Expand Up @@ -4592,9 +4592,10 @@ create_thread_common(HANDLE hProcess, bool target_64bit, void *start_addr,

/* Creates a new stack w/ guard page */
HANDLE
create_thread(HANDLE hProcess, bool target_64bit, void *start_addr,
void *arg, const void *arg_buf, size_t arg_buf_size,
uint stack_reserve, uint stack_commit, bool suspended, thread_id_t *tid)
our_create_thread(HANDLE hProcess, bool target_64bit, void *start_addr,
void *arg, const void *arg_buf, size_t arg_buf_size,
uint stack_reserve, uint stack_commit, bool suspended,
thread_id_t *tid)
{
USER_STACK stack = {0};
uint num_commit_bytes, old_prot;
Expand Down Expand Up @@ -4636,10 +4637,10 @@ create_thread(HANDLE hProcess, bool target_64bit, void *start_addr,

/* Uses caller-allocated stack */
HANDLE
create_thread_have_stack(HANDLE hProcess, bool target_64bit, void *start_addr,
void *arg, const void *arg_buf, size_t arg_buf_size,
byte *stack_base, size_t stack_size,
bool suspended, thread_id_t *tid)
our_create_thread_have_stack(HANDLE hProcess, bool target_64bit, void *start_addr,
void *arg, const void *arg_buf, size_t arg_buf_size,
byte *stack_base, size_t stack_size,
bool suspended, thread_id_t *tid)
{
USER_STACK stack = {0};
stack.ExpandableStackBase = stack_base;
Expand Down
17 changes: 9 additions & 8 deletions core/win32/ntdll.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2011-2015 Google, Inc. All rights reserved.
* Copyright (c) 2011-2016 Google, Inc. All rights reserved.
* Copyright (c) 2003-2010 VMware, Inc. All rights reserved.
* **********************************************************/

Expand Down Expand Up @@ -2102,14 +2102,15 @@ create_process(wchar_t *exe, wchar_t *cmdline);
/* NOTE see important usage information in ntdll.c, threads created with this
* function can NOT return from their start routine */
HANDLE
create_thread(HANDLE hProcess, bool target_64bit, void *start_addr,
void *arg, const void *arg_buf, size_t arg_buf_size,
uint stack_reserve, uint stack_commit, bool suspended, thread_id_t *tid);
our_create_thread(HANDLE hProcess, bool target_64bit, void *start_addr,
void *arg, const void *arg_buf, size_t arg_buf_size,
uint stack_reserve, uint stack_commit, bool suspended,
thread_id_t *tid);
HANDLE
create_thread_have_stack(HANDLE hProcess, bool target_64bit, void *start_addr,
void *arg, const void *arg_buf, size_t arg_buf_size,
byte *stack_base, size_t stack_size,
bool suspended, thread_id_t *tid);
our_create_thread_have_stack(HANDLE hProcess, bool target_64bit, void *start_addr,
void *arg, const void *arg_buf, size_t arg_buf_size,
byte *stack_base, size_t stack_size,
bool suspended, thread_id_t *tid);

/* NOTE : this isn't equivalent to nt_get_context(NT_CURRENT_THREAD, cxt)
* (where the returned context is undefined) so use this to get the context
Expand Down
8 changes: 4 additions & 4 deletions core/win32/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -2675,10 +2675,10 @@ dr_create_client_thread(void (*func)(void *param), void *arg)
arg_buf[1] = arg;

/* FIXME PR 225714: does this work on Vista? */
hthread = create_thread_have_stack(NT_CURRENT_PROCESS, IF_X64_ELSE(true, false),
(void *)client_thread_target,
NULL, arg_buf, BUFFER_SIZE_BYTES(arg_buf),
dstack, DYNAMORIO_STACK_SIZE, false, &tid);
hthread = our_create_thread_have_stack(NT_CURRENT_PROCESS, IF_X64_ELSE(true, false),
(void *)client_thread_target,
NULL, arg_buf, BUFFER_SIZE_BYTES(arg_buf),
dstack, DYNAMORIO_STACK_SIZE, false, &tid);
CLIENT_ASSERT(hthread != INVALID_HANDLE_VALUE, "error creating thread");
if (hthread == INVALID_HANDLE_VALUE) {
stack_free(dstack, DYNAMORIO_STACK_SIZE);
Expand Down

0 comments on commit 4f70937

Please sign in to comment.