2004-10-28 Casper S. Hornstrup <chorns@users.sourceforge.net>
authorCasper Hornstrup <chorns@users.sourceforge.net>
Thu, 28 Oct 2004 19:01:59 +0000 (19:01 +0000)
committerCasper Hornstrup <chorns@users.sourceforge.net>
Thu, 28 Oct 2004 19:01:59 +0000 (19:01 +0000)
* drivers/net/tcpip/tests/setup.c: Include windows.h.
* lib/gdiplus/tests/setup.c: Ditto.
* lib/kernel32/tests/setup.c: Ditto.
* lib/ws2_32/tests/setup.c: Ditto.
* subsys/win32k/tests/setup.c: Ditto.
* ntoskrnl/tests/setup.c: Ditto.
* ntoskrnl/include/ntoskrnl.h: Include test.h.
* ntoskrnl/mm/virtual.c (NtLockVirtualMemoryInternal): New function.
(NtLockVirtualMemory): Use NtLockVirtualMemoryInternal.
* ntoskrnl/tests/Makefile (TARGET_CFLAGS): Add -I../include.
* ntoskrnl/tests/stubs.tst: Remove stubs for functions in libgcc.
* regtests/shared/regtests.h: Make independent of windows.h.
* tools/helper.mk (run): Link with libgcc.
* tools/regtests.c (EXESTUB): Include windows.h.
* ntoskrnl/include/internal/test.h: New file.
* ntoskrnl/tests/tests/VirtualMemory.c: Ditto.

svn path=/trunk/; revision=11466

16 files changed:
reactos/ChangeLog
reactos/drivers/net/tcpip/tests/setup.c
reactos/lib/gdiplus/tests/setup.c
reactos/lib/kernel32/tests/setup.c
reactos/lib/ws2_32/tests/setup.c
reactos/ntoskrnl/include/internal/test.h [new file with mode: 0644]
reactos/ntoskrnl/include/ntoskrnl.h
reactos/ntoskrnl/mm/virtual.c
reactos/ntoskrnl/tests/Makefile
reactos/ntoskrnl/tests/setup.c
reactos/ntoskrnl/tests/stubs.tst
reactos/ntoskrnl/tests/tests/VirtualMemory.c [new file with mode: 0644]
reactos/regtests/shared/regtests.h
reactos/subsys/win32k/tests/setup.c
reactos/tools/helper.mk
reactos/tools/regtests.c

index fa54f09..3a335ae 100644 (file)
@@ -1,3 +1,22 @@
+2004-10-28  Casper S. Hornstrup  <chorns@users.sourceforge.net>
+
+       * drivers/net/tcpip/tests/setup.c: Include windows.h.
+       * lib/gdiplus/tests/setup.c: Ditto.
+       * lib/kernel32/tests/setup.c: Ditto.
+       * lib/ws2_32/tests/setup.c: Ditto.
+       * subsys/win32k/tests/setup.c: Ditto.
+       * ntoskrnl/tests/setup.c: Ditto.
+       * ntoskrnl/include/ntoskrnl.h: Include test.h.
+       * ntoskrnl/mm/virtual.c (NtLockVirtualMemoryInternal): New function.
+       (NtLockVirtualMemory): Use NtLockVirtualMemoryInternal.
+       * ntoskrnl/tests/Makefile (TARGET_CFLAGS): Add -I../include.
+       * ntoskrnl/tests/stubs.tst: Remove stubs for functions in libgcc.
+       * regtests/shared/regtests.h: Make independent of windows.h.
+       * tools/helper.mk (run): Link with libgcc.
+       * tools/regtests.c (EXESTUB): Include windows.h.
+       * ntoskrnl/include/internal/test.h: New file.
+       * ntoskrnl/tests/tests/VirtualMemory.c: Ditto.
+
 2004-10-24  Casper S. Hornstrup  <chorns@users.sourceforge.net>
 
        * ntoskrnl/Makefile (TARGET_REGTESTS): Define to yes.
 2004-10-24  Casper S. Hornstrup  <chorns@users.sourceforge.net>
 
        * ntoskrnl/Makefile (TARGET_REGTESTS): Define to yes.
