From: bdemsky Date: Thu, 24 Nov 2016 20:40:03 +0000 (-0800) Subject: Work around changes in newer versions of glibc X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=01f8364dda87f16e1a8823232c2d90de1d5168a6;hp=178fa56c36e45267d59c545dea0b9c7be93a4e1e;p=c11tester.git Work around changes in newer versions of glibc --- diff --git a/common.h b/common.h index 62c16f45..7be72d72 100644 --- a/common.h +++ b/common.h @@ -9,8 +9,9 @@ #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) diff --git a/main.cc b/main.cc index 0d1fa1cc..502f499e 100644 --- a/main.cc +++ b/main.cc @@ -270,6 +270,18 @@ int main(int argc, char **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(); diff --git a/mymemory.cc b/mymemory.cc index 4182e094..e8ec0805 100644 --- a/mymemory.cc +++ b/mymemory.cc @@ -16,6 +16,7 @@ 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 @@ -179,6 +180,9 @@ static void * user_malloc(size_t size) 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); @@ -189,8 +193,12 @@ void *malloc(size_t size) /** @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); + } } /** @brief Snapshotting realloc implementation for user programs */