Create a new module, m_vki, and move all knowledge about the kernel
interface, except for the syscall numbers, into that.  Mostly this
means moving include/vki-*.h to include/vki/vki-*.h.

include/pub_tool_basics.h previously dragged in the entire kernel
interface.  I've done away with that, so that modules which need to
see the kernel interface now have to include pub_{core,tool}_vki.h
explicitly.  This is why there are many modified .c files -- they have
all acquired an extra #include line.

This certainly breaks all platforms except x86.  Will fix shortly.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6225 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/auxprogs/valgrind-listener.c b/auxprogs/valgrind-listener.c
index 4bd3edc..133cff1 100644
--- a/auxprogs/valgrind-listener.c
+++ b/auxprogs/valgrind-listener.c
@@ -46,6 +46,8 @@
 
 #include "pub_core_basics.h"
 #include "pub_core_libcassert.h"    // For VG_BUGS_TO
+#include "pub_core_vki.h"           // Avoids warnings from 
+                                    // pub_core_libcfile.h
 #include "pub_core_libcfile.h"      // For VG_CLO_DEFAULT_LOGPORT
 
 
diff --git a/cachegrind/cg_main.c b/cachegrind/cg_main.c
index 6d68387..92c3c7c 100644
--- a/cachegrind/cg_main.c
+++ b/cachegrind/cg_main.c
@@ -30,6 +30,7 @@
 */
 
 #include "pub_tool_basics.h"
+#include "pub_tool_vki.h"
 #include "pub_tool_debuginfo.h"
 #include "pub_tool_libcbase.h"
 #include "pub_tool_libcassert.h"
diff --git a/callgrind/global.h b/callgrind/global.h
index 335de14..96d3f25 100644
--- a/callgrind/global.h
+++ b/callgrind/global.h
@@ -8,6 +8,7 @@
 #define CLG_GLOBAL
 
 #include "pub_tool_basics.h"
+#include "pub_tool_vki.h"
 #include "pub_tool_debuginfo.h"
 #include "pub_tool_libcbase.h"
 #include "pub_tool_libcassert.h"
diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am
index 8d216b3..b2b0bf5 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -108,6 +108,7 @@
 	pub_core_transtab.h	\
 	pub_core_transtab_asm.h	\
 	pub_core_ume.h		\
+	pub_core_vki.h		\
 	pub_core_vkiscnums.h	\
 	m_coredump/priv_elf.h	\
 	m_debuginfo/priv_storage.h	\
@@ -162,6 +163,7 @@
 	m_translate.c \
 	m_transtab.c \
 	m_ume.c \
+	m_vki.c \
 	m_vkiscnums.c \
 	m_aspacemgr/aspacemgr.c \
 	m_debuginfo/storage.c \
diff --git a/coregrind/launcher.c b/coregrind/launcher.c
index 30ed02d..ab24345 100644
--- a/coregrind/launcher.c
+++ b/coregrind/launcher.c
@@ -46,6 +46,8 @@
 #include <unistd.h>
 
 #include "pub_core_debuglog.h"
+#include "pub_core_vki.h"       // Avoids warnings from
+                                // pub_core_libcfile.h
 #include "pub_core_libcproc.h"  // For VALGRIND_LIB, VALGRIND_LAUNCHER
 #include "pub_core_ume.h"
 
diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c
index 0e857cd..28c8a46 100644
--- a/coregrind/m_aspacemgr/aspacemgr.c
+++ b/coregrind/m_aspacemgr/aspacemgr.c
@@ -35,6 +35,7 @@
    minimal set of imports. */
 
 #include "pub_core_basics.h"     // types
+#include "pub_core_vki.h"
 
 #include "pub_core_debuglog.h"   // VG_(debugLog)
 
diff --git a/coregrind/m_clientstate.c b/coregrind/m_clientstate.c
index 2db9299..fd16cff 100644
--- a/coregrind/m_clientstate.c
+++ b/coregrind/m_clientstate.c
@@ -31,6 +31,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_clientstate.h"
 
 /*-----------------------------------------------------------------*/