index 86ae3e6..507484d 100644 (file)
@@ -1,3 +1,4 @@
+#include <windows.h>
 #include "regtests.h"
 
 _SetupOnce()
 #include "regtests.h"
 
 _SetupOnce()
index b3793c3..a18de0e 100644 (file)
@@ -1,3 +1,4 @@
+#include <windows.h>
 #include "regtests.h"
 
 extern BOOL
 #include "regtests.h"
 
 extern BOOL
index 86ae3e6..507484d 100644 (file)
@@ -1,3 +1,4 @@
+#include <windows.h>
 #include "regtests.h"
 
 _SetupOnce()
 #include "regtests.h"
 
 _SetupOnce()
index b3793c3..a18de0e 100644 (file)
@@ -1,3 +1,4 @@
+#include <windows.h>
 #include "regtests.h"
 
 extern BOOL
 #include "regtests.h"
 
 extern BOOL
diff --git a/reactos/ntoskrnl/include/internal/test.h b/reactos/ntoskrnl/include/internal/test.h
new file mode 100644 (file)
index 0000000..e0f12a6
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef __NTOSKRNL_INCLUDE_INTERNAL_TEST_H
+#define __NTOSKRNL_INCLUDE_INTERNAL_TEST_H
+
+typedef VOID STDCALL
+PExFreePool(PVOID Block);
+
+typedef PMDL STDCALL
+PMmCreateMdl(PMDL Mdl,
+  PVOID Base,
+  ULONG Length);
+
+typedef VOID STDCALL
+PMmProbeAndLockPages(PMDL Mdl,
+  KPROCESSOR_MODE AccessMode,
+  LOCK_OPERATION Operation);
+
+typedef VOID FASTCALL
+PObDereferenceObject(PVOID Object);
+
+typedef NTSTATUS STDCALL
+PObReferenceObjectByHandle(HANDLE Handle,
+  ACCESS_MASK DesiredAccess,
+  POBJECT_TYPE ObjectType,
+  KPROCESSOR_MODE AccessMode,
+  PVOID* Object,
+  POBJECT_HANDLE_INFORMATION HandleInformation);
+
+
+NTSTATUS STDCALL
+NtLockVirtualMemoryInternal(HANDLE ProcessHandle,
+  PVOID BaseAddress,
+  ULONG NumberOfBytesToLock,
+  PULONG NumberOfBytesLocked,
+  PObReferenceObjectByHandle pObReferenceObjectByHandle,
+  PMmCreateMdl pMmCreateMdl,
+  PObDereferenceObject pObDereferenceObject,
+  PMmProbeAndLockPages pMmProbeAndLockPages,
+  PExFreePool pExFreePool);
+
+#endif /* __NTOSKRNL_INCLUDE_INTERNAL_TEST_H */
index bc86183..510af7c 100755 (executable)
@@ -54,6 +54,7 @@
 #include <internal/dbg.h>
 #include <internal/trap.h>
 #include <internal/safe.h>
 #include <internal/dbg.h>
 #include <internal/trap.h>
 #include <internal/safe.h>
+#include <internal/test.h>
 #include <ntdll/ldr.h>
 #include <napi/core.h>
 #include <napi/dbg.h>
 #include <ntdll/ldr.h>
 #include <napi/core.h>
 #include <napi/dbg.h>
index 8632876..12c017c 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: virtual.c,v 1.81 2004/10/22 20:38:23 ekohl Exp $
+/* $Id: virtual.c,v 1.82 2004/10/28 19:01:58 chorns Exp $
  *
  * PROJECT:     ReactOS kernel
  * FILE:        ntoskrnl/mm/virtual.c
  *
  * PROJECT:     ReactOS kernel
  * FILE:        ntoskrnl/mm/virtual.c
 
 /* INCLUDE *****************************************************************/
 
 
 /* INCLUDE *****************************************************************/
 
