Mercurial > hg > xemacs-beta
comparison src/unexaix.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 |
---|---|
55 | 55 |
56 #ifndef emacs | 56 #ifndef emacs |
57 #define PERROR(arg) perror (arg); return -1 | 57 #define PERROR(arg) perror (arg); return -1 |
58 #else | 58 #else |
59 #include <config.h> | 59 #include <config.h> |
60 #define PERROR(file) report_error (file, new) | 60 #define PERROR(file) report_error (file, new_) |
61 #endif | 61 #endif |
62 | 62 |
63 #include <a.out.h> | 63 #include <a.out.h> |
64 /* Define getpagesize () if the system does not. | 64 /* Define getpagesize () if the system does not. |
65 Note that this may depend on symbols defined in a.out.h | 65 Note that this may depend on symbols defined in a.out.h |
124 report_error_with_errno (Qio_error, "Cannot unexec", | 124 report_error_with_errno (Qio_error, "Cannot unexec", |
125 build_string (file)); | 125 build_string (file)); |
126 } | 126 } |
127 #endif /* emacs */ | 127 #endif /* emacs */ |
128 | 128 |
129 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1 | 129 #define ERROR0(msg) report_error_1 (new_, msg, 0, 0); return -1 |
130 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1 | 130 #define ERROR1(msg,x) report_error_1 (new_, msg, x, 0); return -1 |
131 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1 | 131 #define ERROR2(msg,x,y) report_error_1 (new_, msg, x, y); return -1 |
132 | 132 |
133 static void | 133 static void |
134 report_error_1 (int fd, char *msg, int a1, int a2) | 134 report_error_1 (int fd, char *msg, int a1, int a2) |
135 { | 135 { |
136 close (fd); | 136 close (fd); |
156 int unexec (char *new_name, char *a_name, | 156 int unexec (char *new_name, char *a_name, |
157 uintptr_t data_start, | 157 uintptr_t data_start, |
158 uintptr_t bss_start, | 158 uintptr_t bss_start, |
159 uintptr_t entry_address) | 159 uintptr_t entry_address) |
160 { | 160 { |
161 int new = -1, a_out = -1; | 161 int new_ = -1, a_out = -1; |
162 | 162 |
163 if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) | 163 if (a_name && (a_out = open (a_name, O_RDONLY)) < 0) |
164 { | 164 { |
165 PERROR (a_name); | 165 PERROR (a_name); |
166 } | 166 } |
167 if ((new = creat (new_name, 0666)) < 0) | 167 if ((new_ = creat (new_name, 0666)) < 0) |
168 { | 168 { |
169 PERROR (new_name); | 169 PERROR (new_name); |
170 } | 170 } |
171 if (make_hdr (new, a_out, | 171 if (make_hdr (new_, a_out, |
172 data_start, bss_start, | 172 data_start, bss_start, |
173 entry_address, | 173 entry_address, |
174 a_name, new_name) < 0 | 174 a_name, new_name) < 0 |
175 || copy_text_and_data (new) < 0 | 175 || copy_text_and_data (new_) < 0 |
176 || copy_sym (new, a_out, a_name, new_name) < 0 | 176 || copy_sym (new_, a_out, a_name, new_name) < 0 |
177 || adjust_lnnoptrs (new, a_out, new_name) < 0 | 177 || adjust_lnnoptrs (new_, a_out, new_name) < 0 |
178 || unrelocate_symbols (new, a_out, a_name, new_name) < 0) | 178 || unrelocate_symbols (new_, a_out, a_name, new_name) < 0) |
179 { | 179 { |
180 close (new); | 180 close (new_); |
181 return -1; | 181 return -1; |
182 } | 182 } |
183 | 183 |
184 close (new); | 184 close (new_); |
185 if (a_out >= 0) | 185 if (a_out >= 0) |
186 close (a_out); | 186 close (a_out); |
187 mark_x (new_name); | 187 mark_x (new_name); |
188 return 0; | 188 return 0; |
189 } | 189 } |
193 * | 193 * |
194 * Make the header in the new a.out from the header in core. | 194 * Make the header in the new a.out from the header in core. |
195 * Modify the text and data sizes. | 195 * Modify the text and data sizes. |
196 */ | 196 */ |
197 static int | 197 static int |
198 make_hdr (int new, int a_out, | 198 make_hdr (int new_, int a_out, |
199 unsigned data_start, unsigned bss_start, | 199 unsigned data_start, unsigned bss_start, |
200 unsigned UNUSED (entry_address), | 200 unsigned UNUSED (entry_address), |
201 char *a_name, char *new_name) | 201 char *a_name, char *new_name) |
202 { | 202 { |
203 int scns; | 203 int scns; |
389 | 389 |
390 text_scnptr = f_thdr->s_scnptr; | 390 text_scnptr = f_thdr->s_scnptr; |
391 data_scnptr = f_dhdr->s_scnptr; | 391 data_scnptr = f_dhdr->s_scnptr; |
392 load_scnptr = f_lhdr ? f_lhdr->s_scnptr : 0; | 392 load_scnptr = f_lhdr ? f_lhdr->s_scnptr : 0; |
393 | 393 |
394 if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) | 394 if (write (new_, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) |
395 { | 395 { |
396 PERROR (new_name); | 396 PERROR (new_name); |
397 } | 397 } |
398 | 398 |
399 if (f_hdr.f_opthdr > 0) | 399 if (f_hdr.f_opthdr > 0) |
400 { | 400 { |
401 if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) | 401 if (write (new_, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) |
402 { | 402 { |
403 PERROR (new_name); | 403 PERROR (new_name); |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 for (scns = 0; scns < f_hdr.f_nscns; scns++) { | 407 for (scns = 0; scns < f_hdr.f_nscns; scns++) { |
408 struct scnhdr *s = §ion[scns]; | 408 struct scnhdr *s = §ion[scns]; |
409 if (write (new, s, sizeof (*s)) != sizeof (*s)) | 409 if (write (new_, s, sizeof (*s)) != sizeof (*s)) |
410 { | 410 { |
411 PERROR (new_name); | 411 PERROR (new_name); |
412 } | 412 } |
413 } | 413 } |
414 | 414 |
419 | 419 |
420 * | 420 * |
421 * Copy the text and data segments from memory to the new a.out | 421 * Copy the text and data segments from memory to the new a.out |
422 */ | 422 */ |
423 static int | 423 static int |
424 copy_text_and_data (int new) | 424 copy_text_and_data (int new_) |
425 { | 425 { |
426 char *end; | 426 char *end; |
427 char *ptr; | 427 char *ptr; |
428 | 428 |
429 lseek (new, (long) text_scnptr, SEEK_SET); | 429 lseek (new_, (long) text_scnptr, SEEK_SET); |
430 ptr = start_of_text () + text_scnptr; | 430 ptr = start_of_text () + text_scnptr; |
431 end = ptr + f_ohdr.tsize; | 431 end = ptr + f_ohdr.tsize; |
432 write_segment (new, ptr, end); | 432 write_segment (new_, ptr, end); |
433 | 433 |
434 lseek (new, (long) data_scnptr, SEEK_SET); | 434 lseek (new_, (long) data_scnptr, SEEK_SET); |
435 ptr = (char *) f_ohdr.data_start; | 435 ptr = (char *) f_ohdr.data_start; |
436 end = ptr + f_ohdr.dsize; | 436 end = ptr + f_ohdr.dsize; |
437 write_segment (new, ptr, end); | 437 write_segment (new_, ptr, end); |
438 | 438 |
439 return 0; | 439 return 0; |
440 } | 440 } |
441 | 441 |
442 #define UnexBlockSz (1<<12) /* read/write block size */ | 442 #define UnexBlockSz (1<<12) /* read/write block size */ |
443 static void | 443 static void |
444 write_segment (int new, char *ptr, char *end) | 444 write_segment (int new_, char *ptr, char *end) |
445 { | 445 { |
446 int i, nwrite, ret; | 446 int i, nwrite, ret; |
447 char buf[80]; | 447 char buf[80]; |
448 char zeros[UnexBlockSz]; | 448 char zeros[UnexBlockSz]; |
449 | 449 |
451 { | 451 { |
452 /* distance to next block. */ | 452 /* distance to next block. */ |
453 nwrite = (((int) ptr + UnexBlockSz) & -UnexBlockSz) - (int) ptr; | 453 nwrite = (((int) ptr + UnexBlockSz) & -UnexBlockSz) - (int) ptr; |
454 /* But not beyond specified end. */ | 454 /* But not beyond specified end. */ |
455 if (nwrite > end - ptr) nwrite = end - ptr; | 455 if (nwrite > end - ptr) nwrite = end - ptr; |
456 ret = write (new, ptr, nwrite); | 456 ret = write (new_, ptr, nwrite); |
457 /* If write gets a page fault, it means we reached | 457 /* If write gets a page fault, it means we reached |
458 a gap between the old text segment and the old data segment. | 458 a gap between the old text segment and the old data segment. |
459 This gap has probably been remapped into part of the text segment. | 459 This gap has probably been remapped into part of the text segment. |
460 So write zeros for it. */ | 460 So write zeros for it. */ |
461 if (ret == -1 && errno == EFAULT) | 461 if (ret == -1 && errno == EFAULT) |
462 { | 462 { |
463 memset (zeros, 0, nwrite); | 463 memset (zeros, 0, nwrite); |
464 write (new, zeros, nwrite); | 464 write (new_, zeros, nwrite); |
465 } | 465 } |
466 else if (nwrite != ret) | 466 else if (nwrite != ret) |
467 { | 467 { |
468 sprintf (buf, | 468 sprintf (buf, |
469 "unexec write failure: addr 0x%lx, fileno %d, size 0x%x, wrote 0x%x, errno %d", | 469 "unexec write failure: addr 0x%lx, fileno %d, size 0x%x, wrote 0x%x, errno %d", |
470 (unsigned long)ptr, new, nwrite, ret, errno); | 470 (unsigned long)ptr, new_, nwrite, ret, errno); |
471 PERROR (buf); | 471 PERROR (buf); |
472 } | 472 } |
473 i += nwrite; | 473 i += nwrite; |
474 ptr += nwrite; | 474 ptr += nwrite; |
475 } | 475 } |
479 * copy_sym | 479 * copy_sym |
480 * | 480 * |
481 * Copy the relocation information and symbol table from the a.out to the new | 481 * Copy the relocation information and symbol table from the a.out to the new |
482 */ | 482 */ |
483 static int | 483 static int |
484 copy_sym (int new, int a_out, char *a_name, char *new_name) | 484 copy_sym (int new_, int a_out, char *a_name, char *new_name) |
485 { | 485 { |
486 char page[UnexBlockSz]; | 486 char page[UnexBlockSz]; |
487 int n; | 487 int n; |
488 | 488 |
489 if (a_out < 0) | 489 if (a_out < 0) |
497 else | 497 else |
498 lseek (a_out, orig_load_scnptr, SEEK_SET); /* Position a.out to symtab. */ | 498 lseek (a_out, orig_load_scnptr, SEEK_SET); /* Position a.out to symtab. */ |
499 | 499 |
500 while ((n = read (a_out, page, sizeof (page))) > 0) | 500 while ((n = read (a_out, page, sizeof (page))) > 0) |
501 { | 501 { |
502 if (write (new, page, n) != n) | 502 if (write (new_, page, n) != n) |
503 { | 503 { |
504 PERROR (new_name); | 504 PERROR (new_name); |
505 } | 505 } |
506 } | 506 } |
507 if (n < 0) | 507 if (n < 0) |
519 static void | 519 static void |
520 mark_x (char *name) | 520 mark_x (char *name) |
521 { | 521 { |
522 struct stat sbuf; | 522 struct stat sbuf; |
523 int um; | 523 int um; |
524 int new = 0; /* for PERROR */ | 524 int new_ = 0; /* for PERROR */ |
525 | 525 |
526 um = umask (777); | 526 um = umask (777); |
527 umask (um); | 527 umask (um); |
528 if (stat (name, &sbuf) == -1) | 528 if (stat (name, &sbuf) == -1) |
529 { | 529 { |
537 static int | 537 static int |
538 adjust_lnnoptrs (int UNUSED (writedesc), int UNUSED (readdesc), char *new_name) | 538 adjust_lnnoptrs (int UNUSED (writedesc), int UNUSED (readdesc), char *new_name) |
539 { | 539 { |
540 int nsyms; | 540 int nsyms; |
541 int naux; | 541 int naux; |
542 int new; | 542 int new_; |
543 struct syment symentry; | 543 struct syment symentry; |
544 union auxent auxentry; | 544 union auxent auxentry; |
545 | 545 |
546 if (!lnnoptr || !f_hdr.f_symptr) | 546 if (!lnnoptr || !f_hdr.f_symptr) |
547 return 0; | 547 return 0; |
548 | 548 |
549 if ((new = open (new_name, O_RDWR)) < 0) | 549 if ((new_ = open (new_name, O_RDWR)) < 0) |
550 { | 550 { |
551 PERROR (new_name); | 551 PERROR (new_name); |
552 return -1; | 552 return -1; |
553 } | 553 } |
554 | 554 |
555 lseek (new, f_hdr.f_symptr, SEEK_SET); | 555 lseek (new_, f_hdr.f_symptr, SEEK_SET); |
556 for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++) | 556 for (nsyms = 0; nsyms < f_hdr.f_nsyms; nsyms++) |
557 { | 557 { |
558 read (new, &symentry, SYMESZ); | 558 read (new_, &symentry, SYMESZ); |
559 if (symentry.n_sclass == C_BINCL || symentry.n_sclass == C_EINCL) | 559 if (symentry.n_sclass == C_BINCL || symentry.n_sclass == C_EINCL) |
560 { | 560 { |
561 symentry.n_value += bias; | 561 symentry.n_value += bias; |
562 lseek (new, -SYMESZ, SEEK_CUR); | 562 lseek (new_, -SYMESZ, SEEK_CUR); |
563 write (new, &symentry, SYMESZ); | 563 write (new_, &symentry, SYMESZ); |
564 } | 564 } |
565 | 565 |
566 for (naux = symentry.n_numaux; naux-- != 0; ) | 566 for (naux = symentry.n_numaux; naux-- != 0; ) |
567 { | 567 { |
568 read (new, &auxentry, AUXESZ); | 568 read (new_, &auxentry, AUXESZ); |
569 nsyms++; | 569 nsyms++; |
570 if (naux != 0 /* skip csect auxentry (last entry) */ | 570 if (naux != 0 /* skip csect auxentry (last entry) */ |
571 && (symentry.n_sclass == C_EXT || symentry.n_sclass == C_HIDEXT)) | 571 && (symentry.n_sclass == C_EXT || symentry.n_sclass == C_HIDEXT)) |
572 { | 572 { |
573 auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias; | 573 auxentry.x_sym.x_fcnary.x_fcn.x_lnnoptr += bias; |
574 lseek (new, -AUXESZ, SEEK_CUR); | 574 lseek (new_, -AUXESZ, SEEK_CUR); |
575 write (new, &auxentry, AUXESZ); | 575 write (new_, &auxentry, AUXESZ); |
576 } | 576 } |
577 } | 577 } |
578 } | 578 } |
579 close (new); | 579 close (new_); |
580 | 580 |
581 return 0; | 581 return 0; |
582 } | 582 } |
583 | 583 |
584 static int | 584 static int |
585 unrelocate_symbols (int new, int a_out, char *a_name, char *new_name) | 585 unrelocate_symbols (int new_, int a_out, char *a_name, char *new_name) |
586 { | 586 { |
587 int i; | 587 int i; |
588 LDHDR ldhdr; | 588 LDHDR ldhdr; |
589 LDREL ldrel; | 589 LDREL ldrel; |
590 ulong t_reloc = (ulong) &_text - f_ohdr.text_start; | 590 ulong t_reloc = (ulong) &_text - f_ohdr.text_start; |
624 /* move the BSS loader symbols to the DATA segment */ | 624 /* move the BSS loader symbols to the DATA segment */ |
625 if (ldrel.l_symndx == SYMNDX_BSS) | 625 if (ldrel.l_symndx == SYMNDX_BSS) |
626 { | 626 { |
627 ldrel.l_symndx = SYMNDX_DATA; | 627 ldrel.l_symndx = SYMNDX_DATA; |
628 | 628 |
629 lseek (new, | 629 lseek (new_, |
630 load_scnptr + LDHDRSZ + LDSYMSZ*ldhdr.l_nsyms + LDRELSZ*i, | 630 load_scnptr + LDHDRSZ + LDSYMSZ*ldhdr.l_nsyms + LDRELSZ*i, |
631 SEEK_SET); | 631 SEEK_SET); |
632 | 632 |
633 if (write (new, &ldrel, LDRELSZ) != LDRELSZ) | 633 if (write (new_, &ldrel, LDRELSZ) != LDRELSZ) |
634 { | 634 { |
635 PERROR (new_name); | 635 PERROR (new_name); |
636 } | 636 } |
637 } | 637 } |
638 | 638 |
663 break; | 663 break; |
664 } | 664 } |
665 | 665 |
666 if (orig_int != * p) | 666 if (orig_int != * p) |
667 { | 667 { |
668 lseek (new, | 668 lseek (new_, |
669 data_scnptr + (ldrel.l_vaddr - f_ohdr.data_start), | 669 data_scnptr + (ldrel.l_vaddr - f_ohdr.data_start), |
670 SEEK_SET); | 670 SEEK_SET); |
671 if (write (new, (void *) &orig_int, sizeof (orig_int)) | 671 if (write (new_, (void *) &orig_int, sizeof (orig_int)) |
672 != sizeof (orig_int)) | 672 != sizeof (orig_int)) |
673 { | 673 { |
674 PERROR (new_name); | 674 PERROR (new_name); |
675 } | 675 } |
676 } | 676 } |