diff --git a/coregrind/m_commandline.c b/coregrind/m_commandline.c
index c4637f3..2d1a83f 100644
--- a/coregrind/m_commandline.c
+++ b/coregrind/m_commandline.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_libcfile.h"
diff --git a/coregrind/m_coredump/coredump-elf.c b/coregrind/m_coredump/coredump-elf.c
index 814026b..87fad6f 100644
--- a/coregrind/m_coredump/coredump-elf.c
+++ b/coregrind/m_coredump/coredump-elf.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_machine.h"
diff --git a/coregrind/m_coredump/coredump-x86-linux.c b/coregrind/m_coredump/coredump-x86-linux.c
index 754df98..ed2f95f 100644
--- a/coregrind/m_coredump/coredump-x86-linux.c
+++ b/coregrind/m_coredump/coredump-x86-linux.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_coredump.h"
 #include "pub_core_threadstate.h"
diff --git a/coregrind/m_debugger.c b/coregrind/m_debugger.c
index 7122be8..ae30646 100644
--- a/coregrind/m_debugger.c
+++ b/coregrind/m_debugger.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_clientstate.h"
 #include "pub_core_debugger.h"
diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c
index d4d34f1..23256ac 100644
--- a/coregrind/m_debuginfo/debuginfo.c
+++ b/coregrind/m_debuginfo/debuginfo.c
@@ -35,6 +35,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_debuginfo.h"   /* self */
 #include "pub_core_demangle.h"
diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
index e3318e6..49c0c1a 100644
--- a/coregrind/m_debuginfo/readelf.c
+++ b/coregrind/m_debuginfo/readelf.c
@@ -35,6 +35,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_libcassert.h"
diff --git a/coregrind/m_errormgr.c b/coregrind/m_errormgr.c
index 2fb30f4..cb71883 100644
--- a/coregrind/m_errormgr.c
+++ b/coregrind/m_errormgr.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"      // For VG_N_THREADS
 #include "pub_core_debugger.h"
 #include "pub_core_debuginfo.h"
diff --git a/coregrind/m_libcassert.c b/coregrind/m_libcassert.c
index 5e4c5ed..1f50fed 100644
--- a/coregrind/m_libcassert.c
+++ b/coregrind/m_libcassert.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c
index ec455841..37bdb07 100644
--- a/coregrind/m_libcfile.c
+++ b/coregrind/m_libcfile.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcfile.h"
diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c
index 118cad1..e425590 100644
--- a/coregrind/m_libcprint.c
+++ b/coregrind/m_libcprint.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.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 16efd4d..b3d1747 100644
--- a/coregrind/m_libcproc.c
+++ b/coregrind/m_libcproc.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.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 39c81cd..9e11ed0 100644
--- a/coregrind/m_libcsignal.c
+++ b/coregrind/m_libcsignal.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.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 f0d6630..357fbdb 100644
--- a/coregrind/m_machine.c
+++ b/coregrind/m_machine.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcbase.h"
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index 4bb7eea..207c4ed 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_clientstate.h"
 #include "pub_core_aspacemgr.h"
diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c
index f607eeb..d1bd9d1 100644
--- a/coregrind/m_mallocfree.c
+++ b/coregrind/m_mallocfree.c
@@ -30,6 +30,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_debuglog.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_aspacemgr.h"
diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c
index 4d1783c..6d6800a 100644
--- a/coregrind/m_replacemalloc/vg_replace_malloc.c
+++ b/coregrind/m_replacemalloc/vg_replace_malloc.c
@@ -45,6 +45,7 @@
    ------------------------------------------------------------------ */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"           // VKI_EINVAL, VKI_ENOMEM, VKI_PAGE_SIZE
 #include "pub_core_clreq.h"         // for VALGRIND_INTERNAL_PRINTF,
                                     //   VALGRIND_NON_SIMD_CALL[12]
 #include "pub_core_debuginfo.h"     // needed for pub_core_redir.h :(
diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c
index c2f4333..6788b29 100644
--- a/coregrind/m_scheduler/scheduler.c
+++ b/coregrind/m_scheduler/scheduler.c
@@ -58,6 +58,8 @@
  */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
+#include "pub_core_vkiscnums.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_clreq.h"         // for VG_USERREQ__*
@@ -81,7 +83,6 @@
 #include "pub_core_tooliface.h"
 #include "pub_core_translate.h"     // For VG_(translate)()
 #include "pub_core_transtab.h"
-#include "pub_core_vkiscnums.h"
 #include "priv_sema.h"
 
 /* #include "pub_core_debuginfo.h" */   // DEBUGGING HACK ONLY
diff --git a/coregrind/m_scheduler/sema.c b/coregrind/m_scheduler/sema.c
index a50e0d0..bc9fc69 100644
--- a/coregrind/m_scheduler/sema.c
+++ b/coregrind/m_scheduler/sema.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcfile.h"
 #include "pub_core_libcproc.h"      // For VG_(gettid)()
diff --git a/coregrind/m_sigframe/sigframe-x86-linux.c b/coregrind/m_sigframe/sigframe-x86-linux.c
index a6a50d1..6f90460 100644
--- a/coregrind/m_sigframe/sigframe-x86-linux.c
+++ b/coregrind/m_sigframe/sigframe-x86-linux.c
@@ -30,6 +30,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_aspacemgr.h" /* find_segment */
 #include "pub_core_libcbase.h"
diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c
index 3ca1398..5aabb68 100644
--- a/coregrind/m_signals.c
+++ b/coregrind/m_signals.c
@@ -80,6 +80,7 @@
  */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_debuglog.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_clientstate.h"
diff --git a/coregrind/m_stacktrace.c b/coregrind/m_stacktrace.c
index c502a3f..d7d9d16 100644
--- a/coregrind/m_stacktrace.c
+++ b/coregrind/m_stacktrace.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_debuginfo.h"
 #include "pub_core_aspacemgr.h"     // For VG_(is_addressable)()
diff --git a/coregrind/m_syscall.c b/coregrind/m_syscall.c
index 2514069..721dafa 100644
--- a/coregrind/m_syscall.c
+++ b/coregrind/m_syscall.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_syscall.h"
 
 /* ---------------------------------------------------------------------
diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c
index 3812e19..19a694e 100644
--- a/coregrind/m_syswrap/syswrap-generic.c
+++ b/coregrind/m_syswrap/syswrap-generic.c
@@ -29,6 +29,8 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
+#include "pub_core_vkiscnums.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_debuginfo.h"     // VG_(di_notify_*)
 #include "pub_core_aspacemgr.h"
@@ -55,8 +57,6 @@
 #include "priv_types_n_macros.h"
 #include "priv_syswrap-generic.h"
 
-#include "pub_core_vkiscnums.h"     /* for the __NR_* constants */
-
 
 /* Returns True iff address range is something the client can
    plausibly mess with: all of it is either already belongs to the
diff --git a/coregrind/m_syswrap/syswrap-linux-variants.c b/coregrind/m_syswrap/syswrap-linux-variants.c
index a4cdcca..d805d1f 100644
--- a/coregrind/m_syswrap/syswrap-linux-variants.c
+++ b/coregrind/m_syswrap/syswrap-linux-variants.c
@@ -46,6 +46,7 @@
 
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_debuginfo.h"    // VG_(di_notify_*)
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
index de5e737..cd46345 100644
--- a/coregrind/m_syswrap/syswrap-linux.c
+++ b/coregrind/m_syswrap/syswrap-linux.c
@@ -29,6 +29,8 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
+#include "pub_core_vkiscnums.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_debuginfo.h"    // VG_(di_notify_*)
@@ -53,7 +55,6 @@
 #include "priv_syswrap-generic.h"
 #include "priv_syswrap-linux.h"
 
-#include "pub_core_vkiscnums.h"    /* for the __NR_* constants */
 
 // Run a thread from beginning to end and return the thread's
 // scheduler-return-code.
