PERFORCE change 152760 for review

Peter Wemm peter at FreeBSD.org
Mon Nov 10 12:16:47 PST 2008


http://perforce.freebsd.org/chv.cgi?CH=152760

Change 152760 by peter at peter_hammer on 2008/11/10 20:16:02

	Implement 32bit thr_new() for libthr

Affected files ...

.. //depot/projects/valgrind/coregrind/m_syswrap/syswrap-x86-freebsd.c#12 edit

Differences ...

==== //depot/projects/valgrind/coregrind/m_syswrap/syswrap-x86-freebsd.c#12 (text+ko) ====

@@ -347,29 +347,26 @@
 
    if (debug)
       VG_(printf)("clone child has SETTLS: tls at %#lx\n", (Addr)tp.tls_base);
-#if 0	/* XXX implement. use set_thread_area stuff */
-   ctst->arch.vex.guest_FS_ZERO = (UWord)tp.tls_base;
-#endif
+   sys_set_thread_area( ctid, 2, tp.tls_base );
+   ctst->arch.vex.guest_GS = (2 << 3) | 3;	/* GSEL(GUGS_SEL, SEL_UPL) */
    tp.tls_base = 0;	/* Don't have the kernel do it too */
 
    /* start the thread with everything blocked */
    VG_(sigprocmask)(VKI_SIG_SETMASK, &blockall, &savedmask);
 
-#if 0	/* XXX implement. either use stack args or change to regparm */
    /* Set the client state for scheduler to run libthr's trampoline */
-   ctst->arch.vex.guest_RDI = (Addr)tp.arg;
-   ctst->arch.vex.guest_RSP = (Addr)tp.stack_base + tp.stack_size - 8;
-   ctst->arch.vex.guest_RIP = (Addr)tp.start_func;
-#endif
+   ctst->arch.vex.guest_ESP = (Addr)tp.stack_base + tp.stack_size - 4;
+   ctst->arch.vex.guest_EIP = (Addr)tp.start_func;
 
-   /* But this is for thr_new() to run valgrind's trampoline */
-   tp.start_func = (void *)ML_(start_thread_NORETURN);
-   tp.arg = &VG_(threads)[ctid];
-
-   /* And valgrind's trampoline on its own stack */
+   /* Set up valgrind's trampoline on its own stack */
    stk = ML_(allocstack)(ctid);
    tp.stack_base = (void *)ctst->os_state.valgrind_stack_base;
    tp.stack_size = (Addr)stk - (Addr)tp.stack_base;
+   *(UWord *)(stk - 4) = tp.arg;	/* Client arg */
+   *(UWord *)(stk - 8) = 0xdeadc0de;	/* fake return addr */
+   /* This is for thr_new() to run valgrind's trampoline */
+   tp.start_func = (void *)ML_(start_thread_NORETURN);
+   tp.arg = &VG_(threads)[ctid];
 
    /* Create the new thread */
    res = VG_(do_syscall2)(__NR_thr_new, (UWord)&tp, sizeof(tp));


More information about the p4-projects mailing list