sync with trunk (r48253)
authorJérôme Gardou <jerome.gardou@reactos.org>
Sun, 25 Jul 2010 16:44:57 +0000 (16:44 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Sun, 25 Jul 2010 16:44:57 +0000 (16:44 +0000)
svn path=/branches/reactos-yarotows/; revision=48255

29 files changed:
base/applications/network/ipconfig/ipconfig.c
base/setup/usetup/inffile.c
base/setup/usetup/inffile.h
base/setup/usetup/usetup.h
include/psdk/ntdef.h
include/psdk/winnt.h
include/psdk/wspiapi.h
lib/3rdparty/mingw/tlsmcrt.c
lib/drivers/oskittcp/include/freebsd/src/sys/sys/kernel.h
lib/inflib/infget.c
lib/inflib/infpriv.h
lib/inflib/infros.h
lib/inflib/infrosget.c
lib/newinflib/infget.c
lib/newinflib/infhost.h
lib/newinflib/infhostget.c
lib/newinflib/infpriv.h
lib/newinflib/infros.h
lib/newinflib/infrosget.c
lib/sdk/crt/time/asctime.c
ntoskrnl/include/internal/amd64/mm.h
ntoskrnl/include/internal/i386/mm.h
ntoskrnl/include/internal/lpc_x.h
ntoskrnl/mm/ARM3/largepag.c
ntoskrnl/mm/ARM3/miarm.h
ntoskrnl/mm/ARM3/mmsup.c
ntoskrnl/mm/ARM3/procsup.c
ntoskrnl/mm/amd64/page.c
ntoskrnl/mm/i386/page.c

index 5bb2d95..3d9de7d 100644 (file)
@@ -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;
index 0bbde01..7b0d2a9 100644 (file)
@@ -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,
index 864d201..4a5b8d9 100644 (file)
 
 #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,
index b95ad66..ff7cf87 100644 (file)
@@ -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"
index d25ff9f..aaf5182 100644 (file)
 #elif (_MSC_VER)
 #define FORCEINLINE __inline
 #else
-#define FORCEINLINE static __inline__ __attribute__((always_inline))
+#define FORCEINLINE extern __inline__ __attribute__((always_inline))
 #endif
 #endif
 
index 2df2d5f..47e0cb8 100644 (file)
@@ -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);
 }
index 4b4b5ce..ea41ec8 100644 (file)
@@ -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(
index 2450b8b..c5c01d9 100644 (file)
    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 <windows.h>
+#include <stdlib.h>
+
+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
+
index 2d42aee..18f031a 100644 (file)
@@ -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)
index 104cb3d..b21b2dd 100644 (file)
@@ -271,7 +271,7 @@ InfpGetBinaryField(PINFCONTEXT Context,
 INFSTATUS
 InfpGetIntField(PINFCONTEXT Context,
                 ULONG FieldIndex,
-                PLONG IntegerValue)
+                INT* IntegerValue)
 {
   PINFCACHELINE CacheLine;
   PINFCACHEFIELD CacheField;
index 0dd7d88..e4424cc 100644 (file)
@@ -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,
index 7de6967..80e8692 100644 (file)
@@ -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,
index 9f3e7b0..ee919cb 100644 (file)
@@ -84,7 +84,7 @@ InfGetBinaryField(PINFCONTEXT Context,
 BOOLEAN
 InfGetIntField(PINFCONTEXT Context,
                ULONG FieldIndex,
-               PLONG IntegerValue)
+               PINT IntegerValue)
 {
   return INF_SUCCESS(InfpGetIntField(Context, FieldIndex, IntegerValue));
 }
index e2b360a..666f712 100644 (file)
@@ -416,7 +416,7 @@ InfpGetBinaryField(PINFCONTEXT Context,
 INFSTATUS
 InfpGetIntField(PINFCONTEXT Context,
                 ULONG FieldIndex,
-                PLONG IntegerValue)
+                INT *IntegerValue)
 {
   PINFCACHELINE CacheLine;
   PINFCACHEFIELD CacheField;
index b1dfaaf..e1ee6d0 100644 (file)
@@ -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,
index bd49be1..e1714d6 100644 (file)
@@ -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;
index c7adede..f1b3341 100644 (file)
@@ -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,
index 92dbc51..3786814 100644 (file)
@@ -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,
index 9f3e7b0..9094d23 100644 (file)
@@ -84,7 +84,7 @@ InfGetBinaryField(PINFCONTEXT Context,
 BOOLEAN
 InfGetIntField(PINFCONTEXT Context,
                ULONG FieldIndex,
-               PLONG IntegerValue)
+               INT *IntegerValue)
 {
   return INF_SUCCESS(InfpGetIntField(Context, FieldIndex, IntegerValue));
 }
index 84e0591..377269d 100644 (file)
@@ -73,7 +73,7 @@ IntToChar2(int x)
     return u.char2;
 }
 
-FORCEINLINE
+static __inline
 void
 FillBuf(timebuf_t *buf, const struct tm *ptm)
 {
index 889c43e..a9d865b 100644 (file)
@@ -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
index edd86bb..1014884 100644 (file)
@@ -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))
 
index 80c66e4..3c688fb 100644 (file)
@@ -95,7 +95,7 @@
 //
 // Allocates a new message
 //
-FORCEINLINE
+static __inline
 PLPCP_MESSAGE
 LpcpAllocateFromPortZone(VOID)
 {
index 0cd1e50..01917b8 100644 (file)
@@ -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);
index c577633..59aac80 100644 (file)
 #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
 //
index b84c7a0..4410a39 100644 (file)
@@ -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;
 }
 
index 857a181..816c7d1 100644 (file)
@@ -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
index d9830b4..b91e5e6 100644 (file)
@@ -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 <ntoskrnl.h>
 #define NDEBUG
 #include <debug.h>
+#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;
+
+    /* 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;
 }
 
-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);
-}
-
-
 /* EOF */
index 8945ff2..800e933 100644 (file)
@@ -12,6 +12,7 @@
 #include <ntoskrnl.h>
 #define NDEBUG
 #include <debug.h>
+#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);