]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Factor out VG_(exit_now) to contain the syscall incantation to terminate
authorFlorian Krohm <florian@eich-krohm.de>
Thu, 24 Jul 2014 12:46:28 +0000 (12:46 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Thu, 24 Jul 2014 12:46:28 +0000 (12:46 +0000)
the process. Make ML_(am_exit) and VG_(exit) use it, thereby avoiding
double maintenance.
Introduce libcbase_assert macro and use it in VG_(strncpy_safely) to
document the case that function cannot handle.
Add stub functions to memcheck/tests/unit_libcbase.c to satisfy new
dependencies.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14185

coregrind/m_aspacemgr/aspacemgr-common.c
coregrind/m_aspacemgr/priv_aspacemgr.h
coregrind/m_libcassert.c
coregrind/m_libcbase.c
coregrind/pub_core_libcassert.h
memcheck/tests/unit_libcbase.c

index b8d694db79f799421bda12dbf58987eee8062044..96f5ecfcd00cc32bbc5b72b0492a024f05ac11fd 100644 (file)
 __attribute__ ((noreturn))
 void ML_(am_exit)( Int status )
 {
-#  if defined(VGO_linux)
-   (void)VG_(do_syscall1)(__NR_exit_group, status);
-#  endif
-   (void)VG_(do_syscall1)(__NR_exit, status);
-   /* Why are we still alive here? */
-   /*NOTREACHED*/
-   *(volatile Int *)0 = 'x';
-   aspacem_assert(2+2 == 5);
+   VG_(exit_now) (status);
 }
 
 void ML_(am_barf) ( const HChar* what )
index 4ef4323ac5c5ecf2c7f6edf47c2ca234d81f0809..730e536946aa9a636aafefe469c8e86149669145 100644 (file)
@@ -47,6 +47,8 @@
                                  // VG_IS_PAGE_ALIGNED
                                  // VG_PGROUNDDN, VG_PGROUNDUP
 
+#include "pub_core_libcassert.h" // VG_(exit_now)
+
 #include "pub_core_syscall.h"    // VG_(do_syscallN)
                                  // VG_(mk_SysRes_Error)
                                  // VG_(mk_SysRes_Success)
index f8a957bab3cac67f28bfbebac7918af09bb117fb..df11fba78c727179e467ad4f09670853d033c0ab 100644 (file)
@@ -256,6 +256,15 @@ static void exit_wrk( Int status, Bool gdbserver_call_allowed)
    }
    exit_called = True;
 
+   VG_(exit_now) (status);
+}
+
+/* Call the appropriate system call and nothing else. This function should
+   be called in places where the dependencies of VG_(exit) need to be
+   avoided. */
+__attribute__ ((__noreturn__))
+void VG_(exit_now)( Int status )
+{
 #if defined(VGO_linux)
    (void)VG_(do_syscall1)(__NR_exit_group, status );
 #elif defined(VGO_darwin)
index 61f6fefd45c153185079b4af6169a4cc6420755f..56a70397407f7b544b9be58aa3568d2f75a4dc42 100644 (file)
 */
 
 #include "pub_core_basics.h"
+#include "pub_core_libcassert.h"    // VG_(exit_now)
+#include "pub_core_debuglog.h"      // VG_(debugLog)
 #include "pub_core_libcbase.h"
 
+
+/* ---------------------------------------------------------------------
+   Assert machinery for use in this file. VG_(assert) cannot be called
+   here due to cyclic dependencies.
+   ------------------------------------------------------------------ */
+#define libcbase_assert(expr)                             \
+  ((void) ((expr) ? 0 :                                   \
+           (ML_(libcbase_assert_fail)(#expr,              \
+                                __FILE__, __LINE__,       \
+                                __PRETTY_FUNCTION__))))
+
+static void ML_(libcbase_assert_fail)( const HChar *expr,
+                                       const HChar *file,
+                                       Int line, 
+                                       const HChar *fn )
+{
+   VG_(debugLog)(0, "libcbase", 
+                    "Valgrind: FATAL: assertion failed:\n");
+   VG_(debugLog)(0, "libcbase", "  %s\n", expr);
+   VG_(debugLog)(0, "libcbase", "  at %s:%d (%s)\n", file, line, fn);
+   VG_(debugLog)(0, "libcbase", "Exiting now.\n");
+   VG_(exit_now)(1);
+}
+
 /* ---------------------------------------------------------------------
    HChar functions.
    ------------------------------------------------------------------ */
@@ -276,6 +302,8 @@ HChar* VG_(strcpy) ( HChar* dest, const HChar* src )
    zero termination. */
 void VG_(strncpy_safely) ( HChar* dest, const HChar* src, SizeT ndest )
 {
+   libcbase_assert(ndest > 0);
+
    SizeT i = 0;
    while (True) {
       dest[i] = 0;
index e9326a46104f957d407d52688eaa019accb68f18..de4b3ccfc6c53062e19d125670644e9164a14cb3 100644 (file)
@@ -69,6 +69,10 @@ extern void  VG_(core_panic_at)   ( const HChar* str, UnwindStartRegs* );
 /* Exits with status as client exit code. */
 extern void VG_(client_exit)( Int status );
 
+/* Lightweight exit without any dependencies. */
+__attribute__ ((__noreturn__))
+extern void VG_(exit_now)( Int status );
+
 /* Called when some unhandleable client behaviour is detected.
    Prints a msg and aborts. */
 extern void VG_(unimplemented) ( const HChar* msg )
index 019b67a7f79c003efe2f26314888fd90651e59ed..33542ceaa97482601743cc1899767e46d68d3df9 100644 (file)
@@ -3,11 +3,30 @@
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stddef.h>
 
 #include "pub_tool_basics.h"  /* UInt et al, needed for pub_tool_vki.h */
 #include "pub_tool_vki.h"
 #include "m_libcbase.c"
 
+/* Provide a stub to not have to pull in m_debuglog.c */
+void VG_(debugLog) ( Int level, const HChar* modulename,
+                                const HChar* format, ... )
+{
+   va_list args;
+   va_start(args, format);
+   fprintf(stderr, "debuglog: %s: ", modulename);
+   vfprintf(stderr, format, args);
+   va_end(args);
+}
+
+/* Provide a stub to not have to pull in m_libcassert.c */
+void VG_(exit_now)( Int status )
+{
+   exit(status);
+}
+
+
 #define  CHECK(x) \
    if (!x) { fprintf(stderr, "failure: %s:%d\n", __FILE__, __LINE__); }