Converted sigprocmask and rt_sigprocmask.

While doing so, fixed bug #93328, by using the right sized types in
sigprocmask(), and converting them as necessary.  Added a regression test for
it too.

(partly) MERGE TO STABLE


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3013 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/memcheck/tests/.cvsignore b/memcheck/tests/.cvsignore
index 04d1dab..b1dfc52 100644
--- a/memcheck/tests/.cvsignore
+++ b/memcheck/tests/.cvsignore
@@ -55,6 +55,7 @@
 scalar_vfork
 sigaltstack
 signal2
+sigprocmask
 str_tester
 supp1
 supp2
diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am
index 2c6f9c2..9328cc2 100644
--- a/memcheck/tests/Makefile.am
+++ b/memcheck/tests/Makefile.am
@@ -59,8 +59,8 @@
 	scalar_supp.stderr.exp scalar_supp.vgtest scalar_supp.supp \
 	scalar_vfork.stderr.exp scalar_vfork.vgtest \
 	sigaltstack.stderr.exp sigaltstack.vgtest \
-	signal2.stderr.exp \
-	signal2.stdout.exp signal2.vgtest \
+	signal2.stderr.exp signal2.stdout.exp signal2.vgtest \
+	sigprocmask.stderr.exp sigprocmask.vgtest \
 	str_tester.stderr.exp str_tester.vgtest \
 	supp1.stderr.exp supp1.vgtest \
 	supp2.stderr.exp supp2.vgtest \
@@ -88,7 +88,7 @@
 	null_socket overlap \
 	realloc1 realloc2 realloc3 \
 	scalar scalar_exit_group scalar_fork scalar_supp scalar_vfork \
-	sigaltstack signal2 \
+	sigaltstack signal2 sigprocmask \
 	str_tester supp1 supp2 suppfree \
 	trivialleak weirdioctl	\
 	mismatches new_override metadata threadederrno \
@@ -146,6 +146,7 @@
 scalar_supp_SOURCES 	= scalar_supp.c
 scalar_vfork_SOURCES 	= scalar_vfork.c
 signal2_SOURCES 	= signal2.c
+sigprocmask_SOURCES 	= sigprocmask.c
 supp1_SOURCES 		= supp.c
 supp2_SOURCES 		= supp.c
 suppfree_SOURCES 	= suppfree.c
diff --git a/memcheck/tests/scalar.c b/memcheck/tests/scalar.c
index 0555207..d2f9098 100644
--- a/memcheck/tests/scalar.c
+++ b/memcheck/tests/scalar.c
@@ -1,3 +1,4 @@
+#include "../memcheck.h"
 #include "scalar.h"
 
 int main(void)
@@ -541,8 +542,10 @@
    SY(__NR_mprotect, x0, x0, x0);
 
    // __NR_sigprocmask 126
- //GO(__NR_sigprocmask, ".s .m");
- //SY(__NR_sigprocmask);
+   {
+      GO(__NR_sigprocmask, "3s 2m");
+      SY(__NR_sigprocmask, x0, x0+&px[1], x0+&px[1]);
+   }
 
    // __NR_create_module 127
    GO(__NR_create_module, "ni");
@@ -737,8 +740,8 @@
    SY(__NR_rt_sigaction, x0, x0+1, x0+1, x0);
 
    // __NR_rt_sigprocmask 175
- //GO(__NR_rt_sigprocmask, ".s .m");
- //SY(__NR_rt_sigprocmask);
+   GO(__NR_rt_sigprocmask, "4s 2m");
+   SY(__NR_rt_sigprocmask, x0, x0+1, x0+1, x0);
 
    // __NR_rt_sigpending 176
  //GO(__NR_rt_sigpending, ".s .m");
diff --git a/memcheck/tests/scalar.stderr.exp b/memcheck/tests/scalar.stderr.exp
index d3415d2..0230c86 100644
--- a/memcheck/tests/scalar.stderr.exp
+++ b/memcheck/tests/scalar.stderr.exp
@@ -1601,6 +1601,40 @@
    by 0x........: __libc_start_main (...libc...)
    by 0x........: ...
 -----------------------------------------------------
