From: Martin Quinson Date: Wed, 1 Feb 2012 14:56:58 +0000 (+0100) Subject: rename sup-mmap.c into mmorecore.c and simplify the code since we want no more than... X-Git-Tag: exp_20120216~104 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0ed506b0a9c949af9b2f672ac917ecaedca266c0 rename sup-mmap.c into mmorecore.c and simplify the code since we want no more than one core provider --- diff --git a/src/xbt/mmalloc/attach.c b/src/xbt/mmalloc/attach.c index 5c6b3d286b..228141fa54 100644 --- a/src/xbt/mmalloc/attach.c +++ b/src/xbt/mmalloc/attach.c @@ -105,7 +105,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 +128,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!"); @@ -192,7 +191,6 @@ 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++; diff --git a/src/xbt/mmalloc/detach.c b/src/xbt/mmalloc/detach.c index e1157ed081..5dfaf4224d 100644 --- a/src/xbt/mmalloc/detach.c +++ b/src/xbt/mmalloc/detach.c @@ -57,7 +57,7 @@ void *mmalloc_detach(void *md) /* Now unmap all the pages associated with this region by asking for a negative increment equal to the current size of the region. */ - if ((mtemp.morecore(&mtemp, + if ((mmorecore(&mtemp, (char *) mtemp.base - (char *) mtemp.breakval)) == NULL) { /* Deallocating failed. Update the original malloc descriptor diff --git a/src/xbt/mmalloc/mm.c b/src/xbt/mmalloc/mm.c index 7396adda8d..ee448555f4 100644 --- a/src/xbt/mmalloc/mm.c +++ b/src/xbt/mmalloc/mm.c @@ -22,7 +22,7 @@ #include "mmstats.c" #include "mrealloc.c" #include "mvalloc.c" -#include "mmap-sup.c" +#include "mmorecore.c" #include "attach.c" #include "detach.c" #include "mm_legacy.c" diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index fe893b0c25..e9e8588bf1 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -27,11 +27,11 @@ static void *align(struct mdesc *mdp, size_t size) void *result; unsigned long int adj; - result = mdp->morecore(mdp, size); + result = mmorecore(mdp, size); adj = RESIDUAL(result, BLOCKSIZE); if (adj != 0) { adj = BLOCKSIZE - adj; - mdp->morecore(mdp, adj); + mmorecore(mdp, adj); result = (char *) result + adj; } return (result); @@ -78,7 +78,7 @@ static void *morecore(struct mdesc *mdp, size_t size) } newinfo = (malloc_info *) align(mdp, newsize * sizeof(malloc_info)); if (newinfo == NULL) { - mdp->morecore(mdp, -size); + mmorecore(mdp, -size); return (NULL); } memset((void *) newinfo, 0, newsize * sizeof(malloc_info)); @@ -209,7 +209,7 @@ void *mmalloc(void *md, size_t size) lastblocks = mdp->heapinfo[block].free.size; if (mdp->heaplimit != 0 && block + lastblocks == mdp->heaplimit && - mdp->morecore(mdp, 0) == ADDRESS(block + lastblocks) && + mmorecore(mdp, 0) == ADDRESS(block + lastblocks) && (morecore(mdp, (blocks - lastblocks) * BLOCKSIZE)) != NULL) { /* Which block we are extending (the `final free block' referred to above) might have changed, if diff --git a/src/xbt/mmalloc/mmap-sup.c b/src/xbt/mmalloc/mmorecore.c similarity index 99% rename from src/xbt/mmalloc/mmap-sup.c rename to src/xbt/mmalloc/mmorecore.c index 964e484c31..2c68d503e4 100644 --- a/src/xbt/mmalloc/mmap-sup.c +++ b/src/xbt/mmalloc/mmorecore.c @@ -53,7 +53,7 @@ static size_t pagesize; amount to either add to or subtract from the existing region. Works like sbrk(), but using mmap(). */ -void *__mmalloc_mmap_morecore(struct mdesc *mdp, int size) +void *mmorecore(struct mdesc *mdp, int size) { ssize_t test = 0; void *result = NULL; diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index f351b59082..37673659aa 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -165,17 +165,6 @@ struct mdesc { preserved for future examination. */ int saved_errno; - /* Pointer to the function that is used to get more core, or return core - to the system, for requests using this malloc descriptor. For memory - mapped regions, this is the mmap() based routine. There may also be - a single malloc descriptor that points to an sbrk() based routine - for systems without mmap() or for applications that call the mmalloc() - package with a NULL malloc descriptor. - - FIXME: For mapped regions shared by more than one process, this - needs to be maintained on a per-process basis. */ - void *(*morecore) (struct mdesc * mdp, int size); - /* Number of info entries. */ size_t heapsize; @@ -268,6 +257,11 @@ extern void *__mmalloc_mmap_morecore(struct mdesc *mdp, int size); extern void *__mmalloc_remap_core(struct mdesc *mdp); +/* Get core for the memory region specified by MDP, using SIZE as the + amount to either add to or subtract from the existing region. Works + like sbrk(), but using mmap(). */ +extern void *mmorecore(struct mdesc *mdp, int size); + /* Macro to convert from a user supplied malloc descriptor to pointer to the internal malloc descriptor. If the user supplied descriptor is NULL, then use the default internal version, initializing it if necessary. Otherwise