Work around changes in newer versions of glibc
authorbdemsky <bdemsky@uci.edu>
Thu, 24 Nov 2016 20:40:03 +0000 (12:40 -0800)
committerbdemsky <bdemsky@uci.edu>
Thu, 24 Nov 2016 20:40:03 +0000 (12:40 -0800)
common.h
main.cc
mymemory.cc

index 62c16f45250e55a693864fd17759b9673d0220d6..7be72d72f8e0b56fc8f333ffe25489685b053f60 100644 (file)
--- a/common.h
+++ b/common.h
@@ -9,8 +9,9 @@
 #include "config.h"
 
 extern int model_out;
 #include "config.h"
 
 extern int model_out;
+extern int switch_alloc;
 
 
-#define model_print(fmt, ...) do { dprintf(model_out, fmt, ##__VA_ARGS__); } while (0)
+#define model_print(fmt, ...) do { switch_alloc = 1; dprintf(model_out, fmt, ##__VA_ARGS__); switch_alloc = 0; } while (0)
 
 #ifdef CONFIG_DEBUG
 #define DEBUG(fmt, ...) do { model_print("*** %15s:%-4d %25s() *** " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); } while (0)
 
 #ifdef CONFIG_DEBUG
 #define DEBUG(fmt, ...) do { model_print("*** %15s:%-4d %25s() *** " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); } while (0)
diff --git a/main.cc b/main.cc
index 0d1fa1cc31bb93e3c8e740886f8464dc379d788d..502f499eff9cb2de956256bb6f24b84080e600e0 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -270,6 +270,18 @@ int main(int argc, char **argv)
        main_argc = argc;
        main_argv = argv;
 
        main_argc = argc;
        main_argv = argv;
 
+       /*
+        * If this printf statement is removed, CDSChecker will fail on an
+        * assert on some versions of glibc.  The first time printf is
+        * called, it allocated internal buffers.  We can't easily snapshot
+        * libc since we also use it.
+        */
+
+       printf("CDSChecker\n"
+                                "Copyright (c) 2013 Regents of the University of California. All rights reserved.\n"
+                                "Distributed under the GPLv2\n"
+                                "Written by Brian Norris and Brian Demsky\n\n");
+
        /* Configure output redirection for the model-checker */
        redirect_output();
 
        /* Configure output redirection for the model-checker */
        redirect_output();
 
index 4182e094e5251c1a8efedbe8a92c232c012f13f3..e8ec08050f5d8e5389c01e136fe1c0a27f374f13 100644 (file)
@@ -16,6 +16,7 @@
 size_t allocatedReqs[REQUESTS_BEFORE_ALLOC] = { 0 };
 int nextRequest = 0;
 int howManyFreed = 0;
 size_t allocatedReqs[REQUESTS_BEFORE_ALLOC] = { 0 };
 int nextRequest = 0;
 int howManyFreed = 0;
+int switch_alloc = 0;
 #if !USE_MPROTECT_SNAPSHOT
 static mspace sStaticSpace = NULL;
 #endif
 #if !USE_MPROTECT_SNAPSHOT
 static mspace sStaticSpace = NULL;
 #endif
@@ -179,6 +180,9 @@ static void * user_malloc(size_t size)
 void *malloc(size_t size)
 {
        if (user_snapshot_space) {
 void *malloc(size_t size)
 {
        if (user_snapshot_space) {
+               if (switch_alloc) {
+                       return model_malloc(size);
+               }
                /* Only perform user allocations from user context */
                ASSERT(!model || thread_current());
                return user_malloc(size);
                /* Only perform user allocations from user context */
                ASSERT(!model || thread_current());
                return user_malloc(size);
@@ -189,8 +193,12 @@ void *malloc(size_t size)
 /** @brief Snapshotting free implementation for user programs */
 void free(void * ptr)
 {
 /** @brief Snapshotting free implementation for user programs */
 void free(void * ptr)
 {
-       if (!DontFree(ptr))
+       if (!DontFree(ptr)) {
+               if (switch_alloc) {
+                       return model_free(ptr);
+               }
                mspace_free(user_snapshot_space, ptr);
                mspace_free(user_snapshot_space, ptr);
+       }
 }
 
 /** @brief Snapshotting realloc implementation for user programs */
 }
 
 /** @brief Snapshotting realloc implementation for user programs */