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