diff --git a/coregrind/m_syswrap/syswrap-main.c b/coregrind/m_syswrap/syswrap-main.c
index a2fb0ca..cc0da7d 100644
--- a/coregrind/m_syswrap/syswrap-main.c
+++ b/coregrind/m_syswrap/syswrap-main.c
@@ -30,6 +30,8 @@
 
 #include "libvex_guest_offsets.h"
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
+#include "pub_core_basics.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c
index a782af1..26a0d9b 100644
--- a/coregrind/m_syswrap/syswrap-x86-linux.c
+++ b/coregrind/m_syswrap/syswrap-x86-linux.c
@@ -34,6 +34,8 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
+#include "pub_core_vkiscnums.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_debuginfo.h"     // VG_(di_notify_mmap)
 #include "pub_core_aspacemgr.h"
@@ -58,8 +60,6 @@
 #include "priv_syswrap-linux-variants.h" /* decls of linux variant wrappers */
 #include "priv_syswrap-main.h"
 
-#include "pub_core_vkiscnums.h"      /* for the __NR_* constants */
-
 
 /* ---------------------------------------------------------------------
    clone() handling
diff --git a/coregrind/m_threadmodel.c b/coregrind/m_threadmodel.c
index 6e3c64f..e7d3a09 100644
--- a/coregrind/m_threadmodel.c
+++ b/coregrind/m_threadmodel.c
@@ -61,6 +61,7 @@
  */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_errormgr.h"
 #include "pub_core_execontext.h"
 #include "pub_core_libcassert.h"
diff --git a/coregrind/m_threadstate.c b/coregrind/m_threadstate.c
index a5d0891..1c4633e 100644
--- a/coregrind/m_threadstate.c
+++ b/coregrind/m_threadstate.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_threadstate.h"
 #include "pub_core_libcassert.h"
 
diff --git a/coregrind/m_translate.c b/coregrind/m_translate.c
index baf2541..63dbb20 100644
--- a/coregrind/m_translate.c
+++ b/coregrind/m_translate.c
@@ -30,6 +30,7 @@
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_aspacemgr.h"
 
 #include "pub_core_machine.h"    // VG_(fnptr_to_fnentry)
diff --git a/coregrind/m_ume.c b/coregrind/m_ume.c
index 4ff5953..8151267 100644
--- a/coregrind/m_ume.c
+++ b/coregrind/m_ume.c
@@ -38,6 +38,7 @@
 // included ahead of the glibc ones.  This fix is a kludge;  the right
 // solution is to entirely remove the glibc dependency.
 #include "pub_core_basics.h"
+#include "pub_core_vki.h"
 #include "pub_core_aspacemgr.h"   // various mapping fns
 #include "pub_core_debuglog.h"
 #include "pub_core_libcbase.h"
diff --git a/coregrind/m_vki.c b/coregrind/m_vki.c
new file mode 100644
index 0000000..7cd88e7
--- /dev/null
+++ b/coregrind/m_vki.c
@@ -0,0 +1,43 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Notional "implementation" for m_vki.                         ---*/
+/*---                                                      m_vki.c ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2006-2006 OpenWorks LLP
+      info@open-works.co.uk
+
+   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_vki.h"     /* self */
+
+/* We have pub_{core,tool}_vki.h.  This is the matching implementation
+   for that interface.  In fact there is no implementation, as the
+   sole purpose of the module is to export types and constants
+   describing the kernel interface, so this file is empty. */
+
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                  m_vki.c ---*/
+/*--------------------------------------------------------------------*/
diff --git a/coregrind/pub_core_vki.h b/coregrind/pub_core_vki.h
new file mode 100644
index 0000000..38999bb
--- /dev/null
+++ b/coregrind/pub_core_vki.h
@@ -0,0 +1,50 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Top level for kernel interface declarations.                 ---*/
+/*---                                               pub_core_vki.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2006 Julian Seward
+      jseward@acm.org
+   Copyright (C) 2005-2006 Nicholas Nethercote
+      njn@valgrind.org
+   Copyright (C) 2006-2006 OpenWorks LLP
+      info@open-works.co.uk
+
+   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_VKI_H
+#define __PUB_CORE_VKI_H
+
+/* Most unfortunately, all the kernel decls are visible to tools.  Not
+   really necessary, but to avoid this would require some tedious
+   refactoring of the sources.  Anyway, we live with this kludge, and
+   that means the only thing to be done here is ... */
+
+#include "pub_tool_vki.h"
+
+#endif // __PUB_CORE_VKI_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c
index 897b2ad..9c3a3fa 100644
--- a/helgrind/hg_main.c
+++ b/helgrind/hg_main.c
@@ -43,6 +43,7 @@
 // fundamentals in each case.
 
 #include "pub_tool_basics.h"