+126:    __NR_sigprocmask 3s 2m
+-----------------------------------------------------
+
+Syscall param sigprocmask(how) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param sigprocmask(set) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param sigprocmask(oldset) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param sigprocmask(set) points to unaddressable byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+ Address 0x........ is 0 bytes after a block of size 4 alloc'd
+   at 0x........: malloc (vg_replace_malloc.c:...)
+   by 0x........: main (scalar.c:7)
+
+Syscall param sigprocmask(oldset) points to unaddressable byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+ Address 0x........ is 0 bytes after a block of size 4 alloc'd
+   at 0x........: malloc (vg_replace_malloc.c:...)
+   by 0x........: main (scalar.c:7)
+-----------------------------------------------------
 127:  __NR_create_module ni
 -----------------------------------------------------
 -----------------------------------------------------
@@ -2289,6 +2323,41 @@
    by 0x........: ...
  Address 0x........ is not stack'd, malloc'd or (recently) free'd
 -----------------------------------------------------
+175: __NR_rt_sigprocmask 4s 2m
+-----------------------------------------------------
+
+Syscall param rt_sigprocmask(how) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param rt_sigprocmask(set) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param rt_sigprocmask(oldset) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param rt_sigprocmask(sigsetsize) contains uninitialised byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+
+Syscall param rt_sigprocmask(set) points to unaddressable byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
+
+Syscall param rt_sigprocmask(oldset) points to unaddressable byte(s)
+   at 0x........: syscall (in /...libc...)
+   by 0x........: __libc_start_main (...libc...)
+   by 0x........: ...
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
+-----------------------------------------------------
 182:          __NR_chown 3s 1m
 -----------------------------------------------------
 
diff --git a/memcheck/tests/sigprocmask.c b/memcheck/tests/sigprocmask.c
new file mode 100644
index 0000000..dc00102
--- /dev/null
+++ b/memcheck/tests/sigprocmask.c
@@ -0,0 +1,47 @@
+
+#include <signal.h>
+#include <stdio.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+// Reg test for bug #93328: we were using too-big sigset types, and thus
+// trashing memory when we wrote out the 'oldset' param from sigprocmask().
+
+int main(void)
+{
+   int x[6], *s, *os, i;
+
+   x[0] = 0x11111111;
+   x[1] = 0x89abcdef;
+   x[2] = 0x22222222;
+   x[3] = 0x33333333;
+   x[4] = 0x0;
+   x[5] = 0x44444444;
+
+   s  = &x[1];
+   os = &x[4];
+
+   fprintf(stderr, "before\n");
+   for (i = 0; i < 6; i++) {
+      fprintf(stderr, "%x ", x[i]);
+   }
+   fprintf(stderr, "\n");
+
+   syscall(__NR_sigprocmask, SIG_BLOCK, s, os);
+
+   fprintf(stderr, "after1\n");
+   for (i = 0; i < 6; i++) {
+      fprintf(stderr, "%x ", x[i]);
+   }
+   fprintf(stderr, "\n");
+   
+   syscall(__NR_sigprocmask, SIG_BLOCK, s, os);
+
+   fprintf(stderr, "after2\n");
+   for (i = 0; i < 6; i++) {
+      fprintf(stderr, "%x ", x[i]);
+   }
+   fprintf(stderr, "\n");
+   
+   return(0);
+}
diff --git a/memcheck/tests/sigprocmask.stderr.exp b/memcheck/tests/sigprocmask.stderr.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/memcheck/tests/sigprocmask.stderr.exp
diff --git a/memcheck/tests/sigprocmask.vgtest b/memcheck/tests/sigprocmask.vgtest
new file mode 100644
index 0000000..e033128
--- /dev/null
+++ b/memcheck/tests/sigprocmask.vgtest
@@ -0,0 +1,2 @@
+prog: sigprocmask
+vgopts: -q