Add support for sys_pivot_root and sys_unshare.  Patch from
Steven Stewart-Gallus <sstewartgallus00@mylangara.bc.ca>.
n-i-bz (patch on dev@, 27 Aug 2014)



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14494 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_syswrap/priv_syswrap-linux.h b/coregrind/m_syswrap/priv_syswrap-linux.h
index 40c43a0..f7b6b90 100644
--- a/coregrind/m_syswrap/priv_syswrap-linux.h
+++ b/coregrind/m_syswrap/priv_syswrap-linux.h
@@ -87,6 +87,7 @@
 DECL_TEMPLATE(linux, sys_vhangup);
 DECL_TEMPLATE(linux, sys_sysinfo);
 DECL_TEMPLATE(linux, sys_personality);
+DECL_TEMPLATE(linux, sys_pivot_root);
 DECL_TEMPLATE(linux, sys_sysctl);
 DECL_TEMPLATE(linux, sys_prctl);
 DECL_TEMPLATE(linux, sys_sendfile);
@@ -232,6 +233,8 @@
 DECL_TEMPLATE(linux, sys_sched_setaffinity);
 DECL_TEMPLATE(linux, sys_sched_getaffinity);
 
+DECL_TEMPLATE(linux, sys_unshare);
+
 // These ones have different parameters and/or return values on Darwin.
 // Also, some archs on Linux do not match the generic wrapper for sys_pipe.
 DECL_TEMPLATE(linux, sys_munlockall);
diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c
index 5999270..92148a8 100644
--- a/coregrind/m_syswrap/syswrap-amd64-linux.c
+++ b/coregrind/m_syswrap/syswrap-amd64-linux.c
@@ -873,7 +873,7 @@
    LINX_(__NR_vhangup,           sys_vhangup),        // 153 
    //   (__NR_modify_ldt,        sys_modify_ldt),     // 154 
 
-   //   (__NR_pivot_root,        sys_pivot_root),     // 155 
+   LINX_(__NR_pivot_root,        sys_pivot_root),     // 155
    LINXY(__NR__sysctl,           sys_sysctl),         // 156 
    LINXY(__NR_prctl,             sys_prctl),          // 157 
    PLAX_(__NR_arch_prctl,	 sys_arch_prctl),     // 158 
@@ -1013,7 +1013,7 @@
 
    LINX_(__NR_pselect6,		 sys_pselect6),         // 270
    LINXY(__NR_ppoll,		 sys_ppoll),            // 271
-//   LINX_(__NR_unshare,		 sys_unshare),          // 272
+   LINX_(__NR_unshare,		 sys_unshare),          // 272
    LINX_(__NR_set_robust_list,	 sys_set_robust_list),  // 273
    LINXY(__NR_get_robust_list,	 sys_get_robust_list),  // 274
 
diff --git a/coregrind/m_syswrap/syswrap-arm-linux.c b/coregrind/m_syswrap/syswrap-arm-linux.c
index db17e1d..b2ba414 100644
--- a/coregrind/m_syswrap/syswrap-arm-linux.c
+++ b/coregrind/m_syswrap/syswrap-arm-linux.c
@@ -1022,7 +1022,7 @@
 
    LINX_(__NR_setfsuid32,        sys_setfsuid),       // 215
    LINX_(__NR_setfsgid32,        sys_setfsgid),       // 216
-//zz    //   (__NR_pivot_root,        sys_pivot_root),     // 217 */Linux
+   LINX_(__NR_pivot_root,        sys_pivot_root),     // 217
    GENXY(__NR_mincore,           sys_mincore),        // 218
    GENX_(__NR_madvise,           sys_madvise),        // 219
 
@@ -1161,7 +1161,7 @@
    LINXY(__NR_shmctl,            sys_shmctl),         // 308 
 //   LINX_(__NR_pselect6,       sys_pselect6),         //
 
-//   LINX_(__NR_unshare,       sys_unshare),          // 310
+   LINX_(__NR_unshare,       sys_unshare),          // 310
    LINX_(__NR_set_robust_list,    sys_set_robust_list),  // 311
    LINXY(__NR_get_robust_list,    sys_get_robust_list),  // 312
 //   LINX_(__NR_splice,            sys_ni_syscall),       // 313
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
index bcd00f1..9f6623e 100644
--- a/coregrind/m_syswrap/syswrap-linux.c
+++ b/coregrind/m_syswrap/syswrap-linux.c
@@ -554,6 +554,18 @@
    PRE_MEM_RASCIIZ( "umount2(path)", ARG1);
 }
 
