cleanup: types in gc_alloc_update_page_tables
[sbcl.git] / src / runtime / coreparse.c
index a794c39..240c8c8 100644 (file)
 #include <unistd.h>
 
 #include "sbcl.h"
+
+#ifndef LISP_FEATURE_WIN32
+#ifdef LISP_FEATURE_LINUX
+/* For madvise */
+# define _BSD_SOURCE
+#endif
+#include <sys/mman.h>
+#endif
+
 #include "os.h"
 #include "runtime.h"
 #include "globals.h"
 
 #include "validate.h"
 #include "gc-internal.h"
-
-/* lutex stuff */
-#if defined(LISP_FEATURE_SB_THREAD) && defined(LISP_FEATURE_SB_LUTEX)
-#include "genesis/sap.h"
-#include "pthread-lutex.h"
-#endif
+#include "runtime-options.h"
 
 #include <errno.h>
 
@@ -65,10 +69,10 @@ open_binary(char *filename, int mode)
 static struct runtime_options *
 read_runtime_options(int fd)
 {
-    size_t optarray[RUNTIME_OPTIONS_WORDS];
+    os_vm_size_t optarray[RUNTIME_OPTIONS_WORDS];
     struct runtime_options *options = NULL;
 
-    if (read(fd, optarray, RUNTIME_OPTIONS_WORDS * sizeof(size_t)) !=
+    if (read(fd, optarray, RUNTIME_OPTIONS_WORDS * sizeof(os_vm_size_t)) !=
         RUNTIME_OPTIONS_WORDS * sizeof(size_t)) {
         return NULL;
     }
@@ -95,7 +99,7 @@ maybe_initialize_runtime_options(int fd)
 
     lseek(fd, -end_offset, SEEK_END);
 
-    if (new_runtime_options = read_runtime_options(fd)) {
+    if ((new_runtime_options = read_runtime_options(fd))) {
         runtime_options = new_runtime_options;
     }
 }
@@ -262,6 +266,8 @@ os_vm_address_t inflate_core_bytes(int fd, os_vm_offset_t offset,
 # undef ZLIB_BUFFER_SIZE
 #endif
 
+int merge_core_pages = -1;
+
 static void
 process_directory(int fd, lispobj *ptr, int count, os_vm_offset_t file_offset)
 {
@@ -308,6 +314,13 @@ process_directory(int fd, lispobj *ptr, int count, os_vm_offset_t file_offset)
             }
         }
 
+#ifdef MADV_MERGEABLE
+        if ((merge_core_pages == 1)
+            || ((merge_core_pages == -1) && compressed)) {
+                madvise(addr, len, MADV_MERGEABLE);
+        }
+#endif
+
         FSHOW((stderr, "/space id = %ld, free pointer = 0x%lx\n",
                id, (unsigned long)free_pointer));
 
@@ -472,47 +485,12 @@ load_core_file(char *file, os_vm_offset_t file_offset)
             initial_function = (lispobj)*ptr;
             break;
 
-#if defined(LISP_FEATURE_SB_THREAD) && defined(LISP_FEATURE_SB_LUTEX)
-        case LUTEX_TABLE_CORE_ENTRY_TYPE_CODE:
-            SHOW("LUTEX_TABLE_CORE_ENTRY_TYPE_CODE case");
-            {
-                size_t n_lutexes = *ptr;
-                size_t fdoffset = (*(ptr + 1) + 1) * (os_vm_page_size);
-                size_t data_length = n_lutexes * sizeof(struct sap *);
-                struct lutex **lutexes_to_resurrect = malloc(data_length);
-                long bytes_read;
-
-                lseek(fd, fdoffset + file_offset, SEEK_SET);
-
-                FSHOW((stderr, "attempting to read %ld lutexes from core\n", n_lutexes));
-                bytes_read = read(fd, lutexes_to_resurrect, data_length);
-
-                /* XXX */
-                if (bytes_read != data_length) {
-                    lose("Could not read the lutex table");
-                }
-                else {
-                    int i;
-
-                    for (i=0; i<n_lutexes; ++i) {
-                        struct lutex *lutex = lutexes_to_resurrect[i];
-
-                        FSHOW((stderr, "re-init'ing lutex @ %p\n", lutex));
-                        lutex_init((tagged_lutex_t) lutex);
-                    }
-
-                    free(lutexes_to_resurrect);
-                }
-                break;
-            }
-#endif
-
 #ifdef LISP_FEATURE_GENCGC
         case PAGE_TABLE_CORE_ENTRY_TYPE_CODE:
         {
             size_t size = *ptr;
             size_t fdoffset = (*(ptr+1) + 1) * (os_vm_page_size);
-            size_t offset = 0;
+            page_index_t offset = 0;
             long bytes_read;
             unsigned long data[4096];
             unsigned long word;