Final commit for the initial modularisation pass:
- Broke part of m_scheduler off into a new module m_threadstate. It
contains ThreadState, VG_(threads)[] and some basic operations on the
thread table. All simple stuff, the complex stuff stays in m_scheduler.
This avoids lots of circular dependencies between m_scheduler and other
modules.
- Managed to finally remove core.h and tool.h, double hurrah!
- Introduced pub_tool_basics.h and pub_core_basics.h, one of which is
include by every single C file.
- Lots of little cleanups and changes related to the above.
- I even did a small amount of documentation updating.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3944 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am
index a0f87e3..fce5f56 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -31,9 +31,9 @@
vg_preload_core.so
noinst_HEADERS = \
- core.h \
coregrind.h \
pub_core_aspacemgr.h \
+ pub_core_basics.h \
pub_core_cpuid.h \
pub_core_debuginfo.h \
pub_core_debuglog.h \
@@ -65,6 +65,7 @@
pub_core_stacktrace.h \
pub_core_syswrap.h \
pub_core_threadmodel.h \
+ pub_core_threadstate.h \
pub_core_tooliface.h \
pub_core_trampoline.h \
pub_core_translate.h \
@@ -117,6 +118,7 @@
m_stacktrace.c \
m_syscall.c \
m_threadmodel.c \
+ m_threadstate.c \
m_tooliface.c \
m_trampoline.S \
m_translate.c \
diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c
index 613cf22..0c4208e 100644
--- a/coregrind/m_aspacemgr/aspacemgr.c
+++ b/coregrind/m_aspacemgr/aspacemgr.c
@@ -30,7 +30,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
diff --git a/coregrind/m_aspacemgr/read_procselfmaps.c b/coregrind/m_aspacemgr/read_procselfmaps.c
index 0e6381d..f7b17df 100644
--- a/coregrind/m_aspacemgr/read_procselfmaps.c
+++ b/coregrind/m_aspacemgr/read_procselfmaps.c
@@ -29,8 +29,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h" // needed for pub_core_aspacemgr.h
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
diff --git a/coregrind/m_cpuid.S b/coregrind/m_cpuid.S
index c08a151..fd40a77 100644
--- a/coregrind/m_cpuid.S
+++ b/coregrind/m_cpuid.S
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "pub_basics_asm.h"
+#include "pub_tool_basics_asm.h"
/*
Bool VG_(has_cpuid)(void)
diff --git a/coregrind/m_debuginfo/dwarf.c b/coregrind/m_debuginfo/dwarf.c
index 3b89dbe..2e77dd7 100644
--- a/coregrind/m_debuginfo/dwarf.c
+++ b/coregrind/m_debuginfo/dwarf.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
diff --git a/coregrind/m_debuginfo/stabs.c b/coregrind/m_debuginfo/stabs.c
index 14e0a38..3540695 100644
--- a/coregrind/m_debuginfo/stabs.c
+++ b/coregrind/m_debuginfo/stabs.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
diff --git a/coregrind/m_debuginfo/symtab.c b/coregrind/m_debuginfo/symtab.c
index 5815a7f..a381162 100644
--- a/coregrind/m_debuginfo/symtab.c
+++ b/coregrind/m_debuginfo/symtab.c
@@ -29,7 +29,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_demangle.h"
#include "pub_core_libcbase.h"
diff --git a/coregrind/m_debuginfo/symtypes.c b/coregrind/m_debuginfo/symtypes.c
index 0b74a4e..6147a7f 100644
--- a/coregrind/m_debuginfo/symtypes.c
+++ b/coregrind/m_debuginfo/symtypes.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_debuginfo.h"
#include "pub_core_debuglog.h" /* VG_(debugLog_vprintf) */
#include "pub_core_libcbase.h"
diff --git a/coregrind/m_debuglog.c b/coregrind/m_debuglog.c
index 8c47ccc..8cd0136 100644
--- a/coregrind/m_debuglog.c
+++ b/coregrind/m_debuglog.c
@@ -42,12 +42,12 @@
latter depend on this module. DO NOT MESS WITH THESE INCLUDES
UNLESS YOU ARE 100% CERTAIN YOU UNDERSTAND THE CONSEQUENCES.
*/
-/* This module is also different from all others in the sense that it
- is linked into both stage1 and stage2.
-*/
-#include "basic_types.h" /* basic types */
-#include "pub_core_debuglog.h" /* our own iface */
+/* This module is also notable because it is linked into both
+ stage1 and stage2. */
+
+#include "pub_core_basics.h" /* basic types */
+#include "pub_core_debuglog.h" /* our own iface */
/*------------------------------------------------------------*/
/*--- Stuff to make us completely independent. ---*/
diff --git a/coregrind/m_demangle/cp-demangle.c b/coregrind/m_demangle/cp-demangle.c
index 33095ff..0e22abc 100644
--- a/coregrind/m_demangle/cp-demangle.c
+++ b/coregrind/m_demangle/cp-demangle.c
@@ -40,7 +40,7 @@
#include <string.h>
#endif*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_mallocfree.h"
diff --git a/coregrind/m_demangle/cplus-dem.c b/coregrind/m_demangle/cplus-dem.c
index d1da6f2..b8bcc9a 100644
--- a/coregrind/m_demangle/cplus-dem.c
+++ b/coregrind/m_demangle/cplus-dem.c
@@ -37,7 +37,7 @@
#endif
#include "safe-ctype.h"
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_tool_libcprint.h"
diff --git a/coregrind/m_demangle/demangle.c b/coregrind/m_demangle/demangle.c
index 7100ba8..82f8e18 100644
--- a/coregrind/m_demangle/demangle.c
+++ b/coregrind/m_demangle/demangle.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_demangle.h"
#include "pub_core_libcbase.h"
#include "pub_core_mallocfree.h"
diff --git a/coregrind/m_demangle/dyn-string.c b/coregrind/m_demangle/dyn-string.c
index c5220fc..1c0466b 100644
--- a/coregrind/m_demangle/dyn-string.c
+++ b/coregrind/m_demangle/dyn-string.c
@@ -31,7 +31,7 @@
#include <stdlib.h>
#endif*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_mallocfree.h"
diff --git a/coregrind/m_dispatch/dispatch-amd64.S b/coregrind/m_dispatch/dispatch-amd64.S
index f328352..9c178d9 100644
--- a/coregrind/m_dispatch/dispatch-amd64.S
+++ b/coregrind/m_dispatch/dispatch-amd64.S
@@ -29,7 +29,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "pub_basics_asm.h"
+#include "pub_tool_basics_asm.h"
#include "pub_core_dispatch_asm.h"
#include "pub_core_transtab_asm.h"
#include "libvex_guest_offsets.h" /* for OFFSET_amd64_RIP */
diff --git a/coregrind/m_dispatch/dispatch-arm.S b/coregrind/m_dispatch/dispatch-arm.S
index 3372a0e..a7cf36f 100644
--- a/coregrind/m_dispatch/dispatch-arm.S
+++ b/coregrind/m_dispatch/dispatch-arm.S
@@ -29,7 +29,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "pub_basics_asm.h"
+#include "pub_tool_basics_asm.h"
#include "pub_core_dispatch_asm.h"
#include "pub_core_transtab_asm.h"
diff --git a/coregrind/m_dispatch/dispatch-x86.S b/coregrind/m_dispatch/dispatch-x86.S
index d90bb3d..1e97563 100644
--- a/coregrind/m_dispatch/dispatch-x86.S
+++ b/coregrind/m_dispatch/dispatch-x86.S
@@ -29,7 +29,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "pub_basics_asm.h"
+#include "pub_tool_basics_asm.h"
#include "pub_core_dispatch_asm.h"
#include "pub_core_transtab_asm.h"
#include "libvex_guest_offsets.h" /* for OFFSET_x86_EIP */
diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c
index 7ac1394..a192e35 100644
--- a/coregrind/m_errormgr.c
+++ b/coregrind/m_errormgr.c
@@ -28,7 +28,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h" // needed for pub_core_main.h
#include "pub_core_debuginfo.h"
#include "pub_core_errormgr.h"
#include "pub_core_execontext.h"
@@ -90,7 +91,7 @@
/* Errors. Extensible (via the 'extra' field). Tools can use a normal
enum (with element values in the normal range (0..)) for 'ekind'.
Functions for getting/setting the tool-relevant fields are in
- include/tool.h.
+ include/pub_tool_errormgr.h.
When errors are found and recorded with VG_(maybe_record_error)(), all
the tool must do is pass in the four parameters; core will
@@ -174,7 +175,7 @@
SuppLoc;
/* Suppressions. Tools can get/set tool-relevant parts with functions
- declared in include/tool.h. Extensible via the 'extra' field.
+ declared in include/pub_tool_errormgr.h. Extensible via the 'extra' field.
Tools can use a normal enum (with element values in the normal range
(0..)) for 'skind'. */
struct _Supp {
diff --git a/coregrind/m_execontext.c b/coregrind/m_execontext.c
index 15b5d70..649e746 100644
--- a/coregrind/m_execontext.c
+++ b/coregrind/m_execontext.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_execontext.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
diff --git a/coregrind/m_hashtable.c b/coregrind/m_hashtable.c
index c5312c5..fd8ace0 100644
--- a/coregrind/m_hashtable.c
+++ b/coregrind/m_hashtable.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_hashtable.h"
#include "pub_core_libcassert.h"
#include "pub_core_mallocfree.h"
diff --git a/coregrind/m_libcassert.c b/coregrind/m_libcassert.c
index d5825bd..ecaf6b6 100644
--- a/coregrind/m_libcassert.c
+++ b/coregrind/m_libcassert.c
@@ -28,12 +28,14 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
-#include "pub_core_main.h"
+#include "pub_core_main.h" // for VG_(bbs_done) -- stupid!
+#include "pub_core_options.h" // for VG_(bbs_done) -- stupid!
#include "pub_core_stacktrace.h"
#include "pub_core_syscall.h"
#include "pub_core_tooliface.h"
@@ -70,6 +72,21 @@
vg_assert(2+2 == 5);
}
+// Print the scheduler status.
+static void pp_sched_status ( void )
+{
+ Int i;
+ VG_(printf)("\nsched status:\n");
+ VG_(printf)(" running_tid=%d\n", VG_(get_running_tid)());
+ for (i = 1; i < VG_N_THREADS; i++) {
+ if (VG_(threads)[i].status == VgTs_Empty) continue;
+ VG_(printf)( "\nThread %d: status = %s\n", i,
+ VG_(name_of_ThreadStatus)(VG_(threads)[i].status) );
+ VG_(get_and_pp_StackTrace)( i, VG_(clo_backtrace_size) );
+ }
+ VG_(printf)("\n");
+}
+
__attribute__ ((noreturn))
static void report_and_quit ( const Char* report, Addr ip, Addr sp, Addr fp )
{
@@ -95,7 +112,7 @@
VG_(printf)("\nBasic block ctr is approximately %llu\n", VG_(bbs_done) );
- VG_(pp_sched_status)();
+ pp_sched_status();
VG_(printf)("\n");
VG_(printf)("Note: see also the FAQ.txt in the source distribution.\n");
VG_(printf)("It contains workarounds to several common problems.\n");
@@ -196,7 +213,7 @@
"Valgrind has to exit now. Sorry. Bye!");
VG_(message)(Vg_UserMsg,
"");
- VG_(pp_sched_status)();
+ pp_sched_status();
VG_(exit)(1);
}
diff --git a/coregrind/m_libcbase.c b/coregrind/m_libcbase.c
index 1ab10d3..7369cb3 100644
--- a/coregrind/m_libcbase.c
+++ b/coregrind/m_libcbase.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h" // XXX: temporary, for NULL, VG_(), Char, etc
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
/* ---------------------------------------------------------------------
diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c
index aa217b2..0f4e6c1 100644
--- a/coregrind/m_libcfile.c
+++ b/coregrind/m_libcfile.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h"
diff --git a/coregrind/m_libcmman.c b/coregrind/m_libcmman.c
index d3c66f1..a39d472 100644
--- a/coregrind/m_libcmman.c
+++ b/coregrind/m_libcmman.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c
index b4bdda3..88e5a7e 100644
--- a/coregrind/m_libcprint.c
+++ b/coregrind/m_libcprint.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_debuglog.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
diff --git a/coregrind/m_libcproc.c b/coregrind/m_libcproc.c
index bb6997c..f5249b5 100644
--- a/coregrind/m_libcproc.c
+++ b/coregrind/m_libcproc.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
diff --git a/coregrind/m_libcsignal.c b/coregrind/m_libcsignal.c
index d32d7ee..4810da3 100644
--- a/coregrind/m_libcsignal.c
+++ b/coregrind/m_libcsignal.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcsignal.h"
diff --git a/coregrind/m_machine.c b/coregrind/m_machine.c
index 09cebc3..bca38a9 100644
--- a/coregrind/m_machine.c
+++ b/coregrind/m_machine.c
@@ -28,11 +28,11 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcbase.h"
#include "pub_core_machine.h"
-#include "pub_core_scheduler.h"
#define INSTR_PTR(regs) ((regs).vex.VGA_INSTR_PTR)
#define STACK_PTR(regs) ((regs).vex.VGA_STACK_PTR)
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index 702df47..3c465c4 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -30,8 +30,8 @@
#define _FILE_OFFSET_BITS 64
-#include "core.h"
-#include "ume.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_debuglog.h"
#include "pub_core_errormgr.h"
@@ -49,11 +49,13 @@
#include "pub_core_options.h"
#include "pub_core_profile.h"
#include "pub_core_redir.h"
+#include "pub_core_scheduler.h"
#include "pub_core_signals.h"
#include "pub_core_syswrap.h"
#include "pub_core_tooliface.h"
#include "pub_core_trampoline.h"
#include "pub_core_transtab.h"
+#include "ume.h"
#include <dirent.h>
#include <dlfcn.h>
diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c
index 3e74e3d..28ea67c 100644
--- a/coregrind/m_mallocfree.c
+++ b/coregrind/m_mallocfree.c
@@ -29,8 +29,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
diff --git a/coregrind/m_options.c b/coregrind/m_options.c
index 40f2251..24d76f8 100644
--- a/coregrind/m_options.c
+++ b/coregrind/m_options.c
@@ -29,7 +29,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_options.h"
// See pub_{core,tool}_options.h for explanations of all these.
diff --git a/coregrind/m_profile.c b/coregrind/m_profile.c
index 965503a..212358f 100644
--- a/coregrind/m_profile.c
+++ b/coregrind/m_profile.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
#include "pub_core_profile.h"
diff --git a/coregrind/m_pthreadmodel.c b/coregrind/m_pthreadmodel.c
index 33fd2bf..76c0bd3 100644
--- a/coregrind/m_pthreadmodel.c
+++ b/coregrind/m_pthreadmodel.c
@@ -53,7 +53,7 @@
pthread_t identifiers and internal thread identifiers.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#if 0
diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c
index 3d5988c..155812f 100644
--- a/coregrind/m_redir.c
+++ b/coregrind/m_redir.c
@@ -29,13 +29,14 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h" // needed for pub_core_main.h
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
-#include "pub_core_main.h"
+#include "pub_core_main.h" // for VG_(set_libc_freeres_wrapper_addr)
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
#include "pub_core_redir.h"
diff --git a/coregrind/m_replacemalloc/replacemalloc_core.c b/coregrind/m_replacemalloc/replacemalloc_core.c
index 76dbdc6..952e089 100644
--- a/coregrind/m_replacemalloc/replacemalloc_core.c
+++ b/coregrind/m_replacemalloc/replacemalloc_core.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcprint.h"
#include "pub_core_mallocfree.h"
diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c
index be1a26f..df5603e 100644
--- a/coregrind/m_replacemalloc/vg_replace_malloc.c
+++ b/coregrind/m_replacemalloc/vg_replace_malloc.c
@@ -47,7 +47,7 @@
#include "valgrind.h" // for VALGRIND_NON_SIMD_CALL[12]
#include "coregrind.h" // for VALGRIND_INTERNAL_PRINTF
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_debuginfo.h" // needed for pub_core_redir.h :(
#include "pub_core_mallocfree.h" // for VG_MIN_MALLOC_SZB, VG_AR_CLIENT
#include "pub_core_redir.h" // for VG_REPLACE_FUNCTION
diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c
index 1d149e5..762e80e 100644
--- a/coregrind/m_scheduler/scheduler.c
+++ b/coregrind/m_scheduler/scheduler.c
@@ -60,7 +60,8 @@
#include "valgrind.h" // for VG_USERREQ__*
#include "coregrind.h" // for VG_USERREQ__*
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_dispatch.h"
#include "pub_core_errormgr.h"
@@ -90,18 +91,13 @@
Types and globals for the scheduler.
------------------------------------------------------------------ */
-/* ThreadId and ThreadState are defined in core.h. */
+/* ThreadId and ThreadState are defined elsewhere*/
/* Defines the thread-scheduling timeslice, in terms of the number of
basic blocks we attempt to run each thread for. Smaller values
give finer interleaving but much increased scheduling overheads. */
#define SCHEDULING_QUANTUM 50000
-/* Globals. A statically allocated array of threads. NOTE: [0] is
- never used, to simplify the simulation of initialisers for
- LinuxThreads. */
-ThreadState VG_(threads)[VG_N_THREADS];
-
/* If true, a fault is Valgrind-internal (ie, a bug) */
Bool VG_(my_fault) = True;
@@ -112,7 +108,6 @@
static void do_client_request ( ThreadId tid );
static void scheduler_sanity ( ThreadId tid );
static void mostly_clear_thread_record ( ThreadId tid );
-static const HChar *name_of_thread_state ( ThreadStatus );
/* Stats. */
static UInt n_scheduling_events_MINOR = 0;
@@ -128,58 +123,12 @@
/* CPU semaphore, so that threads can run exclusively */
static vg_sema_t run_sema;
-static ThreadId running_tid = VG_INVALID_THREADID;
/* ---------------------------------------------------------------------
Helper functions for the scheduler.
------------------------------------------------------------------ */
-__inline__
-Bool VG_(is_valid_tid) ( ThreadId tid )
-{
- /* tid is unsigned, hence no < 0 test. */
- if (tid == 0) return False;
- if (tid >= VG_N_THREADS) return False;
- if (VG_(threads)[tid].status == VgTs_Empty) return False;
- return True;
-}
-
-
-/* For constructing error messages only: try and identify a thread
- whose stack satisfies the predicate p, or return VG_INVALID_THREADID
- if none do.
-*/
-ThreadId VG_(first_matching_thread_stack)
- ( Bool (*p) ( Addr stack_min, Addr stack_max, void* d ),
- void* d )
-{
- ThreadId tid;
-
- for (tid = 1; tid < VG_N_THREADS; tid++) {
- if (VG_(threads)[tid].status == VgTs_Empty) continue;
-
- if ( p ( VG_(get_SP)(tid),
- VG_(threads)[tid].client_stack_highest_word, d ) )
- return tid;
- }
- return VG_INVALID_THREADID;
-}
-
-/* Print the scheduler status. */
-void VG_(pp_sched_status) ( void )
-{
- Int i;
- VG_(printf)("\nsched status:\n");
- VG_(printf)(" running_tid=%d\n", running_tid);
- for (i = 1; i < VG_N_THREADS; i++) {
- if (VG_(threads)[i].status == VgTs_Empty) continue;
- VG_(printf)("\nThread %d: status = %s\n", i, name_of_thread_state(VG_(threads)[i].status));
- VG_(get_and_pp_StackTrace)( i, VG_(clo_backtrace_size) );
- }
- VG_(printf)("\n");
-}
-
static
void print_sched_event ( ThreadId tid, Char* what )
{
@@ -201,20 +150,6 @@
}
}
-static
-const HChar* name_of_thread_state ( ThreadStatus state )
-{
- switch (state) {
- case VgTs_Empty: return "VgTs_Empty";
- case VgTs_Init: return "VgTs_Init";
- case VgTs_Runnable: return "VgTs_Runnable";
- case VgTs_WaitSys: return "VgTs_WaitSys";
- case VgTs_Yielding: return "VgTs_Yielding";
- case VgTs_Zombie: return "VgTs_Zombie";
- default: return "VgTs_???";
- }
-}
-
/* Allocate a completely empty ThreadState record. */
ThreadId VG_(alloc_ThreadState) ( void )
{
@@ -232,25 +167,6 @@
/*NOTREACHED*/
}
-ThreadState *VG_(get_ThreadState)(ThreadId tid)
-{
- vg_assert(tid >= 0 && tid < VG_N_THREADS);
- return &VG_(threads)[tid];
-}
-
-/* Given an LWP id (ie, real kernel thread id), find the corresponding
- ThreadId */
-ThreadId VG_(get_lwp_tid)(Int lwp)
-{
- ThreadId tid;
-
- for(tid = 1; tid < VG_N_THREADS; tid++)
- if (VG_(threads)[tid].status != VgTs_Empty && VG_(threads)[tid].os_state.lwpid == lwp)
- return tid;
-
- return VG_INVALID_THREADID;
-}
-
/*
Mark a thread as Runnable. This will block until the run_sema is
available, so that we get exclusive access to all the shared
@@ -268,44 +184,15 @@
tst->status = VgTs_Runnable;
VG_(sema_down)(&run_sema);
- if (running_tid != VG_INVALID_THREADID)
- VG_(printf)("tid %d found %d running\n", tid, running_tid);
- vg_assert(running_tid == VG_INVALID_THREADID);
- running_tid = tid;
+ if (VG_(running_tid) != VG_INVALID_THREADID)
+ VG_(printf)("tid %d found %d running\n", tid, VG_(running_tid));
+ vg_assert(VG_(running_tid) == VG_INVALID_THREADID);
+ VG_(running_tid) = tid;
if (VG_(clo_trace_sched))
print_sched_event(tid, "now running");
}
-ThreadId VG_(get_running_tid)(void)
-{
- return running_tid;
-}
-
-Bool VG_(is_running_thread)(ThreadId tid)
-{
- ThreadState *tst = VG_(get_ThreadState)(tid);
-
- return
-// tst->os_state.lwpid == VG_(gettid)() && /* check we're this tid */
- running_tid == tid && /* and that we've got the lock */
- tst->status == VgTs_Runnable; /* and we're runnable */
-}
-
-/* Return the number of non-dead Threads */
-Int VG_(count_living_threads)(void)
-{
- Int count = 0;
- ThreadId tid;
-
- for(tid = 1; tid < VG_N_THREADS; tid++)
- if (VG_(threads)[tid].status != VgTs_Empty &&
- VG_(threads)[tid].status != VgTs_Zombie)
- count++;
-
- return count;
-}
-
/*
Set a thread into a sleeping state, and give up exclusive access to
the CPU. On return, the thread must be prepared to block until it
@@ -324,8 +211,8 @@
tst->status = sleepstate;
- vg_assert(running_tid == tid);
- running_tid = VG_INVALID_THREADID;
+ vg_assert(VG_(running_tid) == tid);
+ VG_(running_tid) = VG_INVALID_THREADID;
/* Release the run_sema; this will reschedule any runnable
thread. */
@@ -334,19 +221,11 @@
if (VG_(clo_trace_sched)) {
Char buf[50];
VG_(sprintf)(buf, "now sleeping in state %s",
- name_of_thread_state(sleepstate));
+ VG_(name_of_ThreadStatus)(sleepstate));
print_sched_event(tid, buf);
}
}
-/* Return true if the thread is still alive but in the process of
- exiting. */
-inline Bool VG_(is_exiting)(ThreadId tid)
-{
- vg_assert(VG_(is_valid_tid)(tid));
- return VG_(threads)[tid].exitreason != VgSrc_None;
-}
-
/* Clear out the ThreadState and release the semaphore. Leaves the
ThreadState in VgTs_Zombie state, so that it doesn't get
reallocated until the caller is really ready. */
@@ -357,7 +236,7 @@
vg_assert(VG_(is_exiting)(tid));
mostly_clear_thread_record(tid);
- running_tid = VG_INVALID_THREADID;
+ VG_(running_tid) = VG_INVALID_THREADID;
/* There should still be a valid exitreason for this thread */
vg_assert(VG_(threads)[tid].exitreason != VgSrc_None);
@@ -388,7 +267,7 @@
void VG_(vg_yield)(void)
{
struct vki_timespec ts = { 0, 1 };
- ThreadId tid = running_tid;
+ ThreadId tid = VG_(running_tid);
vg_assert(tid != VG_INVALID_THREADID);
vg_assert(VG_(threads)[tid].os_state.lwpid == VG_(gettid)());
@@ -609,7 +488,7 @@
static void sched_fork_cleanup(ThreadId me)
{
ThreadId tid;
- vg_assert(running_tid == me);
+ vg_assert(VG_(running_tid) == me);
VG_(threads)[me].os_state.lwpid = VG_(gettid)();
VG_(threads)[me].os_state.threadgroup = VG_(getpid)();
@@ -708,8 +587,8 @@
SCHEDSETJMP(tid, jumped, VG_(client_syscall)(tid));
if (!VG_(is_running_thread)(tid))
- VG_(printf)("tid %d not running; running_tid=%d, tid %d status %d\n",
- tid, running_tid, tid, tst->status);
+ VG_(printf)("tid %d not running; VG_(running_tid)=%d, tid %d status %d\n",
+ tid, VG_(running_tid), tid, tst->status);
vg_assert(VG_(is_running_thread)(tid));
if (jumped) {
@@ -1159,7 +1038,7 @@
if (!VG_(is_running_thread)(tid)) {
VG_(message)(Vg_DebugMsg,
"Thread %d is supposed to be running, but doesn't own run_sema (owned by %d)\n",
- tid, running_tid);
+ tid, VG_(running_tid));
bad = True;
}
diff --git a/coregrind/m_scheduler/sema.c b/coregrind/m_scheduler/sema.c
index a01aed7..0d12923 100644
--- a/coregrind/m_scheduler/sema.c
+++ b/coregrind/m_scheduler/sema.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h"
#include "pub_core_libcproc.h"
diff --git a/coregrind/m_sigframe/sigframe-amd64-linux.c b/coregrind/m_sigframe/sigframe-amd64-linux.c
index 6d0780e..a3246bc 100644
--- a/coregrind/m_sigframe/sigframe-amd64-linux.c
+++ b/coregrind/m_sigframe/sigframe-amd64-linux.c
@@ -29,7 +29,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
@@ -41,8 +42,6 @@
#include "pub_core_tooliface.h"
#include "pub_core_trampoline.h"
-#include "libvex_guest_amd64.h"
-
/* This module creates and removes signal frames for signal deliveries
on amd64-linux.
diff --git a/coregrind/m_sigframe/sigframe-arm-linux.c b/coregrind/m_sigframe/sigframe-arm-linux.c
index 49704f3..767162e 100644
--- a/coregrind/m_sigframe/sigframe-arm-linux.c
+++ b/coregrind/m_sigframe/sigframe-arm-linux.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "libvex_guest_arm.h"
diff --git a/coregrind/m_sigframe/sigframe-x86-linux.c b/coregrind/m_sigframe/sigframe-x86-linux.c
index 6000657..05af319 100644
--- a/coregrind/m_sigframe/sigframe-x86-linux.c
+++ b/coregrind/m_sigframe/sigframe-x86-linux.c
@@ -29,7 +29,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h" /* find_segment */
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
@@ -41,8 +42,6 @@
#include "pub_core_tooliface.h"
#include "pub_core_trampoline.h"
-#include "libvex_guest_x86.h"
-
/* This module creates and removes signal frames for signal deliveries
on x86-linux.
diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c
index 7f082ad..63dfd3a 100644
--- a/coregrind/m_signals.c
+++ b/coregrind/m_signals.c
@@ -79,8 +79,8 @@
always unblocked).
*/
-#include "core.h"
-
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_errormgr.h"
#include "pub_core_libcbase.h"
@@ -93,6 +93,7 @@
#include "pub_core_main.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
+#include "pub_core_scheduler.h"
#include "pub_core_signals.h"
#include "pub_core_sigframe.h"
#include "pub_core_stacktrace.h"
diff --git a/coregrind/m_skiplist.c b/coregrind/m_skiplist.c
index 0a80f5c..796b1d3 100644
--- a/coregrind/m_skiplist.c
+++ b/coregrind/m_skiplist.c
@@ -86,7 +86,7 @@
won't be accidentally used.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
diff --git a/coregrind/m_stacktrace.c b/coregrind/m_stacktrace.c
index 2f5fb83..38adf15 100644
--- a/coregrind/m_stacktrace.c
+++ b/coregrind/m_stacktrace.c
@@ -28,7 +28,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
diff --git a/coregrind/m_syscall.c b/coregrind/m_syscall.c
index 06b6cf0..b3a7036 100644
--- a/coregrind/m_syscall.c
+++ b/coregrind/m_syscall.c
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_syscall.h"
/* ---------------------------------------------------------------------
diff --git a/coregrind/m_syswrap/syscall-amd64-linux.S b/coregrind/m_syswrap/syscall-amd64-linux.S
index 200c1b8..6fa4271 100644
--- a/coregrind/m_syswrap/syscall-amd64-linux.S
+++ b/coregrind/m_syswrap/syscall-amd64-linux.S
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "pub_basics_asm.h"
+#include "pub_tool_basics_asm.h"
#include "vki_unistd.h"
#include "libvex_guest_offsets.h"
diff --git a/coregrind/m_syswrap/syscall-arm-linux.S b/coregrind/m_syswrap/syscall-arm-linux.S
index c1c319a..4423863 100644
--- a/coregrind/m_syswrap/syscall-arm-linux.S
+++ b/coregrind/m_syswrap/syscall-arm-linux.S
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "pub_basics_asm.h"
+#include "pub_tool_basics_asm.h"
#include "vki_unistd.h"
# XXX: must reinstate comments also -- see x86-linux/syscall.S
diff --git a/coregrind/m_syswrap/syscall-x86-linux.S b/coregrind/m_syswrap/syscall-x86-linux.S
index 14986f1..9b2761a 100644
--- a/coregrind/m_syswrap/syscall-x86-linux.S
+++ b/coregrind/m_syswrap/syscall-x86-linux.S
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "pub_basics_asm.h"
+#include "pub_tool_basics_asm.h"
#include "vki_unistd.h"
#include "libvex_guest_offsets.h"
diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c
index 9baa6f2..f8dd3d2 100644
--- a/coregrind/m_syswrap/syswrap-amd64-linux.c
+++ b/coregrind/m_syswrap/syswrap-amd64-linux.c
@@ -28,7 +28,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_debuglog.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_options.h"
@@ -38,6 +39,8 @@
#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"
#include "pub_core_syscall.h"
diff --git a/coregrind/m_syswrap/syswrap-arm-linux.c b/coregrind/m_syswrap/syswrap-arm-linux.c
index 735d1cc..e24df5c 100644
--- a/coregrind/m_syswrap/syswrap-arm-linux.c
+++ b/coregrind/m_syswrap/syswrap-arm-linux.c
@@ -28,12 +28,6 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
-
-
-// See the comment accompanying the declaration of VGA_(thread_syscall)() in
-// coregrind/core.h for an explanation of what this does, and why.
-//
// XXX: this function and these variables should be assembly code! See the
// x86 version.
const Addr VGA_(sys_before), VGA_(sys_restarted),
diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c
index 44d25f3..ad719a7 100644
--- a/coregrind/m_syswrap/syswrap-generic.c
+++ b/coregrind/m_syswrap/syswrap-generic.c
@@ -28,7 +28,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_debuglog.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
@@ -43,6 +44,7 @@
#include "pub_core_stacktrace.h"
#include "pub_core_tooliface.h"
#include "pub_core_options.h"
+#include "pub_core_scheduler.h"
#include "pub_core_signals.h"
#include "pub_core_syscall.h"
#include "pub_core_syswrap.h"
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
index 5fb88df..00af0fe 100644
--- a/coregrind/m_syswrap/syswrap-linux.c
+++ b/coregrind/m_syswrap/syswrap-linux.c
@@ -28,7 +28,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_debuglog.h"
#include "pub_core_libcbase.h"
@@ -39,6 +40,7 @@
#include "pub_core_mallocfree.h"
#include "pub_core_tooliface.h"
#include "pub_core_options.h"
+#include "pub_core_scheduler.h"
#include "pub_core_signals.h"
#include "pub_core_syscall.h"
diff --git a/coregrind/m_syswrap/syswrap-main.c b/coregrind/m_syswrap/syswrap-main.c
index d775efa..c26e1d7 100644
--- a/coregrind/m_syswrap/syswrap-main.c
+++ b/coregrind/m_syswrap/syswrap-main.c
@@ -29,12 +29,14 @@
*/
#include "libvex_guest_offsets.h"
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_libcsignal.h"
+#include "pub_core_scheduler.h"
#include "pub_core_stacktrace.h"
#include "pub_core_tooliface.h"
#include "pub_core_options.h"
diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c
index e800393..5168e21 100644
--- a/coregrind/m_syswrap/syswrap-x86-linux.c
+++ b/coregrind/m_syswrap/syswrap-x86-linux.c
@@ -33,7 +33,8 @@
to assign the shadow state.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
#include "pub_core_debuglog.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_options.h"
@@ -43,7 +44,9 @@
#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_scheduler.h"
#include "pub_core_sigframe.h"
#include "pub_core_signals.h"
#include "pub_core_syscall.h"
diff --git a/coregrind/m_threadmodel.c b/coregrind/m_threadmodel.c
index c920430..9787ac9 100644
--- a/coregrind/m_threadmodel.c
+++ b/coregrind/m_threadmodel.c
@@ -60,9 +60,8 @@
introduce a separate notion of a "thread" for modelling purposes.
*/
-//::
-//:: #include "core.h"
-//::
+#include "pub_core_basics.h"
+
//:: struct thread;
//:: struct mutex;
//:: struct condvar;
diff --git a/coregrind/m_threadstate.c b/coregrind/m_threadstate.c
new file mode 100644
index 0000000..b38642b
--- /dev/null
+++ b/coregrind/m_threadstate.c
@@ -0,0 +1,148 @@
+
+/*--------------------------------------------------------------------*/
+/*--- The thread state. m_threadstate.c ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ jseward@acm.org
+
+ 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.
+*/
+
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_machine.h" // For VG_(get_SP)
+
+/*------------------------------------------------------------*/
+/*--- Data structures. ---*/
+/*------------------------------------------------------------*/
+
+ThreadId VG_(running_tid) = VG_INVALID_THREADID;
+
+ThreadState VG_(threads)[VG_N_THREADS];
+
+/*------------------------------------------------------------*/
+/*--- Operations. ---*/
+/*------------------------------------------------------------*/
+
+const HChar* VG_(name_of_ThreadStatus) ( ThreadStatus status )
+{
+ switch (status) {
+ case VgTs_Empty: return "VgTs_Empty";
+ case VgTs_Init: return "VgTs_Init";
+ case VgTs_Runnable: return "VgTs_Runnable";
+ case VgTs_WaitSys: return "VgTs_WaitSys";
+ case VgTs_Yielding: return "VgTs_Yielding";
+ case VgTs_Zombie: return "VgTs_Zombie";
+ default: return "VgTs_???";
+ }
+}
+
+ThreadState *VG_(get_ThreadState)(ThreadId tid)
+{
+ vg_assert(tid >= 0 && tid < VG_N_THREADS);
+ return &VG_(threads)[tid];
+}
+
+Bool VG_(is_valid_tid) ( ThreadId tid )
+{
+ /* tid is unsigned, hence no < 0 test. */
+ if (tid == 0) return False;
+ if (tid >= VG_N_THREADS) return False;
+ if (VG_(threads)[tid].status == VgTs_Empty) return False;
+ return True;
+}
+
+// This function is for tools to call.
+ThreadId VG_(get_running_tid)(void)
+{
+ return VG_(running_tid);
+}
+
+Bool VG_(is_running_thread)(ThreadId tid)
+{
+ ThreadState *tst = VG_(get_ThreadState)(tid);
+
+ return
+// tst->os_state.lwpid == VG_(gettid)() && // check we're this tid
+ VG_(running_tid) == tid && // and that we've got the lock
+ tst->status == VgTs_Runnable; // and we're runnable
+}
+
+/* Return true if the thread is still alive but in the process of exiting. */
+inline Bool VG_(is_exiting)(ThreadId tid)
+{
+ vg_assert(VG_(is_valid_tid)(tid));
+ return VG_(threads)[tid].exitreason != VgSrc_None;
+}
+
+/* Return the number of non-dead Threads */
+Int VG_(count_living_threads)(void)
+{
+ Int count = 0;
+ ThreadId tid;
+
+ for(tid = 1; tid < VG_N_THREADS; tid++)
+ if (VG_(threads)[tid].status != VgTs_Empty &&
+ VG_(threads)[tid].status != VgTs_Zombie)
+ count++;
+
+ return count;
+}
+
+/* Given an LWP id (ie, real kernel thread id), find the corresponding
+ ThreadId */
+ThreadId VG_(get_lwp_tid)(Int lwp)
+{
+ ThreadId tid;
+
+ for(tid = 1; tid < VG_N_THREADS; tid++)
+ if (VG_(threads)[tid].status != VgTs_Empty && VG_(threads)[tid].os_state.lwpid == lwp)
+ return tid;
+
+ return VG_INVALID_THREADID;
+}
+
+/* For constructing error messages only: try and identify a thread
+ whose stack satisfies the predicate p, or return VG_INVALID_THREADID
+ if none do.
+*/
+ThreadId VG_(first_matching_thread_stack)
+ ( Bool (*p) ( Addr stack_min, Addr stack_max, void* d ),
+ void* d )
+{
+ ThreadId tid;
+
+ for (tid = 1; tid < VG_N_THREADS; tid++) {
+ if (VG_(threads)[tid].status == VgTs_Empty) continue;
+
+ if ( p ( VG_(get_SP)(tid),
+ VG_(threads)[tid].client_stack_highest_word, d ) )
+ return tid;
+ }
+ return VG_INVALID_THREADID;
+}
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
diff --git a/coregrind/m_tooliface.c b/coregrind/m_tooliface.c
index fa0feda..c17e40a 100644
--- a/coregrind/m_tooliface.c
+++ b/coregrind/m_tooliface.c
@@ -29,7 +29,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
diff --git a/coregrind/m_trampoline.S b/coregrind/m_trampoline.S
index c4d0d98..c57737c 100644
--- a/coregrind/m_trampoline.S
+++ b/coregrind/m_trampoline.S
@@ -28,7 +28,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "pub_basics_asm.h"
+#include "pub_tool_basics_asm.h"
#include "vki_unistd.h"
/* ------------------ SIMULATED CPU HELPERS ------------------ */
diff --git a/coregrind/m_translate.c b/coregrind/m_translate.c
index 5442fa5..d64914d 100644
--- a/coregrind/m_translate.c
+++ b/coregrind/m_translate.c
@@ -29,7 +29,8 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
+#include "pub_core_threadstate.h" // needed for pub_core_main.h
#include "pub_core_aspacemgr.h"
#include "pub_core_cpuid.h"
#include "pub_core_libcbase.h"
diff --git a/coregrind/m_transtab.c b/coregrind/m_transtab.c
index 8ef0f9f..e74cbcc 100644
--- a/coregrind/m_transtab.c
+++ b/coregrind/m_transtab.c
@@ -29,7 +29,7 @@
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_debuginfo.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
diff --git a/coregrind/core.h b/coregrind/pub_core_basics.h
similarity index 69%
rename from coregrind/core.h
rename to coregrind/pub_core_basics.h
index a7d927b..42d6f20 100644
--- a/coregrind/core.h
+++ b/coregrind/pub_core_basics.h
@@ -1,14 +1,13 @@
/*--------------------------------------------------------------------*/
-/*--- A header file for various private parts of Valgrind's core. ---*/
-/*--- core.h ---*/
+/*--- Header included by every core C file. pub_core_basics.h ---*/
/*--------------------------------------------------------------------*/
-
+
/*
This file is part of Valgrind, a dynamic binary instrumentation
framework.
- Copyright (C) 2000-2005 Julian Seward
+ Copyright (C) 2000-2005 Julian Seward
jseward@acm.org
This program is free software; you can redistribute it and/or
@@ -29,14 +28,26 @@
The GNU General Public License is contained in the file COPYING.
*/
-#ifndef __CORE_H
-#define __CORE_H
+#ifndef __PUB_CORE_BASICS_H
+#define __PUB_CORE_BASICS_H
-#include "tool.h" // tool stuff
+//--------------------------------------------------------------------
+// PURPOSE: This header should be imported by every single C file
+// in the core. It contains the basic types and other things needed
+// everywhere.
+//--------------------------------------------------------------------
+
+#include "pub_tool_basics.h"
+
+/* ---------------------------------------------------------------------
+ Other headers to include
+ ------------------------------------------------------------------ */
+
+// Might as well have the following two in here, their contents are used so
+// broadly (eg. in pub_core_threadstate.h).
#include "libvex.h"
-// XXX: this is needed because pub_core_scheduler needs VexGuestXXXState...
#if defined(VGA_x86)
# include "libvex_guest_x86.h"
#elif defined(VGA_amd64)
@@ -45,19 +56,10 @@
# error Unknown arch
#endif
-#include <setjmp.h> // for jmp_buf
+#include <setjmp.h>
-#include "pub_core_scheduler.h" // for types 'ThreadArchState'
-
-/* ---------------------------------------------------------------------
- Finally - autoconf-generated settings
- ------------------------------------------------------------------ */
-
-#include "config.h"
-
-#endif /* ndef __CORE_H */
+#endif // __PUB_CORE_BASICS_H
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
-
diff --git a/coregrind/pub_core_debuglog.h b/coregrind/pub_core_debuglog.h
index 218c355..1027fc7 100644
--- a/coregrind/pub_core_debuglog.h
+++ b/coregrind/pub_core_debuglog.h
@@ -47,7 +47,7 @@
portable way to avoid using stdarg.h. */
#include <stdarg.h>
-#include "pub_basics_asm.h" /* For definition of VG_ macro */
+#include "pub_tool_basics.h" /* For definition of VG_ macro */
/* There are no tool-visible exports from m_debuglog, hence no header
file for it. */
diff --git a/coregrind/pub_core_errormgr.h b/coregrind/pub_core_errormgr.h
index a40cddd..4483555 100644
--- a/coregrind/pub_core_errormgr.h
+++ b/coregrind/pub_core_errormgr.h
@@ -38,8 +38,6 @@
#include "pub_tool_errormgr.h"
-//#include "pub_core_stacktrace.h"
-
// XXX: should this be in pthreadmodel.c?
// These must be negative, so as to not overlap with tool error kinds.
typedef
diff --git a/coregrind/pub_core_main.h b/coregrind/pub_core_main.h
index 99b148e..667d9db 100644
--- a/coregrind/pub_core_main.h
+++ b/coregrind/pub_core_main.h
@@ -57,6 +57,13 @@
// Set up the libc freeres wrapper
extern void VG_(set_libc_freeres_wrapper_addr)(Addr);
+// Do everything which needs doing before the process finally ends,
+// like printing reports, etc
+extern void VG_(shutdown_actions_NORETURN) (
+ ThreadId tid,
+ VgSchedReturnCode tids_schedretcode
+ );
+
#endif // __PUB_CORE_MAIN_H
/*--------------------------------------------------------------------*/
diff --git a/coregrind/pub_core_scheduler.h b/coregrind/pub_core_scheduler.h
index 33e9e6b..7940357 100644
--- a/coregrind/pub_core_scheduler.h
+++ b/coregrind/pub_core_scheduler.h
@@ -37,165 +37,6 @@
// It's at the centre of everything.
//--------------------------------------------------------------------
-/*
- Thread state machine:
-
- Empty -> Init -> Runnable <=> WaitSys/Yielding
- ^ |
- \---- Zombie -----/
- */
-typedef
- enum ThreadStatus {
- VgTs_Empty, /* this slot is not in use */
- VgTs_Init, /* just allocated */
- VgTs_Runnable, /* ready to run */
- VgTs_WaitSys, /* waiting for a syscall to complete */
- VgTs_Yielding, /* temporarily yielding the CPU */
- VgTs_Zombie, /* transient state just before exiting */
- }
- ThreadStatus;
-
-/* Return codes from the scheduler. */
-typedef
- enum {
- VgSrc_None, /* not exiting yet */
- VgSrc_ExitSyscall, /* client called exit(). This is the normal
- route out. */
- VgSrc_FatalSig /* Killed by the default action of a fatal
- signal */
- }
- VgSchedReturnCode;
-
-
-#if defined(VGA_x86)
- typedef VexGuestX86State VexGuestArchState;
-#elif defined(VGA_amd64)
- typedef VexGuestAMD64State VexGuestArchState;
-#elif defined(VGA_arm)
- typedef VexGuestARMState VexGuestArchState;
-#else
-# error Unknown architecture
-#endif
-
-
-typedef
- struct {
- /* --- BEGIN vex-mandated guest state --- */
-
- /* Saved machine context. */
- VexGuestArchState vex;
-
- /* Saved shadow context. */
- VexGuestArchState vex_shadow;
-
- /* Spill area. */
- UChar vex_spill[LibVEX_N_SPILL_BYTES];
-
- /* --- END vex-mandated guest state --- */
- }
- 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.
- The thread identity is simply the index in vg_threads[].
- ThreadId == 1 is the root thread and has the special property
- that we don't try and allocate or deallocate its stack. For
- convenience of generating error message, we also put the
- ThreadId in this tid field, but be aware that it should
- ALWAYS == the index in vg_threads[]. */
- ThreadId tid;
-
- /* Current scheduling status. */
- ThreadStatus status;
-
- /* This is set if the thread is in the process of exiting for any
- reason. The precise details of the exit are in the OS-specific
- state. */
- VgSchedReturnCode exitreason;
-
- /* Architecture-specific thread state. */
- ThreadArchState arch;
-
- /* This thread's blocked-signals mask. Semantics is that for a
- signal to be delivered to this thread, the signal must not be
- blocked by this signal mask. If more than one thread accepts a
- signal, then it will be delivered to one at random. If all
- threads block the signal, it will remain pending until either a
- thread unblocks it or someone uses sigwaitsig/sigtimedwait. */
- vki_sigset_t sig_mask;
-
- /* tmp_sig_mask is usually the same as sig_mask, and is kept in
- sync whenever sig_mask is changed. The only time they have
- different values is during the execution of a sigsuspend, where
- tmp_sig_mask is the temporary mask which sigsuspend installs.
- It is only consulted to compute the signal mask applied to a
- signal handler. */
- vki_sigset_t tmp_sig_mask;
-
- /* A little signal queue for signals we can't get the kernel to
- queue for us. This is only allocated as needed, since it should
- be rare. */
- struct SigQueue *sig_queue;
-
- /* Client stacks. When a thread slot is freed, we don't deallocate its
- stack; we just leave it lying around for the next use of the
- slot. If the next use of the slot requires a larger stack,
- only then is the old one deallocated and a new one
- allocated.
-
- For the main thread (threadid == 0), this mechanism doesn't
- apply. We don't know the size of the stack since we didn't
- allocate it, and furthermore we never reallocate it. */
-
- /* The allocated size of this thread's stack (permanently zero
- if this is ThreadId == 0, since we didn't allocate its stack) */
- SizeT client_stack_szB;
-
- /* Address of the highest legitimate word in this stack. This is
- used for error messages only -- not critical for execution
- correctness. Is is set for all stacks, specifically including
- ThreadId == 0 (the main thread). */
- Addr client_stack_highest_word;
-
- /* Alternate signal stack */
- vki_stack_t altstack;
-
- /* OS-specific thread state */
- os_thread_t os_state;
-
- /* Used in the syscall handlers. Set to True to indicate that the
- PRE routine for a syscall has set the syscall result already and
- so the syscall does not need to be handed to the kernel. */
- Bool syscall_result_set;
-
- /* Per-thread jmp_buf to resume scheduler after a signal */
- Bool sched_jmpbuf_valid;
- jmp_buf sched_jmpbuf;
-}
-ThreadState;
-
-
-/* The thread table. */
-extern ThreadState VG_(threads)[VG_N_THREADS];
-
/* Allocate a new ThreadState */
extern ThreadId VG_(alloc_ThreadState)(void);
@@ -207,25 +48,6 @@
exitcode. */
extern void VG_(kill_thread)(ThreadId tid);
-/* Check that tid is in range and denotes a non-Empty thread. */
-extern Bool VG_(is_valid_tid) ( ThreadId tid );
-
-/* Get the ThreadState for a particular thread */
-extern ThreadState *VG_(get_ThreadState)(ThreadId tid);
-
-/* Given an LWP id (ie, real kernel thread id), find the corresponding
- ThreadId */
-extern ThreadId VG_(get_lwp_tid)(Int lwpid);
-
-/* Returns true if a thread is currently running (ie, has the CPU lock) */
-extern Bool VG_(is_running_thread)(ThreadId tid);
-
-/* Returns true if the thread is in the process of exiting */
-extern Bool VG_(is_exiting)(ThreadId tid);
-
-/* Return the number of non-dead Threads */
-extern Int VG_(count_living_threads)(void);
-
/* Nuke all threads except tid. */
extern void VG_(nuke_all_threads_except) ( ThreadId me,
VgSchedReturnCode reason );
@@ -253,17 +75,8 @@
// The scheduler.
extern VgSchedReturnCode VG_(scheduler) ( ThreadId tid );
-// Do everything which needs doing before the process finally ends,
-// like printing reports, etc
-extern void VG_(shutdown_actions_NORETURN) (
- ThreadId tid,
- VgSchedReturnCode tids_schedretcode
- );
-
extern void VG_(scheduler_init) ( void );
-extern void VG_(pp_sched_status) ( void );
-
/* Stats ... */
extern void VG_(print_scheduler_stats) ( void );
diff --git a/coregrind/pub_core_threadstate.h b/coregrind/pub_core_threadstate.h
new file mode 100644
index 0000000..148d18e
--- /dev/null
+++ b/coregrind/pub_core_threadstate.h
@@ -0,0 +1,247 @@
+
+/*--------------------------------------------------------------------*/
+/*--- The thread state. pub_core_threadstate.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ jseward@acm.org
+
+ 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_THREADSTATE_H
+#define __PUB_CORE_THREADSTATE_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module defines the ThreadState type and the
+// VG_(threads)[] data structure which holds all the important thread
+// state. It also defines some simple operations on the data structure
+// that don't require any external help. (m_scheduler does the complex
+// stuff).
+//--------------------------------------------------------------------
+
+#include "pub_tool_threadstate.h"
+
+/*------------------------------------------------------------*/
+/*--- Types ---*/
+/*------------------------------------------------------------*/
+
+/*
+ Thread state machine:
+
+ Empty -> Init -> Runnable <=> WaitSys/Yielding
+ ^ |
+ \---- Zombie -----/
+ */
+typedef
+ enum ThreadStatus {
+ VgTs_Empty, /* this slot is not in use */
+ VgTs_Init, /* just allocated */
+ VgTs_Runnable, /* ready to run */
+ VgTs_WaitSys, /* waiting for a syscall to complete */
+ VgTs_Yielding, /* temporarily yielding the CPU */
+ VgTs_Zombie, /* transient state just before exiting */
+ }
+ ThreadStatus;
+
+/* Return codes from the scheduler. */
+typedef
+ enum {
+ VgSrc_None, /* not exiting yet */
+ VgSrc_ExitSyscall, /* client called exit(). This is the normal
+ route out. */
+ VgSrc_FatalSig /* Killed by the default action of a fatal
+ signal */
+ }
+ VgSchedReturnCode;
+
+
+#if defined(VGA_x86)
+ typedef VexGuestX86State VexGuestArchState;
+#elif defined(VGA_amd64)
+ typedef VexGuestAMD64State VexGuestArchState;
+#elif defined(VGA_arm)
+ typedef VexGuestARMState VexGuestArchState;
+#else
+# error Unknown architecture
+#endif
+
+
+typedef
+ struct {
+ /* --- BEGIN vex-mandated guest state --- */
+
+ /* Saved machine context. */
+ VexGuestArchState vex;
+
+ /* Saved shadow context. */
+ VexGuestArchState vex_shadow;
+
+ /* Spill area. */
+ UChar vex_spill[LibVEX_N_SPILL_BYTES];
+
+ /* --- END vex-mandated guest state --- */
+ }
+ 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.
+ The thread identity is simply the index in vg_threads[].
+ ThreadId == 1 is the root thread and has the special property
+ that we don't try and allocate or deallocate its stack. For
+ convenience of generating error message, we also put the
+ ThreadId in this tid field, but be aware that it should
+ ALWAYS == the index in vg_threads[]. */
+ ThreadId tid;
+
+ /* Current scheduling status. */
+ ThreadStatus status;
+
+ /* This is set if the thread is in the process of exiting for any
+ reason. The precise details of the exit are in the OS-specific
+ state. */
+ VgSchedReturnCode exitreason;
+
+ /* Architecture-specific thread state. */
+ ThreadArchState arch;
+
+ /* This thread's blocked-signals mask. Semantics is that for a
+ signal to be delivered to this thread, the signal must not be
+ blocked by this signal mask. If more than one thread accepts a
+ signal, then it will be delivered to one at random. If all
+ threads block the signal, it will remain pending until either a
+ thread unblocks it or someone uses sigwaitsig/sigtimedwait. */
+ vki_sigset_t sig_mask;
+
+ /* tmp_sig_mask is usually the same as sig_mask, and is kept in
+ sync whenever sig_mask is changed. The only time they have
+ different values is during the execution of a sigsuspend, where
+ tmp_sig_mask is the temporary mask which sigsuspend installs.
+ It is only consulted to compute the signal mask applied to a
+ signal handler. */
+ vki_sigset_t tmp_sig_mask;
+
+ /* A little signal queue for signals we can't get the kernel to
+ queue for us. This is only allocated as needed, since it should
+ be rare. */
+ struct SigQueue *sig_queue;
+
+ /* Client stacks. When a thread slot is freed, we don't deallocate its
+ stack; we just leave it lying around for the next use of the
+ slot. If the next use of the slot requires a larger stack,
+ only then is the old one deallocated and a new one
+ allocated.
+
+ For the main thread (threadid == 0), this mechanism doesn't
+ apply. We don't know the size of the stack since we didn't
+ allocate it, and furthermore we never reallocate it. */
+
+ /* The allocated size of this thread's stack (permanently zero
+ if this is ThreadId == 0, since we didn't allocate its stack) */
+ SizeT client_stack_szB;
+
+ /* Address of the highest legitimate word in this stack. This is
+ used for error messages only -- not critical for execution
+ correctness. Is is set for all stacks, specifically including
+ ThreadId == 0 (the main thread). */
+ Addr client_stack_highest_word;
+
+ /* Alternate signal stack */
+ vki_stack_t altstack;
+
+ /* OS-specific thread state */
+ os_thread_t os_state;
+
+ /* Used in the syscall handlers. Set to True to indicate that the
+ PRE routine for a syscall has set the syscall result already and
+ so the syscall does not need to be handed to the kernel. */
+ Bool syscall_result_set;
+
+ /* Per-thread jmp_buf to resume scheduler after a signal */
+ Bool sched_jmpbuf_valid;
+ jmp_buf sched_jmpbuf;
+}
+ThreadState;
+
+
+/*------------------------------------------------------------*/
+/*--- The thread table. ---*/
+/*------------------------------------------------------------*/
+
+/* A statically allocated array of threads. NOTE: [0] is
+ never used, to simplify the simulation of initialisers for
+ LinuxThreads. */
+extern ThreadState VG_(threads)[VG_N_THREADS];
+
+// The running thread. m_scheduler should be the only other module
+// to write to this.
+extern ThreadId VG_(running_tid);
+
+/*------------------------------------------------------------*/
+/*--- Basic operations on the thread table. ---*/
+/*------------------------------------------------------------*/
+
+// Convert a ThreadStatus to a string.
+const HChar* VG_(name_of_ThreadStatus) ( ThreadStatus status );
+
+/* Get the ThreadState for a particular thread */
+extern ThreadState *VG_(get_ThreadState) ( ThreadId tid );
+
+/* Check that tid is in range and denotes a non-Empty thread. */
+extern Bool VG_(is_valid_tid) ( ThreadId tid );
+
+/* Returns true if a thread is currently running (ie, has the CPU lock) */
+extern Bool VG_(is_running_thread)(ThreadId tid);
+
+/* Returns true if the thread is in the process of exiting */
+extern Bool VG_(is_exiting)(ThreadId tid);
+
+/* Return the number of non-dead Threads */
+extern Int VG_(count_living_threads)(void);
+
+/* Given an LWP id (ie, real kernel thread id), find the corresponding
+ ThreadId */
+extern ThreadId VG_(get_lwp_tid)(Int lwpid);
+
+#endif // __PUB_CORE_THREADSTATE_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
diff --git a/coregrind/pub_core_tooliface.h b/coregrind/pub_core_tooliface.h
index b779327..341fc29 100644
--- a/coregrind/pub_core_tooliface.h
+++ b/coregrind/pub_core_tooliface.h
@@ -55,7 +55,7 @@
/* These structs are not exposed to tools to mitigate possibility of
binary-incompatibilities when the core/tool interface changes. Instead,
- set functions are provided (see include/tool.h). */
+ set functions are provided (see include/pub_tool_tooliface.h). */
/* ---------------------------------------------------------------------
'Details'
diff --git a/coregrind/stage1.c b/coregrind/stage1.c
index 45a1999..fc61276 100644
--- a/coregrind/stage1.c
+++ b/coregrind/stage1.c
@@ -41,12 +41,12 @@
#include <sys/resource.h>
#include <unistd.h>
-#include "core.h"
-#include "ume.h"
#include "memcheck/memcheck.h"
+#include "pub_core_basics.h"
#include "pub_core_debuglog.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcproc.h"
+#include "ume.h"
static int stack[SIGSTKSZ*4];
diff --git a/coregrind/ume.c b/coregrind/ume.c
index 983dfe8..032dcf2 100644
--- a/coregrind/ume.c
+++ b/coregrind/ume.c
@@ -33,8 +33,6 @@
#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
-#include "core.h"
-
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
@@ -44,9 +42,10 @@
#include <unistd.h>
#include <assert.h>
-#include "ume.h"
+#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_machine.h"
+#include "ume.h"
#if ELFSZ == 64
#define ESZ(x) Elf64_##x
diff --git a/coregrind/ume.h b/coregrind/ume.h
index a2679c7..beb4d99 100644
--- a/coregrind/ume.h
+++ b/coregrind/ume.h
@@ -35,8 +35,6 @@
#include <elf.h>
#include <sys/types.h>
-#include "basic_types.h"
-
/*------------------------------------------------------------*/
/*--- General stuff ---*/
/*------------------------------------------------------------*/
diff --git a/coregrind/vg_preloaded.c b/coregrind/vg_preloaded.c
index 11c1507..d76267c 100644
--- a/coregrind/vg_preloaded.c
+++ b/coregrind/vg_preloaded.c
@@ -45,7 +45,7 @@
#include "valgrind.h"
#include "coregrind.h"
-#include "core.h"
+#include "pub_core_basics.h"
#include "pub_core_debuginfo.h" // needed for pub_core_redir.h :(
#include "pub_core_redir.h"