Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/kernelbase/kernelbase.spec | 1 + dlls/kernelbase/memory.c | 18 +++++++++++++++++ dlls/kernelbase/tests/process.c | 35 +++++++++++++++++++++++++++++++++ include/winbase.h | 1 + 4 files changed, 55 insertions(+)
diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index a651bc20909..9dd166c7b65 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -981,6 +981,7 @@ # @ stub MapPredefinedHandleInternal @ stdcall MapUserPhysicalPages(ptr long ptr) @ stdcall MapViewOfFile(long long long long long) +@ stdcall MapViewOfFile3(long long ptr int64 long long long ptr long) @ stdcall MapViewOfFileEx(long long long long long ptr) @ stdcall MapViewOfFileExNuma(long long long long long ptr long) # @ stub MapViewOfFileFromApp diff --git a/dlls/kernelbase/memory.c b/dlls/kernelbase/memory.c index ea223c3986a..49bf71e0aa2 100644 --- a/dlls/kernelbase/memory.c +++ b/dlls/kernelbase/memory.c @@ -234,6 +234,24 @@ LPVOID WINAPI DECLSPEC_HOTPATCH MapViewOfFileEx( HANDLE handle, DWORD access, DW return addr; }
+/*********************************************************************** + * MapViewOfFile3 (kernelbase.@) + */ +LPVOID WINAPI DECLSPEC_HOTPATCH MapViewOfFile3( HANDLE handle, HANDLE process, PVOID baseaddr, ULONG64 offset, + SIZE_T size, ULONG alloc_type, ULONG protection, MEM_EXTENDED_PARAMETER *params, ULONG params_count ) +{ + LARGE_INTEGER off; + void *addr; + + addr = baseaddr; + off.QuadPart = offset; + if (!set_ntstatus( NtMapViewOfSectionEx( handle, process, &addr, &off, &size, alloc_type, protection, + params, params_count ))) + { + return NULL; + } + return addr; +}
/*********************************************************************** * ReadProcessMemory (kernelbase.@) diff --git a/dlls/kernelbase/tests/process.c b/dlls/kernelbase/tests/process.c index d119dca650d..077ee1082dd 100644 --- a/dlls/kernelbase/tests/process.c +++ b/dlls/kernelbase/tests/process.c @@ -31,6 +31,8 @@ #include "wine/test.h"
static BOOL (WINAPI *pCompareObjectHandles)(HANDLE, HANDLE); +static LPVOID (WINAPI *pMapViewOfFile3)(HANDLE, HANDLE, PVOID, ULONG64 offset, SIZE_T size, + ULONG, ULONG, MEM_EXTENDED_PARAMETER *, ULONG);
static void test_CompareObjectHandles(void) { @@ -89,6 +91,37 @@ static void test_CompareObjectHandles(void) CloseHandle( h1 ); }
+static void test_MapViewOfFile3(void) +{ + static const char testfile[] = "testfile.xxx"; + HANDLE file, mapping; + void *ptr; + + if (!pMapViewOfFile3) + { + win_skip("MapViewOfFile3() is not supported.\n"); + return; + } + + SetLastError(0xdeadbeef); + file = CreateFileA( testfile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 ); + ok( file != INVALID_HANDLE_VALUE, "CreateFile error %lu\n", GetLastError() ); + SetFilePointer( file, 12288, NULL, FILE_BEGIN ); + SetEndOfFile( file ); + + SetLastError(0xdeadbeef); + mapping = CreateFileMappingA( file, NULL, PAGE_READWRITE, 0, 4096, NULL ); + ok( mapping != 0, "CreateFileMapping error %lu\n", GetLastError() ); + + SetLastError(0xdeadbeef); + ptr = pMapViewOfFile3( mapping, GetCurrentProcess(), NULL, 0, 4096, 0, PAGE_READONLY, NULL, 0); + ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %lu\n", GetLastError() ); + UnmapViewOfFile( ptr ); + + CloseHandle( file ); + DeleteFileA( testfile ); +} + START_TEST(process) { HMODULE hmod; @@ -99,6 +132,8 @@ START_TEST(process)
hmod = GetModuleHandleA("kernelbase.dll"); pCompareObjectHandles = (void *)GetProcAddress(hmod, "CompareObjectHandles"); + pMapViewOfFile3 = (void *)GetProcAddress(hmod, "MapViewOfFile3");
test_CompareObjectHandles(); + test_MapViewOfFile3(); } diff --git a/include/winbase.h b/include/winbase.h index a0c62d710b9..55be6dbf62b 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -2484,6 +2484,7 @@ WINADVAPI BOOL WINAPI MakeSelfRelativeSD(PSECURITY_DESCRIPTOR,PSECURITY_ WINADVAPI VOID WINAPI MapGenericMask(PDWORD,PGENERIC_MAPPING); WINBASEAPI BOOL WINAPI MapUserPhysicalPages(PVOID,ULONG_PTR,PULONG_PTR); WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE,DWORD,DWORD,DWORD,SIZE_T); +WINBASEAPI LPVOID WINAPI MapViewOfFile3(HANDLE,HANDLE,PVOID,ULONG64,SIZE_T,ULONG,ULONG,MEM_EXTENDED_PARAMETER*,ULONG); WINBASEAPI LPVOID WINAPI MapViewOfFileEx(HANDLE,DWORD,DWORD,DWORD,SIZE_T,LPVOID); WINBASEAPI BOOL WINAPI MoveFileA(LPCSTR,LPCSTR); WINBASEAPI BOOL WINAPI MoveFileW(LPCWSTR,LPCWSTR);