Author: fireball Date: Wed Sep 26 20:41:35 2007 New Revision: 29214
URL: http://svn.reactos.org/svn/reactos?rev=29214&view=rev Log: - Implement InterlockedExchangeAdd/Decrement/Increment16. - Fix MM_EXTEND_INFO definition. - Fix MMWSLE definition. - Fix EPROCESS definition. - Add quota functions to NDK. - Add one more parameter to PspMapSystemDll to support mapping large pages. - Don't make the quota functions do anything for the system process. - Add page file quota functions. - Other misc small fixes.
Modified: trunk/reactos/include/ddk/winddk.h trunk/reactos/include/ndk/mmtypes.h trunk/reactos/include/ndk/psfuncs.h trunk/reactos/include/ndk/pstypes.h trunk/reactos/include/psdk/intrin_x86.h trunk/reactos/ntoskrnl/include/internal/i386/intrin_i.h trunk/reactos/ntoskrnl/include/internal/ke.h trunk/reactos/ntoskrnl/include/internal/ke_x.h trunk/reactos/ntoskrnl/include/internal/mm.h trunk/reactos/ntoskrnl/include/internal/ps.h trunk/reactos/ntoskrnl/include/internal/ps_x.h trunk/reactos/ntoskrnl/ke/i386/cpu.c trunk/reactos/ntoskrnl/mm/aspace.c trunk/reactos/ntoskrnl/mm/drvlck.c trunk/reactos/ntoskrnl/ps/process.c trunk/reactos/ntoskrnl/ps/psmgr.c trunk/reactos/ntoskrnl/ps/quota.c
Modified: trunk/reactos/include/ddk/winddk.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/winddk.h?rev=29... ============================================================================== --- trunk/reactos/include/ddk/winddk.h (original) +++ trunk/reactos/include/ddk/winddk.h Wed Sep 26 20:41:35 2007 @@ -9689,6 +9689,20 @@ NTKERNELAPI PVOID NTAPI +MmLockPageableDataSection ( + IN PVOID AddressWithinSection +); + +NTKERNELAPI +VOID +NTAPI +MmUnlockPageableImageSection( + IN PVOID ImageSectionHandle +); + +NTKERNELAPI +PVOID +NTAPI MmPageEntireDriver( IN PVOID AddressWithinSection);
@@ -9748,6 +9762,9 @@ } \ }
+#define MmGetProcedureAddress(Address) (Address) +#define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address) + NTKERNELAPI VOID NTAPI
Modified: trunk/reactos/include/ndk/mmtypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/mmtypes.h?rev=2... ============================================================================== --- trunk/reactos/include/ndk/mmtypes.h (original) +++ trunk/reactos/include/ndk/mmtypes.h Wed Sep 26 20:41:35 2007 @@ -248,20 +248,6 @@ } MMPTE, *PMMPTE;
// -// Section Information structure -// -typedef struct _MI_EXTRA_IMAGE_INFORMATION -{ - ULONG SizeOfHeaders; -} MI_EXTRA_IMAGE_INFORMATION, *PMI_EXTRA_IMAGE_INFORMATION; - -typedef struct _MI_SECTION_IMAGE_INFORMATION -{ - SECTION_IMAGE_INFORMATION ExportedImageInformation; - MI_EXTRA_IMAGE_INFORMATION InternalImageInformation; -} MI_SECTION_IMAGE_INFORMATION, *PMI_SECTION_IMAGE_INFORMATION; - -// // Section Extension Information // typedef struct _MMEXTEND_INFO @@ -295,12 +281,12 @@ PVOID BaseAddress; union { - ULONG ImageCommitment; + SIZE_T ImageCommitment; PEPROCESS CreatingProcess; } u1; union { - PMI_SECTION_IMAGE_INFORMATION ImageInformation; + PSECTION_IMAGE_INFORMATION ImageInformation; PVOID FirstMappedVa; } u2; PMMPTE PrototypePte; @@ -545,7 +531,7 @@ PVOID VirtualAddress; ULONG Long; MMWSLENTRY e1; - }; + } u1; } MMWSLE, *PMMWSLE;
typedef struct _MMWSLE_HASH
Modified: trunk/reactos/include/ndk/psfuncs.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/psfuncs.h?rev=2... ============================================================================== --- trunk/reactos/include/ndk/psfuncs.h (original) +++ trunk/reactos/include/ndk/psfuncs.h Wed Sep 26 20:41:35 2007 @@ -130,6 +130,68 @@ NTAPI PsIsProtectedProcess( IN PEPROCESS Process +); + +// +// Quota Functions +// +NTKERNELAPI +VOID +NTAPI +PsChargePoolQuota( + IN PEPROCESS Process, + IN POOL_TYPE PoolType, + IN ULONG Amount +); + +NTKERNELAPI +NTSTATUS +NTAPI +PsChargeProcessNonPagedPoolQuota( + IN PEPROCESS Process, + IN ULONG_PTR Amount +); + +NTKERNELAPI +NTSTATUS +NTAPI +PsChargeProcessPagedPoolQuota( + IN PEPROCESS Process, + IN ULONG_PTR Amount +); + +NTKERNELAPI +NTSTATUS +NTAPI +PsChargeProcessPoolQuota( + IN PEPROCESS Process, + IN POOL_TYPE PoolType, + IN ULONG Amount +); + +NTKERNELAPI +VOID +NTAPI +PsReturnPoolQuota( + IN PEPROCESS Process, + IN POOL_TYPE PoolType, + IN ULONG_PTR Amount +); + +NTKERNELAPI +VOID +NTAPI +PsReturnProcessNonPagedPoolQuota( + IN PEPROCESS Process, + IN ULONG_PTR Amount +); + +NTKERNELAPI +VOID +NTAPI +PsReturnProcessPagedPoolQuota( + IN PEPROCESS Process, + IN ULONG_PTR Amount );
#endif
Modified: trunk/reactos/include/ndk/pstypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/pstypes.h?rev=2... ============================================================================== --- trunk/reactos/include/ndk/pstypes.h (original) +++ trunk/reactos/include/ndk/pstypes.h Wed Sep 26 20:41:35 2007 @@ -1177,16 +1177,12 @@ EX_PUSH_LOCK AddressCreationLock; PETHREAD RotateInProgress; #else - FAST_MUTEX AddressCreationLock; // FIXME: FAST_MUTEX for XP, KGUARDED_MUTEX for 2K3 + KGUARDED_MUTEX AddressCreationLock; KSPIN_LOCK HyperSpaceLock; #endif PETHREAD ForkInProgress; ULONG HardwareTrigger; -#if (NTDDI_VERSION >= NTDDI_LONGHORN) - PMM_AVL_TABLE PhysicalVadroot; -#else - MM_AVL_TABLE PhysicalVadroot; -#endif + PMM_AVL_TABLE PhysicalVadRoot; PVOID CloneRoot; ULONG NumberOfPrivatePages; ULONG NumberOfLockedPages;
Modified: trunk/reactos/include/psdk/intrin_x86.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/psdk/intrin_x86.h?r... ============================================================================== --- trunk/reactos/include/psdk/intrin_x86.h (original) +++ trunk/reactos/include/psdk/intrin_x86.h Wed Sep 26 20:41:35 2007 @@ -128,6 +128,11 @@ return __sync_lock_test_and_set(Target, Value); }
+static __inline__ __attribute__((always_inline)) long _InterlockedExchangeAdd16(volatile short * const Addend, const short Value) +{ + return __sync_fetch_and_add(Addend, Value); +} + static __inline__ __attribute__((always_inline)) long _InterlockedExchangeAdd(volatile long * const Addend, const long Value) { return __sync_fetch_and_add(Addend, Value); @@ -239,6 +244,13 @@ return retval; }
+static __inline__ __attribute__((always_inline)) long _InterlockedExchangeAdd16(volatile short * const Addend, const short Value) +{ + long retval = Value; + __asm__("lock; xaddw %[retval], %[Addend]" : [retval] "+r" (retval) : [Addend] "m" (*Addend) : "memory"); + return retval; +} + static __inline__ __attribute__((always_inline)) long _InterlockedExchangeAdd(volatile long * const Addend, const long Value) { long retval = Value; @@ -424,6 +436,16 @@ static __inline__ __attribute__((always_inline)) long _InterlockedIncrement(volatile long * const lpAddend) { return _InterlockedExchangeAdd(lpAddend, 1) + 1; +} + +static __inline__ __attribute__((always_inline)) long _InterlockedDecrement16(volatile short * const lpAddend) +{ + return _InterlockedExchangeAdd16(lpAddend, -1) - 1; +} + +static __inline__ __attribute__((always_inline)) long _InterlockedIncrement16(volatile short * const lpAddend) +{ + return _InterlockedExchangeAdd16(lpAddend, 1) + 1; }
static __inline__ __attribute__((always_inline)) unsigned char _interlockedbittestandreset(volatile long * a, const long b)
Modified: trunk/reactos/ntoskrnl/include/internal/i386/intrin_i.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/i... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/i386/intrin_i.h (original) +++ trunk/reactos/ntoskrnl/include/internal/i386/intrin_i.h Wed Sep 26 20:41:35 2007 @@ -79,6 +79,9 @@ #define Ke386HaltProcessor() __asm__("hlt\n\t");
#define Ke386FnInit() __asm__("fninit\n\t"); + +#define Ke386WbInvd() __asm__("wbinvd\n\t"); +
// // CR Macros
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/k... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ke.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ke.h Wed Sep 26 20:41:35 2007 @@ -751,6 +751,15 @@ NTAPI KeFlushCurrentTb(VOID);
+BOOLEAN +NTAPI +KeInvalidateAllCaches(VOID); + +VOID +FASTCALL +KeZeroPages(IN PVOID Address, + IN ULONG Size); + VOID NTAPI KeRosDumpStackFrames(
Modified: trunk/reactos/ntoskrnl/include/internal/ke_x.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/k... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ke_x.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ke_x.h Wed Sep 26 20:41:35 2007 @@ -96,7 +96,7 @@ PKTHREAD _Thread = KeGetCurrentThread(); \ \ /* Sanity checks */ \ - ASSERT_IRQL_LESS_OR_EQUAL(APC_LEVEL); \ + ASSERT(KeGetCurrentIrql() <= APC_LEVEL); \ ASSERT(_Thread == KeGetCurrentThread()); \ ASSERT((_Thread->SpecialApcDisable <= 0) && \ (_Thread->SpecialApcDisable != -32768)); \ @@ -113,7 +113,7 @@ PKTHREAD _Thread = KeGetCurrentThread(); \ \ /* Sanity checks */ \ - ASSERT_IRQL_LESS_OR_EQUAL(APC_LEVEL); \ + ASSERT(KeGetCurrentIrql() <= APC_LEVEL); \ ASSERT(_Thread == KeGetCurrentThread()); \ ASSERT(_Thread->SpecialApcDisable < 0); \ \ @@ -1540,3 +1540,11 @@ return KeGetCurrentThread()->PreviousMode; }
+VOID +FORCEINLINE +KeFlushProcessTb(VOID) +{ + /* Flush the TLB by resetting CR3 */ + __writecr3(__readcr3()); +} +
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/m... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/mm.h (original) +++ trunk/reactos/ntoskrnl/include/internal/mm.h Wed Sep 26 20:41:35 2007 @@ -1457,4 +1457,14 @@ IN BOOLEAN PurgeSection );
+FORCEINLINE +VOID +NTAPI +MiSyncThreadProcessViews(IN PKPROCESS Process, + IN PVOID Address, + IN ULONG Size) +{ + MmUpdatePageDir((PEPROCESS)Process, Address, Size); +} + #endif
Modified: trunk/reactos/ntoskrnl/include/internal/ps.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/p... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ps.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ps.h Wed Sep 26 20:41:35 2007 @@ -105,7 +105,8 @@ NTAPI PspMapSystemDll( IN PEPROCESS Process, - OUT PVOID *DllBase + OUT PVOID *DllBase, + IN BOOLEAN UseLargePages );
NTSTATUS @@ -347,6 +348,23 @@ PsSuspendThread( IN PETHREAD Thread, OUT PULONG PreviousCount OPTIONAL +); + +// +// Process Quotas +// +NTSTATUS +NTAPI +PsReturnProcessPageFileQuota( + IN PEPROCESS Process, + IN SIZE_T Amount +); + +NTSTATUS +NTAPI +PsChargeProcessPageFileQuota( + IN PEPROCESS Process, + IN SIZE_T Amount );
//
Modified: trunk/reactos/ntoskrnl/include/internal/ps_x.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/p... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ps_x.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ps_x.h Wed Sep 26 20:41:35 2007 @@ -20,18 +20,20 @@ ((Mask) & 48)
// -// Set Process Flag routines -// -#define PspSetProcessFlag(Process, Flag) \ - InterlockedOr((PLONG)&Process->Flags, Flag) - -// // Cross Thread Flag routines // #define PspSetCrossThreadFlag(Thread, Flag) \ InterlockedOr((PLONG)&Thread->CrossThreadFlags, Flag) #define PspClearCrossThreadFlag(Thread, Flag) \ InterlockedAnd((PLONG)&Thread->CrossThreadFlags, ~Flag) + +// +// Process flag routines +// +#define PspSetProcessFlag(Process, Flag) \ + InterlockedOr((PLONG)&Process->Flags, Flag) +#define PspClearProcessFlag(Process, Flag) \ + InterlockedAnd((PLONG)&Process->Flags, ~Flag)
VOID FORCEINLINE
Modified: trunk/reactos/ntoskrnl/ke/i386/cpu.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/cpu.c?rev=... ============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/cpu.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/cpu.c Wed Sep 26 20:41:35 2007 @@ -78,6 +78,9 @@ KIRQL KiOldIrql; ULONG KiFreezeFlag;
+/* Flush data */ +volatile LONG KiTbFlushTimeStamp; + /* CPU Signatures */ static const CHAR CmpIntelID[] = "GenuineIntel"; static const CHAR CmpAmdID[] = "AuthenticAMD"; @@ -882,6 +885,27 @@ if (Enable) _enable(); }
+BOOLEAN +NTAPI +KeInvalidateAllCaches(VOID) +{ + /* Only supported on Pentium Pro and higher */ + if (KeI386CpuType < 6) return FALSE; + + /* Invalidate all caches */ + Ke386WbInvd(); + return TRUE; +} + +VOID +FASTCALL +KeZeroPages(IN PVOID Address, + IN ULONG Size) +{ + /* Not using XMMI in this routine */ + RtlZeroMemory(Address, Size); +} + /* PUBLIC FUNCTIONS **********************************************************/
/*
Modified: trunk/reactos/ntoskrnl/mm/aspace.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/aspace.c?rev=29... ============================================================================== --- trunk/reactos/ntoskrnl/mm/aspace.c (original) +++ trunk/reactos/ntoskrnl/mm/aspace.c Wed Sep 26 20:41:35 2007 @@ -39,11 +39,11 @@
if (AddressSpace->Process) { - ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&AddressSpace->Process->AddressCreationLock); + ExEnterCriticalRegionAndAcquireFastMutexUnsafe((PFAST_MUTEX)&AddressSpace->Process->AddressCreationLock); } else { - ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&KernelAddressSpaceLock); + ExEnterCriticalRegionAndAcquireFastMutexUnsafe((PFAST_MUTEX)&KernelAddressSpaceLock); } }
@@ -60,11 +60,11 @@ } if (AddressSpace->Process) { - ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&AddressSpace->Process->AddressCreationLock); + ExReleaseFastMutexUnsafeAndLeaveCriticalRegion((PFAST_MUTEX)&AddressSpace->Process->AddressCreationLock); } else { - ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&KernelAddressSpaceLock); + ExReleaseFastMutexUnsafeAndLeaveCriticalRegion((PFAST_MUTEX)&KernelAddressSpaceLock); } }
@@ -98,11 +98,11 @@ AddressSpace->MemoryAreaRoot = NULL; if (Process) { - ExInitializeFastMutex(&Process->AddressCreationLock); + ExInitializeFastMutex((PFAST_MUTEX)&Process->AddressCreationLock); } else { - ExInitializeFastMutex(&KernelAddressSpaceLock); + ExInitializeFastMutex((PFAST_MUTEX)&KernelAddressSpaceLock); } if (Process != NULL) {
Modified: trunk/reactos/ntoskrnl/mm/drvlck.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/drvlck.c?rev=29... ============================================================================== --- trunk/reactos/ntoskrnl/mm/drvlck.c (original) +++ trunk/reactos/ntoskrnl/mm/drvlck.c Wed Sep 26 20:41:35 2007 @@ -14,6 +14,8 @@ #include <internal/debug.h>
/* FUNCTIONS *****************************************************************/ + +#undef MmLockPagableDataSection
#if 0 VOID
Modified: trunk/reactos/ntoskrnl/ps/process.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/process.c?rev=2... ============================================================================== --- trunk/reactos/ntoskrnl/ps/process.c (original) +++ trunk/reactos/ntoskrnl/ps/process.c Wed Sep 26 20:41:35 2007 @@ -592,7 +592,7 @@ if (!NT_SUCCESS(Status)) goto CleanupWithRef;
/* Check if we have a section object and map the system DLL */ - if (SectionObject) PspMapSystemDll(Process, NULL); + if (SectionObject) PspMapSystemDll(Process, NULL, FALSE);
/* Create a handle for the Process */ CidEntry.Object = Process;
Modified: trunk/reactos/ntoskrnl/ps/psmgr.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/psmgr.c?rev=292... ============================================================================== --- trunk/reactos/ntoskrnl/ps/psmgr.c (original) +++ trunk/reactos/ntoskrnl/ps/psmgr.c Wed Sep 26 20:41:35 2007 @@ -218,13 +218,14 @@ NTSTATUS NTAPI PspMapSystemDll(IN PEPROCESS Process, - IN PVOID *DllBase) + IN PVOID *DllBase, + IN BOOLEAN UseLargePages) { NTSTATUS Status; LARGE_INTEGER Offset = {{0}}; SIZE_T ViewSize = 0; PVOID ImageBase = 0; - + /* Map the System DLL */ Status = MmMapViewOfSection(PspSystemDllSection, Process, @@ -236,7 +237,12 @@ ViewShare, 0, PAGE_READWRITE); - + if (Status != STATUS_SUCCESS) + { + /* Normalize status code */ + Status = STATUS_CONFLICTING_ADDRESSES; + } + /* Write the image base and return status */ if (DllBase) *DllBase = ImageBase; return Status; @@ -316,7 +322,7 @@ }
/* Map it */ - Status = PspMapSystemDll(PsGetCurrentProcess(), &PspSystemDllBase); + Status = PspMapSystemDll(PsGetCurrentProcess(), &PspSystemDllBase, FALSE); if (!NT_SUCCESS(Status)) { /* Failed, bugcheck */
Modified: trunk/reactos/ntoskrnl/ps/quota.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/quota.c?rev=292... ============================================================================== --- trunk/reactos/ntoskrnl/ps/quota.c (original) +++ trunk/reactos/ntoskrnl/ps/quota.c Wed Sep 26 20:41:35 2007 @@ -59,6 +59,19 @@ } }
+NTSTATUS +NTAPI +PsChargeProcessPageFileQuota(IN PEPROCESS Process, + IN SIZE_T Amount) +{ + /* Don't do anything for the system process */ + if (Process == PsInitialSystemProcess) return STATUS_SUCCESS; + + /* Otherwise, not implemented */ + UNIMPLEMENTED; + return STATUS_SUCCESS; +} + /* * @implemented */ @@ -70,14 +83,12 @@ { NTSTATUS Status;
+ /* Don't do anything for the system process */ + if (Process == PsInitialSystemProcess) return; + /* Charge the usage */ Status = PsChargeProcessPoolQuota(Process, PoolType, Amount); - - /* Raise Exception */ - if (!NT_SUCCESS(Status)) - { - ExRaiseStatus(Status); - } + if (!NT_SUCCESS(Status)) ExRaiseStatus(Status); }
/* @@ -113,6 +124,9 @@ IN POOL_TYPE PoolType, IN ULONG Amount) { + /* Don't do anything for the system process */ + if (Process == PsInitialSystemProcess) return STATUS_SUCCESS; + UNIMPLEMENTED; return STATUS_SUCCESS; } @@ -126,6 +140,9 @@ IN POOL_TYPE PoolType, IN ULONG_PTR Amount) { + /* Don't do anything for the system process */ + if (Process == PsInitialSystemProcess) return; + UNIMPLEMENTED; }
@@ -137,6 +154,9 @@ PsReturnProcessNonPagedPoolQuota(IN PEPROCESS Process, IN ULONG_PTR Amount) { + /* Don't do anything for the system process */ + if (Process == PsInitialSystemProcess) return; + UNIMPLEMENTED; }
@@ -148,7 +168,23 @@ PsReturnProcessPagedPoolQuota(IN PEPROCESS Process, IN ULONG_PTR Amount) { + /* Don't do anything for the system process */ + if (Process == PsInitialSystemProcess) return; + UNIMPLEMENTED; }
+NTSTATUS +NTAPI +PsReturnProcessPageFileQuota(IN PEPROCESS Process, + IN SIZE_T Amount) +{ + /* Don't do anything for the system process */ + if (Process == PsInitialSystemProcess) return STATUS_SUCCESS; + + /* Otherwise, not implemented */ + UNIMPLEMENTED; + return STATUS_SUCCESS; +} + /* EOF */