projects
/
model-checker.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
threads/model: allocate Thread from w/in ModelChecker
[model-checker.git]
/
mymemory.cc
diff --git
a/mymemory.cc
b/mymemory.cc
index 08bd4e437c897967830d5dc760d0d4f27f351b50..44985fa3aebc0d3fc32f97c0606b3c7ef11154a8 100644
(file)
--- a/
mymemory.cc
+++ b/
mymemory.cc
@@
-1,13
+1,17
@@
-#include "mymemory.h"
-#include "snapshot.h"
-#include "snapshotimp.h"
+#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>
#include <dlfcn.h>
#include <unistd.h>
-#include <cstring>
+#include <string.h>
+#include <new>
+
+#include "mymemory.h"
+#include "snapshot.h"
#include "common.h"
#include "common.h"
+
#define REQUESTS_BEFORE_ALLOC 1024
#define REQUESTS_BEFORE_ALLOC 1024
-size_t allocatedReqs[ REQUESTS_BEFORE_ALLOC ] = { 0 };
+
+size_t allocatedReqs[REQUESTS_BEFORE_ALLOC] = { 0 };
int nextRequest = 0;
int howManyFreed = 0;
#if !USE_MPROTECT_SNAPSHOT
int nextRequest = 0;
int howManyFreed = 0;
#if !USE_MPROTECT_SNAPSHOT
@@
-33,11
+37,8
@@
void *model_calloc(size_t count, size_t size)
ptr = callocp(count, size);
return ptr;
#else
ptr = callocp(count, size);
return ptr;
#else
- if (!snapshotrecord) {
- createSharedMemory();
- }
- if (NULL == sStaticSpace)
- sStaticSpace = create_mspace_with_base(( void *)( snapshotrecord->mSharedMemoryBase), SHARED_MEMORY_DEFAULT -sizeof(struct SnapShot), 1);
+ if (!sStaticSpace)
+ sStaticSpace = create_shared_mspace();
return mspace_calloc(sStaticSpace, count, size);
#endif
}
return mspace_calloc(sStaticSpace, count, size);
#endif
}
@@
-61,11
+62,8
@@
void *model_malloc(size_t size)
ptr = mallocp(size);
return ptr;
#else
ptr = mallocp(size);
return ptr;
#else
- if (!snapshotrecord) {
- createSharedMemory();
- }
- if (NULL == sStaticSpace)
- sStaticSpace = create_mspace_with_base(( void *)( snapshotrecord->mSharedMemoryBase), SHARED_MEMORY_DEFAULT -sizeof(struct SnapShot), 1);
+ if (!sStaticSpace)
+ sStaticSpace = create_shared_mspace();
return mspace_malloc(sStaticSpace, size);
#endif
}
return mspace_malloc(sStaticSpace, size);
#endif
}
@@
-109,7
+107,7
@@
void model_free(void *ptr)
/* get address of libc free */
if (!freep) {
/* get address of libc free */
if (!freep) {
- freep = (
void ( * )(
void *))dlsym(RTLD_NEXT, "free");
+ freep = (
void (*)(
void *))dlsym(RTLD_NEXT, "free");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(EXIT_FAILURE);
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(EXIT_FAILURE);
@@
-121,9
+119,8
@@
void model_free(void *ptr)
#endif
}
#endif
}
-/** Bootstrap allocation. Problem is that the dynamic linker calls
- * require calloc to work and calloc requires the dynamic linker to
- * work. */
+/** Bootstrap allocation. Problem is that the dynamic linker calls require
+ * calloc to work and calloc requires the dynamic linker to work. */
#define BOOTSTRAPBYTES 4096
char bootstrapmemory[BOOTSTRAPBYTES];
#define BOOTSTRAPBYTES 4096
char bootstrapmemory[BOOTSTRAPBYTES];
@@
-135,11
+132,11
@@
void * HandleEarlyAllocationRequest(size_t sz)
sz = (sz + 7) & ~7;
if (sz > (BOOTSTRAPBYTES-offset)) {
sz = (sz + 7) & ~7;
if (sz > (BOOTSTRAPBYTES-offset)) {
-
printf
("OUT OF BOOTSTRAP MEMORY\n");
+
model_print
("OUT OF BOOTSTRAP MEMORY\n");
exit(EXIT_FAILURE);
}
exit(EXIT_FAILURE);
}
- void *pointer= (void *)&bootstrapmemory[offset];
+ void *pointer
= (void *)&bootstrapmemory[offset];
offset += sz;
return pointer;
}
offset += sz;
return pointer;
}
@@
-149,9
+146,7
@@
mspace model_snapshot_space = NULL;
#if USE_MPROTECT_SNAPSHOT
#if USE_MPROTECT_SNAPSHOT
-/** @brief Global mspace reference for the user's snapshotting heap
- * @todo use this ONLY for user's allocations, not for internal snapshotting
- * state */
+/** @brief Global mspace reference for the user's snapshotting heap */
mspace user_snapshot_space = NULL;
/** Check whether this is bootstrapped memory that we should not free */
mspace user_snapshot_space = NULL;
/** Check whether this is bootstrapped memory that we should not free */
@@
-195,7
+190,7
@@
void * calloc(size_t num, size_t size)
return tmp;
} else {
void *tmp = HandleEarlyAllocationRequest(size * num);
return tmp;
} else {
void *tmp = HandleEarlyAllocationRequest(size * num);
-
std::
memset(tmp, 0, size * num);
+ memset(tmp, 0, size * num);
return tmp;
}
}
return tmp;
}
}