diff options
| author | Andrew Innes | 1999-01-31 21:53:14 +0000 |
|---|---|---|
| committer | Andrew Innes | 1999-01-31 21:53:14 +0000 |
| commit | 7fef47a3894718ee161a88141b1b465fda13955a (patch) | |
| tree | 295b57db6f83110e383667d70818a27a2c1bbae6 /src | |
| parent | 7466aec434cabb63c909c6f9540d4d8c7af06cd8 (diff) | |
| download | emacs-7fef47a3894718ee161a88141b1b465fda13955a.tar.gz emacs-7fef47a3894718ee161a88141b1b465fda13955a.zip | |
(ROUND_UP_DST_AND_ZERO): New macro.
(copy_executable_and_dump_data): Use it to ensure alignment slop
is zeroed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/unexw32.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/unexw32.c b/src/unexw32.c index 4cdffac287d..743ce0086f6 100644 --- a/src/unexw32.c +++ b/src/unexw32.c | |||
| @@ -99,7 +99,7 @@ _start (void) | |||
| 99 | { | 99 | { |
| 100 | extern void mainCRTStartup (void); | 100 | extern void mainCRTStartup (void); |
| 101 | 101 | ||
| 102 | #if 0 | 102 | #if 1 |
| 103 | /* Give us a way to debug problems with crashes on startup when | 103 | /* Give us a way to debug problems with crashes on startup when |
| 104 | running under the MSVC profiler. */ | 104 | running under the MSVC profiler. */ |
| 105 | if (GetEnvironmentVariable ("EMACS_DEBUG", NULL, 0) > 0) | 105 | if (GetEnvironmentVariable ("EMACS_DEBUG", NULL, 0) > 0) |
| @@ -499,6 +499,14 @@ copy_executable_and_dump_data (file_data *p_infile, | |||
| 499 | #define DST_TO_OFFSET() PTR_TO_OFFSET (dst, p_outfile) | 499 | #define DST_TO_OFFSET() PTR_TO_OFFSET (dst, p_outfile) |
| 500 | #define ROUND_UP_DST(align) \ | 500 | #define ROUND_UP_DST(align) \ |
| 501 | (dst = p_outfile->file_base + ROUND_UP (DST_TO_OFFSET (), (align))) | 501 | (dst = p_outfile->file_base + ROUND_UP (DST_TO_OFFSET (), (align))) |
| 502 | #define ROUND_UP_DST_AND_ZERO(align) \ | ||
| 503 | do { \ | ||
| 504 | unsigned char *newdst = p_outfile->file_base \ | ||
| 505 | + ROUND_UP (DST_TO_OFFSET (), (align)); \ | ||
| 506 | /* Zero the alignment slop; it may actually initialize real data. */ \ | ||
| 507 | memset (dst, 0, newdst - dst); \ | ||
| 508 | dst = newdst; \ | ||
| 509 | } while (0) | ||
| 502 | 510 | ||
| 503 | /* Copy the source image sequentially, ie. section by section after | 511 | /* Copy the source image sequentially, ie. section by section after |
| 504 | copying the headers and section table, to simplify the process of | 512 | copying the headers and section table, to simplify the process of |
| @@ -522,13 +530,16 @@ copy_executable_and_dump_data (file_data *p_infile, | |||
| 522 | COPY_CHUNK ("Copying section table...", section, | 530 | COPY_CHUNK ("Copying section table...", section, |
| 523 | nt_header->FileHeader.NumberOfSections * sizeof (*section)); | 531 | nt_header->FileHeader.NumberOfSections * sizeof (*section)); |
| 524 | 532 | ||
| 533 | /* Align the first section's raw data area, and set the header size | ||
| 534 | field accordingly. */ | ||
| 535 | ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment); | ||
| 536 | dst_nt_header->OptionalHeader.SizeOfHeaders = DST_TO_OFFSET (); | ||
| 537 | |||
| 525 | for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++) | 538 | for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++) |
| 526 | { | 539 | { |
| 527 | char msg[100]; | 540 | char msg[100]; |
| 528 | sprintf (msg, "Copying raw data for %s...", section->Name); | 541 | sprintf (msg, "Copying raw data for %s...", section->Name); |
| 529 | 542 | ||
| 530 | /* Align the section's raw data area. */ | ||
| 531 | ROUND_UP_DST (dst_nt_header->OptionalHeader.FileAlignment); | ||
| 532 | dst_save = dst; | 543 | dst_save = dst; |
| 533 | 544 | ||
| 534 | /* Update the file-relative offset for this section's raw data (if | 545 | /* Update the file-relative offset for this section's raw data (if |
| @@ -541,6 +552,8 @@ copy_executable_and_dump_data (file_data *p_infile, | |||
| 541 | COPY_CHUNK | 552 | COPY_CHUNK |
| 542 | (msg, OFFSET_TO_PTR (section->PointerToRawData, p_infile), | 553 | (msg, OFFSET_TO_PTR (section->PointerToRawData, p_infile), |
| 543 | section->SizeOfRawData); | 554 | section->SizeOfRawData); |
| 555 | /* Ensure alignment slop is zeroed. */ | ||
| 556 | ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment); | ||
| 544 | 557 | ||
| 545 | /* Note that various sections below may be aliases. */ | 558 | /* Note that various sections below may be aliases. */ |
| 546 | if (section == data_section) | 559 | if (section == data_section) |
| @@ -608,13 +621,13 @@ copy_executable_and_dump_data (file_data *p_infile, | |||
| 608 | dst_section->Characteristics |= IMAGE_SCN_CNT_INITIALIZED_DATA; | 621 | dst_section->Characteristics |= IMAGE_SCN_CNT_INITIALIZED_DATA; |
| 609 | } | 622 | } |
| 610 | 623 | ||
| 624 | /* Align the section's raw data area. */ | ||
| 625 | ROUND_UP_DST (dst_nt_header->OptionalHeader.FileAlignment); | ||
| 626 | |||
| 611 | section++; | 627 | section++; |
| 612 | dst_section++; | 628 | dst_section++; |
| 613 | } | 629 | } |
| 614 | 630 | ||
| 615 | /* Pad out the final section raw data area. */ | ||
| 616 | ROUND_UP_DST (dst_nt_header->OptionalHeader.FileAlignment); | ||
| 617 | |||
| 618 | /* Copy remainder of source image. */ | 631 | /* Copy remainder of source image. */ |
| 619 | do | 632 | do |
| 620 | section--; | 633 | section--; |