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.
22 #include <sys/types.h>
36 static void process_directory(int fd, long *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 = CORE_PAGESIZE * (1 + entry->data_page);
46 os_vm_address_t addr =
47 (os_vm_address_t) (CORE_PAGESIZE * entry->address);
48 lispobj *free_pointer = (lispobj *) addr + entry->nwords;
49 long len = CORE_PAGESIZE * entry->page_count;
52 os_vm_address_t real_addr;
53 FSHOW((stderr, "mapping %ld bytes at 0x%lx\n", 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",
67 case DYNAMIC_SPACE_ID:
68 if (addr != (os_vm_address_t)DYNAMIC_SPACE_START) {
69 lose("core/runtime address mismatch: DYNAMIC_SPACE_START");
71 #if defined(ibmrt) || defined(__i386__)
72 SetSymbolValue(ALLOCATION_POINTER, (lispobj)free_pointer);
74 dynamic_space_free_pointer = free_pointer;
78 if (addr != (os_vm_address_t)STATIC_SPACE_START) {
79 lose("core/runtime address mismatch: STATIC_SPACE_START");
82 case READ_ONLY_SPACE_ID:
83 if (addr != (os_vm_address_t)READ_ONLY_SPACE_START) {
84 lose("core/runtime address mismatch: READ_ONLY_SPACE_START");
88 lose("unknown space ID %ld", id);
93 lispobj load_core_file(char *file)
95 int fd = open(file, O_RDONLY), count;
97 /* KLUDGE: This kind of conditionalization everywhere that 32-bit
98 * ints are used is really nasty. It would be much nicer to define
99 * a typedef a la addr_as_int once and for all in each
100 * architecture file, then use that everywhere. -- WHN 19990904 */
102 long header[CORE_PAGESIZE / sizeof(long)], val, len, *ptr;
105 u32 header[CORE_PAGESIZE / sizeof(u32)], val, len, *ptr;
109 lispobj initial_function = NIL;
112 fprintf(stderr, "could not open file \"%s\"\n", file);
117 count = read(fd, header, CORE_PAGESIZE);
118 if (count < CORE_PAGESIZE) {
119 lose("premature end of core file");
125 if (val != CORE_MAGIC) {
126 lose("invalid magic number in core: 0x%lx should have been 0x%x.",
131 while (val != CORE_END) {
134 remaining_len = len - 2; /* (-2 to cancel the two ++ operations) */
142 if (*ptr != SBCL_CORE_VERSION_INTEGER) {
143 lose("core file version (%d) != runtime library version (%d)",
145 SBCL_CORE_VERSION_INTEGER);
149 case CORE_NDIRECTORY:
150 process_directory(fd,
153 remaining_len / (sizeof(struct ndir_entry) /
156 remaining_len / (sizeof(struct ndir_entry) /
162 case CORE_INITIAL_FUNCTION:
163 initial_function = (lispobj)*ptr;
167 lose("unknown core file entry: %ld", val);
170 ptr += remaining_len;
173 return initial_function;