Mercurial > hg > xemacs-beta
comparison src/unexcw.c @ 448:3078fd1074e8 r21-2-39
Import from CVS: tag r21-2-39
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:38:25 +0200 |
parents | 1ccc32a20af4 |
children | 0784d089fdc9 |
comparison
equal
deleted
inserted
replaced
447:4fc5f13f3bd3 | 448:3078fd1074e8 |
---|---|
21 */ | 21 */ |
22 | 22 |
23 /* This is a complete rewrite, some code snarfed from unexnt.c and | 23 /* This is a complete rewrite, some code snarfed from unexnt.c and |
24 unexec.c, Andy Piper (andy@xemacs.org) 13-1-98 */ | 24 unexec.c, Andy Piper (andy@xemacs.org) 13-1-98 */ |
25 | 25 |
26 #include <config.h> | |
27 #include "lisp.h" | |
28 | |
26 #include <stdio.h> | 29 #include <stdio.h> |
27 #include <stdlib.h> | 30 #include <stdlib.h> |
28 #include <unistd.h> | 31 #include <unistd.h> |
29 #include <fcntl.h> | 32 #include <fcntl.h> |
30 #include <config.h> | |
31 #include <string.h> | 33 #include <string.h> |
32 | 34 |
33 #define DONT_ENCAPSULATE /* filenames are external in unex*.c */ | 35 #define DONT_ENCAPSULATE /* filenames are external in unex*.c */ |
34 #include "sysfile.h" | 36 #include "sysfile.h" |
35 | 37 |
51 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT)) | 53 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT)) |
52 #define ALIGN_ALLOC(addr) \ | 54 #define ALIGN_ALLOC(addr) \ |
53 ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK) | 55 ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK) |
54 /* Note that all sections must be aligned on a 0x1000 boundary so | 56 /* Note that all sections must be aligned on a 0x1000 boundary so |
55 this is the minimum size that our dummy bss can be. */ | 57 this is the minimum size that our dummy bss can be. */ |
56 #ifdef BROKEN_GDB | 58 #ifndef NO_DEBUG |
57 #define BSS_PAD_SIZE 0x1000 | 59 #define BSS_PAD_SIZE 0x1000 |
58 #else | 60 #else |
59 #define BSS_PAD_SIZE 0 | 61 #define BSS_PAD_SIZE 0 |
60 #endif | 62 #endif |
61 | 63 |
90 printf("we are at %lx, should be at %lx\n", \ | 92 printf("we are at %lx, should be at %lx\n", \ |
91 lseek(a_out, 0, SEEK_CUR), a); \ | 93 lseek(a_out, 0, SEEK_CUR), a); \ |
92 exit(-1); \ | 94 exit(-1); \ |
93 } | 95 } |
94 | 96 |
95 void | |
96 unexec (char *out_name, char *in_name, void *start_data, | |
97 void * d1, void * d2); | |
98 /* Dump out .data and .bss sections into a new executable. */ | 97 /* Dump out .data and .bss sections into a new executable. */ |
99 void unexec (char *out_name, char *in_name, void *start_data, | 98 int |
100 void * d1, void * d2) | 99 unexec (char *out_name, char *in_name, uintptr_t start_data, |
100 uintptr_t d1, uintptr_t d2) | |
101 { | 101 { |
102 /* ugly nt hack - should be in lisp */ | 102 /* ugly nt hack - should be in lisp */ |
103 int a_new, a_out = -1; | 103 int a_new, a_out = -1; |
104 char new_name[MAX_PATH], a_name[MAX_PATH]; | 104 char new_name[MAX_PATH], a_name[MAX_PATH]; |
105 char *ptr; | 105 char *ptr; |
135 | 135 |
136 copy_executable_and_dump_data_section (a_out, a_new); | 136 copy_executable_and_dump_data_section (a_out, a_new); |
137 | 137 |
138 close(a_out); | 138 close(a_out); |
139 close(a_new); | 139 close(a_new); |
140 return 0; | |
140 } | 141 } |
141 | 142 |
142 /* Flip through the executable and cache the info necessary for dumping. */ | 143 /* Flip through the executable and cache the info necessary for dumping. */ |
143 static void get_section_info (int a_out, char* a_name) | 144 static void get_section_info (int a_out, char* a_name) |
144 { | 145 { |
145 extern int my_ebss; | 146 extern char my_ebss[]; |
146 /* From lastfile.c */ | 147 /* From lastfile.c */ |
147 extern char my_edata[]; | 148 extern char my_edata[]; |
148 | 149 |
149 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) | 150 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) |
150 { | 151 { |
289 { | 290 { |
290 new_bss_size = f_nextdata.s_vaddr - f_bss.s_vaddr; | 291 new_bss_size = f_nextdata.s_vaddr - f_bss.s_vaddr; |
291 data_padding = (f_bss.s_vaddr - f_data.s_vaddr) - f_data.s_size; | 292 data_padding = (f_bss.s_vaddr - f_data.s_vaddr) - f_data.s_size; |
292 } | 293 } |
293 | 294 |
295 if ((new_bss_size - bss_size) < BSS_PAD_SIZE) | |
296 { | |
297 PERROR (".bss free space too small"); | |
298 } | |
299 | |
294 file_sz_change=(new_bss_size + data_padding) - BSS_PAD_SIZE; | 300 file_sz_change=(new_bss_size + data_padding) - BSS_PAD_SIZE; |
295 new_data_size=f_ohdr.dsize + file_sz_change; | 301 new_data_size=f_ohdr.dsize + file_sz_change; |
296 | 302 |
297 if (!sections_reversed) | 303 if (!sections_reversed) |
298 { | 304 { |
308 #endif | 314 #endif |
309 f_data.s_size += file_sz_change; | 315 f_data.s_size += file_sz_change; |
310 lseek (a_new, 0, SEEK_SET); | 316 lseek (a_new, 0, SEEK_SET); |
311 /* write file header */ | 317 /* write file header */ |
312 f_hdr.f_symptr += file_sz_change; | 318 f_hdr.f_symptr += file_sz_change; |
313 #ifndef BROKEN_GDB | 319 #ifdef NO_DEBUG |
314 f_hdr.f_nscns--; | 320 f_hdr.f_nscns--; |
315 #endif | 321 #endif |
316 | 322 |
317 printf("writing file header\n"); | 323 printf("writing file header\n"); |
318 if (write(a_new, &f_hdr, sizeof(f_hdr)) != sizeof(f_hdr)) | 324 if (write(a_new, &f_hdr, sizeof(f_hdr)) != sizeof(f_hdr)) |
338 | 344 |
339 if (write(a_new, &f_text, sizeof(f_text)) != sizeof(f_text)) | 345 if (write(a_new, &f_text, sizeof(f_text)) != sizeof(f_text)) |
340 { | 346 { |
341 PERROR("failed to write text header"); | 347 PERROR("failed to write text header"); |
342 } | 348 } |
343 #ifdef BROKEN_GDB | 349 #ifndef NO_DEBUG |
344 /* Write small bss section. */ | 350 /* Write small bss section. */ |
345 if (!sections_reversed) | 351 if (!sections_reversed) |
346 { | 352 { |
347 f_bss.s_size = BSS_PAD_SIZE; | 353 f_bss.s_size = BSS_PAD_SIZE; |
348 f_bss.s_paddr = BSS_PAD_SIZE; | 354 f_bss.s_paddr = BSS_PAD_SIZE; |
358 | 364 |
359 if (write(a_new, &f_data, sizeof(f_data)) != sizeof(f_data)) | 365 if (write(a_new, &f_data, sizeof(f_data)) != sizeof(f_data)) |
360 { | 366 { |
361 PERROR("failed to write data header"); | 367 PERROR("failed to write data header"); |
362 } | 368 } |
363 #ifdef BROKEN_GDB | 369 #ifndef NO_DEBUG |
364 /* Write small bss section. */ | 370 /* Write small bss section. */ |
365 if (sections_reversed) | 371 if (sections_reversed) |
366 { | 372 { |
367 f_bss.s_size = BSS_PAD_SIZE; | 373 f_bss.s_size = BSS_PAD_SIZE; |
368 f_bss.s_paddr = BSS_PAD_SIZE; | 374 f_bss.s_paddr = BSS_PAD_SIZE; |
397 if (write(a_new, §ion, sizeof(section)) != sizeof(section)) | 403 if (write(a_new, §ion, sizeof(section)) != sizeof(section)) |
398 { | 404 { |
399 PERROR("failed to write data header"); | 405 PERROR("failed to write data header"); |
400 } | 406 } |
401 } | 407 } |
402 #ifndef BROKEN_GDB | 408 #ifdef NO_DEBUG |
403 /* dump bss to maintain offsets */ | 409 /* dump bss to maintain offsets */ |
404 memset(&f_bss, 0, sizeof(f_bss)); | 410 memset(&f_bss, 0, sizeof(f_bss)); |
405 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss)) | 411 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss)) |
406 { | 412 { |
407 PERROR("failed to write bss header"); | 413 PERROR("failed to write bss header"); |