Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify the mmalloc library further
[simgrid.git] / src / xbt / mmalloc / attach.c
index 254182e..7741a0b 100644 (file)
@@ -49,7 +49,7 @@ static struct mdesc *reuse(int fd);
 
    If the open file corresponding to FD is from a previous use of
    mmalloc and passes some basic sanity checks to ensure that it is
-   compatible with the current mmalloc package, then it's data is
+   compatible with the current mmalloc package, then its data is
    mapped in and is immediately accessible at the same addresses in
    the current process as the process that created the file (ignoring
    the BASEADDR parameter).
@@ -63,16 +63,15 @@ static struct mdesc *reuse(int fd);
 
    On success, returns a "malloc descriptor" which is used in subsequent
    calls to other mmalloc package functions.  It is explicitly "void *"
-   ("char *" for systems that don't fully support void) so that users
-   of the package don't have to worry about the actual implementation
-   details.
+   so that users of the package don't have to worry about the actual
+   implementation details.
 
    On failure returns NULL. */
 
-void *mmalloc_attach(int fd, void *baseaddr)
+xbt_mheap_t mmalloc_attach(int fd, void *baseaddr)
 {
   struct mdesc mtemp;
-  struct mdesc *mdp;
+  xbt_mheap_t mdp;
   void *mbase;
   struct stat sbuf;
 
@@ -105,7 +104,6 @@ void *mmalloc_attach(int fd, void *baseaddr)
   strncpy(mdp->magic, MMALLOC_MAGIC, MMALLOC_MAGIC_SIZE);
   mdp->headersize = sizeof(mtemp);
   mdp->version = MMALLOC_VERSION;
-  mdp->morecore = __mmalloc_mmap_morecore;
   mdp->fd = fd;
   mdp->base = mdp->breakval = mdp->top = baseaddr;
   mdp->next_mdesc = NULL;
@@ -129,7 +127,7 @@ void *mmalloc_attach(int fd, void *baseaddr)
      fails, then close the file descriptor if it was opened by us, and arrange
      to return a NULL. */
 
-  if ((mbase = mdp->morecore(mdp, sizeof(mtemp))) != NULL) {
+  if ((mbase = mmorecore(mdp, sizeof(mtemp))) != NULL) {
     memcpy(mbase, mdp, sizeof(mtemp));
   } else {
     THROWF(system_error,0,"morecore failed to get some memory!");
@@ -145,8 +143,8 @@ void *mmalloc_attach(int fd, void *baseaddr)
       mdp->next_mdesc = (struct mdesc *)mbase;
     UNLOCK(mdp);
   }
-  
-  return ((void *) mbase);
+
+  return mbase;
 }
 
 /* Given an valid file descriptor on an open file, test to see if that file
@@ -192,14 +190,10 @@ static struct mdesc *reuse(int fd)
   if (__mmalloc_remap_core(&mtemp) == mtemp.base) {
     mdp = (struct mdesc *) mtemp.base;
     mdp->fd = fd;
-    mdp->morecore = __mmalloc_mmap_morecore;
     if(!mdp->refcount){
       sem_init(&mdp->sem, 1, 1);
       mdp->refcount++;
     }
-    if (mdp->mfree_hook != NULL) {
-      mmcheckf((void *) mdp, (void (*)(void)) NULL, 1);
-    }
   }
   
   /* Add the new heap to the linked list of heaps attached by mmalloc */