613
|
1 /* unexec for XEmacs on Cygwin32.
|
428
|
2 Copyright (C) 1994, 1998 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to the Free
|
|
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
19 02111-1307, USA.
|
|
20
|
|
21 */
|
|
22
|
|
23 /* This is a complete rewrite, some code snarfed from unexnt.c and
|
|
24 unexec.c, Andy Piper (andy@xemacs.org) 13-1-98 */
|
|
25
|
448
|
26 #include <config.h>
|
|
27 #include "lisp.h"
|
|
28
|
428
|
29 #include "sysfile.h"
|
442
|
30
|
546
|
31 #define PERROR(arg) \
|
|
32 do { \
|
|
33 perror (arg); \
|
|
34 exit (-1); \
|
|
35 } while (0)
|
428
|
36
|
546
|
37 #if !defined (HAVE_A_OUT_H) && !defined (WIN32_NATIVE)
|
428
|
38 unexec (char *, char *, void *, void *, void *)
|
|
39 {
|
647
|
40 PERROR ("cannot unexec() a.out.h not installed");
|
428
|
41 }
|
|
42 #else
|
|
43
|
546
|
44 #ifdef MINGW
|
|
45 #include <../../include/a.out.h>
|
|
46 #else
|
428
|
47 #include <a.out.h>
|
546
|
48 #endif
|
428
|
49
|
|
50 #define ALLOC_UNIT 0xFFFF
|
647
|
51 #define ALLOC_MASK ~((unsigned long) (ALLOC_UNIT))
|
428
|
52 #define ALIGN_ALLOC(addr) \
|
647
|
53 ((((unsigned long) addr) + ALLOC_UNIT) & ALLOC_MASK)
|
444
|
54 /* Note that all sections must be aligned on a 0x1000 boundary so
|
|
55 this is the minimum size that our dummy bss can be. */
|
448
|
56 #ifndef NO_DEBUG
|
444
|
57 #define BSS_PAD_SIZE 0x1000
|
446
|
58 #else
|
|
59 #define BSS_PAD_SIZE 0
|
|
60 #endif
|
428
|
61
|
|
62 /* To prevent zero-initialized variables from being placed into the bss
|
|
63 section, use non-zero values to represent an uninitialized state. */
|
|
64 #define UNINIT_PTR ((void *) 0xF0A0F0A0)
|
|
65 #define UNINIT_LONG (0xF0A0F0A0L)
|
|
66
|
|
67 static void get_section_info (int a_out, char* a_name);
|
|
68 static void copy_executable_and_dump_data_section (int a_out, int a_new);
|
647
|
69 static void dup_file_area (int a_out, int a_new, long size);
|
428
|
70 #if 0
|
647
|
71 static void write_int_to_bss (int a_out, int a_new, void* va, void* newval);
|
428
|
72 #endif
|
|
73
|
|
74 /* Cached info about the .data section in the executable. */
|
647
|
75 void *data_start_va = UNINIT_PTR;
|
|
76 long data_size = UNINIT_LONG;
|
428
|
77
|
|
78 /* Cached info about the .bss section in the executable. */
|
647
|
79 void *bss_start = UNINIT_PTR;
|
|
80 long bss_size = UNINIT_LONG;
|
428
|
81 int sections_reversed = 0;
|
|
82 FILHDR f_hdr;
|
|
83 PEAOUTHDR f_ohdr;
|
|
84 SCNHDR f_data, f_bss, f_text, f_nextdata;
|
|
85
|
647
|
86 #define CHECK_AOUT_POS(a) \
|
|
87 do { \
|
|
88 if (lseek (a_out, 0, SEEK_CUR) != a) \
|
|
89 { \
|
|
90 printf ("we are at %lx, should be at %lx\n", \
|
|
91 lseek (a_out, 0, SEEK_CUR), a); \
|
|
92 exit (-1); \
|
|
93 } \
|
|
94 } while (0)
|
428
|
95
|
|
96 /* Dump out .data and .bss sections into a new executable. */
|
448
|
97 int
|
|
98 unexec (char *out_name, char *in_name, uintptr_t start_data,
|
|
99 uintptr_t d1, uintptr_t d2)
|
428
|
100 {
|
|
101 /* ugly nt hack - should be in lisp */
|
|
102 int a_new, a_out = -1;
|
558
|
103 char new_name[PATH_MAX], a_name[PATH_MAX];
|
428
|
104 char *ptr;
|
|
105
|
|
106 /* Make sure that the input and output filenames have the
|
|
107 ".exe" extension...patch them up if they don't. */
|
|
108 strcpy (a_name, in_name);
|
|
109 ptr = a_name + strlen (a_name) - 4;
|
|
110 if (strcmp (ptr, ".exe"))
|
|
111 strcat (a_name, ".exe");
|
|
112
|
|
113 strcpy (new_name, out_name);
|
|
114 ptr = new_name + strlen (new_name) - 4;
|
|
115 if (strcmp (ptr, ".exe"))
|
|
116 strcat (new_name, ".exe");
|
|
117
|
|
118 /* We need to round off our heap to NT's allocation unit (64KB). */
|
|
119 /* round_heap (get_allocation_unit ()); */
|
|
120
|
|
121 if (a_name && (a_out = open (a_name, O_RDONLY | OPEN_BINARY)) < 0)
|
558
|
122 PERROR (a_name);
|
428
|
123
|
|
124 if ((a_new = open (new_name, O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
|
446
|
125 0755)) < 0)
|
558
|
126 PERROR (new_name);
|
428
|
127
|
|
128 /* Get the interesting section info, like start and size of .bss... */
|
|
129 get_section_info (a_out, a_name);
|
|
130
|
|
131 copy_executable_and_dump_data_section (a_out, a_new);
|
|
132
|
647
|
133 close (a_out);
|
|
134 close (a_new);
|
448
|
135 return 0;
|
428
|
136 }
|
|
137
|
|
138 /* Flip through the executable and cache the info necessary for dumping. */
|
558
|
139 static void
|
|
140 get_section_info (int a_out, char* a_name)
|
428
|
141 {
|
448
|
142 extern char my_ebss[];
|
428
|
143 /* From lastfile.c */
|
|
144 extern char my_edata[];
|
|
145
|
|
146 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
|
558
|
147 PERROR (a_name);
|
428
|
148
|
|
149 if (f_hdr.e_magic != DOSMAGIC)
|
647
|
150 PERROR ("unknown exe header");
|
428
|
151
|
|
152 /* Check the NT header signature ... */
|
|
153 if (f_hdr.nt_signature != NT_SIGNATURE)
|
647
|
154 PERROR ("invalid nt header");
|
428
|
155
|
|
156 /* Flip through the sections for .data and .bss ... */
|
|
157 if (f_hdr.f_opthdr > 0)
|
|
158 {
|
|
159 if (read (a_out, &f_ohdr, AOUTSZ) != AOUTSZ)
|
558
|
160 PERROR (a_name);
|
428
|
161 }
|
|
162 /* Loop through .data & .bss section headers, copying them in.
|
|
163 With newer lds these are reversed so we have to cope with both */
|
|
164 lseek (a_out, sizeof (f_hdr) + f_hdr.f_opthdr, 0);
|
|
165
|
|
166 if (read (a_out, &f_text, sizeof (f_text)) != sizeof (f_text)
|
558
|
167 || strcmp (f_text.s_name, ".text"))
|
|
168 PERROR ("no .text section");
|
428
|
169
|
|
170 /* The .bss section. */
|
|
171 if (read (a_out, &f_bss, sizeof (f_bss)) != sizeof (f_bss)
|
558
|
172 || (strcmp (f_bss.s_name, ".bss") && strcmp (f_bss.s_name, ".data")))
|
|
173 PERROR ("no .bss / .data section");
|
428
|
174
|
|
175 /* check for reversed .bss and .data */
|
647
|
176 if (!strcmp (f_bss.s_name, ".data"))
|
428
|
177 {
|
647
|
178 printf (".data and .bss reversed\n");
|
428
|
179 sections_reversed = 1;
|
647
|
180 memcpy (&f_data, &f_bss, sizeof (f_bss));
|
428
|
181 }
|
|
182
|
|
183 /* The .data section. */
|
|
184 if (!sections_reversed)
|
|
185 {
|
|
186 if (read (a_out, &f_data, sizeof (f_data)) != sizeof (f_data)
|
558
|
187 || strcmp (f_data.s_name, ".data"))
|
|
188 PERROR ("no .data section");
|
428
|
189 }
|
|
190 else
|
|
191 {
|
|
192 if (read (a_out, &f_bss, sizeof (f_bss)) != sizeof (f_bss)
|
558
|
193 || strcmp (f_bss.s_name, ".bss"))
|
|
194 PERROR ("no .bss section");
|
428
|
195 }
|
|
196
|
|
197 bss_start = (void *) ((char*)f_ohdr.ImageBase + f_bss.s_vaddr);
|
|
198 bss_size = (unsigned long)((char*)&my_ebss-(char*)bss_start);
|
|
199
|
|
200 /* must keep bss data that we want to be blank as blank */
|
647
|
201 printf ("found bss - keeping %lx of %lx bytes\n", bss_size, f_ohdr.bsize);
|
428
|
202
|
|
203 /* The .data section. */
|
|
204 data_start_va = (void *) ((char*)f_ohdr.ImageBase + f_data.s_vaddr);
|
|
205
|
|
206 /* We want to only write Emacs data back to the executable,
|
|
207 not any of the library data (if library data is included,
|
|
208 then a dumped Emacs won't run on system versions other
|
|
209 than the one Emacs was dumped on). */
|
|
210 data_size = (unsigned long)my_edata - (unsigned long)data_start_va;
|
647
|
211 printf ("found data - keeping %lx of %lx bytes\n", data_size, f_ohdr.dsize);
|
428
|
212
|
|
213 /* The following data section - often .idata */
|
|
214 if (read (a_out, &f_nextdata, sizeof (f_nextdata)) != sizeof (f_nextdata)
|
647
|
215 && strcmp (&f_nextdata.s_name[2], "data"))
|
558
|
216 PERROR ("no other data section");
|
428
|
217 }
|
|
218
|
|
219 /* The dump routines. */
|
|
220
|
|
221 static void
|
|
222 copy_executable_and_dump_data_section (int a_out, int a_new)
|
|
223 {
|
647
|
224 long size = 0;
|
|
225 /* NOTE: Some of these were previously declared as unsigned long,
|
|
226 but the ones changed to long represent file sizes or pointers,
|
|
227 which can't reasonably get above 2G. (A 2G executable???)
|
|
228 Furthermore, some were even being compared as in if (x < 0) ... */
|
|
229 long new_data_size, new_bss_size, bss_padding, file_sz_change;
|
|
230 long data_padding = 0;
|
|
231 long f_data_s_scnptr = f_data.s_scnptr;
|
|
232 long f_nextdata_s_scnptr = f_nextdata.s_scnptr;
|
|
233 unsigned long f_data_s_vaddr = f_data.s_vaddr;
|
|
234 unsigned long f_bss_s_vaddr = f_bss.s_vaddr;
|
428
|
235
|
|
236 int i;
|
|
237 void* empty_space;
|
|
238 extern int static_heap_dumped;
|
|
239 SCNHDR section;
|
444
|
240 /* calculate new sizes:
|
558
|
241
|
444
|
242 f_ohdr.dsize is the total initialized data size on disk which is
|
|
243 f_data.s_size + f_idata.s_size.
|
558
|
244
|
444
|
245 f_ohdr.data_start is the base addres of all data and so should
|
|
246 not be changed.
|
|
247
|
|
248 *.s_vaddr is the virtual address of the start of the section
|
|
249 *normalized from f_ohdr.ImageBase.
|
558
|
250
|
444
|
251 *.s_paddr appears to be the number of bytes in the section
|
|
252 *actually used (whereas *.s_size is aligned).
|
558
|
253
|
428
|
254 bsize is now 0 since subsumed into .data
|
|
255 dsize is dsize + (f_data.s_vaddr - f_bss.s_vaddr)
|
|
256 f_data.s_vaddr is f_bss.s_vaddr
|
|
257 f_data.s_size is new dsize maybe.
|
|
258 what about s_paddr & s_scnptr? */
|
|
259
|
|
260 /* this is the amount the file increases in size */
|
|
261 if (!sections_reversed)
|
|
262 {
|
|
263 new_bss_size = f_data.s_vaddr - f_bss.s_vaddr;
|
|
264 data_padding = 0;
|
|
265 }
|
|
266 else
|
|
267 {
|
|
268 new_bss_size = f_nextdata.s_vaddr - f_bss.s_vaddr;
|
|
269 data_padding = (f_bss.s_vaddr - f_data.s_vaddr) - f_data.s_size;
|
|
270 }
|
|
271
|
448
|
272 if ((new_bss_size - bss_size) < BSS_PAD_SIZE)
|
558
|
273 PERROR (".bss free space too small");
|
448
|
274
|
647
|
275 file_sz_change = (new_bss_size + data_padding) - BSS_PAD_SIZE;
|
|
276 new_data_size = f_ohdr.dsize + file_sz_change;
|
428
|
277
|
|
278 if (!sections_reversed)
|
558
|
279 f_data.s_vaddr = f_bss.s_vaddr;
|
428
|
280 f_data.s_paddr += file_sz_change;
|
|
281 #if 0
|
|
282 if (f_data.s_size + f_nextdata.s_size != f_ohdr.dsize)
|
647
|
283 printf ("section size doesn't tally with dsize %lx != %lx\n",
|
558
|
284 f_data.s_size + f_nextdata.s_size, f_ohdr.dsize);
|
428
|
285 #endif
|
|
286 f_data.s_size += file_sz_change;
|
|
287 lseek (a_new, 0, SEEK_SET);
|
|
288 /* write file header */
|
|
289 f_hdr.f_symptr += file_sz_change;
|
448
|
290 #ifdef NO_DEBUG
|
446
|
291 f_hdr.f_nscns--;
|
|
292 #endif
|
444
|
293
|
647
|
294 printf ("writing file header\n");
|
|
295 if (write (a_new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
|
|
296 PERROR ("failed to write file header");
|
428
|
297 /* write optional header fixing dsize & bsize*/
|
647
|
298 printf ("writing optional header\n");
|
|
299 printf ("new data size is %lx, >= %lx\n", new_data_size,
|
428
|
300 f_ohdr.dsize + f_ohdr.bsize);
|
647
|
301 if (new_data_size < (long) (f_ohdr.dsize + f_ohdr.bsize))
|
|
302 printf ("warning: new data size is < approx\n");
|
428
|
303 f_ohdr.dsize=new_data_size;
|
444
|
304 f_ohdr.bsize=BSS_PAD_SIZE;
|
647
|
305 if (write (a_new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
|
|
306 PERROR ("failed to write optional header");
|
428
|
307 /* write text as is */
|
647
|
308 printf ("writing text header (unchanged)\n");
|
428
|
309
|
647
|
310 if (write (a_new, &f_text, sizeof (f_text)) != sizeof (f_text))
|
|
311 PERROR ("failed to write text header");
|
448
|
312 #ifndef NO_DEBUG
|
444
|
313 /* Write small bss section. */
|
|
314 if (!sections_reversed)
|
|
315 {
|
|
316 f_bss.s_size = BSS_PAD_SIZE;
|
|
317 f_bss.s_paddr = BSS_PAD_SIZE;
|
|
318 f_bss.s_vaddr = f_data.s_vaddr - BSS_PAD_SIZE;
|
647
|
319 if (write (a_new, &f_bss, sizeof (f_bss)) != sizeof (f_bss))
|
|
320 PERROR ("failed to write bss header");
|
444
|
321 }
|
446
|
322 #endif
|
428
|
323 /* write new data header */
|
647
|
324 printf ("writing .data header\n");
|
428
|
325
|
647
|
326 if (write (a_new, &f_data, sizeof (f_data)) != sizeof (f_data))
|
|
327 PERROR ("failed to write data header");
|
448
|
328 #ifndef NO_DEBUG
|
444
|
329 /* Write small bss section. */
|
|
330 if (sections_reversed)
|
|
331 {
|
|
332 f_bss.s_size = BSS_PAD_SIZE;
|
|
333 f_bss.s_paddr = BSS_PAD_SIZE;
|
|
334 f_bss.s_vaddr = f_nextdata.s_vaddr - BSS_PAD_SIZE;
|
647
|
335 if (write (a_new, &f_bss, sizeof (f_bss)) != sizeof (f_bss))
|
|
336 PERROR ("failed to write bss header");
|
444
|
337 }
|
446
|
338 #endif
|
647
|
339 printf ("writing following data header\n");
|
428
|
340 f_nextdata.s_scnptr += file_sz_change;
|
|
341 if (f_nextdata.s_lnnoptr != 0) f_nextdata.s_lnnoptr += file_sz_change;
|
|
342 if (f_nextdata.s_relptr != 0) f_nextdata.s_relptr += file_sz_change;
|
647
|
343 if (write (a_new, &f_nextdata, sizeof (f_nextdata)) != sizeof (f_nextdata))
|
|
344 PERROR ("failed to write nextdata header");
|
428
|
345
|
|
346 /* copy other section headers adjusting the file offset */
|
|
347 for (i=0; i<(f_hdr.f_nscns-3); i++)
|
|
348 {
|
|
349 if (read (a_out, §ion, sizeof (section)) != sizeof (section))
|
558
|
350 PERROR ("no .data section");
|
428
|
351
|
|
352 section.s_scnptr += file_sz_change;
|
|
353 if (section.s_lnnoptr != 0) section.s_lnnoptr += file_sz_change;
|
|
354 if (section.s_relptr != 0) section.s_relptr += file_sz_change;
|
|
355
|
647
|
356 if (write (a_new, §ion, sizeof (section)) != sizeof (section))
|
|
357 PERROR ("failed to write data header");
|
428
|
358 }
|
448
|
359 #ifdef NO_DEBUG
|
446
|
360 /* dump bss to maintain offsets */
|
647
|
361 memset (&f_bss, 0, sizeof (f_bss));
|
|
362 if (write (a_new, &f_bss, sizeof (f_bss)) != sizeof (f_bss))
|
|
363 PERROR ("failed to write bss header");
|
446
|
364 #endif
|
647
|
365 size = lseek (a_new, 0, SEEK_CUR);
|
|
366 CHECK_AOUT_POS (size);
|
428
|
367
|
|
368 /* copy eveything else until start of data */
|
|
369 size = f_data_s_scnptr - lseek (a_out, 0, SEEK_CUR);
|
|
370
|
|
371 printf ("copying executable up to data section ... %lx bytes\n",
|
|
372 size);
|
647
|
373 dup_file_area (a_out, a_new, size);
|
428
|
374
|
647
|
375 CHECK_AOUT_POS (f_data_s_scnptr);
|
428
|
376
|
|
377 if (!sections_reversed)
|
|
378 {
|
444
|
379 /* dump bss + padding between sections, sans small bss pad */
|
428
|
380 printf ("dumping .bss into executable... %lx bytes\n", bss_size);
|
647
|
381 if (write (a_new, bss_start, bss_size) != bss_size)
|
428
|
382 {
|
647
|
383 PERROR ("failed to write bss section");
|
428
|
384 }
|
|
385
|
|
386 /* pad, needs to be zero */
|
444
|
387 bss_padding = (new_bss_size - bss_size) - BSS_PAD_SIZE;
|
|
388 if (bss_padding < 0)
|
647
|
389 PERROR ("padded .bss too small");
|
428
|
390 printf ("padding .bss ... %lx bytes\n", bss_padding);
|
647
|
391 empty_space = malloc (bss_padding);
|
|
392 memset (empty_space, 0, bss_padding);
|
|
393 if (write (a_new, empty_space, bss_padding) != bss_padding)
|
|
394 PERROR ("failed to write bss section");
|
|
395 free (empty_space);
|
428
|
396 }
|
|
397
|
|
398 /* tell dumped version not to free pure heap */
|
|
399 static_heap_dumped = 1;
|
|
400 /* Get a pointer to the raw data in our address space. */
|
|
401 printf ("dumping .data section... %lx bytes\n", data_size);
|
647
|
402 if (write (a_new, data_start_va, data_size) != data_size)
|
|
403 PERROR ("failed to write data section");
|
428
|
404 /* were going to use free again ... */
|
|
405 static_heap_dumped = 0;
|
|
406
|
647
|
407 size = lseek (a_out, f_data_s_scnptr + data_size, SEEK_SET);
|
428
|
408
|
|
409 if (!sections_reversed)
|
|
410 {
|
|
411 size = f_nextdata_s_scnptr - size;
|
647
|
412 dup_file_area (a_out, a_new, size);
|
428
|
413 }
|
|
414 else
|
|
415 {
|
444
|
416 /* need to pad to bss with data in file */
|
428
|
417 printf ("padding .data ... %lx bytes\n", data_padding);
|
|
418 size = (f_bss_s_vaddr - f_data_s_vaddr) - data_size;
|
647
|
419 dup_file_area (a_out, a_new, size);
|
428
|
420
|
|
421 /* dump bss + padding between sections */
|
|
422 printf ("dumping .bss into executable... %lx bytes\n", bss_size);
|
647
|
423 if (write (a_new, bss_start, bss_size) != bss_size)
|
|
424 PERROR ("failed to write bss section");
|
428
|
425
|
|
426 /* pad, needs to be zero */
|
444
|
427 bss_padding = (new_bss_size - bss_size) - BSS_PAD_SIZE;
|
|
428 if (bss_padding < 0)
|
647
|
429 PERROR ("padded .bss too small");
|
428
|
430 printf ("padding .bss ... %lx bytes\n", bss_padding);
|
647
|
431 empty_space = malloc (bss_padding);
|
|
432 memset (empty_space, 0, bss_padding);
|
|
433 if (write (a_new, empty_space, bss_padding) != bss_padding)
|
|
434 PERROR ("failed to write bss section");
|
|
435 free (empty_space);
|
|
436 if (lseek (a_new, 0, SEEK_CUR) != (long) f_nextdata.s_scnptr)
|
428
|
437 {
|
647
|
438 printf ("at %lx should be at %lx\n",
|
|
439 lseek (a_new, 0, SEEK_CUR),
|
428
|
440 f_nextdata.s_scnptr);
|
647
|
441 PERROR ("file positioning error\n");
|
428
|
442 }
|
647
|
443 lseek (a_out, f_nextdata_s_scnptr, SEEK_SET);
|
428
|
444 }
|
|
445
|
647
|
446 CHECK_AOUT_POS (f_nextdata_s_scnptr);
|
428
|
447
|
|
448 /* now dump - nextdata don't need to do this cygwin ds is in .data! */
|
|
449 printf ("dumping following data section... %lx bytes\n", f_nextdata.s_size);
|
|
450
|
647
|
451 dup_file_area (a_out,a_new,f_nextdata.s_size);
|
428
|
452
|
|
453 /* write rest of file */
|
|
454 printf ("writing rest of file\n");
|
647
|
455 size = lseek (a_out, 0, SEEK_END);
|
428
|
456 size = size - (f_nextdata_s_scnptr + f_nextdata.s_size); /* length remaining in a_out */
|
647
|
457 lseek (a_out, f_nextdata_s_scnptr + f_nextdata.s_size, SEEK_SET);
|
428
|
458
|
647
|
459 dup_file_area (a_out, a_new, size);
|
428
|
460 }
|
|
461
|
|
462 /*
|
|
463 * copy from aout to anew
|
|
464 */
|
647
|
465 static void
|
|
466 dup_file_area (int a_out, int a_new, long size)
|
428
|
467 {
|
|
468 char page[BUFSIZ];
|
|
469 long n;
|
|
470 for (; size > 0; size -= sizeof (page))
|
|
471 {
|
647
|
472 n = size > (long) sizeof (page) ? sizeof (page) : size;
|
428
|
473 if (read (a_out, page, n) != n || write (a_new, page, n) != n)
|
558
|
474 PERROR ("dump_out()");
|
428
|
475 }
|
|
476 }
|
|
477
|
|
478 #if 0
|
647
|
479 static void
|
|
480 write_int_to_bss (int a_out, int a_new, void* va, void* newval)
|
428
|
481 {
|
|
482 int cpos;
|
|
483
|
647
|
484 cpos = lseek (a_new, 0, SEEK_CUR);
|
428
|
485 if (va < bss_start || va > bss_start + f_data.s_size)
|
647
|
486 PERROR ("address not in data space\n");
|
|
487 lseek (a_new, f_data.s_scnptr + ((unsigned long)va -
|
428
|
488 (unsigned long)bss_start), SEEK_SET);
|
647
|
489 if (write (a_new, newval, sizeof (int)) != (int) sizeof (int))
|
|
490 PERROR ("failed to write int value");
|
|
491 lseek (a_new, cpos, SEEK_SET);
|
428
|
492 }
|
|
493 #endif
|
|
494
|
|
495 #endif /* HAVE_A_OUT_H */
|