XBT_PUBLIC( xbt_mheap_t ) xbt_mheap_new(int fd, void *baseaddr);
+#define XBT_MHEAP_OPTION_MEMSET 1
+
+XBT_PUBLIC( xbt_mheap_t ) xbt_mheap_new_options(int fd, void *baseaddr, int options);
+
XBT_PUBLIC( void ) xbt_mheap_destroy_no_free(xbt_mheap_t md);
XBT_PUBLIC( void ) *xbt_mheap_destroy(xbt_mheap_t md);
}
-
mc_snapshot_t MC_take_snapshot(int num_state){
mc_snapshot_t snapshot = xbt_new0(s_mc_snapshot_t, 1);
}
void mc_dwarf_expression_init(mc_expression_t expression, size_t len, Dwarf_Op* ops) {
- if(expression->ops) {
- free(expression->ops);
- }
expression->lowpc = NULL;
expression->highpc = NULL;
expression->size = len;
}
void mc_dwarf_location_list_init_from_expression(mc_location_list_t target, size_t len, Dwarf_Op* ops) {
- if(target->locations) {
- mc_dwarf_location_list_clear(target);
- }
target->size = 1;
target->locations = (mc_expression_t) xbt_malloc(sizeof(s_mc_expression_t));
mc_dwarf_expression_init(target->locations, len, ops);
raw_heap = NULL;
#else
/* Create the second region a page after the first one ends + safety gap */
- raw_heap = xbt_mheap_new(-1, (char*)(std_heap) + STD_HEAP_SIZE + xbt_pagesize);
+ raw_heap = xbt_mheap_new_options(-1, (char*)(std_heap) + STD_HEAP_SIZE + xbt_pagesize, 0);
xbt_assert(raw_heap != NULL);
#endif
}
static char junkareas[MAX_JUNK_AREAS][JUNK_SIZE];
/* This version use mmalloc if there is a current heap, or the legacy implem if not */
-void *malloc(size_t n) {
+static void *malloc_or_calloc(size_t n, int setzero) {
xbt_mheap_t mdp = __mmalloc_current_heap;
void *ret;
#ifdef MM_LEGACY_VERBOSE
LOCK(mdp);
ret = mmalloc(mdp, n);
UNLOCK(mdp);
+ // This was already done by mmalloc:
+ if (mdp->options & XBT_MHEAP_OPTION_MEMSET) {
+ setzero = 0;
+ }
#ifdef MM_LEGACY_VERBOSE
if (!warned_mmalloc) {
fprintf(stderr,"Using mmalloc; enabling the model-checker in cmake may have a bad impact on your simulation performance\n");
warned_mmalloc = 1;
}
#endif
- } else {
- if (!real_malloc) {
+ } else if (!real_malloc) {
size_t needed_areas = n / JUNK_SIZE;
if(needed_areas * JUNK_SIZE != n) needed_areas++;
if (allocated_junk+needed_areas>=MAX_JUNK_AREAS) {
} else {
size_t i = allocated_junk;
allocated_junk += needed_areas;
- return junkareas[i];
+ ret = junkareas[i];
}
}
+ else {
#ifdef MM_LEGACY_VERBOSE
if (!warned_raw) {
fprintf(stderr,"Using system malloc after interception; you seem to be currently model-checking\n");
#endif
ret = real_malloc(n);
}
+ if (ret && setzero) {
+ memset(ret, 0, n);
+ }
return ret;
}
+void *malloc(size_t n)
+{
+ return malloc_or_calloc(n, 0);
+}
void *calloc(size_t nmemb, size_t size)
{
- void *ret = malloc(nmemb*size);
- memset(ret, 0, nmemb * size);
- return ret;
+ return malloc_or_calloc(nmemb*size, 1);
}
void *realloc(void *p, size_t s)
On failure returns NULL. */
xbt_mheap_t xbt_mheap_new(int fd, void *baseaddr)
+{
+ return xbt_mheap_new_options(fd, baseaddr, 0);
+}
+
+xbt_mheap_t xbt_mheap_new_options(int fd, void *baseaddr, int options)
{
struct mdesc mtemp;
xbt_mheap_t mdp;
mdp->base = mdp->breakval = mdp->top = baseaddr;
mdp->next_mdesc = NULL;
mdp->refcount = 1;
+ mdp->options = options;
/* If we have not been passed a valid open file descriptor for the file
to map to, then we go for an anonymous map */
if (__mmalloc_default_mdp == NULL) {
unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
void *addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask);
- __mmalloc_default_mdp = xbt_mheap_new(-1, addr);
+ __mmalloc_default_mdp = xbt_mheap_new_options(-1, addr, XBT_MHEAP_OPTION_MEMSET);
/* Fixme? only the default mdp in protected against forks */
// This is mandated to protect the mmalloced areas through forks. Think of tesh.
// Nah, removing the mutex isn't a good idea either for tesh
/* Allocate memory from the heap. */
void *mmalloc(xbt_mheap_t mdp, size_t size) {
void *res= mmalloc_no_memset(mdp,size);
-// fprintf(stderr,"malloc(%zu)~>%p\n",size,res);
- memset(res,0,size);
+ if (mdp->options & XBT_MHEAP_OPTION_MEMSET) {
+ memset(res,0,size);
+ }
return res;
}
/* Spliting mmalloc this way is mandated by a trick in mrealloc, that gives
/* The version number of the mmalloc package that created this file. */
unsigned char version;
+ unsigned int options;
+
/* Some flag bits to keep track of various internal things. */
unsigned int flags;