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