*** ntheap0.h Wed Apr 16 00:13:00 1997 --- ntheap.h Thu May 22 17:17:22 1997 *************** *** 44,52 **** extern unsigned long data_region_size; extern unsigned long reserved_heap_size; extern SYSTEM_INFO sysinfo_cache; - extern BOOL need_to_recreate_heap; extern int nt_major_version; extern int nt_minor_version; enum { OS_WIN95 = 1, --- 44,56 ---- extern unsigned long data_region_size; extern unsigned long reserved_heap_size; extern SYSTEM_INFO sysinfo_cache; extern int nt_major_version; extern int nt_minor_version; + + /* To prevent zero-initialized variables from being placed into the bss + section, use non-zero values to represent an uninitialized state. */ + #define UNINIT_PTR ((void *) 0xF0A0F0A0) + #define UNINIT_LONG (0xF0A0F0A0L) enum { OS_WIN95 = 1, *** ntheap0.c Mon Apr 21 09:38:02 1997 --- ntheap.c Fri May 23 12:15:47 1997 *************** *** 87,97 **** } /* Info for keeping track of our heap. */ ! unsigned char *data_region_base = NULL; ! unsigned char *data_region_end = NULL; ! unsigned char *real_data_region_end = NULL; ! unsigned long data_region_size = 0; ! unsigned long reserved_heap_size = 0; /* The start of the data segment. */ unsigned char * --- 87,97 ---- } /* Info for keeping track of our heap. */ ! unsigned char *data_region_base = UNINIT_PTR; ! unsigned char *data_region_end = UNINIT_PTR; ! unsigned char *real_data_region_end = UNINIT_PTR; ! unsigned long data_region_size = UNINIT_LONG; ! unsigned long reserved_heap_size = UNINIT_LONG; /* The start of the data segment. */ unsigned char * *************** *** 150,155 **** --- 150,156 ---- unsigned long end = 1 << VALBITS; /* 256MB */ void *ptr = NULL; + #define NTHEAP_PROBE_BASE 1 #if NTHEAP_PROBE_BASE /* This is never normally defined */ /* Try various addresses looking for one the kernel will let us have. */ while (!ptr && (base < end)) *************** *** 182,188 **** long size = (long) increment; /* Allocate our heap if we haven't done so already. */ ! if (!data_region_base) { data_region_base = allocate_heap (); if (!data_region_base) --- 183,189 ---- long size = (long) increment; /* Allocate our heap if we haven't done so already. */ ! if (data_region_base == UNINIT_PTR) { data_region_base = allocate_heap (); if (!data_region_base) *** unexnt0.c Wed Apr 16 00:13:02 1997 --- unexnt.c Fri May 23 12:12:37 1997 *************** *** 39,49 **** unsigned char *file_base; } file_data; /* Basically, our "initialized" flag. */ ! BOOL need_to_recreate_heap = FALSE; /* So we can find our heap in the file to recreate it. */ ! unsigned long heap_index_in_executable = 0; void open_input_file (file_data *p_file, char *name); void open_output_file (file_data *p_file, char *name, unsigned long size); --- 39,55 ---- unsigned char *file_base; } file_data; + enum { + HEAP_UNINITIALIZED = 1, + HEAP_UNLOADED, + HEAP_LOADED + }; + /* Basically, our "initialized" flag. */ ! int heap_state = HEAP_UNINITIALIZED; /* So we can find our heap in the file to recreate it. */ ! unsigned long heap_index_in_executable = UNINIT_LONG; void open_input_file (file_data *p_file, char *name); void open_output_file (file_data *p_file, char *name, unsigned long size); *************** *** 54,66 **** void dump_bss_and_heap (file_data *p_infile, file_data *p_outfile); /* Cached info about the .data section in the executable. */ ! PUCHAR data_start_va = 0; ! DWORD data_start_file = 0; ! DWORD data_size = 0; /* Cached info about the .bss section in the executable. */ ! PUCHAR bss_start = 0; ! DWORD bss_size = 0; #ifdef HAVE_NTGUI HINSTANCE hinst = NULL; --- 60,72 ---- void dump_bss_and_heap (file_data *p_infile, file_data *p_outfile); /* Cached info about the .data section in the executable. */ ! PUCHAR data_start_va = UNINIT_PTR; ! DWORD data_start_file = UNINIT_LONG; ! DWORD data_size = UNINIT_LONG; /* Cached info about the .bss section in the executable. */ ! PUCHAR bss_start = UNINIT_PTR; ! DWORD bss_size = UNINIT_LONG; #ifdef HAVE_NTGUI HINSTANCE hinst = NULL; *************** *** 93,99 **** start up. (WARNING: Do not put any code before this section that relies upon malloc () and runs in the dumped version. It won't work.) */ ! if (need_to_recreate_heap) { char executable_path[MAX_PATH]; --- 99,105 ---- start up. (WARNING: Do not put any code before this section that relies upon malloc () and runs in the dumped version. It won't work.) */ ! if (heap_state == HEAP_UNLOADED) { char executable_path[MAX_PATH]; *************** *** 116,122 **** } recreate_heap (executable_path); ! need_to_recreate_heap = FALSE; } else { --- 122,128 ---- } recreate_heap (executable_path); ! heap_state = HEAP_LOADED; } else { *************** *** 185,191 **** open_output_file (&out_file, out_filename, size); /* Set the flag (before dumping). */ ! need_to_recreate_heap = TRUE; copy_executable_and_dump_data_section (&in_file, &out_file); dump_bss_and_heap (&in_file, &out_file); --- 191,197 ---- open_output_file (&out_file, out_filename, size); /* Set the flag (before dumping). */ ! heap_state = HEAP_UNLOADED; copy_executable_and_dump_data_section (&in_file, &out_file); dump_bss_and_heap (&in_file, &out_file); *************** *** 413,419 **** section++; } ! if (!bss_start && !bss_size) { /* Starting with MSVC 4.0, the .bss section has been eliminated and appended virtually to the end of the .data section. Our --- 419,425 ---- section++; } ! if (bss_start == UNINIT_PTR && bss_size == UNINIT_LONG) { /* Starting with MSVC 4.0, the .bss section has been eliminated and appended virtually to the end of the .data section. Our