Commit d510f5e4 authored by Austin Seipp's avatar Austin Seipp
Browse files

Nuke tabs in rts/posix/OSMem.c


Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
parent 57700b9a
......@@ -81,13 +81,13 @@ my_mmap (void *addr, W_ size)
#if defined(solaris2_HOST_OS) || defined(irix_HOST_OS)
{
int fd = open("/dev/zero",O_RDONLY);
ret = mmap(addr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd);
int fd = open("/dev/zero",O_RDONLY);
ret = mmap(addr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd);
}
#elif hpux_HOST_OS
ret = mmap(addr, size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
#elif darwin_HOST_OS
// Without MAP_FIXED, Apple's mmap ignores addr.
// With MAP_FIXED, it overwrites already mapped regions, whic
......@@ -99,18 +99,18 @@ my_mmap (void *addr, W_ size)
kern_return_t err = 0;
ret = addr;
if(addr) // try to allocate at address
err = vm_allocate(mach_task_self(),(vm_address_t*) &ret, size, FALSE);
if(!addr || err) // try to allocate anywhere
err = vm_allocate(mach_task_self(),(vm_address_t*) &ret, size, TRUE);
if(addr) // try to allocate at address
err = vm_allocate(mach_task_self(),(vm_address_t*) &ret, size, FALSE);
if(!addr || err) // try to allocate anywhere
err = vm_allocate(mach_task_self(),(vm_address_t*) &ret, size, TRUE);
if(err) {
// don't know what the error codes mean exactly, assume it's
// not our problem though.
errorBelch("memory allocation failed (requested %" FMT_Word " bytes)", size);
stg_exit(EXIT_FAILURE);
// don't know what the error codes mean exactly, assume it's
// not our problem though.
errorBelch("memory allocation failed (requested %" FMT_Word " bytes)", size);
stg_exit(EXIT_FAILURE);
} else {
vm_protect(mach_task_self(),(vm_address_t)ret,size,FALSE,VM_PROT_READ|VM_PROT_WRITE);
vm_protect(mach_task_self(),(vm_address_t)ret,size,FALSE,VM_PROT_READ|VM_PROT_WRITE);
}
#elif linux_HOST_OS
ret = mmap(addr, size, PROT_READ | PROT_WRITE,
......@@ -139,15 +139,15 @@ my_mmap (void *addr, W_ size)
#endif
if (ret == (void *)-1) {
if (errno == ENOMEM ||
(errno == EINVAL && sizeof(void*)==4 && size >= 0xc0000000)) {
// If we request more than 3Gig, then we get EINVAL
// instead of ENOMEM (at least on Linux).
if (errno == ENOMEM ||
(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 %" FMT_Word " bytes)", size);
stg_exit(EXIT_FAILURE);
} else {
barf("getMBlock: mmap: %s", strerror(errno));
}
} else {
barf("getMBlock: mmap: %s", strerror(errno));
}
}
return ret;
......@@ -207,17 +207,17 @@ osGetMBlocks(nat n)
ret = my_mmap(next_request, size);
if (((W_)ret & MBLOCK_MASK) != 0) {
// misaligned block!
// misaligned block!
#if 0 // defined(DEBUG)
errorBelch("warning: getMBlock: misaligned block %p returned when allocating %d megablock(s) at %p", ret, n, next_request);
errorBelch("warning: getMBlock: misaligned block %p returned when allocating %d megablock(s) at %p", ret, n, next_request);
#endif
// unmap this block...
if (munmap(ret, size) == -1) {
barf("getMBlock: munmap failed");
}
// and do it the hard way
ret = gen_map_mblocks(size);
// unmap this block...
if (munmap(ret, size) == -1) {
barf("getMBlock: munmap failed");
}
// and do it the hard way
ret = gen_map_mblocks(size);
}
}
// Next time, we'll try to allocate right after the block we just got.
......@@ -273,7 +273,7 @@ void setExecutable (void *p, W_ len, rtsBool exec)
StgWord startOfLastPage = ((StgWord)p + len - 1) & mask;
StgWord size = startOfLastPage - startOfFirstPage + pageSize;
if (mprotect((void*)startOfFirstPage, (size_t)size,
(exec ? PROT_EXEC : 0) | PROT_READ | PROT_WRITE) != 0) {
barf("setExecutable: failed to protect 0x%p\n", p);
(exec ? PROT_EXEC : 0) | PROT_READ | PROT_WRITE) != 0) {
barf("setExecutable: failed to protect 0x%p\n", p);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment