From 0617f84edac14cc7031547fb37e57869ded1cbe2 Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sun, 21 Jun 2015 19:15:01 +0000 Subject: [PATCH] [RTL][NDK][NTDLL_APITEST] - Properly implement/declare/test RtlCopyMappedMemory... it's not that hard CORE-9857 svn path=/trunk/; revision=68234 --- reactos/include/ndk/rtlfuncs.h | 8 +++++ reactos/lib/rtl/memstream.c | 21 ++++++++--- rostests/apitests/ntdll/CMakeLists.txt | 1 + rostests/apitests/ntdll/RtlCopyMappedMemory.c | 35 +++++++++++++++++++ rostests/apitests/ntdll/testlist.c | 2 ++ 5 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 rostests/apitests/ntdll/RtlCopyMappedMemory.c diff --git a/reactos/include/ndk/rtlfuncs.h b/reactos/include/ndk/rtlfuncs.h index d317f0623a3..c6ce74dccd4 100644 --- a/reactos/include/ndk/rtlfuncs.h +++ b/reactos/include/ndk/rtlfuncs.h @@ -2046,6 +2046,14 @@ RtlFillMemoryUlonglong( _In_ ULONGLONG Pattern ); +NTSYSAPI +NTSTATUS +NTAPI +RtlCopyMappedMemory( + _Out_writes_bytes_all_(Size) PVOID Destination, + _In_reads_bytes_(Size) const VOID *Source, + _In_ SIZE_T Size +); NTSYSAPI SIZE_T diff --git a/reactos/lib/rtl/memstream.c b/reactos/lib/rtl/memstream.c index 158640bea24..0549424ca45 100644 --- a/reactos/lib/rtl/memstream.c +++ b/reactos/lib/rtl/memstream.c @@ -469,13 +469,24 @@ RtlCloneMemoryStream( /* * @implemented */ -VOID +NTSTATUS NTAPI RtlCopyMappedMemory( - _Out_ PVOID Destination, - _In_ const VOID *Source, + _Out_writes_bytes_all_(Size) PVOID Destination, + _In_reads_bytes_(Size) const VOID *Source, _In_ SIZE_T Size) { - /* FIXME: This is supposed to handle STATUS_IN_PAGE_ERROR exceptions */ - RtlCopyMemory(Destination, Source, Size); + NTSTATUS Status = STATUS_SUCCESS; + _SEH2_TRY + { + RtlCopyMemory(Destination, Source, Size); + } + _SEH2_EXCEPT(_SEH2_GetExceptionCode() == STATUS_IN_PAGE_ERROR + ? EXCEPTION_EXECUTE_HANDLER + : EXCEPTION_CONTINUE_SEARCH) + { + Status = _SEH2_GetExceptionCode(); + } + _SEH2_END; + return Status; } diff --git a/rostests/apitests/ntdll/CMakeLists.txt b/rostests/apitests/ntdll/CMakeLists.txt index 3313f4bcd80..570faec9ddc 100644 --- a/rostests/apitests/ntdll/CMakeLists.txt +++ b/rostests/apitests/ntdll/CMakeLists.txt @@ -15,6 +15,7 @@ list(APPEND SOURCE NtQueryVolumeInformationFile.c NtSaveKey.c RtlBitmap.c + RtlCopyMappedMemory.c RtlDetermineDosPathNameType.c RtlDoesFileExists.c RtlDosPathNameToNtPathName_U.c diff --git a/rostests/apitests/ntdll/RtlCopyMappedMemory.c b/rostests/apitests/ntdll/RtlCopyMappedMemory.c new file mode 100644 index 00000000000..5a8f3be13e1 --- /dev/null +++ b/rostests/apitests/ntdll/RtlCopyMappedMemory.c @@ -0,0 +1,35 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory + * PURPOSE: Test for RtlCopyMappedMemory + * PROGRAMMERS: Thomas Faber + */ + +#include + +#define WIN32_NO_STATUS +#include + +START_TEST(RtlCopyMappedMemory) +{ + NTSTATUS Status; + UCHAR Buffer1[32]; + UCHAR Buffer2[32]; + + StartSeh() RtlCopyMappedMemory(NULL, NULL, 1); EndSeh(STATUS_ACCESS_VIOLATION); + StartSeh() RtlCopyMappedMemory(Buffer1, NULL, 1); EndSeh(STATUS_ACCESS_VIOLATION); + StartSeh() RtlCopyMappedMemory(NULL, Buffer1, 1); EndSeh(STATUS_ACCESS_VIOLATION); + + StartSeh() + Status = RtlCopyMappedMemory(NULL, NULL, 0); + EndSeh(STATUS_SUCCESS); + ok(Status == STATUS_SUCCESS, "RtlCopyMappedMemory returned %lx\n", Status); + + RtlFillMemory(Buffer1, sizeof(Buffer1), 0x11); + RtlFillMemory(Buffer2, sizeof(Buffer2), 0x22); + StartSeh() + Status = RtlCopyMappedMemory(Buffer1, Buffer2, sizeof(Buffer1)); + EndSeh(STATUS_SUCCESS); + ok(Status == STATUS_SUCCESS, "RtlCopyMappedMemory returned %lx\n", Status); + ok(RtlCompareMemory(Buffer1, Buffer2, sizeof(Buffer1)) == sizeof(Buffer1), "Data not copied\n"); +} diff --git a/rostests/apitests/ntdll/testlist.c b/rostests/apitests/ntdll/testlist.c index 8c2406981a5..daefbaa5e1d 100644 --- a/rostests/apitests/ntdll/testlist.c +++ b/rostests/apitests/ntdll/testlist.c @@ -19,6 +19,7 @@ extern void func_NtQueryVolumeInformationFile(void); extern void func_NtSaveKey(void); extern void func_NtSystemInformation(void); extern void func_RtlBitmap(void); +extern void func_RtlCopyMappedMemory(void); extern void func_RtlDetermineDosPathNameType(void); extern void func_RtlDoesFileExists(void); extern void func_RtlDosPathNameToNtPathName_U(void); @@ -53,6 +54,7 @@ const struct test winetest_testlist[] = { "NtSaveKey", func_NtSaveKey}, { "NtSystemInformation", func_NtSystemInformation }, { "RtlBitmapApi", func_RtlBitmap }, + { "RtlCopyMappedMemory", func_RtlCopyMappedMemory }, { "RtlDetermineDosPathNameType", func_RtlDetermineDosPathNameType }, { "RtlDoesFileExists", func_RtlDoesFileExists }, { "RtlDosPathNameToNtPathName_U", func_RtlDosPathNameToNtPathName_U },