Mercurial > hg > xemacs-beta
comparison src/unexnt.c @ 282:c42ec1d1cded r21-0b39
Import from CVS: tag r21-0b39
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:33:18 +0200 |
parents | 41ff10fd062f |
children | 57709be46d1b |
comparison
equal
deleted
inserted
replaced
281:090b52736db2 | 282:c42ec1d1cded |
---|---|
505 /* Load the dumped .bss section into the .bss area of our address space. */ | 505 /* Load the dumped .bss section into the .bss area of our address space. */ |
506 void | 506 void |
507 read_in_bss (char *filename) | 507 read_in_bss (char *filename) |
508 { | 508 { |
509 HANDLE file; | 509 HANDLE file; |
510 unsigned long size, index, n_read, total_read; | 510 unsigned long index, n_read; |
511 char buffer[512], *bss; | |
512 int i; | |
513 | 511 |
514 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, | 512 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
515 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); | 513 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
516 if (file == INVALID_HANDLE_VALUE) | 514 if (file == INVALID_HANDLE_VALUE) |
517 { | 515 abort (); |
518 i = GetLastError (); | 516 |
519 exit (1); | |
520 } | |
521 | |
522 /* Seek to where the .bss section is tucked away after the heap... */ | 517 /* Seek to where the .bss section is tucked away after the heap... */ |
523 index = heap_index_in_executable + get_committed_heap_size (); | 518 index = heap_index_in_executable + get_committed_heap_size (); |
524 if (SetFilePointer (file, index, NULL, FILE_BEGIN) == 0xFFFFFFFF) | 519 if (SetFilePointer (file, index, NULL, FILE_BEGIN) == 0xFFFFFFFF) |
525 { | 520 abort (); |
526 i = GetLastError (); | 521 |
527 exit (1); | |
528 } | |
529 | |
530 | |
531 /* Ok, read in the saved .bss section and initialize all | 522 /* Ok, read in the saved .bss section and initialize all |
532 uninitialized variables. */ | 523 uninitialized variables. */ |
533 if (!ReadFile (file, bss_start, bss_size, &n_read, NULL)) | 524 if (!ReadFile (file, bss_start, bss_size, &n_read, NULL)) |
534 { | 525 abort (); |
535 i = GetLastError (); | |
536 exit (1); | |
537 } | |
538 | 526 |
539 CloseHandle (file); | 527 CloseHandle (file); |
540 } | 528 } |
541 | 529 |
542 /* Map the heap dumped into the executable file into our address space. */ | 530 /* Map the heap dumped into the executable file into our address space. */ |
545 { | 533 { |
546 HANDLE file; | 534 HANDLE file; |
547 HANDLE file_mapping; | 535 HANDLE file_mapping; |
548 void *file_base; | 536 void *file_base; |
549 unsigned long size, upper_size, n_read; | 537 unsigned long size, upper_size, n_read; |
550 int i; | |
551 | 538 |
552 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, | 539 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
553 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); | 540 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
554 if (file == INVALID_HANDLE_VALUE) | 541 if (file == INVALID_HANDLE_VALUE) |
555 { | 542 abort (); |
556 i = GetLastError (); | 543 |
557 exit (1); | |
558 } | |
559 | |
560 size = GetFileSize (file, &upper_size); | 544 size = GetFileSize (file, &upper_size); |
561 file_mapping = CreateFileMapping (file, NULL, PAGE_WRITECOPY, | 545 file_mapping = CreateFileMapping (file, NULL, PAGE_WRITECOPY, |
562 0, size, NULL); | 546 0, size, NULL); |
563 if (!file_mapping) | 547 if (!file_mapping) |
564 { | 548 abort (); |
565 i = GetLastError (); | 549 |
566 exit (1); | |
567 } | |
568 | |
569 size = get_committed_heap_size (); | 550 size = get_committed_heap_size (); |
570 file_base = MapViewOfFileEx (file_mapping, FILE_MAP_COPY, 0, | 551 file_base = MapViewOfFileEx (file_mapping, FILE_MAP_COPY, 0, |
571 heap_index_in_executable, size, | 552 heap_index_in_executable, size, |
572 get_heap_start ()); | 553 get_heap_start ()); |
573 if (file_base != 0) | 554 if (file_base != 0) |
580 | 561 |
581 CloseHandle (file_mapping); | 562 CloseHandle (file_mapping); |
582 | 563 |
583 if (VirtualAlloc (get_heap_start (), get_committed_heap_size (), | 564 if (VirtualAlloc (get_heap_start (), get_committed_heap_size (), |
584 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) == NULL) | 565 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) == NULL) |
585 { | 566 abort (); |
586 i = GetLastError (); | |
587 exit (1); | |
588 } | |
589 | 567 |
590 /* Seek to the location of the heap data in the executable. */ | 568 /* Seek to the location of the heap data in the executable. */ |
591 i = heap_index_in_executable; | 569 if (SetFilePointer (file, heap_index_in_executable, |
592 if (SetFilePointer (file, i, NULL, FILE_BEGIN) == 0xFFFFFFFF) | 570 NULL, FILE_BEGIN) == 0xFFFFFFFF) |
593 { | 571 abort (); |
594 i = GetLastError (); | |
595 exit (1); | |
596 } | |
597 | 572 |
598 /* Read in the data. */ | 573 /* Read in the data. */ |
599 if (!ReadFile (file, get_heap_start (), | 574 if (!ReadFile (file, get_heap_start (), |
600 get_committed_heap_size (), &n_read, NULL)) | 575 get_committed_heap_size (), &n_read, NULL)) |
601 { | 576 abort (); |
602 i = GetLastError (); | |
603 exit (1); | |
604 } | |
605 | 577 |
606 CloseHandle (file); | 578 CloseHandle (file); |
607 } | 579 } |