The attached patch allows clone() without VKI_CLONE_FS
for both a fork-like clone() and a thread-like clone().
The patch is against valgrind-3.2.3, and includes an earlier
patch of a couple months ago that did not handle both cases.

-- 
John Reiser, [EMAIL PROTECTED]
diff -Nur valgrind-3.2.3/coregrind/m_syswrap/priv_syswrap-linux.h valgrind-3.2.3.new/coregrind/m_syswrap/priv_syswrap-linux.h
--- valgrind-3.2.3/coregrind/m_syswrap/priv_syswrap-linux.h	2007-01-07 23:43:12.000000000 -0800
+++ valgrind-3.2.3.new/coregrind/m_syswrap/priv_syswrap-linux.h	2007-08-28 09:35:59.000000000 -0700
@@ -38,7 +38,7 @@
 extern Addr ML_(allocstack)            ( ThreadId tid );
 extern void ML_(call_on_new_stack_0_1) ( Addr stack, Addr retaddr,
 			                 void (*f)(Word), Word arg1 );
-extern SysRes ML_(do_fork_clone) ( ThreadId tid, UInt flags,
+extern SysRes ML_(do_fork_clone) ( ThreadId tid, UInt flags, Addr child_esp,
                                    Int* parent_tidptr, Int* child_tidptr );
 
 
diff -Nur valgrind-3.2.3/coregrind/m_syswrap/syswrap-amd64-linux.c valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-amd64-linux.c
--- valgrind-3.2.3/coregrind/m_syswrap/syswrap-amd64-linux.c	2007-01-17 19:26:53.000000000 -0800
+++ valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-amd64-linux.c	2007-08-28 09:35:33.000000000 -0700
@@ -422,6 +422,7 @@
       SET_STATUS_from_SysRes(
          ML_(do_fork_clone)(tid,
                        cloneflags,      /* flags */
+                       (Addr)ARG2,      /* child ESP */
                        (Int *)ARG3,     /* parent_tidptr */
                        (Int *)ARG4));   /* child_tidptr */
       break;
diff -Nur valgrind-3.2.3/coregrind/m_syswrap/syswrap-linux.c valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-linux.c
--- valgrind-3.2.3/coregrind/m_syswrap/syswrap-linux.c	2007-01-07 23:43:12.000000000 -0800
+++ valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-linux.c	2007-12-01 08:33:26.000000000 -0800
@@ -292,7 +292,7 @@
 
 
 /* Do a clone which is really a fork() */
-SysRes ML_(do_fork_clone) ( ThreadId tid, UInt flags,
+SysRes ML_(do_fork_clone) ( ThreadId tid, UInt flags, Addr child_esp,
                             Int* parent_tidptr, Int* child_tidptr )
 {
    vki_sigset_t fork_saved_mask;
@@ -300,8 +300,10 @@
    SysRes       res;
 
    if (flags & (VKI_CLONE_SETTLS | VKI_CLONE_FS | VKI_CLONE_VM 
-                | VKI_CLONE_FILES | VKI_CLONE_VFORK))
+                /*| VKI_CLONE_FILES*/ | VKI_CLONE_VFORK)) {
+      VG_(message)(Vg_DebugMsg, "do_fork_clone EINVAL  flags=0x%x\n", flags);
       return VG_(mk_SysRes_Error)( VKI_EINVAL );
+   }
 
    /* Block all signals during fork, so that we can fix things up in
       the child without being interrupted. */
@@ -326,6 +328,11 @@
 
    if (!res.isError && res.val == 0) {
       /* child */
+      if (child_esp != 0) {
+         ThreadState *const ctst = VG_(get_ThreadState)(tid);
+         ctst->arch.vex.guest_ESP = child_esp;
+      }
+
       VG_(do_atfork_child)(tid);
 
       /* restore signal mask */
diff -Nur valgrind-3.2.3/coregrind/m_syswrap/syswrap-ppc32-linux.c valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-ppc32-linux.c
--- valgrind-3.2.3/coregrind/m_syswrap/syswrap-ppc32-linux.c	2007-01-02 06:52:27.000000000 -0800
+++ valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-ppc32-linux.c	2007-08-28 09:36:12.000000000 -0700
@@ -995,6 +995,7 @@
       SET_STATUS_from_SysRes(
          ML_(do_fork_clone)(tid,
                        cloneflags,      /* flags */
+                       (Addr)ARG2,      /* child SP */
                        (Int *)ARG3,     /* parent_tidptr */
                        (Int *)ARG5));   /* child_tidptr */
       break;
diff -Nur valgrind-3.2.3/coregrind/m_syswrap/syswrap-ppc64-linux.c valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-ppc64-linux.c
--- valgrind-3.2.3/coregrind/m_syswrap/syswrap-ppc64-linux.c	2007-01-02 06:52:27.000000000 -0800
+++ valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-ppc64-linux.c	2007-08-28 09:35:02.000000000 -0700
@@ -973,6 +973,7 @@
       SET_STATUS_from_SysRes(
          ML_(do_fork_clone)(tid,
                        cloneflags,      /* flags */
+                       (Addr)ARG2,      /* child SP */
                        (Int *)ARG3,     /* parent_tidptr */
                        (Int *)ARG5));   /* child_tidptr */
       break;
diff -Nur valgrind-3.2.3/coregrind/m_syswrap/syswrap-x86-linux.c valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-x86-linux.c
--- valgrind-3.2.3/coregrind/m_syswrap/syswrap-x86-linux.c	2007-01-07 23:43:12.000000000 -0800
+++ valgrind-3.2.3.new/coregrind/m_syswrap/syswrap-x86-linux.c	2007-12-01 08:37:07.000000000 -0800
@@ -815,7 +815,6 @@
 {
    UInt cloneflags;
 
-   PRINT("sys_clone ( %x, %p, %p, %p, %p )",ARG1,ARG2,ARG3,ARG4,ARG5);
    PRE_REG_READ5(int, "clone",
                  unsigned long, flags,
                  void *, child_stack,
@@ -882,8 +881,11 @@
    }
 
    /* Only look at the flags we really care about */
-   switch (cloneflags & (VKI_CLONE_VM | VKI_CLONE_FS 
+   switch (cloneflags & (VKI_CLONE_VM | VKI_CLONE_FS
                          | VKI_CLONE_FILES | VKI_CLONE_VFORK)) {
+   case VKI_CLONE_VM                | VKI_CLONE_FILES:
+      /*VG_(message)(Vg_UserMsg, "Warning: clone() without CLONE_FS: 0x%x", ARG1);*/
+      /* fall through */
    case VKI_CLONE_VM | VKI_CLONE_FS | VKI_CLONE_FILES:
       /* thread creation */
       SET_STATUS_from_SysRes(
@@ -895,14 +897,20 @@
                   (vki_modify_ldt_t *)ARG4)); /* set_tls */
       break;
 
+   case VKI_CLONE_FILES:  /* note no CLONE_VM, ==> fork */
+      /*VG_(message)(Vg_UserMsg, "Warning: fork clone() without CLONE_FS: 0x%x", ARG1);*/
+      goto do_fork;
+
    case VKI_CLONE_VFORK | VKI_CLONE_VM: /* vfork */
       /* FALLTHROUGH - assume vfork == fork */
       cloneflags &= ~(VKI_CLONE_VFORK | VKI_CLONE_VM);
 
+do_fork:
    case 0: /* plain fork */
       SET_STATUS_from_SysRes(
          ML_(do_fork_clone)(tid,
                        cloneflags,      /* flags */
+                       (Addr)ARG2,      /* child ESP */
                        (Int *)ARG3,     /* parent_tidptr */
                        (Int *)ARG5));   /* child_tidptr */
       break;
@@ -1303,8 +1311,6 @@
    // pagesize or 4K-size units in offset?  For ppc32/64-linux, this is
    // 4K-sized.  Assert that the page size is 4K here for safety.
    vg_assert(VKI_PAGE_SIZE == 4096);
-   PRINT("sys_mmap2 ( %p, %llu, %d, %d, %d, %d )",
-         ARG1, (ULong)ARG2, ARG3, ARG4, ARG5, ARG6 );
    PRE_REG_READ6(long, "mmap2",
                  unsigned long, start, unsigned long, length,
                  unsigned long, prot,  unsigned long, flags,
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to