From 1a46ca7d8a2d49597c9cf2bcc6606563f3b98410 Mon Sep 17 00:00:00 2001 From: David Welch Date: Sat, 17 Aug 2002 01:42:03 +0000 Subject: [PATCH] 2002-08-17 David Welch * ntoskrnl/ps/create.c (PiDeleteThread): Don't dereference the thread's process while holding the thread list lock. 2002-08-17 David Welch * ntoskrnl/mm/section.c (MmMapViewOfSection): Check there is enough space for all parts of an image before mapping it; if there isn't enough space free at the preferred base address then try to choose a different one. 2002-08-17 David Welch * ntoskrnl/mm/mpw.c (MmInitMpwThread): Run the MPW thread at idle priority. 2002-08-17 David Welch * ntoskrnl/mm/kmap.c (ExUnmapPage, ExAllocatePageWithPhysPage, MiFreeNonPagedPoolRegion, MiAllocNonPagedPoolRegion): Maintain a hint of the next free page; makes running with whole page allocation more bearable. 2002-08-17 David Welch * ntoskrnl/mm/anonmem.c (MmPageOutVirtualMemory): Show an out of swap space message if we are out of swap space. * ntoskrnl/mm/section.c (MmPageOutSectionView): Show an out of swap space message if we are out of swap space. * ntoskrnl/mm/pagefile.c (MmAllocSwapPage): Don't automatically show an out of swap space message on failure. * ntoskrnl/mm/pagefile.c (MmShowOutOfSpaceMessagePagingFile): New function to notify the user that the pagefile is full. 2002-08-17 David Welch * drivers/lib/zlib/Makefile: Create a dummy zlib.sym svn path=/trunk/; revision=3335 --- reactos/ChangeLog | 39 ++++++++++ reactos/drivers/lib/zlib/Makefile | 5 +- reactos/ntoskrnl/include/internal/mm.h | 4 +- reactos/ntoskrnl/include/internal/ps.h | 3 +- reactos/ntoskrnl/mm/anonmem.c | 3 +- reactos/ntoskrnl/mm/kmap.c | 44 ++++++----- reactos/ntoskrnl/mm/marea.c | 52 ++----------- reactos/ntoskrnl/mm/mpw.c | 101 +++++++++++++------------ reactos/ntoskrnl/mm/pagefile.c | 33 ++++---- reactos/ntoskrnl/mm/section.c | 54 +++++++++++-- reactos/ntoskrnl/ps/create.c | 28 ++----- reactos/ntoskrnl/ps/thread.c | 4 +- 12 files changed, 210 insertions(+), 160 deletions(-) diff --git a/reactos/ChangeLog b/reactos/ChangeLog index c1a2a999b96..32d5fcb1440 100644 --- a/reactos/ChangeLog +++ b/reactos/ChangeLog @@ -1,3 +1,42 @@ +2002-08-17 David Welch + + * ntoskrnl/ps/create.c (PiDeleteThread): Don't dereference + the thread's process while holding the thread list lock. + +2002-08-17 David Welch + + * ntoskrnl/mm/section.c (MmMapViewOfSection): Check there is + enough space for all parts of an image before mapping it; if + there isn't enough space free at the preferred base address + then try to choose a different one. + +2002-08-17 David Welch + + * ntoskrnl/mm/mpw.c (MmInitMpwThread): Run the MPW thread at + idle priority. + +2002-08-17 David Welch + + * ntoskrnl/mm/kmap.c (ExUnmapPage, ExAllocatePageWithPhysPage, + MiFreeNonPagedPoolRegion, MiAllocNonPagedPoolRegion): Maintain + a hint of the next free page; makes running with whole page + allocation more bearable. + +2002-08-17 David Welch + + * ntoskrnl/mm/anonmem.c (MmPageOutVirtualMemory): Show an + out of swap space message if we are out of swap space. + * ntoskrnl/mm/section.c (MmPageOutSectionView): Show an + out of swap space message if we are out of swap space. + * ntoskrnl/mm/pagefile.c (MmAllocSwapPage): Don't automatically + show an out of swap space message on failure. + * ntoskrnl/mm/pagefile.c (MmShowOutOfSpaceMessagePagingFile): New + function to notify the user that the pagefile is full. + +2002-08-17 David Welch + + * drivers/lib/zlib/Makefile: Create a dummy zlib.sym + 2002-08-16 David Welch * ntoskrnl/mm/npool.c (ExAllocateWholePageBlock): Converted diff --git a/reactos/drivers/lib/zlib/Makefile b/reactos/drivers/lib/zlib/Makefile index 8f7bbf4c93d..3f7415b8e66 100644 --- a/reactos/drivers/lib/zlib/Makefile +++ b/reactos/drivers/lib/zlib/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.4 2002/06/16 06:05:28 sedwards Exp $ +# $Id: Makefile,v 1.5 2002/08/17 01:42:01 dwelch Exp $ PATH_TO_TOP = ../../.. @@ -18,6 +18,9 @@ include $(PATH_TO_TOP)/rules.mak include $(TOOLS_PATH)/helper.mk +zlib.sym: + @echo FIXME!>$@ + # FIXME: this rule should be defined in helper.mk $(TARGET_NAME).nostrip.a: @echo FIXME! diff --git a/reactos/ntoskrnl/include/internal/mm.h b/reactos/ntoskrnl/include/internal/mm.h index a35c59bb7e0..fa31f219a7d 100644 --- a/reactos/ntoskrnl/include/internal/mm.h +++ b/reactos/ntoskrnl/include/internal/mm.h @@ -288,7 +288,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace, MEMORY_AREA* MmOpenMemoryAreaByRegion(PMADDRESS_SPACE AddressSpace, PVOID Address, ULONG Length); - +PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, ULONG Length); VOID ExUnmapPage(PVOID Addr); PVOID ExAllocatePage(VOID); @@ -604,5 +604,7 @@ MmIsDirtyPageRmap(PHYSICAL_ADDRESS PhysicalAddress); NTSTATUS MmInitMpwThread(VOID); BOOLEAN MmIsAvailableSwapPage(VOID); +VOID +MmShowOutOfSpaceMessagePagingFile(VOID); #endif diff --git a/reactos/ntoskrnl/include/internal/ps.h b/reactos/ntoskrnl/include/internal/ps.h index 38183833c99..cc3c1d9acd4 100644 --- a/reactos/ntoskrnl/include/internal/ps.h +++ b/reactos/ntoskrnl/include/internal/ps.h @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: ps.h,v 1.40 2002/08/16 01:39:16 dwelch Exp $ +/* $Id: ps.h,v 1.41 2002/08/17 01:42:02 dwelch Exp $ * * FILE: ntoskrnl/ke/kthread.c * PURPOSE: Process manager definitions @@ -419,7 +419,6 @@ VOID PiKillMostProcesses(VOID); NTSTATUS STDCALL PiTerminateProcess(PEPROCESS Process, NTSTATUS ExitStatus); VOID PiInitApcManagement(VOID); VOID STDCALL PiDeleteThread(PVOID ObjectBody); -VOID STDCALL PiCloseThread(PVOID ObjectBody, ULONG HandleCount); VOID PsReapThreads(VOID); NTSTATUS PsInitializeThread(HANDLE ProcessHandle, diff --git a/reactos/ntoskrnl/mm/anonmem.c b/reactos/ntoskrnl/mm/anonmem.c index da2c04cedfe..439c730fc55 100644 --- a/reactos/ntoskrnl/mm/anonmem.c +++ b/reactos/ntoskrnl/mm/anonmem.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: anonmem.c,v 1.2 2002/08/14 20:58:36 dwelch Exp $ +/* $Id: anonmem.c,v 1.3 2002/08/17 01:42:02 dwelch Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/mm/anonmem.c @@ -187,6 +187,7 @@ MmPageOutVirtualMemory(PMADDRESS_SPACE AddressSpace, SwapEntry = MmAllocSwapPage(); if (SwapEntry == 0) { + MmShowOutOfSpaceMessagePagingFile(); MmEnableVirtualMapping(MemoryArea->Process, Address); PageOp->Status = STATUS_UNSUCCESSFUL; KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE); diff --git a/reactos/ntoskrnl/mm/kmap.c b/reactos/ntoskrnl/mm/kmap.c index 9ce78ae1bbe..da5bfe8474d 100644 --- a/reactos/ntoskrnl/mm/kmap.c +++ b/reactos/ntoskrnl/mm/kmap.c @@ -1,4 +1,4 @@ -/* $Id: kmap.c,v 1.17 2002/06/04 15:26:56 dwelch Exp $ +/* $Id: kmap.c,v 1.18 2002/08/17 01:42:02 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -13,6 +13,7 @@ #include #include #include +#include #define NDEBUG #include @@ -25,8 +26,9 @@ * One bit for each page in the kmalloc region * If set then the page is used by a kmalloc block */ -static unsigned int AllocMap[ALLOC_MAP_SIZE/32]={0,}; +static ULONG AllocMap[ALLOC_MAP_SIZE/32]={0,}; static KSPIN_LOCK AllocMapLock; +static ULONG AllocMapHint = 1; static PVOID NonPagedPoolBase; @@ -41,9 +43,10 @@ ExUnmapPage(PVOID Addr) DPRINT("ExUnmapPage(Addr %x)\n",Addr); DPRINT("i %x\n",i); - KeAcquireSpinLock(&AllocMapLock, &oldIrql); MmDeleteVirtualMapping(NULL, (PVOID)Addr, FALSE, NULL, NULL); + KeAcquireSpinLock(&AllocMapLock, &oldIrql); AllocMap[i / 32] &= (~(1 << (i % 32))); + AllocMapHint = min(AllocMapHint, i); KeReleaseSpinLock(&AllocMapLock, oldIrql); } @@ -101,12 +104,13 @@ ExAllocatePageWithPhysPage(PHYSICAL_ADDRESS PhysPage) NTSTATUS Status; KeAcquireSpinLock(&AllocMapLock, &oldlvl); - for (i = 1; i < ALLOC_MAP_SIZE; i++) + for (i = AllocMapHint; i < ALLOC_MAP_SIZE; i++) { if (!(AllocMap[i / 32] & (1 << (i % 32)))) { DPRINT("i %x\n",i); AllocMap[i / 32] |= (1 << (i % 32)); + AllocMapHint = i + 1; addr = (ULONG)(NonPagedPoolBase + (i*PAGESIZE)); Status = MmCreateVirtualMapping(NULL, (PVOID)addr, @@ -142,10 +146,11 @@ MiFreeNonPagedPoolRegion(PVOID Addr, ULONG Count, BOOLEAN Free) KIRQL oldlvl; KeAcquireSpinLock(&AllocMapLock, &oldlvl); + AllocMapHint = min(AllocMapHint, Base); for (i = 0; i < Count; i++) { Offset = Base + i; - AllocMap[Offset / 32] &= (~(1 << (Offset % 32))); + AllocMap[Offset / 32] &= (~(1 << (Offset % 32))); MmDeleteVirtualMapping(NULL, Addr + (i * PAGESIZE), Free, @@ -167,7 +172,7 @@ MiAllocNonPagedPoolRegion(ULONG nr_pages) KIRQL oldlvl; KeAcquireSpinLock(&AllocMapLock, &oldlvl); - for (i=1; iMAreaListHead); - previous_entry = &AddressSpace->MAreaListHead; current_entry = AddressSpace->MAreaListHead.Flink; while (current_entry != &AddressSpace->MAreaListHead) @@ -80,22 +78,7 @@ MEMORY_AREA* MmOpenMemoryAreaByAddress(PMADDRESS_SPACE AddressSpace, current = CONTAINING_RECORD(current_entry, MEMORY_AREA, Entry); - DPRINT("Scanning %x BaseAddress %x Length %x\n", - current, current->BaseAddress, current->Length); assert(current_entry->Blink->Flink == current_entry); - if (current_entry->Flink->Blink != current_entry) - { - DPRINT1("BaseAddress %x\n", current->BaseAddress); - DPRINT1("current_entry->Flink %x ", current_entry->Flink); - DPRINT1("¤t_entry->Flink %x\n", - ¤t_entry->Flink); - DPRINT1("current_entry->Flink->Blink %x\n", - current_entry->Flink->Blink); - DPRINT1("¤t_entry->Flink->Blink %x\n", - ¤t_entry->Flink->Blink); - DPRINT1("¤t_entry->Flink %x\n", - ¤t_entry->Flink); - } assert(current_entry->Flink->Blink == current_entry); assert(previous_entry->Flink == current_entry); if (current->BaseAddress <= Address && @@ -184,38 +167,24 @@ static VOID MmInsertMemoryArea(PMADDRESS_SPACE AddressSpace, ListHead = &AddressSpace->MAreaListHead; current_entry = ListHead->Flink; - CHECKPOINT; if (IsListEmpty(ListHead)) { - CHECKPOINT; InsertHeadList(ListHead,&marea->Entry); - DPRINT("Inserting at list head\n"); - CHECKPOINT; return; } - CHECKPOINT; current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry); - CHECKPOINT; if (current->BaseAddress > marea->BaseAddress) { - CHECKPOINT; InsertHeadList(ListHead,&marea->Entry); - DPRINT("Inserting at list head\n"); - CHECKPOINT; return; } - CHECKPOINT; while (current_entry->Flink!=ListHead) { -// CHECKPOINT; current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry); next = CONTAINING_RECORD(current_entry->Flink,MEMORY_AREA,Entry); -// assert(current->BaseAddress != marea->BaseAddress); -// assert(next->BaseAddress != marea->BaseAddress); if (current->BaseAddress < marea->BaseAddress && current->Entry.Flink==ListHead) { - DPRINT("Insert after %x\n", current_entry); current_entry->Flink = inserted_entry; inserted_entry->Flink=ListHead; inserted_entry->Blink=current_entry; @@ -225,7 +194,6 @@ static VOID MmInsertMemoryArea(PMADDRESS_SPACE AddressSpace, if (current->BaseAddress < marea->BaseAddress && next->BaseAddress > marea->BaseAddress) { - DPRINT("Inserting before %x\n", current_entry); inserted_entry->Flink = current_entry->Flink; inserted_entry->Blink = current_entry; inserted_entry->Flink->Blink = inserted_entry; @@ -234,13 +202,10 @@ static VOID MmInsertMemoryArea(PMADDRESS_SPACE AddressSpace, } current_entry = current_entry->Flink; } - CHECKPOINT; - DPRINT("Inserting at list tail\n"); InsertTailList(ListHead,inserted_entry); } -static PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, - ULONG Length) +PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, ULONG Length) { PLIST_ENTRY ListHead; PLIST_ENTRY current_entry; @@ -257,12 +222,7 @@ static PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, { current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry); next = CONTAINING_RECORD(current_entry->Flink,MEMORY_AREA,Entry); - DPRINT("current %x current->BaseAddress %x ",current, - current->BaseAddress); - DPRINT("current->Length %x\n",current->Length); - DPRINT("next %x next->BaseAddress %x ",next,next->BaseAddress); Gap = (next->BaseAddress ) -(current->BaseAddress + current->Length); - DPRINT("Base %x Gap %x\n",current->BaseAddress,Gap); if (Gap >= Length) { return(current->BaseAddress + PAGE_ROUND_UP(current->Length)); @@ -276,8 +236,6 @@ static PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, } current = CONTAINING_RECORD(current_entry,MEMORY_AREA,Entry); - //DbgPrint("current %x returning %x\n",current,current->BaseAddress+ -// current->Length); return(current->BaseAddress + PAGE_ROUND_UP(current->Length)); } @@ -294,15 +252,17 @@ NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace, PVOID BaseAddress, ULONG Length, - VOID (*FreePage)(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, - PHYSICAL_ADDRESS PhysAddr, SWAPENTRY SwapEntry, BOOLEAN Dirty), + VOID (*FreePage)(PVOID Context, MEMORY_AREA* MemoryArea, + PVOID Address, PHYSICAL_ADDRESS PhysAddr, + SWAPENTRY SwapEntry, BOOLEAN Dirty), PVOID FreePageContext) { MEMORY_AREA* MemoryArea; ULONG i; DPRINT("MmFreeMemoryArea(AddressSpace %x, BaseAddress %x, Length %x," - "FreePageContext %d)\n",AddressSpace,BaseAddress,Length,FreePageContext); + "FreePageContext %d)\n",AddressSpace,BaseAddress,Length, + FreePageContext); MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace, BaseAddress); diff --git a/reactos/ntoskrnl/mm/mpw.c b/reactos/ntoskrnl/mm/mpw.c index a3f72e8c9eb..0133a9c4ad0 100644 --- a/reactos/ntoskrnl/mm/mpw.c +++ b/reactos/ntoskrnl/mm/mpw.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: mpw.c,v 1.8 2002/08/14 20:58:36 dwelch Exp $ +/* $Id: mpw.c,v 1.9 2002/08/17 01:42:02 dwelch Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/mm/mpw.c @@ -74,55 +74,62 @@ MmWriteDirtyPages(ULONG Target, PULONG Actual) NTSTATUS STDCALL MmMpwThreadMain(PVOID Ignored) { - NTSTATUS Status; - ULONG PagesWritten; - LARGE_INTEGER Timeout; - - Timeout.QuadPart = -50000000; - - for(;;) - { - Status = KeWaitForSingleObject(&MpwThreadEvent, - 0, - KernelMode, - FALSE, - &Timeout); - if (!NT_SUCCESS(Status)) - { - DbgPrint("MpwThread: Wait failed\n"); - KeBugCheck(0); - return(STATUS_UNSUCCESSFUL); - } - if (MpwThreadShouldTerminate) - { - DbgPrint("MpwThread: Terminating\n"); - return(STATUS_SUCCESS); - } - - PagesWritten = 0; - MmWriteDirtyPages(128, &PagesWritten); - CcRosFlushDirtyPages(128, &PagesWritten); - } + NTSTATUS Status; + ULONG PagesWritten; + LARGE_INTEGER Timeout; + + Timeout.QuadPart = -50000000; + + for(;;) + { + Status = KeWaitForSingleObject(&MpwThreadEvent, + 0, + KernelMode, + FALSE, + &Timeout); + if (!NT_SUCCESS(Status)) + { + DbgPrint("MpwThread: Wait failed\n"); + KeBugCheck(0); + return(STATUS_UNSUCCESSFUL); + } + if (MpwThreadShouldTerminate) + { + DbgPrint("MpwThread: Terminating\n"); + return(STATUS_SUCCESS); + } + + PagesWritten = 0; + MmWriteDirtyPages(128, &PagesWritten); + CcRosFlushDirtyPages(128, &PagesWritten); + } } NTSTATUS MmInitMpwThread(VOID) { - NTSTATUS Status; - - MpwThreadShouldTerminate = FALSE; - KeInitializeEvent(&MpwThreadEvent, SynchronizationEvent, FALSE); - - Status = PsCreateSystemThread(&MpwThreadHandle, - THREAD_ALL_ACCESS, - NULL, - NULL, - &MpwThreadId, - MmMpwThreadMain, - NULL); - if (!NT_SUCCESS(Status)) - { - return(Status); + KPRIORITY Priority; + NTSTATUS Status; + + MpwThreadShouldTerminate = FALSE; + KeInitializeEvent(&MpwThreadEvent, SynchronizationEvent, FALSE); + + Status = PsCreateSystemThread(&MpwThreadHandle, + THREAD_ALL_ACCESS, + NULL, + NULL, + &MpwThreadId, + MmMpwThreadMain, + NULL); + if (!NT_SUCCESS(Status)) + { + return(Status); } - - return(STATUS_SUCCESS); + + Priority = 1; + NtSetInformationThread(MpwThreadHandle, + ThreadPriority, + &Priority, + sizeof(Priority)); + + return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/mm/pagefile.c b/reactos/ntoskrnl/mm/pagefile.c index ab9d0252b5b..dfcba690991 100644 --- a/reactos/ntoskrnl/mm/pagefile.c +++ b/reactos/ntoskrnl/mm/pagefile.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: pagefile.c,v 1.22 2002/08/14 20:58:36 dwelch Exp $ +/* $Id: pagefile.c,v 1.23 2002/08/17 01:42:02 dwelch Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/mm/pagefile.c @@ -105,8 +105,20 @@ ULONG MmCoreDumpType; #define OFFSET_FROM_ENTRY(i) (((i) & 0xffffff) - 1) #define ENTRY_FROM_FILE_OFFSET(i, j) (((i) << 24) | ((j) + 1)) +static BOOLEAN MmSwapSpaceMessage = FALSE; + /* FUNCTIONS *****************************************************************/ +VOID +MmShowOutOfSpaceMessagePagingFile(VOID) +{ + if (!MmSwapSpaceMessage) + { + DPRINT1("MM: Out of swap space.\n"); + MmSwapSpaceMessage = TRUE; + } +} + NTSTATUS MmWriteToSwapPage(SWAPENTRY SwapEntry, PMDL Mdl) { ULONG i, offset; @@ -316,19 +328,13 @@ MmAllocSwapPage(VOID) KIRQL oldIrql; ULONG i; ULONG off; - SWAPENTRY entry; - static BOOLEAN SwapSpaceMessage = FALSE; + SWAPENTRY entry; KeAcquireSpinLock(&PagingFileListLock, &oldIrql); if (MiFreeSwapPages == 0) { - KeReleaseSpinLock(&PagingFileListLock, oldIrql); - if (!SwapSpaceMessage) - { - DPRINT1("MM: Out of swap space.\n"); - SwapSpaceMessage = TRUE; - } + KeReleaseSpinLock(&PagingFileListLock, oldIrql); return(0); } @@ -354,11 +360,7 @@ MmAllocSwapPage(VOID) } KeReleaseSpinLock(&PagingFileListLock, oldIrql); - if (!SwapSpaceMessage) - { - DPRINT1("MM: Out of swap space.\n"); - SwapSpaceMessage = TRUE; - } + KeBugCheck(0); return(0); } @@ -658,6 +660,9 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName, } } NtClose(FileHandle); + + MmSwapSpaceMessage = FALSE; + return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index 2fba5f16fab..284640b4f5c 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: section.c,v 1.89 2002/08/14 20:58:37 dwelch Exp $ +/* $Id: section.c,v 1.90 2002/08/17 01:42:02 dwelch Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/mm/section.c @@ -1387,6 +1387,8 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace, SwapEntry = MmAllocSwapPage(); if (SwapEntry == 0) { + MmShowOutOfSpaceMessagePagingFile(); + /* * For private pages restore the old mappings. */ @@ -3286,16 +3288,56 @@ MmMapViewOfSection(IN PVOID SectionObject, if (Section->AllocationAttributes & SEC_IMAGE) { ULONG i; - + PVOID ImageBase; + ULONG ImageSize; + + ImageBase = *BaseAddress; + if (ImageBase == NULL) + { + ImageBase = Section->ImageBase; + } + + ImageSize = 0; for (i = 0; i < Section->NrSegments; i++) { - PVOID SBaseAddress; + if (!(Section->Segments[i].Characteristics & IMAGE_SECTION_NOLOAD)) + { + ULONG MaxExtent; + MaxExtent = (ULONG)(Section->Segments[i].VirtualAddress + + Section->Segments[i].Length); + ImageSize = max(ImageSize, MaxExtent); + } + } + /* Check there is enough space to map the section at that point. */ + if (MmOpenMemoryAreaByRegion(AddressSpace, ImageBase, + ImageSize) != NULL) + { + /* Fail if the user requested a fixed base address. */ + if ((*BaseAddress) != NULL) + { + MmUnlockSection(Section); + MmUnlockAddressSpace(AddressSpace); + return(Status); + } + /* Otherwise find a gap to map the image. */ + ImageBase = MmFindGap(AddressSpace, ImageSize); + if (ImageBase == NULL) + { + MmUnlockSection(Section); + MmUnlockAddressSpace(AddressSpace); + return(Status); + } + } + + for (i = 0; i < Section->NrSegments; i++) + { + PVOID SBaseAddress; + if (!(Section->Segments[i].Characteristics & IMAGE_SECTION_NOLOAD)) { SBaseAddress = (PVOID) - ((ULONG)Section->ImageBase + - (ULONG)Section->Segments[i].VirtualAddress); + (ImageBase + (ULONG_PTR)Section->Segments[i].VirtualAddress); MmLockSectionSegment(&Section->Segments[i]); Status = MmMapViewOfSegment(Process, @@ -3315,7 +3357,7 @@ MmMapViewOfSection(IN PVOID SectionObject, } } } - *BaseAddress = Section->ImageBase; + *BaseAddress = ImageBase; } else { diff --git a/reactos/ntoskrnl/ps/create.c b/reactos/ntoskrnl/ps/create.c index 075f169c3e7..53f631b7902 100644 --- a/reactos/ntoskrnl/ps/create.c +++ b/reactos/ntoskrnl/ps/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.50 2002/08/14 20:58:38 dwelch Exp $ +/* $Id: create.c,v 1.51 2002/08/17 01:42:03 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -279,24 +279,21 @@ PiDeleteThread(PVOID ObjectBody) KIRQL oldIrql; PETHREAD Thread; ULONG i; + Thread = (PETHREAD)ObjectBody; DPRINT("PiDeleteThread(ObjectBody %x)\n",ObjectBody); - KeAcquireSpinLock(&PiThreadListLock, &oldIrql); - Thread = (PETHREAD)ObjectBody; + ObDereferenceObject(Thread->ThreadsProcess); + Thread->ThreadsProcess = NULL; + KeAcquireSpinLock(&PiThreadListLock, &oldIrql); + for (i = 0; i < PiThreadNotifyRoutineCount; i++) { PiThreadNotifyRoutine[i](Thread->Cid.UniqueProcess, Thread->Cid.UniqueThread, FALSE); - } - - DPRINT("Process %x(%d)\n", - Thread->ThreadsProcess, - ObGetObjectPointerCount(Thread->ThreadsProcess)); - ObDereferenceObject(Thread->ThreadsProcess); - Thread->ThreadsProcess = NULL; + } PiNrThreads--; RemoveEntryList(&Thread->Tcb.ThreadListEntry); KeReleaseThread(Thread); @@ -304,17 +301,6 @@ PiDeleteThread(PVOID ObjectBody) DPRINT("PiDeleteThread() finished\n"); } -VOID STDCALL -PiCloseThread(PVOID ObjectBody, - ULONG HandleCount) -{ - DPRINT("PiCloseThread(ObjectBody %x)\n", ObjectBody); - DPRINT("ObGetObjectPointerCount(ObjectBody) %d " - "ObGetObjectHandleCount(ObjectBody) %d\n", - ObGetObjectPointerCount(ObjectBody), - ObGetObjectHandleCount(ObjectBody)); -} - NTSTATUS PsInitializeThread(HANDLE ProcessHandle, PETHREAD* ThreadPtr, diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index 5a4f1234adf..8d2cbdb303d 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -1,4 +1,4 @@ -/* $Id: thread.c,v 1.102 2002/08/16 01:39:16 dwelch Exp $ +/* $Id: thread.c,v 1.103 2002/08/17 01:42:03 dwelch Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -426,7 +426,7 @@ PsInitThreadManagment(VOID) PsThreadType->Mapping = &PiThreadMapping; PsThreadType->Dump = NULL; PsThreadType->Open = NULL; - PsThreadType->Close = PiCloseThread; + PsThreadType->Close = NULL; PsThreadType->Delete = PiDeleteThread; PsThreadType->Parse = NULL; PsThreadType->Security = NULL;