X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0ed506b0a9c949af9b2f672ac917ecaedca266c0..87817af89b2262a403386b38a0ec95388a6df5ad:/src/xbt/mmalloc/mmorecore.c diff --git a/src/xbt/mmalloc/mmorecore.c b/src/xbt/mmalloc/mmorecore.c index 2c68d503e4..9e2d22ed53 100644 --- a/src/xbt/mmalloc/mmorecore.c +++ b/src/xbt/mmalloc/mmorecore.c @@ -21,7 +21,6 @@ #include #include "mmprivate.h" -#include "xbt/ex.h" /* Cache the pagesize for the current host machine. Note that if the host does not readily provide a getpagesize() function, we need to emulate it @@ -113,17 +112,15 @@ void *mmorecore(struct mdesc *mdp, int size) MAP_PRIVATE_OR_SHARED(mdp) | MAP_IS_ANONYMOUS(mdp) | MAP_FIXED, MAP_ANON_OR_FD(mdp), foffset); - if (mapto != (void *) -1/* That's MAP_FAILED */) { + if (mapto == (void *) -1/* That's MAP_FAILED */) + THROWF(system_error,0,"mmap returned MAP_FAILED! error: %s",strerror(errno)); - if (mdp->top == 0) - mdp->base = mdp->breakval = mapto; + if (mdp->top == 0) + mdp->base = mdp->breakval = mapto; - mdp->top = PAGE_ALIGN((char *) mdp->breakval + size); - result = (void *) mdp->breakval; - mdp->breakval = (char *) mdp->breakval + size; - } else { - THROWF(system_error,0,"mmap returned MAP_FAILED! error: %s",strerror(errno)); - } + mdp->top = PAGE_ALIGN((char *) mdp->breakval + size); + result = (void *) mdp->breakval; + mdp->breakval = (char *) mdp->breakval + size; } else { result = (void *) mdp->breakval; mdp->breakval = (char *) mdp->breakval + size; @@ -132,53 +129,12 @@ void *mmorecore(struct mdesc *mdp, int size) return (result); } -void *__mmalloc_remap_core(struct mdesc *mdp) +void *__mmalloc_remap_core(xbt_mheap_t mdp) { - void *base; - /* FIXME: Quick hack, needs error checking and other attention. */ - base = mmap(mdp->base, (char *) mdp->top - (char *) mdp->base, + return mmap(mdp->base, (char*) mdp->top - (char*) mdp->base, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE_OR_SHARED(mdp) | MAP_FIXED, mdp->fd, 0); - return ((void *) base); } -void *mmalloc_findbase(int size) -{ - int fd; - int flags; - void *base = NULL; - -#ifdef MAP_ANONYMOUS - flags = MAP_PRIVATE | MAP_ANONYMOUS; - fd = -1; -#else -#ifdef MAP_FILE - flags = MAP_PRIVATE | MAP_FILE; -#else - flags = MAP_PRIVATE; -#endif - fd = open("/dev/zero", O_RDWR); - if (fd != -1) { - return ((void *) NULL); - } -#endif - base = mmap(0, size, PROT_READ | PROT_WRITE, flags, fd, 0); - if (base != (void *) -1) { - munmap(base, (size_t) size); - } - if (fd != -1) { - close(fd); - } - if (base == 0) { - /* Don't allow mapping at address zero. We use that value - to signal an error return, and besides, it is useful to - catch NULL pointers if it is unmapped. Instead start - at the next page boundary. */ - base = (void *) (long) getpagesize(); - } else if (base == (void *) -1) { - base = NULL; - } - return ((void *) base); -}