Ben Bass avatar Ben Bass committed cc8f03d

fix munmap sigsegv fault when run on linux

Comments (0)

Files changed (3)

 
 superclean: clean
 	rm -f mandel_*.dat
-
 
 #include <pthread.h>
 
+#ifndef _POSIX_MAPPED_FILES
+#error "no mapped file support"
+#endif
+
 #ifndef MAP_NOCACHE
 #define MAP_NOCACHE 0
 #endif
     // floating point can exactly represent the values. Work out the
     // such a value by repeated dividing by two.
     //
-    // TODO: this is all constant, so use a bit of TMP on it.
+    // TODO: this is all constant, so use a bit of TMP on it. Just for fun
     FLOAT step = 1.0;
     unsigned long long invstep = 1;
     for (int i=0; i<BINARY_DIGITS; i++)
             MAP_FILE|MAP_SHARED|MAP_NOCACHE,
             fd, 0)))
     {
+        printf("mmap failed\n");
         return 1;
     }
     close(fd);  // we no longer need the FD when we have the mapping
 
+    void* sourceBuffer = mapping;  // for unmmaping later
     brotfile_header* fheader = (brotfile_header*)(mapping);
     pinfo* fptr = (pinfo*)((char*)mapping+HEADER_LEN);
-    void* sourceBuffer = fptr;  // for unmmaping later
 
     printf("mapped file %d at %p %llu bytes\n", fd, fptr, mapsize);
     printf("Current MAX_ITER: %d\n", fheader->max_iter);
-// MandelMap - copyright Ben Bass 2010-2011
+// MandelMap - Ben Bass 2010-2012
 
 #ifndef MANDEL_MAP_H
 #define MANDEL_MAP_H
 };
 
 
-const int HEADER_LEN=4096;
+const int HEADER_LEN=4096;  // probable page size for happiness
 struct brotfile_header
 {
     FLOAT startx;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.