From 8f1d4c0a6fec701d3af943188952d55f8b56582a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Tue, 6 Jun 2017 23:42:56 +0200 Subject: ntoskrnl.exe: Implement ExInitializeNPagedLookasideList. --- dlls/ntoskrnl.exe/ntoskrnl.c | 19 ++++++++++- include/ddk/wdm.h | 76 ++++++++++++++++++++++++++++++++++++++++++-- include/winnt.h | 2 ++ 3 files changed, 93 insertions(+), 4 deletions(-) diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c index 81f5738..a9f7029 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/ntoskrnl.c @@ -1814,7 +1814,24 @@ void WINAPI ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST Lookaside, ULONG Tag, USHORT Depth) { - FIXME( "stub: %p, %p, %p, %u, %lu, %u, %u\n", Lookaside, Allocate, Free, Flags, Size, Tag, Depth ); + TRACE( "%p, %p, %p, %u, %lu, %u, %u\n", Lookaside, Allocate, Free, Flags, Size, Tag, Depth ); + + RtlInitializeSListHead( &Lookaside->L.u.ListHead ); + Lookaside->L.Depth = 4; + Lookaside->L.MaximumDepth = 256; + Lookaside->L.TotalAllocates = 0; + Lookaside->L.u2.AllocateMisses = 0; + Lookaside->L.TotalFrees = 0; + Lookaside->L.u3.FreeMisses = 0; + Lookaside->L.Type = NonPagedPool | Flags; + Lookaside->L.Tag = Tag; + Lookaside->L.Size = Size; + Lookaside->L.u4.Allocate = Allocate ? Allocate : ExAllocatePoolWithTag; + Lookaside->L.u5.Free = Free ? Free : ExFreePool; + Lookaside->L.LastTotalAllocates = 0; + Lookaside->L.u6.LastAllocateMisses = 0; + + /* FIXME: insert in global list of lookadside lists */ } /*********************************************************************** diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index 8634f36..8453079 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -144,20 +144,18 @@ typedef enum _KWAIT_REASON MaximumWaitReason, } KWAIT_REASON; -typedef struct _ALLOCATE_FUNCTION *PALLOCATE_FUNCTION; typedef struct _IO_TIMER *PIO_TIMER; typedef struct _IO_TIMER_ROUTINE *PIO_TIMER_ROUTINE; typedef struct _ETHREAD *PETHREAD; -typedef struct _FREE_FUNCTION *PFREE_FUNCTION; typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD; typedef struct _EPROCESS *PEPROCESS; typedef struct _ERESOURCE *PERESOURCE; typedef struct _IO_WORKITEM *PIO_WORKITEM; -typedef struct _NPAGED_LOOKASIDE_LIST *PNPAGED_LOOKASIDE_LIST; typedef struct _PAGED_LOOKASIDE_LIST *PPAGED_LOOKASIDE_LIST; typedef struct _OBJECT_TYPE *POBJECT_TYPE; typedef struct _OBJECT_HANDLE_INFORMATION *POBJECT_HANDLE_INFORMATION; typedef struct _ZONE_HEADER *PZONE_HEADER; +typedef struct _LOOKASIDE_LIST_EX *PLOOKASIDE_LIST_EX; typedef struct _FAST_MUTEX { @@ -182,6 +180,11 @@ typedef struct _VPB { WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)]; } VPB, *PVPB; +#define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE 0x8 +#define POOL_RAISE_IF_ALLOCATION_FAILURE 0x10 +#define POOL_COLD_ALLOCATION 0x100 +#define POOL_NX_ALLOCATION 0x200 + typedef enum _POOL_TYPE { NonPagedPool, PagedPool, @@ -1221,6 +1224,71 @@ typedef struct _KLOCK_QUEUE_HANDLE { KIRQL OldIrql; } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE; +typedef void * (NTAPI *PALLOCATE_FUNCTION)(POOL_TYPE, SIZE_T, ULONG); +typedef void * (NTAPI *PALLOCATE_FUNCTION_EX)(POOL_TYPE, SIZE_T, ULONG, PLOOKASIDE_LIST_EX); +typedef void (NTAPI *PFREE_FUNCTION)(void *); +typedef void (NTAPI *PFREE_FUNCTION_EX)(void *, PLOOKASIDE_LIST_EX); + +#ifdef _WIN64 +#define LOOKASIDE_ALIGN DECLSPEC_CACHEALIGN +#else +#define LOOKASIDE_ALIGN +#endif + +#define LOOKASIDE_MINIMUM_BLOCK_SIZE (RTL_SIZEOF_THROUGH_FIELD(SLIST_ENTRY, Next)) + +typedef struct LOOKASIDE_ALIGN _GENERAL_LOOKASIDE +{ + union + { + SLIST_HEADER ListHead; + SINGLE_LIST_ENTRY SingleListHead; + } DUMMYUNIONNAME; + USHORT Depth; + USHORT MaximumDepth; + ULONG TotalAllocates; + union + { + ULONG AllocateMisses; + ULONG AllocateHits; + } DUMMYUNIONNAME2; + ULONG TotalFrees; + union + { + ULONG FreeMisses; + ULONG FreeHits; + } DUMMYUNIONNAME3; + POOL_TYPE Type; + ULONG Tag; + ULONG Size; + union + { + PALLOCATE_FUNCTION_EX AllocateEx; + PALLOCATE_FUNCTION Allocate; + } DUMMYUNIONNAME4; + union + { + PFREE_FUNCTION_EX FreeEx; + PFREE_FUNCTION Free; + } DUMMYUNIONNAME5; + LIST_ENTRY ListEntry; + ULONG LastTotalAllocates; + union + { + ULONG LastAllocateMisses; + ULONG LastAllocateHits; + } DUMMYUNIONNAME6; + ULONG Future[2]; +} GENERAL_LOOKASIDE; + +typedef struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST +{ + GENERAL_LOOKASIDE L; +#if defined(__i386__) + KSPIN_LOCK Lock__ObsoleteButDoNotDelete; +#endif +} NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST; + typedef NTSTATUS (NTAPI EX_CALLBACK_FUNCTION)(void *CallbackContext, void *Argument1, void *Argument2); typedef EX_CALLBACK_FUNCTION *PEX_CALLBACK_FUNCTION; @@ -1372,8 +1440,10 @@ PVOID WINAPI ExAllocatePool(POOL_TYPE,SIZE_T); PVOID WINAPI ExAllocatePoolWithQuota(POOL_TYPE,SIZE_T); PVOID WINAPI ExAllocatePoolWithTag(POOL_TYPE,SIZE_T,ULONG); PVOID WINAPI ExAllocatePoolWithQuotaTag(POOL_TYPE,SIZE_T,ULONG); +void WINAPI ExDeleteNPagedLookasideList(PNPAGED_LOOKASIDE_LIST); void WINAPI ExFreePool(PVOID); void WINAPI ExFreePoolWithTag(PVOID,ULONG); +void WINAPI ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST,PALLOCATE_FUNCTION,PFREE_FUNCTION,ULONG,SIZE_T,ULONG,USHORT); PSLIST_ENTRY WINAPI ExInterlockedPopEntrySList(PSLIST_HEADER,PKSPIN_LOCK); PSLIST_ENTRY WINAPI ExInterlockedPushEntrySList(PSLIST_HEADER,PSLIST_ENTRY,PKSPIN_LOCK); void WINAPI ExReleaseFastMutexUnsafe(PFAST_MUTEX); diff --git a/include/winnt.h b/include/winnt.h index b309929..d7694ab 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -755,6 +755,8 @@ typedef struct _MEMORY_BASIC_INFORMATION #define UNICODE_STRING_MAX_CHARS 32767 #define FIELD_OFFSET(type, field) ((LONG)offsetof(type, field)) +#define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field)) +#define RTL_SIZEOF_THROUGH_FIELD(type, field) (FIELD_OFFSET(type, field) + RTL_FIELD_SIZE(type, field)) #ifdef __GNUC__ # define CONTAINING_RECORD(address, type, field) ({ \ -- 2.7.4