+#include "pub_tool_vki.h"
 #include "pub_tool_threadstate.h"
 #include "pub_tool_aspacemgr.h"
 #include "pub_tool_debuginfo.h"
diff --git a/include/Makefile.am b/include/Makefile.am
index 0331635..eaa615e 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -30,11 +30,16 @@
 	pub_tool_tooliface.h 		\
 	pub_tool_vkiscnums.h		\
 	valgrind.h 			\
-	vki-linux.h			\
-	vki-amd64-linux.h		\
-	vki-ppc32-linux.h		\
-	vki-ppc64-linux.h		\
-	vki-x86-linux.h			\
+	vki/vki-linux.h			\
+	vki/vki-amd64-linux.h		\
+	vki/vki-ppc32-linux.h		\
+	vki/vki-ppc64-linux.h		\
+	vki/vki-x86-linux.h			\
+	vki/vki-linux.h				\
+	vki/vki-posixtypes-amd64-linux.h	\
+	vki/vki-posixtypes-ppc32-linux.h	\
+	vki/vki-posixtypes-ppc64-linux.h	\
+	vki/vki-posixtypes-x86-linux.h		\
 	vki/vki-scnums-amd64-linux.h		\
 	vki/vki-scnums-ppc32-linux.h		\
 	vki/vki-scnums-ppc64-linux.h		\
diff --git a/include/pub_tool_basics.h b/include/pub_tool_basics.h
index 0e8ab27..3b4b8ea 100644
--- a/include/pub_tool_basics.h
+++ b/include/pub_tool_basics.h
@@ -52,13 +52,6 @@
 // For varargs types
 #include <stdarg.h>
 
-// Kernel types.  Might as well have them here, they're used so broadly
-// (eg. in pub_core_threadstate.h).
-#if defined(VGO_linux)
-#  include "vki-linux.h"
-#else
-#  error Unknown OS
-#endif
 
 /* ---------------------------------------------------------------------
    builtin types
diff --git a/include/pub_tool_vki.h b/include/pub_tool_vki.h
new file mode 100644
index 0000000..25573fb
--- /dev/null
+++ b/include/pub_tool_vki.h
@@ -0,0 +1,62 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Top level for kernel interface declarations.                 ---*/
+/*---                                               pub_tool_vki.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2006 Julian Seward
+      jseward@acm.org
+   Copyright (C) 2005-2006 Nicholas Nethercote
+      njn@valgrind.org
+   Copyright (C) 2006-2006 OpenWorks LLP
+      info@open-works.co.uk
+
+   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.
+*/
+
+/* This file defines types and constants for the kernel interface, and to
+   make that clear everything is prefixed VKI_/vki_.
+
+   This file is merely a top-level "steering" file, which pulls in the
+   correct bits for the relevant platform.  You should not directly
+   #include any file in include/vki; instead #include only this one or
+   pub_core_vki.h.
+*/
+
+#ifndef __PUB_TOOL_VKI_H
+#define __PUB_TOOL_VKI_H
+
+#if defined(VGO_linux)
+#  include "vki/vki-linux.h"
+#elif defined(VGP_ppc32_aix5)
+#  include "vki/vki-ppc32-aix5.h"
+#elif defined(VGP_ppc64_aix5)
+#  include "vki/vki-ppc64-aix5.h"
+#else
+#  error Unknown Plat/OS
+#endif
+
+#endif // __PUB_TOOL_VKI_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                           pub_tool_vki.h ---*/
+/*--------------------------------------------------------------------*/
diff --git a/include/vki-amd64-linux.h b/include/vki/vki-amd64-linux.h
similarity index 100%
rename from include/vki-amd64-linux.h
rename to include/vki/vki-amd64-linux.h
diff --git a/include/vki-linux.h b/include/vki/vki-linux.h
similarity index 98%
rename from include/vki-linux.h
rename to include/vki/vki-linux.h
index 7066709..007ff20 100644
--- a/include/vki-linux.h
+++ b/include/vki/vki-linux.h
@@ -57,6 +57,21 @@
    definitions, which affects some of them.
 */
 
