From owner-p4-projects@FreeBSD.ORG Wed Nov 5 09:45:20 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 14A49106567F; Wed, 5 Nov 2008 09:45:20 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B3C041065675 for ; Wed, 5 Nov 2008 09:45:19 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 6D4E28FC0C for ; Wed, 5 Nov 2008 09:45:19 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id mA59jJPK068361 for ; Wed, 5 Nov 2008 09:45:19 GMT (envelope-from peter-gmail@wemm.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id mA59jJJB068359 for perforce@freebsd.org; Wed, 5 Nov 2008 09:45:19 GMT (envelope-from peter-gmail@wemm.org) Date: Wed, 5 Nov 2008 09:45:19 GMT Message-Id: <200811050945.mA59jJJB068359@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter-gmail@wemm.org using -f From: Peter Wemm To: Perforce Change Reviews Cc: Subject: PERFORCE change 152515 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Nov 2008 09:45:20 -0000 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