+/* Not actually wrapped by GLibc but does things with the system
+ * mounts so it is put here.
+ */
+PRE(sys_pivot_root)
+{
+   PRINT("sys_pivot_root ( %s %s )", (HChar*)ARG1, (HChar*)ARG2);
+   PRE_REG_READ2(int, "pivot_root", char *, new_root, char *, old_root);
+   PRE_MEM_RASCIIZ( "pivot_root(new_root)", ARG1);
+   PRE_MEM_RASCIIZ( "pivot_root(old_root)", ARG2);
+}
+
+
 /* ---------------------------------------------------------------------
    16- and 32-bit uid/gid wrappers
    ------------------------------------------------------------------ */
@@ -2749,6 +2761,12 @@
    POST_MEM_WRITE(ARG3, ARG2);
 }
 
+PRE(sys_unshare)
+{
+   PRINT("sys_unshare ( %ld )", ARG1);
+   PRE_REG_READ1(int, "unshare", int, flags);
+}
+
 /* ---------------------------------------------------------------------
    miscellaneous wrappers
    ------------------------------------------------------------------ */
diff --git a/coregrind/m_syswrap/syswrap-mips64-linux.c b/coregrind/m_syswrap/syswrap-mips64-linux.c
index 799836d..c1154a2 100644
--- a/coregrind/m_syswrap/syswrap-mips64-linux.c
+++ b/coregrind/m_syswrap/syswrap-mips64-linux.c
@@ -782,7 +782,7 @@
    GENX_ (__NR_mlockall, sys_mlockall),
    LINX_ (__NR_munlockall, sys_munlockall),
    LINX_ (__NR_vhangup, sys_vhangup),
-   /* GENX_(__NR_pivot_root,sys_pivot_root), */
+   LINX_ (__NR_pivot_root,sys_pivot_root),
    LINXY (__NR__sysctl, sys_sysctl),
    LINXY (__NR_prctl, sys_prctl),
    LINXY (__NR_adjtimex, sys_adjtimex),
diff --git a/coregrind/m_syswrap/syswrap-ppc32-linux.c b/coregrind/m_syswrap/syswrap-ppc32-linux.c
index b7ab7b6..2e5436d 100644
--- a/coregrind/m_syswrap/syswrap-ppc32-linux.c
+++ b/coregrind/m_syswrap/syswrap-ppc32-linux.c
@@ -1103,7 +1103,7 @@
 // __NR_multiplexer                                           // 201
 
    GENXY(__NR_getdents64,        sys_getdents64),        // 202
-//..    //   (__NR_pivot_root,        sys_pivot_root),        // 203 */Linux
+   LINX_(__NR_pivot_root,        sys_pivot_root),        // 203
    LINXY(__NR_fcntl64,           sys_fcntl64),           // 204
    GENX_(__NR_madvise,           sys_madvise),           // 205
    GENXY(__NR_mincore,           sys_mincore),           // 206
diff --git a/coregrind/m_syswrap/syswrap-ppc64-linux.c b/coregrind/m_syswrap/syswrap-ppc64-linux.c
index d660833..d775f9b 100644
--- a/coregrind/m_syswrap/syswrap-ppc64-linux.c
+++ b/coregrind/m_syswrap/syswrap-ppc64-linux.c
@@ -1022,7 +1022,7 @@
 // _____(__NR_pciconfig_iobase,  sys_pciconfig_iobase),   // 200
 // _____(__NR_multiplexer,       sys_multiplexer),        // 201
    GENXY(__NR_getdents64,        sys_getdents64),         // 202
-// _____(__NR_pivot_root,        sys_pivot_root),         // 203
+   LINX_(__NR_pivot_root,        sys_pivot_root),         // 203
    LINXY(__NR_fcntl64,           sys_fcntl64),            // 204 !!!!?? 32bit only */
 
    GENX_(__NR_madvise,           sys_madvise),            // 205
diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c
index c51a9f4..2ba73f9 100644
--- a/coregrind/m_syswrap/syswrap-x86-linux.c
+++ b/coregrind/m_syswrap/syswrap-x86-linux.c
@@ -1655,7 +1655,7 @@
 
    LINX_(__NR_setfsuid32,        sys_setfsuid),       // 215
    LINX_(__NR_setfsgid32,        sys_setfsgid),       // 216
-//zz    //   (__NR_pivot_root,        sys_pivot_root),     // 217 */Linux
+   LINX_(__NR_pivot_root,        sys_pivot_root),     // 217
    GENXY(__NR_mincore,           sys_mincore),        // 218
    GENX_(__NR_madvise,           sys_madvise),        // 219
 
@@ -1767,7 +1767,7 @@
    LINX_(__NR_pselect6,		 sys_pselect6),         // 308
    LINXY(__NR_ppoll,		 sys_ppoll),            // 309
 
-//   LINX_(__NR_unshare,		 sys_unshare),          // 310
+   LINX_(__NR_unshare,		 sys_unshare),          // 310
    LINX_(__NR_set_robust_list,	 sys_set_robust_list),  // 311
    LINXY(__NR_get_robust_list,	 sys_get_robust_list),  // 312
    LINX_(__NR_splice,            sys_splice),           // 313