changeset 939077a54014 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=939077a54014
description:
        Mem: Allow serializing of more than INT_MAX bytes

        Despite gzwrite taking an unsigned for length, it returns an int for
        bytes written; gzwrite fails if (int)len < 0.  Because of this, call
        gzwrite with len no larger than INT_MAX: write in blocks of INT_MAX if
        data to be written is larger than INT_MAX.

diffstat:

 src/mem/abstract_mem.cc |  15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diffs (32 lines):

diff -r 5c8e92f3d6f7 -r 939077a54014 src/mem/abstract_mem.cc
--- a/src/mem/abstract_mem.cc   Mon Sep 10 11:57:42 2012 -0400
+++ b/src/mem/abstract_mem.cc   Mon Sep 10 11:57:43 2012 -0400
@@ -51,6 +51,7 @@
 
 #include <cerrno>
 #include <cstdio>
+#include <climits>
 #include <iostream>
 #include <string>
 
@@ -486,9 +487,17 @@
         fatal("Insufficient memory to allocate compression state for %s\n",
                 filename);
 
-    if (gzwrite(compressedMem, pmemAddr, size()) != (int)size()) {
-        fatal("Write failed on physical memory checkpoint file '%s'\n",
-              filename);
+    uint64_t pass_size = 0;
+    // gzwrite fails if (int)len < 0 (gzwrite returns int)
+    for (uint64_t written = 0; written < size(); written += pass_size) {
+        pass_size = (uint64_t)INT_MAX < (size() - written) ?
+            (uint64_t)INT_MAX : (size() - written);
+
+        if (gzwrite(compressedMem, pmemAddr + written,
+                    (unsigned int) pass_size) != (int)pass_size) {
+            fatal("Write failed on physical memory checkpoint file '%s'\n",
+                  filename);
+        }
     }
 
     if (gzclose(compressedMem))
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to