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>
34 static void process_directory(int fd, long *ptr, int count)
36 struct ndir_entry *entry;
38 FSHOW((stderr, "process_directory(..), count=%d\n", count));
40 for (entry = (struct ndir_entry *) ptr; --count>= 0; ++entry) {
42 long id = entry->identifier;
43 long offset = os_vm_page_size * (1 + entry->data_page);
44 os_vm_address_t addr =
45 (os_vm_address_t) (os_vm_page_size * entry->address);
46 lispobj *free_pointer = (lispobj *) addr + entry->nwords;
47 long len = os_vm_page_size * entry->page_count;
50 os_vm_address_t real_addr;
51 FSHOW((stderr, "mapping %ld bytes at 0x%lx\n", len, addr));
52 real_addr = os_map(fd, offset, addr, len);
53 if (real_addr != addr) {
54 lose("file mapped in wrong place! "
55 "(0x%08x != 0x%08lx)",
61 FSHOW((stderr, "space id = %d, free pointer = 0x%08x\n",
65 case DYNAMIC_SPACE_ID:
67 if (addr != (os_vm_address_t)DYNAMIC_SPACE_START) {
68 fprintf(stderr, "in core: 0x%x - in runtime: 0x%x \n",
69 addr, (os_vm_address_t)DYNAMIC_SPACE_START);
70 fprintf(stderr,"warning: core/runtime address mismatch: DYNAMIC_SPACE_START");
73 if ((addr != (os_vm_address_t)DYNAMIC_0_SPACE_START) &&
74 (addr != (os_vm_address_t)DYNAMIC_1_SPACE_START)) {
75 fprintf(stderr, "in core: 0x%x - in runtime: 0x%x or 0x%x\n",
76 addr, (os_vm_address_t)DYNAMIC_0_SPACE_START,
77 (os_vm_address_t)DYNAMIC_1_SPACE_START);
78 fprintf(stderr,"warning: core/runtime address mismatch: DYNAMIC_SPACE_START");
81 #if defined(ibmrt) || defined(__i386__)
82 SetSymbolValue(ALLOCATION_POINTER, (lispobj)free_pointer);
84 dynamic_space_free_pointer = free_pointer;
86 /* on the x86, this will always be space 0 */
87 current_dynamic_space = (lispobj *)addr;
90 if (addr != (os_vm_address_t)STATIC_SPACE_START) {
91 fprintf(stderr, "in core: 0x%p - in runtime: 0x%x\n",
92 addr, (os_vm_address_t)STATIC_SPACE_START);
93 lose("core/runtime address mismatch: STATIC_SPACE_START");
96 case READ_ONLY_SPACE_ID:
97 if (addr != (os_vm_address_t)READ_ONLY_SPACE_START) {
98 fprintf(stderr, "in core: 0x%x - in runtime: 0x%x\n",
99 addr, (os_vm_address_t)READ_ONLY_SPACE_START);
100 lose("core/runtime address mismatch: READ_ONLY_SPACE_START");
104 lose("unknown space ID %ld addr 0x%p", id);
109 lispobj load_core_file(char *file)
111 int fd = open(file, O_RDONLY), count;
113 /* KLUDGE: This kind of conditionalization everywhere that 32-bit
114 * ints are used is really nasty. It would be much nicer to define
115 * a typedef like addr_as_int once and for all in each
116 * architecture file, then use that everywhere. -- WHN 19990904 */
118 long *header, val, len, *ptr;
121 u32 *header, val, len, *ptr;
125 lispobj initial_function = NIL;
127 fprintf(stderr, "could not open file \"%s\"\n", file);
132 header=calloc(os_vm_page_size / sizeof(u32),sizeof(u32));
134 count = read(fd, header, os_vm_page_size);
135 if (count < os_vm_page_size) {
136 lose("premature end of core file");
142 if (val != CORE_MAGIC) {
143 lose("invalid magic number in core: 0x%lx should have been 0x%x.",
148 while (val != CORE_END) {
151 remaining_len = len - 2; /* (-2 to cancel the two ++ operations) */
159 if (*ptr != SBCL_CORE_VERSION_INTEGER) {
160 lose("core file version (%d) != runtime library version (%d)",
162 SBCL_CORE_VERSION_INTEGER);
166 case CORE_NDIRECTORY:
167 process_directory(fd,
170 remaining_len / (sizeof(struct ndir_entry) /
173 remaining_len / (sizeof(struct ndir_entry) /
179 case CORE_INITIAL_FUNCTION:
180 initial_function = (lispobj)*ptr;
184 lose("unknown core file entry: %ld", val);
187 ptr += remaining_len;
190 return initial_function;