#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)
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();
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
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);
/** @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 */