*
* ---------------------------------------------------------------------------*/
-/* This is non-posix compliant. */
-/* #include "PosixSource.h" */
+// This is non-posix compliant.
+// #include "PosixSource.h"
#include "Rts.h"
-#include "OSMem.h"
-#include "RtsFlags.h"
+
+#include "RtsUtils.h"
+#include "sm/OSMem.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
(errno == EINVAL && sizeof(void*)==4 && size >= 0xc0000000)) {
// If we request more than 3Gig, then we get EINVAL
// instead of ENOMEM (at least on Linux).
- errorBelch("out of memory (requested %lu bytes)", size);
- stg_exit(EXIT_FAILURE);
+ errorBelch("out of memory (requested %lu bytes)", size);
+ stg_exit(EXIT_FAILURE);
} else {
barf("getMBlock: mmap: %s", strerror(errno));
}
gen_map_mblocks (lnat size)
{
int slop;
- void *ret;
+ StgWord8 *ret;
// Try to map a larger block, and take the aligned portion from
// it (unmap the rest).
// unmap the slop bits around the chunk we allocated
slop = (W_)ret & MBLOCK_MASK;
- if (munmap(ret, MBLOCK_SIZE - slop) == -1) {
+ if (munmap((void*)ret, MBLOCK_SIZE - slop) == -1) {
barf("gen_map_mblocks: munmap failed");
}
- if (slop > 0 && munmap(ret+size-slop, slop) == -1) {
+ if (slop > 0 && munmap((void*)(ret+size-slop), slop) == -1) {
barf("gen_map_mblocks: munmap failed");
}
{
caddr_t ret;
lnat size = MBLOCK_SIZE * (lnat)n;
-
+
if (next_request == 0) {
// use gen_map_mblocks the first time.
ret = gen_map_mblocks(size);
ret = gen_map_mblocks(size);
}
}
-
// Next time, we'll try to allocate right after the block we just got.
// ToDo: check that we haven't already grabbed the memory at next_request
next_request = ret + size;
return ret;
}
+void osFreeMBlocks(char *addr, nat n)
+{
+ munmap(addr, n * MBLOCK_SIZE);
+}
+
+void osReleaseFreeMemory(void) {
+ /* Nothing to do on POSIX */
+}
+
void osFreeAllMBlocks(void)
{
- /* XXX Do something here (bug #711) */
+ void *mblock;
+
+ for (mblock = getFirstMBlock();
+ mblock != NULL;
+ mblock = getNextMBlock(mblock)) {
+ munmap(mblock, MBLOCK_SIZE);
+ }
}
lnat getPageSize (void)
StgWord size = startOfLastPage - startOfFirstPage + pageSize;
if (mprotect((void*)startOfFirstPage, (size_t)size,
(exec ? PROT_EXEC : 0) | PROT_READ | PROT_WRITE) != 0) {
- barf("makeExecutable: failed to protect 0x%p\n", p);
+ barf("setExecutable: failed to protect 0x%p\n", p);
}
}