From: Simon Marlow Date: Tue, 29 Jul 2008 15:04:59 +0000 (+0000) Subject: FIX #2332: avoid overflow on 64-bit machines in the memory allocator X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=d9aa9b1a3059bd6c96f83fadec0419c22606f5f3 FIX #2332: avoid overflow on 64-bit machines in the memory allocator --- diff --git a/includes/Storage.h b/includes/Storage.h index 34a5411..caa7c1d 100644 --- a/includes/Storage.h +++ b/includes/Storage.h @@ -184,10 +184,10 @@ extern void freeStorage(void); -------------------------------------------------------------------------- */ -extern StgPtr allocate ( nat n ); -extern StgPtr allocateInGen ( generation *g, nat n ); -extern StgPtr allocateLocal ( Capability *cap, nat n ); -extern StgPtr allocatePinned ( nat n ); +extern StgPtr allocate ( lnat n ); +extern StgPtr allocateInGen ( generation *g, lnat n ); +extern StgPtr allocateLocal ( Capability *cap, lnat n ); +extern StgPtr allocatePinned ( lnat n ); extern lnat allocatedBytes ( void ); extern bdescr * RTS_VAR(small_alloc_list); diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c index 66f6309..7216f0e 100644 --- a/rts/posix/OSMem.c +++ b/rts/posix/OSMem.c @@ -176,7 +176,7 @@ void * osGetMBlocks(nat n) { caddr_t ret; - lnat size = MBLOCK_SIZE * n; + lnat size = MBLOCK_SIZE * (lnat)n; if (next_request == 0) { // use gen_map_mblocks the first time. diff --git a/rts/sm/Storage.c b/rts/sm/Storage.c index 69e441d..a41894a 100644 --- a/rts/sm/Storage.c +++ b/rts/sm/Storage.c @@ -585,7 +585,7 @@ move_TSO (StgTSO *src, StgTSO *dest) -------------------------------------------------------------------------- */ StgPtr -allocateInGen (generation *g, nat n) +allocateInGen (generation *g, lnat n) { step *stp; bdescr *bd; @@ -600,7 +600,7 @@ allocateInGen (generation *g, nat n) if (n >= LARGE_OBJECT_THRESHOLD/sizeof(W_)) { - nat req_blocks = (lnat)BLOCK_ROUND_UP(n*sizeof(W_)) / BLOCK_SIZE; + lnat req_blocks = (lnat)BLOCK_ROUND_UP(n*sizeof(W_)) / BLOCK_SIZE; // Attempting to allocate an object larger than maxHeapSize // should definitely be disallowed. (bug #1791) @@ -642,7 +642,7 @@ allocateInGen (generation *g, nat n) } StgPtr -allocate (nat n) +allocate (lnat n) { return allocateInGen(g0,n); } @@ -703,7 +703,7 @@ splitLargeBlock (bdescr *bd, nat blocks) -------------------------------------------------------------------------- */ StgPtr -allocateLocal (Capability *cap, nat n) +allocateLocal (Capability *cap, lnat n) { bdescr *bd; StgPtr p; @@ -780,7 +780,7 @@ allocateLocal (Capability *cap, nat n) ------------------------------------------------------------------------- */ StgPtr -allocatePinned( nat n ) +allocatePinned( lnat n ) { StgPtr p; bdescr *bd = pinned_object_block;