2 * This software is part of the SBCL system. See the README file for
5 * This software is derived from the CMU CL system, which was
6 * written at Carnegie Mellon University and released into the
7 * public domain. The software is in the public domain and is
8 * provided with absolutely no warranty. See the COPYING and CREDITS
9 * files for more information.
32 write_bytes(FILE *file, char *addr, long bytes)
34 long count, here, data;
36 bytes = (bytes+os_vm_page_size-1)&~(os_vm_page_size-1);
41 data = (ftell(file)+os_vm_page_size-1)&~(os_vm_page_size-1);
45 count = fwrite(addr, 1, bytes, file);
51 perror("error writing to save file");
57 return data/os_vm_page_size - 1;
61 output_space(FILE *file, int id, lispobj *addr, lispobj *end)
63 int words, bytes, data;
64 static char *names[] = {NULL, "dynamic", "static", "read-only"};
70 bytes = words * sizeof(lispobj);
72 printf("writing %d bytes from the %s space at 0x%08lx\n",
73 bytes, names[id], (unsigned long)addr);
75 data = write_bytes(file, (char *)addr, bytes);
78 putw((long)addr / os_vm_page_size, file);
79 putw((bytes + os_vm_page_size - 1) / os_vm_page_size, file);
83 save(char *filename, lispobj init_function)
87 /* Open the output file. We don't actually need the file yet, but
88 * the fopen() might fail for some reason, and we want to detect
89 * that and back out before we do anything irreversible. */
91 file = fopen(filename, "w");
97 /* Smash the enclosing state. (Once we do this, there's no good
98 * way to go back, which is a sufficient reason that this ends up
99 * being SAVE-LISP-AND-DIE instead of SAVE-LISP-AND-GO-ON). */
100 printf("[undoing binding stack and other enclosing state... ");
102 unbind_to_here((lispobj *)BINDING_STACK_START);
103 SetSymbolValue(CURRENT_CATCH_BLOCK, 0);
104 SetSymbolValue(CURRENT_UNWIND_PROTECT_BLOCK, 0);
108 /* (Now we can actually start copying ourselves into the
111 printf("[saving current Lisp image into %s:\n", filename);
114 putw(CORE_MAGIC, file);
116 putw(CORE_VERSION, file);
118 putw(SBCL_CORE_VERSION_INTEGER, file);
120 putw(CORE_NDIRECTORY, file);
125 (lispobj *)READ_ONLY_SPACE_START,
126 (lispobj *)SymbolValue(READ_ONLY_SPACE_FREE_POINTER));
129 (lispobj *)STATIC_SPACE_START,
130 (lispobj *)SymbolValue(STATIC_SPACE_FREE_POINTER));
134 (lispobj *)current_dynamic_space,
135 dynamic_space_free_pointer);
138 /* Flush the current_region, updating the tables. */
139 gc_alloc_update_page_tables(0,&boxed_region);
140 gc_alloc_update_page_tables(1,&unboxed_region);
141 update_x86_dynamic_space_free_pointer();
145 (lispobj *)DYNAMIC_SPACE_START,
146 (lispobj *)SymbolValue(ALLOCATION_POINTER));
149 putw(CORE_INITIAL_FUNCTION, file);
151 putw(init_function, file);
153 putw(CORE_END, file);