442
|
1 /* Portable data dumper for XEmacs.
|
|
2 Copyright (C) 1999-2000 Olivier Galibert
|
458
|
3 Copyright (C) 2001 Martin Buchholz
|
1333
|
4 Copyright (C) 2001, 2002, 2003 Ben Wing.
|
442
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
800
|
25 /* !!#### Not yet Mule-ized */
|
|
26
|
442
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "specifier.h"
|
771
|
31 #include "file-coding.h"
|
442
|
32 #include "elhash.h"
|
1204
|
33 #include "lstream.h"
|
442
|
34 #include "sysfile.h"
|
|
35 #include "console-stream.h"
|
|
36
|
|
37 #ifdef WIN32_NATIVE
|
771
|
38 #include "syswindows.h"
|
442
|
39 #else
|
|
40 #ifdef HAVE_MMAP
|
|
41 #include <sys/mman.h>
|
|
42 #endif
|
2015
|
43 #include "dump-data.h"
|
442
|
44 #endif
|
|
45
|
|
46 typedef struct
|
|
47 {
|
545
|
48 const void *varaddress;
|
665
|
49 Bytecount size;
|
1204
|
50 const struct memory_description *desc;
|
|
51 } pdump_root_block;
|
452
|
52
|
|
53 typedef struct
|
|
54 {
|
1204
|
55 Dynarr_declare (pdump_root_block);
|
|
56 } pdump_root_block_dynarr;
|
452
|
57
|
|
58 typedef struct
|
|
59 {
|
|
60 void **ptraddress;
|
1204
|
61 const struct sized_memory_description *desc;
|
452
|
62 } pdump_root_struct_ptr;
|
|
63
|
|
64 typedef struct
|
|
65 {
|
|
66 Dynarr_declare (pdump_root_struct_ptr);
|
|
67 } pdump_root_struct_ptr_dynarr;
|
|
68
|
458
|
69 typedef struct
|
|
70 {
|
|
71 Lisp_Object *address;
|
|
72 Lisp_Object value;
|
|
73 } pdump_static_Lisp_Object;
|
|
74
|
|
75 typedef struct
|
|
76 {
|
|
77 char **address; /* char * for ease of doing relocation */
|
|
78 char * value;
|
|
79 } pdump_static_pointer;
|
|
80
|
1204
|
81 static pdump_root_block_dynarr *pdump_root_blocks;
|
452
|
82 static pdump_root_struct_ptr_dynarr *pdump_root_struct_ptrs;
|
1204
|
83 static Lisp_Object_ptr_dynarr *pdump_root_lisp_objects;
|
452
|
84 static Lisp_Object_ptr_dynarr *pdump_weak_object_chains;
|
|
85
|
1204
|
86 /* Mark SIZE bytes at non-heap address VARADDRESS for dumping, described
|
|
87 by DESC. */
|
452
|
88 void
|
1204
|
89 dump_add_root_block (const void *varaddress, Bytecount size,
|
|
90 const struct memory_description *desc)
|
452
|
91 {
|
1204
|
92 pdump_root_block info;
|
452
|
93 info.varaddress = varaddress;
|
|
94 info.size = size;
|
1204
|
95 info.desc = desc;
|
|
96 if (pdump_root_blocks == NULL)
|
|
97 pdump_root_blocks = Dynarr_new (pdump_root_block);
|
|
98 Dynarr_add (pdump_root_blocks, info);
|
452
|
99 }
|
|
100
|
|
101 /* Mark the struct described by DESC and pointed to by the pointer at
|
|
102 non-heap address VARADDRESS for dumping.
|
|
103 All the objects reachable from this pointer will also be dumped. */
|
|
104 void
|
771
|
105 dump_add_root_struct_ptr (void *ptraddress,
|
1204
|
106 const struct sized_memory_description *desc)
|
452
|
107 {
|
|
108 pdump_root_struct_ptr info;
|
|
109 info.ptraddress = (void **) ptraddress;
|
|
110 info.desc = desc;
|
|
111 if (pdump_root_struct_ptrs == NULL)
|
|
112 pdump_root_struct_ptrs = Dynarr_new (pdump_root_struct_ptr);
|
|
113 Dynarr_add (pdump_root_struct_ptrs, info);
|
|
114 }
|
|
115
|
|
116 /* Mark the Lisp_Object at non-heap address VARADDRESS for dumping.
|
|
117 All the objects reachable from this var will also be dumped. */
|
|
118 void
|
1204
|
119 dump_add_root_lisp_object (Lisp_Object *varaddress)
|
452
|
120 {
|
1204
|
121 if (pdump_root_lisp_objects == NULL)
|
|
122 pdump_root_lisp_objects = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
|
|
123 Dynarr_add (pdump_root_lisp_objects, varaddress);
|
452
|
124 }
|
|
125
|
|
126 /* Mark the list pointed to by the Lisp_Object at VARADDRESS for dumping. */
|
|
127 void
|
|
128 dump_add_weak_object_chain (Lisp_Object *varaddress)
|
|
129 {
|
|
130 if (pdump_weak_object_chains == NULL)
|
|
131 pdump_weak_object_chains = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
|
|
132 Dynarr_add (pdump_weak_object_chains, varaddress);
|
|
133 }
|
|
134
|
|
135
|
458
|
136 inline static void
|
665
|
137 pdump_align_stream (FILE *stream, Bytecount alignment)
|
458
|
138 {
|
|
139 long offset = ftell (stream);
|
|
140 long adjustment = ALIGN_SIZE (offset, alignment) - offset;
|
|
141 if (adjustment)
|
|
142 fseek (stream, adjustment, SEEK_CUR);
|
|
143 }
|
|
144
|
|
145 #define PDUMP_ALIGN_OUTPUT(type) pdump_align_stream (pdump_out, ALIGNOF (type))
|
|
146
|
|
147 #define PDUMP_WRITE(type, object) \
|
771
|
148 retry_fwrite (&object, sizeof (object), 1, pdump_out);
|
458
|
149
|
|
150 #define PDUMP_WRITE_ALIGNED(type, object) do { \
|
|
151 PDUMP_ALIGN_OUTPUT (type); \
|
|
152 PDUMP_WRITE (type, object); \
|
|
153 } while (0)
|
|
154
|
|
155 #define PDUMP_READ(ptr, type) \
|
|
156 (((type *) (ptr = (char*) (((type *) ptr) + 1)))[-1])
|
|
157
|
|
158 #define PDUMP_READ_ALIGNED(ptr, type) \
|
826
|
159 ((ptr = (char *) ALIGN_PTR (ptr, type)), PDUMP_READ (ptr, type))
|
458
|
160
|
|
161
|
|
162
|
452
|
163 typedef struct
|
|
164 {
|
1204
|
165 const struct memory_description *desc;
|
442
|
166 int count;
|
|
167 } pdump_reloc_table;
|
|
168
|
|
169 static char *pdump_rt_list = 0;
|
|
170
|
|
171 void
|
|
172 pdump_objects_unmark (void)
|
|
173 {
|
|
174 int i;
|
|
175 char *p = pdump_rt_list;
|
|
176 if (p)
|
|
177 for (;;)
|
|
178 {
|
|
179 pdump_reloc_table *rt = (pdump_reloc_table *)p;
|
|
180 p += sizeof (pdump_reloc_table);
|
|
181 if (rt->desc)
|
|
182 {
|
|
183 for (i=0; i<rt->count; i++)
|
|
184 {
|
|
185 struct lrecord_header *lh = * (struct lrecord_header **) p;
|
|
186 if (! C_READONLY_RECORD_HEADER_P (lh))
|
|
187 UNMARK_RECORD_HEADER (lh);
|
|
188 p += sizeof (EMACS_INT);
|
|
189 }
|
|
190 } else
|
|
191 break;
|
|
192 }
|
|
193 }
|
|
194
|
|
195
|
1204
|
196 /* The structure of the dump file looks like this:
|
458
|
197 0 - header
|
|
198 - dumped objects
|
1204
|
199 stab_offset - nb_root_struct_ptrs*struct(void *, adr)
|
|
200 for global pointers to structures
|
|
201 - nb_root_blocks*struct(void *, size, info) for global
|
|
202 objects to restore
|
458
|
203 - relocation table
|
|
204 - root lisp object address/value couples with the count
|
|
205 preceding the list
|
442
|
206 */
|
|
207
|
|
208
|
452
|
209 #define PDUMP_SIGNATURE "XEmacsDP"
|
|
210 #define PDUMP_SIGNATURE_LEN (sizeof (PDUMP_SIGNATURE) - 1)
|
442
|
211
|
|
212 typedef struct
|
|
213 {
|
452
|
214 char signature[PDUMP_SIGNATURE_LEN];
|
442
|
215 unsigned int id;
|
|
216 EMACS_UINT stab_offset;
|
|
217 EMACS_UINT reloc_address;
|
452
|
218 int nb_root_struct_ptrs;
|
1204
|
219 int nb_root_blocks;
|
452
|
220 } pdump_header;
|
442
|
221
|
458
|
222 char *pdump_start;
|
|
223 char *pdump_end;
|
665
|
224 static Bytecount pdump_length;
|
442
|
225
|
|
226 #ifdef WIN32_NATIVE
|
452
|
227 /* Handle for the dump file */
|
458
|
228 static HANDLE pdump_hFile = INVALID_HANDLE_VALUE;
|
452
|
229 /* Handle for the file mapping object for the dump file */
|
458
|
230 static HANDLE pdump_hMap = INVALID_HANDLE_VALUE;
|
442
|
231 #endif
|
|
232
|
458
|
233 static void (*pdump_free) (void);
|
442
|
234
|
460
|
235 static unsigned char pdump_align_table[] =
|
442
|
236 {
|
460
|
237 64, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1,
|
|
238 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1,
|
|
239 32, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1,
|
|
240 16, 1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1
|
442
|
241 };
|
|
242
|
647
|
243 static inline int
|
665
|
244 pdump_size_to_align (Bytecount size)
|
442
|
245 {
|
460
|
246 return pdump_align_table[size % countof (pdump_align_table)];
|
|
247 }
|
|
248
|
|
249 typedef struct pdump_entry_list_elt
|
|
250 {
|
|
251 struct pdump_entry_list_elt *next;
|
442
|
252 const void *obj;
|
665
|
253 Bytecount size;
|
442
|
254 int count;
|
|
255 EMACS_INT save_offset;
|
460
|
256 } pdump_entry_list_elt;
|
442
|
257
|
|
258 typedef struct
|
|
259 {
|
460
|
260 pdump_entry_list_elt *first;
|
442
|
261 int align;
|
|
262 int count;
|
|
263 } pdump_entry_list;
|
|
264
|
460
|
265 typedef struct pdump_struct_list_elt
|
442
|
266 {
|
|
267 pdump_entry_list list;
|
1204
|
268 const struct memory_description *desc;
|
460
|
269 } pdump_struct_list_elt;
|
442
|
270
|
|
271 typedef struct
|
|
272 {
|
460
|
273 pdump_struct_list_elt *list;
|
442
|
274 int count;
|
|
275 int size;
|
|
276 } pdump_struct_list;
|
|
277
|
460
|
278 static pdump_entry_list *pdump_object_table;
|
442
|
279 static pdump_entry_list pdump_opaque_data_list;
|
|
280 static pdump_struct_list pdump_struct_table;
|
|
281
|
460
|
282 static int *pdump_alert_undump_object;
|
442
|
283
|
|
284 static unsigned long cur_offset;
|
665
|
285 static Bytecount max_size;
|
442
|
286 static int pdump_fd;
|
|
287 static void *pdump_buf;
|
458
|
288 static FILE *pdump_out;
|
442
|
289
|
|
290 #define PDUMP_HASHSIZE 200001
|
|
291
|
460
|
292 static pdump_entry_list_elt **pdump_hash;
|
442
|
293
|
|
294 /* Since most pointers are eight bytes aligned, the >>3 allows for a better hash */
|
|
295 static int
|
|
296 pdump_make_hash (const void *obj)
|
|
297 {
|
|
298 return ((unsigned long)(obj)>>3) % PDUMP_HASHSIZE;
|
|
299 }
|
|
300
|
460
|
301 static pdump_entry_list_elt *
|
442
|
302 pdump_get_entry (const void *obj)
|
|
303 {
|
|
304 int pos = pdump_make_hash (obj);
|
460
|
305 pdump_entry_list_elt *e;
|
442
|
306
|
|
307 assert (obj != 0);
|
|
308
|
|
309 while ((e = pdump_hash[pos]) != 0)
|
|
310 {
|
|
311 if (e->obj == obj)
|
|
312 return e;
|
|
313
|
|
314 pos++;
|
|
315 if (pos == PDUMP_HASHSIZE)
|
|
316 pos = 0;
|
|
317 }
|
|
318 return 0;
|
|
319 }
|
|
320
|
|
321 static void
|
665
|
322 pdump_add_entry (pdump_entry_list *list, const void *obj, Bytecount size,
|
458
|
323 int count)
|
442
|
324 {
|
460
|
325 pdump_entry_list_elt *e;
|
442
|
326 int pos = pdump_make_hash (obj);
|
|
327
|
|
328 while ((e = pdump_hash[pos]) != 0)
|
|
329 {
|
|
330 if (e->obj == obj)
|
|
331 return;
|
|
332
|
|
333 pos++;
|
|
334 if (pos == PDUMP_HASHSIZE)
|
|
335 pos = 0;
|
|
336 }
|
|
337
|
460
|
338 e = xnew (pdump_entry_list_elt);
|
442
|
339
|
|
340 e->next = list->first;
|
|
341 e->obj = obj;
|
|
342 e->size = size;
|
|
343 e->count = count;
|
|
344 list->first = e;
|
|
345
|
|
346 list->count += count;
|
|
347 pdump_hash[pos] = e;
|
|
348
|
460
|
349 {
|
|
350 int align = pdump_size_to_align (size);
|
442
|
351
|
460
|
352 if (align < list->align)
|
|
353 list->align = align;
|
|
354 }
|
442
|
355 }
|
|
356
|
|
357 static pdump_entry_list *
|
1204
|
358 pdump_get_entry_list (const struct memory_description *desc)
|
442
|
359 {
|
|
360 int i;
|
|
361 for (i=0; i<pdump_struct_table.count; i++)
|
1204
|
362 if (pdump_struct_table.list[i].desc == desc)
|
442
|
363 return &pdump_struct_table.list[i].list;
|
|
364
|
|
365 if (pdump_struct_table.size <= pdump_struct_table.count)
|
|
366 {
|
|
367 if (pdump_struct_table.size == -1)
|
|
368 pdump_struct_table.size = 10;
|
|
369 else
|
|
370 pdump_struct_table.size = pdump_struct_table.size * 2;
|
460
|
371 pdump_struct_table.list = (pdump_struct_list_elt *)
|
442
|
372 xrealloc (pdump_struct_table.list,
|
460
|
373 pdump_struct_table.size * sizeof (pdump_struct_list_elt));
|
442
|
374 }
|
|
375 pdump_struct_table.list[pdump_struct_table.count].list.first = 0;
|
460
|
376 pdump_struct_table.list[pdump_struct_table.count].list.align = ALIGNOF (max_align_t);
|
442
|
377 pdump_struct_table.list[pdump_struct_table.count].list.count = 0;
|
1204
|
378 pdump_struct_table.list[pdump_struct_table.count].desc = desc;
|
442
|
379
|
|
380 return &pdump_struct_table.list[pdump_struct_table.count++].list;
|
|
381 }
|
|
382
|
|
383 static struct
|
|
384 {
|
|
385 struct lrecord_header *obj;
|
|
386 int position;
|
|
387 int offset;
|
|
388 } backtrace[65536];
|
|
389
|
1204
|
390 static int pdump_depth;
|
442
|
391
|
1204
|
392 void
|
452
|
393 pdump_backtrace (void)
|
442
|
394 {
|
|
395 int i;
|
|
396 stderr_out ("pdump backtrace :\n");
|
1204
|
397 for (i = 0; i < pdump_depth; i++)
|
442
|
398 {
|
|
399 if (!backtrace[i].obj)
|
458
|
400 stderr_out (" - ind. (%d, %d)\n",
|
|
401 backtrace[i].position,
|
|
402 backtrace[i].offset);
|
442
|
403 else
|
|
404 {
|
|
405 stderr_out (" - %s (%d, %d)\n",
|
1204
|
406 LHEADER_IMPLEMENTATION (backtrace[i].obj)->name,
|
|
407 backtrace[i].position,
|
|
408 backtrace[i].offset);
|
442
|
409 }
|
|
410 }
|
|
411 }
|
|
412
|
1204
|
413 static void
|
1333
|
414 pdump_unsupported_dump_type (enum memory_description_type type,
|
|
415 int do_backtrace)
|
|
416 {
|
|
417 stderr_out ("Unsupported dump type : %d\n", type);
|
|
418 #ifdef WIN32_NATIVE
|
|
419 stderr_out ("Are you compiling with SUPPORT_EDIT_AND_CONTINUE?\n");
|
|
420 stderr_out ("See the PROBLEMS file.\n");
|
|
421 #endif
|
|
422 if (do_backtrace)
|
|
423 pdump_backtrace ();
|
|
424 abort ();
|
|
425 }
|
|
426
|
|
427 static void
|
1204
|
428 pdump_bump_depth (void)
|
|
429 {
|
|
430 int me = pdump_depth++;
|
|
431 if (me > 65536)
|
|
432 {
|
|
433 stderr_out ("Backtrace overflow, loop ?\n");
|
|
434 abort ();
|
|
435 }
|
|
436 backtrace[me].obj = 0;
|
|
437 backtrace[me].position = 0;
|
|
438 backtrace[me].offset = 0;
|
|
439 }
|
|
440
|
442
|
441 static void pdump_register_object (Lisp_Object obj);
|
771
|
442 static void pdump_register_struct_contents (const void *data,
|
1204
|
443 const struct sized_memory_description *
|
771
|
444 sdesc,
|
|
445 int count);
|
458
|
446 static void pdump_register_struct (const void *data,
|
1204
|
447 const struct sized_memory_description *sdesc,
|
458
|
448 int count);
|
442
|
449
|
|
450 static void
|
1204
|
451 pdump_register_sub (const void *data, const struct memory_description *desc)
|
442
|
452 {
|
|
453 int pos;
|
1204
|
454 int me = pdump_depth - 1;
|
442
|
455
|
|
456 for (pos = 0; desc[pos].type != XD_END; pos++)
|
|
457 {
|
1204
|
458 const struct memory_description *desc1 = &desc[pos];
|
|
459 EMACS_INT offset = lispdesc_indirect_count (desc1->offset, desc,
|
|
460 data);
|
|
461 const void *rdata = (const char *) data + offset;
|
442
|
462
|
|
463 backtrace[me].position = pos;
|
1204
|
464 backtrace[me].offset = offset;
|
|
465
|
|
466 union_switcheroo:
|
442
|
467
|
1204
|
468 /* If the flag says don't dump, then don't dump. */
|
|
469 if ((desc1->flags) & XD_FLAG_NO_PDUMP)
|
|
470 continue;
|
|
471
|
|
472 switch (desc1->type)
|
442
|
473 {
|
665
|
474 case XD_BYTECOUNT:
|
|
475 case XD_ELEMCOUNT:
|
|
476 case XD_HASHCODE:
|
442
|
477 case XD_INT:
|
|
478 case XD_LONG:
|
|
479 case XD_INT_RESET:
|
|
480 case XD_LO_LINK:
|
|
481 break;
|
|
482 case XD_OPAQUE_DATA_PTR:
|
|
483 {
|
1204
|
484 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc,
|
|
485 data);
|
442
|
486
|
|
487 pdump_add_entry (&pdump_opaque_data_list,
|
458
|
488 *(void **)rdata, count, 1);
|
442
|
489 break;
|
|
490 }
|
|
491 case XD_C_STRING:
|
|
492 {
|
1204
|
493 const char *str = * (const char **) rdata;
|
442
|
494 if (str)
|
1204
|
495 pdump_add_entry (&pdump_opaque_data_list, str, strlen (str) + 1,
|
|
496 1);
|
442
|
497 break;
|
|
498 }
|
|
499 case XD_DOC_STRING:
|
|
500 {
|
1204
|
501 const char *str = * (const char **) rdata;
|
|
502 if ((EMACS_INT) str > 0)
|
|
503 pdump_add_entry (&pdump_opaque_data_list, str, strlen (str) + 1,
|
|
504 1);
|
442
|
505 break;
|
|
506 }
|
|
507 case XD_LISP_OBJECT:
|
|
508 {
|
1204
|
509 const Lisp_Object *pobj = (const Lisp_Object *) rdata;
|
442
|
510
|
1204
|
511 assert (desc1->data1 == 0);
|
442
|
512
|
1204
|
513 backtrace[me].offset = (const char *) pobj - (const char *) data;
|
442
|
514 pdump_register_object (*pobj);
|
|
515 break;
|
|
516 }
|
|
517 case XD_LISP_OBJECT_ARRAY:
|
|
518 {
|
|
519 int i;
|
1204
|
520 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc,
|
|
521 data);
|
442
|
522
|
|
523 for (i = 0; i < count; i++)
|
|
524 {
|
1204
|
525 const Lisp_Object *pobj = ((const Lisp_Object *) rdata) + i;
|
442
|
526 Lisp_Object dobj = *pobj;
|
|
527
|
1204
|
528 backtrace[me].offset =
|
|
529 (const char *) pobj - (const char *) data;
|
442
|
530 pdump_register_object (dobj);
|
|
531 }
|
|
532 break;
|
|
533 }
|
|
534 case XD_STRUCT_PTR:
|
|
535 {
|
1204
|
536 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc,
|
|
537 data);
|
|
538 const struct sized_memory_description *sdesc =
|
|
539 lispdesc_indirect_description (data, desc1->data2);
|
442
|
540 const char *dobj = *(const char **)rdata;
|
|
541 if (dobj)
|
1204
|
542 pdump_register_struct (dobj, sdesc, count);
|
442
|
543 break;
|
|
544 }
|
771
|
545 case XD_STRUCT_ARRAY:
|
|
546 {
|
1204
|
547 EMACS_INT count = lispdesc_indirect_count (desc1->data1, desc,
|
|
548 data);
|
|
549 const struct sized_memory_description *sdesc =
|
|
550 lispdesc_indirect_description (data, desc1->data2);
|
771
|
551
|
|
552 pdump_register_struct_contents (rdata, sdesc, count);
|
|
553 break;
|
|
554 }
|
|
555 case XD_UNION:
|
1204
|
556 case XD_UNION_DYNAMIC_SIZE:
|
|
557 desc1 = lispdesc_process_xd_union (desc1, desc, data);
|
|
558 if (desc1)
|
|
559 goto union_switcheroo;
|
|
560 break;
|
771
|
561
|
442
|
562 default:
|
1333
|
563 pdump_unsupported_dump_type (desc1->type, 1);
|
1204
|
564 }
|
442
|
565 }
|
|
566 }
|
|
567
|
|
568 static void
|
|
569 pdump_register_object (Lisp_Object obj)
|
|
570 {
|
|
571 struct lrecord_header *objh;
|
458
|
572 const struct lrecord_implementation *imp;
|
442
|
573
|
|
574 if (!POINTER_TYPE_P (XTYPE (obj)))
|
|
575 return;
|
|
576
|
|
577 objh = XRECORD_LHEADER (obj);
|
|
578 if (!objh)
|
|
579 return;
|
|
580
|
|
581 if (pdump_get_entry (objh))
|
|
582 return;
|
|
583
|
458
|
584 imp = LHEADER_IMPLEMENTATION (objh);
|
|
585
|
934
|
586 if (imp->description
|
1204
|
587 && RECORD_DUMPABLE (objh))
|
442
|
588 {
|
1204
|
589 pdump_bump_depth ();
|
|
590 backtrace[pdump_depth - 1].obj = objh;
|
442
|
591 pdump_add_entry (pdump_object_table + objh->type,
|
1204
|
592 objh, detagged_lisp_object_size (objh), 1);
|
|
593 pdump_register_sub (objh, imp->description);
|
|
594 --pdump_depth;
|
442
|
595 }
|
|
596 else
|
|
597 {
|
|
598 pdump_alert_undump_object[objh->type]++;
|
458
|
599 stderr_out ("Undumpable object type : %s\n", imp->name);
|
442
|
600 pdump_backtrace ();
|
|
601 }
|
|
602 }
|
|
603
|
771
|
604 /* Register the referenced objects in the array of COUNT objects of
|
|
605 located at DATA; each object is described by SDESC. "Object" here
|
|
606 simply means any block of memory; it need not actually be a C
|
|
607 "struct". It could be a single integer or Lisp_Object, for
|
|
608 example, as long as the description is accurate.
|
|
609
|
|
610 This does not register the block of memory itself; it may, for
|
|
611 example, be an array of structures inlined in another memory block
|
|
612 and thus should not be registered. See pdump_register_struct(),
|
|
613 which does register the memory block. */
|
|
614
|
|
615 static void
|
|
616 pdump_register_struct_contents (const void *data,
|
1204
|
617 const struct sized_memory_description *sdesc,
|
771
|
618 int count)
|
|
619
|
|
620 {
|
|
621 int i;
|
|
622 Bytecount elsize;
|
|
623
|
1204
|
624 pdump_bump_depth ();
|
|
625 elsize = lispdesc_structure_size (data, sdesc);
|
771
|
626 for (i = 0; i < count; i++)
|
|
627 {
|
1204
|
628 pdump_register_sub (((char *) data) + elsize * i, sdesc->description);
|
771
|
629 }
|
1204
|
630 --pdump_depth;
|
771
|
631 }
|
|
632
|
|
633 /* Register the array of COUNT objects of located at DATA; each object is
|
|
634 described by SDESC. "Object" here simply means any block of memory;
|
|
635 it need not actually be a C "struct". It could be a single integer
|
|
636 or Lisp_Object, for example, as long as the description is accurate.
|
|
637
|
|
638 This is like pdump_register_struct_contents() but also registers
|
|
639 the memory block itself. */
|
|
640
|
442
|
641 static void
|
458
|
642 pdump_register_struct (const void *data,
|
1204
|
643 const struct sized_memory_description *sdesc,
|
458
|
644 int count)
|
442
|
645 {
|
|
646 if (data && !pdump_get_entry (data))
|
|
647 {
|
1204
|
648 pdump_add_entry (pdump_get_entry_list (sdesc->description), data,
|
|
649 lispdesc_structure_size (data, sdesc), count);
|
442
|
650
|
771
|
651 pdump_register_struct_contents (data, sdesc, count);
|
442
|
652 }
|
|
653 }
|
|
654
|
1204
|
655 /* Store the already-calculated new pointer offsets for all pointers in the
|
|
656 COUNT contiguous blocks of memory, each described by DESC and of size
|
|
657 SIZE, whose original is located at ORIG_DATA and the modifiable copy at
|
|
658 DATA. We examine the description to figure out where the pointers are,
|
|
659 and then look up the replacement values using pdump_get_entry().
|
771
|
660
|
1204
|
661 This is done just before writing the modified block of memory to the
|
|
662 dump file. The new pointer offsets have been carefully calculated so
|
|
663 that the data being pointed gets written at that offset in the dump
|
|
664 file. That way, the dump file is a correct memory image except perhaps
|
|
665 for a constant that needs to be added to all pointers. (#### In fact, we
|
|
666 SHOULD be starting up a dumped XEmacs, seeing where the dumped file gets
|
|
667 loaded into memory, and then rewriting the dumped file after relocating
|
|
668 all the pointers relative to this memory location. That way, if the
|
|
669 file gets loaded again at the same location, which will be common, we
|
|
670 don't have to do any relocating, which is both faster at startup and
|
771
|
671 allows the read-only part of the dumped data to be shared read-only
|
|
672 between different invocations of XEmacs.)
|
|
673
|
|
674 #### Do we distinguish between read-only and writable dumped data?
|
|
675 Should we? It's tricky because the dumped data, once loaded again,
|
1204
|
676 cannot really be free()d or garbage collected since it's all stored in
|
|
677 one contiguous block of data with no malloc() headers, and we don't keep
|
|
678 track of the pointers used internally in malloc() and the Lisp allocator
|
|
679 to track allocated blocks of memory. */
|
771
|
680
|
|
681 static void
|
|
682 pdump_store_new_pointer_offsets (int count, void *data, const void *orig_data,
|
1204
|
683 const struct memory_description *desc,
|
771
|
684 int size)
|
|
685 {
|
|
686 int pos, i;
|
|
687 /* Process each block one by one */
|
|
688 for (i = 0; i < count; i++)
|
|
689 {
|
|
690 /* CUR points to the beginning of each block in the new data. */
|
|
691 char *cur = ((char *)data) + i*size;
|
|
692 /* Scan each line of the description for relocatable pointers */
|
|
693 for (pos = 0; desc[pos].type != XD_END; pos++)
|
|
694 {
|
|
695 /* RDATA points to the beginning of each element in the new data. */
|
1204
|
696 const struct memory_description *desc1 = &desc[pos];
|
|
697 /* #### Change ORIG_DATA to DATA. See below. */
|
|
698 void *rdata = cur + lispdesc_indirect_count (desc1->offset, desc,
|
|
699 orig_data);
|
|
700 union_switcheroo:
|
|
701
|
|
702 /* If the flag says don't dump, then don't dump. */
|
|
703 if ((desc1->flags) & XD_FLAG_NO_PDUMP)
|
|
704 continue;
|
|
705
|
|
706 switch (desc1->type)
|
771
|
707 {
|
|
708 case XD_BYTECOUNT:
|
|
709 case XD_ELEMCOUNT:
|
|
710 case XD_HASHCODE:
|
|
711 case XD_INT:
|
|
712 case XD_LONG:
|
|
713 break;
|
|
714 case XD_INT_RESET:
|
|
715 {
|
1204
|
716 EMACS_INT val = lispdesc_indirect_count (desc1->data1, desc,
|
|
717 orig_data);
|
771
|
718 * (int *) rdata = val;
|
|
719 break;
|
|
720 }
|
|
721 case XD_OPAQUE_DATA_PTR:
|
|
722 case XD_C_STRING:
|
|
723 case XD_STRUCT_PTR:
|
|
724 {
|
|
725 void *ptr = * (void **) rdata;
|
|
726 if (ptr)
|
|
727 * (EMACS_INT *) rdata = pdump_get_entry (ptr)->save_offset;
|
|
728 break;
|
|
729 }
|
|
730 case XD_LO_LINK:
|
|
731 {
|
|
732 /* As described in lrecord.h, this is a weak link.
|
|
733 Thus, we need to link this object not (necessarily)
|
|
734 to the object directly pointed to, but to the next
|
|
735 referenced object in the chain. None of the
|
|
736 intermediate objects will be written out, so we
|
|
737 traverse down the chain of objects until we find a
|
|
738 referenced one. (The Qnil or Qunbound that ends the
|
|
739 chain will always be a referenced object.) */
|
|
740 Lisp_Object obj = * (Lisp_Object *) rdata;
|
|
741 pdump_entry_list_elt *elt1;
|
1204
|
742 /* #### Figure out how to handle indirect offsets here.
|
|
743 #### In general, when computing indirect counts, do we
|
|
744 really need to use the orig_data pointer? Why not just
|
|
745 use the new stuff?
|
|
746
|
|
747 No, we don't usually need orig_data. We only need it
|
|
748 when fetching pointers out of the data, not integers.
|
|
749 This currently occurs only with description maps. We
|
|
750 should change the other places to DATA to emphasize
|
|
751 this. */
|
|
752 assert (!XD_IS_INDIRECT (desc1->offset));
|
771
|
753 for (;;)
|
|
754 {
|
|
755 elt1 = pdump_get_entry (XRECORD_LHEADER (obj));
|
|
756 if (elt1)
|
|
757 break;
|
1204
|
758 obj = * (Lisp_Object *) (desc1->offset +
|
771
|
759 (char *)(XRECORD_LHEADER (obj)));
|
|
760 }
|
|
761 * (EMACS_INT *) rdata = elt1->save_offset;
|
|
762 break;
|
|
763 }
|
|
764 case XD_LISP_OBJECT:
|
|
765 {
|
|
766 Lisp_Object *pobj = (Lisp_Object *) rdata;
|
|
767
|
1204
|
768 assert (desc1->data1 == 0);
|
771
|
769
|
|
770 if (POINTER_TYPE_P (XTYPE (*pobj)) && XRECORD_LHEADER (*pobj))
|
|
771 * (EMACS_INT *) pobj =
|
|
772 pdump_get_entry (XRECORD_LHEADER (*pobj))->save_offset;
|
|
773 break;
|
|
774 }
|
|
775 case XD_LISP_OBJECT_ARRAY:
|
|
776 {
|
1204
|
777 EMACS_INT num = lispdesc_indirect_count (desc1->data1, desc,
|
|
778 orig_data);
|
771
|
779 int j;
|
|
780
|
|
781 for (j = 0; j < num; j++)
|
|
782 {
|
|
783 Lisp_Object *pobj = ((Lisp_Object *) rdata) + j;
|
|
784 if (POINTER_TYPE_P (XTYPE (*pobj)) &&
|
|
785 XRECORD_LHEADER (*pobj))
|
|
786 * (EMACS_INT *) pobj =
|
|
787 pdump_get_entry (XRECORD_LHEADER (*pobj))->save_offset;
|
|
788 }
|
|
789 break;
|
|
790 }
|
|
791 case XD_DOC_STRING:
|
|
792 {
|
|
793 EMACS_INT str = *(EMACS_INT *)rdata;
|
|
794 if (str > 0)
|
|
795 * (EMACS_INT *) rdata =
|
|
796 pdump_get_entry ((void *)str)->save_offset;
|
|
797 break;
|
|
798 }
|
|
799 case XD_STRUCT_ARRAY:
|
|
800 {
|
1204
|
801 EMACS_INT num = lispdesc_indirect_count (desc1->data1, desc,
|
|
802 orig_data);
|
|
803 const struct sized_memory_description *sdesc =
|
|
804 lispdesc_indirect_description (orig_data, desc1->data2);
|
771
|
805
|
|
806 pdump_store_new_pointer_offsets
|
|
807 (num, rdata,
|
|
808 ((char *) rdata - (char *) data) + (char *) orig_data,
|
1204
|
809 sdesc->description,
|
|
810 lispdesc_structure_size
|
771
|
811 (((char *) rdata - (char *) data) + (char *) orig_data,
|
1204
|
812 sdesc));
|
771
|
813 break;
|
|
814 }
|
|
815 case XD_UNION:
|
1204
|
816 case XD_UNION_DYNAMIC_SIZE:
|
|
817 desc1 = lispdesc_process_xd_union (desc1, desc, orig_data);
|
|
818 if (desc1)
|
|
819 goto union_switcheroo;
|
|
820 break;
|
771
|
821
|
|
822 default:
|
1333
|
823 pdump_unsupported_dump_type (desc1->type, 0);
|
771
|
824 }
|
|
825 }
|
|
826 }
|
|
827 }
|
|
828
|
|
829 /* Write out to global file descriptor PDUMP_OUT the element (one or
|
|
830 more contiguous blocks of identical size/description) recorded in
|
|
831 ELT and described by DESC. The element is first copied to a buffer
|
|
832 and then all pointers (this includes Lisp_Objects other than
|
|
833 integer/character) are relocated to the (pre-computed) offset in
|
|
834 the dump file. */
|
|
835
|
442
|
836 static void
|
460
|
837 pdump_dump_data (pdump_entry_list_elt *elt,
|
1204
|
838 const struct memory_description *desc)
|
442
|
839 {
|
665
|
840 Bytecount size = elt->size;
|
460
|
841 int count = elt->count;
|
442
|
842 if (desc)
|
|
843 {
|
771
|
844 /* Copy to temporary buffer */
|
460
|
845 memcpy (pdump_buf, elt->obj, size*count);
|
442
|
846
|
771
|
847 /* Store new offsets into all pointers in block */
|
|
848 pdump_store_new_pointer_offsets (count, pdump_buf, elt->obj, desc, size);
|
|
849 }
|
|
850 retry_fwrite (desc ? pdump_buf : elt->obj, size, count, pdump_out);
|
|
851 }
|
442
|
852
|
771
|
853 /* Relocate a single memory block at DATA, described by DESC, from its
|
1204
|
854 assumed load location to its actual one by adding DELTA to all pointers
|
|
855 in the block. Does not recursively relocate any other memory blocks
|
|
856 pointed to. (We already have a list of all memory blocks in the dump
|
|
857 file.) This is used once the dump data has been loaded back in, both
|
|
858 for blocks sitting in the dumped data and in global data objects whose
|
|
859 contents have been restored from the dumped data. */
|
442
|
860
|
|
861 static void
|
458
|
862 pdump_reloc_one (void *data, EMACS_INT delta,
|
1204
|
863 const struct memory_description *desc)
|
442
|
864 {
|
|
865 int pos;
|
|
866
|
|
867 for (pos = 0; desc[pos].type != XD_END; pos++)
|
|
868 {
|
1204
|
869 const struct memory_description *desc1 = &desc[pos];
|
|
870 void *rdata = (char *) data + lispdesc_indirect_count (desc1->offset,
|
|
871 desc, data);
|
|
872
|
|
873 union_switcheroo:
|
|
874
|
|
875 /* If the flag says don't dump, then don't dump. */
|
|
876 if ((desc1->flags) & XD_FLAG_NO_PDUMP)
|
|
877 continue;
|
|
878
|
|
879 switch (desc1->type)
|
442
|
880 {
|
665
|
881 case XD_BYTECOUNT:
|
|
882 case XD_ELEMCOUNT:
|
|
883 case XD_HASHCODE:
|
442
|
884 case XD_INT:
|
|
885 case XD_LONG:
|
|
886 case XD_INT_RESET:
|
|
887 break;
|
|
888 case XD_OPAQUE_DATA_PTR:
|
|
889 case XD_C_STRING:
|
|
890 case XD_STRUCT_PTR:
|
|
891 case XD_LO_LINK:
|
|
892 {
|
|
893 EMACS_INT ptr = *(EMACS_INT *)rdata;
|
|
894 if (ptr)
|
|
895 *(EMACS_INT *)rdata = ptr+delta;
|
|
896 break;
|
|
897 }
|
|
898 case XD_LISP_OBJECT:
|
|
899 {
|
|
900 Lisp_Object *pobj = (Lisp_Object *) rdata;
|
|
901
|
1204
|
902 assert (desc1->data1 == 0);
|
442
|
903
|
|
904 if (POINTER_TYPE_P (XTYPE (*pobj))
|
|
905 && ! EQ (*pobj, Qnull_pointer))
|
793
|
906 *pobj = wrap_pointer_1 ((char *) XPNTR (*pobj) + delta);
|
442
|
907
|
|
908 break;
|
|
909 }
|
|
910 case XD_LISP_OBJECT_ARRAY:
|
|
911 {
|
1204
|
912 EMACS_INT num = lispdesc_indirect_count (desc1->data1, desc,
|
|
913 data);
|
442
|
914 int j;
|
|
915
|
|
916 for (j=0; j<num; j++)
|
|
917 {
|
|
918 Lisp_Object *pobj = (Lisp_Object *) rdata + j;
|
|
919
|
|
920 if (POINTER_TYPE_P (XTYPE (*pobj))
|
|
921 && ! EQ (*pobj, Qnull_pointer))
|
793
|
922 *pobj = wrap_pointer_1 ((char *) XPNTR (*pobj) + delta);
|
442
|
923 }
|
|
924 break;
|
|
925 }
|
|
926 case XD_DOC_STRING:
|
|
927 {
|
|
928 EMACS_INT str = *(EMACS_INT *)rdata;
|
|
929 if (str > 0)
|
|
930 *(EMACS_INT *)rdata = str + delta;
|
|
931 break;
|
|
932 }
|
771
|
933 case XD_STRUCT_ARRAY:
|
|
934 {
|
1204
|
935 EMACS_INT num = lispdesc_indirect_count (desc1->data1, desc,
|
|
936 data);
|
771
|
937 int j;
|
1204
|
938 const struct sized_memory_description *sdesc =
|
|
939 lispdesc_indirect_description (data, desc1->data2);
|
|
940 Bytecount size = lispdesc_structure_size (rdata, sdesc);
|
771
|
941
|
|
942 /* Note: We are recursing over data in the block itself */
|
|
943 for (j = 0; j < num; j++)
|
|
944 pdump_reloc_one ((char *) rdata + j * size, delta,
|
|
945 sdesc->description);
|
|
946
|
|
947 break;
|
|
948 }
|
1204
|
949 case XD_UNION:
|
|
950 case XD_UNION_DYNAMIC_SIZE:
|
|
951 desc1 = lispdesc_process_xd_union (desc1, desc, data);
|
|
952 if (desc1)
|
|
953 goto union_switcheroo;
|
|
954 break;
|
771
|
955
|
442
|
956 default:
|
1333
|
957 pdump_unsupported_dump_type (desc1->type, 0);
|
1204
|
958 }
|
442
|
959 }
|
|
960 }
|
|
961
|
|
962 static void
|
460
|
963 pdump_allocate_offset (pdump_entry_list_elt *elt,
|
1204
|
964 const struct memory_description *desc)
|
442
|
965 {
|
665
|
966 Bytecount size = elt->count * elt->size;
|
460
|
967 elt->save_offset = cur_offset;
|
442
|
968 if (size>max_size)
|
|
969 max_size = size;
|
|
970 cur_offset += size;
|
|
971 }
|
|
972
|
|
973 static void
|
460
|
974 pdump_scan_by_alignment (void (*f)(pdump_entry_list_elt *,
|
1204
|
975 const struct memory_description *))
|
442
|
976 {
|
460
|
977 int align;
|
|
978
|
|
979 for (align = ALIGNOF (max_align_t); align; align>>=1)
|
442
|
980 {
|
460
|
981 int i;
|
|
982 pdump_entry_list_elt *elt;
|
|
983
|
442
|
984 for (i=0; i<lrecord_type_count; i++)
|
|
985 if (pdump_object_table[i].align == align)
|
460
|
986 for (elt = pdump_object_table[i].first; elt; elt = elt->next)
|
|
987 f (elt, lrecord_implementations_table[i]->description);
|
442
|
988
|
|
989 for (i=0; i<pdump_struct_table.count; i++)
|
460
|
990 {
|
|
991 pdump_struct_list_elt list = pdump_struct_table.list[i];
|
|
992 if (list.list.align == align)
|
|
993 for (elt = list.list.first; elt; elt = elt->next)
|
1204
|
994 f (elt, list.desc);
|
460
|
995 }
|
442
|
996
|
460
|
997 for (elt = pdump_opaque_data_list.first; elt; elt = elt->next)
|
|
998 if (pdump_size_to_align (elt->size) == align)
|
|
999 f (elt, 0);
|
442
|
1000 }
|
|
1001 }
|
|
1002
|
|
1003 static void
|
458
|
1004 pdump_dump_root_struct_ptrs (void)
|
442
|
1005 {
|
|
1006 int i;
|
665
|
1007 Elemcount count = Dynarr_length (pdump_root_struct_ptrs);
|
458
|
1008 pdump_static_pointer *data = alloca_array (pdump_static_pointer, count);
|
|
1009 for (i = 0; i < count; i++)
|
442
|
1010 {
|
1333
|
1011 data[i].address =
|
|
1012 (char **) Dynarr_atp (pdump_root_struct_ptrs, i)->ptraddress;
|
|
1013 data[i].value =
|
|
1014 (char *) pdump_get_entry (* data[i].address)->save_offset;
|
442
|
1015 }
|
458
|
1016 PDUMP_ALIGN_OUTPUT (pdump_static_pointer);
|
771
|
1017 retry_fwrite (data, sizeof (pdump_static_pointer), count, pdump_out);
|
442
|
1018 }
|
|
1019
|
|
1020 static void
|
1204
|
1021 pdump_dump_root_blocks (void)
|
442
|
1022 {
|
|
1023 int i;
|
1204
|
1024 for (i = 0; i < Dynarr_length (pdump_root_blocks); i++)
|
442
|
1025 {
|
1204
|
1026 pdump_root_block *info = Dynarr_atp (pdump_root_blocks, i);
|
|
1027 PDUMP_WRITE_ALIGNED (pdump_root_block, *info);
|
771
|
1028 retry_fwrite (info->varaddress, info->size, 1, pdump_out);
|
442
|
1029 }
|
|
1030 }
|
|
1031
|
|
1032 static void
|
|
1033 pdump_dump_rtables (void)
|
|
1034 {
|
452
|
1035 int i;
|
460
|
1036 pdump_entry_list_elt *elt;
|
442
|
1037 pdump_reloc_table rt;
|
|
1038
|
|
1039 for (i=0; i<lrecord_type_count; i++)
|
|
1040 {
|
460
|
1041 elt = pdump_object_table[i].first;
|
|
1042 if (!elt)
|
442
|
1043 continue;
|
|
1044 rt.desc = lrecord_implementations_table[i]->description;
|
|
1045 rt.count = pdump_object_table[i].count;
|
458
|
1046 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
|
460
|
1047 while (elt)
|
442
|
1048 {
|
460
|
1049 EMACS_INT rdata = pdump_get_entry (elt->obj)->save_offset;
|
458
|
1050 PDUMP_WRITE_ALIGNED (EMACS_INT, rdata);
|
460
|
1051 elt = elt->next;
|
442
|
1052 }
|
|
1053 }
|
|
1054
|
|
1055 rt.desc = 0;
|
|
1056 rt.count = 0;
|
458
|
1057 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
|
442
|
1058
|
|
1059 for (i=0; i<pdump_struct_table.count; i++)
|
|
1060 {
|
460
|
1061 elt = pdump_struct_table.list[i].list.first;
|
1204
|
1062 rt.desc = pdump_struct_table.list[i].desc;
|
442
|
1063 rt.count = pdump_struct_table.list[i].list.count;
|
458
|
1064 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
|
460
|
1065 while (elt)
|
442
|
1066 {
|
460
|
1067 EMACS_INT rdata = pdump_get_entry (elt->obj)->save_offset;
|
452
|
1068 int j;
|
460
|
1069 for (j=0; j<elt->count; j++)
|
442
|
1070 {
|
458
|
1071 PDUMP_WRITE_ALIGNED (EMACS_INT, rdata);
|
460
|
1072 rdata += elt->size;
|
442
|
1073 }
|
460
|
1074 elt = elt->next;
|
442
|
1075 }
|
|
1076 }
|
|
1077 rt.desc = 0;
|
|
1078 rt.count = 0;
|
458
|
1079 PDUMP_WRITE_ALIGNED (pdump_reloc_table, rt);
|
442
|
1080 }
|
|
1081
|
|
1082 static void
|
1204
|
1083 pdump_dump_root_lisp_objects (void)
|
442
|
1084 {
|
1204
|
1085 Elemcount count = (Dynarr_length (pdump_root_lisp_objects) +
|
647
|
1086 Dynarr_length (pdump_weak_object_chains));
|
665
|
1087 Elemcount i;
|
442
|
1088
|
665
|
1089 PDUMP_WRITE_ALIGNED (Elemcount, count);
|
458
|
1090 PDUMP_ALIGN_OUTPUT (pdump_static_Lisp_Object);
|
442
|
1091
|
1204
|
1092 for (i = 0; i < Dynarr_length (pdump_root_lisp_objects); i++)
|
442
|
1093 {
|
458
|
1094 pdump_static_Lisp_Object obj;
|
1204
|
1095 obj.address = Dynarr_at (pdump_root_lisp_objects, i);
|
458
|
1096 obj.value = * obj.address;
|
460
|
1097
|
458
|
1098 if (POINTER_TYPE_P (XTYPE (obj.value)))
|
619
|
1099 obj.value =
|
|
1100 wrap_pointer_1 ((void *) pdump_get_entry (XRECORD_LHEADER
|
617
|
1101 (obj.value))->save_offset);
|
460
|
1102
|
458
|
1103 PDUMP_WRITE (pdump_static_Lisp_Object, obj);
|
442
|
1104 }
|
|
1105
|
452
|
1106 for (i=0; i<Dynarr_length (pdump_weak_object_chains); i++)
|
442
|
1107 {
|
460
|
1108 pdump_entry_list_elt *elt;
|
458
|
1109 pdump_static_Lisp_Object obj;
|
442
|
1110
|
458
|
1111 obj.address = Dynarr_at (pdump_weak_object_chains, i);
|
|
1112 obj.value = * obj.address;
|
460
|
1113
|
442
|
1114 for (;;)
|
|
1115 {
|
1204
|
1116 const struct memory_description *desc;
|
442
|
1117 int pos;
|
460
|
1118 elt = pdump_get_entry (XRECORD_LHEADER (obj.value));
|
|
1119 if (elt)
|
442
|
1120 break;
|
458
|
1121 desc = XRECORD_LHEADER_IMPLEMENTATION (obj.value)->description;
|
442
|
1122 for (pos = 0; desc[pos].type != XD_LO_LINK; pos++)
|
|
1123 assert (desc[pos].type != XD_END);
|
|
1124
|
1204
|
1125 /* #### Figure out how to handle indirect offsets here. */
|
|
1126 assert (!XD_IS_INDIRECT (desc[pos].offset));
|
|
1127 obj.value =
|
|
1128 * (Lisp_Object *) (desc[pos].offset +
|
|
1129 (char *) (XRECORD_LHEADER (obj.value)));
|
442
|
1130 }
|
619
|
1131 obj.value = wrap_pointer_1 ((void *) elt->save_offset);
|
442
|
1132
|
458
|
1133 PDUMP_WRITE (pdump_static_Lisp_Object, obj);
|
442
|
1134 }
|
|
1135 }
|
|
1136
|
|
1137 void
|
|
1138 pdump (void)
|
|
1139 {
|
|
1140 int i;
|
|
1141 Lisp_Object t_console, t_device, t_frame;
|
|
1142 int none;
|
458
|
1143 pdump_header header;
|
442
|
1144
|
1204
|
1145 in_pdump = 1;
|
|
1146
|
460
|
1147 pdump_object_table = xnew_array (pdump_entry_list, lrecord_type_count);
|
|
1148 pdump_alert_undump_object = xnew_array (int, lrecord_type_count);
|
|
1149
|
|
1150 assert (ALIGNOF (max_align_t) <= pdump_align_table[0]);
|
|
1151
|
|
1152 for (i = 0; i < countof (pdump_align_table); i++)
|
|
1153 if (pdump_align_table[i] > ALIGNOF (max_align_t))
|
|
1154 pdump_align_table[i] = ALIGNOF (max_align_t);
|
|
1155
|
446
|
1156 flush_all_buffer_local_cache ();
|
|
1157
|
442
|
1158 /* These appear in a DEFVAR_LISP, which does a staticpro() */
|
452
|
1159 t_console = Vterminal_console; Vterminal_console = Qnil;
|
|
1160 t_frame = Vterminal_frame; Vterminal_frame = Qnil;
|
|
1161 t_device = Vterminal_device; Vterminal_device = Qnil;
|
442
|
1162
|
452
|
1163 dump_add_opaque (&lrecord_implementations_table,
|
1204
|
1164 lrecord_type_count *
|
|
1165 sizeof (lrecord_implementations_table[0]));
|
1676
|
1166 #ifdef USE_KKCC
|
|
1167 dump_add_opaque (&lrecord_memory_descriptions,
|
|
1168 lrecord_type_count
|
|
1169 * sizeof (lrecord_memory_descriptions[0]));
|
|
1170 #else /* not USE_KKCC */
|
452
|
1171 dump_add_opaque (&lrecord_markers,
|
|
1172 lrecord_type_count * sizeof (lrecord_markers[0]));
|
1676
|
1173 #endif /* not USE_KKCC */
|
442
|
1174
|
460
|
1175 pdump_hash = xnew_array_and_zero (pdump_entry_list_elt *, PDUMP_HASHSIZE);
|
442
|
1176
|
|
1177 for (i=0; i<lrecord_type_count; i++)
|
|
1178 {
|
|
1179 pdump_object_table[i].first = 0;
|
460
|
1180 pdump_object_table[i].align = ALIGNOF (max_align_t);
|
442
|
1181 pdump_object_table[i].count = 0;
|
|
1182 pdump_alert_undump_object[i] = 0;
|
|
1183 }
|
|
1184 pdump_struct_table.count = 0;
|
|
1185 pdump_struct_table.size = -1;
|
|
1186
|
|
1187 pdump_opaque_data_list.first = 0;
|
460
|
1188 pdump_opaque_data_list.align = ALIGNOF (max_align_t);
|
442
|
1189 pdump_opaque_data_list.count = 0;
|
1204
|
1190 pdump_depth = 0;
|
442
|
1191
|
1204
|
1192 for (i = 0; i < Dynarr_length (pdump_root_lisp_objects); i++)
|
|
1193 pdump_register_object (* Dynarr_at (pdump_root_lisp_objects, i));
|
442
|
1194
|
|
1195 none = 1;
|
|
1196 for (i=0; i<lrecord_type_count; i++)
|
|
1197 if (pdump_alert_undump_object[i])
|
|
1198 {
|
|
1199 if (none)
|
|
1200 printf ("Undumpable types list :\n");
|
|
1201 none = 0;
|
1204
|
1202 printf (" - %s (%d)\n", lrecord_implementations_table[i]->name,
|
|
1203 pdump_alert_undump_object[i]);
|
442
|
1204 }
|
|
1205 if (!none)
|
1204
|
1206 {
|
|
1207 in_pdump = 0;
|
|
1208 return;
|
|
1209 }
|
442
|
1210
|
452
|
1211 for (i=0; i<Dynarr_length (pdump_root_struct_ptrs); i++)
|
|
1212 {
|
|
1213 pdump_root_struct_ptr info = Dynarr_at (pdump_root_struct_ptrs, i);
|
|
1214 pdump_register_struct (*(info.ptraddress), info.desc, 1);
|
|
1215 }
|
442
|
1216
|
458
|
1217 memcpy (header.signature, PDUMP_SIGNATURE, PDUMP_SIGNATURE_LEN);
|
|
1218 header.id = dump_id;
|
|
1219 header.reloc_address = 0;
|
|
1220 header.nb_root_struct_ptrs = Dynarr_length (pdump_root_struct_ptrs);
|
1204
|
1221 header.nb_root_blocks = Dynarr_length (pdump_root_blocks);
|
442
|
1222
|
826
|
1223 cur_offset = MAX_ALIGN_SIZE (sizeof (header));
|
442
|
1224 max_size = 0;
|
|
1225
|
|
1226 pdump_scan_by_alignment (pdump_allocate_offset);
|
826
|
1227 cur_offset = MAX_ALIGN_SIZE (cur_offset);
|
458
|
1228 header.stab_offset = cur_offset;
|
442
|
1229
|
|
1230 pdump_buf = xmalloc (max_size);
|
|
1231 pdump_fd = open (EMACS_PROGNAME ".dmp",
|
|
1232 O_WRONLY | O_CREAT | O_TRUNC | OPEN_BINARY, 0666);
|
771
|
1233 if (pdump_fd < 0)
|
|
1234 report_file_error ("Unable to open dump file",
|
|
1235 build_string (EMACS_PROGNAME ".dmp"));
|
458
|
1236 pdump_out = fdopen (pdump_fd, "w");
|
771
|
1237 if (pdump_out < 0)
|
|
1238 report_file_error ("Unable to open dump file for writing",
|
|
1239 build_string (EMACS_PROGNAME ".dmp"));
|
442
|
1240
|
771
|
1241 retry_fwrite (&header, sizeof (header), 1, pdump_out);
|
458
|
1242 PDUMP_ALIGN_OUTPUT (max_align_t);
|
442
|
1243
|
|
1244 pdump_scan_by_alignment (pdump_dump_data);
|
|
1245
|
458
|
1246 fseek (pdump_out, header.stab_offset, SEEK_SET);
|
442
|
1247
|
458
|
1248 pdump_dump_root_struct_ptrs ();
|
1204
|
1249 pdump_dump_root_blocks ();
|
442
|
1250 pdump_dump_rtables ();
|
1204
|
1251 pdump_dump_root_lisp_objects ();
|
442
|
1252
|
771
|
1253 retry_fclose (pdump_out);
|
|
1254 retry_close (pdump_fd);
|
458
|
1255
|
442
|
1256 free (pdump_buf);
|
|
1257
|
|
1258 free (pdump_hash);
|
|
1259
|
|
1260 Vterminal_console = t_console;
|
|
1261 Vterminal_frame = t_frame;
|
|
1262 Vterminal_device = t_device;
|
1204
|
1263 in_pdump = 0;
|
442
|
1264 }
|
|
1265
|
452
|
1266 static int
|
|
1267 pdump_load_check (void)
|
442
|
1268 {
|
452
|
1269 return (!memcmp (((pdump_header *)pdump_start)->signature,
|
|
1270 PDUMP_SIGNATURE, PDUMP_SIGNATURE_LEN)
|
|
1271 && ((pdump_header *)pdump_start)->id == dump_id);
|
442
|
1272 }
|
|
1273
|
458
|
1274 /*----------------------------------------------------------------------*/
|
|
1275 /* Reading the dump file */
|
|
1276 /*----------------------------------------------------------------------*/
|
452
|
1277 static int
|
|
1278 pdump_load_finish (void)
|
442
|
1279 {
|
|
1280 int i;
|
|
1281 char *p;
|
|
1282 EMACS_INT delta;
|
|
1283 EMACS_INT count;
|
1204
|
1284 pdump_header *header = (pdump_header *) pdump_start;
|
442
|
1285
|
|
1286 pdump_end = pdump_start + pdump_length;
|
|
1287
|
1204
|
1288 delta = ((EMACS_INT) pdump_start) - header->reloc_address;
|
458
|
1289 p = pdump_start + header->stab_offset;
|
442
|
1290
|
452
|
1291 /* Put back the pdump_root_struct_ptrs */
|
826
|
1292 p = (char *) ALIGN_PTR (p, pdump_static_pointer);
|
1204
|
1293 for (i = 0; i < header->nb_root_struct_ptrs; i++)
|
442
|
1294 {
|
458
|
1295 pdump_static_pointer ptr = PDUMP_READ (p, pdump_static_pointer);
|
|
1296 (* ptr.address) = ptr.value + delta;
|
442
|
1297 }
|
|
1298
|
1204
|
1299 /* Put back the pdump_root_blocks and relocate */
|
|
1300 for (i = 0; i < header->nb_root_blocks; i++)
|
442
|
1301 {
|
1204
|
1302 pdump_root_block info = PDUMP_READ_ALIGNED (p, pdump_root_block);
|
|
1303 memcpy ((void *) info.varaddress, p, info.size);
|
|
1304 if (info.desc)
|
|
1305 pdump_reloc_one ((void *) info.varaddress, delta, info.desc);
|
452
|
1306 p += info.size;
|
442
|
1307 }
|
|
1308
|
1204
|
1309 /* Relocate the heap objects */
|
442
|
1310 pdump_rt_list = p;
|
|
1311 count = 2;
|
|
1312 for (;;)
|
|
1313 {
|
458
|
1314 pdump_reloc_table rt = PDUMP_READ_ALIGNED (p, pdump_reloc_table);
|
826
|
1315 p = (char *) ALIGN_PTR (p, char *);
|
442
|
1316 if (rt.desc)
|
|
1317 {
|
1204
|
1318 char **reloc = (char **) p;
|
|
1319 for (i = 0; i < rt.count; i++)
|
442
|
1320 {
|
458
|
1321 reloc[i] += delta;
|
|
1322 pdump_reloc_one (reloc[i], delta, rt.desc);
|
442
|
1323 }
|
458
|
1324 p += rt.count * sizeof (char *);
|
1204
|
1325 }
|
|
1326 else if (!(--count))
|
|
1327 break;
|
442
|
1328 }
|
|
1329
|
1204
|
1330 /* Put the pdump_root_lisp_objects variables in place */
|
665
|
1331 i = PDUMP_READ_ALIGNED (p, Elemcount);
|
826
|
1332 p = (char *) ALIGN_PTR (p, pdump_static_Lisp_Object);
|
458
|
1333 while (i--)
|
442
|
1334 {
|
458
|
1335 pdump_static_Lisp_Object obj = PDUMP_READ (p, pdump_static_Lisp_Object);
|
442
|
1336
|
458
|
1337 if (POINTER_TYPE_P (XTYPE (obj.value)))
|
619
|
1338 obj.value = wrap_pointer_1 ((char *) XPNTR (obj.value) + delta);
|
442
|
1339
|
458
|
1340 (* obj.address) = obj.value;
|
442
|
1341 }
|
|
1342
|
|
1343 /* Final cleanups */
|
|
1344 /* reorganize hash tables */
|
|
1345 p = pdump_rt_list;
|
|
1346 for (;;)
|
|
1347 {
|
458
|
1348 pdump_reloc_table rt = PDUMP_READ_ALIGNED (p, pdump_reloc_table);
|
826
|
1349 p = (char *) ALIGN_PTR (p, Lisp_Object);
|
442
|
1350 if (!rt.desc)
|
|
1351 break;
|
|
1352 if (rt.desc == hash_table_description)
|
|
1353 {
|
1204
|
1354 for (i = 0; i < rt.count; i++)
|
442
|
1355 pdump_reorganize_hash_table (PDUMP_READ (p, Lisp_Object));
|
|
1356 break;
|
1204
|
1357 }
|
|
1358 else
|
|
1359 p += sizeof (Lisp_Object) * rt.count;
|
442
|
1360 }
|
|
1361
|
|
1362 return 1;
|
|
1363 }
|
|
1364
|
|
1365 #ifdef WIN32_NATIVE
|
|
1366 /* Free the mapped file if we decide we don't want it after all */
|
452
|
1367 static void
|
|
1368 pdump_file_unmap (void)
|
442
|
1369 {
|
|
1370 UnmapViewOfFile (pdump_start);
|
|
1371 CloseHandle (pdump_hFile);
|
|
1372 CloseHandle (pdump_hMap);
|
|
1373 }
|
|
1374
|
452
|
1375 static int
|
|
1376 pdump_file_get (const char *path)
|
442
|
1377 {
|
|
1378
|
800
|
1379 pdump_hFile = CreateFileA (path,
|
442
|
1380 GENERIC_READ + GENERIC_WRITE, /* Required for copy on write */
|
|
1381 0, /* Not shared */
|
|
1382 NULL, /* Not inheritable */
|
|
1383 OPEN_EXISTING,
|
|
1384 FILE_ATTRIBUTE_NORMAL,
|
|
1385 NULL); /* No template file */
|
|
1386 if (pdump_hFile == INVALID_HANDLE_VALUE)
|
|
1387 return 0;
|
|
1388
|
|
1389 pdump_length = GetFileSize (pdump_hFile, NULL);
|
800
|
1390 pdump_hMap = CreateFileMappingA (pdump_hFile,
|
442
|
1391 NULL, /* No security attributes */
|
|
1392 PAGE_WRITECOPY, /* Copy on write */
|
|
1393 0, /* Max size, high half */
|
|
1394 0, /* Max size, low half */
|
|
1395 NULL); /* Unnamed */
|
|
1396 if (pdump_hMap == INVALID_HANDLE_VALUE)
|
|
1397 return 0;
|
|
1398
|
1204
|
1399 pdump_start = (char *) MapViewOfFile (pdump_hMap,
|
|
1400 FILE_MAP_COPY, /* Copy on write */
|
|
1401 0, /* Start at zero */
|
|
1402 0,
|
|
1403 0); /* Map all of it */
|
442
|
1404 pdump_free = pdump_file_unmap;
|
|
1405 return 1;
|
|
1406 }
|
|
1407
|
|
1408 /* pdump_resource_free is called (via the pdump_free pointer) to release
|
|
1409 any resources allocated by pdump_resource_get. Since the Windows API
|
|
1410 specs specifically state that you don't need to (and shouldn't) free the
|
|
1411 resources allocated by FindResource, LoadResource, and LockResource this
|
|
1412 routine does nothing. */
|
452
|
1413 static void
|
|
1414 pdump_resource_free (void)
|
442
|
1415 {
|
|
1416 }
|
|
1417
|
452
|
1418 static int
|
|
1419 pdump_resource_get (void)
|
442
|
1420 {
|
452
|
1421 HRSRC hRes; /* Handle to dump resource */
|
|
1422 HRSRC hResLoad; /* Handle to loaded dump resource */
|
442
|
1423
|
|
1424 /* See Q126630 which describes how Windows NT and 95 trap writes to
|
|
1425 resource sections and duplicate the page to allow the write to proceed.
|
|
1426 It also describes how to make the resource section read/write (and hence
|
|
1427 private to each process). Doing this avoids the exceptions and related
|
|
1428 overhead, but causes the resource section to be private to each process
|
|
1429 that is running XEmacs. Since the resource section contains little
|
|
1430 other than the dumped data, which should be private to each process, we
|
|
1431 make the whole resource section read/write so we don't have to copy it. */
|
|
1432
|
800
|
1433 hRes = FindResourceA (NULL, MAKEINTRESOURCE (101), "DUMP");
|
442
|
1434 if (hRes == NULL)
|
|
1435 return 0;
|
|
1436
|
|
1437 /* Found it, use the data in the resource */
|
1204
|
1438 hResLoad = (HRSRC) LoadResource (NULL, hRes);
|
442
|
1439 if (hResLoad == NULL)
|
|
1440 return 0;
|
|
1441
|
1204
|
1442 pdump_start = (char *) LockResource (hResLoad);
|
442
|
1443 if (pdump_start == NULL)
|
|
1444 return 0;
|
|
1445
|
|
1446 pdump_free = pdump_resource_free;
|
|
1447 pdump_length = SizeofResource (NULL, hRes);
|
665
|
1448 if (pdump_length <= (Bytecount) sizeof (pdump_header))
|
442
|
1449 {
|
|
1450 pdump_start = 0;
|
|
1451 return 0;
|
|
1452 }
|
|
1453
|
|
1454 return 1;
|
|
1455 }
|
|
1456
|
|
1457 #else /* !WIN32_NATIVE */
|
|
1458
|
452
|
1459 static void
|
|
1460 pdump_file_free (void)
|
442
|
1461 {
|
1726
|
1462 xfree (pdump_start, char *);
|
442
|
1463 }
|
|
1464
|
|
1465 #ifdef HAVE_MMAP
|
452
|
1466 static void
|
|
1467 pdump_file_unmap (void)
|
442
|
1468 {
|
|
1469 munmap (pdump_start, pdump_length);
|
|
1470 }
|
|
1471 #endif
|
|
1472
|
452
|
1473 static int
|
|
1474 pdump_file_get (const char *path)
|
442
|
1475 {
|
|
1476 int fd = open (path, O_RDONLY | OPEN_BINARY);
|
|
1477 if (fd<0)
|
|
1478 return 0;
|
|
1479
|
|
1480 pdump_length = lseek (fd, 0, SEEK_END);
|
665
|
1481 if (pdump_length < (Bytecount) sizeof (pdump_header))
|
442
|
1482 {
|
771
|
1483 retry_close (fd);
|
442
|
1484 return 0;
|
|
1485 }
|
|
1486
|
|
1487 lseek (fd, 0, SEEK_SET);
|
|
1488
|
|
1489 #ifdef HAVE_MMAP
|
456
|
1490 /* Unix 98 requires that sys/mman.h define MAP_FAILED,
|
|
1491 but many earlier implementations don't. */
|
|
1492 # ifndef MAP_FAILED
|
|
1493 # define MAP_FAILED ((void *) -1L)
|
|
1494 # endif
|
442
|
1495 pdump_start = (char *) mmap (0, pdump_length, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
|
452
|
1496 if (pdump_start != (char *) MAP_FAILED)
|
442
|
1497 {
|
|
1498 pdump_free = pdump_file_unmap;
|
771
|
1499 retry_close (fd);
|
442
|
1500 return 1;
|
|
1501 }
|
456
|
1502 #endif /* HAVE_MMAP */
|
442
|
1503
|
460
|
1504 pdump_start = xnew_array (char, pdump_length);
|
442
|
1505 pdump_free = pdump_file_free;
|
771
|
1506 retry_read (fd, pdump_start, pdump_length);
|
442
|
1507
|
771
|
1508 retry_close (fd);
|
442
|
1509 return 1;
|
|
1510 }
|
2015
|
1511
|
|
1512 static int
|
|
1513 pdump_ram_try (void)
|
|
1514 {
|
|
1515 pdump_start = dumped_data_get();
|
|
1516 pdump_length = dumped_data_size();
|
|
1517
|
|
1518 return pdump_load_check();
|
|
1519 }
|
|
1520
|
442
|
1521 #endif /* !WIN32_NATIVE */
|
|
1522
|
|
1523
|
452
|
1524 static int
|
|
1525 pdump_file_try (char *exe_path)
|
442
|
1526 {
|
460
|
1527 char *w = exe_path + strlen (exe_path);
|
442
|
1528
|
|
1529 do
|
|
1530 {
|
|
1531 sprintf (w, "-%s-%08x.dmp", EMACS_VERSION, dump_id);
|
|
1532 if (pdump_file_get (exe_path))
|
|
1533 {
|
|
1534 if (pdump_load_check ())
|
|
1535 return 1;
|
452
|
1536 pdump_free ();
|
442
|
1537 }
|
|
1538
|
|
1539 sprintf (w, "-%08x.dmp", dump_id);
|
|
1540 if (pdump_file_get (exe_path))
|
|
1541 {
|
|
1542 if (pdump_load_check ())
|
|
1543 return 1;
|
452
|
1544 pdump_free ();
|
442
|
1545 }
|
|
1546
|
|
1547 sprintf (w, ".dmp");
|
|
1548 if (pdump_file_get (exe_path))
|
|
1549 {
|
|
1550 if (pdump_load_check ())
|
|
1551 return 1;
|
452
|
1552 pdump_free ();
|
442
|
1553 }
|
|
1554
|
|
1555 do
|
|
1556 w--;
|
|
1557 while (w>exe_path && !IS_DIRECTORY_SEP (*w) && (*w != '-') && (*w != '.'));
|
|
1558 }
|
|
1559 while (w>exe_path && !IS_DIRECTORY_SEP (*w));
|
|
1560 return 0;
|
|
1561 }
|
|
1562
|
452
|
1563 int
|
771
|
1564 pdump_load (const Extbyte *argv0)
|
442
|
1565 {
|
771
|
1566 Extbyte exe_path[PATH_MAX];
|
2015
|
1567
|
442
|
1568 #ifdef WIN32_NATIVE
|
800
|
1569 GetModuleFileNameA (NULL, exe_path, PATH_MAX);
|
442
|
1570 #else /* !WIN32_NATIVE */
|
771
|
1571 Extbyte *w;
|
|
1572 const Extbyte *dir, *p;
|
442
|
1573
|
2015
|
1574 if(pdump_ram_try()) {
|
|
1575 pdump_load_finish();
|
|
1576 in_pdump = 0;
|
|
1577 return 1;
|
|
1578 }
|
|
1579
|
1204
|
1580 in_pdump = 1;
|
442
|
1581 dir = argv0;
|
|
1582 if (dir[0] == '-')
|
|
1583 {
|
|
1584 /* XEmacs as a login shell, oh goody! */
|
771
|
1585 dir = getenv ("SHELL"); /* not egetenv -- not yet initialized */
|
442
|
1586 }
|
|
1587
|
452
|
1588 p = dir + strlen (dir);
|
442
|
1589 while (p != dir && !IS_ANY_SEP (p[-1])) p--;
|
|
1590
|
|
1591 if (p != dir)
|
|
1592 {
|
|
1593 /* invocation-name includes a directory component -- presumably it
|
|
1594 is relative to cwd, not $PATH */
|
|
1595 strcpy (exe_path, dir);
|
|
1596 }
|
|
1597 else
|
|
1598 {
|
771
|
1599 const Extbyte *path = getenv ("PATH"); /* not egetenv -- not yet init. */
|
|
1600 const Extbyte *name = p;
|
442
|
1601 for (;;)
|
|
1602 {
|
|
1603 p = path;
|
|
1604 while (*p && *p != SEPCHAR)
|
|
1605 p++;
|
|
1606 if (p == path)
|
|
1607 {
|
|
1608 exe_path[0] = '.';
|
|
1609 w = exe_path + 1;
|
|
1610 }
|
|
1611 else
|
|
1612 {
|
|
1613 memcpy (exe_path, path, p - path);
|
|
1614 w = exe_path + (p - path);
|
|
1615 }
|
|
1616 if (!IS_DIRECTORY_SEP (w[-1]))
|
|
1617 {
|
|
1618 *w++ = '/';
|
|
1619 }
|
452
|
1620 strcpy (w, name);
|
442
|
1621
|
1466
|
1622 #undef access /* avoid !@#$%^& encapsulated access */
|
|
1623 #undef stat /* avoid !@#$%^& encapsulated stat */
|
|
1624
|
|
1625 {
|
|
1626 struct stat statbuf;
|
|
1627 if (access (exe_path, X_OK) == 0
|
|
1628 && stat (exe_path, &statbuf) == 0
|
|
1629 && ! S_ISDIR (statbuf.st_mode))
|
|
1630 break;
|
|
1631 }
|
|
1632
|
442
|
1633 if (!*p)
|
|
1634 {
|
|
1635 /* Oh well, let's have some kind of default */
|
|
1636 sprintf (exe_path, "./%s", name);
|
|
1637 break;
|
|
1638 }
|
|
1639 path = p+1;
|
|
1640 }
|
|
1641 }
|
|
1642 #endif /* WIN32_NATIVE */
|
|
1643
|
|
1644 if (pdump_file_try (exe_path))
|
|
1645 {
|
|
1646 pdump_load_finish ();
|
1204
|
1647 in_pdump = 0;
|
442
|
1648 return 1;
|
|
1649 }
|
|
1650
|
|
1651 #ifdef WIN32_NATIVE
|
|
1652 if (pdump_resource_get ())
|
|
1653 {
|
|
1654 if (pdump_load_check ())
|
|
1655 {
|
|
1656 pdump_load_finish ();
|
1204
|
1657 in_pdump = 0;
|
442
|
1658 return 1;
|
|
1659 }
|
|
1660 pdump_free ();
|
|
1661 }
|
|
1662 #endif
|
|
1663
|
1204
|
1664 in_pdump = 0;
|
442
|
1665 return 0;
|
|
1666 }
|