X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fdumper.c;h=8def7462b1cfe980ca1b458d06b0ebf1ae3fbf40;hb=153c92fa2a3b77ce954a1e54a5dc9ec15370cfd6;hp=c9a74a8609615a808cc3046cf7b33cc50fd64d6d;hpb=dd8f4c0e5ff27909836e7478df6b17d816a0db28;p=chise%2Fxemacs-chise.git- diff --git a/src/dumper.c b/src/dumper.c index c9a74a8..8def746 100644 --- a/src/dumper.c +++ b/src/dumper.c @@ -1,5 +1,6 @@ /* Portable data dumper for XEmacs. Copyright (C) 1999-2000 Olivier Galibert + Copyright (C) 2001 Martin Buchholz This file is part of XEmacs. @@ -25,7 +26,6 @@ Boston, MA 02111-1307, USA. */ #include "dump-id.h" #include "specifier.h" -#include "alloc.h" #include "elhash.h" #include "sysfile.h" #include "console-stream.h" @@ -45,6 +45,119 @@ 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; + +typedef struct +{ + Lisp_Object *address; + Lisp_Object value; +} pdump_static_Lisp_Object; + +typedef struct +{ + char **address; /* char * for ease of doing relocation */ + char * value; +} pdump_static_pointer; + +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); +} + + +inline static void +pdump_align_stream (FILE *stream, size_t alignment) +{ + long offset = ftell (stream); + long adjustment = ALIGN_SIZE (offset, alignment) - offset; + if (adjustment) + fseek (stream, adjustment, SEEK_CUR); +} + +#define PDUMP_ALIGN_OUTPUT(type) pdump_align_stream (pdump_out, ALIGNOF (type)) + +#define PDUMP_WRITE(type, object) \ +fwrite (&object, sizeof (object), 1, pdump_out); + +#define PDUMP_WRITE_ALIGNED(type, object) do { \ + PDUMP_ALIGN_OUTPUT (type); \ + PDUMP_WRITE (type, object); \ +} while (0) + +#define PDUMP_READ(ptr, type) \ +(((type *) (ptr = (char*) (((type *) ptr) + 1)))[-1]) + +#define PDUMP_READ_ALIGNED(ptr, type) \ +((ptr = (char *) ALIGN_PTR (ptr, ALIGNOF (type))), PDUMP_READ (ptr, type)) + + + +typedef struct +{ const struct lrecord_description *desc; int count; } pdump_reloc_table; @@ -77,45 +190,44 @@ pdump_objects_unmark (void) /* The structure of the file - * - * 0 - header - * 256 - dumped objects - * 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 + 0 - header + - 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 + - relocation table + - root lisp object address/value couples with the count + preceding the list */ -#define DUMP_SIGNATURE "XEmacsDP" -#define DUMP_SIGNATURE_LEN (sizeof (DUMP_SIGNATURE) - 1) +#define PDUMP_SIGNATURE "XEmacsDP" +#define PDUMP_SIGNATURE_LEN (sizeof (PDUMP_SIGNATURE) - 1) typedef struct { - char signature[DUMP_SIGNATURE_LEN]; + char signature[PDUMP_SIGNATURE_LEN]; unsigned int id; EMACS_UINT stab_offset; EMACS_UINT reloc_address; - int nb_staticpro; - int nb_structdmp; - int nb_opaquedmp; -} dump_header; + int nb_root_struct_ptrs; + int nb_opaques; +} pdump_header; -char *pdump_start, *pdump_end; +char *pdump_start; +char *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; +/* Handle for the dump file */ +static HANDLE pdump_hFile = INVALID_HANDLE_VALUE; +/* Handle for the file mapping object for the dump file */ +static HANDLE pdump_hMap = INVALID_HANDLE_VALUE; #endif -void (*pdump_free) (void); +static void (*pdump_free) (void); -static const unsigned char align_table[256] = +static const unsigned char pdump_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, @@ -141,7 +253,6 @@ typedef struct pdump_entry_list_elmt const void *obj; size_t size; int count; - int is_lrecord; EMACS_INT save_offset; } pdump_entry_list_elmt; @@ -168,7 +279,6 @@ 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]; @@ -176,8 +286,13 @@ static unsigned long cur_offset; static size_t max_size; static int pdump_fd; static void *pdump_buf; +static FILE *pdump_out; +#ifdef UTF2000 +#define PDUMP_HASHSIZE 20000001 +#else #define PDUMP_HASHSIZE 200001 +#endif static pdump_entry_list_elmt **pdump_hash; @@ -209,7 +324,8 @@ pdump_get_entry (const void *obj) } static void -pdump_add_entry (pdump_entry_list *list, const void *obj, size_t size, int count, int is_lrecord) +pdump_add_entry (pdump_entry_list *list, const void *obj, size_t size, + int count) { pdump_entry_list_elmt *e; int align; @@ -231,15 +347,12 @@ pdump_add_entry (pdump_entry_list *list, const void *obj, size_t size, int count e->obj = obj; e->size = size; e->count = count; - e->is_lrecord = is_lrecord; list->first = e; list->count += count; pdump_hash[pos] = e; - align = align_table[size & 255]; - if (align < 2 && is_lrecord) - align = 2; + align = pdump_align_table[size & 255]; if (align < list->align) list->align = align; @@ -280,29 +393,36 @@ static struct static int depth; -static void pdump_backtrace (void) +static void +pdump_backtrace (void) { int i; stderr_out ("pdump backtrace :\n"); for (i=0;iname, - backtrace[i].position, - backtrace[i].offset); + LHEADER_IMPLEMENTATION (backtrace[i].obj)->name, + backtrace[i].position, + backtrace[i].offset); } } } static void pdump_register_object (Lisp_Object obj); -static void pdump_register_struct (const void *data, const struct struct_description *sdesc, int count); +static void pdump_register_struct (const void *data, + const struct struct_description *sdesc, + int count); static EMACS_INT -pdump_get_indirect_count (EMACS_INT code, const struct lrecord_description *idesc, const void *idata) +pdump_get_indirect_count (EMACS_INT code, + const struct lrecord_description *idesc, + const void *idata) { EMACS_INT count; const void *irdata; @@ -326,7 +446,8 @@ pdump_get_indirect_count (EMACS_INT code, const struct lrecord_description *ides count = *(Bytecount *)irdata; break; default: - stderr_out ("Unsupported count type : %d (line = %d, code=%ld)\n", idesc[line].type, line, (long)code); + stderr_out ("Unsupported count type : %d (line = %d, code=%ld)\n", + idesc[line].type, line, (long)code); pdump_backtrace (); abort (); } @@ -357,7 +478,6 @@ 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; @@ -368,24 +488,21 @@ pdump_register_sub (const void *data, const struct lrecord_description *desc, in count = pdump_get_indirect_count (count, desc, data); pdump_add_entry (&pdump_opaque_data_list, - *(void **)rdata, - count, - 1, - 0); + *(void **)rdata, count, 1); break; } case XD_C_STRING: { const char *str = *(const char **)rdata; if (str) - pdump_add_entry (&pdump_opaque_data_list, str, strlen (str)+1, 1, 0); + pdump_add_entry (&pdump_opaque_data_list, str, strlen (str)+1, 1); break; } case XD_DOC_STRING: { const char *str = *(const char **)rdata; if ((EMACS_INT)str > 0) - pdump_add_entry (&pdump_opaque_data_list, str, strlen (str)+1, 1, 0); + pdump_add_entry (&pdump_opaque_data_list, str, strlen (str)+1, 1); break; } case XD_LISP_OBJECT: @@ -441,6 +558,7 @@ static void pdump_register_object (Lisp_Object obj) { struct lrecord_header *objh; + const struct lrecord_implementation *imp; if (!POINTER_TYPE_P (XTYPE (obj))) return; @@ -452,7 +570,9 @@ pdump_register_object (Lisp_Object obj) if (pdump_get_entry (objh)) return; - if (LHEADER_IMPLEMENTATION (objh)->description) + imp = LHEADER_IMPLEMENTATION (objh); + + if (imp->description) { int me = depth++; if (me>65536) @@ -466,26 +586,25 @@ pdump_register_object (Lisp_Object obj) pdump_add_entry (pdump_object_table + objh->type, objh, - LHEADER_IMPLEMENTATION (objh)->static_size ? - LHEADER_IMPLEMENTATION (objh)->static_size : - LHEADER_IMPLEMENTATION (objh)->size_in_bytes_method (objh), - 1, + imp->static_size ? + imp->static_size : + imp->size_in_bytes_method (objh), 1); - pdump_register_sub (objh, - LHEADER_IMPLEMENTATION (objh)->description, - me); + pdump_register_sub (objh, imp->description, me); --depth; } else { pdump_alert_undump_object[objh->type]++; - stderr_out ("Undumpable object type : %s\n", LHEADER_IMPLEMENTATION (objh)->name); + stderr_out ("Undumpable object type : %s\n", imp->name); pdump_backtrace (); } } static void -pdump_register_struct (const void *data, const struct struct_description *sdesc, int count) +pdump_register_struct (const void *data, + const struct struct_description *sdesc, + int count) { if (data && !pdump_get_entry (data)) { @@ -501,10 +620,7 @@ pdump_register_struct (const void *data, const struct struct_description *sdesc, backtrace[me].offset = 0; pdump_add_entry (pdump_get_entry_list (sdesc), - data, - sdesc->size, - count, - 0); + data, sdesc->size, count); for (i=0; isize*i, @@ -516,7 +632,8 @@ pdump_register_struct (const void *data, const struct struct_description *sdesc, } static void -pdump_dump_data (pdump_entry_list_elmt *elmt, const struct lrecord_description *desc) +pdump_dump_data (pdump_entry_list_elmt *elmt, + const struct lrecord_description *desc) { size_t size = elmt->size; int count = elmt->count; @@ -542,16 +659,6 @@ 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; @@ -620,17 +727,16 @@ pdump_dump_data (pdump_entry_list_elmt *elmt, const struct lrecord_description * default: stderr_out ("Unsupported dump type : %d\n", desc[pos].type); abort (); - }; + } } } } - write (pdump_fd, desc ? pdump_buf : elmt->obj, size*count); - if (elmt->is_lrecord && ((size*count) & 3)) - write (pdump_fd, "\0\0\0", 4-((size*count) & 3)); + fwrite (desc ? pdump_buf : elmt->obj, size, count, pdump_out); } static void -pdump_reloc_one (void *data, EMACS_INT delta, const struct lrecord_description *desc) +pdump_reloc_one (void *data, EMACS_INT delta, + const struct lrecord_description *desc) { int pos; @@ -668,12 +774,11 @@ pdump_reloc_one (void *data, EMACS_INT delta, const struct lrecord_description * if (POINTER_TYPE_P (XTYPE (*pobj)) && ! EQ (*pobj, Qnull_pointer)) - XSETOBJ (*pobj, XTYPE (*pobj), (char *) XPNTR (*pobj) + delta); + XSETOBJ (*pobj, (char *) XPNTR (*pobj) + delta); break; } case XD_LISP_OBJECT_ARRAY: - case XD_LO_RESET_NIL: { EMACS_INT num = desc[pos].data1; int j; @@ -686,7 +791,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, XTYPE (*pobj), (char *) XPNTR (*pobj) + delta); + XSETOBJ (*pobj, (char *) XPNTR (*pobj) + delta); } break; } @@ -705,9 +810,10 @@ pdump_reloc_one (void *data, EMACS_INT delta, const struct lrecord_description * } static void -pdump_allocate_offset (pdump_entry_list_elmt *elmt, const struct lrecord_description *desc) +pdump_allocate_offset (pdump_entry_list_elmt *elmt, + const struct lrecord_description *desc) { - size_t size = (elmt->is_lrecord ? (elmt->size + 3) & ~3 : elmt->size)*elmt->count; + size_t size = elmt->count * elmt->size; elmt->save_offset = cur_offset; if (size>max_size) max_size = size; @@ -715,7 +821,8 @@ pdump_allocate_offset (pdump_entry_list_elmt *elmt, const struct lrecord_descrip } static void -pdump_scan_by_alignment (void (*f)(pdump_entry_list_elmt *, const struct lrecord_description *)) +pdump_scan_by_alignment (void (*f)(pdump_entry_list_elmt *, + const struct lrecord_description *)) { int align, i; const struct lrecord_description *idesc; @@ -751,7 +858,7 @@ pdump_scan_by_alignment (void (*f)(pdump_entry_list_elmt *, const struct lrecord elmt = pdump_opaque_data_list.first; while (elmt) { - if (align_table[elmt->size & 255] == align) + if (pdump_align_table[elmt->size & 255] == align) f (elmt, 0); elmt = elmt->next; } @@ -759,58 +866,36 @@ pdump_scan_by_alignment (void (*f)(pdump_entry_list_elmt *, const struct lrecord } static 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) +pdump_dump_root_struct_ptrs (void) { int i; - for (i=0; isave_offset; - write (pdump_fd, &adr, sizeof (adr)); + data[i].address = (char **) Dynarr_atp (pdump_root_struct_ptrs, i)->ptraddress; + data[i].value = (char *) pdump_get_entry (* data[i].address)->save_offset; } + PDUMP_ALIGN_OUTPUT (pdump_static_pointer); + fwrite (data, sizeof (pdump_static_pointer), count, pdump_out); } static void -pdump_dump_opaquevec (void) +pdump_dump_opaques (void) { int i; - for (i=0; ivaraddress, info->size, 1, pdump_out); } } 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, j; + int i; pdump_entry_list_elmt *elmt; pdump_reloc_table rt; @@ -821,31 +906,32 @@ pdump_dump_rtables (void) continue; rt.desc = lrecord_implementations_table[i]->description; rt.count = pdump_object_table[i].count; - write (pdump_fd, &rt, sizeof (rt)); + PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt); while (elmt) { EMACS_INT rdata = pdump_get_entry (elmt->obj)->save_offset; - write (pdump_fd, &rdata, sizeof (rdata)); + PDUMP_WRITE_ALIGNED (EMACS_INT, rdata); elmt = elmt->next; } } rt.desc = 0; rt.count = 0; - write (pdump_fd, &rt, sizeof (rt)); + PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt); for (i=0; idescription; rt.count = pdump_struct_table.list[i].list.count; - write (pdump_fd, &rt, sizeof (rt)); + PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt); 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)); + PDUMP_WRITE_ALIGNED (EMACS_INT, rdata); rdata += elmt->size; } elmt = elmt->next; @@ -853,47 +939,55 @@ pdump_dump_rtables (void) } rt.desc = 0; rt.count = 0; - write (pdump_fd, &rt, sizeof (rt)); + PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt); } static void -pdump_dump_wired (void) +pdump_dump_root_objects (void) { - EMACS_INT count = pdump_wireidx + pdump_wireidx_list; - int i; + size_t count = (Dynarr_length (pdump_root_objects) + + Dynarr_length (pdump_weak_object_chains)); + size_t i; - write (pdump_fd, &count, sizeof (count)); + PDUMP_WRITE_ALIGNED (size_t, count); + PDUMP_ALIGN_OUTPUT (pdump_static_Lisp_Object); - for (i=0; isave_offset; - write (pdump_fd, &pdump_wirevec[i], sizeof (pdump_wirevec[i])); - write (pdump_fd, &obj, sizeof (obj)); + pdump_static_Lisp_Object obj; + obj.address = Dynarr_at (pdump_root_objects, i); + obj.value = * obj.address; + + if (POINTER_TYPE_P (XTYPE (obj.value))) + obj.value = wrap_object ((void *) pdump_get_entry (XRECORD_LHEADER (obj.value))->save_offset); + + PDUMP_WRITE (pdump_static_Lisp_Object, obj); } - for (i=0; idescription; + desc = XRECORD_LHEADER_IMPLEMENTATION (obj.value)->description; for (pos = 0; desc[pos].type != XD_LO_LINK; pos++) assert (desc[pos].type != XD_END); - obj = *(Lisp_Object *)(desc[pos].offset + (char *)(XRECORD_LHEADER (obj))); + obj.value = *(Lisp_Object *)(desc[pos].offset + (char *)(XRECORD_LHEADER (obj.value))); } - res = elmt->save_offset; + obj.value = wrap_object ((void *) elmt->save_offset); - write (pdump_fd, &pdump_wirevec_list[i], sizeof (pdump_wirevec_list[i])); - write (pdump_fd, &res, sizeof (res)); + PDUMP_WRITE (pdump_static_Lisp_Object, obj); } } @@ -903,16 +997,19 @@ pdump (void) int i; Lisp_Object t_console, t_device, t_frame; int none; - dump_header hd; + pdump_header header; + + flush_all_buffer_local_cache (); /* These appear in a DEFVAR_LISP, which does a staticpro() */ - t_console = Vterminal_console; - t_frame = Vterminal_frame; - t_device = Vterminal_device; + t_console = Vterminal_console; Vterminal_console = Qnil; + t_frame = Vterminal_frame; Vterminal_frame = Qnil; + t_device = Vterminal_device; Vterminal_device = Qnil; - Vterminal_console = Qnil; - Vterminal_frame = Qnil; - Vterminal_device = Qnil; + 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])); pdump_hash = xnew_array_and_zero (pdump_entry_list_elmt *, PDUMP_HASHSIZE); @@ -931,10 +1028,8 @@ pdump (void) pdump_opaque_data_list.count = 0; depth = 0; - for (i=0; isignature, DUMP_SIGNATURE, DUMP_SIGNATURE_LEN) - && ((dump_header *)pdump_start)->id == dump_id); + return (!memcmp (((pdump_header *)pdump_start)->signature, + PDUMP_SIGNATURE, PDUMP_SIGNATURE_LEN) + && ((pdump_header *)pdump_start)->id == dump_id); } -static int pdump_load_finish (void) +/*----------------------------------------------------------------------*/ +/* Reading the dump file */ +/*----------------------------------------------------------------------*/ +static int +pdump_load_finish (void) { int i; char *p; EMACS_INT delta; EMACS_INT count; + pdump_header *header = (pdump_header *)pdump_start; pdump_end = pdump_start + pdump_length; -#define PDUMP_READ(p, type) (p = (char*) (((type *) p) + 1), *((type *) p - 1)) + delta = ((EMACS_INT)pdump_start) - header->reloc_address; + p = pdump_start + header->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_structdmp; i++) + /* Put back the pdump_root_struct_ptrs */ + p = (char *) ALIGN_PTR (p, ALIGNOF (pdump_static_pointer)); + for (i=0; inb_root_struct_ptrs; i++) { - void **adr = PDUMP_READ (p, void **); - *adr = (void *) (PDUMP_READ (p, char *) + delta); + pdump_static_pointer ptr = PDUMP_READ (p, pdump_static_pointer); + (* ptr.address) = ptr.value + delta; } - /* Put back the opaques */ - for (i=0; i<((dump_header *)pdump_start)->nb_opaquedmp; i++) + /* Put back the pdump_opaques */ + for (i=0; inb_opaques; i++) { - struct pdump_dumpopaqueinfo di = PDUMP_READ (p, struct pdump_dumpopaqueinfo); - memcpy (di.data, p, di.size); - p += di.size; + pdump_opaque info = PDUMP_READ_ALIGNED (p, pdump_opaque); + memcpy (info.varaddress, p, info.size); + p += info.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; for (;;) { - pdump_reloc_table rt = PDUMP_READ (p, pdump_reloc_table); + pdump_reloc_table rt = PDUMP_READ_ALIGNED (p, pdump_reloc_table); + p = (char *) ALIGN_PTR (p, ALIGNOF (char *)); if (rt.desc) { + char **reloc = (char **)p; for (i=0; i < rt.count; i++) { - char *adr = delta + *(char **)p; - *(char **)p = adr; - pdump_reloc_one (adr, delta, rt.desc); - p += sizeof (char *); + reloc[i] += delta; + pdump_reloc_one (reloc[i], delta, rt.desc); } + p += rt.count * sizeof (char *); } else if (!(--count)) break; } - /* 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); + GetModuleFileName (NULL, exe_path, PATH_MAX); #else /* !WIN32_NATIVE */ char *w; const char *dir, *p; @@ -1301,12 +1395,12 @@ int pdump_load(const char *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 @@ -1336,13 +1430,13 @@ int 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) @@ -1351,7 +1445,7 @@ int pdump_load(const char *argv0) sprintf (exe_path, "./%s", name); break; } - path = p+1; + path = p+1; } } #endif /* WIN32_NATIVE */