|
From: <sv...@va...> - 2005-09-28 10:47:44
|
Author: sewardj
Date: 2005-09-28 11:47:38 +0100 (Wed, 28 Sep 2005)
New Revision: 4806
Log:
Get rid of pub_core_main.h, so that m_main is not imported by anyone,
and so is not part of a module cycle. This requires a moderately
grotty hack of passing a continuation-function pointer in a global
variable.
Removed:
trunk/coregrind/pub_core_main.h
Modified:
trunk/coregrind/Makefile.am
trunk/coregrind/m_main.c
trunk/coregrind/m_syswrap/syswrap-amd64-linux.c
trunk/coregrind/m_syswrap/syswrap-generic.c
trunk/coregrind/m_syswrap/syswrap-main.c
trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c
trunk/coregrind/m_syswrap/syswrap-x86-linux.c
trunk/coregrind/pub_core_syswrap.h
Modified: trunk/coregrind/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/Makefile.am 2005-09-28 09:37:16 UTC (rev 4805)
+++ trunk/coregrind/Makefile.am 2005-09-28 10:47:38 UTC (rev 4806)
@@ -48,7 +48,6 @@
pub_core_libcproc.h \
pub_core_libcsignal.h \
pub_core_machine.h \
- pub_core_main.h \
pub_core_mallocfree.h \
pub_core_options.h \
pub_core_oset.h \
Modified: trunk/coregrind/m_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_main.c 2005-09-28 09:37:16 UTC (rev 4805)
+++ trunk/coregrind/m_main.c 2005-09-28 10:47:38 UTC (rev 4806)
@@ -44,7 +44,6 @@
#include "pub_core_libcsignal.h"
#include "pub_core_syscall.h" // VG_(strerror)
#include "pub_core_machine.h"
-#include "pub_core_main.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
#include "pub_core_profile.h"
@@ -1823,8 +1822,18 @@
=20
static Addr sp_at_startup =3D 0;
=20
+/* --- Forwards decls to do with shutdown --- */
=20
+static void final_tidyup(ThreadId tid);=20
=20
+/* Do everything which needs doing when the last thread exits */
+static=20
+void shutdown_actions_NORETURN( ThreadId tid,=20
+ VgSchedReturnCode tids_schedretcode );
+
+/* --- end of Forwards decls to do with shutdown --- */
+
+
/* TODO: GIVE THIS A PROPER HOME
TODO: MERGE THIS WITH DUPLICATE IN mac_leakcheck.c
Extract from aspacem a vector of the current segment start
@@ -1860,8 +1869,6 @@
=20
=20
=20
-
-
Int main(Int argc, HChar **argv, HChar **envp)
{
HChar* toolname =3D "memcheck"; // default to Memcheck
@@ -2480,68 +2487,34 @@
}
=20
VG_(debugLog)(1, "main", "Running thread 1\n");
+
/* As a result of the following call, the last thread standing
- eventually winds up running VG_(shutdown_actions_NORETURN) just
- below. */
+ eventually winds up running shutdown_actions_NORETURN
+ just below. Unfortunately, simply exporting said function
+ causes m_main to be part of a module cycle, which is pretty
+ nonsensical. So instead of doing that, the address of said
+ function is stored in a global variable 'owned' by m_syswrap,
+ and it uses that function pointer to get back here when it needs
+ to. */
+
+ /* Set continuation address. */
+ VG_(address_of_m_main_shutdown_actions_NORETURN)
+ =3D & shutdown_actions_NORETURN;
+
+ /* Run the first thread, eventually ending up at the continuation
+ address. */
VG_(main_thread_wrapper_NORETURN)(1);
=20
/*NOTREACHED*/
vg_assert(0);
}
=20
+/* Do everything which needs doing when the last thread exits. */
=20
-/* Final clean-up before terminating the process. =20
- Clean up the client by calling __libc_freeres() (if requested)=20
- This is Linux-specific?
-*/
-static void final_tidyup(ThreadId tid)
+static=20
+void shutdown_actions_NORETURN( ThreadId tid,=20
+ VgSchedReturnCode tids_schedretcode )
{
- Addr __libc_freeres_wrapper;
-
- vg_assert(VG_(is_running_thread)(tid));
- =20
- if ( !VG_(needs).libc_freeres ||
- !VG_(clo_run_libc_freeres) ||
- 0 =3D=3D (__libc_freeres_wrapper =3D VG_(get_libc_freeres_wrappe=
r)()) )
- return; /* can't/won't do it */
-
- if (VG_(clo_verbosity) > 2 ||
- VG_(clo_trace_syscalls) ||
- VG_(clo_trace_sched))
- VG_(message)(Vg_DebugMsg,=20
- "Caught __NR_exit; running __libc_freeres()");
- =20
- /* point thread context to point to libc_freeres_wrapper */
- VG_(set_IP)(tid, __libc_freeres_wrapper);
- // XXX should we use a special stack?
-
- /* Block all blockable signals by copying the real block state into
- the thread's block state*/
- VG_(sigprocmask)(VKI_SIG_BLOCK, NULL, &VG_(threads)[tid].sig_mask);
- VG_(threads)[tid].tmp_sig_mask =3D VG_(threads)[tid].sig_mask;
-
- /* and restore handlers to default */
- VG_(set_default_handler)(VKI_SIGSEGV);
- VG_(set_default_handler)(VKI_SIGBUS);
- VG_(set_default_handler)(VKI_SIGILL);
- VG_(set_default_handler)(VKI_SIGFPE);
-
- // We were exiting, so assert that...
- vg_assert(VG_(is_exiting)(tid));
- // ...but now we're not again
- VG_(threads)[tid].exitreason =3D VgSrc_None;
-
- // run until client thread exits - ideally with LIBC_FREERES_DONE,
- // but exit/exitgroup/signal will do
- VG_(scheduler)(tid);
-
- vg_assert(VG_(is_exiting)(tid));
-}
-
-/* Do everything which needs doing when the last thread exits */
-void VG_(shutdown_actions_NORETURN) ( ThreadId tid,=20
- VgSchedReturnCode tids_schedretcod=
e )
-{
VG_(debugLog)(1, "main", "entering VG_(shutdown_actions_NORETURN)\n")=
;
=20
vg_assert( VG_(count_living_threads)() =3D=3D 1 );
@@ -2646,7 +2619,57 @@
}
}
=20
+/* -------------------- */
=20
+/* Final clean-up before terminating the process. =20
+ Clean up the client by calling __libc_freeres() (if requested)=20
+ This is Linux-specific?
+*/
+static void final_tidyup(ThreadId tid)
+{
+ Addr __libc_freeres_wrapper;
+
+ vg_assert(VG_(is_running_thread)(tid));
+ =20
+ if ( !VG_(needs).libc_freeres ||
+ !VG_(clo_run_libc_freeres) ||
+ 0 =3D=3D (__libc_freeres_wrapper =3D VG_(get_libc_freeres_wrappe=
r)()) )
+ return; /* can't/won't do it */
+
+ if (VG_(clo_verbosity) > 2 ||
+ VG_(clo_trace_syscalls) ||
+ VG_(clo_trace_sched))
+ VG_(message)(Vg_DebugMsg,=20
+ "Caught __NR_exit; running __libc_freeres()");
+ =20
+ /* point thread context to point to libc_freeres_wrapper */
+ VG_(set_IP)(tid, __libc_freeres_wrapper);
+ // XXX should we use a special stack?
+
+ /* Block all blockable signals by copying the real block state into
+ the thread's block state*/
+ VG_(sigprocmask)(VKI_SIG_BLOCK, NULL, &VG_(threads)[tid].sig_mask);
+ VG_(threads)[tid].tmp_sig_mask =3D VG_(threads)[tid].sig_mask;
+
+ /* and restore handlers to default */
+ VG_(set_default_handler)(VKI_SIGSEGV);
+ VG_(set_default_handler)(VKI_SIGBUS);
+ VG_(set_default_handler)(VKI_SIGILL);
+ VG_(set_default_handler)(VKI_SIGFPE);
+
+ // We were exiting, so assert that...
+ vg_assert(VG_(is_exiting)(tid));
+ // ...but now we're not again
+ VG_(threads)[tid].exitreason =3D VgSrc_None;
+
+ // run until client thread exits - ideally with LIBC_FREERES_DONE,
+ // but exit/exitgroup/signal will do
+ VG_(scheduler)(tid);
+
+ vg_assert(VG_(is_exiting)(tid));
+}
+
+
/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
/*=3D=3D=3D Getting to main() alive =
=3D=3D=3D*/
/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
Modified: trunk/coregrind/m_syswrap/syswrap-amd64-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-amd64-linux.c 2005-09-28 09:37:16 U=
TC (rev 4805)
+++ trunk/coregrind/m_syswrap/syswrap-amd64-linux.c 2005-09-28 10:47:38 U=
TC (rev 4806)
@@ -38,7 +38,6 @@
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_libcsignal.h"
-#include "pub_core_main.h"
#include "pub_core_scheduler.h"
#include "pub_core_sigframe.h"
#include "pub_core_signals.h"
@@ -133,8 +132,9 @@
(ULong)tidW);
=20
/* We are the last one standing. Keep hold of the lock and
- carry on to show final tool results, then exit the entire syste=
m. */
- VG_(shutdown_actions_NORETURN)(tid, src);
+ carry on to show final tool results, then exit the entire syste=
m.=20
+ Use the continuation pointer set at startup in m_main. */
+ ( * VG_(address_of_m_main_shutdown_actions_NORETURN) ) (tid, src);
=20
} else {
=20
Modified: trunk/coregrind/m_syswrap/syswrap-generic.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-generic.c 2005-09-28 09:37:16 UTC (=
rev 4805)
+++ trunk/coregrind/m_syswrap/syswrap-generic.c 2005-09-28 10:47:38 UTC (=
rev 4806)
@@ -42,7 +42,6 @@
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_libcsignal.h"
-#include "pub_core_main.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
#include "pub_core_scheduler.h"
Modified: trunk/coregrind/m_syswrap/syswrap-main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-main.c 2005-09-28 09:37:16 UTC (rev=
4805)
+++ trunk/coregrind/m_syswrap/syswrap-main.c 2005-09-28 10:47:38 UTC (rev=
4806)
@@ -1153,6 +1153,20 @@
}
=20
=20
+/* ---------------------------------------------------------------------
+ A place to store the where-to-call-when-really-done pointer
+ ------------------------------------------------------------------ */
+
+// When the final thread is done, where shall I call to shutdown the
+// system cleanly? Is set once at startup (in m_main) and never
+// changes after that. Is basically a pointer to the exit
+// continuation. This is all just a nasty hack to avoid calling
+// directly from m_syswrap to m_main at exit, since that would cause
+// m_main to become part of a module cycle, which is silly.
+void (* VG_(address_of_m_main_shutdown_actions_NORETURN) )
+ (ThreadId,VgSchedReturnCode)
+ =3D NULL;
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c 2005-09-28 09:37:16 U=
TC (rev 4805)
+++ trunk/coregrind/m_syswrap/syswrap-ppc32-linux.c 2005-09-28 10:47:38 U=
TC (rev 4806)
@@ -37,7 +37,6 @@
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_libcsignal.h"
-#include "pub_core_main.h" // For VG_(shutdown_actions_NORETURN=
)()
#include "pub_core_options.h"
#include "pub_core_scheduler.h"
#include "pub_core_sigframe.h" // For VG_(sigframe_destroy)()
@@ -158,8 +157,9 @@
(ULong)tidW);
=20
/* We are the last one standing. Keep hold of the lock and
- carry on to show final tool results, then exit the entire syste=
m. */
- VG_(shutdown_actions_NORETURN)(tid, src);
+ carry on to show final tool results, then exit the entire syste=
m.=20
+ Use the continuation pointer set at startup in m_main. */
+ ( * VG_(address_of_m_main_shutdown_actions_NORETURN) ) (tid, src);
=20
} else {
VG_(debugLog)(1, "syswrap-ppc32-linux",=20
Modified: trunk/coregrind/m_syswrap/syswrap-x86-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syswrap/syswrap-x86-linux.c 2005-09-28 09:37:16 UTC=
(rev 4805)
+++ trunk/coregrind/m_syswrap/syswrap-x86-linux.c 2005-09-28 10:47:38 UTC=
(rev 4806)
@@ -43,7 +43,6 @@
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_libcsignal.h"
-#include "pub_core_main.h" // For VG_(shutdown_actions_NORETURN=
)()
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
#include "pub_core_scheduler.h"
@@ -140,8 +139,9 @@
(ULong)tidW);
=20
/* We are the last one standing. Keep hold of the lock and
- carry on to show final tool results, then exit the entire syste=
m. */
- VG_(shutdown_actions_NORETURN)(tid, src);
+ carry on to show final tool results, then exit the entire syste=
m.=20
+ Use the continuation pointer set at startup in m_main. */
+ ( * VG_(address_of_m_main_shutdown_actions_NORETURN) ) (tid, src);
=20
} else {
=20
Deleted: trunk/coregrind/pub_core_main.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_main.h 2005-09-28 09:37:16 UTC (rev 4805)
+++ trunk/coregrind/pub_core_main.h 2005-09-28 10:47:38 UTC (rev 4806)
@@ -1,52 +0,0 @@
-
-/*--------------------------------------------------------------------*/
-/*--- The main module. pub_core_main.h ---*/
-/*--------------------------------------------------------------------*/
-
-/*
- This file is part of Valgrind, a dynamic binary instrumentation
- framework.
-
- Copyright (C) 2000-2005 Julian Seward
- js...@ac...
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307, USA.
-
- The GNU General Public License is contained in the file COPYING.
-*/
-
-#ifndef __PUB_CORE_MAIN_H
-#define __PUB_CORE_MAIN_H
-
-//--------------------------------------------------------------------
-// PURPOSE: This module is the main module, ie. the one holding main().
-// It arguably shouldn't export anything to other modules, since it depe=
nds
-// on almost every other module! But currently it exports quite a few
-// things.
-//--------------------------------------------------------------------
-
-// Do everything which needs doing before the process finally ends,
-// like printing reports, etc
-extern void VG_(shutdown_actions_NORETURN) (
- ThreadId tid,=20
- VgSchedReturnCode tids_schedretcode=20
- );
-
-#endif // __PUB_CORE_MAIN_H
-
-/*--------------------------------------------------------------------*/
-/*--- end ---*/
-/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/pub_core_syswrap.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_syswrap.h 2005-09-28 09:37:16 UTC (rev 4805)
+++ trunk/coregrind/pub_core_syswrap.h 2005-09-28 10:47:38 UTC (rev 4806)
@@ -66,6 +66,15 @@
extern void VG_(init_preopened_fds) ( void );
extern void VG_(show_open_fds) ( void );
=20
+// When the final thread is done, where shall I call to shutdown the
+// system cleanly? Is set once at startup (in m_main) and never
+// changes after that. Is basically a pointer to the exit
+// continuation. This is all just a nasty hack to avoid calling
+// directly from m_syswrap to m_main at exit, since that would cause
+// m_main to become part of a module cycle, which is silly.
+extern void (* VG_(address_of_m_main_shutdown_actions_NORETURN) )
+ (ThreadId,VgSchedReturnCode);
+
#endif // __PUB_CORE_SYSWRAP_H
=20
/*--------------------------------------------------------------------*/
|