annotate src/dumper.c @ 2039:fd0cbe945410

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