diff --git a/reactos/ntoskrnl/config/cmsysini.c b/reactos/ntoskrnl/config/cmsysini.c index 93ab54bbfd6..b8dae163186 100644 --- a/reactos/ntoskrnl/config/cmsysini.c +++ b/reactos/ntoskrnl/config/cmsysini.c @@ -333,7 +333,7 @@ CmpSetSystemValues(IN PLOADER_PARAMETER_BLOCK LoaderBlock) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName, ValueName = { 0, 0, NULL }; - HANDLE KeyHandle; + HANDLE KeyHandle = NULL; NTSTATUS Status; ASSERT(LoaderBlock != NULL); @@ -374,7 +374,7 @@ Quickie: RtlFreeUnicodeString(&ValueName); /* Close the key and return */ - NtClose(KeyHandle); + if (KeyHandle) NtClose(KeyHandle); /* Return the status */ return (ExpInTextModeSetup ? STATUS_SUCCESS : Status); @@ -1098,7 +1098,8 @@ CmpLoadHiveThread(IN PVOID StartContext) { WCHAR FileBuffer[MAX_PATH], RegBuffer[MAX_PATH], ConfigPath[MAX_PATH]; UNICODE_STRING TempName, FileName, RegName; - ULONG FileStart, i, ErrorResponse, WorkerCount, Length; + ULONG i, ErrorResponse, WorkerCount, Length; + USHORT FileStart; //ULONG RegStart; ULONG PrimaryDisposition, SecondaryDisposition, ClusterSize; PCMHIVE CmHive; @@ -1259,7 +1260,8 @@ CmpInitializeHiveList(IN USHORT Flag) UNICODE_STRING TempName, FileName, RegName; HANDLE Thread; NTSTATUS Status; - ULONG RegStart, i; + ULONG i; + USHORT RegStart; PSECURITY_DESCRIPTOR SecurityDescriptor; PAGED_CODE(); @@ -1611,25 +1613,25 @@ CmpFreeDriverList(IN PHHIVE Hive, PLIST_ENTRY NextEntry, OldEntry; PBOOT_DRIVER_NODE DriverNode; PAGED_CODE(); - + /* Parse the current list */ NextEntry = DriverList->Flink; while (NextEntry != DriverList) { /* Get the driver node */ DriverNode = CONTAINING_RECORD(NextEntry, BOOT_DRIVER_NODE, ListEntry.Link); - + /* Get the next entry now, since we're going to free it later */ OldEntry = NextEntry; NextEntry = NextEntry->Flink; - + /* Was there a name? */ if (DriverNode->Name.Buffer) { /* Free it */ CmpFree(DriverNode->Name.Buffer, DriverNode->Name.Length); } - + /* Was there a registry path? */ if (DriverNode->ListEntry.RegistryPath.Buffer) { @@ -1637,7 +1639,7 @@ CmpFreeDriverList(IN PHHIVE Hive, CmpFree(DriverNode->ListEntry.RegistryPath.Buffer, DriverNode->ListEntry.RegistryPath.MaximumLength); } - + /* Was there a file path? */ if (DriverNode->ListEntry.FilePath.Buffer) { @@ -1645,7 +1647,7 @@ CmpFreeDriverList(IN PHHIVE Hive, CmpFree(DriverNode->ListEntry.FilePath.Buffer, DriverNode->ListEntry.FilePath.MaximumLength); } - + /* Now free the node, and move on */ CmpFree(OldEntry, sizeof(BOOT_DRIVER_NODE)); } @@ -1673,7 +1675,7 @@ CmGetSystemDriverList(VOID) /* Initialize the driver list */ InitializeListHead(&DriverList); - + /* Open the system hive key */ RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\System"); InitializeObjectAttributes(&ObjectAttributes, @@ -1683,7 +1685,7 @@ CmGetSystemDriverList(VOID) NULL); Status = NtOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes); if (!NT_SUCCESS(Status)) return NULL; - + /* Reference the key object to get the root hive/cell to access directly */ Status = ObReferenceObjectByHandle(KeyHandle, KEY_QUERY_VALUE, @@ -1697,38 +1699,38 @@ CmGetSystemDriverList(VOID) NtClose(KeyHandle); return NULL; } - + /* Do all this under the registry lock */ CmpLockRegistryExclusive(); - + /* Get the hive and key cell */ Hive = KeyBody->KeyControlBlock->KeyHive; RootCell = KeyBody->KeyControlBlock->KeyCell; - + /* Open the current control set key */ RtlInitUnicodeString(&KeyName, L"Current"); ControlCell = CmpFindControlSet(Hive, RootCell, &KeyName, &AutoSelect); if (ControlCell == HCELL_NIL) goto EndPath; - + /* Find all system drivers */ Success = CmpFindDrivers(Hive, ControlCell, SystemLoad, NULL, &DriverList); if (!Success) goto EndPath; - + /* Sort by group/tag */ if (!CmpSortDriverList(Hive, ControlCell, &DriverList)) goto EndPath; - + /* Remove circular dependencies (cycles) and sort */ if (!CmpResolveDriverDependencies(&DriverList)) goto EndPath; - + /* Loop the list to count drivers */ for (i = 0, NextEntry = DriverList.Flink; NextEntry != &DriverList; i++, NextEntry = NextEntry->Flink); - + /* Allocate the array */ ServicePath = ExAllocatePool(NonPagedPool, (i + 1) * sizeof(PUNICODE_STRING)); if (!ServicePath) KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 2, 1, 0, 0); - + /* Loop the driver list */ for (i = 0, NextEntry = DriverList.Flink; NextEntry != &DriverList; @@ -1743,17 +1745,17 @@ CmGetSystemDriverList(VOID) &DriverEntry->RegistryPath, ServicePath[i]); } - + /* Terminate the list */ ServicePath[i] = NULL; - + EndPath: /* Free the driver list if we had one */ if (!IsListEmpty(&DriverList)) CmpFreeDriverList(Hive, &DriverList); - + /* Unlock the registry */ CmpUnlockRegistry(); - + /* Close the key handle and dereference the object, then return the path */ ObDereferenceObject(KeyBody); NtClose(KeyHandle); diff --git a/reactos/ntoskrnl/ex/zw.S b/reactos/ntoskrnl/ex/zw.S index bacead4d752..87441ef7502 100644 --- a/reactos/ntoskrnl/ex/zw.S +++ b/reactos/ntoskrnl/ex/zw.S @@ -5,7 +5,9 @@ #ifdef _M_IX86 EXTERN _KiSystemService:PROC #elif defined(_M_AMD64) +#include EXTERN KiSystemService:PROC +EXTERN KiZwSystemService:PROC #endif .code diff --git a/reactos/ntoskrnl/include/internal/amd64/ke.h b/reactos/ntoskrnl/include/internal/amd64/ke.h index 54ee8767c7b..b01e9940899 100644 --- a/reactos/ntoskrnl/include/internal/amd64/ke.h +++ b/reactos/ntoskrnl/include/internal/amd64/ke.h @@ -56,6 +56,8 @@ #define AMD64_TSS 9 +#define APIC_EOI_REGISTER 0xFFFFFFFFFFFE00B0ULL + #ifndef __ASM__ #include "intrin_i.h" @@ -68,6 +70,17 @@ typedef struct _KIDT_INIT PVOID ServiceRoutine; } KIDT_INIT, *PKIDT_INIT; +#include +typedef struct _KI_INTERRUPT_DISPATCH_ENTRY +{ + UCHAR _Op_nop; + UCHAR _Op_push; + UCHAR _Vector; + UCHAR _Op_jmp; + ULONG RelativeAddress; +} KI_INTERRUPT_DISPATCH_ENTRY, *PKI_INTERRUPT_DISPATCH_ENTRY; +#include + extern ULONG Ke386CacheAlignment; extern ULONG KeI386NpxPresent; extern ULONG KeI386XMMIPresent; @@ -95,7 +108,7 @@ extern ULONG KeI386CpuStep; ((TrapFrame)->Rip) #define KiGetLinkedTrapFrame(x) \ - (PKTRAP_FRAME)((x)->Rdx) + (PKTRAP_FRAME)((x)->TrapFrame) #define KeGetContextReturnRegister(Context) \ ((Context)->Rax) @@ -233,6 +246,14 @@ KeQueryInterruptHandler(IN ULONG Vector) (ULONG64)Idt->OffsetLow); } +VOID +FORCEINLINE +KiSendEOI() +{ + /* Write 0 to the apic EOI register */ + *((volatile ULONG*)APIC_EOI_REGISTER) = 0; +} + VOID FORCEINLINE KiEndInterrupt(IN KIRQL Irql, @@ -240,6 +261,7 @@ KiEndInterrupt(IN KIRQL Irql, { /* Make sure this is from the clock handler */ ASSERT(TrapFrame->ErrorCode == 0xc10c4); + //KeLowerIrql(Irql); } BOOLEAN diff --git a/reactos/ntoskrnl/include/internal/ke_x.h b/reactos/ntoskrnl/include/internal/ke_x.h index 8b0ef980b23..def10d75fc3 100644 --- a/reactos/ntoskrnl/include/internal/ke_x.h +++ b/reactos/ntoskrnl/include/internal/ke_x.h @@ -127,8 +127,8 @@ FORCEINLINE KIRQL KiAcquireDispatcherLock(VOID) { - /* Raise to DPC level */ - return KeRaiseIrqlToDpcLevel(); + /* Raise to synch level */ + return KfRaiseIrql(SYNCH_LEVEL); } FORCEINLINE @@ -303,7 +303,7 @@ KiAcquireDispatcherObject(IN DISPATCHER_HEADER* Object) /* Let the CPU know that this is a loop */ YieldProcessor(); - } + } /* Try acquiring the lock now */ } while (InterlockedCompareExchange(&Object->Lock, @@ -902,7 +902,7 @@ KiRemoveEntryTimer(IN PKTIMER Timer) { ULONG Hand; PKTIMER_TABLE_ENTRY TableEntry; - + /* Remove the timer from the timer list and check if it's empty */ Hand = Timer->Header.Hand; if (RemoveEntryList(&Timer->TimerListEntry)) @@ -962,17 +962,17 @@ KiComputeDueTime(IN PKTIMER Timer, OUT PULONG Hand) { LARGE_INTEGER InterruptTime, SystemTime, DifferenceTime; - + /* Convert to relative time if needed */ Timer->Header.Absolute = FALSE; if (DueTime.HighPart >= 0) { /* Get System Time */ KeQuerySystemTime(&SystemTime); - + /* Do the conversion */ DifferenceTime.QuadPart = SystemTime.QuadPart - DueTime.QuadPart; - + /* Make sure it hasn't already expired */ Timer->Header.Absolute = TRUE; if (DifferenceTime.HighPart >= 0) @@ -984,17 +984,17 @@ KiComputeDueTime(IN PKTIMER Timer, *Hand = 0; return FALSE; } - + /* Set the time as Absolute */ DueTime = DifferenceTime; } - + /* Get the Interrupt Time */ InterruptTime.QuadPart = KeQueryInterruptTime(); - + /* Recalculate due time */ Timer->DueTime.QuadPart = InterruptTime.QuadPart - DueTime.QuadPart; - + /* Get the handle */ *Hand = KiComputeTimerTableIndex(Timer->DueTime.QuadPart); Timer->Header.Hand = (UCHAR)*Hand; @@ -1515,7 +1515,7 @@ _KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex) GuardedMutex->Count = GM_LOCK_BIT; GuardedMutex->Owner = NULL; GuardedMutex->Contention = 0; - + /* Initialize the Wait Gate */ KeInitializeGate(&GuardedMutex->Gate); } @@ -1525,21 +1525,21 @@ VOID _KeAcquireGuardedMutexUnsafe(IN OUT PKGUARDED_MUTEX GuardedMutex) { PKTHREAD Thread = KeGetCurrentThread(); - + /* Sanity checks */ ASSERT((KeGetCurrentIrql() == APC_LEVEL) || (Thread->SpecialApcDisable < 0) || (Thread->Teb == NULL) || (Thread->Teb >= (PTEB)MM_SYSTEM_RANGE_START)); ASSERT(GuardedMutex->Owner != Thread); - + /* Remove the lock */ if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V)) { /* The Guarded Mutex was already locked, enter contented case */ KiAcquireGuardedMutex(GuardedMutex); } - + /* Set the Owner */ GuardedMutex->Owner = Thread; } @@ -1549,21 +1549,21 @@ VOID _KeReleaseGuardedMutexUnsafe(IN OUT PKGUARDED_MUTEX GuardedMutex) { LONG OldValue, NewValue; - + /* Sanity checks */ ASSERT((KeGetCurrentIrql() == APC_LEVEL) || (KeGetCurrentThread()->SpecialApcDisable < 0) || (KeGetCurrentThread()->Teb == NULL) || (KeGetCurrentThread()->Teb >= (PTEB)MM_SYSTEM_RANGE_START)); ASSERT(GuardedMutex->Owner == KeGetCurrentThread()); - + /* Destroy the Owner */ GuardedMutex->Owner = NULL; - + /* Add the Lock Bit */ OldValue = InterlockedExchangeAdd(&GuardedMutex->Count, GM_LOCK_BIT); ASSERT((OldValue & GM_LOCK_BIT) == 0); - + /* Check if it was already locked, but not woken */ if ((OldValue) && !(OldValue & GM_LOCK_WAITER_WOKEN)) { @@ -1573,7 +1573,7 @@ _KeReleaseGuardedMutexUnsafe(IN OUT PKGUARDED_MUTEX GuardedMutex) /* The mutex will be woken, minus one waiter */ NewValue = OldValue + GM_LOCK_WAITER_WOKEN - GM_LOCK_WAITER_INC; - + /* Remove the Woken bit */ if (InterlockedCompareExchange(&GuardedMutex->Count, NewValue, @@ -1590,21 +1590,21 @@ VOID _KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex) { PKTHREAD Thread = KeGetCurrentThread(); - + /* Sanity checks */ ASSERT(KeGetCurrentIrql() <= APC_LEVEL); ASSERT(GuardedMutex->Owner != Thread); - + /* Disable Special APCs */ KeEnterGuardedRegion(); - + /* Remove the lock */ if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V)) { /* The Guarded Mutex was already locked, enter contented case */ KiAcquireGuardedMutex(GuardedMutex); } - + /* Set the Owner and Special APC Disable state */ GuardedMutex->Owner = Thread; GuardedMutex->SpecialApcDisable = Thread->SpecialApcDisable; @@ -1615,20 +1615,20 @@ VOID _KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex) { LONG OldValue, NewValue; - + /* Sanity checks */ ASSERT(KeGetCurrentIrql() <= APC_LEVEL); ASSERT(GuardedMutex->Owner == KeGetCurrentThread()); ASSERT(KeGetCurrentThread()->SpecialApcDisable == GuardedMutex->SpecialApcDisable); - + /* Destroy the Owner */ GuardedMutex->Owner = NULL; - + /* Add the Lock Bit */ OldValue = InterlockedExchangeAdd(&GuardedMutex->Count, GM_LOCK_BIT); ASSERT((OldValue & GM_LOCK_BIT) == 0); - + /* Check if it was already locked, but not woken */ if ((OldValue) && !(OldValue & GM_LOCK_WAITER_WOKEN)) { @@ -1638,7 +1638,7 @@ _KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex) /* The mutex will be woken, minus one waiter */ NewValue = OldValue + GM_LOCK_WAITER_WOKEN - GM_LOCK_WAITER_INC; - + /* Remove the Woken bit */ if (InterlockedCompareExchange(&GuardedMutex->Count, NewValue, @@ -1648,7 +1648,7 @@ _KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex) KeSignalGateBoostPriority(&GuardedMutex->Gate); } } - + /* Re-enable APCs */ KeLeaveGuardedRegion(); } @@ -1658,21 +1658,21 @@ BOOLEAN _KeTryToAcquireGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex) { PKTHREAD Thread = KeGetCurrentThread(); - + /* Block APCs */ KeEnterGuardedRegion(); - + /* Remove the lock */ if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V)) { /* Re-enable APCs */ KeLeaveGuardedRegion(); YieldProcessor(); - + /* Return failure */ return FALSE; } - + /* Set the Owner and APC State */ GuardedMutex->Owner = Thread; GuardedMutex->SpecialApcDisable = Thread->SpecialApcDisable; diff --git a/reactos/ntoskrnl/include/internal/ob.h b/reactos/ntoskrnl/include/internal/ob.h index cc9ff526cca..dd1f375598b 100644 --- a/reactos/ntoskrnl/include/internal/ob.h +++ b/reactos/ntoskrnl/include/internal/ob.h @@ -56,8 +56,11 @@ // // Identifies a Kernel Handle // -#define KERNEL_HANDLE_FLAG \ - ((ULONG_PTR)1 << ((sizeof(HANDLE) * 8) - 1)) +#ifdef _WIN64 +#define KERNEL_HANDLE_FLAG 0xFFFFFFFF80000000ULL +#else +#define KERNEL_HANDLE_FLAG 0x80000000 +#endif #define ObIsKernelHandle(Handle, ProcessorMode) \ (((ULONG_PTR)(Handle) & KERNEL_HANDLE_FLAG) && \ ((ProcessorMode) == KernelMode)) diff --git a/reactos/ntoskrnl/io/iomgr/irp.c b/reactos/ntoskrnl/io/iomgr/irp.c index 91596bab657..97e9b192810 100644 --- a/reactos/ntoskrnl/io/iomgr/irp.c +++ b/reactos/ntoskrnl/io/iomgr/irp.c @@ -1650,7 +1650,8 @@ IoGetRequestorSessionId(IN PIRP Irp, /* Return the session */ if ((Process = IoGetRequestorProcess(Irp))) { - *pSessionId = Process->Session; + // FIXME: broken + *pSessionId = PtrToUlong(Process->Session); return STATUS_SUCCESS; } diff --git a/reactos/ntoskrnl/mm/ARM3/i386/init.c b/reactos/ntoskrnl/mm/ARM3/i386/init.c index d67b858461b..b8e161aeda6 100644 --- a/reactos/ntoskrnl/mm/ARM3/i386/init.c +++ b/reactos/ntoskrnl/mm/ARM3/i386/init.c @@ -281,8 +281,9 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock) // nonpaged pool expansion (above) and the system PTEs. Note that it is // then aligned to a PDE boundary (4MB). // + MiNonPagedSystemSize = (MmNumberOfSystemPtes + 1) * PAGE_SIZE; MmNonPagedSystemStart = (PVOID)((ULONG_PTR)MmNonPagedPoolStart - - (MmNumberOfSystemPtes + 1) * PAGE_SIZE); + MiNonPagedSystemSize); MmNonPagedSystemStart = (PVOID)((ULONG_PTR)MmNonPagedSystemStart & ~(PDE_MAPPED_VA - 1)); diff --git a/reactos/ntoskrnl/mm/ARM3/mdlsup.c b/reactos/ntoskrnl/mm/ARM3/mdlsup.c index ede078ee183..3932c68b1cf 100644 --- a/reactos/ntoskrnl/mm/ARM3/mdlsup.c +++ b/reactos/ntoskrnl/mm/ARM3/mdlsup.c @@ -593,6 +593,12 @@ MmProbeAndLockPages(IN PMDL Mdl, NTSTATUS ProbeStatus; PMMPTE PointerPte, LastPte; PMMPDE PointerPde; +#if (_MI_PAGING_LEVELS >= 3) + PMMPDE PointerPpe; +#endif +#if (_MI_PAGING_LEVELS == 4) + PMMPDE PointerPxe; +#endif PFN_NUMBER PageFrameIndex; BOOLEAN UsePfnLock; KIRQL OldIrql; @@ -741,8 +747,10 @@ MmProbeAndLockPages(IN PMDL Mdl, PointerPte = MiAddressToPte(StartAddress); PointerPde = MiAddressToPde(StartAddress); #if (_MI_PAGING_LEVELS >= 3) - DPRINT1("PAE/x64 Not Implemented\n"); - ASSERT(FALSE); + PointerPpe = MiAddressToPpe(StartAddress); +#endif +#if (_MI_PAGING_LEVELS == 4) + PointerPxe = MiAddressToPxe(StartAddress); #endif // @@ -776,7 +784,7 @@ MmProbeAndLockPages(IN PMDL Mdl, // // Check if this came from kernel mode // - if (Base >= MM_HIGHEST_USER_ADDRESS) + if (Base > MM_HIGHEST_USER_ADDRESS) { // // We should not have a process @@ -834,11 +842,14 @@ MmProbeAndLockPages(IN PMDL Mdl, // Assume failure and check for non-mapped pages // *MdlPages = LIST_HEAD; -#if (_MI_PAGING_LEVELS >= 3) - /* Should be checking the PPE and PXE */ - ASSERT(FALSE); + while ( +#if (_MI_PAGING_LEVELS == 4) + (PointerPxe->u.Hard.Valid == 0) || #endif - while ((PointerPde->u.Hard.Valid == 0) || +#if (_MI_PAGING_LEVELS >= 3) + (PointerPpe->u.Hard.Valid == 0) || +#endif + (PointerPde->u.Hard.Valid == 0) || (PointerPte->u.Hard.Valid == 0)) { // @@ -1042,7 +1053,14 @@ MmProbeAndLockPages(IN PMDL Mdl, PointerPte++; /* Check if we're on a PDE boundary */ - if (!((ULONG_PTR)PointerPte & (PD_SIZE - 1))) PointerPde++; + if (MiIsPteOnPdeBoundary(PointerPte)) PointerPde++; +#if (_MI_PAGING_LEVELS >= 3) + if (MiIsPteOnPpeBoundary(PointerPte)) PointerPpe++; +#endif +#if (_MI_PAGING_LEVELS == 4) + if (MiIsPteOnPxeBoundary(PointerPte)) PointerPxe++; +#endif + } while (PointerPte <= LastPte); // diff --git a/reactos/ntoskrnl/mm/ARM3/miarm.h b/reactos/ntoskrnl/mm/ARM3/miarm.h index 9fead56191f..5e0541e3a46 100644 --- a/reactos/ntoskrnl/mm/ARM3/miarm.h +++ b/reactos/ntoskrnl/mm/ARM3/miarm.h @@ -78,6 +78,8 @@ #define PDE_COUNT 1024 #define PTE_COUNT 1024 C_ASSERT(SYSTEM_PD_SIZE == PAGE_SIZE); +#define MiIsPteOnPdeBoundary(PointerPte) \ + ((((ULONG_PTR)PointerPte) & (PAGE_SIZE - 1)) == 0) #elif _M_ARM #define PD_COUNT 1 #define PDE_COUNT 4096 @@ -164,7 +166,7 @@ C_ASSERT(SYSTEM_PD_SIZE == PAGE_SIZE); #error Define these please! #endif -extern const ULONG MmProtectToPteMask[32]; +extern const ULONG_PTR MmProtectToPteMask[32]; extern const ULONG MmProtectToValue[32]; // @@ -262,7 +264,11 @@ extern const ULONG MmProtectToValue[32]; // // Prototype PTEs that don't yet have a pagefile association // +#ifdef _M_AMD64 +#define MI_PTE_LOOKUP_NEEDED 0xffffffffULL +#else #define MI_PTE_LOOKUP_NEEDED 0xFFFFF +#endif // // System views are binned into 64K chunks @@ -444,6 +450,7 @@ extern SIZE_T MmMaximumNonPagedPoolInBytes; extern PFN_NUMBER MmMaximumNonPagedPoolInPages; extern PFN_NUMBER MmSizeOfPagedPoolInPages; extern PVOID MmNonPagedSystemStart; +extern SIZE_T MiNonPagedSystemSize; extern PVOID MmNonPagedPoolStart; extern PVOID MmNonPagedPoolExpansionStart; extern PVOID MmNonPagedPoolEnd; @@ -1379,7 +1386,14 @@ MiRemoveZeroPageSafe(IN ULONG Color) // // New ARM3<->RosMM PAGE Architecture // +#ifdef _WIN64 +// HACK ON TOP OF HACK ALERT!!! +#define MI_GET_ROS_DATA(x) \ + (((x)->RosMmData == 0) ? NULL : ((PMMROSPFN)((ULONG64)(ULONG)((x)->RosMmData) | \ + ((ULONG64)MmNonPagedPoolStart & 0xffffffff00000000ULL)))) +#else #define MI_GET_ROS_DATA(x) ((PMMROSPFN)(x->RosMmData)) +#endif #define MI_IS_ROS_PFN(x) (((x)->u4.AweAllocation == TRUE) && (MI_GET_ROS_DATA(x) != NULL)) #define ASSERT_IS_ROS_PFN(x) ASSERT(MI_IS_ROS_PFN(x) == TRUE); typedef struct _MMROSPFN diff --git a/reactos/ntoskrnl/mm/ARM3/mminit.c b/reactos/ntoskrnl/mm/ARM3/mminit.c index 7e932e64836..524f20e822f 100644 --- a/reactos/ntoskrnl/mm/ARM3/mminit.c +++ b/reactos/ntoskrnl/mm/ARM3/mminit.c @@ -93,6 +93,7 @@ ULONG MmMaxAdditionNonPagedPoolPerMb = 400 * 1024; // http://www.ditii.com/2007/09/28/windows-memory-management-x86-virtual-address-space/ // PVOID MmNonPagedSystemStart; +SIZE_T MiNonPagedSystemSize; PVOID MmNonPagedPoolStart; PVOID MmNonPagedPoolExpansionStart; PVOID MmNonPagedPoolEnd = MI_NONPAGED_POOL_END; diff --git a/reactos/ntoskrnl/mm/ARM3/procsup.c b/reactos/ntoskrnl/mm/ARM3/procsup.c index 1d7ba0aabaa..6356f933fa0 100644 --- a/reactos/ntoskrnl/mm/ARM3/procsup.c +++ b/reactos/ntoskrnl/mm/ARM3/procsup.c @@ -913,7 +913,7 @@ MiInitializeWorkingSetList(IN PEPROCESS CurrentProcess) MmWorkingSetList->LastInitializedWsle = 4; /* The rule is that the owner process is always in the FLINK of the PDE's PFN entry */ - Pfn1 = MiGetPfnEntry(MiAddressToPte(PDE_BASE)->u.Hard.PageFrameNumber); + Pfn1 = MiGetPfnEntry(CurrentProcess->Pcb.DirectoryTableBase[0] >> PAGE_SHIFT); ASSERT(Pfn1->u4.PteFrame == MiGetPfnEntryIndex(Pfn1)); Pfn1->u1.Event = (PKEVENT)CurrentProcess; } @@ -963,13 +963,23 @@ MmInitializeProcessAddressSpace(IN PEPROCESS Process, OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock); /* Setup the PFN for the PDE base of this process */ +#ifdef _M_AMD64 + PointerPte = MiAddressToPte(PXE_BASE); +#else PointerPte = MiAddressToPte(PDE_BASE); +#endif PageFrameNumber = PFN_FROM_PTE(PointerPte); + ASSERT(Process->Pcb.DirectoryTableBase[0] == PageFrameNumber * PAGE_SIZE); MiInitializePfn(PageFrameNumber, PointerPte, TRUE); /* Do the same for hyperspace */ +#ifdef _M_AMD64 + PointerPde = MiAddressToPxe((PVOID)HYPER_SPACE); +#else PointerPde = MiAddressToPde(HYPER_SPACE); +#endif PageFrameNumber = PFN_FROM_PTE(PointerPde); + //ASSERT(Process->Pcb.DirectoryTableBase[0] == PageFrameNumber * PAGE_SIZE); // we're not lucky MiInitializePfn(PageFrameNumber, (PMMPTE)PointerPde, TRUE); /* Setup the PFN for the PTE for the working set */ diff --git a/reactos/ntoskrnl/mm/ARM3/special.c b/reactos/ntoskrnl/mm/ARM3/special.c index ad599428340..2aa97a48043 100644 --- a/reactos/ntoskrnl/mm/ARM3/special.c +++ b/reactos/ntoskrnl/mm/ARM3/special.c @@ -261,7 +261,7 @@ MmAllocateSpecialPool(SIZE_T NumberOfBytes, ULONG Tag, POOL_TYPE PoolType, ULONG RtlZeroMemory(Header, sizeof(POOL_HEADER)); /* Save allocation size there */ - Header->Ulong1 = NumberOfBytes; + Header->Ulong1 = (ULONG)NumberOfBytes; /* Make sure it's all good */ ASSERT((NumberOfBytes <= PAGE_SIZE - sizeof(POOL_HEADER)) && @@ -286,7 +286,7 @@ MmAllocateSpecialPool(SIZE_T NumberOfBytes, ULONG Tag, POOL_TYPE PoolType, ULONG That time will be used to check memory consistency within the allocated page. */ Header->PoolTag = Tag; - Header->BlockSize = TickCount.LowPart; + Header->BlockSize = (USHORT)TickCount.LowPart; DPRINT1("%p\n", Entry); return Entry; } @@ -305,7 +305,7 @@ MiSpecialPoolCheckPattern(PUCHAR P, PPOOL_HEADER Header) Ptr = P + BytesRequested; /* Calculate how many bytes to check */ - BytesToCheck = (PUCHAR)PAGE_ALIGN(P) + PAGE_SIZE - Ptr; + BytesToCheck = (ULONG)((PUCHAR)PAGE_ALIGN(P) + PAGE_SIZE - Ptr); /* Remove pool header size if we're catching underruns */ if (((ULONG_PTR)P & (PAGE_SIZE - 1)) == 0) @@ -335,7 +335,7 @@ MmFreeSpecialPool(PVOID P) KIRQL Irql = KeGetCurrentIrql(); POOL_TYPE PoolType; ULONG BytesRequested, BytesReal = 0; - ULONG_PTR PtrOffset; + ULONG PtrOffset; PUCHAR b; PMI_FREED_SPECIAL_POOL FreedHeader; LARGE_INTEGER TickCount; @@ -358,7 +358,7 @@ MmFreeSpecialPool(PVOID P) } /* Determine if it's a underruns or overruns pool pointer */ - PtrOffset = (ULONG_PTR)P & (PAGE_SIZE - 1); + PtrOffset = (ULONG)((ULONG_PTR)P & (PAGE_SIZE - 1)); if (PtrOffset) { /* Pool catches overruns */ diff --git a/reactos/ntoskrnl/ps/job.c b/reactos/ntoskrnl/ps/job.c index 7bded05b5ef..7f1ac67005e 100644 --- a/reactos/ntoskrnl/ps/job.c +++ b/reactos/ntoskrnl/ps/job.c @@ -165,7 +165,8 @@ NtAssignProcessToJobObject ( ExAcquireRundownProtection(&Process->RundownProtect); if(NT_SUCCESS(Status)) { - if(Process->Job == NULL && Process->Session == Job->SessionId) + // FIXME: This is broken + if(Process->Job == NULL && PtrToUlong(Process->Session) == Job->SessionId) { /* Just store the pointer to the job object in the process, we'll assign it later. The reason we can't do this here is that locking @@ -269,7 +270,7 @@ NtCreateJobObject ( /* setup the job object */ InitializeListHead(&Job->ProcessListHead); - Job->SessionId = CurrentProcess->Session; /* inherit the session id from the caller */ + Job->SessionId = PtrToUlong(CurrentProcess->Session); /* inherit the session id from the caller, FIXME: broken */ Status = ExInitializeResource(&Job->JobLock); if(!NT_SUCCESS(Status)) diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index ce5232d9546..a5ff7d14ab0 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -1113,7 +1113,8 @@ ULONG NTAPI PsGetCurrentProcessSessionId(VOID) { - return PsGetCurrentProcess()->Session; + // FIXME: this is broken! + return PtrToUlong(PsGetCurrentProcess()->Session); } /* diff --git a/reactos/ntoskrnl/ps/query.c b/reactos/ntoskrnl/ps/query.c index 15ec9123c1c..1fbf36a4be1 100644 --- a/reactos/ntoskrnl/ps/query.c +++ b/reactos/ntoskrnl/ps/query.c @@ -419,7 +419,7 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle, _SEH2_TRY { /* Write back the Session ID */ - SessionInfo->SessionId = Process->Session; //MmGetSessionId(Process); + SessionInfo->SessionId = PtrToUlong(PsGetProcessSessionId(Process)); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { @@ -818,32 +818,32 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle, } _SEH2_END; break; - + case ProcessImageInformation: DPRINT1("Image Information Query Not implemented: %lx\n", ProcessInformationClass); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessDebugObjectHandle: DPRINT1("Debug Object Query Not implemented: %lx\n", ProcessInformationClass); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessHandleTracing: DPRINT1("Handle tracing Not implemented: %lx\n", ProcessInformationClass); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessLUIDDeviceMapsEnabled: DPRINT1("LUID Device Maps Not implemented: %lx\n", ProcessInformationClass); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessExecuteFlags: DPRINT1("No execute Not implemented: %lx\n", ProcessInformationClass); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessWow64Information: case ProcessLdtInformation: case ProcessWx86Information: @@ -855,12 +855,12 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle, DPRINT1("WS Watch Not implemented: %lx\n", ProcessInformationClass); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessPooledUsageAndLimits: DPRINT1("Pool limits Not implemented: %lx\n", ProcessInformationClass); Status = STATUS_NOT_IMPLEMENTED; break; - + /* Not supported by Server 2003 */ default: DPRINT1("Unsupported info class: %lx\n", ProcessInformationClass); @@ -978,7 +978,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, Status = STATUS_PRIVILEGE_NOT_HELD; break; } - + /* Get the LPC Port */ Status = ObReferenceObjectByHandle(PortHandle, 0, @@ -1050,10 +1050,10 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, _SEH2_YIELD(break); } _SEH2_END; - + /* Set the mode */ Process->DefaultHardErrorProcessing = DefaultHardErrorMode; - + /* Call Ke for the update */ if (DefaultHardErrorMode & SEM_NOALIGNMENTFAULTEXCEPT) { @@ -1219,7 +1219,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, PsProcessPriorityBackground); Status = STATUS_SUCCESS; break; - + case ProcessBasePriority: /* Validate input length */ @@ -1242,7 +1242,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, _SEH2_YIELD(break); } _SEH2_END; - + /* Extract the memory priority out of there */ if (BasePriority & 0x80000000) { @@ -1253,22 +1253,22 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, { MemoryPriority = MEMORY_PRIORITY_BACKGROUND; } - + /* Validate the number */ if ((BasePriority > HIGH_PRIORITY) || (BasePriority <= LOW_PRIORITY)) { return STATUS_INVALID_PARAMETER; } - + /* Check if the new base is higher */ if (BasePriority > Process->Pcb.BasePriority) { DPRINT1("Should check privilege\n"); } - + /* Call Ke */ KeSetPriorityAndQuantumProcess(&Process->Pcb, BasePriority, 0); - + /* Now set the memory priority */ MmSetMemoryPriorityProcess(Process, MemoryPriority); Status = STATUS_SUCCESS; @@ -1351,14 +1351,14 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, _SEH2_YIELD(break); } _SEH2_END; - + /* Setting 'break on termination' requires the SeDebugPrivilege */ if (!SeSinglePrivilegeCheck(SeDebugPrivilege, PreviousMode)) { Status = STATUS_PRIVILEGE_NOT_HELD; break; } - + /* Set or clear the flag */ if (Break) { @@ -1370,9 +1370,9 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, } break; - + case ProcessAffinityMask: - + /* Check buffer length */ if (ProcessInformationLength != sizeof(KAFFINITY)) { @@ -1393,7 +1393,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, _SEH2_YIELD(break); } _SEH2_END; - + /* Make sure it's valid for the CPUs present */ ValidAffinity = Affinity & KeActiveProcessors; if (!Affinity || (ValidAffinity != Affinity)) @@ -1435,7 +1435,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, Status = STATUS_PROCESS_IS_TERMINATING; } break; - + /* Priority Boosting status */ case ProcessPriorityBoost: @@ -1469,7 +1469,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, /* Call Ke to do the work */ KeSetDisableBoostProcess(&Process->Pcb, DisableBoost); - + /* Loop the threads too */ for (Next = Process->ThreadListHead.Flink; Next != &Process->ThreadListHead; @@ -1494,7 +1494,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, Status = STATUS_PROCESS_IS_TERMINATING; } break; - + case ProcessDebugFlags: /* Check buffer length */ @@ -1516,7 +1516,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, _SEH2_YIELD(break); } _SEH2_END; - + /* Set the mode */ if (DebugFlags & ~1) { @@ -1537,7 +1537,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, /* Done */ Status = STATUS_SUCCESS; break; - + case ProcessEnableAlignmentFaultFixup: /* Check buffer length */ @@ -1559,7 +1559,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, _SEH2_YIELD(break); } _SEH2_END; - + /* Set the mode */ if (EnableFixup) { @@ -1569,12 +1569,12 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, { Process->DefaultHardErrorProcessing &= ~SEM_NOALIGNMENTFAULTEXCEPT; } - + /* Call Ke for the update */ KeSetAutoAlignmentProcess(&Process->Pcb, FALSE); Status = STATUS_SUCCESS; break; - + /* We currently don't implement any of these */ case ProcessLdtInformation: case ProcessLdtSize: @@ -1584,32 +1584,32 @@ NtSetInformationProcess(IN HANDLE ProcessHandle, DPRINT1("VDM/16-bit Request not implemented: %lx\n", ProcessInformationClass); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessQuotaLimits: DPRINT1("Quota Limits not implemented\n"); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessWorkingSetWatch: DPRINT1("WS watch not implemented\n"); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessDeviceMap: DPRINT1("Device map not implemented\n"); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessHandleTracing: DPRINT1("Handle tracing not implemented\n"); Status = STATUS_NOT_IMPLEMENTED; break; - + case ProcessExecuteFlags: DPRINT1("No execute support not implemented\n"); Status = STATUS_NOT_IMPLEMENTED; break; - + /* Anything else is invalid */ default: DPRINT1("Invalid Server 2003 Info Class: %lx\n", ProcessInformationClass);