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