comparison src/unexnt.c @ 286:57709be46d1b r21-0b41

Import from CVS: tag r21-0b41
author cvs
date Mon, 13 Aug 2007 10:35:03 +0200
parents c42ec1d1cded
children 70ad99077275
comparison
equal deleted inserted replaced
285:9a3756523c1b 286:57709be46d1b
428 } 428 }
429 429
430 430
431 /* The dump routines. */ 431 /* The dump routines. */
432 432
433 #ifdef DEBUG_XEMACS
434 #define DUMP_MSG(x) printf x
435 #else
436 #define DUMP_MSG(x)
437 #endif
438
433 static void 439 static void
434 copy_executable_and_dump_data_section (file_data *p_infile, 440 copy_executable_and_dump_data_section (file_data *p_infile,
435 file_data *p_outfile) 441 file_data *p_outfile)
436 { 442 {
437 unsigned char *data_file, *data_va; 443 unsigned char *data_file, *data_va;
438 unsigned long size, index; 444 unsigned long size, index;
439 445
440 /* Get a pointer to where the raw data should go in the executable file. */ 446 /* Get a pointer to where the raw data should go in the executable file. */
441 data_file = (char *) p_outfile->file_base + data_start_file; 447 data_file = (char *) p_outfile->file_base + data_start_file;
442 448
443 /* Get a pointer to the raw data in our address space. */ 449 /* Get a pointer to the raw data in our address space. */
444 data_va = data_start_va; 450 data_va = data_start_va;
445 451
446 size = (DWORD) data_file - (DWORD) p_outfile->file_base; 452 size = (DWORD) data_file - (DWORD) p_outfile->file_base;
447 printf ("Copying executable up to data section...\n"); 453 DUMP_MSG (("Copying executable up to data section...\n"));
448 printf ("\t0x%08x Offset in input file.\n", 0); 454 DUMP_MSG (("\t0x%08x Offset in input file.\n", 0));
449 printf ("\t0x%08x Offset in output file.\n", 0); 455 DUMP_MSG (("\t0x%08x Offset in output file.\n", 0));
450 printf ("\t0x%08x Size in bytes.\n", size); 456 DUMP_MSG (("\t0x%08x Size in bytes.\n", size));
451 memcpy (p_outfile->file_base, p_infile->file_base, size); 457 memcpy (p_outfile->file_base, p_infile->file_base, size);
452 458
453 size = data_size; 459 size = data_size;
454 printf ("Dumping .data section...\n"); 460 DUMP_MSG (("Dumping .data section...\n"));
455 printf ("\t0x%08x Address in process.\n", data_va); 461 DUMP_MSG (("\t0x%08x Address in process.\n", data_va));
456 printf ("\t0x%08x Offset in output file.\n", 462 DUMP_MSG (("\t0x%08x Offset in output file.\n",
457 data_file - p_outfile->file_base); 463 data_file - p_outfile->file_base));
458 printf ("\t0x%08x Size in bytes.\n", size); 464 DUMP_MSG (("\t0x%08x Size in bytes.\n", size));
459 memcpy (data_file, data_va, size); 465 memcpy (data_file, data_va, size);
460 466
461 index = (DWORD) data_file + size - (DWORD) p_outfile->file_base; 467 index = (DWORD) data_file + size - (DWORD) p_outfile->file_base;
462 size = p_infile->size - index; 468 size = p_infile->size - index;
463 printf ("Copying rest of executable...\n"); 469 DUMP_MSG (("Copying rest of executable...\n"));
464 printf ("\t0x%08x Offset in input file.\n", index); 470 DUMP_MSG (("\t0x%08x Offset in input file.\n", index));
465 printf ("\t0x%08x Offset in output file.\n", index); 471 DUMP_MSG (("\t0x%08x Offset in output file.\n", index));
466 printf ("\t0x%08x Size in bytes.\n", size); 472 DUMP_MSG (("\t0x%08x Size in bytes.\n", size));
467 memcpy ((char *) p_outfile->file_base + index, 473 memcpy ((char *) p_outfile->file_base + index,
468 (char *) p_infile->file_base + index, size); 474 (char *) p_infile->file_base + index, size);
469 } 475 }
470 476
471 static void 477 static void
472 dump_bss_and_heap (file_data *p_infile, file_data *p_outfile) 478 dump_bss_and_heap (file_data *p_infile, file_data *p_outfile)
473 { 479 {
474 unsigned char *heap_data, *bss_data; 480 unsigned char *heap_data, *bss_data;
475 unsigned long size, index; 481 unsigned long size, index;
476 482
477 printf ("Dumping heap into executable...\n"); 483 DUMP_MSG (("Dumping heap into executable...\n"));
478 484
479 index = heap_index_in_executable; 485 index = heap_index_in_executable;
480 size = get_committed_heap_size (); 486 size = get_committed_heap_size ();
481 heap_data = get_heap_start (); 487 heap_data = get_heap_start ();
482 488
483 printf ("\t0x%08x Heap start in process.\n", heap_data); 489 DUMP_MSG (("\t0x%08x Heap start in process.\n", heap_data));
484 printf ("\t0x%08x Heap offset in executable.\n", index); 490 DUMP_MSG (("\t0x%08x Heap offset in executable.\n", index));
485 printf ("\t0x%08x Heap size in bytes.\n", size); 491 DUMP_MSG (("\t0x%08x Heap size in bytes.\n", size));
486 492
487 memcpy ((PUCHAR) p_outfile->file_base + index, heap_data, size); 493 memcpy ((PUCHAR) p_outfile->file_base + index, heap_data, size);
488 494
489 printf ("Dumping .bss into executable...\n"); 495 DUMP_MSG (("Dumping .bss into executable...\n"));
490 496
491 index += size; 497 index += size;
492 size = bss_size; 498 size = bss_size;
493 bss_data = bss_start; 499 bss_data = bss_start;
494 500
495 printf ("\t0x%08x BSS start in process.\n", bss_data); 501 DUMP_MSG (("\t0x%08x BSS start in process.\n", bss_data));
496 printf ("\t0x%08x BSS offset in executable.\n", index); 502 DUMP_MSG (("\t0x%08x BSS offset in executable.\n", index));
497 printf ("\t0x%08x BSS size in bytes.\n", size); 503 DUMP_MSG (("\t0x%08x BSS size in bytes.\n", size));
498 memcpy ((char *) p_outfile->file_base + index, bss_data, size); 504 memcpy ((char *) p_outfile->file_base + index, bss_data, size);
499 } 505 }
500 506
507 #undef DUMP_MSG
501 508
502 /* Reload and remap routines. */ 509 /* Reload and remap routines. */
503 510
504 511
505 /* Load the dumped .bss section into the .bss area of our address space. */ 512 /* Load the dumped .bss section into the .bss area of our address space. */