X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/33a9da85867c540b95d99573defe39b47c5f6f45..bbc1569a8f78a6dcdb4511735830587adfa06e87:/src/xbt/mmalloc/attach.c diff --git a/src/xbt/mmalloc/attach.c b/src/xbt/mmalloc/attach.c index 2fe1de9c11..db06a3c470 100644 --- a/src/xbt/mmalloc/attach.c +++ b/src/xbt/mmalloc/attach.c @@ -34,11 +34,9 @@ Boston, MA 02111-1307, USA. */ #endif -#if defined(HAVE_MMAP) - /* Forward declarations/prototypes for local functions */ -static struct mdesc *reuse PARAMS ((int)); +static struct mdesc *reuse (int fd); /* Initialize access to a mmalloc managed region. @@ -70,14 +68,10 @@ static struct mdesc *reuse PARAMS ((int)); On failure returns NULL. */ -PTR -mmalloc_attach (fd, baseaddr) - int fd; - PTR baseaddr; -{ +void * mmalloc_attach (int fd, void *baseaddr) { struct mdesc mtemp; struct mdesc *mdp; - PTR mbase; + void* mbase; struct stat sbuf; /* First check to see if FD is a valid file descriptor, and if so, see @@ -90,10 +84,10 @@ mmalloc_attach (fd, baseaddr) if (fd >= 0) { if (fstat (fd, &sbuf) < 0) - return (NULL); + return (NULL); else if (sbuf.st_size > 0) - return ((PTR) reuse (fd)); + return ((void*) reuse (fd)); } /* If the user provided NULL BASEADDR then fail */ @@ -123,18 +117,6 @@ mmalloc_attach (fd, baseaddr) /* If we have not been passed a valid open file descriptor for the file to map to, then open /dev/zero and use that to map to. */ -/* if (mdp -> fd < 0)*/ -/* {*/ -/* if ((mdp -> fd = open ("/dev/zero", O_RDWR)) < 0)*/ -/* {*/ -/* return (NULL);*/ -/* }*/ -/* else*/ -/* {*/ -/* mdp -> flags |= MMALLOC_DEVZERO;*/ -/* }*/ -/* }*/ - /* Now try to map in the first page, copy the malloc descriptor structure there, and arrange to return a pointer to this new copy. If the mapping fails, then close the file descriptor if it was opened by us, and arrange @@ -143,15 +125,22 @@ mmalloc_attach (fd, baseaddr) if ((mbase = mdp -> morecore (mdp, sizeof (mtemp))) != NULL) { memcpy (mbase, mdp, sizeof (mtemp)); -// mdp = (struct mdesc *) mbase; + // mdp = (struct mdesc *) mbase; } else { abort(); -// mdp = NULL; + // mdp = NULL; } - - return ((PTR) mbase); + + { /* create the mutex within that heap */ + void*old_heap=mmalloc_get_current_heap(); + mmalloc_set_current_heap(mbase); + mdp->mutex =xbt_os_mutex_init(); + mmalloc_set_current_heap(old_heap); + } + + return ((void*) mbase); } /* Given an valid file descriptor on an open file, test to see if that file @@ -178,8 +167,7 @@ mmalloc_attach (fd, baseaddr) unsuccessful for some reason. */ static struct mdesc * -reuse (fd) - int fd; +reuse (int fd) { struct mdesc mtemp; struct mdesc *mdp = NULL; @@ -199,30 +187,22 @@ reuse (fd) if (__mmalloc_remap_core (&mtemp) == mtemp.base) { mdp = (struct mdesc *) mtemp.base; - mdp -> fd = fd; - mdp -> morecore = __mmalloc_mmap_morecore; - if (mdp -> mfree_hook != NULL) - { - mmcheckf ((PTR) mdp, (void (*) PARAMS ((void))) NULL, 1); - } + mdp -> fd = fd; + mdp -> morecore = __mmalloc_mmap_morecore; + mdp->mutex =xbt_os_mutex_init(); + if (mdp -> mfree_hook != NULL) + { + mmcheckf ((void*) mdp, (void (*) (void)) NULL, 1); + } } - return (mdp); -} - -#else /* !defined (HAVE_MMAP) */ -/* For systems without mmap, the library still supplies an entry point - to link to, but trying to initialize access to an mmap'd managed region - always fails. */ + { /* create the mutex within that heap */ + void*old_heap=mmalloc_get_current_heap(); + mmalloc_set_current_heap(mdp); + mdp->mutex =xbt_os_mutex_init(); + mmalloc_set_current_heap(old_heap); + } -/* ARGSUSED */ -PTR -mmalloc_attach (fd, baseaddr) - int fd; - PTR baseaddr; -{ - return (NULL); + return (mdp); } -#endif /* defined (HAVE_MMAP) */ -