Mercurial > hg > xemacs-beta
comparison src/unexec.c @ 3025:facf3239ba30
[xemacs-hg @ 2005-10-25 11:16:19 by ben]
rename new->new_, convert 'foo to `foo'
EmacsFrame.c, ExternalClient.c, ExternalShell.c, chartab.c, cmdloop.c, compiler.h, console.c, database.c, device-msw.c, device-x.c, device.c, doc.c, dragdrop.c, eval.c, event-msw.c, event-stream.c, events.c, extents.c, file-coding.c, fns.c, frame-tty.c, frame.c, gpmevent.c, gutter.c, hash.c, imgproc.c, indent.c, keymap.c, lisp-union.h, macros.c, malloc.c, marker.c, menubar-x.c, menubar.c, mule-charset.c, number.c, process.c, profile.h, ralloc.c, redisplay.c, select-common.h, select.c, syntax.c, sysfile.h, sysproc.h, systime.h, syswindows.h, toolbar.c, tooltalk.c, tparam.c, unexaix.c, unexalpha.c, unexconvex.c, unexec.c, unexhp9k800.c, unexmips.c, unicode.c, window.c: new -> new_.
'foo -> `foo'.
lwlib-internal.h: redo assert macros to follow lisp.h and not trigger warnings.
lwlib.c, xlwtabs.c: new -> new_.
author | ben |
---|---|
date | Tue, 25 Oct 2005 11:16:49 +0000 |
parents | 04bc9d2f42c7 |
children | aa5ed11f473b |
comparison
equal
deleted
inserted
replaced
3024:b7f26b2f78bd | 3025:facf3239ba30 |
---|---|
167 #ifndef emacs | 167 #ifndef emacs |
168 #define PERROR(arg) perror (arg); return -1 | 168 #define PERROR(arg) perror (arg); return -1 |
169 #else | 169 #else |
170 #define IN_UNEXEC | 170 #define IN_UNEXEC |
171 #include <config.h> | 171 #include <config.h> |
172 #define PERROR(file) report_error (file, new) | 172 #define PERROR(file) report_error (file, new_) |
173 #endif | 173 #endif |
174 | 174 |
175 #if __STDC__ || defined(STDC_HEADERS) | 175 #if __STDC__ || defined(STDC_HEADERS) |
176 | 176 |
177 /* I don't know how correct this attempt to get more prototypes is... */ | 177 /* I don't know how correct this attempt to get more prototypes is... */ |
339 report_error_with_errno (Qio_error, "Cannot unexec", | 339 report_error_with_errno (Qio_error, "Cannot unexec", |
340 build_ext_string (file, Qfile_name)); | 340 build_ext_string (file, Qfile_name)); |
341 } | 341 } |
342 #endif /* emacs */ | 342 #endif /* emacs */ |
343 | 343 |
344 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1 | 344 #define ERROR0(msg) report_error_1 (new_, msg, 0, 0); return -1 |
345 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 | 345 #define ERROR1(msg,x) report_error_1 (new_, msg, x, 0); return -1 |
346 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 | 346 #define ERROR2(msg,x,y) report_error_1 (new_, msg, x, y); return -1 |
347 | 347 |
348 static void | 348 static void |
349 report_error_1 (fd, msg, a1, a2) | 349 report_error_1 (fd, msg, a1, a2) |
350 int fd; | 350 int fd; |
351 const char *msg; | 351 const char *msg; |
358 fprintf (stderr, msg, a1, a2); | 358 fprintf (stderr, msg, a1, a2); |
359 fprintf (stderr, "\n"); | 359 fprintf (stderr, "\n"); |
360 #endif | 360 #endif |
361 } | 361 } |
362 | 362 |
363 static int make_hdr (int new, int a_out, unsigned data_start, | 363 static int make_hdr (int new_, int a_out, unsigned data_start, |
364 unsigned bss_start, unsigned entry_address, | 364 unsigned bss_start, unsigned entry_address, |
365 char *a_name, char *new_name); | 365 char *a_name, char *new_name); |
366 static int copy_text_and_data (int new, int a_out); | 366 static int copy_text_and_data (int new_, int a_out); |
367 static int copy_sym (int new, int a_out, char *a_name, char *new_name); | 367 static int copy_sym (int new_, int a_out, char *a_name, char *new_name); |
368 static void mark_x (char *name); | 368 static void mark_x (char *name); |
369 | 369 |
370 /* **************************************************************** | 370 /* **************************************************************** |
371 * unexec | 371 * unexec |
372 * | 372 * |
375 int | 375 int |
376 unexec (new_name, a_name, data_start, bss_start, entry_address) | 376 unexec (new_name, a_name, data_start, bss_start, entry_address) |
377 char *new_name, *a_name; | 377 char *new_name, *a_name; |
378 unsigned data_start, bss_start, entry_address; | 378 unsigned data_start, bss_start, entry_address; |
379 { | 379 { |
380 int new, a_out = -1; | 380 int new_, a_out = -1; |
381 | 381 |
382 if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) | 382 if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) |
383 { | 383 { |
384 PERROR (a_name); | 384 PERROR (a_name); |
385 } | 385 } |
386 if ((new = creat (new_name, 0666)) < 0) | 386 if ((new_ = creat (new_name, 0666)) < 0) |
387 { | 387 { |
388 PERROR (new_name); | 388 PERROR (new_name); |
389 } | 389 } |
390 | 390 |
391 if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0 | 391 if (make_hdr (new_, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0 |
392 || copy_text_and_data (new, a_out) < 0 | 392 || copy_text_and_data (new_, a_out) < 0 |
393 || copy_sym (new, a_out, a_name, new_name) < 0 | 393 || copy_sym (new_, a_out, a_name, new_name) < 0 |
394 #ifdef COFF | 394 #ifdef COFF |
395 #ifndef COFF_BSD_SYMBOLS | 395 #ifndef COFF_BSD_SYMBOLS |
396 || adjust_lnnoptrs (new, a_out, new_name) < 0 | 396 || adjust_lnnoptrs (new_, a_out, new_name) < 0 |
397 #endif | 397 #endif |
398 #endif | 398 #endif |
399 ) | 399 ) |
400 { | 400 { |
401 close (new); | 401 close (new_); |
402 /* unlink (new_name); / * Failed, unlink new a.out */ | 402 /* unlink (new_name); / * Failed, unlink new a.out */ |
403 return -1; | 403 return -1; |
404 } | 404 } |
405 | 405 |
406 close (new); | 406 close (new_); |
407 if (a_out >= 0) | 407 if (a_out >= 0) |
408 close (a_out); | 408 close (a_out); |
409 mark_x (new_name); | 409 mark_x (new_name); |
410 return 0; | 410 return 0; |
411 } | 411 } |
415 * | 415 * |
416 * Make the header in the new a.out from the header in core. | 416 * Make the header in the new a.out from the header in core. |
417 * Modify the text and data sizes. | 417 * Modify the text and data sizes. |
418 */ | 418 */ |
419 static int | 419 static int |
420 make_hdr (int new, int a_out, unsigned data_start, unsigned bss_start, | 420 make_hdr (int new_, int a_out, unsigned data_start, unsigned bss_start, |
421 unsigned entry_address, char *a_name, char *new_name) | 421 unsigned entry_address, char *a_name, char *new_name) |
422 { | 422 { |
423 #ifdef COFF | 423 #ifdef COFF |
424 auto struct scnhdr f_thdr; /* Text section header */ | 424 auto struct scnhdr f_thdr; /* Text section header */ |
425 auto struct scnhdr f_dhdr; /* Data section header */ | 425 auto struct scnhdr f_dhdr; /* Data section header */ |
616 | 616 |
617 #ifdef ADJUST_EXEC_HEADER | 617 #ifdef ADJUST_EXEC_HEADER |
618 ADJUST_EXEC_HEADER; | 618 ADJUST_EXEC_HEADER; |
619 #endif /* ADJUST_EXEC_HEADER */ | 619 #endif /* ADJUST_EXEC_HEADER */ |
620 | 620 |
621 if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) | 621 if (write (new_, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) |
622 { | 622 { |
623 PERROR (new_name); | 623 PERROR (new_name); |
624 } | 624 } |
625 | 625 |
626 if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) | 626 if (write (new_, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) |
627 { | 627 { |
628 PERROR (new_name); | 628 PERROR (new_name); |
629 } | 629 } |
630 | 630 |
631 #ifndef USG_SHARED_LIBRARIES | 631 #ifndef USG_SHARED_LIBRARIES |
632 | 632 |
633 if (write (new, &f_thdr, sizeof (f_thdr)) != sizeof (f_thdr)) | 633 if (write (new_, &f_thdr, sizeof (f_thdr)) != sizeof (f_thdr)) |
634 { | 634 { |
635 PERROR (new_name); | 635 PERROR (new_name); |
636 } | 636 } |
637 | 637 |
638 if (write (new, &f_dhdr, sizeof (f_dhdr)) != sizeof (f_dhdr)) | 638 if (write (new_, &f_dhdr, sizeof (f_dhdr)) != sizeof (f_dhdr)) |
639 { | 639 { |
640 PERROR (new_name); | 640 PERROR (new_name); |
641 } | 641 } |
642 | 642 |
643 if (write (new, &f_bhdr, sizeof (f_bhdr)) != sizeof (f_bhdr)) | 643 if (write (new_, &f_bhdr, sizeof (f_bhdr)) != sizeof (f_bhdr)) |
644 { | 644 { |
645 PERROR (new_name); | 645 PERROR (new_name); |
646 } | 646 } |
647 | 647 |
648 #else /* USG_SHARED_LIBRARIES */ | 648 #else /* USG_SHARED_LIBRARIES */ |
669 if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) | 669 if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) |
670 PERROR (a_name); | 670 PERROR (a_name); |
671 | 671 |
672 if (!strcmp (scntemp.s_name, f_thdr.s_name)) /* .text */ | 672 if (!strcmp (scntemp.s_name, f_thdr.s_name)) /* .text */ |
673 { | 673 { |
674 if (write (new, &f_thdr, sizeof (f_thdr)) != sizeof (f_thdr)) | 674 if (write (new_, &f_thdr, sizeof (f_thdr)) != sizeof (f_thdr)) |
675 PERROR (new_name); | 675 PERROR (new_name); |
676 } | 676 } |
677 else if (!strcmp (scntemp.s_name, f_dhdr.s_name)) /* .data */ | 677 else if (!strcmp (scntemp.s_name, f_dhdr.s_name)) /* .data */ |
678 { | 678 { |
679 if (write (new, &f_dhdr, sizeof (f_dhdr)) != sizeof (f_dhdr)) | 679 if (write (new_, &f_dhdr, sizeof (f_dhdr)) != sizeof (f_dhdr)) |
680 PERROR (new_name); | 680 PERROR (new_name); |
681 } | 681 } |
682 else if (!strcmp (scntemp.s_name, f_bhdr.s_name)) /* .bss */ | 682 else if (!strcmp (scntemp.s_name, f_bhdr.s_name)) /* .bss */ |
683 { | 683 { |
684 if (write (new, &f_bhdr, sizeof (f_bhdr)) != sizeof (f_bhdr)) | 684 if (write (new_, &f_bhdr, sizeof (f_bhdr)) != sizeof (f_bhdr)) |
685 PERROR (new_name); | 685 PERROR (new_name); |
686 } | 686 } |
687 else | 687 else |
688 { | 688 { |
689 if (scntemp.s_scnptr) | 689 if (scntemp.s_scnptr) |
690 scntemp.s_scnptr += bias; | 690 scntemp.s_scnptr += bias; |
691 if (write (new, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) | 691 if (write (new_, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) |
692 PERROR (new_name); | 692 PERROR (new_name); |
693 } | 693 } |
694 } | 694 } |
695 #endif /* USG_SHARED_LIBRARIES */ | 695 #endif /* USG_SHARED_LIBRARIES */ |
696 | 696 |
778 coffheader.dsize = dp->s_size; | 778 coffheader.dsize = dp->s_size; |
779 coffheader.bsize = bp->s_size; | 779 coffheader.bsize = bp->s_size; |
780 coffheader.text_start = tp->s_vaddr; | 780 coffheader.text_start = tp->s_vaddr; |
781 coffheader.data_start = dp->s_vaddr; | 781 coffheader.data_start = dp->s_vaddr; |
782 } | 782 } |
783 if (write (new, &coffheader, sizeof (coffheader)) != sizeof (coffheader)) | 783 if (write (new_, &coffheader, sizeof (coffheader)) != sizeof (coffheader)) |
784 { | 784 { |
785 PERROR(new_name); | 785 PERROR(new_name); |
786 } | 786 } |
787 #endif /* COFF_ENCAPSULATE */ | 787 #endif /* COFF_ENCAPSULATE */ |
788 | 788 |
789 if (write (new, (char *) &hdr, sizeof (hdr)) != sizeof (hdr)) | 789 if (write (new_, (char *) &hdr, sizeof (hdr)) != sizeof (hdr)) |
790 { | 790 { |
791 PERROR (new_name); | 791 PERROR (new_name); |
792 } | 792 } |
793 | 793 |
794 #if 0 /* This #ifndef caused a bug on Linux when using QMAGIC. */ | 794 #if 0 /* This #ifndef caused a bug on Linux when using QMAGIC. */ |
811 * copy_text_and_data | 811 * copy_text_and_data |
812 * | 812 * |
813 * Copy the text and data segments from memory to the new a.out | 813 * Copy the text and data segments from memory to the new a.out |
814 */ | 814 */ |
815 static int | 815 static int |
816 copy_text_and_data (int new, | 816 copy_text_and_data (int new_, |
817 #if defined (COFF) && defined (USG_SHARED_LIBRARIES) | 817 #if defined (COFF) && defined (USG_SHARED_LIBRARIES) |
818 int a_out | 818 int a_out |
819 #else | 819 #else |
820 int UNUSED (a_out) | 820 int UNUSED (a_out) |
821 #endif | 821 #endif |
848 if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) | 848 if (read (a_out, &scntemp, sizeof (scntemp)) != sizeof (scntemp)) |
849 PERROR ("temacs"); | 849 PERROR ("temacs"); |
850 | 850 |
851 if (!strcmp (scntemp.s_name, ".text")) | 851 if (!strcmp (scntemp.s_name, ".text")) |
852 { | 852 { |
853 lseek (new, (long) text_scnptr, 0); | 853 lseek (new_, (long) text_scnptr, 0); |
854 ptr = (char *) f_ohdr.text_start; | 854 ptr = (char *) f_ohdr.text_start; |
855 end = ptr + f_ohdr.tsize; | 855 end = ptr + f_ohdr.tsize; |
856 write_segment (new, ptr, end); | 856 write_segment (new_, ptr, end); |
857 } | 857 } |
858 else if (!strcmp (scntemp.s_name, ".data")) | 858 else if (!strcmp (scntemp.s_name, ".data")) |
859 { | 859 { |
860 lseek (new, (long) data_scnptr, 0); | 860 lseek (new_, (long) data_scnptr, 0); |
861 ptr = (char *) f_ohdr.data_start; | 861 ptr = (char *) f_ohdr.data_start; |
862 end = ptr + f_ohdr.dsize; | 862 end = ptr + f_ohdr.dsize; |
863 write_segment (new, ptr, end); | 863 write_segment (new_, ptr, end); |
864 } | 864 } |
865 else if (!scntemp.s_scnptr) | 865 else if (!scntemp.s_scnptr) |
866 ; /* do nothing - no data for this section */ | 866 ; /* do nothing - no data for this section */ |
867 else | 867 else |
868 { | 868 { |
872 | 872 |
873 lseek (a_out, scntemp.s_scnptr, 0); | 873 lseek (a_out, scntemp.s_scnptr, 0); |
874 for (size = scntemp.s_size; size > 0; size -= sizeof (page)) | 874 for (size = scntemp.s_size; size > 0; size -= sizeof (page)) |
875 { | 875 { |
876 n = size > sizeof (page) ? sizeof (page) : size; | 876 n = size > sizeof (page) ? sizeof (page) : size; |
877 if (read (a_out, page, n) != n || write (new, page, n) != n) | 877 if (read (a_out, page, n) != n || write (new_, page, n) != n) |
878 PERROR ("emacs"); | 878 PERROR ("emacs"); |
879 } | 879 } |
880 lseek (a_out, old_a_out_ptr, 0); | 880 lseek (a_out, old_a_out_ptr, 0); |
881 } | 881 } |
882 } | 882 } |
883 | 883 |
884 #else /* COFF, but not USG_SHARED_LIBRARIES */ | 884 #else /* COFF, but not USG_SHARED_LIBRARIES */ |
885 | 885 |
886 lseek (new, (long) text_scnptr, 0); | 886 lseek (new_, (long) text_scnptr, 0); |
887 ptr = (char *) f_ohdr.text_start; | 887 ptr = (char *) f_ohdr.text_start; |
888 #ifdef HEADER_INCL_IN_TEXT | 888 #ifdef HEADER_INCL_IN_TEXT |
889 /* For Gould UTX/32, text starts after headers */ | 889 /* For Gould UTX/32, text starts after headers */ |
890 ptr = (char *) (ptr + text_scnptr); | 890 ptr = (char *) (ptr + text_scnptr); |
891 #endif /* HEADER_INCL_IN_TEXT */ | 891 #endif /* HEADER_INCL_IN_TEXT */ |
892 end = ptr + f_ohdr.tsize; | 892 end = ptr + f_ohdr.tsize; |
893 write_segment (new, ptr, end); | 893 write_segment (new_, ptr, end); |
894 | 894 |
895 lseek (new, (long) data_scnptr, 0); | 895 lseek (new_, (long) data_scnptr, 0); |
896 ptr = (char *) f_ohdr.data_start; | 896 ptr = (char *) f_ohdr.data_start; |
897 end = ptr + f_ohdr.dsize; | 897 end = ptr + f_ohdr.dsize; |
898 write_segment (new, ptr, end); | 898 write_segment (new_, ptr, end); |
899 | 899 |
900 #endif /* USG_SHARED_LIBRARIES */ | 900 #endif /* USG_SHARED_LIBRARIES */ |
901 | 901 |
902 #else /* if not COFF */ | 902 #else /* if not COFF */ |
903 | 903 |
908 We must adjust the seek to the place after the header. | 908 We must adjust the seek to the place after the header. |
909 Note that at this point hdr.a_text does *not* count | 909 Note that at this point hdr.a_text does *not* count |
910 the extra A_TEXT_OFFSET bytes, only the actual bytes of code. */ | 910 the extra A_TEXT_OFFSET bytes, only the actual bytes of code. */ |
911 | 911 |
912 #ifdef A_TEXT_SEEK | 912 #ifdef A_TEXT_SEEK |
913 lseek (new, (long) A_TEXT_SEEK (hdr), 0); | 913 lseek (new_, (long) A_TEXT_SEEK (hdr), 0); |
914 #else | 914 #else |
915 lseek (new, (long) N_TXTOFF (hdr), 0); | 915 lseek (new_, (long) N_TXTOFF (hdr), 0); |
916 #endif /* no A_TEXT_SEEK */ | 916 #endif /* no A_TEXT_SEEK */ |
917 | 917 |
918 #ifdef RISCiX | 918 #ifdef RISCiX |
919 | 919 |
920 /* Acorn's RISC-iX has a wacky way of initializing the position of the heap. | 920 /* Acorn's RISC-iX has a wacky way of initializing the position of the heap. |
978 #define EDATA_OFFSET 0x30 | 978 #define EDATA_OFFSET 0x30 |
979 #endif | 979 #endif |
980 | 980 |
981 end = ptr + mcount_offset - EDATA_OFFSET; | 981 end = ptr + mcount_offset - EDATA_OFFSET; |
982 | 982 |
983 write_segment (new, ptr, end); | 983 write_segment (new_, ptr, end); |
984 | 984 |
985 proforma[0] = bss_end; /* becomes _edata */ | 985 proforma[0] = bss_end; /* becomes _edata */ |
986 proforma[1] = bss_end; /* becomes _end */ | 986 proforma[1] = bss_end; /* becomes _end */ |
987 proforma[2] = bss_end; /* becomes _minbrk */ | 987 proforma[2] = bss_end; /* becomes _minbrk */ |
988 proforma[3] = bss_end; /* becomes _curbrk */ | 988 proforma[3] = bss_end; /* becomes _curbrk */ |
989 | 989 |
990 write (new, proforma, 16); | 990 write (new_, proforma, 16); |
991 | 991 |
992 temp_ptr = ptr; | 992 temp_ptr = ptr; |
993 ptr = end + 16; | 993 ptr = end + 16; |
994 end = temp_ptr + hdr.a_text; | 994 end = temp_ptr + hdr.a_text; |
995 | 995 |
996 write_segment (new, ptr, end); | 996 write_segment (new_, ptr, end); |
997 } | 997 } |
998 | 998 |
999 #else /* !RISCiX */ | 999 #else /* !RISCiX */ |
1000 ptr = (char *) unexec_text_start; | 1000 ptr = (char *) unexec_text_start; |
1001 end = ptr + hdr.a_text; | 1001 end = ptr + hdr.a_text; |
1002 write_segment (new, ptr, end); | 1002 write_segment (new_, ptr, end); |
1003 #endif /* RISCiX */ | 1003 #endif /* RISCiX */ |
1004 | 1004 |
1005 ptr = (char *) unexec_data_start; | 1005 ptr = (char *) unexec_data_start; |
1006 end = ptr + hdr.a_data; | 1006 end = ptr + hdr.a_data; |
1007 /* This lseek is certainly incorrect when A_TEXT_OFFSET | 1007 /* This lseek is certainly incorrect when A_TEXT_OFFSET |
1008 and I believe it is a no-op otherwise. | 1008 and I believe it is a no-op otherwise. |
1009 Let's see if its absence ever fails. */ | 1009 Let's see if its absence ever fails. */ |
1010 /* lseek (new, (long) N_TXTOFF (hdr) + hdr.a_text, 0); */ | 1010 /* lseek (new_, (long) N_TXTOFF (hdr) + hdr.a_text, 0); */ |
1011 write_segment (new, ptr, end); | 1011 write_segment (new_, ptr, end); |
1012 | 1012 |
1013 #endif /* not COFF */ | 1013 #endif /* not COFF */ |
1014 | 1014 |
1015 return 0; | 1015 return 0; |
1016 } | 1016 } |
1017 | 1017 |
1018 static void | 1018 static void |
1019 write_segment (new, ptr, end) | 1019 write_segment (new_, ptr, end) |
1020 int new; | 1020 int new_; |
1021 char *ptr, *end; | 1021 char *ptr, *end; |
1022 { | 1022 { |
1023 int i, nwrite, ret; | 1023 int i, nwrite, ret; |
1024 #if 0 | 1024 #if 0 |
1025 char buf[80]; | 1025 char buf[80]; |
1036 { | 1036 { |
1037 /* Distance to next multiple of writesize. */ | 1037 /* Distance to next multiple of writesize. */ |
1038 nwrite = (((int) ptr + writesize) & -writesize) - (int) ptr; | 1038 nwrite = (((int) ptr + writesize) & -writesize) - (int) ptr; |
1039 /* But not beyond specified end. */ | 1039 /* But not beyond specified end. */ |
1040 if (nwrite > end - ptr) nwrite = end - ptr; | 1040 if (nwrite > end - ptr) nwrite = end - ptr; |
1041 ret = write (new, ptr, nwrite); | 1041 ret = write (new_, ptr, nwrite); |
1042 /* If write gets a page fault, it means we reached | 1042 /* If write gets a page fault, it means we reached |
1043 a gap between the old text segment and the old data segment. | 1043 a gap between the old text segment and the old data segment. |
1044 This gap has probably been remapped into part of the text segment. | 1044 This gap has probably been remapped into part of the text segment. |
1045 So write zeros for it. */ | 1045 So write zeros for it. */ |
1046 if (ret == -1 | 1046 if (ret == -1 |
1052 /* Write only a page of zeros at once, | 1052 /* Write only a page of zeros at once, |
1053 so that we don't overshoot the start | 1053 so that we don't overshoot the start |
1054 of the valid memory in the old data segment. */ | 1054 of the valid memory in the old data segment. */ |
1055 if (nwrite > pagesize) | 1055 if (nwrite > pagesize) |
1056 nwrite = pagesize; | 1056 nwrite = pagesize; |
1057 write (new, zeros, nwrite); | 1057 write (new_, zeros, nwrite); |
1058 } | 1058 } |
1059 #if 0 /* Now that we have can ask `write' to write more than a page, | 1059 #if 0 /* Now that we have can ask `write' to write more than a page, |
1060 it is legit for write do less than the whole amount specified. */ | 1060 it is legit for write do less than the whole amount specified. */ |
1061 else if (nwrite != ret) | 1061 else if (nwrite != ret) |
1062 { | 1062 { |
1063 sprintf (buf, | 1063 sprintf (buf, |
1064 "unexec write failure: addr 0x%lx, fileno %d, size 0x%x, wrote 0x%x, errno %d", | 1064 "unexec write failure: addr 0x%lx, fileno %d, size 0x%x, wrote 0x%x, errno %d", |
1065 (unsigned long) ptr, new, nwrite, ret, errno); | 1065 (unsigned long) ptr, new_, nwrite, ret, errno); |
1066 PERROR (buf); | 1066 PERROR (buf); |
1067 } | 1067 } |
1068 #endif | 1068 #endif |
1069 i += nwrite; | 1069 i += nwrite; |
1070 ptr += nwrite; | 1070 ptr += nwrite; |
1075 * copy_sym | 1075 * copy_sym |
1076 * | 1076 * |
1077 * Copy the relocation information and symbol table from the a.out to the new | 1077 * Copy the relocation information and symbol table from the a.out to the new |
1078 */ | 1078 */ |
1079 static int | 1079 static int |
1080 copy_sym (int new, int a_out, char *a_name, char *new_name) | 1080 copy_sym (int new_, int a_out, char *a_name, char *new_name) |
1081 { | 1081 { |
1082 char page[1024]; | 1082 char page[1024]; |
1083 int n; | 1083 int n; |
1084 | 1084 |
1085 if (a_out < 0) | 1085 if (a_out < 0) |
1097 #endif /* COFF */ | 1097 #endif /* COFF */ |
1098 lseek (a_out, SYMS_START, 0); /* Position a.out to symtab. */ | 1098 lseek (a_out, SYMS_START, 0); /* Position a.out to symtab. */ |
1099 | 1099 |
1100 while ((n = read (a_out, page, sizeof (page))) > 0) | 1100 while ((n = read (a_out, page, sizeof (page))) > 0) |
1101 { | 1101 { |
1102 if (write (new, page, n) != n) | 1102 if (write (new_, page, n) != n) |
1103 { | 1103 { |
1104 PERROR (new_name); | 1104 PERROR (new_name); |
1105 } | 1105 } |
1106 } | 1106 } |
1107 if (n < 0) | 1107 if (n < 0) |
1119 static void | 1119 static void |
1120 mark_x (char *name) | 1120 mark_x (char *name) |
1121 { | 1121 { |
1122 struct stat sbuf; | 1122 struct stat sbuf; |
1123 int um; | 1123 int um; |
1124 int new = 0; /* for PERROR */ | 1124 int new_ = 0; /* for PERROR */ |
1125 | 1125 |
1126 um = umask (777); | 1126 um = umask (777); |
1127 umask (um); | 1127 umask (um); |
1128 if (stat (name, &sbuf) == -1) | 1128 if (stat (name, &sbuf) == -1) |
1129 { | 1129 { |
1164 int UNUSED (writedesc); | 1164 int UNUSED (writedesc); |
1165 int UNUSED (readdesc); | 1165 int UNUSED (readdesc); |
1166 char *new_name; | 1166 char *new_name; |
1167 { | 1167 { |
1168 int nsyms; | 1168 int nsyms; |
1169 int new; | 1169 int new_; |
1170 #if defined (amdahl_uts) || defined (pfa) | 1170 #if defined (amdahl_uts) || defined (pfa) |
1171 SYMENT symentry; | 1171 SYMENT symentry; |
1172 AUXENT auxentry; | 1172 AUXENT auxentry; |
1173 #else | 1173 #else |
1174 struct syment symentry; | 1174 struct syment symentry; |
1176 #endif | 1176 #endif |
1177 | 1177 |
1178 if (!lnnoptr || !f_hdr.f_symptr) | 1178 if (!lnnoptr || !f_hdr.f_symptr) |
1179 return 0; | 1179 return 0; |
1180 | 1180 |
1181 if ((new = open (new_name, O_RDWR)) < 0) | 1181 if ((new_ = open (new_name, O_RDWR)) < 0) |
1182 { | 1182 { |
1183 PERROR (new_name); | 1183 PERROR (new_name); |
1184 return -1; | 1184 return -1; |
1185 } | 1185 } |
1186 | 1186 |
1187 lseek (new, f_hdr.f_symptr, 0); | 1187 lseek (new_, f_hdr.f_symptr, 0); |
1188 for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++) | 1188 for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++) |
1189 { | 1189 { |
1190 read (new, &symentry, SYMESZ); | 1190 read (new_, &symentry, SYMESZ); |
1191 if (symentry.n_numaux) | 1191 if (symentry.n_numaux) |
1192 { | 1192 { |
1193 read (new, &auxentry, AUXESZ); | 1193 read (new_, &auxentry, AUXESZ); |
1194 nsyms++; | 1194 nsyms++; |
1195 if (ISFCN (symentry.n_type) || symentry.n_type == 0x2400) | 1195 if (ISFCN (symentry.n_type) || symentry.n_type == 0x2400) |
1196 { | 1196 { |
1197 auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias; | 1197 auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias; |
1198 lseek (new, -AUXESZ, 1); | 1198 lseek (new_, -AUXESZ, 1); |
1199 write (new, &auxentry, AUXESZ); | 1199 write (new_, &auxentry, AUXESZ); |
1200 } | 1200 } |
1201 } | 1201 } |
1202 } | 1202 } |
1203 close (new); | 1203 close (new_); |
1204 return 0; | 1204 return 0; |
1205 } | 1205 } |
1206 | 1206 |
1207 #endif /* COFF_BSD_SYMBOLS */ | 1207 #endif /* COFF_BSD_SYMBOLS */ |
1208 | 1208 |