[commit: ghc] master: Use lnats to avoid overflowing when allocating large amounts (a8787ec)

Ian Lynagh igloo at earth.li
Sat May 5 20:06:36 CEST 2012


Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/a8787ece1d6cd807fb3c76efd80753e7ffc87f1e

>---------------------------------------------------------------

commit a8787ece1d6cd807fb3c76efd80753e7ffc87f1e
Author: Ian Lynagh <igloo at earth.li>
Date:   Sat May 5 14:54:09 2012 +0100

    Use lnats to avoid overflowing when allocating large amounts
    
    Stops outofmem segfaulting on Win64

>---------------------------------------------------------------

 rts/win32/OSMem.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/rts/win32/OSMem.c b/rts/win32/OSMem.c
index e0f38d3..d9a6459 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;





More information about the Cvs-ghc mailing list