aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2012-06-22 19:42:08 -0700
committerMike Frysinger <vapier@gentoo.org>2012-06-23 19:07:27 -0400
commit4fcb367b1a7ff06a55c8bc4a25c38e46b77a1261 (patch)
tree4a4f3e1d83823dfea2b2f23206c474c2c9c4c2fe
parentlibsandbox: kill off SB_MEM_DEBUG (diff)
downloadsandbox-4fcb367b1a7ff06a55c8bc4a25c38e46b77a1261.tar.gz
sandbox-4fcb367b1a7ff06a55c8bc4a25c38e46b77a1261.tar.bz2
sandbox-4fcb367b1a7ff06a55c8bc4a25c38e46b77a1261.zip
libsandbox: handle broken kernel headers
Sometimes the struct in asm/ptrace.h is too small for what the kernel actually writes. Check to see which struct is larger (the one that the kernel declares or the C library declares), and use that. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--configure.ac2
-rw-r--r--localdecls.h11
2 files changed, 13 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index da6f75d..573e412 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,6 +119,8 @@ AC_CHECK_TYPES([sighandler_t, sig_t, __sighandler_t],,,[#include <signal.h>])
save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="-I$srcdir $CPPFLAGS"
AC_CHECK_TYPES([struct user_regs_struct, struct pt_regs],,,[#include "headers.h"])
+AC_CHECK_SIZEOF([struct user_regs_struct],,[#include "headers.h"])
+AC_CHECK_SIZEOF([struct pt_regs],,[#include "headers.h"])
CPPFLAGS=$save_CPPFLAGS
dnl Checks for library functions.
diff --git a/localdecls.h b/localdecls.h
index eef7295..be99617 100644
--- a/localdecls.h
+++ b/localdecls.h
@@ -68,6 +68,17 @@ typedef __sighandler_t sighandler_t;
#endif
#define HAVE_TRACE_REGS
+#if defined(HAVE_STRUCT_PT_REGS) && defined(HAVE_STRUCT_USER_REGS_STRUCT)
+/*
+ * Some systems have broken kernel headers who declare struct pt_regs as
+ * smaller than what the kernel actually operates on. If we have both
+ * reg structs available, pick the one that is larger in the hopes that
+ * we won't randomly clobber memory.
+ */
+# if SIZEOF_STRUCT_PT_REGS < SIZEOF_STRUCT_USER_REGS_STRUCT
+# undef HAVE_STRUCT_PT_REGS
+# endif
+#endif
#if defined(HAVE_STRUCT_PT_REGS)
typedef struct pt_regs trace_regs;
#elif defined(HAVE_STRUCT_USER_REGS_STRUCT)