Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Nov 2008 09:45:19 GMT
From:      Peter Wemm <peter@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 152515 for review
Message-ID:  <200811050945.mA59jJJB068359@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=152515

Change 152515 by peter@peter_overcee on 2008/11/05 09:44:49

	Make libthr threads work.  Exiting/shutdown leaves a bit to be desired.
	Sometimes everything exits without doing the final error report.  I think
	this is what happens if the last thread calls thr_exit() after the main
	thread has already called exit().

Affected files ...

.. //depot/projects/valgrind/coregrind/m_syswrap/syswrap-amd64-freebsd.c#8 edit
.. //depot/projects/valgrind/coregrind/m_syswrap/syswrap-freebsd.c#25 edit

Differences ...

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

@@ -149,6 +149,7 @@
    SysRes       res;
    vki_sigset_t blockall, savedmask;
    struct vki_thr_param tp;
+   Addr stk;
 
    PRINT("thr_new ( %#lx, %ld )",ARG1,ARG2);
    PRE_REG_READ2(int, "thr_new",
@@ -218,9 +219,22 @@
    /* start the thread with everything blocked */
    VG_(sigprocmask)(VKI_SIG_SETMASK, &blockall, &savedmask);
 
+   /* 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;
 
+   /* 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 */
+   stk = ML_(allocstack)(ctid);
+   tp.stack_base = (void *)ctst->os_state.valgrind_stack_base;
+   tp.stack_size = (Addr)stk - (Addr)tp.stack_base;
+
    /* Create the new thread */
-   res = VG_(do_syscall2)(__NR_thr_new, ARG1, ARG2);
+   res = VG_(do_syscall2)(__NR_thr_new, (UWord)&tp, sizeof(tp));
 
    VG_(sigprocmask)(VKI_SIG_SETMASK, &savedmask, NULL);
 
@@ -237,8 +251,11 @@
 
       /* Thread creation was successful; let the child have the chance
          to run */
-      /* *flags |= SfYieldAfter; */
+      *flags |= SfYieldAfter;
    }
+
+   /* "Complete" the syscall so that the wrapper doesn't call the kernel again. */
+   SET_STATUS_from_SysRes(res);
 }
 
 PRE(sys_sigreturn)

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

@@ -1761,6 +1761,19 @@
    POST_MEM_WRITE( ARG1, sizeof(long));
 }
 
+PRE(sys_thr_exit)
+{
+   ThreadState *tst;
+
+   tst = VG_(get_ThreadState)(tid);
+   tst->exitreason = VgSrc_ExitThread;
+
+   VG_(exit_thread)(tid);
+   PRINT( "sys_thr_exit ( %#lx )", ARG1 );
+   PRE_REG_READ1(long, "thr_exit", long *, "status");
+// PRE_MEM_WRITE( "thr_exit()", ARG1, sizeof(long));
+}
+
 PRE(sys_thr_set_name)
 {
    PRINT( "sys_thr_set_name ( %ld, %#lx )", ARG1, ARG2 );
@@ -3450,7 +3463,7 @@
    BSDX_(__NR___acl_aclcheck_link,	sys___acl_aclcheck_link),	// 428
    //!sigwait								   429
    // thr_create							   430
-   // thr_exit								   431
+   BSDX_(__NR_thr_exit,			sys_thr_exit),			// 431
 
    BSDXY(__NR_thr_self, 		sys_thr_self),			// 432
    // thr_kill								   433



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811050945.mA59jJJB068359>