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.
18 #include <sys/types.h>
35 process_directory(int fd, long *ptr, int count)
37 struct ndir_entry *entry;
39 FSHOW((stderr, "/process_directory(..), count=%d\n", count));
41 for (entry = (struct ndir_entry *) ptr; --count>= 0; ++entry) {
43 long id = entry->identifier;
44 long offset = os_vm_page_size * (1 + entry->data_page);
45 os_vm_address_t addr =
46 (os_vm_address_t) (os_vm_page_size * entry->address);
47 lispobj *free_pointer = (lispobj *) addr + entry->nwords;
48 long len = os_vm_page_size * entry->page_count;
51 os_vm_address_t real_addr;
52 FSHOW((stderr, "/mapping %ld(0x%lx) bytes at 0x%lx\n",
53 (long)len, (long)len, addr));
54 real_addr = os_map(fd, offset, addr, len);
55 if (real_addr != addr) {
56 lose("file mapped in wrong place! "
57 "(0x%08x != 0x%08lx)",
63 FSHOW((stderr, "/space id = %d, free pointer = 0x%08x\n",
64 id, (long)free_pointer));
67 case DYNAMIC_SPACE_ID:
69 if (addr != (os_vm_address_t)DYNAMIC_SPACE_START) {
70 fprintf(stderr, "in core: 0x%x - in runtime: 0x%x \n",
71 addr, (os_vm_address_t)DYNAMIC_SPACE_START);
72 fprintf(stderr,"warning: core/runtime address mismatch: DYNAMIC_SPACE_START");
75 if ((addr != (os_vm_address_t)DYNAMIC_0_SPACE_START) &&
76 (addr != (os_vm_address_t)DYNAMIC_1_SPACE_START)) {
77 fprintf(stderr, "in core: 0x%x - in runtime: 0x%x or 0x%x\n",
78 addr, (os_vm_address_t)DYNAMIC_0_SPACE_START,
79 (os_vm_address_t)DYNAMIC_1_SPACE_START);
80 fprintf(stderr,"warning: core/runtime address mismatch: DYNAMIC_SPACE_START");
83 /* FIXME: Should the conditional here be reg_ALLOC instead of
84 * defined(ibmrt) || defined(__i386__)
86 #if defined(ibmrt) || defined(__i386__)
87 SetSymbolValue(ALLOCATION_POINTER, (lispobj)free_pointer);
89 dynamic_space_free_pointer = free_pointer;
91 /* With GENCGC, this will always be space 0. (We checked
92 * above that addr==DYNAMIC_SPACE_START.) */
93 current_dynamic_space = (lispobj *)addr;
96 if (addr != (os_vm_address_t)STATIC_SPACE_START) {
97 fprintf(stderr, "in core: 0x%p - in runtime: 0x%x\n",
98 addr, (os_vm_address_t)STATIC_SPACE_START);
99 lose("core/runtime address mismatch: STATIC_SPACE_START");
102 case READ_ONLY_SPACE_ID:
103 if (addr != (os_vm_address_t)READ_ONLY_SPACE_START) {
104 fprintf(stderr, "in core: 0x%x - in runtime: 0x%x\n",
105 addr, (os_vm_address_t)READ_ONLY_SPACE_START);
106 lose("core/runtime address mismatch: READ_ONLY_SPACE_START");
110 lose("unknown space ID %ld addr 0x%p", id);
116 load_core_file(char *file)
118 int fd = open(file, O_RDONLY), count;
120 /* KLUDGE: This kind of conditionalization everywhere that 32-bit
121 * ints are used is really nasty. It would be much nicer to define
122 * a typedef like addr_as_int once and for all in each
123 * architecture file, then use that everywhere. -- WHN 19990904 */
125 long *header, val, len, *ptr;
128 u32 *header, val, len, *ptr;
132 lispobj initial_function = NIL;
133 FSHOW((stderr, "/entering load_core_file(%s)\n", file));
135 fprintf(stderr, "could not open file \"%s\"\n", file);
140 header = calloc(os_vm_page_size / sizeof(u32),sizeof(u32));
142 count = read(fd, header, os_vm_page_size);
143 if (count < os_vm_page_size) {
144 lose("premature end of core file");
146 SHOW("successfully read first page of core");
151 if (val != CORE_MAGIC) {
152 lose("invalid magic number in core: 0x%lx should have been 0x%x.",
156 SHOW("found CORE_MAGIC");
158 while (val != CORE_END) {
161 remaining_len = len - 2; /* (-2 to cancel the two ++ operations) */
162 FSHOW((stderr, "/val=0x%ld, remaining_len=0x%ld\n",
163 (long)val, (long)remaining_len));
168 SHOW("CORE_END case");
172 SHOW("CORE_VERSION case");
173 if (*ptr != SBCL_CORE_VERSION_INTEGER) {
174 lose("core file version (%d) != runtime library version (%d)",
176 SBCL_CORE_VERSION_INTEGER);
180 case CORE_NDIRECTORY:
181 SHOW("CORE_NDIRECTORY case");
182 process_directory(fd,
185 remaining_len / (sizeof(struct ndir_entry) /
188 remaining_len / (sizeof(struct ndir_entry) /
194 case CORE_INITIAL_FUNCTION:
195 SHOW("CORE_INITIAL_FUNCTION case");
196 initial_function = (lispobj)*ptr;
200 lose("unknown core file entry: %ld", (long)val);
203 ptr += remaining_len;
204 FSHOW((stderr, "/new ptr=%x\n", ptr));
206 SHOW("about to free(header)");
208 SHOW("returning from load_core_file(..)");
209 return initial_function;