-#include <ddk/ntddk.h>
-#include <internal/mm.h>
-#include <internal/ob.h>
-#include <internal/io.h>
-#include <internal/ps.h>
-#include <internal/pool.h>
-#include <internal/safe.h>
+#include <ntoskrnl.h>
 
 #define NDEBUG
 #include <internal/debug.h>
 
 #define NDEBUG
 #include <internal/debug.h>
@@ -59,58 +53,75 @@ NtFlushVirtualMemory(IN HANDLE ProcessHandle,
    return(STATUS_NOT_IMPLEMENTED);
 }
 
    return(STATUS_NOT_IMPLEMENTED);
 }
 
-/* (tMk 2004.II.4)
- * FUNCTION: Locks range of process virtual memory.
- * Called from VirtualLock (lib\kernel32\mem\virtual.c)
- *
- * NOTE: This function will be correct if MmProbeAndLockPages() would be fully IMPLEMENTED.
- */
+
 NTSTATUS STDCALL
 NTSTATUS STDCALL
-NtLockVirtualMemory(HANDLE ProcessHandle,
-                    PVOID BaseAddress,
-                    ULONG NumberOfBytesToLock,
-                    PULONG NumberOfBytesLocked)   // ULONG LockOption?
+NtLockVirtualMemoryInternal(HANDLE ProcessHandle,
+  PVOID BaseAddress,
+  ULONG NumberOfBytesToLock,
+  PULONG NumberOfBytesLocked,
+  PObReferenceObjectByHandle pObReferenceObjectByHandle,
+  PMmCreateMdl pMmCreateMdl,
+  PObDereferenceObject pObDereferenceObject,
+  PMmProbeAndLockPages pMmProbeAndLockPages,
+  PExFreePool pExFreePool)
 {
 {
-   // AG [08-20-03] : I have *no* idea if this is correct, I just used the
-   // other functions as a template and made a few intelligent guesses...
-
-   NTSTATUS Status;
-   PMDL Mdl;
-   PEPROCESS Process;
+  PEPROCESS Process;
+  NTSTATUS Status;
+  PMDL Mdl;
+
+  Status = pObReferenceObjectByHandle(ProcessHandle,
+    PROCESS_VM_WRITE,
+    NULL,
+    UserMode,
+    (PVOID*)(&Process),
+    NULL);
+  if (!NT_SUCCESS(Status))
+    return(Status);
+
+  Mdl = pMmCreateMdl(NULL,
+    BaseAddress,
+    NumberOfBytesToLock);
+  if (Mdl == NULL)
+    {
+      pObDereferenceObject(Process);
+      return(STATUS_NO_MEMORY);
+    }
 
 
-   DPRINT("NtLockVirtualMemory(ProcessHandle %x, BaseAddress %x, "
-          "NumberOfBytesToLock %d), NumberOfBytesLocked %x\n",ProcessHandle,BaseAddress,
-          NumberOfBytesToLock, NumberOfBytesLocked);
+  pMmProbeAndLockPages(Mdl,
+    UserMode,
+    IoWriteAccess);
 
 
-   Status = ObReferenceObjectByHandle(ProcessHandle,
-                                      PROCESS_VM_WRITE,
-                                      NULL,
-                                      UserMode,
-                                      (PVOID*)(&Process),
-                                      NULL);
-   if (!NT_SUCCESS(Status))
-   {
-      return(Status);
-   }
+  pExFreePool(Mdl);
 
 
-   Mdl = MmCreateMdl(NULL,
-                     BaseAddress,
-                     NumberOfBytesToLock);
-   if(Mdl == NULL) 
-   {
-      ObDereferenceObject(Process);
-      return(STATUS_NO_MEMORY);
-   }
-   MmProbeAndLockPages(Mdl,
-                       UserMode,
-                       IoWriteAccess);
+  pObDereferenceObject(Process);
 
 
-   ExFreePool(Mdl);  // Are we supposed to do this here?
+  *NumberOfBytesLocked = NumberOfBytesToLock;
+  return(STATUS_SUCCESS);
+}
 
 
-   ObDereferenceObject(Process);
 
 
-   *NumberOfBytesLocked = NumberOfBytesToLock;
-   return(STATUS_SUCCESS);
+NTSTATUS STDCALL
+NtLockVirtualMemory(HANDLE ProcessHandle,
+  PVOID BaseAddress,
+  ULONG NumberOfBytesToLock,
+  PULONG NumberOfBytesLocked)
+{
+  DPRINT("NtLockVirtualMemory(ProcessHandle %x, BaseAddress %x, "
+    "NumberOfBytesToLock %d, NumberOfBytesLocked %x)\n",
+    ProcessHandle,
+    BaseAddress,
+    NumberOfBytesToLock,
+    NumberOfBytesLocked);
+
+  return NtLockVirtualMemoryInternal(ProcessHandle,
+    BaseAddress,
+    NumberOfBytesToLock,
+    NumberOfBytesLocked,
+    ObReferenceObjectByHandle,
+    MmCreateMdl,
+    ObfDereferenceObject,
+    MmProbeAndLockPages,
+    ExFreePool);
 }
 
 
 }
 
 
