Converted fork(), and added a separate regtest for it.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2961 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_syscalls.c b/coregrind/vg_syscalls.c
index 38b936d..bccd070 100644
--- a/coregrind/vg_syscalls.c
+++ b/coregrind/vg_syscalls.c
@@ -2111,10 +2111,15 @@
static vki_sigset_t fork_saved_mask;
-PRE(fork)
+// In Linux, the sys_fork() function varies across architectures, but we
+// ignore the various args it gets, and so it looks arch-neutral. Hmm.
+PREx(sys_fork, 0)
{
vki_sigset_t mask;
+ PRINT("sys_fork ( )");
+ PRE_REG_READ0(long, "fork");
+
vg_assert(VG_(gettid)() == VG_(main_pid));
/* Block all signals during fork, so that we can fix things up in
@@ -2122,13 +2127,10 @@
VG_(sigfillset)(&mask);
VG_(sigprocmask)(VKI_SIG_SETMASK, &mask, &fork_saved_mask);
- /* pid_t fork(void); */
- PRINT("fork ()");
-
do_atfork_pre(tid);
}
-POST(fork)
+POST(sys_fork)
{
if (res == 0) {
do_atfork_child(tid);
@@ -2160,9 +2162,9 @@
(arg1 == (VKI_CLONE_CHILD_CLEARTID|VKI_CLONE_CHILD_SETTID|VKI_SIGCHLD)
|| arg1 == (VKI_CLONE_PARENT_SETTID|VKI_SIGCHLD)))
{
- before_fork(tid, tst);
+ before_sys_fork(tid, tst);
set_result( VG_(do_syscall)(SYSNO, arg1, arg2, arg3, arg4, arg5) );
- after_fork(tid, tst);
+ after_sys_fork(tid, tst);
} else {
VG_(unimplemented)
("clone(): not supported by Valgrind.\n "
@@ -5806,7 +5808,7 @@
static const struct sys_info sys_info[] = {
// 0 is restart_syscall
SYSX_(__NR_exit, sys_exit), // 1 * P
- SYSBA(fork, 0), // 2 sys_fork P
+ SYSXY(__NR_fork, sys_fork), // 2 (quasi-generic...) P
SYSXY(__NR_read, sys_read), // 3 * P
SYSX_(__NR_write, sys_write), // 4 * P
diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am
index 3d99c36..81bce31 100644
--- a/memcheck/tests/Makefile.am
+++ b/memcheck/tests/Makefile.am
@@ -3,6 +3,8 @@
noinst_SCRIPTS = filter_allocs filter_leak_check_size \
filter_stderr filter_stderr_backtrace
+noinst_HEADERS = scalar.h
+
EXTRA_DIST = $(noinst_SCRIPTS) \
badaddrvalue.stderr.exp \
badaddrvalue.stdout.exp badaddrvalue.vgtest \
@@ -52,7 +54,8 @@
realloc2.stderr.exp realloc2.vgtest \
realloc3.stderr.exp realloc3.vgtest \
scalar.stderr.exp scalar.vgtest scalar.supp \
- scalar_supp.stderr.exp scalar_supp.vgtest scalar_supp.c \
+ scalar_fork.stderr.exp scalar_fork.vgtest \
+ scalar_supp.stderr.exp scalar_supp.vgtest \
sigaltstack.stderr.exp sigaltstack.vgtest \
signal2.stderr.exp \
signal2.stdout.exp signal2.vgtest \
@@ -81,7 +84,8 @@
memalign_test memalign2 memcmptest mempool mmaptest \
nanoleak new_nothrow \
null_socket overlap \
- realloc1 realloc2 realloc3 scalar scalar_supp sigaltstack signal2 \
+ realloc1 realloc2 realloc3 scalar scalar_fork \
+ scalar_supp sigaltstack signal2 \
str_tester supp1 supp2 suppfree \
trivialleak weirdioctl \
mismatches new_override metadata threadederrno \
@@ -134,6 +138,7 @@
realloc2_SOURCES = realloc2.c
realloc3_SOURCES = realloc3.c
scalar_SOURCES = scalar.c
+scalar_fork_SOURCES = scalar_fork.c
scalar_supp_SOURCES = scalar_supp.c
signal2_SOURCES = signal2.c
supp1_SOURCES = supp.c
diff --git a/memcheck/tests/scalar.c b/memcheck/tests/scalar.c
index 0cb0fd6..da993ba 100644
--- a/memcheck/tests/scalar.c
+++ b/memcheck/tests/scalar.c
@@ -1,23 +1,4 @@
-#include <assert.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
-
-// Thorough syscall scalar arg checking. Also serves as thorough checking
-// for (very) basic syscall use. Generally not trying to do anything
-// meaningful with the syscalls.
-
-#define GO(__NR_xxx, s) \
- fprintf(stderr, "-----------------------------------------------------\n" \
- "%3d:%20s %s\n" \
- "-----------------------------------------------------\n", \
- __NR_xxx, #__NR_xxx, s);
-
-#define SY syscall
+#include "scalar.h"
int main(void)
{
diff --git a/memcheck/tests/scalar.h b/memcheck/tests/scalar.h
new file mode 100644
index 0000000..70f779c
--- /dev/null
+++ b/memcheck/tests/scalar.h
@@ -0,0 +1,22 @@
+#include <assert.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+
+// Thorough syscall scalar arg checking. Also serves as thorough checking
+// for (very) basic syscall use. Generally not trying to do anything
+// meaningful with the syscalls.
+
+#define GO(__NR_xxx, s) \
+ fprintf(stderr, "-----------------------------------------------------\n" \
+ "%3d:%20s %s\n" \
+ "-----------------------------------------------------\n", \
+ __NR_xxx, #__NR_xxx, s);
+
+#define SY syscall
+
+