diff --git a/reactos/ntoskrnl/dbgk/dbgkutil.c b/reactos/ntoskrnl/dbgk/dbgkutil.c index 9a6b91d3c3d..5476c14e33a 100644 --- a/reactos/ntoskrnl/dbgk/dbgkutil.c +++ b/reactos/ntoskrnl/dbgk/dbgkutil.c @@ -19,7 +19,7 @@ NTAPI DbgkpSectionToFileHandle(IN PVOID Section) { NTSTATUS Status; - UNICODE_STRING FileName; + POBJECT_NAME_INFORMATION FileName; OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; HANDLE Handle; @@ -31,7 +31,7 @@ DbgkpSectionToFileHandle(IN PVOID Section) /* Initialize object attributes */ InitializeObjectAttributes(&ObjectAttributes, - &FileName, + &FileName->Name, OBJ_CASE_INSENSITIVE | OBJ_FORCE_ACCESS_CHECK | OBJ_KERNEL_HANDLE, @@ -39,15 +39,17 @@ DbgkpSectionToFileHandle(IN PVOID Section) NULL); /* Open the file */ + DPRINT1("Trying to open: %wZ\n", &FileName->Name); Status = ZwOpenFile(&Handle, GENERIC_READ | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_NONALERT); + DPRINT1("Status: %lx\n", Status); /* Free the name and return the handle if we succeeded */ - ExFreePool(FileName.Buffer); + ExFreePool(FileName); if (!NT_SUCCESS(Status)) return NULL; return Handle; } @@ -91,7 +93,8 @@ DbgkCreateThread(PVOID StartAddress) ULONG ProcessFlags; IMAGE_INFO ImageInfo; PIMAGE_NT_HEADERS NtHeader; - UNICODE_STRING ModuleName; + POBJECT_NAME_INFORMATION ModuleName; + UNICODE_STRING NtDllName; NTSTATUS Status; PVOID DebugPort; DBGKM_MSG ApiMessage; @@ -130,10 +133,10 @@ DbgkCreateThread(PVOID StartAddress) if (NT_SUCCESS(Status)) { /* Call the notify routines and free the name */ - PspRunLoadImageNotifyRoutines(&ModuleName, + PspRunLoadImageNotifyRoutines(&ModuleName->Name, Process->UniqueProcessId, &ImageInfo); - ExFreePool(ModuleName.Buffer); + ExFreePool(ModuleName); } else { @@ -160,9 +163,9 @@ DbgkCreateThread(PVOID StartAddress) } /* Call the notify routines */ - RtlInitUnicodeString(&ModuleName, + RtlInitUnicodeString(&NtDllName, L"\\SystemRoot\\System32\\ntdll.dll"); - PspRunLoadImageNotifyRoutines(&ModuleName, + PspRunLoadImageNotifyRoutines(&NtDllName, Process->UniqueProcessId, &ImageInfo); } diff --git a/reactos/ntoskrnl/dbgk/debug.c b/reactos/ntoskrnl/dbgk/debug.c index 4c7087bd04d..ce276aa75ce 100644 --- a/reactos/ntoskrnl/dbgk/debug.c +++ b/reactos/ntoskrnl/dbgk/debug.c @@ -653,14 +653,17 @@ DbgkpPostFakeThreadMessages(IN PEPROCESS Process, if (First) { /* So we'll start with the create process message */ + DPRINT1("new proces!\n"); ApiMessage.ApiNumber = DbgKmCreateProcessApi; /* Get the file handle */ + DPRINT1("section object: %p\n", Process->SectionObject); if (Process->SectionObject) { /* Use the section object */ CreateProcess->FileHandle = DbgkpSectionToFileHandle(Process->SectionObject); + DPRINT1("FileHandle: %p\n", CreateProcess->FileHandle); } else { @@ -669,7 +672,9 @@ DbgkpPostFakeThreadMessages(IN PEPROCESS Process, } /* Set the base address */ + DPRINT1("SectionBaseAddress: %p\n", Process->SectionBaseAddress); CreateProcess->BaseOfImage = Process->SectionBaseAddress; + KEBUGCHECK(0); /* Get the NT Header */ NtHeader = RtlImageNtHeader(Process->SectionBaseAddress); diff --git a/reactos/ntoskrnl/include/internal/mm.h b/reactos/ntoskrnl/include/internal/mm.h index 63b10d15589..768947c45be 100644 --- a/reactos/ntoskrnl/include/internal/mm.h +++ b/reactos/ntoskrnl/include/internal/mm.h @@ -1326,7 +1326,7 @@ NTSTATUS NTAPI MmGetFileNameForSection( IN PROS_SECTION_OBJECT Section, - OUT PUNICODE_STRING ModuleName + OUT POBJECT_NAME_INFORMATION *ModuleName ); PVOID diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index 95d5fdd1d70..d9e7eec90fd 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -109,10 +109,40 @@ MmGetFileObjectForSection(IN PROS_SECTION_OBJECT Section) NTSTATUS NTAPI MmGetFileNameForSection(IN PROS_SECTION_OBJECT Section, - OUT PUNICODE_STRING ModuleName) + OUT POBJECT_NAME_INFORMATION *ModuleName) { - /* FIXME: TODO. ObQueryNameString on the FileObject */ - RtlCreateUnicodeString(ModuleName, L"C:\\ReactOS\\system32\\ntdll.dll"); + POBJECT_NAME_INFORMATION ObjectNameInfo; + NTSTATUS Status; + ULONG ReturnLength; + + /* Make sure it's an image section */ + *ModuleName = NULL; + if (!(Section->AllocationAttributes & SEC_IMAGE)) + { + /* It's not, fail */ + return STATUS_SECTION_NOT_IMAGE; + } + + /* Allocate memory for our structure */ + ObjectNameInfo = ExAllocatePoolWithTag(PagedPool, + 1024, + TAG('M', 'm', ' ', ' ')); + if (!ObjectNameInfo) return STATUS_NO_MEMORY; + + /* Query the name */ + Status = ObQueryNameString(Section->FileObject, + ObjectNameInfo, + 1024, + &ReturnLength); + if (!NT_SUCCESS(Status)) + { + /* Failed, free memory */ + ExFreePool(ObjectNameInfo); + return Status; + } + + /* Success */ + *ModuleName = ObjectNameInfo; return STATUS_SUCCESS; }