[gentoo-commits] proj/sandbox:master commit in: libsandbox/trace/linux/, libsandbox/

2015-12-20 Thread Mike Frysinger
commit: e99597cc31b454f97d2629f17d3d6f5145f978d7
Author: Mike Frysinger  gentoo  org>
AuthorDate: Sun Dec 20 21:35:21 2015 +
Commit: Mike Frysinger  gentoo  org>
CommitDate: Sun Dec 20 21:35:21 2015 +
URL:https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=e99597cc

libsandbox: new ia64 ptrace port

Signed-off-by: Mike Frysinger  gentoo.org>

 libsandbox/trace.c|  1 +
 libsandbox/trace/linux/arch.c |  2 ++
 libsandbox/trace/linux/ia64.c | 81 +++
 3 files changed, 84 insertions(+)

diff --git a/libsandbox/trace.c b/libsandbox/trace.c
index 5ccda2a..fb1fc32 100644
--- a/libsandbox/trace.c
+++ b/libsandbox/trace.c
@@ -9,6 +9,7 @@
 #include "wrappers.h"
 #include "sb_nr.h"
 
+static long do_peekdata(long offset);
 static long _do_ptrace(enum __ptrace_request request, const char *srequest, 
void *addr, void *data);
 #define do_ptrace(request, addr, data) _do_ptrace(request, #request, addr, 
data)
 #define _trace_possible(data) true

diff --git a/libsandbox/trace/linux/arch.c b/libsandbox/trace/linux/arch.c
index fbf5b79..4b3d615 100644
--- a/libsandbox/trace/linux/arch.c
+++ b/libsandbox/trace/linux/arch.c
@@ -17,6 +17,8 @@
 # include "hppa.c"
 #elif defined(__i386__)
 # include "i386.c"
+#elif defined(__ia64__)
+# include "ia64.c"
 #elif defined(__powerpc__)
 # include "powerpc.c"
 #elif defined(__s390__)

diff --git a/libsandbox/trace/linux/ia64.c b/libsandbox/trace/linux/ia64.c
new file mode 100644
index 000..5029994
--- /dev/null
+++ b/libsandbox/trace/linux/ia64.c
@@ -0,0 +1,81 @@
+#include 
+#include 
+
+/* We only care about two ptrace regs, so extract them ourselves rather than
+ * get the "full" set via GETREGS.  We still need to extract the out regs by
+ * hand either way.
+ */
+#undef trace_regs
+struct sb_ia64_trace_regs {
+   unsigned long r8, r10, r15;
+   unsigned long out[6];
+};
+#define trace_regs struct sb_ia64_trace_regs
+
+#define trace_reg_sysnum r15
+
+static unsigned long trace_arg(void *vregs, int num)
+{
+   trace_regs *regs = vregs;
+   if (num < 7)
+   return regs->out[num - 1];
+   else
+   return -1;
+}
+
+static long do_peekuser(long offset)
+{
+   return do_ptrace(PTRACE_PEEKUSER, (void *)offset, NULL);
+}
+
+static long do_pokeuser(long offset, long val)
+{
+   return do_ptrace(PTRACE_POKEUSER, (void *)offset, (void *)val);
+}
+
+#undef trace_get_regs
+static long trace_get_regs(void *vregs)
+{
+   trace_regs *regs = vregs;
+   size_t i;
+   unsigned long *out0, cfm, sof, sol;
+   long rbs_end;
+
+   regs->r15 = do_peekuser(PT_R15);
+
+   /* Here there be gremlins! */
+   rbs_end = do_peekuser(PT_AR_BSP);
+   cfm = do_peekuser(PT_CFM);
+   sof = (cfm >> 0) & 0x7f;
+   sol = (cfm >> 7) & 0x7f;
+   out0 = ia64_rse_skip_regs((unsigned long *)rbs_end, -sof + sol);
+   for (i = 0; i < 7; ++i)
+   regs->out[i] = do_peekdata((uintptr_t)ia64_rse_skip_regs(out0, 
i));
+
+   return 0;
+}
+
+#undef trace_set_regs
+static long trace_set_regs(void *vregs)
+{
+   trace_regs *regs = vregs;
+   /* We only support rewriting of syscall/err # currently (not args). */
+   do_pokeuser(PT_R8, regs->r8);
+   do_pokeuser(PT_R10, regs->r10);
+   do_pokeuser(PT_R15, regs->r15);
+   return 0;
+}
+
+static long trace_raw_ret(void *vregs)
+{
+   trace_regs *regs = vregs;
+   return regs->r8;
+}
+
+static void trace_set_ret(void *vregs, int err)
+{
+   trace_regs *regs = vregs;
+   regs->r8 = err;
+   regs->r10 = -1;
+   trace_set_regs(regs);
+}



[gentoo-commits] proj/sandbox:master commit in: libsandbox/trace/linux/, libsandbox/

2015-12-20 Thread Mike Frysinger
commit: 13b45f7910d6039e3a3a0971c786a5750f80cd9b
Author: Mike Frysinger  gentoo  org>
AuthorDate: Sun Dec 20 00:55:14 2015 +
Commit: Mike Frysinger  gentoo  org>
CommitDate: Sun Dec 20 00:55:14 2015 +
URL:https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=13b45f79

libsandbox: switch to PTRACE_O_TRACEEXEC

Rather than try to deal with the inconsistent cross-arch behavior when it
comes to tracking exec behavior, use the PTRACE_O_TRACEEXEC option.  This
means we only support ptrace on linux-2.6+ systems, but that's fine as we
have been requiring that for a long time now.  It also means the code is
much simpler and stable across arches.

Signed-off-by: Mike Frysinger  gentoo.org>

 libsandbox/trace.c| 68 +++
 libsandbox/trace/linux/arch.c |  8 +++--
 2 files changed, 29 insertions(+), 47 deletions(-)

diff --git a/libsandbox/trace.c b/libsandbox/trace.c
index f9194fe..d424389 100644
--- a/libsandbox/trace.c
+++ b/libsandbox/trace.c
@@ -430,41 +430,34 @@ static bool trace_check_syscall(const struct 
syscall_entry *se, void *regs)
 static void trace_loop(void)
 {
trace_regs regs;
-   bool before_syscall, fake_syscall_ret;
+   bool before_exec, before_syscall, fake_syscall_ret;
long ret;
-   int nr, exec_state;
-   const struct syscall_entry *se, *tbl_at_fork, *tbl_after_fork;
+   int nr, status;
+   const struct syscall_entry *se, *tbl_after_fork;
 
-   exec_state = 0;
-   before_syscall = true;
+   before_exec = true;
+   before_syscall = false;
fake_syscall_ret = false;
-   tbl_at_fork = tbl_after_fork = NULL;
+   tbl_after_fork = NULL;
do {
ret = do_ptrace(PTRACE_SYSCALL, NULL, NULL);
-   waitpid(trace_pid, NULL, 0);
-   ret = trace_get_regs();
-   nr = trace_get_sysnum();
+   waitpid(trace_pid, , 0);
 
-   if (!exec_state) {
-   if (!tbl_at_fork)
-   tbl_at_fork = trace_check_personality();
-   se = lookup_syscall_in_tbl(tbl_at_fork, nr);
-   if (!before_syscall || !se || se->sys != SB_NR_EXECVE) {
-   if (before_syscall)
-   _sb_debug(">%s:%i", se ? se->name : 
"IDK", nr);
-   else
-   __sb_debug("(...pre-exec...) = ...\n");
-   goto loop_again;
-   }
-   ++exec_state;
-   } else if (exec_state == 1) {
-   /* Don't bother poking exec return */
-   ++exec_state;
-   goto loop_again;
+   if (before_exec) {
+   unsigned event = ((unsigned)status >> 16);
+   if (event == PTRACE_EVENT_EXEC) {
+   _sb_debug("hit exec!");
+   before_exec = false;
+   } else
+   _sb_debug("waiting for exec; status: %#x", 
status);
+   ret = trace_get_regs();
+   tbl_after_fork = trace_check_personality();
+   continue;
}
 
-   if (!tbl_after_fork)
-   tbl_after_fork = trace_check_personality();
+   ret = trace_get_regs();
+   nr = trace_get_sysnum();
+
se = lookup_syscall_in_tbl(tbl_after_fork, nr);
ret = trace_get_regs();
if (before_syscall) {
@@ -486,24 +479,11 @@ static void trace_loop(void)
ret = trace_result(, );
 
__sb_debug(" = %li", ret);
-   if (err) {
+   if (err)
__sb_debug(" (errno: %i: %s)", err, 
strerror(err));
-
-   /* If the exec() failed for whatever reason, 
kill the
-* child and have the parent resume like normal
-*/
-   if (exec_state == 1) {
-   do_ptrace(PTRACE_KILL, NULL, NULL);
-   trace_pid = 0;
-   return;
-   }
-   }
__sb_debug("\n");
-
-   exec_state = 2;
}
 
- loop_again:
before_syscall = !before_syscall;
} while (1);
 }
@@ -527,10 +507,8 @@ void trace_main(const char *filename, char *const argv[])
} else if (trace_pid) {
sb_debug("parent waiting for child (pid=%i) to signal", 
trace_pid);
waitpid(trace_pid, NULL, 0);
-#if defined(PTRACE_SETOPTIONS) && 

[gentoo-commits] proj/sandbox:master commit in: libsandbox/trace/linux/, libsandbox/, /

2015-09-27 Thread Mike Frysinger
commit: 46fe624223cfe62fb6c2fbb609be42f2f1d1734b
Author: Mike Frysinger  gentoo  org>
AuthorDate: Sun Sep 20 08:51:41 2015 +
Commit: Mike Frysinger  gentoo  org>
CommitDate: Sun Sep 20 08:51:41 2015 +
URL:https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=46fe6242

libsandbox: rework abi syscall header generation

Probe the availability of multilib headers at configure time so that we
can show the status more cleanly.  This allows the header generation to
be done in parallel and not output confusing warning messages to users.

URL: https://bugs.gentoo.org/536582
Reported-by: cmue81  gmx.de
Signed-off-by: Mike Frysinger  gentoo.org>

 configure.ac| 44 -
 libsandbox/Makefile.am  | 19 +++---
 libsandbox/trace/linux/x86_64.c |  6 ++
 3 files changed, 53 insertions(+), 16 deletions(-)

diff --git a/configure.ac b/configure.ac
index dec9686..b57263e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,19 +50,45 @@ dnl multiple personality support (x86 & x86_64: multilib)
 AC_MSG_CHECKING([for multiple personalities])
 AC_ARG_ENABLE([schizo],
[AS_HELP_STRING([--enable-schizo],[Support multiple personalities])],
-   [],[enable_schizo="yes"])
-SB_SCHIZO_SETTINGS="no"
-if test "x$enable_schizo" = "xyes" ; then
-   case $host_alias in
-   x86_64*linux*) SB_SCHIZO_SETTINGS="x86_64:-m64 x86:-m32 
x32:-mx32";;
+   [],[enable_schizo="auto"])
+AC_MSG_RESULT([$enable_schizo])
+SB_SCHIZO_SETTINGS=
+AC_DEFUN([SB_CHECK_SCHIZO],[dnl
+   AC_MSG_CHECKING([checking for $1/$2 compiler support])
+   ac_save_CFLAGS=$CFLAGS
+   CFLAGS="$CFLAGS $2"
+   AC_TRY_COMPILE([
+   #include 
+   ], [
+   return 0
+   ], [
+   enable_schizo=yes
+   AS_VAR_APPEND([SB_SCHIZO_SETTINGS], " $1:$2")
+   AS_VAR_APPEND([SB_SCHIZO_HEADERS], " 
trace_syscalls_$1.h")
+   AC_MSG_RESULT([yes])
+   AC_DEFINE_UNQUOTED([SB_SCHIZO_$1], 1, [Support for 
$1/$2 is available])
+   ], [
+   AC_MSG_RESULT([no])
+   ])
+   CFLAGS=$ac_save_CFLAGS
+])
+if test "x$enable_schizo" != "xno" ; then
+   enable_schizo=no
+   case $host in
+   i686*linux|x86_64*linux*)
+   SB_CHECK_SCHIZO([x86_64], [-m64])
+   SB_CHECK_SCHIZO([x86], [-m32])
+   SB_CHECK_SCHIZO([x32], [-mx32])
+   ;;
esac
-fi
-if test "$SB_SCHIZO_SETTINGS" != "no" ; then
-   AC_DEFINE_UNQUOTED([SB_SCHIZO], ["$SB_SCHIZO_SETTINGS"], [Enable 
multiple personalities support])
+   SB_SCHIZO_SETTINGS=${SB_SCHIZO_SETTINGS# }
+   if test "x$enable_schizo" != "xno" ; then
+   AC_DEFINE_UNQUOTED([SB_SCHIZO], ["$SB_SCHIZO_SETTINGS"], 
[Enable multiple personalities support])
+   fi
 fi
 AC_SUBST(SB_SCHIZO_SETTINGS)
+AC_SUBST(SB_SCHIZO_HEADERS)
 AM_CONDITIONAL([SB_SCHIZO], test "$SB_SCHIZO_SETTINGS" != "no")
-AC_MSG_RESULT($SB_SCHIZO_SETTINGS)
 
 dnl this test fills up the stack and then triggers a segfault ...
 dnl but it's hard to wrap things without a stack, so let's ignore

diff --git a/libsandbox/Makefile.am b/libsandbox/Makefile.am
index 529d835..cbc73ba 100644
--- a/libsandbox/Makefile.am
+++ b/libsandbox/Makefile.am
@@ -70,18 +70,23 @@ TRACE_MAKE_HEADER = \
$(SB_AWK) $(GEN_TRACE_SCRIPT) -v MODE=gen | \
$(COMPILE) -E -P -include $(top_srcdir)/headers.h - $$f | \
$(SB_AWK) $(GEN_TRACE_SCRIPT) -v syscall_prefix=$$t > $$header
-trace_syscalls.h: $(GEN_TRACE_SCRIPT) Makefile
+trace_syscalls.h: $(GEN_TRACE_SCRIPT) $(SB_SCHIZO_HEADERS)
 if SB_SCHIZO
+   $(AM_V_GEN)touch $@
+else
+   $(AM_V_GEN)t= f= header=$@; $(TRACE_MAKE_HEADER)
+endif
+
+$(SB_SCHIZO_HEADERS): $(GEN_TRACE_SCRIPT)
$(AM_V_GEN)for pers in $(SB_SCHIZO_SETTINGS) ; do \
t=_$${pers%:*}; \
f=$${pers#*:}; \
-   header=trace_syscalls$${t}.h; \
-   $(TRACE_MAKE_HEADER) || exit $$?; \
+   header="trace_syscalls$${t}.h"; \
+   if [ "$$header" = "$@" ]; then \
+   $(TRACE_MAKE_HEADER) || exit $$?; \
+   break; \
+   fi; \
done
-   @touch $@
-else
-   $(AM_V_GEN)t= f= header=$@; $(TRACE_MAKE_HEADER)
-endif
 
 EXTRA_DIST = $(SYMBOLS_FILE) $(SYMBOLS_WRAPPERS) $(SB_NR_FILE) $(TRACE_FILES) 
headers.h
 

diff --git a/libsandbox/trace/linux/x86_64.c b/libsandbox/trace/linux/x86_64.c
index 5bd1361..82c492d 100644
--- a/libsandbox/trace/linux/x86_64.c
+++ b/libsandbox/trace/linux/x86_64.c
@@ -4,21 +4,27 @@
 #ifdef SB_SCHIZO
 
 static const struct syscall_entry syscall_table_32[] = {
+#ifdef SB_SCHIZO_x86
 #define S(s) { SB_SYS_x86_##s, SB_NR_##s, #s },
 #include