#include <sys/mman.h>
#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
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;
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);
-}