From 21a56a9d822d20df596e9ef4c905a79e6cf6d63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Sun, 25 Jul 2010 16:44:57 +0000 Subject: [PATCH] sync with trunk (r48253) svn path=/branches/reactos-yarotows/; revision=48255 --- base/applications/network/ipconfig/ipconfig.c | 6 +- base/setup/usetup/inffile.c | 40 ----- base/setup/usetup/inffile.h | 31 +--- base/setup/usetup/usetup.h | 1 + include/psdk/ntdef.h | 2 +- include/psdk/winnt.h | 8 +- include/psdk/wspiapi.h | 6 +- lib/3rdparty/mingw/tlsmcrt.c | 31 ++++ .../include/freebsd/src/sys/sys/kernel.h | 5 + lib/inflib/infget.c | 2 +- lib/inflib/infpriv.h | 2 +- lib/inflib/infros.h | 2 +- lib/inflib/infrosget.c | 2 +- lib/newinflib/infget.c | 2 +- lib/newinflib/infhost.h | 2 +- lib/newinflib/infhostget.c | 4 +- lib/newinflib/infpriv.h | 2 +- lib/newinflib/infros.h | 2 +- lib/newinflib/infrosget.c | 2 +- lib/sdk/crt/time/asctime.c | 2 +- ntoskrnl/include/internal/amd64/mm.h | 15 +- ntoskrnl/include/internal/i386/mm.h | 6 + ntoskrnl/include/internal/lpc_x.h | 2 +- ntoskrnl/mm/ARM3/largepag.c | 3 +- ntoskrnl/mm/ARM3/miarm.h | 53 +----- ntoskrnl/mm/ARM3/mmsup.c | 34 ++-- ntoskrnl/mm/ARM3/procsup.c | 2 + ntoskrnl/mm/amd64/page.c | 168 ++++++++++++++---- ntoskrnl/mm/i386/page.c | 51 ++++++ 29 files changed, 295 insertions(+), 193 deletions(-) diff --git a/base/applications/network/ipconfig/ipconfig.c b/base/applications/network/ipconfig/ipconfig.c index 5bb2d95fc25..3d9de7d8e19 100644 --- a/base/applications/network/ipconfig/ipconfig.c +++ b/base/applications/network/ipconfig/ipconfig.c @@ -359,6 +359,7 @@ CLEANUP: VOID ShowInfo(BOOL bAll) { + MIB_IFROW mibEntry; PIP_ADAPTER_INFO pAdapterInfo = NULL; PIP_ADAPTER_INFO pAdapter = NULL; ULONG adaptOutBufLen = 0; @@ -441,6 +442,9 @@ VOID ShowInfo(BOOL bAll) { LPTSTR IntType, myConType; + mibEntry.dwIndex = pAdapter->Index; + GetIfEntry(&mibEntry); + IntType = GetInterfaceTypeName(pAdapter->Type); myConType = GetConnectionType(pAdapter->AdapterName); @@ -449,7 +453,7 @@ VOID ShowInfo(BOOL bAll) if (myConType != NULL) HeapFree(ProcessHeap, 0, myConType); /* check if the adapter is connected to the media */ - if (_tcscmp(pAdapter->IpAddressList.IpAddress.String, "0.0.0.0") == 0) + if (mibEntry.dwOperStatus != MIB_IF_OPER_STATUS_CONNECTED && mibEntry.dwOperStatus != MIB_IF_OPER_STATUS_OPERATIONAL) { _tprintf(_T("\tMedia State . . . . . . . . . . . : Media disconnected\n")); pAdapter = pAdapter->Next; diff --git a/base/setup/usetup/inffile.c b/base/setup/usetup/inffile.c index 0bbde01d9da..7b0d2a9748a 100644 --- a/base/setup/usetup/inffile.c +++ b/base/setup/usetup/inffile.c @@ -65,46 +65,6 @@ InfpFindFirstLineW( return TRUE; } -BOOL WINAPI -InfpFindNextLine( - IN PINFCONTEXT ContextIn, - OUT PINFCONTEXT ContextOut) -{ - return InfFindNextLine(ContextIn, ContextOut); -} - -BOOL WINAPI -InfpGetBinaryField( - IN PINFCONTEXT Context, - IN ULONG FieldIndex, - IN OUT BYTE* ReturnBuffer, - IN ULONG ReturnBufferSize, - OUT PULONG RequiredSize) -{ - return InfGetBinaryField(Context, FieldIndex, ReturnBuffer, ReturnBufferSize, RequiredSize); -} - -DWORD WINAPI -InfpGetFieldCount( - IN PINFCONTEXT Context) -{ - return (DWORD)InfGetFieldCount(Context); -} - -BOOL WINAPI -InfpGetIntField( - IN PINFCONTEXT Context, - IN DWORD FieldIndex, - OUT PINT IntegerValue) -{ - LONG IntegerValueL; - BOOL ret; - - ret = InfGetIntField(Context, FieldIndex, &IntegerValueL); - *IntegerValue = (INT)IntegerValueL; - return ret; -} - BOOL WINAPI InfpGetMultiSzFieldW( IN PINFCONTEXT Context, diff --git a/base/setup/usetup/inffile.h b/base/setup/usetup/inffile.h index 864d2017020..4a5b8d9360f 100644 --- a/base/setup/usetup/inffile.h +++ b/base/setup/usetup/inffile.h @@ -36,10 +36,10 @@ #define SetupCloseInfFile InfpCloseInfFile #define SetupFindFirstLineW InfpFindFirstLineW -#define SetupFindNextLine InfpFindNextLine -#define SetupGetBinaryField InfpGetBinaryField -#define SetupGetFieldCount InfpGetFieldCount -#define SetupGetIntField InfpGetIntField +#define SetupFindNextLine InfFindNextLine +#define SetupGetBinaryField InfGetBinaryField +#define SetupGetFieldCount InfGetFieldCount +#define SetupGetIntField InfGetIntField #define SetupGetMultiSzFieldW InfpGetMultiSzFieldW #define SetupGetStringFieldW InfpGetStringFieldW #define SetupOpenInfFileW InfpOpenInfFileW @@ -66,29 +66,6 @@ InfpFindFirstLineW( IN PCWSTR Key, IN OUT PINFCONTEXT Context); -BOOL WINAPI -InfpFindNextLine( - IN PINFCONTEXT ContextIn, - OUT PINFCONTEXT ContextOut); - -BOOL WINAPI -InfpGetBinaryField( - IN PINFCONTEXT Context, - IN ULONG FieldIndex, - IN OUT BYTE* ReturnBuffer, - IN ULONG ReturnBufferSize, - OUT PULONG RequiredSize); - -DWORD WINAPI -InfpGetFieldCount( - IN PINFCONTEXT Context); - -BOOL WINAPI -InfpGetIntField( - IN PINFCONTEXT Context, - IN DWORD FieldIndex, - OUT PINT IntegerValue); - BOOL WINAPI InfpGetMultiSzFieldW( IN PINFCONTEXT Context, diff --git a/base/setup/usetup/usetup.h b/base/setup/usetup/usetup.h index b95ad66347a..ff7cf87fb84 100644 --- a/base/setup/usetup/usetup.h +++ b/base/setup/usetup/usetup.h @@ -50,6 +50,7 @@ /* Internal Headers */ #include "interface/consup.h" #include "partlist.h" +#include "infros.h" #include "inffile.h" #include "inicache.h" #include "progress.h" diff --git a/include/psdk/ntdef.h b/include/psdk/ntdef.h index d25ff9f3f4a..aaf5182d9d3 100644 --- a/include/psdk/ntdef.h +++ b/include/psdk/ntdef.h @@ -240,7 +240,7 @@ #elif (_MSC_VER) #define FORCEINLINE __inline #else -#define FORCEINLINE static __inline__ __attribute__((always_inline)) +#define FORCEINLINE extern __inline__ __attribute__((always_inline)) #endif #endif diff --git a/include/psdk/winnt.h b/include/psdk/winnt.h index 2df2d5fa55e..47e0cb85b37 100644 --- a/include/psdk/winnt.h +++ b/include/psdk/winnt.h @@ -79,7 +79,7 @@ extern "C" { #elif (_MSC_VER) #define FORCEINLINE __inline #else -#define FORCEINLINE static __inline__ __attribute__((always_inline)) +#define FORCEINLINE extern __inline__ __attribute__((always_inline)) #endif #endif @@ -5112,7 +5112,7 @@ static __inline__ PVOID GetCurrentFiber(void) #endif #if defined(_M_IX86) -static __inline__ struct _TEB * NtCurrentTeb(void) +extern __inline__ struct _TEB * NtCurrentTeb(void) { struct _TEB *ret; @@ -5137,12 +5137,12 @@ FORCEINLINE struct _TEB * NtCurrentTeb(VOID) return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self)); } #elif defined(_M_PPC) -static __inline__ struct _TEB * NtCurrentTeb(void) +extern __inline__ struct _TEB * NtCurrentTeb(void) { return __readfsdword_winnt(0x18); } #else -static __inline__ struct _TEB * NtCurrentTeb(void) +extern __inline__ struct _TEB * NtCurrentTeb(void) { return __readfsdword_winnt(0x18); } diff --git a/include/psdk/wspiapi.h b/include/psdk/wspiapi.h index 4b4b5ce6008..ea41ec8ab47 100644 --- a/include/psdk/wspiapi.h +++ b/include/psdk/wspiapi.h @@ -236,7 +236,7 @@ WspiapiClone( return 0; } -FORCEINLINE +static __inline void WINAPI WspiapiLegacyFreeAddrInfo( @@ -252,7 +252,7 @@ WspiapiLegacyFreeAddrInfo( } } -FORCEINLINE +static __inline int WINAPI WspiapiLegacyGetAddrInfo( @@ -352,7 +352,7 @@ WspiapiLegacyGetAddrInfo( return (iError); } -FORCEINLINE +static __inline int WINAPI WspiapiLegacyGetNameInfo( diff --git a/lib/3rdparty/mingw/tlsmcrt.c b/lib/3rdparty/mingw/tlsmcrt.c index 2450b8b9216..c5c01d9b8a6 100644 --- a/lib/3rdparty/mingw/tlsmcrt.c +++ b/lib/3rdparty/mingw/tlsmcrt.c @@ -11,3 +11,34 @@ we do tls cleanup in runtime and _CRT_MT has value 2. */ int _CRT_MT = 2; +// HACK around broken imports from libmingwex, until RosBE64 is updated +#ifdef _M_AMD64 + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#include + +int __mingwthr_key_dtor (DWORD key, void (*dtor)(void *)); +int __mingwthr_remove_key_dtor (DWORD key); + +extern int ___w64_mingwthr_remove_key_dtor (DWORD key); +extern int ___w64_mingwthr_add_key_dtor (DWORD key, void (*dtor)(void *)); + +int +__mingwthr_remove_key_dtor (DWORD key) +{ + return ___w64_mingwthr_remove_key_dtor (key); +} + +int +__mingwthr_key_dtor (DWORD key, void (*dtor)(void *)) +{ + if (dtor) + return ___w64_mingwthr_add_key_dtor (key, dtor); + + return 0; +} +#endif + diff --git a/lib/drivers/oskittcp/include/freebsd/src/sys/sys/kernel.h b/lib/drivers/oskittcp/include/freebsd/src/sys/sys/kernel.h index 2d42aee9f5c..18f031a900c 100644 --- a/lib/drivers/oskittcp/include/freebsd/src/sys/sys/kernel.h +++ b/lib/drivers/oskittcp/include/freebsd/src/sys/sys/kernel.h @@ -83,9 +83,14 @@ extern long timedelta; #ifdef _MSC_VER #define MAKE_SET(set, sym, type) #else +#if defined(_M_AMD64) +#define MAKE_SET(set, sym, type) \ + asm(".stabs \"" #set "\", " #type ", 0, 0, " #sym) +#else #define MAKE_SET(set, sym, type) \ asm(".stabs \"_" #set "\", " #type ", 0, 0, _" #sym) #endif +#endif #define TEXT_SET(set, sym) MAKE_SET(set, sym, 23) #define DATA_SET(set, sym) MAKE_SET(set, sym, 25) #define BSS_SET(set, sym) MAKE_SET(set, sym, 27) diff --git a/lib/inflib/infget.c b/lib/inflib/infget.c index 104cb3d1691..b21b2ddd958 100644 --- a/lib/inflib/infget.c +++ b/lib/inflib/infget.c @@ -271,7 +271,7 @@ InfpGetBinaryField(PINFCONTEXT Context, INFSTATUS InfpGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - PLONG IntegerValue) + INT* IntegerValue) { PINFCACHELINE CacheLine; PINFCACHEFIELD CacheField; diff --git a/lib/inflib/infpriv.h b/lib/inflib/infpriv.h index 0dd7d88bba6..e4424cc1575 100644 --- a/lib/inflib/infpriv.h +++ b/lib/inflib/infpriv.h @@ -115,7 +115,7 @@ extern INFSTATUS InfpGetBinaryField(PINFCONTEXT Context, PULONG RequiredSize); extern INFSTATUS InfpGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - PLONG IntegerValue); + INT* IntegerValue); extern INFSTATUS InfpGetMultiSzField(PINFCONTEXT Context, ULONG FieldIndex, PTSTR ReturnBuffer, diff --git a/lib/inflib/infros.h b/lib/inflib/infros.h index 7de69673996..80e8692ca56 100644 --- a/lib/inflib/infros.h +++ b/lib/inflib/infros.h @@ -48,7 +48,7 @@ extern BOOLEAN InfGetBinaryField(PINFCONTEXT Context, PULONG RequiredSize); extern BOOLEAN InfGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - PLONG IntegerValue); + PINT IntegerValue); extern BOOLEAN InfGetMultiSzField(PINFCONTEXT Context, ULONG FieldIndex, PWSTR ReturnBuffer, diff --git a/lib/inflib/infrosget.c b/lib/inflib/infrosget.c index 9f3e7b06abf..ee919cb4288 100644 --- a/lib/inflib/infrosget.c +++ b/lib/inflib/infrosget.c @@ -84,7 +84,7 @@ InfGetBinaryField(PINFCONTEXT Context, BOOLEAN InfGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - PLONG IntegerValue) + PINT IntegerValue) { return INF_SUCCESS(InfpGetIntField(Context, FieldIndex, IntegerValue)); } diff --git a/lib/newinflib/infget.c b/lib/newinflib/infget.c index e2b360ab22d..666f71232da 100644 --- a/lib/newinflib/infget.c +++ b/lib/newinflib/infget.c @@ -416,7 +416,7 @@ InfpGetBinaryField(PINFCONTEXT Context, INFSTATUS InfpGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - PLONG IntegerValue) + INT *IntegerValue) { PINFCACHELINE CacheLine; PINFCACHEFIELD CacheField; diff --git a/lib/newinflib/infhost.h b/lib/newinflib/infhost.h index b1dfaaf8a86..e1ee6d012ec 100644 --- a/lib/newinflib/infhost.h +++ b/lib/newinflib/infhost.h @@ -49,7 +49,7 @@ extern int InfHostGetBinaryField(PINFCONTEXT Context, ULONG *RequiredSize); extern int InfHostGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - ULONG *IntegerValue); + INT *IntegerValue); extern int InfHostGetMultiSzField(PINFCONTEXT Context, ULONG FieldIndex, WCHAR *ReturnBuffer, diff --git a/lib/newinflib/infhostget.c b/lib/newinflib/infhostget.c index bd49be17002..e1714d6aec6 100644 --- a/lib/newinflib/infhostget.c +++ b/lib/newinflib/infhostget.c @@ -138,11 +138,11 @@ InfHostGetBinaryField(PINFCONTEXT Context, int InfHostGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - ULONG *IntegerValue) + INT *IntegerValue) { INFSTATUS Status; - Status = InfpGetIntField(Context, FieldIndex, (PLONG)IntegerValue); + Status = InfpGetIntField(Context, FieldIndex, IntegerValue); if (INF_SUCCESS(Status)) { return 0; diff --git a/lib/newinflib/infpriv.h b/lib/newinflib/infpriv.h index c7adededd5d..f1b3341a201 100644 --- a/lib/newinflib/infpriv.h +++ b/lib/newinflib/infpriv.h @@ -116,7 +116,7 @@ extern INFSTATUS InfpGetBinaryField(PINFCONTEXT Context, PULONG RequiredSize); extern INFSTATUS InfpGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - PLONG IntegerValue); + INT *IntegerValue); extern INFSTATUS InfpGetMultiSzField(PINFCONTEXT Context, ULONG FieldIndex, PWSTR ReturnBuffer, diff --git a/lib/newinflib/infros.h b/lib/newinflib/infros.h index 92dbc5133db..37868147463 100644 --- a/lib/newinflib/infros.h +++ b/lib/newinflib/infros.h @@ -50,7 +50,7 @@ extern BOOLEAN InfGetBinaryField(PINFCONTEXT Context, PULONG RequiredSize); extern BOOLEAN InfGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - PLONG IntegerValue); + INT *IntegerValue); extern BOOLEAN InfGetMultiSzField(PINFCONTEXT Context, ULONG FieldIndex, PWSTR ReturnBuffer, diff --git a/lib/newinflib/infrosget.c b/lib/newinflib/infrosget.c index 9f3e7b06abf..9094d23c914 100644 --- a/lib/newinflib/infrosget.c +++ b/lib/newinflib/infrosget.c @@ -84,7 +84,7 @@ InfGetBinaryField(PINFCONTEXT Context, BOOLEAN InfGetIntField(PINFCONTEXT Context, ULONG FieldIndex, - PLONG IntegerValue) + INT *IntegerValue) { return INF_SUCCESS(InfpGetIntField(Context, FieldIndex, IntegerValue)); } diff --git a/lib/sdk/crt/time/asctime.c b/lib/sdk/crt/time/asctime.c index 84e059186d2..377269d693f 100644 --- a/lib/sdk/crt/time/asctime.c +++ b/lib/sdk/crt/time/asctime.c @@ -73,7 +73,7 @@ IntToChar2(int x) return u.char2; } -FORCEINLINE +static __inline void FillBuf(timebuf_t *buf, const struct tm *ptm) { diff --git a/ntoskrnl/include/internal/amd64/mm.h b/ntoskrnl/include/internal/amd64/mm.h index 889c43e9684..a9d865b8942 100644 --- a/ntoskrnl/include/internal/amd64/mm.h +++ b/ntoskrnl/include/internal/amd64/mm.h @@ -4,6 +4,8 @@ #pragma once +#define _MI_PAGING_LEVELS 4 + /* Helper macros */ #define PAGE_MASK(x) ((x)&(~0xfff)) #define PAE_PAGE_MASK(x) ((x)&(~0xfffLL)) @@ -106,12 +108,17 @@ ULONG FORCEINLINE MiAddressToPti(PVOID Address) { - ULONG64 Pti = (ULONG64)Address >> PTI_SHIFT; - Pti &= PTI_MASK_AMD64; - return Pti; + return ((((ULONG64)Address) >> PTI_SHIFT) & 0x1FF); +} +#define MiAddressToPteOffset(x) MiAddressToPti(x) // FIXME: bad name + +ULONG +FORCEINLINE +MiAddressToPxi(PVOID Address) +{ + return ((((ULONG64)Address) >> PXI_SHIFT) & 0x1FF); } -#define MiAddressToPteOffset(x) MiAddressToPti(x) /* Convert a PTE into a corresponding address */ PVOID diff --git a/ntoskrnl/include/internal/i386/mm.h b/ntoskrnl/include/internal/i386/mm.h index edd86bbaab4..1014884b099 100644 --- a/ntoskrnl/include/internal/i386/mm.h +++ b/ntoskrnl/include/internal/i386/mm.h @@ -7,6 +7,12 @@ struct _EPROCESS; PULONG MmGetPageDirectory(VOID); +#ifdef _PAE_ +#define _MI_PAGING_LEVELS 3 +#else +#define _MI_PAGING_LEVELS 2 +#endif + #define PAGE_MASK(x) ((x)&(~0xfff)) #define PAE_PAGE_MASK(x) ((x)&(~0xfffLL)) diff --git a/ntoskrnl/include/internal/lpc_x.h b/ntoskrnl/include/internal/lpc_x.h index 80c66e41129..3c688fbfedc 100644 --- a/ntoskrnl/include/internal/lpc_x.h +++ b/ntoskrnl/include/internal/lpc_x.h @@ -95,7 +95,7 @@ // // Allocates a new message // -FORCEINLINE +static __inline PLPCP_MESSAGE LpcpAllocateFromPortZone(VOID) { diff --git a/ntoskrnl/mm/ARM3/largepag.c b/ntoskrnl/mm/ARM3/largepag.c index 0cd1e502f2e..01917b89876 100644 --- a/ntoskrnl/mm/ARM3/largepag.c +++ b/ntoskrnl/mm/ARM3/largepag.c @@ -34,7 +34,8 @@ NTAPI MiInitializeLargePageSupport(VOID) { #if _MI_PAGING_LEVELS > 2 -#error "PAE/x64 Not Implemented" + DPRINT1("PAE/x64 Not Implemented\n"); + ASSERT(FALSE); #else /* Initialize the large-page hyperspace PTE used for initial mapping */ MiLargePageHyperPte = MiReserveSystemPtes(1, SystemPteSpace); diff --git a/ntoskrnl/mm/ARM3/miarm.h b/ntoskrnl/mm/ARM3/miarm.h index c5776338d94..59aac80d99a 100644 --- a/ntoskrnl/mm/ARM3/miarm.h +++ b/ntoskrnl/mm/ARM3/miarm.h @@ -139,56 +139,9 @@ #else #error Define these please! #endif -static const -ULONG -MmProtectToPteMask[32] = -{ - // - // These are the base MM_ protection flags - // - 0, - PTE_READONLY | PTE_ENABLE_CACHE, - PTE_EXECUTE | PTE_ENABLE_CACHE, - PTE_EXECUTE_READ | PTE_ENABLE_CACHE, - PTE_READWRITE | PTE_ENABLE_CACHE, - PTE_WRITECOPY | PTE_ENABLE_CACHE, - PTE_EXECUTE_READWRITE | PTE_ENABLE_CACHE, - PTE_EXECUTE_WRITECOPY | PTE_ENABLE_CACHE, - // - // These OR in the MM_NOCACHE flag - // - 0, - PTE_READONLY | PTE_DISABLE_CACHE, - PTE_EXECUTE | PTE_DISABLE_CACHE, - PTE_EXECUTE_READ | PTE_DISABLE_CACHE, - PTE_READWRITE | PTE_DISABLE_CACHE, - PTE_WRITECOPY | PTE_DISABLE_CACHE, - PTE_EXECUTE_READWRITE | PTE_DISABLE_CACHE, - PTE_EXECUTE_WRITECOPY | PTE_DISABLE_CACHE, - // - // These OR in the MM_DECOMMIT flag, which doesn't seem supported on x86/64/ARM - // - 0, - PTE_READONLY | PTE_ENABLE_CACHE, - PTE_EXECUTE | PTE_ENABLE_CACHE, - PTE_EXECUTE_READ | PTE_ENABLE_CACHE, - PTE_READWRITE | PTE_ENABLE_CACHE, - PTE_WRITECOPY | PTE_ENABLE_CACHE, - PTE_EXECUTE_READWRITE | PTE_ENABLE_CACHE, - PTE_EXECUTE_WRITECOPY | PTE_ENABLE_CACHE, - // - // These OR in the MM_NOACCESS flag, which seems to enable WriteCombining? - // - 0, - PTE_READONLY | PTE_WRITECOMBINED_CACHE, - PTE_EXECUTE | PTE_WRITECOMBINED_CACHE, - PTE_EXECUTE_READ | PTE_WRITECOMBINED_CACHE, - PTE_READWRITE | PTE_WRITECOMBINED_CACHE, - PTE_WRITECOPY | PTE_WRITECOMBINED_CACHE, - PTE_EXECUTE_READWRITE | PTE_WRITECOMBINED_CACHE, - PTE_EXECUTE_WRITECOPY | PTE_WRITECOMBINED_CACHE, -}; - + +extern const ULONG MmProtectToPteMask[32]; + // // Assertions for session images, addresses, and PTEs // diff --git a/ntoskrnl/mm/ARM3/mmsup.c b/ntoskrnl/mm/ARM3/mmsup.c index b84c7a0492b..4410a390249 100644 --- a/ntoskrnl/mm/ARM3/mmsup.c +++ b/ntoskrnl/mm/ARM3/mmsup.c @@ -64,22 +64,26 @@ BOOLEAN NTAPI MmIsAddressValid(IN PVOID VirtualAddress) { - // - // Just check the Valid bit in the Address' PDE and PTE - // - if ((MiAddressToPde(VirtualAddress)->u.Hard.Valid == 0) || - (MiAddressToPte(VirtualAddress)->u.Hard.Valid == 0)) - { - // - // Attempting to access this page is guranteed to result in a page fault - // - return FALSE; - } +#if _MI_PAGING_LEVELS >= 4 + /* Check if the PXE is valid */ + if (MiAddressToPxe(VirtualAddress)->u.Hard.Valid == 0) return FALSE; +#endif - // - // This address is valid now, but it will only stay so if the caller holds - // the PFN lock - // +#if _MI_PAGING_LEVELS >= 3 + /* Check if the PPE is valid */ + if (MiAddressToPpe(VirtualAddress)->u.Hard.Valid == 0) return FALSE; +#endif + +#if _MI_PAGING_LEVELS >= 2 + /* Check if the PDE is valid */ + if (MiAddressToPde(VirtualAddress)->u.Hard.Valid == 0) return FALSE; +#endif + + /* Check if the PTE is valid */ + if (MiAddressToPte(VirtualAddress)->u.Hard.Valid == 0) return FALSE; + + /* This address is valid now, but it will only stay so if the caller holds + * the PFN lock */ return TRUE; } diff --git a/ntoskrnl/mm/ARM3/procsup.c b/ntoskrnl/mm/ARM3/procsup.c index 857a181fefd..816c7d191ea 100644 --- a/ntoskrnl/mm/ARM3/procsup.c +++ b/ntoskrnl/mm/ARM3/procsup.c @@ -1040,6 +1040,7 @@ MmInitializeHandBuiltProcess2(IN PEPROCESS Process) return STATUS_SUCCESS; } +#ifdef _M_IX86 /* FIXME: Evaluate ways to make this portable yet arch-specific */ BOOLEAN NTAPI @@ -1131,6 +1132,7 @@ MmCreateProcessAddressSpace(IN ULONG MinWs, MiReleaseSystemPtes(PointerPte, 1, SystemPteSpace); return TRUE; } +#endif VOID NTAPI diff --git a/ntoskrnl/mm/amd64/page.c b/ntoskrnl/mm/amd64/page.c index d9830b409e8..b91e5e6a223 100644 --- a/ntoskrnl/mm/amd64/page.c +++ b/ntoskrnl/mm/amd64/page.c @@ -5,6 +5,7 @@ * PURPOSE: Low level memory managment manipulation * * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) + * ReactOS Portable Systems Group */ /* INCLUDES ***************************************************************/ @@ -12,6 +13,7 @@ #include #define NDEBUG #include +#include "../ARM3/miarm.h" #undef InterlockedExchangePte #define InterlockedExchangePte(pte1, pte2) \ @@ -25,6 +27,55 @@ extern MMPTE HyperTemplatePte; /* GLOBALS *****************************************************************/ +const +ULONG +MmProtectToPteMask[32] = +{ + // + // These are the base MM_ protection flags + // + 0, + PTE_READONLY | PTE_ENABLE_CACHE, + PTE_EXECUTE | PTE_ENABLE_CACHE, + PTE_EXECUTE_READ | PTE_ENABLE_CACHE, + PTE_READWRITE | PTE_ENABLE_CACHE, + PTE_WRITECOPY | PTE_ENABLE_CACHE, + PTE_EXECUTE_READWRITE | PTE_ENABLE_CACHE, + PTE_EXECUTE_WRITECOPY | PTE_ENABLE_CACHE, + // + // These OR in the MM_NOCACHE flag + // + 0, + PTE_READONLY | PTE_DISABLE_CACHE, + PTE_EXECUTE | PTE_DISABLE_CACHE, + PTE_EXECUTE_READ | PTE_DISABLE_CACHE, + PTE_READWRITE | PTE_DISABLE_CACHE, + PTE_WRITECOPY | PTE_DISABLE_CACHE, + PTE_EXECUTE_READWRITE | PTE_DISABLE_CACHE, + PTE_EXECUTE_WRITECOPY | PTE_DISABLE_CACHE, + // + // These OR in the MM_DECOMMIT flag, which doesn't seem supported on x86/64/ARM + // + 0, + PTE_READONLY | PTE_ENABLE_CACHE, + PTE_EXECUTE | PTE_ENABLE_CACHE, + PTE_EXECUTE_READ | PTE_ENABLE_CACHE, + PTE_READWRITE | PTE_ENABLE_CACHE, + PTE_WRITECOPY | PTE_ENABLE_CACHE, + PTE_EXECUTE_READWRITE | PTE_ENABLE_CACHE, + PTE_EXECUTE_WRITECOPY | PTE_ENABLE_CACHE, + // + // These OR in the MM_NOACCESS flag, which seems to enable WriteCombining? + // + 0, + PTE_READONLY | PTE_WRITECOMBINED_CACHE, + PTE_EXECUTE | PTE_WRITECOMBINED_CACHE, + PTE_EXECUTE_READ | PTE_WRITECOMBINED_CACHE, + PTE_READWRITE | PTE_WRITECOMBINED_CACHE, + PTE_WRITECOPY | PTE_WRITECOMBINED_CACHE, + PTE_EXECUTE_READWRITE | PTE_WRITECOMBINED_CACHE, + PTE_EXECUTE_WRITECOPY | PTE_WRITECOMBINED_CACHE, +}; /* PRIVATE FUNCTIONS *******************************************************/ @@ -489,46 +540,95 @@ MmCreateVirtualMapping(PEPROCESS Process, return MmCreateVirtualMappingUnsafe(Process, Address, Protect, Pages, PageCount); } -NTSTATUS -NTAPI -MmInitializeHandBuiltProcess(IN PEPROCESS Process, - IN PULONG_PTR DirectoryTableBase) -{ - /* Share the directory base with the idle process */ - DirectoryTableBase[0] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[0]; - DirectoryTableBase[1] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[1]; - - /* Initialize the Addresss Space */ - KeInitializeGuardedMutex(&Process->AddressCreationLock); - Process->Vm.WorkingSetExpansionLinks.Flink = NULL; - ASSERT(Process->VadRoot.NumberGenericTableElements == 0); - Process->VadRoot.BalancedRoot.u1.Parent = &Process->VadRoot.BalancedRoot; - - /* The process now has an address space */ - Process->HasAddressSpace = TRUE; - return STATUS_SUCCESS; -} - BOOLEAN NTAPI MmCreateProcessAddressSpace(IN ULONG MinWs, IN PEPROCESS Process, - IN PULONG_PTR DirectoryTableBase) + OUT PULONG_PTR DirectoryTableBase) { - UNIMPLEMENTED; - return 0; -} + KIRQL OldIrql; + PFN_NUMBER TableBasePfn, HyperPfn; + PMMPTE PointerPte; + MMPTE TempPte, PdePte; + ULONG TableIndex; + PMMPTE SystemTable; -BOOLEAN -NTAPI -_MmIsAddressValid(IN PVOID VirtualAddress) -{ - /* Check all four page table levels */ - return (MiAddressToPxe(VirtualAddress)->u.Hard.Valid != 0 && - MiAddressToPpe(VirtualAddress)->u.Hard.Valid != 0 && - MiAddressToPde(VirtualAddress)->u.Hard.Valid != 0 && - MiAddressToPte(VirtualAddress)->u.Hard.Valid != 0); -} + /* No page colors yet */ + Process->NextPageColor = 0; + + /* Setup the hyperspace lock */ + KeInitializeSpinLock(&Process->HyperSpaceLock); + /* Lock PFN database */ + OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock); + + /* Get a page for the table base and for hyperspace */ + TableBasePfn = MiRemoveAnyPage(0); + HyperPfn = MiRemoveAnyPage(0); + + /* Release PFN lock */ + KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql); + + /* Zero both pages */ + MiZeroPhysicalPage(TableBasePfn); + MiZeroPhysicalPage(HyperPfn); + + /* Set the base directory pointers */ + DirectoryTableBase[0] = TableBasePfn << PAGE_SHIFT; + DirectoryTableBase[1] = HyperPfn << PAGE_SHIFT; + + /* Make sure we don't already have a page directory setup */ + ASSERT(Process->Pcb.DirectoryTableBase[0] == 0); + + /* Insert us into the Mm process list */ + InsertTailList(&MmProcessList, &Process->MmProcessLinks); + + /* Get a PTE to map the page directory */ + PointerPte = MiReserveSystemPtes(1, SystemPteSpace); + ASSERT(PointerPte != NULL); + + /* Build it */ + MI_MAKE_HARDWARE_PTE_KERNEL(&PdePte, + PointerPte, + MM_READWRITE, + TableBasePfn); + + /* Set it dirty and map it */ + PdePte.u.Hard.Dirty = TRUE; + MI_WRITE_VALID_PTE(PointerPte, PdePte); + + /* Now get the page directory (which we'll double map, so call it a page table */ + SystemTable = MiPteToAddress(PointerPte); + + /* Copy all the kernel mappings */ + TableIndex = MiAddressToPxi(MmSystemRangeStart); + + RtlCopyMemory(&SystemTable[TableIndex], + MiAddressToPxe(MmSystemRangeStart), + PAGE_SIZE - TableIndex * sizeof(MMPTE)); + + /* Now write the PTE/PDE entry for hyperspace itself */ + TempPte = ValidKernelPte; + TempPte.u.Hard.PageFrameNumber = HyperPfn; + TableIndex = MiAddressToPxi(HYPER_SPACE); + SystemTable[TableIndex] = TempPte; + + /* Sanity check */ + ASSERT(MiAddressToPxi(MmHyperSpaceEnd) > TableIndex); + + /* Now do the x86 trick of making the PDE a page table itself */ + TableIndex = MiAddressToPxi(PTE_BASE); + TempPte.u.Hard.PageFrameNumber = TableBasePfn; + SystemTable[TableIndex] = TempPte; + + /* Let go of the system PTE */ + MiReleaseSystemPtes(PointerPte, 1, SystemPteSpace); + + /* Switch to phase 1 initialization */ + ASSERT(Process->AddressSpaceInitialized == 0); + Process->AddressSpaceInitialized = 1; + + return TRUE; +} /* EOF */ diff --git a/ntoskrnl/mm/i386/page.c b/ntoskrnl/mm/i386/page.c index 8945ff24c43..800e9338310 100644 --- a/ntoskrnl/mm/i386/page.c +++ b/ntoskrnl/mm/i386/page.c @@ -12,6 +12,7 @@ #include #define NDEBUG #include +#include "../ARM3/miarm.h" #if defined (ALLOC_PRAGMA) #pragma alloc_text(INIT, MmInitGlobalKernelPageDirectory) @@ -58,6 +59,56 @@ __inline LARGE_INTEGER PTE_TO_PAGE(ULONG npage) } #endif +const +ULONG +MmProtectToPteMask[32] = +{ + // + // These are the base MM_ protection flags + // + 0, + PTE_READONLY | PTE_ENABLE_CACHE, + PTE_EXECUTE | PTE_ENABLE_CACHE, + PTE_EXECUTE_READ | PTE_ENABLE_CACHE, + PTE_READWRITE | PTE_ENABLE_CACHE, + PTE_WRITECOPY | PTE_ENABLE_CACHE, + PTE_EXECUTE_READWRITE | PTE_ENABLE_CACHE, + PTE_EXECUTE_WRITECOPY | PTE_ENABLE_CACHE, + // + // These OR in the MM_NOCACHE flag + // + 0, + PTE_READONLY | PTE_DISABLE_CACHE, + PTE_EXECUTE | PTE_DISABLE_CACHE, + PTE_EXECUTE_READ | PTE_DISABLE_CACHE, + PTE_READWRITE | PTE_DISABLE_CACHE, + PTE_WRITECOPY | PTE_DISABLE_CACHE, + PTE_EXECUTE_READWRITE | PTE_DISABLE_CACHE, + PTE_EXECUTE_WRITECOPY | PTE_DISABLE_CACHE, + // + // These OR in the MM_DECOMMIT flag, which doesn't seem supported on x86/64/ARM + // + 0, + PTE_READONLY | PTE_ENABLE_CACHE, + PTE_EXECUTE | PTE_ENABLE_CACHE, + PTE_EXECUTE_READ | PTE_ENABLE_CACHE, + PTE_READWRITE | PTE_ENABLE_CACHE, + PTE_WRITECOPY | PTE_ENABLE_CACHE, + PTE_EXECUTE_READWRITE | PTE_ENABLE_CACHE, + PTE_EXECUTE_WRITECOPY | PTE_ENABLE_CACHE, + // + // These OR in the MM_NOACCESS flag, which seems to enable WriteCombining? + // + 0, + PTE_READONLY | PTE_WRITECOMBINED_CACHE, + PTE_EXECUTE | PTE_WRITECOMBINED_CACHE, + PTE_EXECUTE_READ | PTE_WRITECOMBINED_CACHE, + PTE_READWRITE | PTE_WRITECOMBINED_CACHE, + PTE_WRITECOPY | PTE_WRITECOMBINED_CACHE, + PTE_EXECUTE_READWRITE | PTE_WRITECOMBINED_CACHE, + PTE_EXECUTE_WRITECOPY | PTE_WRITECOMBINED_CACHE, +}; + /* FUNCTIONS ***************************************************************/ BOOLEAN MmUnmapPageTable(PULONG Pt);