Put all the system call stuff in a new module, m_syscalls. This
required moving a lot of stuff around. I deleted
VG_(set_return_from_syscall_shadow)() and VG_(get_exit_status_shadow)(),
which screwed up the modularity and weren't being used and can be
simulated in other ways with a bit of care.
What are the chances that I've added and moved all the files correctly
in this commit, and not broken the amd64 port?
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3636 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am
index 808a352..43afe6b 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -1,16 +1,22 @@
include $(top_srcdir)/Makefile.all.am
include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
+MODULES = \
+ demangle \
+ m_aspacemgr \
+ m_sigframe \
+ m_syscalls
+
## When building, we are only interested in the current arch/OS/platform.
## But when doing 'make dist', we are interested in every arch/OS/platform.
## That's what DIST_SUBDIRS specifies.
SUBDIRS = \
- $(VG_ARCH) $(VG_OS) $(VG_PLATFORM) \
- m_sigframe m_aspacemgr demangle .
+ $(VG_ARCH) $(VG_OS) $(VG_PLATFORM) \
+ $(MODULES) .
DIST_SUBDIRS = \
$(VG_ARCH_ALL) $(VG_OS_ALL) $(VG_PLATFORM_ALL) \
- m_sigframe m_aspacemgr demangle .
+ $(MODULES) .
AM_CPPFLAGS += -DVG_LIBDIR="\"$(valdir)"\" -I$(srcdir)/demangle \
-DKICKSTART_BASE=@KICKSTART_BASE@
@@ -32,12 +38,13 @@
noinst_HEADERS = \
core.h \
core_asm.h \
+ pub_core_aspacemgr.h \
+ pub_core_debuglog.h \
pub_core_errormgr.h \
pub_core_execontext.h \
- pub_core_stacktrace.h \
pub_core_sigframe.h \
- pub_core_debuglog.h \
- pub_core_aspacemgr.h \
+ pub_core_stacktrace.h \
+ pub_core_syscalls.h \
ume.h \
vg_symtab2.h \
vg_symtypes.h \
@@ -87,7 +94,6 @@
vg_stabs.c \
vg_skiplist.c \
vg_symtypes.c \
- vg_syscalls.c \
vg_toolint.c \
vg_translate.c \
vg_transtab.c
@@ -95,8 +101,9 @@
## libplatform.a must be before libarch.a and libos.a, it seems.
stage2_extra= \
demangle/libdemangle.a \
- m_sigframe/libsigframe.a \
m_aspacemgr/libaspacemgr.a \
+ m_sigframe/libsigframe.a \
+ m_syscalls/libsyscalls.a \
${VG_PLATFORM}/libplatform.a \
${VG_ARCH}/libarch.a \
${VG_OS}/libos.a \
diff --git a/coregrind/amd64-linux/Makefile.am b/coregrind/amd64-linux/Makefile.am
index 64e1ded..d7d46e0 100644
--- a/coregrind/amd64-linux/Makefile.am
+++ b/coregrind/amd64-linux/Makefile.am
@@ -12,9 +12,7 @@
libplatform_a_SOURCES = \
core_platform.c \
- ldt.c \
- syscall.S \
- syscalls.c
+ ldt.c
if USE_PIE
libplatform_a_CFLAGS = $(AM_CFLAGS) -fpie
diff --git a/coregrind/amd64-linux/core_platform.h b/coregrind/amd64-linux/core_platform.h
index 1ac9f43..ddf203c 100644
--- a/coregrind/amd64-linux/core_platform.h
+++ b/coregrind/amd64-linux/core_platform.h
@@ -36,27 +36,6 @@
//#include "platform_arch.h" // platform-specific tool stuff
/* ---------------------------------------------------------------------
- Dealing with registers
- ------------------------------------------------------------------ */
-
-// Accessors for the ThreadArchState
-#define VGP_SYSCALL_NUM guest_RAX
-#define VGP_SYSCALL_ARG1 guest_RDI
-#define VGP_SYSCALL_ARG2 guest_RSI
-#define VGP_SYSCALL_ARG3 guest_RDX
-#define VGP_SYSCALL_ARG4 guest_R10
-#define VGP_SYSCALL_ARG5 guest_R8
-#define VGP_SYSCALL_ARG6 guest_R9
-#define VGP_SYSCALL_RET guest_RAX
-
-// Setting a syscall result
-#define VGP_SET_SYSCALL_RESULT(regs, val) ((regs).vex.guest_RAX = (val))
-
-// For informing tools that a syscall result has been set.
-#define VGP_TRACK_SYSCALL_RETVAL(zztid) \
- VG_TRACK( post_reg_write, Vg_CoreSysCall, zztid, O_SYSCALL_RET, sizeof(UWord) );
-
-/* ---------------------------------------------------------------------
Exports of vg_ldt.c
------------------------------------------------------------------ */
diff --git a/coregrind/arm-linux/Makefile.am b/coregrind/arm-linux/Makefile.am
index c16c329..0e434f3 100644
--- a/coregrind/arm-linux/Makefile.am
+++ b/coregrind/arm-linux/Makefile.am
@@ -9,9 +9,7 @@
noinst_LIBRARIES = libplatform.a
-libplatform_a_SOURCES = \
- syscall.S \
- syscalls.c
+libplatform_a_SOURCES =
if USE_PIE
libplatform_a_CFLAGS = $(AM_CFLAGS) -fpie
diff --git a/coregrind/arm-linux/core_platform.h b/coregrind/arm-linux/core_platform.h
index db441aa..7aba3d1 100644
--- a/coregrind/arm-linux/core_platform.h
+++ b/coregrind/arm-linux/core_platform.h
@@ -36,28 +36,6 @@
//#include "platform_arch.h" // platform-specific tool stuff
/* ---------------------------------------------------------------------
- Dealing with registers
- ------------------------------------------------------------------ */
-
-// Accessors for the ThreadArchState
-#define VGP_SYSCALL_NUM guest_SYSCALLNO
-#define VGP_SYSCALL_ARG1 guest_R0
-#define VGP_SYSCALL_ARG2 guest_R1
-#define VGP_SYSCALL_ARG3 guest_R2
-#define VGP_SYSCALL_ARG4 guest_R3
-#define VGP_SYSCALL_ARG5 guest_R4
-#define VGP_SYSCALL_ARG6 guest_R5
-#define VGP_SYSCALL_RET guest_R0 // ToDo XXX ????????
-
-// ToDo XXX ????????
-#define VGP_SET_SYSCALL_RESULT(regs, val) ((regs).vex.guest_R0 = (val))
-
-// For informing tools that a syscall result has been set.
-// XXX ToDo: not sure about this
-#define VGP_TRACK_SYSCALL_RETVAL(zztid) \
- VG_TRACK( post_reg_write, Vg_CoreSysCall, zztid, O_SYSCALL_RET, sizeof(UWord) );
-
-/* ---------------------------------------------------------------------
ucontext stuff
------------------------------------------------------------------ */
diff --git a/coregrind/core.h b/coregrind/core.h
index d9f7025..566cc46 100644
--- a/coregrind/core.h
+++ b/coregrind/core.h
@@ -34,6 +34,10 @@
#define __CORE_H
/*
+ [This comment is not longer accurate -- we're switching to an easier to
+ understand module-based approach, with one or two headers per module,
+ rather than having monolithic headers as described. --njn 07-May-2005]
+
Header hierarchy:
- core C files include core.h
@@ -822,6 +826,7 @@
extern void VG_(env_remove_valgrind_env_stuff) ( Char** env );
extern void VG_(nanosleep)(struct vki_timespec *);
+
/* ---------------------------------------------------------------------
Exports of vg_message.c
------------------------------------------------------------------ */
@@ -977,440 +982,6 @@
/* ---------------------------------------------------------------------
- Exports of vg_syscalls.c
- ------------------------------------------------------------------ */
-
-extern HChar* VG_(resolve_filename_nodup)(Int fd);
-extern HChar* VG_(resolve_filename)(Int fd);
-
-/* Simple Valgrind-internal atfork mechanism */
-extern void VG_(do_atfork_pre) (ThreadId tid);
-extern void VG_(do_atfork_parent)(ThreadId tid);
-extern void VG_(do_atfork_child) (ThreadId tid);
-
-
-extern void VG_(client_syscall) ( ThreadId tid );
-
-extern void VG_(post_syscall) ( ThreadId tid );
-
-extern Bool VG_(is_kerror) ( Word res );
-
-/* Internal atfork handlers */
-typedef void (*vg_atfork_t)(ThreadId);
-extern void VG_(atfork)(vg_atfork_t pre, vg_atfork_t parent, vg_atfork_t child);
-
-/* fd leakage calls. */
-extern void VG_(init_preopened_fds) ( void );
-extern void VG_(show_open_fds) ( void );
-
-// Return true if address range entirely contained within client
-// address space.
-Bool VG_(valid_client_addr)(Addr start, SizeT size, ThreadId tid,
- const Char *syscallname);
-
-// Return true if we're allowed to use or create this fd.
-Bool VG_(fd_allowed)(Int fd, const Char *syscallname, ThreadId tid, Bool soft);
-
-void VG_(record_fd_open)(ThreadId tid, Int fd, char *pathname);
-
-// Used when killing threads -- we must not kill a thread if it's the thread
-// that would do Valgrind's final cleanup and output.
-Bool VG_(do_sigkill)(Int pid, Int tgid);
-
-// Flags describing syscall wrappers
-#define Special (1 << 0) /* handled specially */
-#define MayBlock (1 << 1) /* may block */
-#define PostOnFail (1 << 2) /* call POST() function on failure */
-#define PadAddr (1 << 3) /* pad+unpad address space around syscall */
-#define Done (1 << 4) /* used if a PRE() did the syscall */
-
-// Templates for generating the PRE and POST macros. For ones that must be
-// publically visible, use an empty 'qual', 'prefix' should start with
-// "vgArch_" or similar, and there should be corresponding global
-// declarations (like the GEN_SYSCALL_WRAPPER ones below). Otherwise, use
-// "static" for 'qual', and "vgArch_" should not be in the 'prefix'.
-#define PRE_TEMPLATE(qual, prefix, name, f) \
- qual UInt prefix##_##name##_flags = f; \
- qual void prefix##_##name##_before(ThreadId tid, ThreadState *tst)
-#define POST_TEMPLATE(qual, prefix, name) \
- qual void prefix##_##name##_after (ThreadId tid, ThreadState *tst)
-
-// This macro is used to write other macros which making writing syscall
-// tables easier.
-#define SYS_WRAPPER_ENTRY_X_(prefix, const, name) \
- [const] = { &prefix##_##name##_flags, \
- prefix##_##name##_before, NULL }
-#define SYS_WRAPPER_ENTRY_XY(prefix, const, name) \
- [const] = { &prefix##_##name##_flags, \
- prefix##_##name##_before, \
- prefix##_##name##_after }
-
-// Macros for adding generic wrappers to a syscall table.
-#define GENX_(const, name) SYS_WRAPPER_ENTRY_X_(vgArch_gen, const, name)
-#define GENXY(const, name) SYS_WRAPPER_ENTRY_XY(vgArch_gen, const, name)
-
-// Space-saving macros for syscall PRE() and POST() wrappers
-#define RES ((tst->arch).vex.VGP_SYSCALL_RET)
-#define SYSNO ((tst->arch).vex.VGP_SYSCALL_NUM)
-#define ARG1 ((tst->arch).vex.VGP_SYSCALL_ARG1)
-#define ARG2 ((tst->arch).vex.VGP_SYSCALL_ARG2)
-#define ARG3 ((tst->arch).vex.VGP_SYSCALL_ARG3)
-#define ARG4 ((tst->arch).vex.VGP_SYSCALL_ARG4)
-#define ARG5 ((tst->arch).vex.VGP_SYSCALL_ARG5)
-#define ARG6 ((tst->arch).vex.VGP_SYSCALL_ARG6)
-
-// For setting the result of a syscall in a wrapper
-#define SET_RESULT(val) \
- do { VGP_SET_SYSCALL_RESULT(tst->arch, (val)); \
- tst->syscall_result_set = True; \
- } while (0)
-
-#define PRINT(format, args...) \
- if (VG_(clo_trace_syscalls)) \
- VG_(printf)(format, ## args)
-
-// Generic (platform-independent) syscall wrappers. These are generally
-// POSIX or something like that; those that are not POSIX are annotated
-// with what standards they are part of, as stated in the Linux man pages.
-// For many of them, it's unclear if they are generic, or Linux-specific, or
-// x86/Linux-specific, or something else again.
-//
-// Nb: This list may change over time... ones thought at first to be generic
-// may turn out not to be, and so be moved into OS-specific or
-// platform-specific files. If there's any doubt, I'm leaving them in here.
-//
-// Nb 2: if porting to a new OS, you should really check all these generic
-// wrappers to make sure they match your OS, painful as it might be.
-//
-// For each generic ("gen") wrapper, we declare the pre-wrapper, the
-// post-wrapper (which is actually not always needed), and the associated
-// flags.
-#define GEN_SYSCALL_WRAPPER(x) \
- extern UInt VGA_(gen_##x##_flags); \
- extern void VGA_(gen_##x##_before)(ThreadId tid, ThreadState *tst); \
- extern void VGA_(gen_##x##_after) (ThreadId tid, ThreadState *tst)
-
-GEN_SYSCALL_WRAPPER(sys_ni_syscall); // * P -- unimplemented
-GEN_SYSCALL_WRAPPER(sys_exit);
-GEN_SYSCALL_WRAPPER(sys_fork);
-GEN_SYSCALL_WRAPPER(sys_read);
-GEN_SYSCALL_WRAPPER(sys_write);
-GEN_SYSCALL_WRAPPER(sys_open);
-GEN_SYSCALL_WRAPPER(sys_close);
-GEN_SYSCALL_WRAPPER(sys_waitpid);
-GEN_SYSCALL_WRAPPER(sys_creat);
-GEN_SYSCALL_WRAPPER(sys_link);
-GEN_SYSCALL_WRAPPER(sys_unlink);
-GEN_SYSCALL_WRAPPER(sys_execve); // (*??) P
-GEN_SYSCALL_WRAPPER(sys_chdir);
-GEN_SYSCALL_WRAPPER(sys_time);
-GEN_SYSCALL_WRAPPER(sys_mknod);
-GEN_SYSCALL_WRAPPER(sys_chmod);
-GEN_SYSCALL_WRAPPER(sys_lseek);
-GEN_SYSCALL_WRAPPER(sys_getpid);
-GEN_SYSCALL_WRAPPER(sys_alarm);
-GEN_SYSCALL_WRAPPER(sys_pause);
-GEN_SYSCALL_WRAPPER(sys_utime);
-GEN_SYSCALL_WRAPPER(sys_access);
-GEN_SYSCALL_WRAPPER(sys_kill);
-GEN_SYSCALL_WRAPPER(sys_rename);
-GEN_SYSCALL_WRAPPER(sys_mkdir);
-GEN_SYSCALL_WRAPPER(sys_rmdir);
-GEN_SYSCALL_WRAPPER(sys_dup);
-GEN_SYSCALL_WRAPPER(sys_times);
-GEN_SYSCALL_WRAPPER(sys_fcntl); // POSIX (but complicated)
-GEN_SYSCALL_WRAPPER(sys_setpgid);
-GEN_SYSCALL_WRAPPER(sys_umask);
-GEN_SYSCALL_WRAPPER(sys_dup2);
-GEN_SYSCALL_WRAPPER(sys_getppid);
-GEN_SYSCALL_WRAPPER(sys_getpgrp);
-GEN_SYSCALL_WRAPPER(sys_setsid);
-GEN_SYSCALL_WRAPPER(sys_munmap);
-GEN_SYSCALL_WRAPPER(sys_truncate);
-GEN_SYSCALL_WRAPPER(sys_ftruncate);
-GEN_SYSCALL_WRAPPER(sys_fchmod);
-GEN_SYSCALL_WRAPPER(sys_msync);
-GEN_SYSCALL_WRAPPER(sys_readv);
-GEN_SYSCALL_WRAPPER(sys_writev);
-GEN_SYSCALL_WRAPPER(sys_getsid);
-GEN_SYSCALL_WRAPPER(sys_fdatasync);
-GEN_SYSCALL_WRAPPER(sys_mlock);
-GEN_SYSCALL_WRAPPER(sys_munlock);
-GEN_SYSCALL_WRAPPER(sys_mlockall);
-GEN_SYSCALL_WRAPPER(sys_munlockall);
-GEN_SYSCALL_WRAPPER(sys_sched_setparam);
-GEN_SYSCALL_WRAPPER(sys_sched_getparam);
-GEN_SYSCALL_WRAPPER(sys_sched_rr_get_interval);
-GEN_SYSCALL_WRAPPER(sys_sched_setscheduler);
-GEN_SYSCALL_WRAPPER(sys_sched_getscheduler);
-GEN_SYSCALL_WRAPPER(sys_sched_yield);
-GEN_SYSCALL_WRAPPER(sys_sched_get_priority_max);
-GEN_SYSCALL_WRAPPER(sys_sched_get_priority_min);
-GEN_SYSCALL_WRAPPER(sys_nanosleep);
-GEN_SYSCALL_WRAPPER(sys_mremap); // POSIX, but Linux arg order may be odd
-GEN_SYSCALL_WRAPPER(sys_getuid);
-GEN_SYSCALL_WRAPPER(sys_getgid);
-GEN_SYSCALL_WRAPPER(sys_geteuid);
-GEN_SYSCALL_WRAPPER(sys_getegid);
-GEN_SYSCALL_WRAPPER(sys_getpgid);
-GEN_SYSCALL_WRAPPER(sys_fsync);
-GEN_SYSCALL_WRAPPER(sys_wait4);
-GEN_SYSCALL_WRAPPER(sys_mprotect);
-GEN_SYSCALL_WRAPPER(sys_sigprocmask);
-GEN_SYSCALL_WRAPPER(sys_timer_create); // Linux: varies across archs?
-GEN_SYSCALL_WRAPPER(sys_timer_settime);
-GEN_SYSCALL_WRAPPER(sys_timer_gettime);
-GEN_SYSCALL_WRAPPER(sys_timer_getoverrun);
-GEN_SYSCALL_WRAPPER(sys_timer_delete);
-GEN_SYSCALL_WRAPPER(sys_clock_settime);
-GEN_SYSCALL_WRAPPER(sys_clock_gettime);
-GEN_SYSCALL_WRAPPER(sys_clock_getres);
-GEN_SYSCALL_WRAPPER(sys_clock_nanosleep);
-GEN_SYSCALL_WRAPPER(sys_getcwd);
-GEN_SYSCALL_WRAPPER(sys_symlink);
-GEN_SYSCALL_WRAPPER(sys_getgroups);
-GEN_SYSCALL_WRAPPER(sys_setgroups); // SVr4, SVID, X/OPEN, 4.3BSD
-GEN_SYSCALL_WRAPPER(sys_chown);
-GEN_SYSCALL_WRAPPER(sys_setuid);
-GEN_SYSCALL_WRAPPER(sys_gettimeofday);
-GEN_SYSCALL_WRAPPER(sys_madvise);
-GEN_SYSCALL_WRAPPER(sys_sigpending);
-
-// These ones aren't POSIX, but are in some standard and look reasonably
-// generic, and are the same for all architectures under Linux.
-GEN_SYSCALL_WRAPPER(sys_nice); // SVr4, SVID EXT, AT&T, X/OPEN, BSD 4.3
-GEN_SYSCALL_WRAPPER(sys_sync); // SVr4, SVID, X/OPEN, BSD 4.3
-GEN_SYSCALL_WRAPPER(sys_brk); // 4.3BSD
-GEN_SYSCALL_WRAPPER(sys_acct); // SVR4, non-POSIX
-GEN_SYSCALL_WRAPPER(sys_chroot); // SVr4, SVID, 4.4BSD, X/OPEN
-GEN_SYSCALL_WRAPPER(sys_readlink); // X/OPEN, 4.4BSD
-GEN_SYSCALL_WRAPPER(sys_fchdir); // SVr4, SVID, POSIX, X/OPEN, 4.4BSD
-GEN_SYSCALL_WRAPPER(sys_getdents); // SVr4,SVID
-GEN_SYSCALL_WRAPPER(sys_select); // 4.4BSD
-GEN_SYSCALL_WRAPPER(sys_flock); // 4.4BSD
-GEN_SYSCALL_WRAPPER(sys_poll); // XPG4-UNIX
-GEN_SYSCALL_WRAPPER(sys_getrusage); // SVr4, 4.3BSD
-GEN_SYSCALL_WRAPPER(sys_stime); // SVr4, SVID, X/OPEN
-GEN_SYSCALL_WRAPPER(sys_settimeofday); // SVr4, 4.3BSD (non-POSIX)
-GEN_SYSCALL_WRAPPER(sys_getpriority); // SVr4, 4.4BSD
-GEN_SYSCALL_WRAPPER(sys_setpriority); // SVr4, 4.4BSD
-GEN_SYSCALL_WRAPPER(sys_setitimer); // SVr4, 4.4BSD
-GEN_SYSCALL_WRAPPER(sys_getitimer); // SVr4, 4.4BSD
-GEN_SYSCALL_WRAPPER(sys_setreuid); // 4.3BSD
-GEN_SYSCALL_WRAPPER(sys_setregid); // 4.3BSD
-GEN_SYSCALL_WRAPPER(sys_fchown); // SVr4,4.3BSD
-GEN_SYSCALL_WRAPPER(sys_setgid); // SVr4,SVID
-GEN_SYSCALL_WRAPPER(sys_utimes); // 4.3BSD
-
-// These ones may be Linux specific... not sure. They use 16-bit gid_t and
-// uid_t types. The similarly named (minus the "16" suffix) ones below use
-// 32-bit versions of these types.
-GEN_SYSCALL_WRAPPER(sys_setuid16); // ## P
-GEN_SYSCALL_WRAPPER(sys_getuid16); // ## P
-GEN_SYSCALL_WRAPPER(sys_setgid16); // ## SVr4,SVID
-GEN_SYSCALL_WRAPPER(sys_getgid16); // ## P
-GEN_SYSCALL_WRAPPER(sys_geteuid16); // ## P
-GEN_SYSCALL_WRAPPER(sys_getegid16); // ## P
-GEN_SYSCALL_WRAPPER(sys_setreuid16); // ## BSD4.3
-GEN_SYSCALL_WRAPPER(sys_setregid16); // ## BSD4.3
-GEN_SYSCALL_WRAPPER(sys_getgroups16); // ## P
-GEN_SYSCALL_WRAPPER(sys_setgroups16); // ## SVr4, SVID, X/OPEN, 4.3BSD
-GEN_SYSCALL_WRAPPER(sys_fchown16); // ## SVr4,BSD4.3
-GEN_SYSCALL_WRAPPER(sys_chown16); // ## P
-
-// Linux's funny many-in-one socketcall is certainly not generic, but I
-// didn't want to move it until necessary because it's big and has a lot of
-// associated junk.
-GEN_SYSCALL_WRAPPER(sys_socketcall);
-
-// Some archs on Linux do not match the generic wrapper for sys_pipe().
-GEN_SYSCALL_WRAPPER(sys_pipe);
-
-// May not be generic for every architecture under Linux.
-GEN_SYSCALL_WRAPPER(sys_sigaction); // (x86) P
-
-// Funny names, not sure...
-GEN_SYSCALL_WRAPPER(sys_newstat); // * P
-GEN_SYSCALL_WRAPPER(sys_newlstat); // *
-GEN_SYSCALL_WRAPPER(sys_newfstat); // * P (SVr4,BSD4.3)
-
-// For the remainder, not really sure yet
-GEN_SYSCALL_WRAPPER(old_mmap); // x86, weird arg passing
-GEN_SYSCALL_WRAPPER(sys_ptrace); // (x86?) (almost-P)
-GEN_SYSCALL_WRAPPER(sys_sigsuspend); // POSIX, but L (proto varies across archs)
-GEN_SYSCALL_WRAPPER(sys_setrlimit); // SVr4, 4.3BSD
-GEN_SYSCALL_WRAPPER(sys_ioctl); // x86? (various)
-GEN_SYSCALL_WRAPPER(sys_old_getrlimit); // SVr4, 4.3BSD L?
-GEN_SYSCALL_WRAPPER(sys_statfs); // * L?
-GEN_SYSCALL_WRAPPER(sys_fstatfs); // * L?
-GEN_SYSCALL_WRAPPER(sys_iopl); // (x86/amd64) L
-GEN_SYSCALL_WRAPPER(sys_ipc); // (x86) L
-GEN_SYSCALL_WRAPPER(sys_newuname); // * P
-GEN_SYSCALL_WRAPPER(sys_init_module); // * L?
-GEN_SYSCALL_WRAPPER(sys_quotactl); // * (?)
-GEN_SYSCALL_WRAPPER(sys_rt_sigaction); // (x86) ()
-GEN_SYSCALL_WRAPPER(sys_rt_sigprocmask); // * ?
-GEN_SYSCALL_WRAPPER(sys_rt_sigpending); // * ?
-GEN_SYSCALL_WRAPPER(sys_rt_sigtimedwait); // * ?
-GEN_SYSCALL_WRAPPER(sys_rt_sigqueueinfo); // * ?
-GEN_SYSCALL_WRAPPER(sys_rt_sigsuspend); // () ()
-GEN_SYSCALL_WRAPPER(sys_pread64); // * (Unix98?)
-GEN_SYSCALL_WRAPPER(sys_pwrite64); // * (Unix98?)
-GEN_SYSCALL_WRAPPER(sys_capget); // * L?
-GEN_SYSCALL_WRAPPER(sys_capset); // * L?
-GEN_SYSCALL_WRAPPER(sys_sigaltstack); // (x86) (XPG4-UNIX)
-GEN_SYSCALL_WRAPPER(sys_getpmsg); // (?) (?)
-GEN_SYSCALL_WRAPPER(sys_putpmsg); // (?) (?)
-GEN_SYSCALL_WRAPPER(sys_getrlimit); // * (?)
-GEN_SYSCALL_WRAPPER(sys_mmap2); // (x86?) P?
-GEN_SYSCALL_WRAPPER(sys_truncate64); // %% (P?)
-GEN_SYSCALL_WRAPPER(sys_ftruncate64); // %% (P?)
-GEN_SYSCALL_WRAPPER(sys_stat64); // %% (?)
-GEN_SYSCALL_WRAPPER(sys_lstat64); // %% (?)
-GEN_SYSCALL_WRAPPER(sys_fstat64); // %% (?)
-GEN_SYSCALL_WRAPPER(sys_lchown); // * (L?)
-GEN_SYSCALL_WRAPPER(sys_mincore); // * L?
-GEN_SYSCALL_WRAPPER(sys_getdents64); // * (SVr4,SVID?)
-GEN_SYSCALL_WRAPPER(sys_fcntl64); // * P?
-GEN_SYSCALL_WRAPPER(sys_setxattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_lsetxattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_fsetxattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_getxattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_lgetxattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_fgetxattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_listxattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_llistxattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_flistxattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_removexattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_lremovexattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_fremovexattr); // * L?
-GEN_SYSCALL_WRAPPER(sys_sched_setaffinity); // * L?
-GEN_SYSCALL_WRAPPER(sys_sched_getaffinity); // * L?
-GEN_SYSCALL_WRAPPER(sys_lookup_dcookie); // (*/32/64) L
-GEN_SYSCALL_WRAPPER(sys_set_tid_address); // * ?
-GEN_SYSCALL_WRAPPER(sys_statfs64); // * (?)
-GEN_SYSCALL_WRAPPER(sys_fstatfs64); // * (?)
-GEN_SYSCALL_WRAPPER(sys_mq_open); // * P?
-GEN_SYSCALL_WRAPPER(sys_mq_unlink); // * P?
-GEN_SYSCALL_WRAPPER(sys_mq_timedsend); // * P?
-GEN_SYSCALL_WRAPPER(sys_mq_timedreceive); // * P?
-GEN_SYSCALL_WRAPPER(sys_mq_notify); // * P?
-GEN_SYSCALL_WRAPPER(sys_mq_getsetattr); // * P?
-
-#undef GEN_SYSCALL_WRAPPER
-
-// Macros used in syscall wrappers
-/* PRRAn == "pre-register-read-argument"
- PRRSN == "pre-register-read-syscall"
-*/
-
-#define PRRSN \
- TL_(pre_reg_read)(Vg_CoreSysCall, tid, "(syscallno)", \
- O_SYSCALL_NUM, sizeof(UWord));
-#define PRRAn(n,s,t,a) \
- TL_(pre_reg_read)(Vg_CoreSysCall, tid, s"("#a")", \
- O_SYSCALL_ARG##n, sizeof(t));
-#define PRE_REG_READ0(tr, s) \
- if (VG_(defined_pre_reg_read)()) { \
- PRRSN; \
- }
-#define PRE_REG_READ1(tr, s, t1, a1) \
- if (VG_(defined_pre_reg_read)()) { \
- PRRSN; \
- PRRAn(1,s,t1,a1); \
- }
-#define PRE_REG_READ2(tr, s, t1, a1, t2, a2) \
- if (VG_(defined_pre_reg_read)()) { \
- PRRSN; \
- PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); \
- }
-#define PRE_REG_READ3(tr, s, t1, a1, t2, a2, t3, a3) \
- if (VG_(defined_pre_reg_read)()) { \
- PRRSN; \
- PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); PRRAn(3,s,t3,a3); \
- }
-#define PRE_REG_READ4(tr, s, t1, a1, t2, a2, t3, a3, t4, a4) \
- if (VG_(defined_pre_reg_read)()) { \
- PRRSN; \
- PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); PRRAn(3,s,t3,a3); \
- PRRAn(4,s,t4,a4); \
- }
-#define PRE_REG_READ5(tr, s, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5) \
- if (VG_(defined_pre_reg_read)()) { \
- PRRSN; \
- PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); PRRAn(3,s,t3,a3); \
- PRRAn(4,s,t4,a4); PRRAn(5,s,t5,a5); \
- }
-#define PRE_REG_READ6(tr, s, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5, t6, a6) \
- if (VG_(defined_pre_reg_read)()) { \
- PRRSN; \
- PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); PRRAn(3,s,t3,a3); \
- PRRAn(4,s,t4,a4); PRRAn(5,s,t5,a5); PRRAn(6,s,t6,a6); \
- }
-
-#define PRE_MEM_READ(zzname, zzaddr, zzlen) \
- VG_TRACK( pre_mem_read, Vg_CoreSysCall, tid, zzname, zzaddr, zzlen)
-
-#define PRE_MEM_RASCIIZ(zzname, zzaddr) \
- VG_TRACK( pre_mem_read_asciiz, Vg_CoreSysCall, tid, zzname, zzaddr)
-
-#define PRE_MEM_WRITE(zzname, zzaddr, zzlen) \
- VG_TRACK( pre_mem_write, Vg_CoreSysCall, tid, zzname, zzaddr, zzlen)
-
-#define POST_MEM_WRITE(zzaddr, zzlen) \
- VG_TRACK( post_mem_write, Vg_CoreSysCall, tid, zzaddr, zzlen)
-
-
-//////////////////////////////////////////////////////////
-
-#define TId ThreadId
-#define UW UWord
-
-extern void VG_(generic_PRE_sys_socketpair) ( TId, UW, UW, UW, UW );
-extern UWord VG_(generic_POST_sys_socketpair) ( TId, UW, UW, UW, UW, UW );
-extern UWord VG_(generic_POST_sys_socket) ( TId, UW );
-extern void VG_(generic_PRE_sys_bind) ( TId, UW, UW, UW );
-extern void VG_(generic_PRE_sys_accept) ( TId, UW, UW, UW );
-extern UWord VG_(generic_POST_sys_accept) ( TId, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_sendto) ( TId, UW, UW, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_send) ( TId, UW, UW, UW );
-extern void VG_(generic_PRE_sys_recvfrom) ( TId, UW, UW, UW, UW, UW, UW );
-extern void VG_(generic_POST_sys_recvfrom) ( TId, UW, UW, UW, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_recv) ( TId, UW, UW, UW );
-extern void VG_(generic_POST_sys_recv) ( TId, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_connect) ( TId, UW, UW, UW );
-extern void VG_(generic_PRE_sys_setsockopt) ( TId, UW, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_getsockopt) ( TId, UW, UW, UW, UW, UW );
-extern void VG_(generic_POST_sys_getsockopt) ( TId, UW, UW, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_getsockname) ( TId, UW, UW, UW );
-extern void VG_(generic_POST_sys_getsockname) ( TId, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_getpeername) ( TId, UW, UW, UW );
-extern void VG_(generic_POST_sys_getpeername) ( TId, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_sendmsg) ( TId, UW, UW );
-extern void VG_(generic_PRE_sys_recvmsg) ( TId, UW, UW );
-extern void VG_(generic_POST_sys_recvmsg) ( TId, UW, UW, UW );
-
-extern void VG_(generic_PRE_sys_semop) ( TId, UW, UW, UW );
-extern void VG_(generic_PRE_sys_semtimedop) ( TId, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_semctl) ( TId, UW, UW, UW, UW );
-extern void VG_(generic_POST_sys_semctl) ( TId, UW, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_msgsnd) ( TId, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_msgrcv) ( TId, UW, UW, UW, UW, UW );
-extern void VG_(generic_POST_sys_msgrcv) ( TId, UW, UW, UW, UW, UW, UW );
-extern void VG_(generic_PRE_sys_msgctl) ( TId, UW, UW, UW );
-extern void VG_(generic_POST_sys_msgctl) ( TId, UW, UW, UW, UW );
-extern UWord VG_(generic_PRE_sys_shmat) ( TId, UW, UW, UW );
-extern void VG_(generic_POST_sys_shmat) ( TId, UW, UW, UW, UW );
-extern Bool VG_(generic_PRE_sys_shmdt) ( TId, UW );
-extern void VG_(generic_POST_sys_shmdt) ( TId, UW, UW );
-extern void VG_(generic_PRE_sys_shmctl) ( TId, UW, UW, UW );
-extern void VG_(generic_POST_sys_shmctl) ( TId, UW, UW, UW, UW );
-
-#undef TID
-#undef UW
-
-
-/* ---------------------------------------------------------------------
Exports of vg_transtab.c
------------------------------------------------------------------ */
@@ -1587,62 +1158,7 @@
// Platform-specific things defined in eg. x86/*.c
// ---------------------------------------------------------------------
-// Offsets for the shadow state
-#define O_SYSCALL_NUM (offsetof(VexGuestArchState, VGP_SYSCALL_NUM))
-#define O_SYSCALL_ARG1 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG1))
-#define O_SYSCALL_ARG2 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG2))
-#define O_SYSCALL_ARG3 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG3))
-#define O_SYSCALL_ARG4 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG4))
-#define O_SYSCALL_ARG5 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG5))
-#define O_SYSCALL_ARG6 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG6))
-#define O_SYSCALL_RET (offsetof(VexGuestArchState, VGP_SYSCALL_RET))
-
-struct SyscallTableEntry {
- UInt *flags_ptr;
- void (*before)(ThreadId tid, ThreadState *tst /*, UInt *flags*/);
- void (*after) (ThreadId tid, ThreadState *tst);
-};
-
-/* This table is the mapping from __NR_xxx syscall numbers to the PRE/POST
- wrappers for the relevant syscalls used in the OS kernel for that number.
- Note that the constant names don't always match the wrapper names in a
- straightforward way. For example, on x86/Linux:
-
- __NR_lchown --> sys_lchown16()
- __NR_lchown32 --> sys_lchown()
- __NR_select --> old_select()
- __NR__newselect --> sys_select()
-*/
-extern const struct SyscallTableEntry VGA_(syscall_table)[];
-
-extern const UInt VGA_(syscall_table_size);
-
-extern void VGA_(restart_syscall)(ThreadArchState* arch);
-
-/*
- Perform a syscall on behalf of a client thread, using a specific
- signal mask. On completion, the signal mask is set to restore_mask
- (which presumably blocks almost everything). If a signal happens
- during the syscall, the handler should call
- VGA_(interrupted_syscall)() to adjust the thread's context to do the
- right thing.
-*/
-extern void VGA_(client_syscall)(Int syscallno, ThreadState *tst,
- const vki_sigset_t *syscall_mask);
-
-/*
- Fix up the thread's state because a syscall may have been
- interrupted with a signal. Returns True if the syscall completed
- (either interrupted or finished normally), or False if it was
- restarted (or the signal didn't actually interrupt a syscall).
- */
-extern void VGA_(interrupted_syscall)(ThreadId tid,
- struct vki_ucontext *uc,
- Bool restart);
-
-/*
- Do any platform specific redirects.
- */
+// Do any platform specific redirects.
extern void VGP_(setup_redirects)(void);
///* ---------------------------------------------------------------------
diff --git a/coregrind/linux/Makefile.am b/coregrind/linux/Makefile.am
index 94663df..871f9b2 100644
--- a/coregrind/linux/Makefile.am
+++ b/coregrind/linux/Makefile.am
@@ -10,8 +10,7 @@
libos_a_SOURCES = \
core_os.c \
- sema.c \
- syscalls.c
+ sema.c
if USE_PIE
libos_a_CFLAGS = $(AM_CFLAGS) -fpie
diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c
index 184501d..785eec7 100644
--- a/coregrind/m_aspacemgr/aspacemgr.c
+++ b/coregrind/m_aspacemgr/aspacemgr.c
@@ -32,6 +32,7 @@
#include "core.h"
#include "pub_core_aspacemgr.h"
+#include "pub_core_syscalls.h"
/* Define to debug the memory-leak-detector. */
diff --git a/coregrind/m_syscalls/Makefile.am b/coregrind/m_syscalls/Makefile.am
new file mode 100644
index 0000000..d30f08a
--- /dev/null
+++ b/coregrind/m_syscalls/Makefile.am
@@ -0,0 +1,27 @@
+include $(top_srcdir)/Makefile.all.am
+include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
+
+AM_CFLAGS = $(WERROR) -Wmissing-prototypes -Winline -Wall -Wshadow -O -g
+
+EXTRA_DIST = \
+ README_SYSCALLS.txt
+
+noinst_HEADERS = \
+ priv_syscalls.h \
+ priv_syscalls-amd64-linux.h \
+ priv_syscalls-arm-linux.h \
+ priv_syscalls-x86-linux.h
+
+noinst_LIBRARIES = libsyscalls.a
+
+libsyscalls_a_SOURCES = \
+ syscall-@VG_PLATFORM@.S \
+ syscalls.c \
+ syscalls-@VG_OS@.c \
+ syscalls-@VG_PLATFORM@.c
+
+if USE_PIE
+libsyscalls_a_CFLAGS = $(AM_CFLAGS) -fpie
+else
+libsyscalls_a_CFLAGS = $(AM_CFLAGS)
+endif
diff --git a/coregrind/m_syscalls/README_SYSCALLS.txt b/coregrind/m_syscalls/README_SYSCALLS.txt
new file mode 100644
index 0000000..5c12cf7
--- /dev/null
+++ b/coregrind/m_syscalls/README_SYSCALLS.txt
@@ -0,0 +1 @@
+(put useful notes about this module in here)
diff --git a/coregrind/m_syscalls/priv_syscalls-amd64-linux.h b/coregrind/m_syscalls/priv_syscalls-amd64-linux.h
new file mode 100644
index 0000000..ff7d2eb
--- /dev/null
+++ b/coregrind/m_syscalls/priv_syscalls-amd64-linux.h
@@ -0,0 +1,58 @@
+
+/*--------------------------------------------------------------------*/
+/*--- AMD64/Linux-specific syscall stuff. ---*/
+/*--- priv_syscalls-amd64-linux.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Nicholas Nethercote
+ njn@valgrind.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 __PRIV_SYSCALLS_AMD64_LINUX_H
+#define __PRIV_SYSCALLS_AMD64_LINUX_H
+
+// Accessors for the ThreadArchState
+#define VGP_SYSCALL_NUM guest_RAX
+#define VGP_SYSCALL_ARG1 guest_RDI
+#define VGP_SYSCALL_ARG2 guest_RSI
+#define VGP_SYSCALL_ARG3 guest_RDX
+#define VGP_SYSCALL_ARG4 guest_R10
+#define VGP_SYSCALL_ARG5 guest_R8
+#define VGP_SYSCALL_ARG6 guest_R9
+#define VGP_SYSCALL_RET guest_RAX
+
+// Setting a syscall result
+#define VGP_SET_SYSCALL_RESULT(regs, val) ((regs).vex.guest_RAX = (val))
+
+// For informing tools that a syscall result has been set.
+#define VGP_TRACK_SYSCALL_RETVAL(zztid) \
+ VG_TRACK( post_reg_write, Vg_CoreSysCall, zztid, O_SYSCALL_RET, sizeof(UWord) );
+
+#endif // __PRIV_SYSCALLS_AMD64_LINUX_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
+
+
diff --git a/coregrind/m_syscalls/priv_syscalls-arm-linux.h b/coregrind/m_syscalls/priv_syscalls-arm-linux.h
new file mode 100644
index 0000000..63b977d
--- /dev/null
+++ b/coregrind/m_syscalls/priv_syscalls-arm-linux.h
@@ -0,0 +1,57 @@
+
+/*--------------------------------------------------------------------*/
+/*--- ARM/Linux-specific syscall stuff. priv_syscalls-arm-linux.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Nicholas Nethercote
+ njn@valgrind.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 __PRIV_SYSCALLS_ARM_LINUX_H
+#define __PRIV_SYSCALLS_ARM_LINUX_H
+
+// Accessors for the ThreadArchState
+#define VGP_SYSCALL_NUM guest_SYSCALLNO
+#define VGP_SYSCALL_ARG1 guest_R0
+#define VGP_SYSCALL_ARG2 guest_R1
+#define VGP_SYSCALL_ARG3 guest_R2
+#define VGP_SYSCALL_ARG4 guest_R3
+#define VGP_SYSCALL_ARG5 guest_R4
+#define VGP_SYSCALL_ARG6 guest_R5
+#define VGP_SYSCALL_RET guest_R0 // ToDo XXX ????????
+
+// ToDo XXX ????????
+#define VGP_SET_SYSCALL_RESULT(regs, val) ((regs).vex.guest_R0 = (val))
+
+// For informing tools that a syscall result has been set.
+// XXX ToDo: not sure about this
+#define VGP_TRACK_SYSCALL_RETVAL(zztid) \
+ VG_TRACK( post_reg_write, Vg_CoreSysCall, zztid, O_SYSCALL_RET, sizeof(UWord) );
+
+#endif // __PRIV_SYSCALLS_ARM_LINUX_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
+
diff --git a/coregrind/m_syscalls/priv_syscalls-x86-linux.h b/coregrind/m_syscalls/priv_syscalls-x86-linux.h
new file mode 100644
index 0000000..69218ce
--- /dev/null
+++ b/coregrind/m_syscalls/priv_syscalls-x86-linux.h
@@ -0,0 +1,56 @@
+
+/*--------------------------------------------------------------------*/
+/*--- x86/Linux-specific syscall stuff. priv_syscalls-x86-linux.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Nicholas Nethercote
+ njn@valgrind.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 __PRIV_SYSCALLS_X86_LINUX_H
+#define __PRIV_SYSCALLS_X86_LINUX_H
+
+// Accessors for the ThreadArchState
+#define VGP_SYSCALL_NUM guest_EAX
+#define VGP_SYSCALL_ARG1 guest_EBX
+#define VGP_SYSCALL_ARG2 guest_ECX
+#define VGP_SYSCALL_ARG3 guest_EDX
+#define VGP_SYSCALL_ARG4 guest_ESI
+#define VGP_SYSCALL_ARG5 guest_EDI
+#define VGP_SYSCALL_ARG6 guest_EBP
+#define VGP_SYSCALL_RET guest_EAX
+
+// Setting a syscall result
+#define VGP_SET_SYSCALL_RESULT(regs, val) ((regs).vex.guest_EAX = (val))
+
+// For informing tools that a syscall result has been set.
+#define VGP_TRACK_SYSCALL_RETVAL(zztid) \
+ VG_TRACK( post_reg_write, Vg_CoreSysCall, zztid, O_SYSCALL_RET, sizeof(UWord) );
+
+#endif // __PRIV_SYSCALLS_X86_LINUX_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
+
diff --git a/coregrind/m_syscalls/priv_syscalls.h b/coregrind/m_syscalls/priv_syscalls.h
new file mode 100644
index 0000000..8add5ec
--- /dev/null
+++ b/coregrind/m_syscalls/priv_syscalls.h
@@ -0,0 +1,505 @@
+/*--------------------------------------------------------------------*/
+/*--- Private syscalls header. priv_syscalls.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 __PRIV_SYSCALLS_H
+#define __PRIV_SYSCALLS_H
+
+// This is ugly, but the alternatives (ie. doing it "properly" with -I options
+// and directories and more Makefiles) are even worse.
+#if defined(VGP_amd64_linux)
+# include "priv_syscalls-amd64-linux.h"
+#elif defined(VGP_arm_linux)
+# include "priv_syscalls-arm-linux.h"
+#elif defined(VGP_x86_linux)
+# include "priv_syscalls-x86-linux.h"
+#else
+# error Unknown platform
+#endif
+
+// Offsets for the shadow state
+#define O_SYSCALL_NUM (offsetof(VexGuestArchState, VGP_SYSCALL_NUM))
+#define O_SYSCALL_ARG1 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG1))
+#define O_SYSCALL_ARG2 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG2))
+#define O_SYSCALL_ARG3 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG3))
+#define O_SYSCALL_ARG4 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG4))
+#define O_SYSCALL_ARG5 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG5))
+#define O_SYSCALL_ARG6 (offsetof(VexGuestArchState, VGP_SYSCALL_ARG6))
+#define O_SYSCALL_RET (offsetof(VexGuestArchState, VGP_SYSCALL_RET))
+
+// The syscall table
+struct SyscallTableEntry {
+ UInt *flags_ptr;
+ void (*before)(ThreadId tid, ThreadState *tst /*, UInt *flags*/);
+ void (*after) (ThreadId tid, ThreadState *tst);
+};
+
+/* This table is the mapping from __NR_xxx syscall numbers to the PRE/POST
+ wrappers for the relevant syscalls used in the OS kernel for that number.
+ Note that the constant names don't always match the wrapper names in a
+ straightforward way. For example, on x86/Linux:
+
+ __NR_lchown --> sys_lchown16()
+ __NR_lchown32 --> sys_lchown()
+ __NR_select --> old_select()
+ __NR__newselect --> sys_select()
+*/
+extern const struct SyscallTableEntry VGA_(syscall_table)[];
+
+extern const UInt VGA_(syscall_table_size);
+
+extern void VGA_(restart_syscall)(ThreadArchState* arch);
+
+/*
+ Perform a syscall on behalf of a client thread, using a specific
+ signal mask. On completion, the signal mask is set to restore_mask
+ (which presumably blocks almost everything). If a signal happens
+ during the syscall, the handler should call
+ VGA_(interrupted_syscall)() to adjust the thread's context to do the
+ right thing.
+*/
+extern void VGA_(client_syscall)(Int syscallno, ThreadState *tst,
+ const vki_sigset_t *syscall_mask);
+
+/* Simple Valgrind-internal atfork mechanism */
+extern void VG_(do_atfork_pre) (ThreadId tid);
+extern void VG_(do_atfork_parent)(ThreadId tid);
+extern void VG_(do_atfork_child) (ThreadId tid);
+
+// Return true if address range entirely contained within client
+// address space.
+Bool VG_(valid_client_addr)(Addr start, SizeT size, ThreadId tid,
+ const Char *syscallname);
+
+// Return true if we're allowed to use or create this fd.
+Bool VG_(fd_allowed)(Int fd, const Char *syscallname, ThreadId tid, Bool soft);
+
+void VG_(record_fd_open)(ThreadId tid, Int fd, char *pathname);
+
+// Used when killing threads -- we must not kill a thread if it's the thread
+// that would do Valgrind's final cleanup and output.
+Bool VG_(do_sigkill)(Int pid, Int tgid);
+
+// Flags describing syscall wrappers
+#define Special (1 << 0) /* handled specially */
+#define MayBlock (1 << 1) /* may block */
+#define PostOnFail (1 << 2) /* call POST() function on failure */
+#define PadAddr (1 << 3) /* pad+unpad address space around syscall */
+#define Done (1 << 4) /* used if a PRE() did the syscall */
+
+// Templates for generating the PRE and POST macros. For ones that must be
+// publically visible, use an empty 'qual', 'prefix' should start with
+// "vgArch_" or similar, and there should be corresponding global
+// declarations (like the GEN_SYSCALL_WRAPPER ones below). Otherwise, use
+// "static" for 'qual', and "vgArch_" should not be in the 'prefix'.
+#define PRE_TEMPLATE(qual, prefix, name, f) \
+ qual UInt prefix##_##name##_flags = f; \
+ qual void prefix##_##name##_before(ThreadId tid, ThreadState *tst)
+#define POST_TEMPLATE(qual, prefix, name) \
+ qual void prefix##_##name##_after (ThreadId tid, ThreadState *tst)
+
+// This macro is used to write other macros which making writing syscall
+// tables easier.
+#define SYS_WRAPPER_ENTRY_X_(prefix, const, name) \
+ [const] = { &prefix##_##name##_flags, \
+ prefix##_##name##_before, NULL }
+#define SYS_WRAPPER_ENTRY_XY(prefix, const, name) \
+ [const] = { &prefix##_##name##_flags, \
+ prefix##_##name##_before, \
+ prefix##_##name##_after }
+
+// Macros for adding generic wrappers to a syscall table.
+#define GENX_(const, name) SYS_WRAPPER_ENTRY_X_(vgArch_gen, const, name)
+#define GENXY(const, name) SYS_WRAPPER_ENTRY_XY(vgArch_gen, const, name)
+
+// Space-saving macros for syscall PRE() and POST() wrappers
+#define RES ((tst->arch).vex.VGP_SYSCALL_RET)
+#define SYSNO ((tst->arch).vex.VGP_SYSCALL_NUM)
+#define ARG1 ((tst->arch).vex.VGP_SYSCALL_ARG1)
+#define ARG2 ((tst->arch).vex.VGP_SYSCALL_ARG2)
+#define ARG3 ((tst->arch).vex.VGP_SYSCALL_ARG3)
+#define ARG4 ((tst->arch).vex.VGP_SYSCALL_ARG4)
+#define ARG5 ((tst->arch).vex.VGP_SYSCALL_ARG5)
+#define ARG6 ((tst->arch).vex.VGP_SYSCALL_ARG6)
+
+// For setting the result of a syscall in a wrapper
+#define SET_RESULT(val) \
+ do { VGP_SET_SYSCALL_RESULT(tst->arch, (val)); \
+ tst->syscall_result_set = True; \
+ } while (0)
+
+#define PRINT(format, args...) \
+ if (VG_(clo_trace_syscalls)) \
+ VG_(printf)(format, ## args)
+
+// Generic (platform-independent) syscall wrappers. These are generally
+// POSIX or something like that; those that are not POSIX are annotated
+// with what standards they are part of, as stated in the Linux man pages.
+// For many of them, it's unclear if they are generic, or Linux-specific, or
+// x86/Linux-specific, or something else again.
+//
+// Nb: This list may change over time... ones thought at first to be generic
+// may turn out not to be, and so be moved into OS-specific or
+// platform-specific files. If there's any doubt, I'm leaving them in here.
+//
+// Nb 2: if porting to a new OS, you should really check all these generic
+// wrappers to make sure they match your OS, painful as it might be.
+//
+// For each generic ("gen") wrapper, we declare the pre-wrapper, the
+// post-wrapper (which is actually not always needed), and the associated
+// flags.
+#define GEN_SYSCALL_WRAPPER(x) \
+ extern UInt VGA_(gen_##x##_flags); \
+ extern void VGA_(gen_##x##_before)(ThreadId tid, ThreadState *tst); \
+ extern void VGA_(gen_##x##_after) (ThreadId tid, ThreadState *tst)
+
+GEN_SYSCALL_WRAPPER(sys_ni_syscall); // * P -- unimplemented
+GEN_SYSCALL_WRAPPER(sys_exit);
+GEN_SYSCALL_WRAPPER(sys_fork);
+GEN_SYSCALL_WRAPPER(sys_read);
+GEN_SYSCALL_WRAPPER(sys_write);
+GEN_SYSCALL_WRAPPER(sys_open);
+GEN_SYSCALL_WRAPPER(sys_close);
+GEN_SYSCALL_WRAPPER(sys_waitpid);
+GEN_SYSCALL_WRAPPER(sys_creat);
+GEN_SYSCALL_WRAPPER(sys_link);
+GEN_SYSCALL_WRAPPER(sys_unlink);
+GEN_SYSCALL_WRAPPER(sys_execve); // (*??) P
+GEN_SYSCALL_WRAPPER(sys_chdir);
+GEN_SYSCALL_WRAPPER(sys_time);
+GEN_SYSCALL_WRAPPER(sys_mknod);
+GEN_SYSCALL_WRAPPER(sys_chmod);
+GEN_SYSCALL_WRAPPER(sys_lseek);
+GEN_SYSCALL_WRAPPER(sys_getpid);
+GEN_SYSCALL_WRAPPER(sys_alarm);
+GEN_SYSCALL_WRAPPER(sys_pause);
+GEN_SYSCALL_WRAPPER(sys_utime);
+GEN_SYSCALL_WRAPPER(sys_access);
+GEN_SYSCALL_WRAPPER(sys_kill);
+GEN_SYSCALL_WRAPPER(sys_rename);
+GEN_SYSCALL_WRAPPER(sys_mkdir);
+GEN_SYSCALL_WRAPPER(sys_rmdir);
+GEN_SYSCALL_WRAPPER(sys_dup);
+GEN_SYSCALL_WRAPPER(sys_times);
+GEN_SYSCALL_WRAPPER(sys_fcntl); // POSIX (but complicated)
+GEN_SYSCALL_WRAPPER(sys_setpgid);
+GEN_SYSCALL_WRAPPER(sys_umask);
+GEN_SYSCALL_WRAPPER(sys_dup2);
+GEN_SYSCALL_WRAPPER(sys_getppid);
+GEN_SYSCALL_WRAPPER(sys_getpgrp);
+GEN_SYSCALL_WRAPPER(sys_setsid);
+GEN_SYSCALL_WRAPPER(sys_munmap);
+GEN_SYSCALL_WRAPPER(sys_truncate);
+GEN_SYSCALL_WRAPPER(sys_ftruncate);
+GEN_SYSCALL_WRAPPER(sys_fchmod);
+GEN_SYSCALL_WRAPPER(sys_msync);
+GEN_SYSCALL_WRAPPER(sys_readv);
+GEN_SYSCALL_WRAPPER(sys_writev);
+GEN_SYSCALL_WRAPPER(sys_getsid);
+GEN_SYSCALL_WRAPPER(sys_fdatasync);
+GEN_SYSCALL_WRAPPER(sys_mlock);
+GEN_SYSCALL_WRAPPER(sys_munlock);
+GEN_SYSCALL_WRAPPER(sys_mlockall);
+GEN_SYSCALL_WRAPPER(sys_munlockall);
+GEN_SYSCALL_WRAPPER(sys_sched_setparam);
+GEN_SYSCALL_WRAPPER(sys_sched_getparam);
+GEN_SYSCALL_WRAPPER(sys_sched_rr_get_interval);
+GEN_SYSCALL_WRAPPER(sys_sched_setscheduler);
+GEN_SYSCALL_WRAPPER(sys_sched_getscheduler);
+GEN_SYSCALL_WRAPPER(sys_sched_yield);
+GEN_SYSCALL_WRAPPER(sys_sched_get_priority_max);
+GEN_SYSCALL_WRAPPER(sys_sched_get_priority_min);
+GEN_SYSCALL_WRAPPER(sys_nanosleep);
+GEN_SYSCALL_WRAPPER(sys_mremap); // POSIX, but Linux arg order may be odd
+GEN_SYSCALL_WRAPPER(sys_getuid);
+GEN_SYSCALL_WRAPPER(sys_getgid);
+GEN_SYSCALL_WRAPPER(sys_geteuid);
+GEN_SYSCALL_WRAPPER(sys_getegid);
+GEN_SYSCALL_WRAPPER(sys_getpgid);
+GEN_SYSCALL_WRAPPER(sys_fsync);
+GEN_SYSCALL_WRAPPER(sys_wait4);
+GEN_SYSCALL_WRAPPER(sys_mprotect);
+GEN_SYSCALL_WRAPPER(sys_sigprocmask);
+GEN_SYSCALL_WRAPPER(sys_timer_create); // Linux: varies across archs?
+GEN_SYSCALL_WRAPPER(sys_timer_settime);
+GEN_SYSCALL_WRAPPER(sys_timer_gettime);
+GEN_SYSCALL_WRAPPER(sys_timer_getoverrun);
+GEN_SYSCALL_WRAPPER(sys_timer_delete);
+GEN_SYSCALL_WRAPPER(sys_clock_settime);
+GEN_SYSCALL_WRAPPER(sys_clock_gettime);
+GEN_SYSCALL_WRAPPER(sys_clock_getres);
+GEN_SYSCALL_WRAPPER(sys_clock_nanosleep);
+GEN_SYSCALL_WRAPPER(sys_getcwd);
+GEN_SYSCALL_WRAPPER(sys_symlink);
+GEN_SYSCALL_WRAPPER(sys_getgroups);
+GEN_SYSCALL_WRAPPER(sys_setgroups); // SVr4, SVID, X/OPEN, 4.3BSD
+GEN_SYSCALL_WRAPPER(sys_chown);
+GEN_SYSCALL_WRAPPER(sys_setuid);
+GEN_SYSCALL_WRAPPER(sys_gettimeofday);
+GEN_SYSCALL_WRAPPER(sys_madvise);
+GEN_SYSCALL_WRAPPER(sys_sigpending);
+
+// These ones aren't POSIX, but are in some standard and look reasonably
+// generic, and are the same for all architectures under Linux.
+GEN_SYSCALL_WRAPPER(sys_nice); // SVr4, SVID EXT, AT&T, X/OPEN, BSD 4.3
+GEN_SYSCALL_WRAPPER(sys_sync); // SVr4, SVID, X/OPEN, BSD 4.3
+GEN_SYSCALL_WRAPPER(sys_brk); // 4.3BSD
+GEN_SYSCALL_WRAPPER(sys_acct); // SVR4, non-POSIX
+GEN_SYSCALL_WRAPPER(sys_chroot); // SVr4, SVID, 4.4BSD, X/OPEN
+GEN_SYSCALL_WRAPPER(sys_readlink); // X/OPEN, 4.4BSD
+GEN_SYSCALL_WRAPPER(sys_fchdir); // SVr4, SVID, POSIX, X/OPEN, 4.4BSD
+GEN_SYSCALL_WRAPPER(sys_getdents); // SVr4,SVID
+GEN_SYSCALL_WRAPPER(sys_select); // 4.4BSD
+GEN_SYSCALL_WRAPPER(sys_flock); // 4.4BSD
+GEN_SYSCALL_WRAPPER(sys_poll); // XPG4-UNIX
+GEN_SYSCALL_WRAPPER(sys_getrusage); // SVr4, 4.3BSD
+GEN_SYSCALL_WRAPPER(sys_stime); // SVr4, SVID, X/OPEN
+GEN_SYSCALL_WRAPPER(sys_settimeofday); // SVr4, 4.3BSD (non-POSIX)
+GEN_SYSCALL_WRAPPER(sys_getpriority); // SVr4, 4.4BSD
+GEN_SYSCALL_WRAPPER(sys_setpriority); // SVr4, 4.4BSD
+GEN_SYSCALL_WRAPPER(sys_setitimer); // SVr4, 4.4BSD
+GEN_SYSCALL_WRAPPER(sys_getitimer); // SVr4, 4.4BSD
+GEN_SYSCALL_WRAPPER(sys_setreuid); // 4.3BSD
+GEN_SYSCALL_WRAPPER(sys_setregid); // 4.3BSD
+GEN_SYSCALL_WRAPPER(sys_fchown); // SVr4,4.3BSD
+GEN_SYSCALL_WRAPPER(sys_setgid); // SVr4,SVID
+GEN_SYSCALL_WRAPPER(sys_utimes); // 4.3BSD
+
+// These ones may be Linux specific... not sure. They use 16-bit gid_t and
+// uid_t types. The similarly named (minus the "16" suffix) ones below use
+// 32-bit versions of these types.
+GEN_SYSCALL_WRAPPER(sys_setuid16); // ## P
+GEN_SYSCALL_WRAPPER(sys_getuid16); // ## P
+GEN_SYSCALL_WRAPPER(sys_setgid16); // ## SVr4,SVID
+GEN_SYSCALL_WRAPPER(sys_getgid16); // ## P
+GEN_SYSCALL_WRAPPER(sys_geteuid16); // ## P
+GEN_SYSCALL_WRAPPER(sys_getegid16); // ## P
+GEN_SYSCALL_WRAPPER(sys_setreuid16); // ## BSD4.3
+GEN_SYSCALL_WRAPPER(sys_setregid16); // ## BSD4.3
+GEN_SYSCALL_WRAPPER(sys_getgroups16); // ## P
+GEN_SYSCALL_WRAPPER(sys_setgroups16); // ## SVr4, SVID, X/OPEN, 4.3BSD
+GEN_SYSCALL_WRAPPER(sys_fchown16); // ## SVr4,BSD4.3
+GEN_SYSCALL_WRAPPER(sys_chown16); // ## P
+
+// Linux's funny many-in-one socketcall is certainly not generic, but I
+// didn't want to move it until necessary because it's big and has a lot of
+// associated junk.
+GEN_SYSCALL_WRAPPER(sys_socketcall);
+
+// Some archs on Linux do not match the generic wrapper for sys_pipe().
+GEN_SYSCALL_WRAPPER(sys_pipe);
+
+// May not be generic for every architecture under Linux.
+GEN_SYSCALL_WRAPPER(sys_sigaction); // (x86) P
+
+// Funny names, not sure...
+GEN_SYSCALL_WRAPPER(sys_newstat); // * P
+GEN_SYSCALL_WRAPPER(sys_newlstat); // *
+GEN_SYSCALL_WRAPPER(sys_newfstat); // * P (SVr4,BSD4.3)
+
+// For the remainder, not really sure yet
+GEN_SYSCALL_WRAPPER(old_mmap); // x86, weird arg passing
+GEN_SYSCALL_WRAPPER(sys_ptrace); // (x86?) (almost-P)
+GEN_SYSCALL_WRAPPER(sys_sigsuspend); // POSIX, but L (proto varies across archs)
+GEN_SYSCALL_WRAPPER(sys_setrlimit); // SVr4, 4.3BSD
+GEN_SYSCALL_WRAPPER(sys_ioctl); // x86? (various)
+GEN_SYSCALL_WRAPPER(sys_old_getrlimit); // SVr4, 4.3BSD L?
+GEN_SYSCALL_WRAPPER(sys_statfs); // * L?
+GEN_SYSCALL_WRAPPER(sys_fstatfs); // * L?
+GEN_SYSCALL_WRAPPER(sys_iopl); // (x86/amd64) L
+GEN_SYSCALL_WRAPPER(sys_ipc); // (x86) L
+GEN_SYSCALL_WRAPPER(sys_newuname); // * P
+GEN_SYSCALL_WRAPPER(sys_init_module); // * L?
+GEN_SYSCALL_WRAPPER(sys_quotactl); // * (?)
+GEN_SYSCALL_WRAPPER(sys_rt_sigaction); // (x86) ()
+GEN_SYSCALL_WRAPPER(sys_rt_sigprocmask); // * ?
+GEN_SYSCALL_WRAPPER(sys_rt_sigpending); // * ?
+GEN_SYSCALL_WRAPPER(sys_rt_sigtimedwait); // * ?
+GEN_SYSCALL_WRAPPER(sys_rt_sigqueueinfo); // * ?
+GEN_SYSCALL_WRAPPER(sys_rt_sigsuspend); // () ()
+GEN_SYSCALL_WRAPPER(sys_pread64); // * (Unix98?)
+GEN_SYSCALL_WRAPPER(sys_pwrite64); // * (Unix98?)
+GEN_SYSCALL_WRAPPER(sys_capget); // * L?
+GEN_SYSCALL_WRAPPER(sys_capset); // * L?
+GEN_SYSCALL_WRAPPER(sys_sigaltstack); // (x86) (XPG4-UNIX)
+GEN_SYSCALL_WRAPPER(sys_getpmsg); // (?) (?)
+GEN_SYSCALL_WRAPPER(sys_putpmsg); // (?) (?)
+GEN_SYSCALL_WRAPPER(sys_getrlimit); // * (?)
+GEN_SYSCALL_WRAPPER(sys_mmap2); // (x86?) P?
+GEN_SYSCALL_WRAPPER(sys_truncate64); // %% (P?)
+GEN_SYSCALL_WRAPPER(sys_ftruncate64); // %% (P?)
+GEN_SYSCALL_WRAPPER(sys_stat64); // %% (?)
+GEN_SYSCALL_WRAPPER(sys_lstat64); // %% (?)
+GEN_SYSCALL_WRAPPER(sys_fstat64); // %% (?)
+GEN_SYSCALL_WRAPPER(sys_lchown); // * (L?)
+GEN_SYSCALL_WRAPPER(sys_mincore); // * L?
+GEN_SYSCALL_WRAPPER(sys_getdents64); // * (SVr4,SVID?)
+GEN_SYSCALL_WRAPPER(sys_fcntl64); // * P?
+GEN_SYSCALL_WRAPPER(sys_setxattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_lsetxattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_fsetxattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_getxattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_lgetxattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_fgetxattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_listxattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_llistxattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_flistxattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_removexattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_lremovexattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_fremovexattr); // * L?
+GEN_SYSCALL_WRAPPER(sys_sched_setaffinity); // * L?
+GEN_SYSCALL_WRAPPER(sys_sched_getaffinity); // * L?
+GEN_SYSCALL_WRAPPER(sys_lookup_dcookie); // (*/32/64) L
+GEN_SYSCALL_WRAPPER(sys_set_tid_address); // * ?
+GEN_SYSCALL_WRAPPER(sys_statfs64); // * (?)
+GEN_SYSCALL_WRAPPER(sys_fstatfs64); // * (?)
+GEN_SYSCALL_WRAPPER(sys_mq_open); // * P?
+GEN_SYSCALL_WRAPPER(sys_mq_unlink); // * P?
+GEN_SYSCALL_WRAPPER(sys_mq_timedsend); // * P?
+GEN_SYSCALL_WRAPPER(sys_mq_timedreceive); // * P?
+GEN_SYSCALL_WRAPPER(sys_mq_notify); // * P?
+GEN_SYSCALL_WRAPPER(sys_mq_getsetattr); // * P?
+
+#undef GEN_SYSCALL_WRAPPER
+
+// Macros used in syscall wrappers
+/* PRRAn == "pre-register-read-argument"
+ PRRSN == "pre-register-read-syscall"
+*/
+
+#define PRRSN \
+ TL_(pre_reg_read)(Vg_CoreSysCall, tid, "(syscallno)", \
+ O_SYSCALL_NUM, sizeof(UWord));
+#define PRRAn(n,s,t,a) \
+ TL_(pre_reg_read)(Vg_CoreSysCall, tid, s"("#a")", \
+ O_SYSCALL_ARG##n, sizeof(t));
+#define PRE_REG_READ0(tr, s) \
+ if (VG_(defined_pre_reg_read)()) { \
+ PRRSN; \
+ }
+#define PRE_REG_READ1(tr, s, t1, a1) \
+ if (VG_(defined_pre_reg_read)()) { \
+ PRRSN; \
+ PRRAn(1,s,t1,a1); \
+ }
+#define PRE_REG_READ2(tr, s, t1, a1, t2, a2) \
+ if (VG_(defined_pre_reg_read)()) { \
+ PRRSN; \
+ PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); \
+ }
+#define PRE_REG_READ3(tr, s, t1, a1, t2, a2, t3, a3) \
+ if (VG_(defined_pre_reg_read)()) { \
+ PRRSN; \
+ PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); PRRAn(3,s,t3,a3); \
+ }
+#define PRE_REG_READ4(tr, s, t1, a1, t2, a2, t3, a3, t4, a4) \
+ if (VG_(defined_pre_reg_read)()) { \
+ PRRSN; \
+ PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); PRRAn(3,s,t3,a3); \
+ PRRAn(4,s,t4,a4); \
+ }
+#define PRE_REG_READ5(tr, s, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5) \
+ if (VG_(defined_pre_reg_read)()) { \
+ PRRSN; \
+ PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); PRRAn(3,s,t3,a3); \
+ PRRAn(4,s,t4,a4); PRRAn(5,s,t5,a5); \
+ }
+#define PRE_REG_READ6(tr, s, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5, t6, a6) \
+ if (VG_(defined_pre_reg_read)()) { \
+ PRRSN; \
+ PRRAn(1,s,t1,a1); PRRAn(2,s,t2,a2); PRRAn(3,s,t3,a3); \
+ PRRAn(4,s,t4,a4); PRRAn(5,s,t5,a5); PRRAn(6,s,t6,a6); \
+ }
+
+#define PRE_MEM_READ(zzname, zzaddr, zzlen) \
+ VG_TRACK( pre_mem_read, Vg_CoreSysCall, tid, zzname, zzaddr, zzlen)
+
+#define PRE_MEM_RASCIIZ(zzname, zzaddr) \
+ VG_TRACK( pre_mem_read_asciiz, Vg_CoreSysCall, tid, zzname, zzaddr)
+
+#define PRE_MEM_WRITE(zzname, zzaddr, zzlen) \
+ VG_TRACK( pre_mem_write, Vg_CoreSysCall, tid, zzname, zzaddr, zzlen)
+
+#define POST_MEM_WRITE(zzaddr, zzlen) \
+ VG_TRACK( post_mem_write, Vg_CoreSysCall, tid, zzaddr, zzlen)
+
+
+//////////////////////////////////////////////////////////
+
+#define TId ThreadId
+#define UW UWord
+
+extern void VG_(generic_PRE_sys_socketpair) ( TId, UW, UW, UW, UW );
+extern UWord VG_(generic_POST_sys_socketpair) ( TId, UW, UW, UW, UW, UW );
+extern UWord VG_(generic_POST_sys_socket) ( TId, UW );
+extern void VG_(generic_PRE_sys_bind) ( TId, UW, UW, UW );
+extern void VG_(generic_PRE_sys_accept) ( TId, UW, UW, UW );
+extern UWord VG_(generic_POST_sys_accept) ( TId, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_sendto) ( TId, UW, UW, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_send) ( TId, UW, UW, UW );
+extern void VG_(generic_PRE_sys_recvfrom) ( TId, UW, UW, UW, UW, UW, UW );
+extern void VG_(generic_POST_sys_recvfrom) ( TId, UW, UW, UW, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_recv) ( TId, UW, UW, UW );
+extern void VG_(generic_POST_sys_recv) ( TId, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_connect) ( TId, UW, UW, UW );
+extern void VG_(generic_PRE_sys_setsockopt) ( TId, UW, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_getsockopt) ( TId, UW, UW, UW, UW, UW );
+extern void VG_(generic_POST_sys_getsockopt) ( TId, UW, UW, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_getsockname) ( TId, UW, UW, UW );
+extern void VG_(generic_POST_sys_getsockname) ( TId, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_getpeername) ( TId, UW, UW, UW );
+extern void VG_(generic_POST_sys_getpeername) ( TId, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_sendmsg) ( TId, UW, UW );
+extern void VG_(generic_PRE_sys_recvmsg) ( TId, UW, UW );
+extern void VG_(generic_POST_sys_recvmsg) ( TId, UW, UW, UW );
+
+extern void VG_(generic_PRE_sys_semop) ( TId, UW, UW, UW );
+extern void VG_(generic_PRE_sys_semtimedop) ( TId, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_semctl) ( TId, UW, UW, UW, UW );
+extern void VG_(generic_POST_sys_semctl) ( TId, UW, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_msgsnd) ( TId, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_msgrcv) ( TId, UW, UW, UW, UW, UW );
+extern void VG_(generic_POST_sys_msgrcv) ( TId, UW, UW, UW, UW, UW, UW );
+extern void VG_(generic_PRE_sys_msgctl) ( TId, UW, UW, UW );
+extern void VG_(generic_POST_sys_msgctl) ( TId, UW, UW, UW, UW );
+extern UWord VG_(generic_PRE_sys_shmat) ( TId, UW, UW, UW );
+extern void VG_(generic_POST_sys_shmat) ( TId, UW, UW, UW, UW );
+extern Bool VG_(generic_PRE_sys_shmdt) ( TId, UW );
+extern void VG_(generic_POST_sys_shmdt) ( TId, UW, UW );
+extern void VG_(generic_PRE_sys_shmctl) ( TId, UW, UW, UW );
+extern void VG_(generic_POST_sys_shmctl) ( TId, UW, UW, UW, UW );
+
+#undef TId
+#undef UW
+
+#endif // __PRIV_SYSCALLS_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
+
diff --git a/coregrind/amd64-linux/syscall.S b/coregrind/m_syscalls/syscall-amd64-linux.S
similarity index 98%
rename from coregrind/amd64-linux/syscall.S
rename to coregrind/m_syscalls/syscall-amd64-linux.S
index c0a952d..591b50d 100644
--- a/coregrind/amd64-linux/syscall.S
+++ b/coregrind/m_syscalls/syscall-amd64-linux.S
@@ -1,6 +1,6 @@
##--------------------------------------------------------------------##
-##--- Support for doing system calls. amd64-linux/syscall.S ---##
+##--- Support for doing system calls. syscall-amd64-linux.S ---##
##--------------------------------------------------------------------##
/*
diff --git a/coregrind/arm-linux/syscall.S b/coregrind/m_syscalls/syscall-arm-linux.S
similarity index 100%
rename from coregrind/arm-linux/syscall.S
rename to coregrind/m_syscalls/syscall-arm-linux.S
diff --git a/coregrind/x86-linux/syscall.S b/coregrind/m_syscalls/syscall-x86-linux.S
similarity index 98%
rename from coregrind/x86-linux/syscall.S
rename to coregrind/m_syscalls/syscall-x86-linux.S
index 367c0ce..4333b3b 100644
--- a/coregrind/x86-linux/syscall.S
+++ b/coregrind/m_syscalls/syscall-x86-linux.S
@@ -1,6 +1,6 @@
##--------------------------------------------------------------------##
-##--- Support for doing system calls. x86-linux/syscall.S ---##
+##--- Support for doing system calls. syscall-x86-linux.S ---##
##--------------------------------------------------------------------##
/*
diff --git a/coregrind/amd64-linux/syscalls.c b/coregrind/m_syscalls/syscalls-amd64-linux.c
similarity index 98%
rename from coregrind/amd64-linux/syscalls.c
rename to coregrind/m_syscalls/syscalls-amd64-linux.c
index cb384d3..b8979c9 100644
--- a/coregrind/amd64-linux/syscalls.c
+++ b/coregrind/m_syscalls/syscalls-amd64-linux.c
@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------*/
-/*--- Platform-specific syscalls stuff. amd64-linux/syscalls.c ---*/
+/*--- Platform-specific syscalls stuff. syscalls-amd64-linux.c ---*/
/*--------------------------------------------------------------------*/
/*
@@ -30,8 +30,10 @@
#include "core.h"
#include "ume.h" /* for jmp_with_stack */
-#include "pub_core_sigframe.h"
#include "pub_core_aspacemgr.h"
+#include "pub_core_sigframe.h"
+#include "pub_core_syscalls.h"
+#include "priv_syscalls.h"
/* COPIED FROM /usr/include/asm-i386/prctl.h (amd64-linux) */
@@ -1156,7 +1158,7 @@
LINXY(__NR_io_cancel, sys_io_cancel), // 210
// (__NR_get_thread_area, sys_ni_syscall), // 211
// (__NR_lookup_dcookie, sys_lookup_dcookie), // 212
- LINXY(__NR_epoll_create, sys_epoll_create), // 213
+ // (__NR_epoll_create, sys_epoll_create), // 213
// (__NR_epoll_ctl_old, sys_ni_syscall), // 214
// (__NR_epoll_wait_old, sys_ni_syscall), // 215
@@ -1179,8 +1181,8 @@
// (__NR_clock_nanosleep, sys_clock_nanosleep),// 230
LINX_(__NR_exit_group, sys_exit_group), // 231
- LINXY(__NR_epoll_wait, sys_epoll_wait), // 232
- LINX_(__NR_epoll_ctl, sys_epoll_ctl), // 233
+ // (__NR_epoll_wait, sys_epoll_wait), // 232
+ // (__NR_epoll_ctl, sys_epoll_ctl), // 233
LINXY(__NR_tgkill, sys_tgkill), // 234
// (__NR_utimes, sys_utimes), // 235
@@ -1209,5 +1211,5 @@
//}
/*--------------------------------------------------------------------*/
-/*--- end amd64-linux/syscalls.c ---*/
+/*--- end ---*/
/*--------------------------------------------------------------------*/
diff --git a/coregrind/arm-linux/syscalls.c b/coregrind/m_syscalls/syscalls-arm-linux.c
similarity index 100%
rename from coregrind/arm-linux/syscalls.c
rename to coregrind/m_syscalls/syscalls-arm-linux.c
diff --git a/coregrind/linux/syscalls.c b/coregrind/m_syscalls/syscalls-linux.c
similarity index 98%
rename from coregrind/linux/syscalls.c
rename to coregrind/m_syscalls/syscalls-linux.c
index a664487..028701f 100644
--- a/coregrind/linux/syscalls.c
+++ b/coregrind/m_syscalls/syscalls-linux.c
@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------*/
-/*--- Linux-specific syscalls, etc. linux/syscalls.c ---*/
+/*--- Linux-specific syscalls, etc. syscalls-linux.c ---*/
/*--------------------------------------------------------------------*/
/*
@@ -30,6 +30,7 @@
#include "core.h"
#include "pub_core_aspacemgr.h"
+#include "priv_syscalls.h"
/* ---------------------------------------------------------------------
PRE/POST wrappers for arch-generic, Linux-specific syscalls
diff --git a/coregrind/x86-linux/syscalls.c b/coregrind/m_syscalls/syscalls-x86-linux.c
similarity index 98%
rename from coregrind/x86-linux/syscalls.c
rename to coregrind/m_syscalls/syscalls-x86-linux.c
index 2701306..201da46 100644
--- a/coregrind/x86-linux/syscalls.c
+++ b/coregrind/m_syscalls/syscalls-x86-linux.c
@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------*/
-/*--- Platform-specific syscalls stuff. x86-linux/syscalls.c ---*/
+/*--- Platform-specific syscalls stuff. syscalls-x86-linux.c ---*/
/*--------------------------------------------------------------------*/
/*
@@ -35,8 +35,10 @@
#include "core.h"
#include "ume.h" /* for jmp_with_stack */
-#include "pub_core_sigframe.h"
#include "pub_core_aspacemgr.h"
+#include "pub_core_sigframe.h"
+#include "pub_core_syscalls.h"
+#include "priv_syscalls.h"
/* ---------------------------------------------------------------------
diff --git a/coregrind/vg_syscalls.c b/coregrind/m_syscalls/syscalls.c
similarity index 99%
rename from coregrind/vg_syscalls.c
rename to coregrind/m_syscalls/syscalls.c
index d0a34b3..118e956 100644
--- a/coregrind/vg_syscalls.c
+++ b/coregrind/m_syscalls/syscalls.c
@@ -1,6 +1,6 @@
/*--------------------------------------------------------------------*/
-/*--- Handle system calls. vg_syscalls.c ---*/
+/*--- Handle system calls. syscalls.c ---*/
/*--------------------------------------------------------------------*/
/*
@@ -29,8 +29,10 @@
*/
#include "core.h"
-#include "pub_core_stacktrace.h"
#include "pub_core_aspacemgr.h"
+#include "pub_core_stacktrace.h"
+#include "pub_core_syscalls.h"
+#include "priv_syscalls.h"
/* All system calls are channelled through here, doing two things:
@@ -40,7 +42,7 @@
* perform the syscall, usually by passing it along to the kernel
unmodified.
- A magical piece of assembly code, VG_(do_syscall)(), in vg_syscall.S
+ A magical piece of assembly code, VG_(do_syscall)(), in syscall-$PLATFORM.S
does the tricky bit of passing a syscall to the kernel, whilst
having the simulator retain control.
*/
diff --git a/coregrind/pub_core_syscalls.h b/coregrind/pub_core_syscalls.h
new file mode 100644
index 0000000..1830d8b
--- /dev/null
+++ b/coregrind/pub_core_syscalls.h
@@ -0,0 +1,69 @@
+
+/*--------------------------------------------------------------------*/
+/*--- System call wrappers, etc. pub_core_syscalls.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_SYSCALLS_H
+#define __PUB_CORE_SYSCALLS_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module contains all the syscall junk: mostly wrappers,
+// but also the code that executes them, and related stuff.
+//--------------------------------------------------------------------
+
+extern HChar* VG_(resolve_filename_nodup)(Int fd);
+extern HChar* VG_(resolve_filename)(Int fd);
+
+extern void VG_(client_syscall) ( ThreadId tid );
+
+extern void VG_(post_syscall) ( ThreadId tid );
+
+// Fix up the thread's state because a syscall may have been
+// interrupted with a signal. Returns True if the syscall completed
+// (either interrupted or finished normally), or False if it was
+// restarted (or the signal didn't actually interrupt a syscall).
+extern void VGA_(interrupted_syscall)(ThreadId tid,
+ struct vki_ucontext *uc,
+ Bool restart);
+
+extern Bool VG_(is_kerror) ( Word res );
+
+/* Internal atfork handlers */
+typedef void (*vg_atfork_t)(ThreadId);
+extern void VG_(atfork)(vg_atfork_t pre, vg_atfork_t parent, vg_atfork_t child);
+
+/* fd leakage calls. */
+extern void VG_(init_preopened_fds) ( void );
+extern void VG_(show_open_fds) ( void );
+
+#endif // __PUB_CORE_SYSCALLS_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
+
diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c
index fdb3b45..3bc1792 100644
--- a/coregrind/vg_main.c
+++ b/coregrind/vg_main.c
@@ -32,10 +32,11 @@
#include "core.h"
#include "ume.h"
-#include "pub_core_execontext.h"
-#include "pub_core_errormgr.h"
-#include "pub_core_debuglog.h"
#include "pub_core_aspacemgr.h"
+#include "pub_core_debuglog.h"
+#include "pub_core_errormgr.h"
+#include "pub_core_execontext.h"
+#include "pub_core_syscalls.h"
#include <dirent.h>
#include <dlfcn.h>
diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c
index ca16b86..caf5af2 100644
--- a/coregrind/vg_mylibc.c
+++ b/coregrind/vg_mylibc.c
@@ -31,9 +31,10 @@
*/
#include "core.h"
-#include "pub_core_stacktrace.h"
-#include "pub_core_debuglog.h" /* VG_(debugLog_vprintf) */
#include "pub_core_aspacemgr.h"
+#include "pub_core_debuglog.h" /* VG_(debugLog_vprintf) */
+#include "pub_core_stacktrace.h"
+#include "pub_core_syscalls.h"
/* ---------------------------------------------------------------------
diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c
index d344444..75dec98 100644
--- a/coregrind/vg_scheduler.c
+++ b/coregrind/vg_scheduler.c
@@ -60,8 +60,9 @@
VG_USERREQ__DISCARD_TRANSLATIONS, and others */
#include "core.h"
-#include "pub_core_stacktrace.h"
#include "pub_core_errormgr.h"
+#include "pub_core_stacktrace.h"
+#include "pub_core_syscalls.h"
/* ---------------------------------------------------------------------
Types and globals for the scheduler.
@@ -936,18 +937,6 @@
VG_(memcpy)( area, (void*)(((Addr)&(tst->arch.vex_shadow)) + offset), size);
}
-
-void VG_(set_return_from_syscall_shadow) ( ThreadId tid, UWord ret_shadow )
-{
- VG_(threads)[tid].arch.vex_shadow.VGP_SYSCALL_RET = ret_shadow;
-}
-
-UInt VG_(get_exit_status_shadow) ( ThreadId tid )
-{
- return VG_(threads)[tid].arch.vex_shadow.VGP_SYSCALL_ARG1;
-}
-
-
/* ---------------------------------------------------------------------
Handle client requests.
------------------------------------------------------------------ */
diff --git a/coregrind/vg_signals.c b/coregrind/vg_signals.c
index c5b2f5a..d763d67 100644
--- a/coregrind/vg_signals.c
+++ b/coregrind/vg_signals.c
@@ -81,9 +81,10 @@
#include "core.h"
+#include "pub_core_aspacemgr.h"
#include "pub_core_errormgr.h"
#include "pub_core_sigframe.h"
-#include "pub_core_aspacemgr.h"
+#include "pub_core_syscalls.h"
/* Define to give more sanity checking for signals. */
diff --git a/coregrind/x86-linux/Makefile.am b/coregrind/x86-linux/Makefile.am
index b061319..d4cf084 100644
--- a/coregrind/x86-linux/Makefile.am
+++ b/coregrind/x86-linux/Makefile.am
@@ -12,9 +12,7 @@
libplatform_a_SOURCES = \
core_platform.c \
- ldt.c \
- syscall.S \
- syscalls.c
+ ldt.c
if USE_PIE
libplatform_a_CFLAGS = $(AM_CFLAGS) -fpie
diff --git a/coregrind/x86-linux/core_platform.h b/coregrind/x86-linux/core_platform.h
index 2726a74..91ea35a 100644
--- a/coregrind/x86-linux/core_platform.h
+++ b/coregrind/x86-linux/core_platform.h
@@ -36,27 +36,6 @@
//#include "platform_arch.h" // platform-specific tool stuff
/* ---------------------------------------------------------------------
- Dealing with registers
- ------------------------------------------------------------------ */
-
-// Accessors for the ThreadArchState
-#define VGP_SYSCALL_NUM guest_EAX
-#define VGP_SYSCALL_ARG1 guest_EBX
-#define VGP_SYSCALL_ARG2 guest_ECX
-#define VGP_SYSCALL_ARG3 guest_EDX
-#define VGP_SYSCALL_ARG4 guest_ESI
-#define VGP_SYSCALL_ARG5 guest_EDI
-#define VGP_SYSCALL_ARG6 guest_EBP
-#define VGP_SYSCALL_RET guest_EAX
-
-// Setting a syscall result
-#define VGP_SET_SYSCALL_RESULT(regs, val) ((regs).vex.guest_EAX = (val))
-
-// For informing tools that a syscall result has been set.
-#define VGP_TRACK_SYSCALL_RETVAL(zztid) \
- VG_TRACK( post_reg_write, Vg_CoreSysCall, zztid, O_SYSCALL_RET, sizeof(UWord) );
-
-/* ---------------------------------------------------------------------
Exports of vg_ldt.c
------------------------------------------------------------------ */