summaryrefslogtreecommitdiff
path: root/rts/PrimOps.cmm
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2017-09-26 15:09:13 -0400
committerBen Gamari <ben@smart-cactus.org>2017-09-26 17:40:03 -0400
commit30a1eeea37e224e4ade9b8e7cdd30076cb716960 (patch)
treea686de6c4aa4b1dbb9622b1af0ba5b699d79fe49 /rts/PrimOps.cmm
parent018c40fb1bb27853d0cefa5b90a44ce13e91a856 (diff)
downloadhaskell-30a1eeea37e224e4ade9b8e7cdd30076cb716960.tar.gz
rts: Throw proper HeapOverflow exception on allocating large array
Test Plan: Validate, add tests Reviewers: simonmar, austin, erikd Reviewed By: simonmar Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D4021
Diffstat (limited to 'rts/PrimOps.cmm')
-rw-r--r--rts/PrimOps.cmm26
1 files changed, 22 insertions, 4 deletions
diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm
index 4d54ecf6dc..b43dfbf554 100644
--- a/rts/PrimOps.cmm
+++ b/rts/PrimOps.cmm
@@ -62,7 +62,10 @@ stg_newByteArrayzh ( W_ n )
payload_words = ROUNDUP_BYTES_TO_WDS(n);
words = BYTES_TO_WDS(SIZEOF_StgArrBytes) + payload_words;
- ("ptr" p) = ccall allocate(MyCapability() "ptr",words);
+ ("ptr" p) = ccall allocateMightFail(MyCapability() "ptr", words);
+ if (p == NULL) {
+ jump stg_raisezh(base_GHCziIOziException_heapOverflow_closure);
+ }
TICK_ALLOC_PRIM(SIZEOF_StgArrBytes,WDS(payload_words),0);
SET_HDR(p, stg_ARR_WORDS_info, CCCS);
StgArrBytes_bytes(p) = n;
@@ -92,6 +95,9 @@ stg_newPinnedByteArrayzh ( W_ n )
words = ROUNDUP_BYTES_TO_WDS(bytes);
("ptr" p) = ccall allocatePinned(MyCapability() "ptr", words);
+ if (p == NULL) {
+ jump stg_raisezh(base_GHCziIOziException_heapOverflow_closure);
+ }
TICK_ALLOC_PRIM(SIZEOF_StgArrBytes,WDS(payload_words),0);
/* Now we need to move p forward so that the payload is aligned
@@ -130,6 +136,9 @@ stg_newAlignedPinnedByteArrayzh ( W_ n, W_ alignment )
words = ROUNDUP_BYTES_TO_WDS(bytes);
("ptr" p) = ccall allocatePinned(MyCapability() "ptr", words);
+ if (p == NULL) {
+ jump stg_raisezh(base_GHCziIOziException_heapOverflow_closure);
+ }
TICK_ALLOC_PRIM(SIZEOF_StgArrBytes,WDS(payload_words),0);
/* Now we need to move p forward so that the payload is aligned
@@ -240,7 +249,10 @@ stg_newArrayzh ( W_ n /* words */, gcptr init )
// number of words.
size = n + mutArrPtrsCardWords(n);
words = BYTES_TO_WDS(SIZEOF_StgMutArrPtrs) + size;
- ("ptr" arr) = ccall allocate(MyCapability() "ptr",words);
+ ("ptr" arr) = ccall allocateMightFail(MyCapability() "ptr",words);
+ if (arr == NULL) {
+ jump stg_raisezh(base_GHCziIOziException_heapOverflow_closure);
+ }
TICK_ALLOC_PRIM(SIZEOF_StgMutArrPtrs, WDS(size), 0);
SET_HDR(arr, stg_MUT_ARR_PTRS_DIRTY_info, CCCS);
@@ -366,7 +378,10 @@ stg_newArrayArrayzh ( W_ n /* words */ )
// number of words.
size = n + mutArrPtrsCardWords(n);
words = BYTES_TO_WDS(SIZEOF_StgMutArrPtrs) + size;
- ("ptr" arr) = ccall allocate(MyCapability() "ptr",words);
+ ("ptr" arr) = ccall allocateMightFail(MyCapability() "ptr",words);
+ if (arr == NULL) {
+ jump stg_raisezh(base_GHCziIOziException_heapOverflow_closure);
+ }
TICK_ALLOC_PRIM(SIZEOF_StgMutArrPtrs, WDS(size), 0);
SET_HDR(arr, stg_MUT_ARR_PTRS_DIRTY_info, W_[CCCS]);
@@ -398,7 +413,10 @@ stg_newSmallArrayzh ( W_ n /* words */, gcptr init )
again: MAYBE_GC(again);
words = BYTES_TO_WDS(SIZEOF_StgSmallMutArrPtrs) + n;
- ("ptr" arr) = ccall allocate(MyCapability() "ptr",words);
+ ("ptr" arr) = ccall allocateMightFail(MyCapability() "ptr",words);
+ if (arr == NULL) {
+ jump stg_raisezh(base_GHCziIOziException_heapOverflow_closure);
+ }
TICK_ALLOC_PRIM(SIZEOF_StgSmallMutArrPtrs, WDS(n), 0);
SET_HDR(arr, stg_SMALL_MUT_ARR_PTRS_DIRTY_info, CCCS);