summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2012-05-05 14:54:09 +0100
committerIan Lynagh <igloo@earth.li>2012-05-05 14:54:09 +0100
commita8787ece1d6cd807fb3c76efd80753e7ffc87f1e (patch)
treebeabbc958f610d02adf41f7c68c45a55d18c694c
parent88f694dd488bfe475c7dfac20ad47781c5689785 (diff)
downloadhaskell-a8787ece1d6cd807fb3c76efd80753e7ffc87f1e.tar.gz
Use lnats to avoid overflowing when allocating large amounts
Stops outofmem segfaulting on Win64
-rw-r--r--rts/win32/OSMem.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/rts/win32/OSMem.c b/rts/win32/OSMem.c
index e0f38d36a0..d9a6459f3d 100644
--- a/rts/win32/OSMem.c
+++ b/rts/win32/OSMem.c
@@ -16,13 +16,13 @@
typedef struct alloc_rec_ {
char* base; /* non-aligned base address, directly from VirtualAlloc */
- int size; /* Size in bytes */
+ lnat size; /* Size in bytes */
struct alloc_rec_* next;
} alloc_rec;
typedef struct block_rec_ {
char* base; /* base address, non-MBLOCK-aligned */
- int size; /* size in bytes */
+ lnat size; /* size in bytes */
struct block_rec_* next;
} block_rec;
@@ -46,7 +46,7 @@ alloc_rec*
allocNew(nat n) {
alloc_rec* rec;
rec = (alloc_rec*)stgMallocBytes(sizeof(alloc_rec),"getMBlocks: allocNew");
- rec->size = (n+1)*MBLOCK_SIZE;
+ rec->size = ((lnat)n+1)*MBLOCK_SIZE;
rec->base =
VirtualAlloc(NULL, rec->size, MEM_RESERVE, PAGE_READWRITE);
if(rec->base==0) {
@@ -76,7 +76,7 @@ allocNew(nat n) {
static
void
-insertFree(char* alloc_base, int alloc_size) {
+insertFree(char* alloc_base, lnat alloc_size) {
block_rec temp;
block_rec* it;
block_rec* prev;
@@ -116,7 +116,7 @@ findFreeBlocks(nat n) {
block_rec temp;
block_rec* prev;
- int required_size;
+ lnat required_size;
it=free_blocks;
required_size = n*MBLOCK_SIZE;
temp.next=free_blocks; temp.base=0; temp.size=0;
@@ -158,12 +158,12 @@ findFreeBlocks(nat n) {
so we might need to do many VirtualAlloc MEM_COMMITs. We simply walk the
(ordered) allocated blocks. */
static void
-commitBlocks(char* base, int size) {
+commitBlocks(char* base, lnat size) {
alloc_rec* it;
it=allocs;
for( ; it!=0 && (it->base+it->size)<=base; it=it->next ) {}
for( ; it!=0 && size>0; it=it->next ) {
- int size_delta;
+ lnat size_delta;
void* temp;
size_delta = it->size - (base-it->base);
if(size_delta>size) size_delta=size;
@@ -199,7 +199,7 @@ osGetMBlocks(nat n) {
barf("getMBlocks: misaligned block returned");
}
- commitBlocks(ret, MBLOCK_SIZE*n);
+ commitBlocks(ret, (lnat)MBLOCK_SIZE*n);
}
return ret;