From 01f8364dda87f16e1a8823232c2d90de1d5168a6 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 24 Nov 2016 12:40:03 -0800 Subject: [PATCH] Work around changes in newer versions of glibc --- common.h | 3 ++- main.cc | 12 ++++++++++++ mymemory.cc | 10 +++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/common.h b/common.h index 62c16f4..7be72d7 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 0d1fa1c..502f499 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 4182e09..e8ec080 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 */ -- 2.34.1