comparison src/unexec.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 183866b06e0b
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
207 207
208 #ifdef COFF_ENCAPSULATE 208 #ifdef COFF_ENCAPSULATE
209 int need_coff_header = 1; 209 int need_coff_header = 1;
210 #include <coff-encap/a.out.encap.h> /* The location might be a poor assumption */ 210 #include <coff-encap/a.out.encap.h> /* The location might be a poor assumption */
211 #else 211 #else
212 #ifdef MSDOS
213 #if __DJGPP__ > 1
214 #include <fcntl.h> /* for O_RDONLY, O_RDWR */
215 #endif
216 #include <coff.h>
217 #define filehdr external_filehdr
218 #define scnhdr external_scnhdr
219 #define syment external_syment
220 #define auxent external_auxent
221 #define n_numaux e_numaux
222 #define n_type e_type
223 struct aouthdr
224 {
225 unsigned short magic; /* type of file */
226 unsigned short vstamp; /* version stamp */
227 unsigned long tsize; /* text size in bytes, padded to FW bdry*/
228 unsigned long dsize; /* initialized data " " */
229 unsigned long bsize; /* uninitialized data " " */
230 unsigned long entry; /* entry pt. */
231 unsigned long text_start;/* base of text used for this file */
232 unsigned long data_start;/* base of data used for this file */
233 };
234
235
236 #else /* not MSDOS */
237 #include <a.out.h> 212 #include <a.out.h>
238 #endif /* not MSDOS */
239 #endif /* not COFF_ENCAPSULATE */ 213 #endif /* not COFF_ENCAPSULATE */
240 214
241 /* Define getpagesize if the system does not. 215 /* Define getpagesize if the system does not.
242 Note that this may depend on symbols defined in a.out.h. */ 216 Note that this may depend on symbols defined in a.out.h. */
243 #include "getpagesize.h" 217 #include "getpagesize.h"
380 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 354 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1
381 355
382 static void 356 static void
383 report_error_1 (fd, msg, a1, a2) 357 report_error_1 (fd, msg, a1, a2)
384 int fd; 358 int fd;
385 CONST char *msg; 359 const char *msg;
386 int a1, a2; 360 int a1, a2;
387 { 361 {
388 close (fd); 362 close (fd);
389 #ifdef emacs 363 #ifdef emacs
390 error (msg, a1, a2); 364 error (msg, a1, a2);
909 } 883 }
910 } 884 }
911 885
912 #else /* COFF, but not USG_SHARED_LIBRARIES */ 886 #else /* COFF, but not USG_SHARED_LIBRARIES */
913 887
914 #ifdef MSDOS
915 #if __DJGPP__ >= 2
916 /* Dump the original table of exception handlers, not the one
917 where our exception hooks are registered. */
918 __djgpp_exception_toggle ();
919 #endif
920 #endif
921
922 lseek (new, (long) text_scnptr, 0); 888 lseek (new, (long) text_scnptr, 0);
923 ptr = (char *) f_ohdr.text_start; 889 ptr = (char *) f_ohdr.text_start;
924 #ifdef HEADER_INCL_IN_TEXT 890 #ifdef HEADER_INCL_IN_TEXT
925 /* For Gould UTX/32, text starts after headers */ 891 /* For Gould UTX/32, text starts after headers */
926 ptr = (char *) (ptr + text_scnptr); 892 ptr = (char *) (ptr + text_scnptr);
930 896
931 lseek (new, (long) data_scnptr, 0); 897 lseek (new, (long) data_scnptr, 0);
932 ptr = (char *) f_ohdr.data_start; 898 ptr = (char *) f_ohdr.data_start;
933 end = ptr + f_ohdr.dsize; 899 end = ptr + f_ohdr.dsize;
934 write_segment (new, ptr, end); 900 write_segment (new, ptr, end);
935
936 #ifdef MSDOS
937 #if __DJGPP__ >= 2
938 /* Restore our exception hooks. */
939 __djgpp_exception_toggle ();
940 #endif
941 #endif
942 901
943 #endif /* USG_SHARED_LIBRARIES */ 902 #endif /* USG_SHARED_LIBRARIES */
944 903
945 #else /* if not COFF */ 904 #else /* if not COFF */
946 905
1219 #endif 1178 #endif
1220 1179
1221 if (!lnnoptr || !f_hdr.f_symptr) 1180 if (!lnnoptr || !f_hdr.f_symptr)
1222 return 0; 1181 return 0;
1223 1182
1224 #ifdef MSDOS
1225 if ((new = writedesc) < 0)
1226 #else
1227 if ((new = open (new_name, O_RDWR)) < 0) 1183 if ((new = open (new_name, O_RDWR)) < 0)
1228 #endif
1229 { 1184 {
1230 PERROR (new_name); 1185 PERROR (new_name);
1231 return -1; 1186 return -1;
1232 } 1187 }
1233 1188
1245 lseek (new, -AUXESZ, 1); 1200 lseek (new, -AUXESZ, 1);
1246 write (new, &auxentry, AUXESZ); 1201 write (new, &auxentry, AUXESZ);
1247 } 1202 }
1248 } 1203 }
1249 } 1204 }
1250 #ifndef MSDOS
1251 close (new); 1205 close (new);
1252 #endif
1253 return 0; 1206 return 0;
1254 } 1207 }
1255 1208
1256 #endif /* COFF_BSD_SYMBOLS */ 1209 #endif /* COFF_BSD_SYMBOLS */
1257 1210