X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fdumper.c;h=1bb3172cfdb59bda12a3add72dd12d48b8e6a626;hb=6b1f1b2af579009e8a95f9c79f3cfe119f2f595d;hp=4118809844860e44d6ff1bf2f422df0ba124a5d6;hpb=0c693dc08f0794304711787b2eb47c144ea4bef1;p=chise%2Fxemacs-chise.git.1 diff --git a/src/dumper.c b/src/dumper.c index 4118809..1bb3172 100644 --- a/src/dumper.c +++ b/src/dumper.c @@ -22,21 +22,17 @@ Boston, MA 02111-1307, USA. */ #include #include "lisp.h" - #include "dump-id.h" #include "specifier.h" +#include "alloc.h" #include "elhash.h" #include "sysfile.h" #include "console-stream.h" #include "dumper.h" -#ifdef WIN32_NATIVE -#include "nt.h" -#else #ifdef HAVE_MMAP #include #endif -#endif #ifndef SEPCHAR #define SEPCHAR ':' @@ -44,80 +40,6 @@ Boston, MA 02111-1307, USA. */ typedef struct { - void *varaddress; - size_t size; -} pdump_opaque; - -typedef struct -{ - Dynarr_declare (pdump_opaque); -} pdump_opaque_dynarr; - -typedef struct -{ - void **ptraddress; - const struct struct_description *desc; -} pdump_root_struct_ptr; - -typedef struct -{ - Dynarr_declare (pdump_root_struct_ptr); -} pdump_root_struct_ptr_dynarr; - -static pdump_opaque_dynarr *pdump_opaques; -static pdump_root_struct_ptr_dynarr *pdump_root_struct_ptrs; -static Lisp_Object_ptr_dynarr *pdump_root_objects; -static Lisp_Object_ptr_dynarr *pdump_weak_object_chains; - -/* Mark SIZE bytes at non-heap address VARADDRESS for dumping as is, - without any bit-twiddling. */ -void -dump_add_opaque (void *varaddress, size_t size) -{ - pdump_opaque info; - info.varaddress = varaddress; - info.size = size; - if (pdump_opaques == NULL) - pdump_opaques = Dynarr_new (pdump_opaque); - Dynarr_add (pdump_opaques, info); -} - -/* Mark the struct described by DESC and pointed to by the pointer at - non-heap address VARADDRESS for dumping. - All the objects reachable from this pointer will also be dumped. */ -void -dump_add_root_struct_ptr (void *ptraddress, const struct struct_description *desc) -{ - pdump_root_struct_ptr info; - info.ptraddress = (void **) ptraddress; - info.desc = desc; - if (pdump_root_struct_ptrs == NULL) - pdump_root_struct_ptrs = Dynarr_new (pdump_root_struct_ptr); - Dynarr_add (pdump_root_struct_ptrs, info); -} - -/* Mark the Lisp_Object at non-heap address VARADDRESS for dumping. - All the objects reachable from this var will also be dumped. */ -void -dump_add_root_object (Lisp_Object *varaddress) -{ - if (pdump_root_objects == NULL) - pdump_root_objects = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); - Dynarr_add (pdump_root_objects, varaddress); -} - -/* Mark the list pointed to by the Lisp_Object at VARADDRESS for dumping. */ -void -dump_add_weak_object_chain (Lisp_Object *varaddress) -{ - if (pdump_weak_object_chains == NULL) - pdump_weak_object_chains = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); - Dynarr_add (pdump_weak_object_chains, varaddress); -} - - -typedef struct -{ const struct lrecord_description *desc; int count; } pdump_reloc_table; @@ -153,39 +75,34 @@ pdump_objects_unmark (void) * * 0 - header * 256 - dumped objects - * stab_offset - nb_root_struct_ptrs*pair(void *, adr) for pointers to structures - * - nb_opaques*pair(void *, size) for raw bits to restore + * stab_offset - nb_staticpro*(Lisp_Object *) from staticvec + * - nb_staticpro*(relocated Lisp_Object) pointed to by staticpro + * - nb_structdmp*pair(void *, adr) for pointers to structures + * - lrecord_implementations_table[] * - relocation table * - wired variable address/value couples with the count preceding the list */ -#define PDUMP_SIGNATURE "XEmacsDP" -#define PDUMP_SIGNATURE_LEN (sizeof (PDUMP_SIGNATURE) - 1) +#define DUMP_SIGNATURE "XEmacsDP" +#define DUMP_SIGNATURE_LEN (sizeof (DUMP_SIGNATURE) - 1) typedef struct { - char signature[PDUMP_SIGNATURE_LEN]; + char signature[DUMP_SIGNATURE_LEN]; unsigned int id; EMACS_UINT stab_offset; EMACS_UINT reloc_address; - int nb_root_struct_ptrs; - int nb_opaques; -} pdump_header; + int nb_staticpro; + int nb_structdmp; + int nb_opaquedmp; +} dump_header; char *pdump_start, *pdump_end; static size_t pdump_length; - -#ifdef WIN32_NATIVE -/* Handle for the dump file */ -HANDLE pdump_hFile = INVALID_HANDLE_VALUE; -/* Handle for the file mapping object for the dump file */ -HANDLE pdump_hMap = INVALID_HANDLE_VALUE; -#endif - void (*pdump_free) (void); -static const unsigned char pdump_align_table[256] = +static const unsigned char align_table[256] = { 8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, @@ -238,6 +155,7 @@ typedef struct static pdump_entry_list pdump_object_table[256]; static pdump_entry_list pdump_opaque_data_list; static pdump_struct_list pdump_struct_table; +static pdump_entry_list_elmt *pdump_qnil; static int pdump_alert_undump_object[256]; @@ -306,7 +224,7 @@ pdump_add_entry (pdump_entry_list *list, const void *obj, size_t size, int count list->count += count; pdump_hash[pos] = e; - align = pdump_align_table[size & 255]; + align = align_table[size & 255]; if (align < 2 && is_lrecord) align = 2; @@ -349,8 +267,7 @@ static struct static int depth; -static void -pdump_backtrace (void) +static void pdump_backtrace (void) { int i; stderr_out ("pdump backtrace :\n"); @@ -427,6 +344,7 @@ pdump_register_sub (const void *data, const struct lrecord_description *desc, in case XD_INT: case XD_LONG: case XD_BYTECOUNT: + case XD_LO_RESET_NIL: case XD_INT_RESET: case XD_LO_LINK: break; @@ -611,6 +529,16 @@ pdump_dump_data (pdump_entry_list_elmt *elmt, const struct lrecord_description * case XD_LONG: case XD_BYTECOUNT: break; + case XD_LO_RESET_NIL: + { + EMACS_INT num = desc[pos].data1; + int j; + if (XD_IS_INDIRECT (num)) + num = pdump_get_indirect_count (num, desc, elmt->obj); + for (j=0; jsave_offset; + break; + } case XD_INT_RESET: { EMACS_INT val = desc[pos].data1; @@ -727,11 +655,12 @@ pdump_reloc_one (void *data, EMACS_INT delta, const struct lrecord_description * if (POINTER_TYPE_P (XTYPE (*pobj)) && ! EQ (*pobj, Qnull_pointer)) - XSETOBJ (*pobj, (char *) XPNTR (*pobj) + delta); + XSETOBJ (*pobj, XTYPE (*pobj), (char *) XPNTR (*pobj) + delta); break; } case XD_LISP_OBJECT_ARRAY: + case XD_LO_RESET_NIL: { EMACS_INT num = desc[pos].data1; int j; @@ -744,7 +673,7 @@ pdump_reloc_one (void *data, EMACS_INT delta, const struct lrecord_description * if (POINTER_TYPE_P (XTYPE (*pobj)) && ! EQ (*pobj, Qnull_pointer)) - XSETOBJ (*pobj, (char *) XPNTR (*pobj) + delta); + XSETOBJ (*pobj, XTYPE (*pobj), (char *) XPNTR (*pobj) + delta); } break; } @@ -809,7 +738,7 @@ pdump_scan_by_alignment (void (*f)(pdump_entry_list_elmt *, const struct lrecord elmt = pdump_opaque_data_list.first; while (elmt) { - if (pdump_align_table[elmt->size & 255] == align) + if (align_table[elmt->size & 255] == align) f (elmt, 0); elmt = elmt->next; } @@ -817,35 +746,58 @@ pdump_scan_by_alignment (void (*f)(pdump_entry_list_elmt *, const struct lrecord } static void -pdump_dump_from_root_struct_ptrs (void) +pdump_dump_staticvec (void) +{ + EMACS_INT *reloc = xnew_array (EMACS_INT, staticidx); + int i; + write (pdump_fd, staticvec, staticidx*sizeof (Lisp_Object *)); + + for (i=0; isave_offset; + else + reloc[i] = *(EMACS_INT *)(staticvec[i]); + } + write (pdump_fd, reloc, staticidx*sizeof (Lisp_Object)); + free (reloc); +} + +static void +pdump_dump_structvec (void) { int i; - for (i = 0; i < Dynarr_length (pdump_root_struct_ptrs); i++) + for (i=0; iptraddress, sizeof (info->ptraddress)); - adr = pdump_get_entry (*(info->ptraddress))->save_offset; + write (pdump_fd, &(dumpstructvec[i].data), sizeof (void *)); + adr = pdump_get_entry (*(void **)(dumpstructvec[i].data))->save_offset; write (pdump_fd, &adr, sizeof (adr)); } } static void -pdump_dump_opaques (void) +pdump_dump_opaquevec (void) { int i; - for (i = 0; i < Dynarr_length (pdump_opaques); i++) + for (i=0; ivaraddress, info->size); + write (pdump_fd, &(dumpopaquevec[i]), sizeof (dumpopaquevec[i])); + write (pdump_fd, dumpopaquevec[i].data, dumpopaquevec[i].size); } } static void +pdump_dump_itable (void) +{ + write (pdump_fd, lrecord_implementations_table, lrecord_type_count*sizeof (lrecord_implementations_table[0])); +} + +static void pdump_dump_rtables (void) { - int i; + int i, j; pdump_entry_list_elmt *elmt; pdump_reloc_table rt; @@ -878,7 +830,6 @@ pdump_dump_rtables (void) while (elmt) { EMACS_INT rdata = pdump_get_entry (elmt->obj)->save_offset; - int j; for (j=0; jcount; j++) { write (pdump_fd, &rdata, sizeof (rdata)); @@ -893,26 +844,25 @@ pdump_dump_rtables (void) } static void -pdump_dump_from_root_objects (void) +pdump_dump_wired (void) { - size_t count = Dynarr_length (pdump_root_objects) + Dynarr_length (pdump_weak_object_chains); - size_t i; + EMACS_INT count = pdump_wireidx + pdump_wireidx_list; + int i; write (pdump_fd, &count, sizeof (count)); - for (i=0; isave_offset); - write (pdump_fd, Dynarr_atp (pdump_root_objects, i), sizeof (Dynarr_atp (pdump_root_objects, i))); + EMACS_INT obj = pdump_get_entry (XRECORD_LHEADER (*(pdump_wirevec[i])))->save_offset; + write (pdump_fd, &pdump_wirevec[i], sizeof (pdump_wirevec[i])); write (pdump_fd, &obj, sizeof (obj)); } - for (i=0; isave_offset); + res = elmt->save_offset; - write (pdump_fd, Dynarr_atp (pdump_weak_object_chains, i), sizeof (Lisp_Object *)); - write (pdump_fd, &obj, sizeof (obj)); + write (pdump_fd, &pdump_wirevec_list[i], sizeof (pdump_wirevec_list[i])); + write (pdump_fd, &res, sizeof (res)); } } @@ -940,19 +890,16 @@ pdump (void) int i; Lisp_Object t_console, t_device, t_frame; int none; - pdump_header hd; - - flush_all_buffer_local_cache (); + dump_header hd; /* These appear in a DEFVAR_LISP, which does a staticpro() */ - t_console = Vterminal_console; Vterminal_console = Qnil; - t_frame = Vterminal_frame; Vterminal_frame = Qnil; - t_device = Vterminal_device; Vterminal_device = Qnil; + t_console = Vterminal_console; + t_frame = Vterminal_frame; + t_device = Vterminal_device; - dump_add_opaque (&lrecord_implementations_table, - lrecord_type_count * sizeof (lrecord_implementations_table[0])); - dump_add_opaque (&lrecord_markers, - lrecord_type_count * sizeof (lrecord_markers[0])); + Vterminal_console = Qnil; + Vterminal_frame = Qnil; + Vterminal_device = Qnil; pdump_hash = xnew_array_and_zero (pdump_entry_list_elmt *, PDUMP_HASHSIZE); @@ -971,8 +918,10 @@ pdump (void) pdump_opaque_data_list.count = 0; depth = 0; - for (i=0; isignature, - PDUMP_SIGNATURE, PDUMP_SIGNATURE_LEN) - && ((pdump_header *)pdump_start)->id == dump_id); + return (!memcmp (((dump_header *)pdump_start)->signature, DUMP_SIGNATURE, DUMP_SIGNATURE_LEN) + && ((dump_header *)pdump_start)->id == dump_id); } -static int -pdump_load_finish (void) +static int pdump_load_finish (void) { int i; char *p; @@ -1052,24 +999,46 @@ pdump_load_finish (void) #define PDUMP_READ(p, type) (p = (char*) (((type *) p) + 1), *((type *) p - 1)) - delta = ((EMACS_INT)pdump_start) - ((pdump_header *)pdump_start)->reloc_address; - p = pdump_start + ((pdump_header *)pdump_start)->stab_offset; + staticidx = ((dump_header *)(pdump_start))->nb_staticpro; + delta = ((EMACS_INT)pdump_start) - ((dump_header *)pdump_start)->reloc_address; + p = pdump_start + ((dump_header *)pdump_start)->stab_offset; + + /* Put back the staticvec in place */ + memcpy (staticvec, p, staticidx*sizeof (Lisp_Object *)); + p += staticidx*sizeof (Lisp_Object *); + for (i=0; inb_root_struct_ptrs; i++) + /* Put back the dumpstructs */ + for (i=0; i<((dump_header *)pdump_start)->nb_structdmp; i++) { void **adr = PDUMP_READ (p, void **); *adr = (void *) (PDUMP_READ (p, char *) + delta); } - /* Put back the pdump_opaques */ - for (i=0; i<((pdump_header *)pdump_start)->nb_opaques; i++) + /* Put back the opaques */ + for (i=0; i<((dump_header *)pdump_start)->nb_opaquedmp; i++) { - pdump_opaque info = PDUMP_READ (p, pdump_opaque); - memcpy (info.varaddress, p, info.size); - p += info.size; + struct pdump_dumpopaqueinfo di = PDUMP_READ (p, struct pdump_dumpopaqueinfo); + memcpy (di.data, p, di.size); + p += di.size; } + /* Put back the lrecord_implementations_table */ + /* The (void *) cast is there to make Ben happy. */ + memcpy ((void *) lrecord_implementations_table, p, lrecord_type_count*sizeof (lrecord_implementations_table[0])); + p += lrecord_type_count*sizeof (lrecord_implementations_table[0]); + + /* Reinitialize lrecord_markers from lrecord_implementations_table */ + for (i=0; i < lrecord_type_count; i++) + if (lrecord_implementations_table[i]) + lrecord_markers[i] = lrecord_implementations_table[i]->marker; + /* Do the relocations */ pdump_rt_list = p; count = 2; @@ -1090,14 +1059,16 @@ pdump_load_finish (void) break; } - /* Put the pdump_root_objects variables in place */ - for (i = PDUMP_READ (p, size_t); i; i--) + /* Put the pdump_wire variables in place */ + count = PDUMP_READ (p, EMACS_INT); + + for (i=0; iexe_path && !IS_DIRECTORY_SEP (*w) && (*w != '-') && (*w != '.')); + while (w>exe_path && !IS_DIRECTORY_SEP (*w) && (*w != '-') && (*w != '.')); } while (w>exe_path && !IS_DIRECTORY_SEP (*w)); return 0; } -int -pdump_load (const char *argv0) +int pdump_load(const char *argv0) { char exe_path[PATH_MAX]; -#ifdef WIN32_NATIVE - GetModuleFileName (NULL, exe_path, PATH_MAX); -#else /* !WIN32_NATIVE */ char *w; +#ifdef WINDOWSNT + GetModuleFileName (NULL, exe_name, PATH_MAX); +#else /* !WINDOWSNT */ const char *dir, *p; dir = argv0; if (dir[0] == '-') { /* XEmacs as a login shell, oh goody! */ - dir = getenv ("SHELL"); + dir = getenv("SHELL"); } - p = dir + strlen (dir); + p = dir + strlen(dir); while (p != dir && !IS_ANY_SEP (p[-1])) p--; - + if (p != dir) { /* invocation-name includes a directory component -- presumably it @@ -1358,13 +1313,13 @@ pdump_load (const char *argv0) { *w++ = '/'; } - strcpy (w, name); - + strcpy(w, name); + /* ### #$%$#^$^@%$^#%@$ ! */ #ifdef access #undef access #endif - + if (!access (exe_path, X_OK)) break; if (!*p) @@ -1373,10 +1328,10 @@ pdump_load (const char *argv0) sprintf (exe_path, "./%s", name); break; } - path = p+1; + path = p+1; } } -#endif /* WIN32_NATIVE */ +#endif /* WINDOWSNT */ if (pdump_file_try (exe_path)) { @@ -1384,7 +1339,7 @@ pdump_load (const char *argv0) return 1; } -#ifdef WIN32_NATIVE +#ifdef WINDOWSNT if (pdump_resource_get ()) { if (pdump_load_check ())