index 7ae8965..2b562d3 100644 (file)
@@ -6,7 +6,7 @@ TARGET_NAME = regtests
 
 TARGET_LIBPATH = .
 
 
 TARGET_LIBPATH = .
 
-TARGET_CFLAGS = -I$(REGTESTS_PATH_INC)
+TARGET_CFLAGS = -I../include -I$(REGTESTS_PATH_INC)
 
 TARGET_LIBS = \
   ../ntoskrnl.a \
 
 TARGET_LIBS = \
   ../ntoskrnl.a \
index 86ae3e6..507484d 100644 (file)
@@ -1,3 +1,4 @@
+#include <windows.h>
 #include "regtests.h"
 
 _SetupOnce()
 #include "regtests.h"
 
 _SetupOnce()
index 16177be..199d320 100644 (file)
@@ -1,7 +1,3 @@
-hal.dll  __divdi3
-hal.dll  __udivdi3
-hal.dll  __moddi3
-hal.dll  __umoddi3
 hal.dll  _init_end__
 hal.dll  _init_start__
 hal.dll  _text_end__
 hal.dll  _init_end__
 hal.dll  _init_start__
 hal.dll  _text_end__
diff --git a/reactos/ntoskrnl/tests/tests/VirtualMemory.c b/reactos/ntoskrnl/tests/tests/VirtualMemory.c
new file mode 100644 (file)
index 0000000..cdaebc0
--- /dev/null
@@ -0,0 +1,103 @@
+#include <ntoskrnl.h>
+#include "regtests.h"
+
+#define TestProcessHandle (HANDLE) 1
+#define TestProcessObject (PVOID) 0x2
+#define TestBaseAddress (PVOID) 0x1000
+#define TestNumberOfBytesToLock 0x2000
+#define TestMdl (PMDL) 0xD0000000
+
+static BOOLEAN MockExFreePoolCalled = FALSE;
+
+static VOID STDCALL
+MockExFreePool(PVOID Block)
+{
+  _AssertFalse(MockExFreePoolCalled);
+  _AssertEqualValue(TestMdl, Block);
+  MockExFreePoolCalled = TRUE;
+}
+
+static BOOLEAN MockMmCreateMdlCalled = FALSE;
+
+static PMDL STDCALL
+MockMmCreateMdl(PMDL Mdl,
+  PVOID Base,
+  ULONG Length)
+{
+  _AssertFalse(MockMmCreateMdlCalled);
+  _AssertEqualValue(TestBaseAddress, Base);
+  _AssertEqualValue(TestNumberOfBytesToLock, Length);
+  MockMmCreateMdlCalled = TRUE;
+  return TestMdl;
+}
+
+static BOOLEAN MockMmProbeAndLockPagesCalled = FALSE;
+
+static VOID STDCALL
+MockMmProbeAndLockPages(PMDL Mdl,
+  KPROCESSOR_MODE AccessMode,
+  LOCK_OPERATION Operation)
+{
+  _AssertFalse(MockMmProbeAndLockPagesCalled);
+  _AssertEqualValue(TestMdl, Mdl);
+  _AssertEqualValue(UserMode, AccessMode);
+  _AssertEqualValue(IoWriteAccess, Operation);
+  MockMmProbeAndLockPagesCalled = TRUE;
+}
+
+static BOOLEAN MockObDereferenceObjectCalled = FALSE;
+
+static VOID FASTCALL
+MockObDereferenceObject(PVOID Object)
+{
+  _AssertFalse(MockObDereferenceObjectCalled);
+  _AssertEqualValue(TestProcessObject, Object);
+  MockObDereferenceObjectCalled = TRUE;
+}
+
+static BOOLEAN MockObReferenceObjectByHandleCalled = FALSE;
+
+static NTSTATUS STDCALL
+MockObReferenceObjectByHandle(HANDLE Handle,
+  ACCESS_MASK DesiredAccess,
+  POBJECT_TYPE ObjectType,
+  KPROCESSOR_MODE AccessMode,
+  PVOID* Object,
+  POBJECT_HANDLE_INFORMATION HandleInformation)
+{
+  _AssertFalse(MockObReferenceObjectByHandleCalled);
+  _AssertEqualValue(TestProcessHandle, Handle);
+  _AssertEqualValue(PROCESS_VM_WRITE, DesiredAccess);
+  _AssertEqualValue(NULL, ObjectType);
+  _AssertEqualValue(UserMode, AccessMode);
+  _AssertNotEqualValue(NULL, Object);
+  _AssertEqualValue(NULL, HandleInformation);
+  *Object = TestProcessObject;
+  MockObReferenceObjectByHandleCalled = TRUE;
+  return STATUS_SUCCESS;
+}
+
+static void RunTest()
+{
+  ULONG NumberOfBytesLocked;
+  NTSTATUS status;
+
+  status = NtLockVirtualMemoryInternal(TestProcessHandle,
+    TestBaseAddress,
+    TestNumberOfBytesToLock,
+    &NumberOfBytesLocked,
+    MockObReferenceObjectByHandle,
+    MockMmCreateMdl,
+    MockObDereferenceObject,
+    MockMmProbeAndLockPages,
+    MockExFreePool);
+  _AssertEqualValue(STATUS_SUCCESS, status);
+  _AssertTrue(MockObReferenceObjectByHandleCalled);
+  _AssertTrue(MockMmCreateMdlCalled);
+  _AssertTrue(MockMmProbeAndLockPagesCalled);
+  _AssertTrue(MockExFreePoolCalled);
+  _AssertTrue(MockObDereferenceObjectCalled);
+  _AssertEqualValue(TestNumberOfBytesToLock, NumberOfBytesLocked);
+}
+
+_Dispatcher(VirtualmemoryTest, "Virtual memory")
index 8ef3276..8d56f87 100755 (executable)
@@ -8,7 +8,6 @@
  */
 #include <stdio.h>
 #include <string.h>
  */
 #include <stdio.h>
 #include <string.h>
