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>
38 process_directory(int fd, u32 *ptr, int count)
40 struct ndir_entry *entry;
42 FSHOW((stderr, "/process_directory(..), count=%d\n", count));
44 for (entry = (struct ndir_entry *) ptr; --count>= 0; ++entry) {
46 long id = entry->identifier;
47 long offset = os_vm_page_size * (1 + entry->data_page);
48 os_vm_address_t addr =
49 (os_vm_address_t) (os_vm_page_size * entry->address);
50 lispobj *free_pointer = (lispobj *) addr + entry->nwords;
51 long len = os_vm_page_size * entry->page_count;
54 os_vm_address_t real_addr;
55 FSHOW((stderr, "/mapping %ld(0x%lx) bytes at 0x%lx\n",
56 (long)len, (long)len, addr));
57 real_addr = os_map(fd, offset, addr, len);
58 if (real_addr != addr) {
59 lose("file mapped in wrong place! "
60 "(0x%08x != 0x%08lx)",
66 FSHOW((stderr, "/space id = %d, free pointer = 0x%08x\n",
67 id, (long)free_pointer));
70 case DYNAMIC_SPACE_ID:
72 if (addr != (os_vm_address_t)DYNAMIC_SPACE_START) {
73 fprintf(stderr, "in core: 0x%lx; in runtime: 0x%lx \n",
74 (long)addr, (long)DYNAMIC_SPACE_START);
75 lose("core/runtime address mismatch: DYNAMIC_SPACE_START");
78 if ((addr != (os_vm_address_t)DYNAMIC_0_SPACE_START) &&
79 (addr != (os_vm_address_t)DYNAMIC_1_SPACE_START)) {
80 fprintf(stderr, "in core: 0x%lx; in runtime: 0x%lx or 0x%lx\n",
82 (long)DYNAMIC_0_SPACE_START,
83 (long)DYNAMIC_1_SPACE_START);
84 lose("warning: core/runtime address mismatch: DYNAMIC_SPACE_START");
87 /* FIXME: Should the conditional here be reg_ALLOC instead of
91 SetSymbolValue(ALLOCATION_POINTER, (lispobj)free_pointer);
93 dynamic_space_free_pointer = free_pointer;
95 /* For stop-and-copy GC, this will be whatever the GC was
96 * using at the time. With GENCGC, this will always be
97 * space 0. (We checked above that for GENCGC,
98 * addr==DYNAMIC_SPACE_START.) */
99 current_dynamic_space = (lispobj *)addr;
101 case STATIC_SPACE_ID:
102 if (addr != (os_vm_address_t)STATIC_SPACE_START) {
103 fprintf(stderr, "in core: 0x%lx - in runtime: 0x%lx\n",
104 (long)addr, (long)STATIC_SPACE_START);
105 lose("core/runtime address mismatch: STATIC_SPACE_START");
108 case READ_ONLY_SPACE_ID:
109 if (addr != (os_vm_address_t)READ_ONLY_SPACE_START) {
110 fprintf(stderr, "in core: 0x%lx - in runtime: 0x%lx\n",
111 (long)addr, (long)READ_ONLY_SPACE_START);
112 lose("core/runtime address mismatch: READ_ONLY_SPACE_START");
116 lose("unknown space ID %ld addr 0x%p", id);
122 load_core_file(char *file)
124 u32 *header, val, len, *ptr, remaining_len;
125 int fd = open(file, O_RDONLY), count;
127 lispobj initial_function = NIL;
128 FSHOW((stderr, "/entering load_core_file(%s)\n", file));
130 fprintf(stderr, "could not open file \"%s\"\n", file);
135 header = calloc(os_vm_page_size / sizeof(u32), sizeof(u32));
137 count = read(fd, header, os_vm_page_size);
138 if (count < os_vm_page_size) {
139 lose("premature end of core file");
141 SHOW("successfully read first page of core");
146 if (val != CORE_MAGIC) {
147 lose("invalid magic number in core: 0x%lx should have been 0x%x.",
151 SHOW("found CORE_MAGIC");
153 while (val != CORE_END) {
156 remaining_len = len - 2; /* (-2 to cancel the two ++ operations) */
157 FSHOW((stderr, "/val=0x%ld, remaining_len=0x%ld\n",
158 (long)val, (long)remaining_len));
163 SHOW("CORE_END case");
167 SHOW("CORE_VERSION case");
168 if (*ptr != SBCL_CORE_VERSION_INTEGER) {
169 lose("core file version (%d) != runtime library version (%d)",
171 SBCL_CORE_VERSION_INTEGER);
175 case CORE_NDIRECTORY:
176 SHOW("CORE_NDIRECTORY case");
177 process_directory(fd,
180 remaining_len / (sizeof(struct ndir_entry) /
183 remaining_len / (sizeof(struct ndir_entry) /
189 case CORE_INITIAL_FUNCTION:
190 SHOW("CORE_INITIAL_FUNCTION case");
191 initial_function = (lispobj)*ptr;
195 lose("unknown core file entry: %ld", (long)val);
198 ptr += remaining_len;
199 FSHOW((stderr, "/new ptr=%x\n", ptr));
201 SHOW("about to free(header)");
203 SHOW("returning from load_core_file(..)");
204 return initial_function;