From 3e519811c456593288cd54ff49ecfc52e22f6b3a Mon Sep 17 00:00:00 2001 From: David Welch Date: Wed, 24 May 2000 22:29:38 +0000 Subject: [PATCH] More bug fixes. svn path=/trunk/; revision=1158 --- reactos/include/internal/mm.h | 6 +- reactos/lib/ntdll/ldr/startup.c | 8 +-- reactos/ntoskrnl/kd/kdebug.c | 8 +-- reactos/ntoskrnl/ke/i386/exp.c | 14 +++++ reactos/ntoskrnl/ke/i386/usercall.c | 4 +- reactos/ntoskrnl/mm/mm.c | 4 +- reactos/ntoskrnl/mm/section.c | 90 ++++++++++++++++++++++++++++- 7 files changed, 118 insertions(+), 16 deletions(-) diff --git a/reactos/include/internal/mm.h b/reactos/include/internal/mm.h index bbe3ec60a2b..83f0b0471ab 100644 --- a/reactos/include/internal/mm.h +++ b/reactos/include/internal/mm.h @@ -26,8 +26,10 @@ enum MEMORY_AREA_CACHE_SEGMENT, }; -#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) ((x) / (4*1024*1024)) -#define PAGE_TO_SECTION_PAGE_TABLE_OFFSET(x) (((x) % 4*1024*1024) / (4*1024)) +#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \ + ((x) / (4*1024*1024)) +#define PAGE_TO_SECTION_PAGE_TABLE_OFFSET(x) \ + ((((x)) % (4*1024*1024)) / (4*1024)) #define NR_SECTION_PAGE_TABLES (1024) #define NR_SECTION_PAGE_ENTRIES (1024) diff --git a/reactos/lib/ntdll/ldr/startup.c b/reactos/lib/ntdll/ldr/startup.c index 729d850afcb..117496f3853 100644 --- a/reactos/lib/ntdll/ldr/startup.c +++ b/reactos/lib/ntdll/ldr/startup.c @@ -1,4 +1,4 @@ -/* $Id: startup.c,v 1.22 2000/03/22 18:35:51 dwelch Exp $ +/* $Id: startup.c,v 1.23 2000/05/24 22:29:35 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -18,7 +18,7 @@ #include #include -#define NDEBUG +//#define NDEBUG #include /* GLOBALS *******************************************************************/ @@ -57,7 +57,7 @@ VOID LdrStartup(VOID) if (ImageBase <= (PVOID)0x1000) { DPRINT("ImageBase is null\n"); - for(;;); + ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL); } NtGlobalFlag = Peb->NtGlobalFlag; @@ -70,7 +70,7 @@ VOID LdrStartup(VOID) *(PULONG)((PUCHAR)ImageBase + PEDosHeader->e_lfanew) != IMAGE_PE_MAGIC) { DbgPrint("Image has bad header\n"); - ZwTerminateProcess(NULL, STATUS_UNSUCCESSFUL); + ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL); } /* normalize process parameters */ diff --git a/reactos/ntoskrnl/kd/kdebug.c b/reactos/ntoskrnl/kd/kdebug.c index 1b7cf1d32a6..47dc8b95e7c 100644 --- a/reactos/ntoskrnl/kd/kdebug.c +++ b/reactos/ntoskrnl/kd/kdebug.c @@ -1,4 +1,4 @@ -/* $Id: kdebug.c,v 1.10 2000/04/08 19:09:30 ekohl Exp $ +/* $Id: kdebug.c,v 1.11 2000/05/24 22:29:36 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -43,7 +43,7 @@ KdDebuggerNotPresent = TRUE; /* EXPORTED */ static BOOLEAN KdpBreakPending = FALSE; static BOOLEAN KdpBreakRecieved = FALSE; -static ULONG KdpDebugType = 0; +static ULONG KdpDebugType = BochsDebug; /* PRIVATE FUNCTIONS ********************************************************/ @@ -134,7 +134,7 @@ KdInitSystem ( if (Value > 0) { KdDebuggerEnabled = TRUE; - KdpDebugType = SerialDebug; + KdpDebugType = KdpDebugType | SerialDebug; PortInfo.BaudRate = Value; } break; @@ -152,7 +152,7 @@ KdInitSystem ( { p2 += 5; KdDebuggerEnabled = TRUE; - KdpDebugType = SerialDebug; + KdpDebugType = KdpDebugType | SerialDebug; break; } p1 = p2; diff --git a/reactos/ntoskrnl/ke/i386/exp.c b/reactos/ntoskrnl/ke/i386/exp.c index ff2cc21451a..7ff024b137e 100644 --- a/reactos/ntoskrnl/ke/i386/exp.c +++ b/reactos/ntoskrnl/ke/i386/exp.c @@ -339,6 +339,20 @@ asmlinkage void exception_handler(unsigned int edi, } } } + + if (MmIsPagePresent(NULL, (PVOID)eip)) + { + char instrs[512]; + + memcpy(instrs, (PVOID)eip, 512); + + DbgPrint("Instrs: "); + + for (i=0; i<10; i++) + { + DbgPrint("%x ", instrs[i]); + } + } #endif } diff --git a/reactos/ntoskrnl/ke/i386/usercall.c b/reactos/ntoskrnl/ke/i386/usercall.c index 609396480e8..c203d6ec740 100644 --- a/reactos/ntoskrnl/ke/i386/usercall.c +++ b/reactos/ntoskrnl/ke/i386/usercall.c @@ -1,4 +1,4 @@ -/* $Id: usercall.c,v 1.11 2000/05/13 13:51:05 dwelch Exp $ +/* $Id: usercall.c,v 1.12 2000/05/24 22:29:36 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -57,7 +57,7 @@ void PsBeginThreadWithContextInternal(void); VOID KiSystemCallHook(ULONG Nr, ...) { -#if 1 +#if 0 va_list ap; ULONG i; diff --git a/reactos/ntoskrnl/mm/mm.c b/reactos/ntoskrnl/mm/mm.c index e7f58c94280..ba5e3358474 100644 --- a/reactos/ntoskrnl/mm/mm.c +++ b/reactos/ntoskrnl/mm/mm.c @@ -1,4 +1,4 @@ -/* $Id: mm.c,v 1.29 2000/05/13 13:51:05 dwelch Exp $ +/* $Id: mm.c,v 1.30 2000/05/24 22:29:36 dwelch Exp $ * * COPYRIGHT: See COPYING in the top directory * PROJECT: ReactOS kernel @@ -146,7 +146,7 @@ NTSTATUS MmNotPresentFault(KPROCESSOR_MODE Mode, MEMORY_AREA* MemoryArea; NTSTATUS Status; - DPRINT1("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address); + DPRINT("MmNotPresentFault(Mode %d, Address %x)\n", Mode, Address); if (KeGetCurrentIrql() >= DISPATCH_LEVEL) { diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index 1cac491b380..782be787ee7 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -1,4 +1,4 @@ -/* $Id: section.c,v 1.30 2000/05/13 13:51:05 dwelch Exp $ +/* $Id: section.c,v 1.31 2000/05/24 22:29:38 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -56,6 +56,8 @@ VOID MmSetPageEntrySection(PSECTION_OBJECT Section, Table = Section->PageDirectory.PageTables[DirectoryOffset] = ExAllocatePool(NonPagedPool, sizeof(SECTION_PAGE_TABLE)); + memset(Table, 0, sizeof(SECTION_PAGE_TABLE)); + DPRINT("Table %x\n", Table); } TableOffset = PAGE_TO_SECTION_PAGE_TABLE_OFFSET(Offset); Table->Pages[TableOffset] = Entry; @@ -69,8 +71,11 @@ PVOID MmGetPageEntrySection(PSECTION_OBJECT Section, ULONG DirectoryOffset; ULONG TableOffset; + DPRINT("MmGetPageEntrySection(Offset %x)\n", Offset); + DirectoryOffset = PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(Offset); Table = Section->PageDirectory.PageTables[DirectoryOffset]; + DPRINT("Table %x\n", Table); if (Table == NULL) { return(NULL); @@ -80,6 +85,70 @@ PVOID MmGetPageEntrySection(PSECTION_OBJECT Section, return(Entry); } +NTSTATUS MmOldLoadPageForSection(PMADDRESS_SPACE AddressSpace, + MEMORY_AREA* MemoryArea, + PVOID Address) +{ + LARGE_INTEGER Offset; + IO_STATUS_BLOCK IoStatus; + PMDL Mdl; + PVOID Page; + NTSTATUS Status; + ULONG PAddress; + PSECTION_OBJECT Section; + + DPRINT("MmOldLoadPageForSection(MemoryArea %x, Address %x)\n", + MemoryArea,Address); + + if (MmIsPagePresent(NULL, Address)) + { + DPRINT("Page is already present\n"); + return(STATUS_SUCCESS); + } + + PAddress = (ULONG)PAGE_ROUND_DOWN(((ULONG)Address)); + Offset.QuadPart = (PAddress - (ULONG)MemoryArea->BaseAddress) + + MemoryArea->Data.SectionData.ViewOffset; + + DPRINT("MemoryArea->BaseAddress %x\n", MemoryArea->BaseAddress); + DPRINT("MemoryArea->Data.SectionData.ViewOffset %x\n", + MemoryArea->Data.SectionData.ViewOffset); + DPRINT("Got offset %x\n", Offset.QuadPart); + + Section = MemoryArea->Data.SectionData.Section; + + DPRINT("Section %x\n", Section); + + MmLockSection(Section); + + Mdl = MmCreateMdl(NULL, NULL, PAGESIZE); + MmBuildMdlFromPages(Mdl); + Page = MmGetMdlPageAddress(Mdl, 0); + MmUnlockSection(Section); + MmUnlockAddressSpace(AddressSpace); + DPRINT("Reading file offset %x\n", Offset.QuadPart); + Status = IoPageRead(MemoryArea->Data.SectionData.Section->FileObject, + Mdl, + &Offset, + &IoStatus); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + MmLockAddressSpace(AddressSpace); + MmLockSection(Section); + + MmSetPage(NULL, + Address, + MemoryArea->Attributes, + (ULONG)Page); + MmUnlockSection(Section); + + return(STATUS_SUCCESS); + +} + NTSTATUS MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace, MEMORY_AREA* MemoryArea, PVOID Address) @@ -98,6 +167,7 @@ NTSTATUS MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace, if (MmIsPagePresent(NULL, Address)) { + DPRINT("Page is already present\n"); return(STATUS_SUCCESS); } @@ -105,11 +175,25 @@ NTSTATUS MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace, Offset.QuadPart = (PAddress - (ULONG)MemoryArea->BaseAddress) + MemoryArea->Data.SectionData.ViewOffset; + if ((MemoryArea->Data.SectionData.ViewOffset % PAGESIZE) != 0) + { + return(MmOldLoadPageForSection(AddressSpace, MemoryArea, Address)); + } + + DPRINT("MemoryArea->BaseAddress %x\n", MemoryArea->BaseAddress); + DPRINT("MemoryArea->Data.SectionData.ViewOffset %x\n", + MemoryArea->Data.SectionData.ViewOffset); + DPRINT("Got offset %x\n", Offset.QuadPart); + Section = MemoryArea->Data.SectionData.Section; + DPRINT("Section %x\n", Section); + MmLockSection(Section); - Entry = MmGetPageEntrySection(Section, Offset.QuadPart); + Entry = MmGetPageEntrySection(Section, Offset.u.LowPart); + + DPRINT("Entry %x\n", Entry); if (Entry == NULL) { @@ -118,6 +202,7 @@ NTSTATUS MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace, Page = MmGetMdlPageAddress(Mdl, 0); MmUnlockSection(Section); MmUnlockAddressSpace(AddressSpace); + DPRINT("Reading file offset %x\n", Offset.QuadPart); Status = IoPageRead(MemoryArea->Data.SectionData.Section->FileObject, Mdl, &Offset, @@ -294,6 +379,7 @@ NTSTATUS STDCALL NtCreateSection (OUT PHANDLE SectionHandle, InitializeListHead(&Section->ViewListHead); KeInitializeSpinLock(&Section->ViewListLock); KeInitializeMutex(&Section->Lock, 0); + memset(&Section->PageDirectory, 0, sizeof(Section->PageDirectory)); if (FileHandle != (HANDLE)0xffffffff) {