+/* The structure is (aiui, jrs 20060504):
+
+     #include plat-specific posix types (vki-posixtypes-ARCH-linux.h)
+
+     Lots more types, structs, consts, in this file
+
+     #include other plat-specific stuff (vki-ARCH-linux.h)
+
+     Even more types, structs, consts, in this file
+
+   The system call numbers are dealt with by
+   pub_{core,tool}_vkiscnums.h, not via pub_{core,tool}_vki.h, which
+   is what this file is part of.
+*/
+
 #ifndef __VKI_LINUX_H
 #define __VKI_LINUX_H
 
@@ -65,13 +80,13 @@
 //----------------------------------------------------------------------
 
 #if defined(VGA_x86)
-#  include "vki_posixtypes-x86-linux.h"
+#  include "vki-posixtypes-x86-linux.h"
 #elif defined(VGA_amd64)
-#  include "vki_posixtypes-amd64-linux.h"
+#  include "vki-posixtypes-amd64-linux.h"
 #elif defined(VGA_ppc32)
-#  include "vki_posixtypes-ppc32-linux.h"
+#  include "vki-posixtypes-ppc32-linux.h"
 #elif defined(VGA_ppc64)
-#  include "vki_posixtypes-ppc64-linux.h"
+#  include "vki-posixtypes-ppc64-linux.h"
 #else
 #  error Unknown platform
 #endif
@@ -2121,8 +2136,6 @@
 	int reserved[9];
 };
 
-#endif // __VKI_LINUX_H
-
 //----------------------------------------------------------------------
 // From linux-2.6.16/include/linux/vt.h
 //----------------------------------------------------------------------
@@ -2172,6 +2185,8 @@
 #define VKI_VT_LOCKSWITCH   0x560B  /* disallow vt switching */
 #define VKI_VT_UNLOCKSWITCH 0x560C  /* allow vt switching */
 
+#endif // __VKI_LINUX_H
+
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/
diff --git a/include/vki_posixtypes-amd64-linux.h b/include/vki/vki-posixtypes-amd64-linux.h
similarity index 97%
rename from include/vki_posixtypes-amd64-linux.h
rename to include/vki/vki-posixtypes-amd64-linux.h
index 6a0ab3f..0c7bf61 100644
--- a/include/vki_posixtypes-amd64-linux.h
+++ b/include/vki/vki-posixtypes-amd64-linux.h
@@ -1,7 +1,7 @@
 
 /*--------------------------------------------------------------------*/
 /*--- AMD64/Linux-specific kernel interface: posix types.          ---*/
