X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/637cf04c852010b27c719a4979dd26998b8da4b9..63c371bbca5afccc4708761d83af6fc2443ca553:/src/xbt/mmalloc/mmorecore.c diff --git a/src/xbt/mmalloc/mmorecore.c b/src/xbt/mmalloc/mmorecore.c index b99f32259e..e876dd2ba5 100644 --- a/src/xbt/mmalloc/mmorecore.c +++ b/src/xbt/mmalloc/mmorecore.c @@ -10,7 +10,8 @@ Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com */ -#ifdef HAVE_UNISTD_H +#include "src/internal_config.h" +#if HAVE_UNISTD_H #include /* Prototypes for lseek */ #endif #include @@ -44,6 +45,11 @@ ? -1 \ : (MDP) -> fd) +/* Return 0if MDP uses anonymous mapping. Otherwise, return off */ +#define MAP_ANON_OR_OFFSET(MDP, off) (((MDP) -> flags & MMALLOC_ANONYMOUS) \ + ? 0 \ + : off) + /** @brief Add memoty to this heap * * Get core for the memory region specified by MDP, using SIZE as the @@ -118,12 +124,12 @@ void *mmorecore(struct mdesc *mdp, ssize_t size) */ mapto = mmap(mdp->top, mapbytes, PROT_READ | PROT_WRITE, MAP_PRIVATE_OR_SHARED(mdp) | MAP_IS_ANONYMOUS(mdp) | - MAP_FIXED, MAP_ANON_OR_FD(mdp), foffset); + MAP_FIXED, MAP_ANON_OR_FD(mdp), MAP_ANON_OR_OFFSET(mdp, foffset)); if (mapto == MAP_FAILED) { char buff[1024]; fprintf(stderr,"Internal error: mmap returned MAP_FAILED! error: %s\n",strerror(errno)); - sprintf(buff,"cat /proc/%d/maps",getpid()); + snprintf(buff,1024,"cat /proc/%d/maps",getpid()); int status = system(buff); if (status == -1 || !(WIFEXITED(status) && WEXITSTATUS(status) == 0)) fprintf(stderr, "Something went wrong when trying to %s\n", buff);