Solaris syscall: Add support for system_stats (154).
Provide scalar test as well.
n-i-bz


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15684 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/configure.ac b/configure.ac
index 73c0c8c..b848de3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3412,6 +3412,29 @@
 ])
 AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR, test x$solaris_reserve_sysstat_zone_addr = xyes)
 
+
+# Solaris-specific check determining if the system_stats() syscall is available
+# (on newer Solaris).
+#
+# C-level symbol: SOLARIS_SYSTEM_STATS_SYSCALL
+# Automake-level symbol: SOLARIS_SYSTEM_STATS_SYSCALL
+#
+AC_MSG_CHECKING([for the `system_stats' syscall (Solaris-specific)])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <sys/syscall.h>
+]], [[
+  return !SYS_system_stats;
+]])], [
+solaris_system_stats_syscall=yes
+AC_MSG_RESULT([yes])
+AC_DEFINE([SOLARIS_SYSTEM_STATS_SYSCALL], 1,
+          [Define to 1 if you have the `system_stats' syscall.])
+], [
+solaris_system_stats_syscall=no
+AC_MSG_RESULT([no])
+])
+AM_CONDITIONAL(SOLARIS_SYSTEM_STATS_SYSCALL, test x$solaris_system_stats_syscall = xyes)
+
 else
 AM_CONDITIONAL(SOLARIS_SUN_STUDIO_AS, false)
 AM_CONDITIONAL(SOLARIS_XPG_SYMBOLS_PRESENT, false)
@@ -3436,6 +3459,7 @@
 AM_CONDITIONAL(SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS, false)
 AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ADDR, false)
 AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR, false)
+AM_CONDITIONAL(SOLARIS_SYSTEM_STATS_SYSCALL, false)
 fi # test "$VGCONF_OS" = "solaris"
 
 
diff --git a/coregrind/m_syswrap/syswrap-solaris.c b/coregrind/m_syswrap/syswrap-solaris.c
index bd2f004..a5bc37b 100644
--- a/coregrind/m_syswrap/syswrap-solaris.c
+++ b/coregrind/m_syswrap/syswrap-solaris.c
@@ -995,6 +995,9 @@
 DECL_TEMPLATE(solaris, sys_lwp_sema_trywait);
 DECL_TEMPLATE(solaris, sys_lwp_detach);
 DECL_TEMPLATE(solaris, sys_fchroot);
+#if defined(SOLARIS_SYSTEM_STATS_SYSCALL)
+DECL_TEMPLATE(solaris, sys_system_stats);
+#endif /* SOLARIS_SYSTEM_STATS_SYSCALL */
 DECL_TEMPLATE(solaris, sys_gettimeofday);
 DECL_TEMPLATE(solaris, sys_lwp_create);
 DECL_TEMPLATE(solaris, sys_lwp_exit);
@@ -6433,6 +6436,15 @@
       SET_STATUS_Failure(VKI_EBADF);
 }
 
