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 /* For stop-and-copy GC, this will be whatever the GC was
92 * using at the time. With GENCGC, this will always be
93 * space 0. (We checked above that for GENCGC,
94 * addr==DYNAMIC_SPACE_START.) */
95 current_dynamic_space = (lispobj *)addr;
98 if (addr != (os_vm_address_t)STATIC_SPACE_START) {
99 fprintf(stderr, "in core: 0x%p - in runtime: 0x%x\n",
100 addr, (os_vm_address_t)STATIC_SPACE_START);
101 lose("core/runtime address mismatch: STATIC_SPACE_START");
104 case READ_ONLY_SPACE_ID:
105 if (addr != (os_vm_address_t)READ_ONLY_SPACE_START) {
106 fprintf(stderr, "in core: 0x%x - in runtime: 0x%x\n",
107 addr, (os_vm_address_t)READ_ONLY_SPACE_START);
108 lose("core/runtime address mismatch: READ_ONLY_SPACE_START");
112 lose("unknown space ID %ld addr 0x%p", id);
118 load_core_file(char *file)
120 u32 *header, val, len, *ptr, remaining_len;
121 int fd = open(file, O_RDONLY), count;
123 lispobj initial_function = NIL;
124 FSHOW((stderr, "/entering load_core_file(%s)\n", file));
126 fprintf(stderr, "could not open file \"%s\"\n", file);
131 header = calloc(os_vm_page_size / sizeof(u32), sizeof(u32));
133 count = read(fd, header, os_vm_page_size);
134 if (count < os_vm_page_size) {
135 lose("premature end of core file");
137 SHOW("successfully read first page of core");
142 if (val != CORE_MAGIC) {
143 lose("invalid magic number in core: 0x%lx should have been 0x%x.",
147 SHOW("found CORE_MAGIC");
149 while (val != CORE_END) {
152 remaining_len = len - 2; /* (-2 to cancel the two ++ operations) */
153 FSHOW((stderr, "/val=0x%ld, remaining_len=0x%ld\n",
154 (long)val, (long)remaining_len));
159 SHOW("CORE_END case");
163 SHOW("CORE_VERSION case");
164 if (*ptr != SBCL_CORE_VERSION_INTEGER) {
165 lose("core file version (%d) != runtime library version (%d)",
167 SBCL_CORE_VERSION_INTEGER);
171 case CORE_NDIRECTORY:
172 SHOW("CORE_NDIRECTORY case");
173 process_directory(fd,
176 remaining_len / (sizeof(struct ndir_entry) /
179 remaining_len / (sizeof(struct ndir_entry) /
185 case CORE_INITIAL_FUNCTION:
186 SHOW("CORE_INITIAL_FUNCTION case");
187 initial_function = (lispobj)*ptr;
191 lose("unknown core file entry: %ld", (long)val);
194 ptr += remaining_len;
195 FSHOW((stderr, "/new ptr=%x\n", ptr));
197 SHOW("about to free(header)");
199 SHOW("returning from load_core_file(..)");
200 return initial_function;