-/*---                                 vki_posixtypes-amd64-linux.h ---*/
+/*---                                 vki-posixtypes-amd64-linux.h ---*/
 /*--------------------------------------------------------------------*/
 
 /*
diff --git a/include/vki_posixtypes-ppc32-linux.h b/include/vki/vki-posixtypes-ppc32-linux.h
similarity index 92%
rename from include/vki_posixtypes-ppc32-linux.h
rename to include/vki/vki-posixtypes-ppc32-linux.h
index a4117ea..59da110 100644
--- a/include/vki_posixtypes-ppc32-linux.h
+++ b/include/vki/vki-posixtypes-ppc32-linux.h
@@ -1,7 +1,7 @@
 
 /*--------------------------------------------------------------------*/
 /*--- PPC32/Linux-specific kernel interface: posix types.          ---*/
-/*---                                 vki_posixtypes-ppc32-linux.h ---*/
+/*---                                 vki-posixtypes-ppc32-linux.h ---*/
 /*--------------------------------------------------------------------*/
 
 /*
@@ -29,8 +29,8 @@
    The GNU General Public License is contained in the file COPYING.
 */
 
-#ifndef __PPC32_LINUX_VKI_ARCH_POSIXTYPES_H
-#define __PPC32_LINUX_VKI_ARCH_POSIXTYPES_H
+#ifndef __VKI_POSIXTYPES_PPC32_LINUX_H
+#define __VKI_POSIXTYPES_PPC32_LINUX_H
 
 //----------------------------------------------------------------------
 // From linux-2.6.9/include/asm-ppc/posix_types.h
@@ -61,7 +61,7 @@
    int val[2];
 } __vki_kernel_fsid_t;
 
-#endif // __PPC32_LINUX_VKI_ARCH_POSIXTYPES_H
+#endif // __VKI_POSIXTYPES_PPC32_LINUX_H
 
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
diff --git a/include/vki_posixtypes-ppc64-linux.h b/include/vki/vki-posixtypes-ppc64-linux.h
similarity index 93%
rename from include/vki_posixtypes-ppc64-linux.h
rename to include/vki/vki-posixtypes-ppc64-linux.h
index d9d38cb..a4c5a0d 100644
--- a/include/vki_posixtypes-ppc64-linux.h
+++ b/include/vki/vki-posixtypes-ppc64-linux.h
@@ -1,7 +1,7 @@
 
 /*--------------------------------------------------------------------*/
 /*--- PPC64/Linux-specific kernel interface: posix types.          ---*/
-/*---                                 vki_posixtypes-ppc64-linux.h ---*/
+/*---                                 vki-posixtypes-ppc64-linux.h ---*/
 /*--------------------------------------------------------------------*/
 
 /*
@@ -29,8 +29,8 @@
    The GNU General Public License is contained in the file COPYING.
 */
 
-#ifndef __PPC64_LINUX_VKI_ARCH_POSIXTYPES_H
-#define __PPC64_LINUX_VKI_ARCH_POSIXTYPES_H
+#ifndef __VKI_POSIXTYPES_PPC64_LINUX_H
+#define __VKI_POSIXTYPES_PPC64_LINUX_H
 
 //----------------------------------------------------------------------
 // From linux-2.6.13/include/asm-ppc64/posix_types.h
@@ -68,7 +68,7 @@
   int     val[2];
 } __vki_kernel_fsid_t;
 
-#endif // __PPC64_LINUX_VKI_ARCH_POSIXTYPES_H
+#endif // __VKI_POSIXTYPES_PPC64_LINUX_H
 
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
diff --git a/include/vki_posixtypes-x86-linux.h b/include/vki/vki-posixtypes-x86-linux.h
similarity index 97%
rename from include/vki_posixtypes-x86-linux.h
rename to include/vki/vki-posixtypes-x86-linux.h
index 6d0e551..23f9831 100644
--- a/include/vki_posixtypes-x86-linux.h
+++ b/include/vki/vki-posixtypes-x86-linux.h
@@ -1,7 +1,7 @@
 
 /*--------------------------------------------------------------------*/
 /*--- x86/Linux-specific kernel interface: posix types.            ---*/