-#include <windows.h>
 
 extern void SetupOnce();
 
 
 extern void SetupOnce();
 
@@ -105,7 +104,7 @@ AppendAssertion(char *message)
 
 #define _AssertNotEqualValue(_Expected, _Actual) \
 { \
 
 #define _AssertNotEqualValue(_Expected, _Actual) \
 { \
-  ULONG __Expected = (ULONG) (_Excepted); \
+  ULONG __Expected = (ULONG) (_Expected); \
   ULONG __Actual = (ULONG) (_Actual); \
   if ((__Expected) == (__Actual)) \
     { \
   ULONG __Actual = (ULONG) (_Actual); \
   if ((__Expected) == (__Actual)) \
     { \
@@ -161,14 +160,14 @@ typedef struct _API_DESCRIPTION
 extern API_DESCRIPTION ExternalDependencies[];
 extern ULONG MaxExternalDependency;
 
 extern API_DESCRIPTION ExternalDependencies[];
 extern ULONG MaxExternalDependency;
 
-HMODULE STDCALL
+HANDLE STDCALL
 _GetModuleHandleA(LPCSTR lpModuleName);
 
 _GetModuleHandleA(LPCSTR lpModuleName);
 
-FARPROC STDCALL
-_GetProcAddress(HMODULE hModule,
+PVOID STDCALL
+_GetProcAddress(HANDLE hModule,
   LPCSTR lpProcName);
 
   LPCSTR lpProcName);
 
-HINSTANCE STDCALL
+HANDLE STDCALL
 _LoadLibraryA(LPCSTR lpLibFileName);
 
 VOID STDCALL
 _LoadLibraryA(LPCSTR lpLibFileName);
 
 VOID STDCALL
@@ -190,7 +189,7 @@ FrameworkGetExportedFunctionNameInternal(PAPI_DESCRIPTION ApiDescription)
 static inline PVOID
 FrameworkGetFunction(PAPI_DESCRIPTION ApiDescription)
 {
 static inline PVOID
 FrameworkGetFunction(PAPI_DESCRIPTION ApiDescription)
 {
-  HMODULE hModule;
+  HANDLE hModule;
   PVOID function;
   PCHAR exportedFunctionName;
 
   PVOID function;
   PCHAR exportedFunctionName;
 
index 86ae3e6..507484d 100644 (file)
@@ -1,3 +1,4 @@
+#include <windows.h>
 #include "regtests.h"
 
 _SetupOnce()
 #include "regtests.h"
 
 _SetupOnce()
index dac1990..91edae4 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: helper.mk,v 1.92 2004/10/24 12:39:54 chorns Exp $
+# $Id: helper.mk,v 1.93 2004/10/28 19:01:59 chorns Exp $
 #
 # Helper makefile for ReactOS modules
 # Variables this makefile accepts:
 #
 # Helper makefile for ReactOS modules
 # Variables this makefile accepts:
@@ -1072,7 +1072,7 @@ endif
 ifeq ($(TARGET_TYPE),test)
 run: all
        @$(CC) -nostdlib -o _runtest.exe regtests.a $(TARGET_LIBS) _stubs.o \
 ifeq ($(TARGET_TYPE),test)
 run: all
        @$(CC) -nostdlib -o _runtest.exe regtests.a $(TARGET_LIBS) _stubs.o \
-       $(SDK_PATH_LIB)/rtshared.a $(SDK_PATH_LIB)/regtests.a _hooks.o -lmsvcrt -lntdll
+       $(SDK_PATH_LIB)/rtshared.a $(SDK_PATH_LIB)/regtests.a _hooks.o -lgcc -lmsvcrt -lntdll
        @$(CP) $(REGTESTS_PATH)/regtests/regtests.dll regtests.dll
        @_runtest.exe
        @$(RM) regtests.dll
        @$(CP) $(REGTESTS_PATH)/regtests/regtests.dll regtests.dll
        @_runtest.exe
        @$(RM) regtests.dll
index bb29ac7..3e2b4f5 100755 (executable)
@@ -431,6 +431,7 @@ write_file_if_changed(char *filename,
 static char EXESTUB[] =
   "/* This file is autogenerated. */\n"
   "\n"
 static char EXESTUB[] =
   "/* This file is autogenerated. */\n"
   "\n"
+  "#include <windows.h>\n"
   "#include \"regtests.h\"\n"
   "\n"
   "void\n"
   "#include \"regtests.h\"\n"
   "\n"
   "void\n"