add sysErrorBelch() for reporting system call errors
[ghc-hetmet.git] / rts / MBlock.c
index f317690..9058205 100644 (file)
@@ -337,9 +337,8 @@ allocNew(nat n) {
     if(rec->base==0) {
         stgFree((void*)rec);
         rec=0;
-        errorBelch(
-            "getMBlocks: VirtualAlloc MEM_RESERVE %d blocks failed with: %ld\n"
-            , n, GetLastError());
+        sysErrorBelch(
+            "getMBlocks: VirtualAlloc MEM_RESERVE %d blocks failed", n);
     } else {
         if(allocs==0) {
             allocs=rec;
@@ -450,8 +449,10 @@ commitBlocks(char* base, int size) {
         size_delta = it->size - (base-it->base);
         if(size_delta>size) size_delta=size;
         temp = VirtualAlloc(base, size_delta, MEM_COMMIT, PAGE_READWRITE);
-        if(temp==0)
-            debugBelch("getMBlocks: VirtualAlloc MEM_COMMIT failed: %ld", GetLastError());
+        if(temp==0) {
+            sysErrorBelch("getMBlocks: VirtualAlloc MEM_COMMIT failed");
+           stg_exit(EXIT_FAILURE);
+       }
         size-=size_delta;
         base+=size_delta;
     }
@@ -465,10 +466,12 @@ getMBlocks(nat n) {
         alloc_rec* alloc;
         alloc = allocNew(n);
         /* We already belch in allocNew if it fails */
-        if(alloc!=0) {
+       if (alloc == 0) {
+           stg_exit(EXIT_FAILURE);
+       } else {
             insertFree(alloc->base, alloc->size);
             ret = findFreeBlocks(n);
-        }
+       }
     }
 
     if(ret!=0) {
@@ -511,7 +514,8 @@ freeAllMBlocks(void)
         it=allocs;
         for(; it!=0; ) {
             if(!VirtualFree((void*)it->base, 0, MEM_RELEASE)) {
-                debugBelch("freeAllMBlocks: VirtualFree MEM_RELEASE failed with %ld", GetLastError());
+                sysErrorBelch("freeAllMBlocks: VirtualFree MEM_RELEASE failed");
+               stg_exit(EXIT_FAILURE);
             }
             next = it->next;
             stgFree(it);