-/*---                                   vki_posixtypes-x86-linux.h ---*/
+/*---                                   vki-posixtypes-x86-linux.h ---*/
 /*--------------------------------------------------------------------*/
 
 /*
diff --git a/include/vki-ppc32-linux.h b/include/vki/vki-ppc32-linux.h
similarity index 99%
rename from include/vki-ppc32-linux.h
rename to include/vki/vki-ppc32-linux.h
index 8e9afa4..827e132 100644
--- a/include/vki-ppc32-linux.h
+++ b/include/vki/vki-ppc32-linux.h
@@ -7,7 +7,7 @@
    This file is part of Valgrind, a dynamic binary instrumentation
    framework.
 
-   Copyright (C) 2005 Julian Seward
+   Copyright (C) 2005-2006 Julian Seward
       jseward@acm.org
 
    This program is free software; you can redistribute it and/or
@@ -28,8 +28,8 @@
    The GNU General Public License is contained in the file COPYING.
 */
 
-#ifndef __PPC32_LINUX_VKI_ARCH_H
-#define __PPC32_LINUX_VKI_ARCH_H
+#ifndef __VKI_PPC32_LINUX_H
+#define __VKI_PPC32_LINUX_H
 
 // ppc32 is big-endian.
 #define VKI_BIG_ENDIAN  1
@@ -912,7 +912,7 @@
 // And that's it!
 //----------------------------------------------------------------------
 
-#endif // __PPC32_LINUX_VKI_ARCH_H
+#endif // __VKI_PPC32_LINUX_H
 
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
diff --git a/include/vki-ppc64-linux.h b/include/vki/vki-ppc64-linux.h
similarity index 99%
rename from include/vki-ppc64-linux.h
rename to include/vki/vki-ppc64-linux.h
index afb865e..4f1882b 100644
--- a/include/vki-ppc64-linux.h
+++ b/include/vki/vki-ppc64-linux.h
@@ -7,7 +7,7 @@
    This file is part of Valgrind, a dynamic binary instrumentation
    framework.
 
-   Copyright (C) 2005 Julian Seward
+   Copyright (C) 2005-2006 Julian Seward
       jseward@acm.org
 
    This program is free software; you can redistribute it and/or
@@ -28,8 +28,8 @@
    The GNU General Public License is contained in the file COPYING.
 */
 
-#ifndef __PPC64_LINUX_VKI_ARCH_H
-#define __PPC64_LINUX_VKI_ARCH_H
+#ifndef __VKI_PPC64_LINUX_H
+#define __VKI_PPC64_LINUX_H
 
 // ppc64 is big-endian.
 #define VKI_BIG_ENDIAN  1
@@ -753,7 +753,7 @@
 // end
 //----------------------------------------------------------------------
 
-#endif // __PPC64_LINUX_VKI_ARCH_H
+#endif // __VKI_PPC64_LINUX_H
 
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
diff --git a/include/vki-x86-linux.h b/include/vki/vki-x86-linux.h
similarity index 100%
rename from include/vki-x86-linux.h
rename to include/vki/vki-x86-linux.h
diff --git a/massif/ms_main.c b/massif/ms_main.c
index a130f43..d8de83f 100644
--- a/massif/ms_main.c
+++ b/massif/ms_main.c
@@ -35,6 +35,7 @@
 // structures below for more info on how things work.
 
 #include "pub_tool_basics.h"
+#include "pub_tool_vki.h"
 #include "pub_tool_aspacemgr.h"
 #include "pub_tool_debuginfo.h"
 #include "pub_tool_hashtable.h"
diff --git a/memcheck/mc_leakcheck.c b/memcheck/mc_leakcheck.c
index f194500..d282e62 100644
--- a/memcheck/mc_leakcheck.c
+++ b/memcheck/mc_leakcheck.c
@@ -29,6 +29,7 @@
 */
 
 #include "pub_tool_basics.h"
+#include "pub_tool_vki.h"
 #include "pub_tool_aspacemgr.h"
 #include "pub_tool_execontext.h"
 #include "pub_tool_hashtable.h"