- Fix/update w32api PE headers
- Implement proper PEB creation, set all necessary fields and read data
from PE Header and Config Directory. Fixes "corruption" issue with
console apps.
Modified: trunk/reactos/lib/kernel32/process/create.c
Modified: trunk/reactos/ntoskrnl/mm/process.c
Modified: trunk/reactos/w32api/include/winnt.h
_____
Modified: trunk/reactos/lib/kernel32/process/create.c
--- trunk/reactos/lib/kernel32/process/create.c 2005-07-28 22:34:11 UTC
(rev 16845)
+++ trunk/reactos/lib/kernel32/process/create.c 2005-07-28 22:43:24 UTC
(rev 16846)
@@ -1380,7 +1380,7 @@
lpProcessInformation->hThread = hThread;
DPRINT("hThread[%lx]: %lx inside hProcess[%lx]: %lx\n", hThread,
ClientId.UniqueThread, ClientId.UniqueProcess, hProcess);
- hProcess = hThread = NULL;
+ hProcess = hThread = NULL;
/* De-allocate heap strings */
if (NameBuffer) RtlFreeHeap(GetProcessHeap(), 0, NameBuffer);
_____
Modified: trunk/reactos/ntoskrnl/mm/process.c
--- trunk/reactos/ntoskrnl/mm/process.c 2005-07-28 22:34:11 UTC (rev
16845)
+++ trunk/reactos/ntoskrnl/mm/process.c 2005-07-28 22:43:24 UTC (rev
16846)
@@ -16,6 +16,7 @@
extern ULONG NtMajorVersion;
extern ULONG NtMinorVersion;
extern ULONG NtOSCSDVersion;
+extern ULONG NtGlobalFlag;
/* FUNCTIONS
*****************************************************************/
@@ -220,7 +221,10 @@
LARGE_INTEGER SectionOffset;
ULONG ViewSize = 0;
PVOID TableBase = NULL;
+ PIMAGE_NT_HEADERS NtHeaders;
+ PIMAGE_LOAD_CONFIG_DIRECTORY ImageConfigData;
NTSTATUS Status;
+ KAFFINITY ProcessAffinityMask = 0;
SectionOffset.QuadPart = (ULONGLONG)0;
DPRINT("MmCreatePeb\n");
@@ -257,18 +261,88 @@
/* Set up data */
DPRINT("Setting up PEB\n");
Peb->ImageBaseAddress = Process->SectionBaseAddress;
+ Peb->InheritedAddressSpace = 0;
+ Peb->Mutant = NULL;
+
+ /* NLS */
+ Peb->AnsiCodePageData = (char*)TableBase + NlsAnsiTableOffset;
+ Peb->OemCodePageData = (char*)TableBase + NlsOemTableOffset;
+ Peb->UnicodeCaseTableData = (char*)TableBase +
NlsUnicodeTableOffset;
+
+ /* Default Version Data (could get changed below) */
Peb->OSMajorVersion = NtMajorVersion;
Peb->OSMinorVersion = NtMinorVersion;
Peb->OSBuildNumber = 2195;
- Peb->OSPlatformId = 2; //VER_PLATFORM_WIN32_NT;
+ Peb->OSPlatformId = 2; /* VER_PLATFORM_WIN32_NT */
Peb->OSCSDVersion = NtOSCSDVersion;
- Peb->AnsiCodePageData = (char*)TableBase + NlsAnsiTableOffset;
- Peb->OemCodePageData = (char*)TableBase + NlsOemTableOffset;
- Peb->UnicodeCaseTableData = (char*)TableBase +
NlsUnicodeTableOffset;
+
+ /* Heap and Debug Data */
Peb->NumberOfProcessors = KeNumberProcessors;
Peb->BeingDebugged = (BOOLEAN)(Process->DebugPort != NULL ? TRUE :
FALSE);
+ Peb->NtGlobalFlag = NtGlobalFlag;
+ /*Peb->HeapSegmentReserve = MmHeapSegmentReserve;
+ Peb->HeapSegmentCommit = MmHeapSegmentCommit;
+ Peb->HeapDeCommitTotalFreeThreshold =
MmHeapDeCommitTotalFreeThreshold;
+ Peb->HeapDeCommitFreeBlockThreshold =
MmHeapDeCommitFreeBlockThreshold;*/
+ Peb->NumberOfHeaps = 0;
+ Peb->MaximumNumberOfHeaps = (PAGE_SIZE - sizeof(PEB)) /
sizeof(PVOID);
+ Peb->ProcessHeaps = (PVOID*)Peb + 1;
+ /* Image Data */
+ if ((NtHeaders = RtlImageNtHeader(Peb->ImageBaseAddress)))
+ {
+ /* Get the Image Config Data too */
+ ImageConfigData =
RtlImageDirectoryEntryToData(Peb->ImageBaseAddress,
+ TRUE,
+
IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,
+ &ViewSize);
+
+ /* Write subsystem data */
+ Peb->ImageSubSystem = NtHeaders->OptionalHeader.Subsystem;
+ Peb->ImageSubSystemMajorVersion =
NtHeaders->OptionalHeader.MajorSubsystemVersion;
+ Peb->ImageSubSystemMinorVersion =
NtHeaders->OptionalHeader.MinorSubsystemVersion;
+
+ /* Write Version Data */
+ if (NtHeaders->OptionalHeader.Win32VersionValue)
+ {
+ Peb->OSMajorVersion =
NtHeaders->OptionalHeader.Win32VersionValue & 0xFF;
+ Peb->OSMinorVersion =
(NtHeaders->OptionalHeader.Win32VersionValue >> 8) & 0xFF;
+ Peb->OSBuildNumber =
(NtHeaders->OptionalHeader.Win32VersionValue >> 16) & 0x3FFF;
+
+ /* Lie about the version if requested */
+ if (ImageConfigData && ImageConfigData->CSDVersion)
+ {
+ Peb->OSCSDVersion = ImageConfigData->CSDVersion;
+ }
+
+ /* Set the Platform ID */
+ Peb->OSPlatformId =
(NtHeaders->OptionalHeader.Win32VersionValue >> 30) ^ 2;
+ }
+
+ /* Check for affinity override */
+ if (ImageConfigData && ImageConfigData->ProcessAffinityMask)
+ {
+ ProcessAffinityMask = ImageConfigData->ProcessAffinityMask;
+ }
+
+ /* Check if the image is not safe for SMP */
+ if (NtHeaders->FileHeader.Characteristics &
IMAGE_FILE_UP_SYSTEM_ONLY)
+ {
+ /* FIXME: Choose one randomly */
+ Peb->ImageProcessAffinityMask = 1;
+ }
+ else
+ {
+ /* Use affinity from Image Header */
+ Peb->ImageProcessAffinityMask = ProcessAffinityMask;
+ }
+ }
+
+ /* Misc data */
+ Peb->SessionId = Process->Session;
Process->Peb = Peb;
+
+ /* Detach from the Process */
KeDetachProcess();
DPRINT("MmCreatePeb: Peb created at %p\n", Peb);
_____
Modified: trunk/reactos/w32api/include/winnt.h
--- trunk/reactos/w32api/include/winnt.h 2005-07-28 22:34:11 UTC
(rev 16845)
+++ trunk/reactos/w32api/include/winnt.h 2005-07-28 22:43:24 UTC
(rev 16846)
@@ -2554,7 +2554,7 @@
WORD MinorImageVersion;
WORD MajorSubsystemVersion;
WORD MinorSubsystemVersion;
- DWORD Reserved1;
+ DWORD Win32VersionValue;
DWORD SizeOfImage;
DWORD SizeOfHeaders;
DWORD CheckSum;
@@ -2900,20 +2900,26 @@
DWORD Reserved;
} IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY;
typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
- DWORD Characteristics;
- DWORD TimeDateStamp;
- WORD MajorVersion;
- WORD MinorVersion;
- DWORD GlobalFlagsClear;
- DWORD GlobalFlagsSet;
- DWORD CriticalSectionDefaultTimeout;
- DWORD DeCommitFreeBlockThreshold;
- DWORD DeCommitTotalFreeThreshold;
- PVOID LockPrefixTable;
- DWORD MaximumAllocationSize;
- DWORD VirtualMemoryThreshold;
- DWORD ProcessHeapFlags;
- DWORD Reserved[4];
+ DWORD Size;
+ DWORD TimeDateStamp;
+ WORD MajorVersion;
+ WORD MinorVersion;
+ DWORD GlobalFlagsClear;
+ DWORD GlobalFlagsSet;
+ DWORD CriticalSectionDefaultTimeout;
+ DWORD DeCommitFreeBlockThreshold;
+ DWORD DeCommitTotalFreeThreshold;
+ DWORD LockPrefixTable;
+ DWORD MaximumAllocationSize;
+ DWORD VirtualMemoryThreshold;
+ DWORD ProcessHeapFlags;
+ DWORD ProcessAffinityMask;
+ WORD CSDVersion;
+ WORD Reserved1;
+ DWORD EditList;
+ DWORD SecurityCookie;
+ DWORD SEHandlerTable;
+ DWORD SEHandlerCount;
} IMAGE_LOAD_CONFIG_DIRECTORY,*PIMAGE_LOAD_CONFIG_DIRECTORY;
typedef struct _IMAGE_RUNTIME_FUNCTION_ENTRY {
DWORD BeginAddress;
Show replies by date