From: Nicholas Nethercote Date: Fri, 10 Jun 2005 22:59:56 +0000 (+0000) Subject: Moved various pieces of linux/core_os.c to the modules that use them. X-Git-Tag: svn/VALGRIND_3_0_0~446 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a2a479c53700bcb963abd7652c69d521dc45b024;p=thirdparty%2Fvalgrind.git Moved various pieces of linux/core_os.c to the modules that use them. Managed to kill linux/core_os.h, hooray. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3872 --- diff --git a/coregrind/core.h b/coregrind/core.h index bd0b4cd431..eb4f6b4e51 100644 --- a/coregrind/core.h +++ b/coregrind/core.h @@ -35,8 +35,6 @@ #include "tool.h" // tool stuff #include "core_arch.h" // arch-specific stuff, eg. x86/core_arch.h -#include "core_os.h" // OS-specific stuff, eg. linux/core_os.h - #include // for jmp_buf #include "pub_core_mallocfree.h" // for type 'ArenaId' @@ -177,18 +175,9 @@ extern void Addr esp_at_startup, /*MOD*/ ThreadArchState* arch ); -// OS/Platform-specific thread clear (after thread exit) -extern void VGO_(os_state_clear)(ThreadState *); - -// OS/Platform-specific thread init (at scheduler init time) -extern void VGO_(os_state_init)(ThreadState *); - // Run a thread from beginning to end. extern VgSchedReturnCode VGO_(thread_wrapper)(Word /*ThreadId*/ tid); -// Call here to exit the entire Valgrind system. -extern void VGO_(terminate_NORETURN)(ThreadId tid, VgSchedReturnCode src); - // Allocates a stack for the first thread, then runs it, // as if the thread had been set up by clone() extern void VGP_(main_thread_wrapper_NORETURN)(ThreadId tid); diff --git a/coregrind/linux/Makefile.am b/coregrind/linux/Makefile.am index efc2331562..4e7ee0854c 100644 --- a/coregrind/linux/Makefile.am +++ b/coregrind/linux/Makefile.am @@ -1,9 +1,6 @@ include $(top_srcdir)/Makefile.all.am include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am -noinst_HEADERS = \ - core_os.h - noinst_LIBRARIES = libos.a libos_a_SOURCES = \ diff --git a/coregrind/linux/core_os.c b/coregrind/linux/core_os.c index 517f51e3b9..d32455e1da 100644 --- a/coregrind/linux/core_os.c +++ b/coregrind/linux/core_os.c @@ -38,20 +38,6 @@ #include "pub_core_signals.h" #include "pub_core_tooliface.h" -void VGO_(os_state_clear)(ThreadState *tst) -{ - tst->os_state.lwpid = 0; - tst->os_state.threadgroup = 0; -} - -void VGO_(os_state_init)(ThreadState *tst) -{ - tst->os_state.valgrind_stack_base = 0; - tst->os_state.valgrind_stack_szB = 0; - - VGO_(os_state_clear)(tst); -} - static Bool i_am_the_only_thread ( void ) { Int c = VG_(count_living_threads)(); @@ -59,37 +45,6 @@ static Bool i_am_the_only_thread ( void ) return c == 1; } - -void VGO_(terminate_NORETURN)(ThreadId tid, VgSchedReturnCode src) -{ - VG_(debugLog)(1, "core_os", - "VGO_(terminate_NORETURN)(tid=%lld)\n", (ULong)tid); - - vg_assert(VG_(count_living_threads)() == 0); - - //-------------------------------------------------------------- - // Exit, according to the scheduler's return code - //-------------------------------------------------------------- - switch (src) { - case VgSrc_ExitSyscall: /* the normal way out */ - VG_(exit)( VG_(threads)[tid].os_state.exitcode ); - /* NOT ALIVE HERE! */ - VG_(core_panic)("entered the afterlife in main() -- ExitSyscall"); - break; /* what the hell :) */ - - case VgSrc_FatalSig: - /* We were killed by a fatal signal, so replicate the effect */ - vg_assert(VG_(threads)[tid].os_state.fatalsig != 0); - VG_(kill_self)(VG_(threads)[tid].os_state.fatalsig); - VG_(core_panic)("main(): signal was supposed to be fatal"); - break; - - default: - VG_(core_panic)("main(): unexpected scheduler return code"); - } -} - - /* Run a thread from beginning to end and return the thread's scheduler-return-code. */ diff --git a/coregrind/linux/core_os.h b/coregrind/linux/core_os.h index f59fce93a5..ae275e93c3 100644 --- a/coregrind/linux/core_os.h +++ b/coregrind/linux/core_os.h @@ -32,23 +32,6 @@ #ifndef __LINUX_CORE_OS_H #define __LINUX_CORE_OS_H -/* OS-specific thread state */ -typedef struct { - /* who we are */ - Int lwpid; /* PID of kernel task */ - Int threadgroup; /* thread group id */ - - ThreadId parent; /* parent tid (if any) */ - - /* runtime details */ - Addr valgrind_stack_base; /* Valgrind's stack base */ - SizeT valgrind_stack_szB; /* stack size in bytes */ - - /* exit details */ - Int exitcode; /* in the case of exitgroup, set by someone else */ - Int fatalsig; /* fatal signal */ -} os_thread_t; - #endif // __LINUX_CORE_OS_H /*--------------------------------------------------------------------*/ diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 5d58a979ce..42152359db 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -2877,11 +2877,32 @@ void VG_(shutdown_actions_NORETURN) ( ThreadId tid, if (0) LibVEX_ShowAllocStats(); - /* Ok, finally exit in the os-specific way. In short, if the - (last) thread exited by calling sys_exit, do likewise; if the - (last) thread stopped due to a fatal signal, terminate the - entire system with that same fatal signal. */ - VGO_(terminate_NORETURN)( tid, tids_schedretcode ); + /* Ok, finally exit in the os-specific way, according to the scheduler's + return code. In short, if the (last) thread exited by calling + sys_exit, do likewise; if the (last) thread stopped due to a fatal + signal, terminate the entire system with that same fatal signal. */ + VG_(debugLog)(1, "core_os", + "VGO_(terminate_NORETURN)(tid=%lld)\n", (ULong)tid); + + vg_assert(VG_(count_living_threads)() == 0); + + switch (tids_schedretcode) { + case VgSrc_ExitSyscall: /* the normal way out */ + VG_(exit)( VG_(threads)[tid].os_state.exitcode ); + /* NOT ALIVE HERE! */ + VG_(core_panic)("entered the afterlife in main() -- ExitSyscall"); + break; /* what the hell :) */ + + case VgSrc_FatalSig: + /* We were killed by a fatal signal, so replicate the effect */ + vg_assert(VG_(threads)[tid].os_state.fatalsig != 0); + VG_(kill_self)(VG_(threads)[tid].os_state.fatalsig); + VG_(core_panic)("main(): signal was supposed to be fatal"); + break; + + default: + VG_(core_panic)("main(): unexpected scheduler return code"); + } } /*--------------------------------------------------------------------*/ diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index 43a4af226d..722acfccd9 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -553,6 +553,20 @@ UInt run_thread_for_a_while ( ThreadId tid ) } +static void os_state_clear(ThreadState *tst) +{ + tst->os_state.lwpid = 0; + tst->os_state.threadgroup = 0; +} + +static void os_state_init(ThreadState *tst) +{ + tst->os_state.valgrind_stack_base = 0; + tst->os_state.valgrind_stack_szB = 0; + + os_state_clear(tst); +} + static void mostly_clear_thread_record ( ThreadId tid ) { @@ -569,7 +583,7 @@ void mostly_clear_thread_record ( ThreadId tid ) VG_(sigemptyset)(&VG_(threads)[tid].sig_mask); VG_(sigemptyset)(&VG_(threads)[tid].tmp_sig_mask); - VGO_(os_state_clear)(&VG_(threads)[tid]); + os_state_clear(&VG_(threads)[tid]); /* start with no altstack */ VG_(threads)[tid].altstack.ss_sp = (void *)0xdeadbeef; @@ -641,7 +655,7 @@ void VG_(scheduler_init) ( void ) VG_(threads)[i].sig_queue = NULL; - VGO_(os_state_init)(&VG_(threads)[i]); + os_state_init(&VG_(threads)[i]); mostly_clear_thread_record(i); VG_(threads)[i].status = VgTs_Empty; diff --git a/coregrind/pub_core_scheduler.h b/coregrind/pub_core_scheduler.h index ddc785ff25..33e9e6b292 100644 --- a/coregrind/pub_core_scheduler.h +++ b/coregrind/pub_core_scheduler.h @@ -95,6 +95,23 @@ typedef } ThreadArchState; +/* OS-specific thread state */ +typedef struct { + /* who we are */ + Int lwpid; // PID of kernel task + Int threadgroup; // thread group id + + ThreadId parent; // parent tid (if any) + + /* runtime details */ + Addr valgrind_stack_base; // Valgrind's stack base + SizeT valgrind_stack_szB; // stack size in bytes + + /* exit details */ + Int exitcode; // in the case of exitgroup, set by someone else + Int fatalsig; // fatal signal +} os_thread_t; + typedef struct { /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.