Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com */
-#ifdef HAVE_UNISTD_H
+#include "src/internal_config.h"
+#if HAVE_UNISTD_H
#include <unistd.h> /* Prototypes for lseek */
#endif
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>
+#include <errno.h>
#include "mmprivate.h"
? -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
*/
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);