mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-19 09:30:44 +00:00
implement sm_InitPages/sm_FiniPages for unix. someone with more of an eye for this sort of code should tell me if what i've done here makes sense. it seems to make the tests go....
This commit is contained in:
parent
9456e00772
commit
4300354ee1
@ -39,6 +39,9 @@
|
||||
#include <Types.h>
|
||||
#include <Memory.h>
|
||||
#include <stdlib.h>
|
||||
#elif defined(XP_UNIX)
|
||||
#include <sys/mman.h>
|
||||
#include <sys/fcntl.h>
|
||||
#endif
|
||||
|
||||
SMPageMgr sm_PageMgr; /* _the_ global page manager */
|
||||
@ -316,7 +319,34 @@ sm_InitPages(SMPageMgr* pm, SMPageCount minPages, SMPageCount maxPages)
|
||||
return PR_FAILURE;
|
||||
|
||||
#else
|
||||
# error "write me"
|
||||
|
||||
SMPage* addr = NULL;
|
||||
SMPageCount size = maxPages;
|
||||
int zero_fd;
|
||||
|
||||
zero_fd = open("/dev/zero", O_RDWR);
|
||||
|
||||
while (addr == NULL) {
|
||||
/* let the system place the heap */
|
||||
addr = (SMPage*)mmap(0, size << SM_PAGE_BITS,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE,
|
||||
zero_fd, 0);
|
||||
if (addr == (SMPage*)MAP_FAILED) {
|
||||
addr = NULL;
|
||||
size--;
|
||||
if (size < minPages) {
|
||||
return PR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
SM_ASSERT(SM_IS_ALIGNED(addr, SM_PAGE_BITS));
|
||||
pm->memoryBase = addr;
|
||||
pm->pageCount = size;
|
||||
pm->boundary = addr;
|
||||
pm->minPage = SM_PAGE_NUMBER(addr);
|
||||
|
||||
return PR_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -336,7 +366,7 @@ sm_FiniPages(SMPageMgr* pm)
|
||||
#elif defined(XP_MAC)
|
||||
|
||||
#else
|
||||
# error "write me"
|
||||
munmap((caddr_t)pm->memoryBase, pm->pageCount << SM_PAGE_BITS);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user