2005-05-13 03:34:13 +00:00
|
|
|
/*
|
2006-10-02 13:23:03 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: ntoskrnl/ex/lookas.c
|
|
|
|
* PURPOSE: Lookaside Lists
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
*/
|
2005-01-26 13:58:37 +00:00
|
|
|
|
2006-10-02 13:23:03 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2001-07-04 20:40:24 +00:00
|
|
|
#define NDEBUG
|
2006-10-02 13:23:03 +00:00
|
|
|
#include <debug.h>
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2005-11-28 23:25:31 +00:00
|
|
|
#if defined (ALLOC_PRAGMA)
|
|
|
|
#pragma alloc_text(INIT, ExpInitLookasideLists)
|
|
|
|
#endif
|
|
|
|
|
2001-07-04 20:40:24 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
LIST_ENTRY ExpNonPagedLookasideListHead;
|
|
|
|
KSPIN_LOCK ExpNonPagedLookasideListLock;
|
|
|
|
LIST_ENTRY ExpPagedLookasideListHead;
|
|
|
|
KSPIN_LOCK ExpPagedLookasideListLock;
|
2006-10-02 13:23:03 +00:00
|
|
|
LIST_ENTRY ExSystemLookasideListHead;
|
|
|
|
LIST_ENTRY ExPoolLookasideListHead;
|
2007-01-24 19:48:34 +00:00
|
|
|
GENERAL_LOOKASIDE ExpSmallNPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
|
|
|
|
GENERAL_LOOKASIDE ExpSmallPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
|
2001-07-04 20:40:24 +00:00
|
|
|
|
2006-10-02 13:23:03 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
|
|
|
|
2018-12-30 11:19:11 +00:00
|
|
|
INIT_FUNCTION
|
2006-10-02 13:23:03 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
ExInitializeSystemLookasideList(IN PGENERAL_LOOKASIDE List,
|
|
|
|
IN POOL_TYPE Type,
|
|
|
|
IN ULONG Size,
|
|
|
|
IN ULONG Tag,
|
|
|
|
IN USHORT MaximumDepth,
|
|
|
|
IN PLIST_ENTRY ListHead)
|
|
|
|
{
|
|
|
|
/* Initialize the list */
|
|
|
|
List->Tag = Tag;
|
|
|
|
List->Type = Type;
|
|
|
|
List->Size = Size;
|
|
|
|
InsertHeadList(ListHead, &List->ListEntry);
|
|
|
|
List->MaximumDepth = MaximumDepth;
|
|
|
|
List->Depth = 2;
|
|
|
|
List->Allocate = ExAllocatePoolWithTag;
|
|
|
|
List->Free = ExFreePool;
|
2010-01-13 22:35:43 +00:00
|
|
|
InitializeSListHead(&List->ListHead);
|
2006-10-02 13:23:03 +00:00
|
|
|
List->TotalAllocates = 0;
|
|
|
|
List->AllocateHits = 0;
|
|
|
|
List->TotalFrees = 0;
|
|
|
|
List->FreeHits = 0;
|
|
|
|
List->LastTotalAllocates = 0;
|
|
|
|
List->LastAllocateHits = 0;
|
|
|
|
}
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2018-12-30 11:19:11 +00:00
|
|
|
INIT_FUNCTION
|
2006-10-01 18:01:38 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
ExInitPoolLookasidePointers(VOID)
|
|
|
|
{
|
|
|
|
ULONG i;
|
2007-01-24 19:48:34 +00:00
|
|
|
PKPRCB Prcb = KeGetCurrentPrcb();
|
|
|
|
PGENERAL_LOOKASIDE Entry;
|
2006-10-01 18:01:38 +00:00
|
|
|
|
2007-01-24 19:48:34 +00:00
|
|
|
/* Loop for all pool lists */
|
2006-10-01 18:01:38 +00:00
|
|
|
for (i = 0; i < MAXIMUM_PROCESSORS; i++)
|
|
|
|
{
|
|
|
|
/* Initialize the non-paged list */
|
2007-01-24 19:48:34 +00:00
|
|
|
Entry = &ExpSmallNPagedPoolLookasideLists[i];
|
|
|
|
InitializeSListHead(&Entry->ListHead);
|
2006-10-01 18:01:38 +00:00
|
|
|
|
|
|
|
/* Bind to PRCB */
|
2007-01-24 19:48:34 +00:00
|
|
|
Prcb->PPNPagedLookasideList[i].P = Entry;
|
|
|
|
Prcb->PPNPagedLookasideList[i].L = Entry;
|
2006-10-01 18:01:38 +00:00
|
|
|
|
|
|
|
/* Initialize the paged list */
|
2007-01-24 19:48:34 +00:00
|
|
|
Entry = &ExpSmallPagedPoolLookasideLists[i];
|
|
|
|
InitializeSListHead(&Entry->ListHead);
|
2006-10-01 18:01:38 +00:00
|
|
|
|
|
|
|
/* Bind to PRCB */
|
2007-01-24 19:48:34 +00:00
|
|
|
Prcb->PPPagedLookasideList[i].P = Entry;
|
|
|
|
Prcb->PPPagedLookasideList[i].L = Entry;
|
2006-10-01 18:01:38 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-02 13:23:03 +00:00
|
|
|
|
2018-12-30 11:19:11 +00:00
|
|
|
INIT_FUNCTION
|
2005-12-29 17:57:11 +00:00
|
|
|
VOID
|
2006-10-02 13:23:03 +00:00
|
|
|
NTAPI
|
2015-09-03 23:57:39 +00:00
|
|
|
ExpInitLookasideLists(VOID)
|
2001-07-04 20:40:24 +00:00
|
|
|
{
|
2007-01-24 19:48:34 +00:00
|
|
|
ULONG i;
|
2006-10-02 13:23:03 +00:00
|
|
|
|
|
|
|
/* Initialize locks and lists */
|
2005-05-13 03:34:13 +00:00
|
|
|
InitializeListHead(&ExpNonPagedLookasideListHead);
|
|
|
|
InitializeListHead(&ExpPagedLookasideListHead);
|
2006-10-02 13:23:03 +00:00
|
|
|
InitializeListHead(&ExSystemLookasideListHead);
|
|
|
|
InitializeListHead(&ExPoolLookasideListHead);
|
|
|
|
KeInitializeSpinLock(&ExpNonPagedLookasideListLock);
|
2005-05-13 03:34:13 +00:00
|
|
|
KeInitializeSpinLock(&ExpPagedLookasideListLock);
|
2006-10-02 13:23:03 +00:00
|
|
|
|
|
|
|
/* Initialize the system lookaside lists */
|
2007-01-24 19:48:34 +00:00
|
|
|
for (i = 0; i < MAXIMUM_PROCESSORS; i++)
|
2006-10-02 13:23:03 +00:00
|
|
|
{
|
|
|
|
/* Initialize the non-paged list */
|
2007-01-24 19:48:34 +00:00
|
|
|
ExInitializeSystemLookasideList(&ExpSmallNPagedPoolLookasideLists[i],
|
2006-10-02 13:23:03 +00:00
|
|
|
NonPagedPool,
|
2007-01-24 19:48:34 +00:00
|
|
|
(i + 1) * 8,
|
2009-08-24 18:19:53 +00:00
|
|
|
'looP',
|
2006-10-02 13:23:03 +00:00
|
|
|
256,
|
|
|
|
&ExPoolLookasideListHead);
|
|
|
|
|
|
|
|
/* Initialize the paged list */
|
2007-01-24 19:48:34 +00:00
|
|
|
ExInitializeSystemLookasideList(&ExpSmallPagedPoolLookasideLists[i],
|
2006-10-02 13:23:03 +00:00
|
|
|
PagedPool,
|
2007-01-24 19:48:34 +00:00
|
|
|
(i + 1) * 8,
|
2009-08-24 18:19:53 +00:00
|
|
|
'looP',
|
2006-10-02 13:23:03 +00:00
|
|
|
256,
|
|
|
|
&ExPoolLookasideListHead);
|
|
|
|
}
|
2001-07-04 20:40:24 +00:00
|
|
|
}
|
|
|
|
|
2006-10-02 13:23:03 +00:00
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
2001-07-04 20:40:24 +00:00
|
|
|
/*
|
2005-05-13 03:34:13 +00:00
|
|
|
* @implemented
|
2001-07-04 20:40:24 +00:00
|
|
|
*/
|
2002-09-08 10:23:54 +00:00
|
|
|
PVOID
|
2006-10-02 13:23:03 +00:00
|
|
|
NTAPI
|
2005-05-13 03:34:13 +00:00
|
|
|
ExiAllocateFromPagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
|
2002-09-08 10:23:54 +00:00
|
|
|
{
|
2005-05-13 03:34:13 +00:00
|
|
|
PVOID Entry;
|
|
|
|
|
|
|
|
Lookaside->L.TotalAllocates++;
|
|
|
|
Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
|
2007-10-19 23:21:45 +00:00
|
|
|
if (!Entry)
|
2005-05-13 03:34:13 +00:00
|
|
|
{
|
|
|
|
Lookaside->L.AllocateMisses++;
|
|
|
|
Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
|
2006-10-02 13:23:03 +00:00
|
|
|
Lookaside->L.Size,
|
2005-05-13 03:34:13 +00:00
|
|
|
Lookaside->L.Tag);
|
|
|
|
}
|
2002-09-08 10:23:54 +00:00
|
|
|
return Entry;
|
|
|
|
}
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2003-07-10 06:27:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-06-07 13:05:09 +00:00
|
|
|
VOID
|
2006-10-02 13:23:03 +00:00
|
|
|
NTAPI
|
2005-05-13 03:34:13 +00:00
|
|
|
ExiFreeToPagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside,
|
|
|
|
IN PVOID Entry)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2005-05-13 03:34:13 +00:00
|
|
|
Lookaside->L.TotalFrees++;
|
2007-10-19 23:21:45 +00:00
|
|
|
if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth)
|
2005-05-13 03:34:13 +00:00
|
|
|
{
|
|
|
|
Lookaside->L.FreeMisses++;
|
|
|
|
(Lookaside->L.Free)(Entry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
|
|
|
|
}
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 06:27:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-06-07 13:05:09 +00:00
|
|
|
VOID
|
2006-10-02 13:23:03 +00:00
|
|
|
NTAPI
|
|
|
|
ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2005-05-13 03:34:13 +00:00
|
|
|
KIRQL OldIrql;
|
|
|
|
PVOID Entry;
|
|
|
|
|
2006-10-02 13:23:03 +00:00
|
|
|
/* Pop all entries off the stack and release their resources */
|
2005-05-13 03:34:13 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
|
|
|
|
if (!Entry) break;
|
|
|
|
(*Lookaside->L.Free)(Entry);
|
|
|
|
}
|
2006-10-02 13:23:03 +00:00
|
|
|
|
2005-05-13 03:34:13 +00:00
|
|
|
/* Remove from list */
|
|
|
|
KeAcquireSpinLock(&ExpNonPagedLookasideListLock, &OldIrql);
|
|
|
|
RemoveEntryList(&Lookaside->L.ListEntry);
|
|
|
|
KeReleaseSpinLock(&ExpNonPagedLookasideListLock, OldIrql);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2005-05-13 03:34:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-06-07 13:05:09 +00:00
|
|
|
VOID
|
2006-10-02 13:23:03 +00:00
|
|
|
NTAPI
|
|
|
|
ExDeletePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2005-05-13 03:34:13 +00:00
|
|
|
KIRQL OldIrql;
|
|
|
|
PVOID Entry;
|
|
|
|
|
2006-10-02 13:23:03 +00:00
|
|
|
/* Pop all entries off the stack and release their resources */
|
2005-05-13 03:34:13 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
|
|
|
|
if (!Entry) break;
|
|
|
|
(*Lookaside->L.Free)(Entry);
|
|
|
|
}
|
2006-10-02 13:23:03 +00:00
|
|
|
|
2005-05-13 03:34:13 +00:00
|
|
|
/* Remove from list */
|
|
|
|
KeAcquireSpinLock(&ExpPagedLookasideListLock, &OldIrql);
|
|
|
|
RemoveEntryList(&Lookaside->L.ListEntry);
|
|
|
|
KeReleaseSpinLock(&ExpPagedLookasideListLock, OldIrql);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 06:27:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-06-07 13:05:09 +00:00
|
|
|
VOID
|
2006-10-02 13:23:03 +00:00
|
|
|
NTAPI
|
|
|
|
ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside,
|
|
|
|
IN PALLOCATE_FUNCTION Allocate OPTIONAL,
|
|
|
|
IN PFREE_FUNCTION Free OPTIONAL,
|
|
|
|
IN ULONG Flags,
|
2008-08-27 22:40:17 +00:00
|
|
|
IN SIZE_T Size,
|
2006-10-02 13:23:03 +00:00
|
|
|
IN ULONG Tag,
|
|
|
|
IN USHORT Depth)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2005-05-13 03:34:13 +00:00
|
|
|
/* Initialize the Header */
|
|
|
|
ExInitializeSListHead(&Lookaside->L.ListHead);
|
|
|
|
Lookaside->L.TotalAllocates = 0;
|
|
|
|
Lookaside->L.AllocateMisses = 0;
|
|
|
|
Lookaside->L.TotalFrees = 0;
|
|
|
|
Lookaside->L.FreeMisses = 0;
|
|
|
|
Lookaside->L.Type = NonPagedPool | Flags;
|
|
|
|
Lookaside->L.Tag = Tag;
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
Lookaside->L.Size = (ULONG)Size;
|
2005-05-13 03:34:13 +00:00
|
|
|
Lookaside->L.Depth = 4;
|
|
|
|
Lookaside->L.MaximumDepth = 256;
|
|
|
|
Lookaside->L.LastTotalAllocates = 0;
|
|
|
|
Lookaside->L.LastAllocateMisses = 0;
|
|
|
|
|
|
|
|
/* Set the Allocate/Free Routines */
|
|
|
|
if (Allocate)
|
|
|
|
{
|
|
|
|
Lookaside->L.Allocate = Allocate;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Lookaside->L.Allocate = ExAllocatePoolWithTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Free)
|
|
|
|
{
|
|
|
|
Lookaside->L.Free = Free;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Lookaside->L.Free = ExFreePool;
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2005-05-13 03:34:13 +00:00
|
|
|
/* Insert it into the list */
|
|
|
|
ExInterlockedInsertTailList(&ExpNonPagedLookasideListHead,
|
|
|
|
&Lookaside->L.ListEntry,
|
|
|
|
&ExpNonPagedLookasideListLock);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 06:27:13 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2000-06-07 13:05:09 +00:00
|
|
|
VOID
|
2006-10-02 13:23:03 +00:00
|
|
|
NTAPI
|
|
|
|
ExInitializePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside,
|
|
|
|
IN PALLOCATE_FUNCTION Allocate OPTIONAL,
|
|
|
|
IN PFREE_FUNCTION Free OPTIONAL,
|
|
|
|
IN ULONG Flags,
|
2008-08-27 22:40:17 +00:00
|
|
|
IN SIZE_T Size,
|
2006-10-02 13:23:03 +00:00
|
|
|
IN ULONG Tag,
|
|
|
|
IN USHORT Depth)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2005-05-13 03:34:13 +00:00
|
|
|
/* Initialize the Header */
|
|
|
|
ExInitializeSListHead(&Lookaside->L.ListHead);
|
|
|
|
Lookaside->L.TotalAllocates = 0;
|
|
|
|
Lookaside->L.AllocateMisses = 0;
|
|
|
|
Lookaside->L.TotalFrees = 0;
|
|
|
|
Lookaside->L.FreeMisses = 0;
|
|
|
|
Lookaside->L.Type = PagedPool | Flags;
|
|
|
|
Lookaside->L.Tag = Tag;
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
Lookaside->L.Size = (ULONG)Size;
|
2005-05-13 03:34:13 +00:00
|
|
|
Lookaside->L.Depth = 4;
|
|
|
|
Lookaside->L.MaximumDepth = 256;
|
|
|
|
Lookaside->L.LastTotalAllocates = 0;
|
|
|
|
Lookaside->L.LastAllocateMisses = 0;
|
|
|
|
|
|
|
|
/* Set the Allocate/Free Routines */
|
|
|
|
if (Allocate)
|
|
|
|
{
|
|
|
|
Lookaside->L.Allocate = Allocate;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Lookaside->L.Allocate = ExAllocatePoolWithTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Free)
|
|
|
|
{
|
|
|
|
Lookaside->L.Free = Free;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Lookaside->L.Free = ExFreePool;
|
|
|
|
}
|
2006-10-02 13:23:03 +00:00
|
|
|
|
2005-05-13 03:34:13 +00:00
|
|
|
/* Insert it into the list */
|
2011-10-30 19:19:49 +00:00
|
|
|
ExInterlockedInsertTailList(&ExpPagedLookasideListHead,
|
2005-05-13 03:34:13 +00:00
|
|
|
&Lookaside->L.ListEntry,
|
2011-10-30 19:19:49 +00:00
|
|
|
&ExpPagedLookasideListLock);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
2000-06-07 13:05:09 +00:00
|
|
|
|
|
|
|
/* EOF */
|