+#if defined(SOLARIS_SYSTEM_STATS_SYSCALL)
+PRE(sys_system_stats)
+{
+   /* void system_stats(int flag); */
+   PRINT("sys_system_stats ( %ld )", SARG1);
+   PRE_REG_READ1(void, "system_stats", int, flag);
+}
+#endif /* SOLARIS_SYSTEM_STATS_SYSCALL */
+
 PRE(sys_gettimeofday)
 {
    /* Kernel: int gettimeofday(struct timeval *tp); */
@@ -10012,6 +10024,9 @@
    SOLXY(__NR_lwp_sema_trywait,     sys_lwp_sema_trywait),      /* 149 */
    SOLX_(__NR_lwp_detach,           sys_lwp_detach),            /* 150 */
    SOLX_(__NR_fchroot,              sys_fchroot),               /* 153 */
+#if defined(SOLARIS_SYSTEM_STATS_SYSCALL)
+   SOLX_(__NR_system_stats,         sys_system_stats),          /* 154 */
+#endif /* SOLARIS_SYSTEM_STATS_SYSCALL */
    SOLXY(__NR_gettimeofday,         sys_gettimeofday),          /* 156 */
    GENXY(__NR_getitimer,            sys_getitimer),             /* 157 */
    GENXY(__NR_setitimer,            sys_setitimer),             /* 158 */
diff --git a/include/vki/vki-scnums-solaris.h b/include/vki/vki-scnums-solaris.h
index 0b85548..92831f0 100644
--- a/include/vki/vki-scnums-solaris.h
+++ b/include/vki/vki-scnums-solaris.h
@@ -203,6 +203,9 @@
 //#define __NR_corectl                    SYS_corectl
 //#define __NR_modctl                     SYS_modctl
 #define __NR_fchroot                    SYS_fchroot
+#if defined(SOLARIS_SYSTEM_STATS_SYSCALL)
+#define __NR_system_stats               SYS_system_stats
+#endif /* SOLARIS_SYSTEM_STATS_SYSCALL */
 //#define __NR_vhangup                    SYS_vhangup
 #define __NR_gettimeofday               SYS_gettimeofday
 #define __NR_getitimer                  SYS_getitimer
diff --git a/memcheck/tests/solaris/Makefile.am b/memcheck/tests/solaris/Makefile.am
index 42397d0..8736c87 100644
--- a/memcheck/tests/solaris/Makefile.am
+++ b/memcheck/tests/solaris/Makefile.am
@@ -37,6 +37,7 @@
 	scalar_obsolete.stderr.exp scalar_obsolete.stdout.exp scalar_obsolete.vgtest \
 	scalar_shm_new.stderr.exp scalar_shm_new.stdout.exp scalar_shm_new.vgtest \
 	scalar_spawn.stderr.exp scalar_spawn.stdout.exp scalar_spawn.vgtest \
+	scalar_system_stats.stderr.exp scalar_system_stats.stdout.exp scalar_system_stats.vgtest \
 	scalar_tsol_clearance.stderr.exp scalar_tsol_clearance.vgtest \
 	scalar_utimensat.stderr.exp scalar_utimensat.stdout.exp scalar_utimensat.vgtest \
 	scalar_utimesys.stderr.exp scalar_utimesys.stdout.exp scalar_utimesys.vgtest \
@@ -117,6 +118,10 @@
 check_PROGRAMS += scalar_spawn spawn
 endif
 
+if SOLARIS_SYSTEM_STATS_SYSCALL
+check_PROGRAMS += scalar_system_stats
+endif
+
 if SOLARIS_TSOL_CLEARANCE
 check_PROGRAMS += scalar_tsol_clearance
 scalar_tsol_clearance_LDADD = -ltsol
diff --git a/memcheck/tests/solaris/scalar_system_stats.c b/memcheck/tests/solaris/scalar_system_stats.c
new file mode 100644
index 0000000..193b6b6
--- /dev/null
+++ b/memcheck/tests/solaris/scalar_system_stats.c
@@ -0,0 +1,18 @@
+/* Test for system_stats syscall which is available on newer Solaris. */ 
+
+#include "scalar.h"
+#include <sys/system_stats.h>
+
+int main(void)
+{
+   /* Uninitialised, but we know px[0] is 0x0. */
+   long *px = malloc(sizeof(long));
+   x0 = px[0];
+
+   /* SYS_system_stats         154 */
+   GO(SYS_system_stats, "1s 0m");
+   SY(SYS_system_stats, x0 + SYSTEM_STATS_START); SUCC;
+
+   return 0;
+}
+
diff --git a/memcheck/tests/solaris/scalar_system_stats.stderr.exp b/memcheck/tests/solaris/scalar_system_stats.stderr.exp
new file mode 100644
index 0000000..4c70b0a
--- /dev/null
+++ b/memcheck/tests/solaris/scalar_system_stats.stderr.exp
@@ -0,0 +1,6 @@
+---------------------------------------------------------
+154:        SYS_system_stats 1s 0m
+---------------------------------------------------------
+Syscall param system_stats(flag) contains uninitialised byte(s)
+   ...
+
diff --git a/memcheck/tests/solaris/scalar_system_stats.stdout.exp b/memcheck/tests/solaris/scalar_system_stats.stdout.exp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/memcheck/tests/solaris/scalar_system_stats.stdout.exp
diff --git a/memcheck/tests/solaris/scalar_system_stats.vgtest b/memcheck/tests/solaris/scalar_system_stats.vgtest
new file mode 100644
index 0000000..eec4b77
--- /dev/null
+++ b/memcheck/tests/solaris/scalar_system_stats.vgtest
@@ -0,0 +1,4 @@
+prereq: test -e scalar_system_stats
+prog: scalar_system_stats
+vgopts: -q
+stderr_filter_args: