|
@@ -20,6 +20,7 @@
|
|
* This file contains codes to maintain bookkeeping of threads in library OS.
|
|
* This file contains codes to maintain bookkeeping of threads in library OS.
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+#include <shim_defs.h>
|
|
#include <shim_internal.h>
|
|
#include <shim_internal.h>
|
|
#include <shim_thread.h>
|
|
#include <shim_thread.h>
|
|
#include <shim_handle.h>
|
|
#include <shim_handle.h>
|
|
@@ -688,10 +689,10 @@ BEGIN_RS_FUNC(thread)
|
|
if (thread->cwd)
|
|
if (thread->cwd)
|
|
get_dentry(thread->cwd);
|
|
get_dentry(thread->cwd);
|
|
|
|
|
|
- DEBUG_RS("tid=%d,tgid=%d,parent=%d,stack=%p,frameptr=%p,tcb=%p",
|
|
|
|
|
|
+ DEBUG_RS("tid=%d,tgid=%d,parent=%d,stack=%p,frameptr=%p,tcb=%p,shim_tcb=%p",
|
|
thread->tid, thread->tgid,
|
|
thread->tid, thread->tgid,
|
|
thread->parent ? thread->parent->tid : thread->tid,
|
|
thread->parent ? thread->parent->tid : thread->tid,
|
|
- thread->stack, thread->frameptr, thread->tcb);
|
|
|
|
|
|
+ thread->stack, thread->frameptr, thread->tcb, thread->shim_tcb);
|
|
}
|
|
}
|
|
END_RS_FUNC(thread)
|
|
END_RS_FUNC(thread)
|
|
|
|
|
|
@@ -707,27 +708,27 @@ BEGIN_CP_FUNC(running_thread)
|
|
DO_CP(thread, thread, &new_thread);
|
|
DO_CP(thread, thread, &new_thread);
|
|
ADD_CP_FUNC_ENTRY((ptr_t) new_thread - base);
|
|
ADD_CP_FUNC_ENTRY((ptr_t) new_thread - base);
|
|
|
|
|
|
- if (!thread->user_tcb && thread->tcb) {
|
|
|
|
- ptr_t toff = ADD_CP_OFFSET(sizeof(__libc_tcb_t));
|
|
|
|
- new_thread->tcb = (void *) (base + toff);
|
|
|
|
- memcpy(new_thread->tcb, thread->tcb, sizeof(__libc_tcb_t));
|
|
|
|
|
|
+ if (thread->shim_tcb) {
|
|
|
|
+ ptr_t toff = ADD_CP_OFFSET(sizeof(shim_tcb_t));
|
|
|
|
+ new_thread->shim_tcb = (void *)(base + toff);
|
|
|
|
+ memcpy(new_thread->shim_tcb, thread->shim_tcb, sizeof(shim_tcb_t));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
END_CP_FUNC(running_thread)
|
|
END_CP_FUNC(running_thread)
|
|
|
|
|
|
-int resume_wrapper (void * param)
|
|
|
|
|
|
+static int resume_wrapper (void * param)
|
|
{
|
|
{
|
|
struct shim_thread * thread = (struct shim_thread *) param;
|
|
struct shim_thread * thread = (struct shim_thread *) param;
|
|
assert(thread);
|
|
assert(thread);
|
|
|
|
|
|
__libc_tcb_t * libc_tcb = thread->tcb;
|
|
__libc_tcb_t * libc_tcb = thread->tcb;
|
|
assert(libc_tcb);
|
|
assert(libc_tcb);
|
|
- shim_tcb_t * tcb = &libc_tcb->shim_tcb;
|
|
|
|
|
|
+ shim_tcb_t * tcb = thread->shim_tcb;
|
|
assert(tcb->context.regs && tcb->context.regs->rsp);
|
|
assert(tcb->context.regs && tcb->context.regs->rsp);
|
|
|
|
|
|
thread->in_vm = thread->is_alive = true;
|
|
thread->in_vm = thread->is_alive = true;
|
|
allocate_tls(libc_tcb, thread->user_tcb, thread);
|
|
allocate_tls(libc_tcb, thread->user_tcb, thread);
|
|
- debug_setbuf(tcb, true);
|
|
|
|
|
|
+ debug_setbuf(tcb, false);
|
|
debug("set tcb to %p\n", libc_tcb);
|
|
debug("set tcb to %p\n", libc_tcb);
|
|
|
|
|
|
object_wait_with_retry(thread_start_event);
|
|
object_wait_with_retry(thread_start_event);
|
|
@@ -747,6 +748,8 @@ BEGIN_RS_FUNC(running_thread)
|
|
|
|
|
|
if (!thread->user_tcb)
|
|
if (!thread->user_tcb)
|
|
CP_REBASE(thread->tcb);
|
|
CP_REBASE(thread->tcb);
|
|
|
|
+ if (thread->shim_tcb)
|
|
|
|
+ CP_REBASE(thread->shim_tcb);
|
|
|
|
|
|
if (thread->set_child_tid) {
|
|
if (thread->set_child_tid) {
|
|
/* CLONE_CHILD_SETTID */
|
|
/* CLONE_CHILD_SETTID */
|
|
@@ -764,10 +767,15 @@ BEGIN_RS_FUNC(running_thread)
|
|
|
|
|
|
thread->pal_handle = handle;
|
|
thread->pal_handle = handle;
|
|
} else {
|
|
} else {
|
|
|
|
+ if (thread->shim_tcb) {
|
|
|
|
+ memcpy(shim_get_tls(), thread->shim_tcb, sizeof(shim_tcb_t));
|
|
|
|
+ thread->shim_tcb = shim_get_tls();
|
|
|
|
+ }
|
|
|
|
+ debug_setbuf(thread->shim_tcb, false);
|
|
__libc_tcb_t * libc_tcb = thread->tcb;
|
|
__libc_tcb_t * libc_tcb = thread->tcb;
|
|
|
|
|
|
if (libc_tcb) {
|
|
if (libc_tcb) {
|
|
- shim_tcb_t * tcb = &libc_tcb->shim_tcb;
|
|
|
|
|
|
+ shim_tcb_t * tcb = thread->shim_tcb;
|
|
assert(tcb->context.regs && tcb->context.regs->rsp);
|
|
assert(tcb->context.regs && tcb->context.regs->rsp);
|
|
tcb->debug_buf = shim_get_tls()->debug_buf;
|
|
tcb->debug_buf = shim_get_tls()->debug_buf;
|
|
allocate_tls(libc_tcb, thread->user_tcb, thread);
|
|
allocate_tls(libc_tcb, thread->user_tcb, thread);
|
|
@@ -783,9 +791,11 @@ BEGIN_RS_FUNC(running_thread)
|
|
* frameptr = NULL
|
|
* frameptr = NULL
|
|
* tcb = NULL
|
|
* tcb = NULL
|
|
* user_tcb = false
|
|
* user_tcb = false
|
|
|
|
+ * shim_tcb = NULL
|
|
* in_vm = false
|
|
* in_vm = false
|
|
*/
|
|
*/
|
|
- init_tcb(&shim_libc_tcb()->shim_tcb);
|
|
|
|
|
|
+ thread->shim_tcb = shim_get_tls();
|
|
|
|
+ init_tcb(thread->shim_tcb);
|
|
set_cur_thread(thread);
|
|
set_cur_thread(thread);
|
|
}
|
|
}
|
|
|
|
|