diff options
| author | Eli Zaretskii | 2005-03-19 11:52:25 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2005-03-19 11:52:25 +0000 |
| commit | 730f4d722a80a8c4dbaf31099ad8721bf97d1c55 (patch) | |
| tree | c9edbc279aaf3f7dcb89f05101a3e49c200a090b /src | |
| parent | f601dcd6022eb8562c8324b037a88dbf2b981071 (diff) | |
| download | emacs-730f4d722a80a8c4dbaf31099ad8721bf97d1c55.tar.gz emacs-730f4d722a80a8c4dbaf31099ad8721bf97d1c55.zip | |
(write_segment, unexec): Move these functions to avoid forward
references (which cause errors with "gcc -gcoff").
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/unexec.c | 195 |
2 files changed, 102 insertions, 98 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 92be15873c0..9a9b706ad1d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2005-03-19 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * unexec.c (write_segment, unexec): Move these functions to avoid | ||
| 4 | forward references (which cause errors with "gcc -gcoff"). | ||
| 5 | |||
| 1 | 2005-03-18 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> | 6 | 2005-03-18 Jan Dj,Ad(Brv <jan.h.d@swipnet.se> |
| 2 | 7 | ||
| 3 | * xfns.c (x_create_tip_frame): Removed setting of Vx_resource_name so | 8 | * xfns.c (x_create_tip_frame): Removed setting of Vx_resource_name so |
diff --git a/src/unexec.c b/src/unexec.c index dadea560e0c..156cad16f97 100644 --- a/src/unexec.c +++ b/src/unexec.c | |||
| @@ -368,48 +368,6 @@ static int copy_sym (); | |||
| 368 | static void mark_x (); | 368 | static void mark_x (); |
| 369 | 369 | ||
| 370 | /* **************************************************************** | 370 | /* **************************************************************** |
| 371 | * unexec | ||
| 372 | * | ||
| 373 | * driving logic. | ||
| 374 | */ | ||
| 375 | unexec (new_name, a_name, data_start, bss_start, entry_address) | ||
| 376 | char *new_name, *a_name; | ||
| 377 | unsigned data_start, bss_start, entry_address; | ||
| 378 | { | ||
| 379 | int new, a_out = -1; | ||
| 380 | |||
| 381 | if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) | ||
| 382 | { | ||
| 383 | PERROR (a_name); | ||
| 384 | } | ||
| 385 | if ((new = creat (new_name, 0666)) < 0) | ||
| 386 | { | ||
| 387 | PERROR (new_name); | ||
| 388 | } | ||
| 389 | |||
| 390 | if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0 | ||
| 391 | || copy_text_and_data (new, a_out) < 0 | ||
| 392 | || copy_sym (new, a_out, a_name, new_name) < 0 | ||
| 393 | #ifdef COFF | ||
| 394 | #ifndef COFF_BSD_SYMBOLS | ||
| 395 | || adjust_lnnoptrs (new, a_out, new_name) < 0 | ||
| 396 | #endif | ||
| 397 | #endif | ||
| 398 | ) | ||
| 399 | { | ||
| 400 | close (new); | ||
| 401 | /* unlink (new_name); /* Failed, unlink new a.out */ | ||
| 402 | return -1; | ||
| 403 | } | ||
| 404 | |||
| 405 | close (new); | ||
| 406 | if (a_out >= 0) | ||
| 407 | close (a_out); | ||
| 408 | mark_x (new_name); | ||
| 409 | return 0; | ||
| 410 | } | ||
| 411 | |||
| 412 | /* **************************************************************** | ||
| 413 | * make_hdr | 371 | * make_hdr |
| 414 | * | 372 | * |
| 415 | * Make the header in the new a.out from the header in core. | 373 | * Make the header in the new a.out from the header in core. |
| @@ -835,6 +793,61 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) | |||
| 835 | #endif /* not COFF */ | 793 | #endif /* not COFF */ |
| 836 | } | 794 | } |
| 837 | 795 | ||
| 796 | write_segment (new, ptr, end) | ||
| 797 | int new; | ||
| 798 | register char *ptr, *end; | ||
| 799 | { | ||
| 800 | register int i, nwrite, ret; | ||
| 801 | char buf[80]; | ||
| 802 | #ifndef USE_CRT_DLL | ||
| 803 | extern int errno; | ||
| 804 | #endif | ||
| 805 | /* This is the normal amount to write at once. | ||
| 806 | It is the size of block that NFS uses. */ | ||
| 807 | int writesize = 1 << 13; | ||
| 808 | int pagesize = getpagesize (); | ||
| 809 | char zeros[1 << 13]; | ||
| 810 | |||
| 811 | bzero (zeros, sizeof (zeros)); | ||
| 812 | |||
| 813 | for (i = 0; ptr < end;) | ||
| 814 | { | ||
| 815 | /* Distance to next multiple of writesize. */ | ||
| 816 | nwrite = (((int) ptr + writesize) & -writesize) - (int) ptr; | ||
| 817 | /* But not beyond specified end. */ | ||
| 818 | if (nwrite > end - ptr) nwrite = end - ptr; | ||
| 819 | ret = write (new, ptr, nwrite); | ||
| 820 | /* If write gets a page fault, it means we reached | ||
| 821 | a gap between the old text segment and the old data segment. | ||
| 822 | This gap has probably been remapped into part of the text segment. | ||
| 823 | So write zeros for it. */ | ||
| 824 | if (ret == -1 | ||
| 825 | #ifdef EFAULT | ||
| 826 | && errno == EFAULT | ||
| 827 | #endif | ||
| 828 | ) | ||
| 829 | { | ||
| 830 | /* Write only a page of zeros at once, | ||
| 831 | so that we we don't overshoot the start | ||
| 832 | of the valid memory in the old data segment. */ | ||
| 833 | if (nwrite > pagesize) | ||
| 834 | nwrite = pagesize; | ||
| 835 | write (new, zeros, nwrite); | ||
| 836 | } | ||
| 837 | #if 0 /* Now that we have can ask `write' to write more than a page, | ||
| 838 | it is legit for write do less than the whole amount specified. */ | ||
| 839 | else if (nwrite != ret) | ||
| 840 | { | ||
| 841 | sprintf (buf, | ||
| 842 | "unexec write failure: addr 0x%x, fileno %d, size 0x%x, wrote 0x%x, errno %d", | ||
| 843 | ptr, new, nwrite, ret, errno); | ||
| 844 | PERROR (buf); | ||
| 845 | } | ||
| 846 | #endif | ||
| 847 | i += nwrite; | ||
| 848 | ptr += nwrite; | ||
| 849 | } | ||
| 850 | } | ||
| 838 | /* **************************************************************** | 851 | /* **************************************************************** |
| 839 | * copy_text_and_data | 852 | * copy_text_and_data |
| 840 | * | 853 | * |
| @@ -1060,62 +1073,6 @@ copy_text_and_data (new, a_out) | |||
| 1060 | 1073 | ||
| 1061 | return 0; | 1074 | return 0; |
| 1062 | } | 1075 | } |
| 1063 | |||
| 1064 | write_segment (new, ptr, end) | ||
| 1065 | int new; | ||
| 1066 | register char *ptr, *end; | ||
| 1067 | { | ||
| 1068 | register int i, nwrite, ret; | ||
| 1069 | char buf[80]; | ||
| 1070 | #ifndef USE_CRT_DLL | ||
| 1071 | extern int errno; | ||
| 1072 | #endif | ||
| 1073 | /* This is the normal amount to write at once. | ||
| 1074 | It is the size of block that NFS uses. */ | ||
| 1075 | int writesize = 1 << 13; | ||
| 1076 | int pagesize = getpagesize (); | ||
| 1077 | char zeros[1 << 13]; | ||
| 1078 | |||
| 1079 | bzero (zeros, sizeof (zeros)); | ||
| 1080 | |||
| 1081 | for (i = 0; ptr < end;) | ||
| 1082 | { | ||
| 1083 | /* Distance to next multiple of writesize. */ | ||
| 1084 | nwrite = (((int) ptr + writesize) & -writesize) - (int) ptr; | ||
| 1085 | /* But not beyond specified end. */ | ||
| 1086 | if (nwrite > end - ptr) nwrite = end - ptr; | ||
| 1087 | ret = write (new, ptr, nwrite); | ||
| 1088 | /* If write gets a page fault, it means we reached | ||
| 1089 | a gap between the old text segment and the old data segment. | ||
| 1090 | This gap has probably been remapped into part of the text segment. | ||
| 1091 | So write zeros for it. */ | ||
| 1092 | if (ret == -1 | ||
| 1093 | #ifdef EFAULT | ||
| 1094 | && errno == EFAULT | ||
| 1095 | #endif | ||
| 1096 | ) | ||
| 1097 | { | ||
| 1098 | /* Write only a page of zeros at once, | ||
| 1099 | so that we we don't overshoot the start | ||
| 1100 | of the valid memory in the old data segment. */ | ||
| 1101 | if (nwrite > pagesize) | ||
| 1102 | nwrite = pagesize; | ||
| 1103 | write (new, zeros, nwrite); | ||
| 1104 | } | ||
| 1105 | #if 0 /* Now that we have can ask `write' to write more than a page, | ||
| 1106 | it is legit for write do less than the whole amount specified. */ | ||
| 1107 | else if (nwrite != ret) | ||
| 1108 | { | ||
| 1109 | sprintf (buf, | ||
| 1110 | "unexec write failure: addr 0x%x, fileno %d, size 0x%x, wrote 0x%x, errno %d", | ||
| 1111 | ptr, new, nwrite, ret, errno); | ||
| 1112 | PERROR (buf); | ||
| 1113 | } | ||
| 1114 | #endif | ||
| 1115 | i += nwrite; | ||
| 1116 | ptr += nwrite; | ||
| 1117 | } | ||
| 1118 | } | ||
| 1119 | 1076 | ||
| 1120 | /* **************************************************************** | 1077 | /* **************************************************************** |
| 1121 | * copy_sym | 1078 | * copy_sym |
| @@ -1264,6 +1221,48 @@ adjust_lnnoptrs (writedesc, readdesc, new_name) | |||
| 1264 | 1221 | ||
| 1265 | #endif /* COFF */ | 1222 | #endif /* COFF */ |
| 1266 | 1223 | ||
| 1224 | /* **************************************************************** | ||
| 1225 | * unexec | ||
| 1226 | * | ||
| 1227 | * driving logic. | ||
| 1228 | */ | ||
| 1229 | unexec (new_name, a_name, data_start, bss_start, entry_address) | ||
| 1230 | char *new_name, *a_name; | ||
| 1231 | unsigned data_start, bss_start, entry_address; | ||
| 1232 | { | ||
| 1233 | int new, a_out = -1; | ||
| 1234 | |||
| 1235 | if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) | ||
| 1236 | { | ||
| 1237 | PERROR (a_name); | ||
| 1238 | } | ||
| 1239 | if ((new = creat (new_name, 0666)) < 0) | ||
| 1240 | { | ||
| 1241 | PERROR (new_name); | ||
| 1242 | } | ||
| 1243 | |||
| 1244 | if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0 | ||
| 1245 | || copy_text_and_data (new, a_out) < 0 | ||
| 1246 | || copy_sym (new, a_out, a_name, new_name) < 0 | ||
| 1247 | #ifdef COFF | ||
| 1248 | #ifndef COFF_BSD_SYMBOLS | ||
| 1249 | || adjust_lnnoptrs (new, a_out, new_name) < 0 | ||
| 1250 | #endif | ||
| 1251 | #endif | ||
| 1252 | ) | ||
| 1253 | { | ||
| 1254 | close (new); | ||
| 1255 | /* unlink (new_name); /* Failed, unlink new a.out */ | ||
| 1256 | return -1; | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | close (new); | ||
| 1260 | if (a_out >= 0) | ||
| 1261 | close (a_out); | ||
| 1262 | mark_x (new_name); | ||
| 1263 | return 0; | ||
| 1264 | } | ||
| 1265 | |||
| 1267 | #endif /* not CANNOT_DUMP */ | 1266 | #endif /* not CANNOT_DUMP */ |
| 1268 | 1267 | ||
| 1269 | /* arch-tag: 62409b69-e27a-4a7c-9413-0210d6b54e7f | 1268 | /* arch-tag: 62409b69-e27a-4a7c-9413-0210d6b54e7f |