Mercurial > hg > xemacs-beta
comparison src/unexec.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | de805c49cfc1 |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
134 structure HDR and return the number of bytes to add to `a_text' | 134 structure HDR and return the number of bytes to add to `a_text' |
135 before writing it (above and beyond the number of bytes of actual | 135 before writing it (above and beyond the number of bytes of actual |
136 program text). HDR's standard fields are already correct, except that | 136 program text). HDR's standard fields are already correct, except that |
137 this adjustment to the `a_text' field has not yet been made; | 137 this adjustment to the `a_text' field has not yet been made; |
138 thus, the amount of offset can depend on the data in the file. | 138 thus, the amount of offset can depend on the data in the file. |
139 | 139 |
140 * A_TEXT_SEEK(HDR) | 140 * A_TEXT_SEEK(HDR) |
141 | 141 |
142 If defined, this macro specifies the number of bytes to seek into the | 142 If defined, this macro specifies the number of bytes to seek into the |
143 a.out file before starting to write the text segment. | 143 a.out file before starting to write the text segment. |
144 | 144 |
184 /* I don't know how correct this attempt to get more prototypes is... */ | 184 /* I don't know how correct this attempt to get more prototypes is... */ |
185 # if defined(sun) && defined(_POSIX_SOURCE) | 185 # if defined(sun) && defined(_POSIX_SOURCE) |
186 # undef _POSIX_SOURCE | 186 # undef _POSIX_SOURCE |
187 # endif | 187 # endif |
188 | 188 |
189 # if defined(__lucid) && !defined(__STDC_EXTENDED__) | |
190 # define __STDC_EXTENDED__ 1 | |
191 # endif | |
192 | |
189 # include <stddef.h> | 193 # include <stddef.h> |
190 # include <stdlib.h> | 194 # include <stdlib.h> |
191 # include <unistd.h> | 195 # include <unistd.h> |
192 # include <string.h> | 196 # include <string.h> |
193 # include <stddef.h> | 197 # include <stddef.h> |
194 # include <errno.h> | 198 |
199 # ifdef __lucid | |
200 # include <sysent.h> | |
201 # endif | |
195 | 202 |
196 #endif | 203 #endif |
197 | 204 |
198 /* I don't understand this, but it's necessary to get some slots in struct exec | 205 /* I don't understand this, but it's necessary to get some slots in struct exec |
199 from /usr/include/sys/exec.h when running LCC in strict ANSI mode. We don't | 206 from /usr/include/sys/exec.h when running LCC in strict ANSI mode. We don't |
207 | 214 |
208 #ifdef COFF_ENCAPSULATE | 215 #ifdef COFF_ENCAPSULATE |
209 int need_coff_header = 1; | 216 int need_coff_header = 1; |
210 #include <coff-encap/a.out.encap.h> /* The location might be a poor assumption */ | 217 #include <coff-encap/a.out.encap.h> /* The location might be a poor assumption */ |
211 #else | 218 #else |
219 #ifdef MSDOS | |
220 #if __DJGPP__ > 1 | |
221 #include <fcntl.h> /* for O_RDONLY, O_RDWR */ | |
222 #endif | |
223 #include <coff.h> | |
224 #define filehdr external_filehdr | |
225 #define scnhdr external_scnhdr | |
226 #define syment external_syment | |
227 #define auxent external_auxent | |
228 #define n_numaux e_numaux | |
229 #define n_type e_type | |
230 struct aouthdr | |
231 { | |
232 unsigned short magic; /* type of file */ | |
233 unsigned short vstamp; /* version stamp */ | |
234 unsigned long tsize; /* text size in bytes, padded to FW bdry*/ | |
235 unsigned long dsize; /* initialized data " " */ | |
236 unsigned long bsize; /* uninitialized data " " */ | |
237 unsigned long entry; /* entry pt. */ | |
238 unsigned long text_start;/* base of text used for this file */ | |
239 unsigned long data_start;/* base of data used for this file */ | |
240 }; | |
241 | |
242 | |
243 #else /* not MSDOS */ | |
212 #include <a.out.h> | 244 #include <a.out.h> |
245 #endif /* not MSDOS */ | |
213 #endif /* not COFF_ENCAPSULATE */ | 246 #endif /* not COFF_ENCAPSULATE */ |
214 | 247 |
215 /* Define getpagesize if the system does not. | 248 /* Define getpagesize if the system does not. |
216 Note that this may depend on symbols defined in a.out.h. */ | 249 Note that this may depend on symbols defined in a.out.h. */ |
217 #include "getpagesize.h" | 250 #include "getpagesize.h" |
338 #ifdef emacs | 371 #ifdef emacs |
339 | 372 |
340 #include "lisp.h" | 373 #include "lisp.h" |
341 | 374 |
342 static void | 375 static void |
343 report_error (const char *file, int fd) | 376 report_error (file, fd) |
377 CONST char *file; | |
378 int fd; | |
344 { | 379 { |
345 if (fd) | 380 if (fd) |
346 close (fd); | 381 close (fd); |
347 report_file_error ("Cannot unexec", | 382 report_file_error ("Cannot unexec", |
348 Fcons (build_ext_string (file, Qfile_name), Qnil)); | 383 Fcons (build_ext_string (file, FORMAT_FILENAME), Qnil)); |
349 } | 384 } |
350 #endif /* emacs */ | 385 #endif /* emacs */ |
351 | 386 |
352 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1 | 387 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1 |
353 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 | 388 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 |
354 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 | 389 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 |
355 | 390 |
356 static void | 391 static void |
357 report_error_1 (fd, msg, a1, a2) | 392 report_error_1 (fd, msg, a1, a2) |
358 int fd; | 393 int fd; |
359 const char *msg; | 394 CONST char *msg; |
360 int a1, a2; | 395 int a1, a2; |
361 { | 396 { |
362 close (fd); | 397 close (fd); |
363 #ifdef emacs | 398 #ifdef emacs |
364 error (msg, a1, a2); | 399 error (msg, a1, a2); |
406 #endif | 441 #endif |
407 ) | 442 ) |
408 { | 443 { |
409 close (new); | 444 close (new); |
410 /* unlink (new_name); / * Failed, unlink new a.out */ | 445 /* unlink (new_name); / * Failed, unlink new a.out */ |
411 return -1; | 446 return -1; |
412 } | 447 } |
413 | 448 |
414 close (new); | 449 close (new); |
415 if (a_out >= 0) | 450 if (a_out >= 0) |
416 close (a_out); | 451 close (a_out); |
883 } | 918 } |
884 } | 919 } |
885 | 920 |
886 #else /* COFF, but not USG_SHARED_LIBRARIES */ | 921 #else /* COFF, but not USG_SHARED_LIBRARIES */ |
887 | 922 |
923 #ifdef MSDOS | |
924 #if __DJGPP__ >= 2 | |
925 /* Dump the original table of exception handlers, not the one | |
926 where our exception hooks are registered. */ | |
927 __djgpp_exception_toggle (); | |
928 #endif | |
929 #endif | |
930 | |
888 lseek (new, (long) text_scnptr, 0); | 931 lseek (new, (long) text_scnptr, 0); |
889 ptr = (char *) f_ohdr.text_start; | 932 ptr = (char *) f_ohdr.text_start; |
890 #ifdef HEADER_INCL_IN_TEXT | 933 #ifdef HEADER_INCL_IN_TEXT |
891 /* For Gould UTX/32, text starts after headers */ | 934 /* For Gould UTX/32, text starts after headers */ |
892 ptr = (char *) (ptr + text_scnptr); | 935 ptr = (char *) (ptr + text_scnptr); |
896 | 939 |
897 lseek (new, (long) data_scnptr, 0); | 940 lseek (new, (long) data_scnptr, 0); |
898 ptr = (char *) f_ohdr.data_start; | 941 ptr = (char *) f_ohdr.data_start; |
899 end = ptr + f_ohdr.dsize; | 942 end = ptr + f_ohdr.dsize; |
900 write_segment (new, ptr, end); | 943 write_segment (new, ptr, end); |
944 | |
945 #ifdef MSDOS | |
946 #if __DJGPP__ >= 2 | |
947 /* Restore our exception hooks. */ | |
948 __djgpp_exception_toggle (); | |
949 #endif | |
950 #endif | |
901 | 951 |
902 #endif /* USG_SHARED_LIBRARIES */ | 952 #endif /* USG_SHARED_LIBRARIES */ |
903 | 953 |
904 #else /* if not COFF */ | 954 #else /* if not COFF */ |
905 | 955 |
946 FILE *pfile; | 996 FILE *pfile; |
947 char *temp_ptr; | 997 char *temp_ptr; |
948 char c; | 998 char c; |
949 int mcount_address, mcount_offset, count; | 999 int mcount_address, mcount_offset, count; |
950 extern char *_execname; | 1000 extern char *_execname; |
951 | 1001 |
952 | 1002 |
953 /* The use of _execname is incompatible with RISCiX 1.1 */ | 1003 /* The use of _execname is incompatible with RISCiX 1.1 */ |
954 sprintf (command, "nm %s | fgrep mcount", _execname); | 1004 sprintf (command, "nm %s | fgrep mcount", _execname); |
955 | 1005 |
956 if ( (pfile = popen(command, "r")) == NULL) | 1006 if ( (pfile = popen(command, "r")) == NULL) |
966 | 1016 |
967 if ((count == 0) || pclose(pfile) != NULL) | 1017 if ((count == 0) || pclose(pfile) != NULL) |
968 { | 1018 { |
969 sprintf (errbuf, "Failed to execute the command '%s'\n", command); | 1019 sprintf (errbuf, "Failed to execute the command '%s'\n", command); |
970 PERROR (errbuf); | 1020 PERROR (errbuf); |
971 } | 1021 } |
972 | 1022 |
973 sscanf(address_text, "%x", &mcount_address); | 1023 sscanf(address_text, "%x", &mcount_address); |
974 ptr = (char *) unexec_text_start; | 1024 ptr = (char *) unexec_text_start; |
975 mcount_offset = (char *)mcount_address - ptr; | 1025 mcount_offset = (char *)mcount_address - ptr; |
976 | 1026 |
1024 { | 1074 { |
1025 int i, nwrite, ret; | 1075 int i, nwrite, ret; |
1026 #if 0 | 1076 #if 0 |
1027 char buf[80]; | 1077 char buf[80]; |
1028 #endif | 1078 #endif |
1079 extern int errno; | |
1029 /* This is the normal amount to write at once. | 1080 /* This is the normal amount to write at once. |
1030 It is the size of block that NFS uses. */ | 1081 It is the size of block that NFS uses. */ |
1031 int writesize = 1 << 13; | 1082 int writesize = 1 << 13; |
1032 int pagesize = getpagesize (); | 1083 int pagesize = getpagesize (); |
1033 char zeros[1 << 13]; | 1084 char zeros[1 << 13]; |
1178 #endif | 1229 #endif |
1179 | 1230 |
1180 if (!lnnoptr || !f_hdr.f_symptr) | 1231 if (!lnnoptr || !f_hdr.f_symptr) |
1181 return 0; | 1232 return 0; |
1182 | 1233 |
1234 #ifdef MSDOS | |
1235 if ((new = writedesc) < 0) | |
1236 #else | |
1183 if ((new = open (new_name, O_RDWR)) < 0) | 1237 if ((new = open (new_name, O_RDWR)) < 0) |
1238 #endif | |
1184 { | 1239 { |
1185 PERROR (new_name); | 1240 PERROR (new_name); |
1186 return -1; | 1241 return -1; |
1187 } | 1242 } |
1188 | 1243 |
1200 lseek (new, -AUXESZ, 1); | 1255 lseek (new, -AUXESZ, 1); |
1201 write (new, &auxentry, AUXESZ); | 1256 write (new, &auxentry, AUXESZ); |
1202 } | 1257 } |
1203 } | 1258 } |
1204 } | 1259 } |
1260 #ifndef MSDOS | |
1205 close (new); | 1261 close (new); |
1262 #endif | |
1206 return 0; | 1263 return 0; |
1207 } | 1264 } |
1208 | 1265 |
1209 #endif /* COFF_BSD_SYMBOLS */ | 1266 #endif /* COFF_BSD_SYMBOLS */ |
1210 | 1267 |