2 * A saved SBCL system is a .core file; the code here helps us accept
3 * such a file as input.
7 * This software is part of the SBCL system. See the README file for
10 * This software is derived from the CMU CL system, which was
11 * written at Carnegie Mellon University and released into the
12 * public domain. The software is in the public domain and is
13 * provided with absolutely no warranty. See the COPYING and CREDITS
14 * files for more information.
20 #include <sys/types.h>
36 process_directory(int fd, u32 *ptr, int count)
38 struct ndir_entry *entry;
40 FSHOW((stderr, "/process_directory(..), count=%d\n", count));
42 for (entry = (struct ndir_entry *) ptr; --count>= 0; ++entry) {
44 long id = entry->identifier;
45 long offset = os_vm_page_size * (1 + entry->data_page);
46 os_vm_address_t addr =
47 (os_vm_address_t) (os_vm_page_size * entry->address);
48 lispobj *free_pointer = (lispobj *) addr + entry->nwords;
49 long len = os_vm_page_size * entry->page_count;
52 os_vm_address_t real_addr;
53 FSHOW((stderr, "/mapping %ld(0x%lx) bytes at 0x%lx\n",
54 (long)len, (long)len, addr));
55 real_addr = os_map(fd, offset, addr, len);
56 if (real_addr != addr) {
57 lose("file mapped in wrong place! "
58 "(0x%08x != 0x%08lx)",
64 FSHOW((stderr, "/space id = %d, free pointer = 0x%08x\n",
65 id, (long)free_pointer));
68 case DYNAMIC_SPACE_ID:
70 if (addr != (os_vm_address_t)DYNAMIC_SPACE_START) {
71 fprintf(stderr, "in core: 0x%lx; in runtime: 0x%lx \n",
72 (long)addr, (long)DYNAMIC_SPACE_START);
73 lose("core/runtime address mismatch: DYNAMIC_SPACE_START");
76 if ((addr != (os_vm_address_t)DYNAMIC_0_SPACE_START) &&
77 (addr != (os_vm_address_t)DYNAMIC_1_SPACE_START)) {
78 fprintf(stderr, "in core: 0x%lx; in runtime: 0x%lx or 0x%lx\n",
80 (long)DYNAMIC_0_SPACE_START,
81 (long)DYNAMIC_1_SPACE_START);
82 lose("warning: core/runtime address mismatch: DYNAMIC_SPACE_START");
85 /* FIXME: Should the conditional here be reg_ALLOC instead of
89 SetSymbolValue(ALLOCATION_POINTER, (lispobj)free_pointer);
91 dynamic_space_free_pointer = free_pointer;
93 /* For stop-and-copy GC, this will be whatever the GC was
94 * using at the time. With GENCGC, this will always be
95 * space 0. (We checked above that for GENCGC,
96 * addr==DYNAMIC_SPACE_START.) */
97 current_dynamic_space = (lispobj *)addr;
100 if (addr != (os_vm_address_t)STATIC_SPACE_START) {
101 fprintf(stderr, "in core: 0x%lx - in runtime: 0x%lx\n",
102 (long)addr, (long)STATIC_SPACE_START);
103 lose("core/runtime address mismatch: STATIC_SPACE_START");
106 case READ_ONLY_SPACE_ID:
107 if (addr != (os_vm_address_t)READ_ONLY_SPACE_START) {
108 fprintf(stderr, "in core: 0x%lx - in runtime: 0x%lx\n",
109 (long)addr, (long)READ_ONLY_SPACE_START);
110 lose("core/runtime address mismatch: READ_ONLY_SPACE_START");
114 lose("unknown space ID %ld addr 0x%p", id);
120 load_core_file(char *file)
122 u32 *header, val, len, *ptr, remaining_len;
123 int fd = open(file, O_RDONLY), count;
125 lispobj initial_function = NIL;
126 FSHOW((stderr, "/entering load_core_file(%s)\n", file));
128 fprintf(stderr, "could not open file \"%s\"\n", file);
133 header = calloc(os_vm_page_size / sizeof(u32), sizeof(u32));
135 count = read(fd, header, os_vm_page_size);
136 if (count < os_vm_page_size) {
137 lose("premature end of core file");
139 SHOW("successfully read first page of core");
144 if (val != CORE_MAGIC) {
145 lose("invalid magic number in core: 0x%lx should have been 0x%x.",
149 SHOW("found CORE_MAGIC");
151 while (val != CORE_END) {
154 remaining_len = len - 2; /* (-2 to cancel the two ++ operations) */
155 FSHOW((stderr, "/val=0x%ld, remaining_len=0x%ld\n",
156 (long)val, (long)remaining_len));
161 SHOW("CORE_END case");
165 SHOW("CORE_VERSION case");
166 if (*ptr != SBCL_CORE_VERSION_INTEGER) {
167 lose("core file version (%d) != runtime library version (%d)",
169 SBCL_CORE_VERSION_INTEGER);
173 case CORE_NDIRECTORY:
174 SHOW("CORE_NDIRECTORY case");
175 process_directory(fd,
178 remaining_len / (sizeof(struct ndir_entry) /
181 remaining_len / (sizeof(struct ndir_entry) /
187 case CORE_INITIAL_FUNCTION:
188 SHOW("CORE_INITIAL_FUNCTION case");
189 initial_function = (lispobj)*ptr;
193 lose("unknown core file entry: %ld", (long)val);
196 ptr += remaining_len;
197 FSHOW((stderr, "/new ptr=%x\n", ptr));
199 SHOW("about to free(header)");
201 SHOW("returning from load_core_file(..)");
202 return initial_function;