ReactOS 0.4.16-dev-334-g4d9f67c
virtual.c File Reference
#include "precomp.h"
#include <wine/exception.h>
Include dependency graph for virtual.c:

Go to the source code of this file.

Macros

#define NUM_THREADS   4
 
#define MAPPING_SIZE   0x100000
 
#define ROUND_SIZE(addr, size)    (((SIZE_T)(size) + ((UINT_PTR)(addr) & page_mask) + page_mask) & ~page_mask)
 
#define ACCESS_READ   0x01
 
#define ACCESS_WRITE   0x02
 
#define ACCESS_EXECUTE   0x04
 
#define ACCESS_WRITECOPY   0x08
 

Functions

static LPVOID (WINAPI *pVirtualAllocEx)(HANDLE
 
static BOOL (WINAPI *pVirtualFreeEx)(HANDLE
 
static UINT (WINAPI *pGetWriteWatch)(DWORD
 
static NTSTATUS (WINAPI *pNtAreMappedFilesTheSame)(PVOID
 
static DWORD (WINAPI *pNtUnmapViewOfSection)(HANDLE
 
static void ULONG *static PVOID (WINAPI *pRtlAddVectoredExceptionHandler)(ULONG
 
static ULONG (WINAPI *pRtlRemoveVectoredExceptionHandler)(PVOID)
 
static PIMAGE_NT_HEADERS image_nt_header (HMODULE module)
 
static HANDLE create_target_process (const char *arg)
 
static void test_VirtualAllocEx (void)
 
static void test_VirtualAlloc (void)
 
static void test_MapViewOfFile (void)
 
static void test_NtMapViewOfSection (void)
 
static void test_NtAreMappedFilesTheSame (void)
 
static void test_CreateFileMapping (void)
 
static void test_IsBadReadPtr (void)
 
static void test_IsBadWritePtr (void)
 
static void test_IsBadCodePtr (void)
 
static void test_write_watch (void)
 
static void test_VirtualProtect (void)
 
static BOOL is_mem_writable (DWORD prot)
 
static void test_VirtualAlloc_protection (void)
 
static void test_CreateFileMapping_protection (void)
 
static DWORD page_prot_to_access (DWORD prot)
 
static BOOL is_compatible_protection (DWORD map_prot, DWORD view_prot, DWORD prot)
 
static DWORD map_prot_to_access (DWORD prot)
 
static BOOL is_compatible_access (DWORD map_prot, DWORD view_prot)
 
static voidmap_view_of_file (HANDLE handle, DWORD access)
 
static void test_mapping (void)
 
static void test_shared_memory (BOOL is_child)
 
static void test_shared_memory_ro (BOOL is_child, DWORD child_access)
 
static void test_NtQuerySection (void)
 
 START_TEST (virtual)
 

Variables

static HINSTANCE hkernel32
 
static HINSTANCE hntdll
 
static LPVOID
 
static SIZE_T
 
static DWORD
 
static PVOID
 
static ACCESS_MASK
 
static const OBJECT_ATTRIBUTES const LARGE_INTEGER ULONG
 
static const OBJECT_ATTRIBUTES const LARGE_INTEGER HANDLE
 
static SECTION_INFORMATION_CLASS
 
static void ULONG *static PVECTORED_EXCEPTION_HANDLER
 
static LPDWORD
 
static PBOOL
 
static UINT_PTR page_mask = 0xfff
 

Macro Definition Documentation

◆ ACCESS_EXECUTE

#define ACCESS_EXECUTE   0x04

Definition at line 3421 of file virtual.c.

◆ ACCESS_READ

#define ACCESS_READ   0x01

Definition at line 3419 of file virtual.c.

◆ ACCESS_WRITE

#define ACCESS_WRITE   0x02

Definition at line 3420 of file virtual.c.

◆ ACCESS_WRITECOPY

#define ACCESS_WRITECOPY   0x08

Definition at line 3422 of file virtual.c.

◆ MAPPING_SIZE

#define MAPPING_SIZE   0x100000

Definition at line 26 of file virtual.c.

◆ NUM_THREADS

#define NUM_THREADS   4

Definition at line 25 of file virtual.c.

◆ ROUND_SIZE

#define ROUND_SIZE (   addr,
  size 
)     (((SIZE_T)(size) + ((UINT_PTR)(addr) & page_mask) + page_mask) & ~page_mask)

Definition at line 50 of file virtual.c.

Function Documentation

◆ BOOL()

static BOOL ( WINAPI pVirtualFreeEx)
static

◆ create_target_process()

static HANDLE create_target_process ( const char arg)
static

Definition at line 66 of file virtual.c.

67{
68 char **argv;
69 char cmdline[MAX_PATH];
71 BOOL ret;
72 STARTUPINFOA si = { 0 };
73 si.cb = sizeof(si);
74
76 sprintf(cmdline, "%s %s %s", argv[0], argv[1], arg);
78 ok(ret, "error: %u\n", GetLastError());
79 ret = CloseHandle(pi.hThread);
80 ok(ret, "error %u\n", GetLastError());
81 return pi.hProcess;
82}
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4747
unsigned int BOOL
Definition: ntddk_ex.h:94
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static refpint_t pi[]
Definition: server.c:96
#define argv
Definition: mplay32.c:18
int winetest_get_mainargs(char ***pargv)
TCHAR * cmdline
Definition: stretchblt.cpp:32
DWORD cb
Definition: winbase.h:856
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by test_NtMapViewOfSection(), and test_VirtualAllocEx().

◆ DWORD()

static DWORD ( WINAPI pNtUnmapViewOfSection)
static

◆ image_nt_header()

static PIMAGE_NT_HEADERS image_nt_header ( HMODULE  module)
static

Definition at line 53 of file virtual.c.

54{
57
59 {
60 ret = (IMAGE_NT_HEADERS *)((char *)dos + dos->e_lfanew);
61 if (ret->Signature != IMAGE_NT_SIGNATURE) ret = NULL;
62 }
63 return ret;
64}
IMAGE_DOS_HEADER dos
Definition: module.c:49
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89

Referenced by test_NtQuerySection().

◆ is_compatible_access()

static BOOL is_compatible_access ( DWORD  map_prot,
DWORD  view_prot 
)
static

Definition at line 3487 of file virtual.c.

3488{
3489 DWORD access = map_prot_to_access(map_prot);
3490 if (!view_prot) view_prot = SECTION_MAP_READ;
3491 return (view_prot & access) == view_prot;
3492}
#define SECTION_MAP_READ
Definition: compat.h:139
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
static DWORD map_prot_to_access(DWORD prot)
Definition: virtual.c:3469

Referenced by test_mapping().

◆ is_compatible_protection()

static BOOL is_compatible_protection ( DWORD  map_prot,
DWORD  view_prot,
DWORD  prot 
)
static

Definition at line 3452 of file virtual.c.

3453{
3454 DWORD map_access, view_access, prot_access;
3455
3456 map_access = page_prot_to_access(map_prot);
3457 view_access = page_prot_to_access(view_prot);
3458 prot_access = page_prot_to_access(prot);
3459
3460 if (view_access == prot_access) return TRUE;
3461 if (!view_access) return FALSE;
3462
3463 if ((view_access & prot_access) != prot_access) return FALSE;
3464 if ((map_access & prot_access) == prot_access) return TRUE;
3465
3466 return FALSE;
3467}
#define TRUE
Definition: types.h:120
static DWORD page_prot_to_access(DWORD prot)
Definition: virtual.c:3424

Referenced by test_mapping().

◆ is_mem_writable()

static BOOL is_mem_writable ( DWORD  prot)
static

Definition at line 3059 of file virtual.c.

3060{
3061 switch (prot & 0xff)
3062 {
3063 case PAGE_READWRITE:
3064 case PAGE_WRITECOPY:
3067 return TRUE;
3068
3069 default:
3070 return FALSE;
3071 }
3072}
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308

Referenced by test_CreateFileMapping_protection(), and test_VirtualAlloc_protection().

◆ LPVOID()

static LPVOID ( WINAPI pVirtualAllocEx)
static

◆ map_prot_to_access()

static DWORD map_prot_to_access ( DWORD  prot)
static

Definition at line 3469 of file virtual.c.

3470{
3471 switch (prot)
3472 {
3473 case PAGE_READWRITE:
3476 case PAGE_READONLY:
3477 case PAGE_WRITECOPY:
3478 case PAGE_EXECUTE:
3479 case PAGE_EXECUTE_READ:
3482 default:
3483 return 0;
3484 }
3485}
#define PAGE_READONLY
Definition: compat.h:138
#define SECTION_MAP_EXECUTE
Definition: nt_native.h:1290
#define SECTION_MAP_WRITE
Definition: nt_native.h:1288
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define SECTION_QUERY
Definition: nt_native.h:1287
#define PAGE_EXECUTE
Definition: nt_native.h:1306
#define SECTION_MAP_EXECUTE_EXPLICIT
Definition: mmtypes.h:51

Referenced by is_compatible_access().

◆ map_view_of_file()

static void * map_view_of_file ( HANDLE  handle,
DWORD  access 
)
static

Definition at line 3494 of file virtual.c.

3495{
3498 SIZE_T count;
3499 ULONG protect;
3500 BOOL exec;
3501 void *addr;
3502
3503 if (!pNtMapViewOfSection) return NULL;
3504
3505 count = 0;
3506 offset.u.LowPart = 0;
3507 offset.u.HighPart = 0;
3508
3509 exec = access & FILE_MAP_EXECUTE;
3510 access &= ~FILE_MAP_EXECUTE;
3511
3512 if (access == FILE_MAP_COPY)
3513 {
3514 if (exec)
3515 protect = PAGE_EXECUTE_WRITECOPY;
3516 else
3517 protect = PAGE_WRITECOPY;
3518 }
3519 else if (access & FILE_MAP_WRITE)
3520 {
3521 if (exec)
3522 protect = PAGE_EXECUTE_READWRITE;
3523 else
3524 protect = PAGE_READWRITE;
3525 }
3526 else if (access & FILE_MAP_READ)
3527 {
3528 if (exec)
3529 protect = PAGE_EXECUTE_READ;
3530 else
3531 protect = PAGE_READONLY;
3532 }
3533 else protect = PAGE_NOACCESS;
3534
3535 addr = NULL;
3536 status = pNtMapViewOfSection(handle, GetCurrentProcess(), &addr, 0, 0, &offset,
3537 &count, 1 /* ViewShare */, 0, protect);
3538 if (status)
3539 {
3540 /* for simplicity */
3542 addr = NULL;
3543 }
3544 return addr;
3545}
LONG NTSTATUS
Definition: precomp.h:26
#define SetLastError(x)
Definition: compat.h:752
#define GetCurrentProcess()
Definition: compat.h:759
#define FILE_MAP_READ
Definition: compat.h:776
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum const GLvoid * addr
Definition: glext.h:9621
GLintptr offset
Definition: glext.h:5920
#define PAGE_NOACCESS
Definition: nt_native.h:1302
Definition: ps.c:97
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
#define FILE_MAP_WRITE
Definition: winbase.h:155
#define FILE_MAP_COPY
Definition: winbase.h:154
#define FILE_MAP_EXECUTE
Definition: winbase.h:158

Referenced by test_mapping().

◆ NTSTATUS()

static NTSTATUS ( WINAPI pNtAreMappedFilesTheSame)
static

◆ page_prot_to_access()

static DWORD page_prot_to_access ( DWORD  prot)
static

Definition at line 3424 of file virtual.c.

3425{
3426 switch (prot)
3427 {
3428 case PAGE_READWRITE:
3429 return ACCESS_READ | ACCESS_WRITE;
3430
3431 case PAGE_EXECUTE:
3432 case PAGE_EXECUTE_READ:
3433 return ACCESS_READ | ACCESS_EXECUTE;
3434
3437
3440
3441 case PAGE_READONLY:
3442 return ACCESS_READ;
3443
3444 case PAGE_WRITECOPY:
3445 return ACCESS_READ;
3446
3447 default:
3448 return 0;
3449 }
3450}
#define ACCESS_WRITECOPY
Definition: virtual.c:3422
#define ACCESS_WRITE
Definition: virtual.c:3420
#define ACCESS_READ
Definition: virtual.c:3419
#define ACCESS_EXECUTE
Definition: virtual.c:3421

Referenced by is_compatible_protection().

◆ PVOID()

static void ULONG *static PVOID ( WINAPI pRtlAddVectoredExceptionHandler)
static

◆ START_TEST()

START_TEST ( virtual  )

Definition at line 4107 of file virtual.c.

4108{
4109 int argc;
4110 char **argv;
4112
4113#if defined(__REACTOS__) && defined(_M_AMD64)
4115 {
4116 skip("ROSTESTS-369: Skipping kernel32_winetest:virtual because it crashes on Windows Server 2003 x64-Testbot. Set winetest_interactive to run it anyway.\n");
4117 return;
4118 }
4119#endif
4120
4121 if (argc >= 3)
4122 {
4123 if (!strcmp(argv[2], "sleep"))
4124 {
4125 Sleep(5000); /* spawned process runs for at most 5 seconds */
4126 return;
4127 }
4128 if (!strcmp(argv[2], "sharedmem"))
4129 {
4131 return;
4132 }
4133 if (!strcmp(argv[2], "sharedmemro"))
4134 {
4136 return;
4137 }
4138 while (1)
4139 {
4140 void *mem;
4141 BOOL ret;
4144 ok(mem != NULL, "VirtualAlloc failed %u\n", GetLastError());
4145 if (mem == NULL) break;
4147 ok(ret, "VirtualFree failed %u\n", GetLastError());
4148 if (!ret) break;
4149 }
4150 return;
4151 }
4152
4153 hkernel32 = GetModuleHandleA("kernel32.dll");
4154 hntdll = GetModuleHandleA("ntdll.dll");
4155
4156 pVirtualAllocEx = (void *) GetProcAddress(hkernel32, "VirtualAllocEx");
4157 pVirtualFreeEx = (void *) GetProcAddress(hkernel32, "VirtualFreeEx");
4158 pGetWriteWatch = (void *) GetProcAddress(hkernel32, "GetWriteWatch");
4159 pResetWriteWatch = (void *) GetProcAddress(hkernel32, "ResetWriteWatch");
4160 pGetProcessDEPPolicy = (void *)GetProcAddress( hkernel32, "GetProcessDEPPolicy" );
4161 pIsWow64Process = (void *)GetProcAddress( hkernel32, "IsWow64Process" );
4162 pNtAreMappedFilesTheSame = (void *)GetProcAddress( hntdll, "NtAreMappedFilesTheSame" );
4163 pNtCreateSection = (void *)GetProcAddress( hntdll, "NtCreateSection" );
4164 pNtMapViewOfSection = (void *)GetProcAddress( hntdll, "NtMapViewOfSection" );
4165 pNtUnmapViewOfSection = (void *)GetProcAddress( hntdll, "NtUnmapViewOfSection" );
4166 pNtQuerySection = (void *)GetProcAddress( hntdll, "NtQuerySection" );
4167 pRtlAddVectoredExceptionHandler = (void *)GetProcAddress( hntdll, "RtlAddVectoredExceptionHandler" );
4168 pRtlRemoveVectoredExceptionHandler = (void *)GetProcAddress( hntdll, "RtlRemoveVectoredExceptionHandler" );
4169 pNtProtectVirtualMemory = (void *)GetProcAddress( hntdll, "NtProtectVirtualMemory" );
4170 pNtAllocateVirtualMemory = (void *)GetProcAddress( hntdll, "NtAllocateVirtualMemory" );
4171 pNtFreeVirtualMemory = (void *)GetProcAddress( hntdll, "NtFreeVirtualMemory" );
4172
4177 test_mapping();
4192#if defined(__i386__) || defined(__x86_64__)
4193 test_stack_commit();
4194#endif
4195#ifdef __i386__
4196 test_guard_page();
4197 /* The following tests should be executed as a last step, and in exactly this
4198 * order, since ATL thunk emulation cannot be enabled anymore on Windows. */
4199 test_atl_thunk_emulation( MEM_EXECUTE_OPTION_ENABLE );
4200 test_atl_thunk_emulation( MEM_EXECUTE_OPTION_DISABLE );
4202#endif
4203}
static int argc
Definition: ServiceArgs.c:12
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define skip(...)
Definition: atltest.h:64
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
static void test_shared_memory(BOOL is_child)
Definition: virtual.c:3793
static void test_shared_memory_ro(BOOL is_child, DWORD child_access)
Definition: virtual.c:3835
static void test_CreateFileMapping(void)
Definition: virtual.c:1452
static void test_NtQuerySection(void)
Definition: virtual.c:3880
static HINSTANCE hkernel32
Definition: virtual.c:28
static void test_IsBadCodePtr(void)
Definition: virtual.c:1541
static void test_write_watch(void)
Definition: virtual.c:1557
static void test_CreateFileMapping_protection(void)
Definition: virtual.c:3167
static void test_mapping(void)
Definition: virtual.c:3547
static void test_NtMapViewOfSection(void)
Definition: virtual.c:1103
static void test_NtAreMappedFilesTheSame(void)
Definition: virtual.c:1312
static void test_VirtualAlloc(void)
Definition: virtual.c:234
static void test_VirtualAlloc_protection(void)
Definition: virtual.c:3074
static void test_MapViewOfFile(void)
Definition: virtual.c:430
static HINSTANCE hntdll
Definition: virtual.c:28
static void test_IsBadReadPtr(void)
Definition: virtual.c:1491
static void test_VirtualAllocEx(void)
Definition: virtual.c:84
static void test_VirtualProtect(void)
Definition: virtual.c:2878
static void test_IsBadWritePtr(void)
Definition: virtual.c:1516
#define MEM_EXECUTE_OPTION_DISABLE
Definition: mmtypes.h:73
#define MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION
Definition: mmtypes.h:75
#define MEM_EXECUTE_OPTION_ENABLE
Definition: mmtypes.h:74
#define MEM_RESERVE
Definition: nt_native.h:1314
#define MEM_RELEASE
Definition: nt_native.h:1316
#define MEM_COMMIT
Definition: nt_native.h:1313
int winetest_interactive
Definition: mem.c:349
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:65
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:119

◆ test_CreateFileMapping()

static void test_CreateFileMapping ( void  )
static

Definition at line 1452 of file virtual.c.

1453{
1454 HANDLE handle, handle2;
1455
1456 /* test case sensitivity */
1457
1458 SetLastError(0xdeadbeef);
1460 "Wine Test Mapping");
1461 ok( handle != NULL, "CreateFileMapping failed with error %u\n", GetLastError());
1462 ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
1463
1464 SetLastError(0xdeadbeef);
1466 "Wine Test Mapping");
1467 ok( handle2 != NULL, "CreateFileMapping failed with error %d\n", GetLastError());
1468 ok( GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
1469 CloseHandle( handle2 );
1470
1471 SetLastError(0xdeadbeef);
1473 "WINE TEST MAPPING");
1474 ok( handle2 != NULL, "CreateFileMapping failed with error %d\n", GetLastError());
1475 ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
1476 CloseHandle( handle2 );
1477
1478 SetLastError(0xdeadbeef);
1479 handle2 = OpenFileMappingA( FILE_MAP_ALL_ACCESS, FALSE, "Wine Test Mapping");
1480 ok( handle2 != NULL, "OpenFileMapping failed with error %d\n", GetLastError());
1481 CloseHandle( handle2 );
1482
1483 SetLastError(0xdeadbeef);
1484 handle2 = OpenFileMappingA( FILE_MAP_ALL_ACCESS, FALSE, "WINE TEST MAPPING");
1485 ok( !handle2, "OpenFileMapping succeeded\n");
1486 ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
1487
1489}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
HANDLE NTAPI CreateFileMappingA(IN HANDLE hFile, IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes, IN DWORD flProtect, IN DWORD dwMaximumSizeHigh, IN DWORD dwMaximumSizeLow, IN LPCSTR lpName)
Definition: filemap.c:23
HANDLE NTAPI OpenFileMappingA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: filemap.c:284
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define SEC_COMMIT
Definition: mmtypes.h:100
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:157

Referenced by START_TEST().

◆ test_CreateFileMapping_protection()

static void test_CreateFileMapping_protection ( void  )
static

Definition at line 3167 of file virtual.c.

3168{
3169 static const struct test_data
3170 {
3171 DWORD prot;
3172 BOOL success;
3173 DWORD prot_after_write;
3174 } td[] =
3175 {
3176 { 0, FALSE, 0 }, /* 0x00 */
3177 { PAGE_NOACCESS, FALSE, PAGE_NOACCESS }, /* 0x01 */
3178 { PAGE_READONLY, TRUE, PAGE_READONLY }, /* 0x02 */
3180 { PAGE_READWRITE, TRUE, PAGE_READWRITE }, /* 0x04 */
3184 { PAGE_WRITECOPY, TRUE, PAGE_READWRITE }, /* 0x08 */
3192
3193 { PAGE_EXECUTE, FALSE, PAGE_EXECUTE }, /* 0x10 */
3194 { PAGE_EXECUTE_READ, TRUE, PAGE_EXECUTE_READ }, /* 0x20 */
3208 };
3209 char *base, *ptr;
3210 DWORD ret, i, alloc_prot, prot, old_prot;
3212 SYSTEM_INFO si;
3213 char temp_path[MAX_PATH];
3214 char file_name[MAX_PATH];
3215 HANDLE hfile, hmap;
3216 BOOL page_exec_supported = TRUE;
3217
3218 GetSystemInfo(&si);
3219 trace("system page size %#x\n", si.dwPageSize);
3220
3223
3224 SetLastError(0xdeadbeef);
3226 ok(hfile != INVALID_HANDLE_VALUE, "CreateFile(%s) error %d\n", file_name, GetLastError());
3228 SetEndOfFile(hfile);
3229
3230 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3231 {
3232 SetLastError(0xdeadbeef);
3233 hmap = CreateFileMappingW(hfile, NULL, td[i].prot | SEC_COMMIT, 0, si.dwPageSize, NULL);
3234
3235 if (td[i].success)
3236 {
3237 if (!hmap)
3238 {
3239 trace("%d: CreateFileMapping(%04x) failed: %d\n", i, td[i].prot, GetLastError());
3240 /* NT4 and win2k don't support EXEC on file mappings */
3241 if (td[i].prot == PAGE_EXECUTE_READ || td[i].prot == PAGE_EXECUTE_READWRITE)
3242 {
3243 page_exec_supported = FALSE;
3244 ok(broken(!hmap), "%d: CreateFileMapping doesn't support PAGE_EXECUTE\n", i);
3245 continue;
3246 }
3247 /* Vista+ supports PAGE_EXECUTE_WRITECOPY, earlier versions don't */
3248 if (td[i].prot == PAGE_EXECUTE_WRITECOPY)
3249 {
3250 page_exec_supported = FALSE;
3251 ok(broken(!hmap), "%d: CreateFileMapping doesn't support PAGE_EXECUTE_WRITECOPY\n", i);
3252 continue;
3253 }
3254 }
3255 ok(hmap != 0, "%d: CreateFileMapping(%04x) error %d\n", i, td[i].prot, GetLastError());
3256
3257 base = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0);
3258 ok(base != NULL, "%d: MapViewOfFile failed %d\n", i, GetLastError());
3259
3260 SetLastError(0xdeadbeef);
3261 ret = VirtualQuery(base, &info, sizeof(info));
3262 ok(ret, "VirtualQuery failed %d\n", GetLastError());
3263 ok(info.BaseAddress == base, "%d: got %p != expected %p\n", i, info.BaseAddress, base);
3264 ok(info.RegionSize == si.dwPageSize, "%d: got %#lx != expected %#x\n", i, info.RegionSize, si.dwPageSize);
3265 ok(info.Protect == PAGE_READONLY, "%d: got %#x != expected PAGE_READONLY\n", i, info.Protect);
3266 ok(info.AllocationBase == base, "%d: %p != %p\n", i, info.AllocationBase, base);
3267 ok(info.AllocationProtect == PAGE_READONLY, "%d: %#x != PAGE_READONLY\n", i, info.AllocationProtect);
3268 ok(info.State == MEM_COMMIT, "%d: %#x != MEM_COMMIT\n", i, info.State);
3269 ok(info.Type == MEM_MAPPED, "%d: %#x != MEM_MAPPED\n", i, info.Type);
3270
3271 if (is_mem_writable(info.Protect))
3272 {
3273 base[0] = 0xfe;
3274
3275 SetLastError(0xdeadbeef);
3276 ret = VirtualQuery(base, &info, sizeof(info));
3277 ok(ret, "VirtualQuery failed %d\n", GetLastError());
3278 ok(info.Protect == td[i].prot, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].prot);
3279 }
3280
3281 SetLastError(0xdeadbeef);
3282 ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, td[i].prot);
3283 ok(!ptr, "%d: VirtualAlloc(%02x) should fail\n", i, td[i].prot);
3284 /* FIXME: remove once Wine is fixed */
3285 todo_wine_if (td[i].prot == PAGE_WRITECOPY || td[i].prot == PAGE_EXECUTE_WRITECOPY)
3286 ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
3287
3288 SetLastError(0xdeadbeef);
3289 ret = VirtualProtect(base, si.dwPageSize, td[i].prot, &old_prot);
3290 if (td[i].prot == PAGE_READONLY || td[i].prot == PAGE_WRITECOPY)
3291 ok(ret, "%d: VirtualProtect(%02x) error %d\n", i, td[i].prot, GetLastError());
3292 else
3293 {
3294 ok(!ret, "%d: VirtualProtect(%02x) should fail\n", i, td[i].prot);
3295 ok(GetLastError() == ERROR_INVALID_PARAMETER, "%d: expected ERROR_INVALID_PARAMETER, got %d\n", i, GetLastError());
3296 }
3297
3299 CloseHandle(hmap);
3300 }
3301 else
3302 {
3303 ok(!hmap, "%d: CreateFileMapping should fail\n", i);
3304 ok(GetLastError() == ERROR_INVALID_PARAMETER, "%d: expected ERROR_INVALID_PARAMETER, got %d\n", i, GetLastError());
3305 }
3306 }
3307
3308 if (page_exec_supported) alloc_prot = PAGE_EXECUTE_READWRITE;
3309 else alloc_prot = PAGE_READWRITE;
3310 SetLastError(0xdeadbeef);
3311 hmap = CreateFileMappingW(hfile, NULL, alloc_prot, 0, si.dwPageSize, NULL);
3312 ok(hmap != 0, "%d: CreateFileMapping error %d\n", i, GetLastError());
3313
3314 SetLastError(0xdeadbeef);
3315 base = MapViewOfFile(hmap, FILE_MAP_READ | FILE_MAP_WRITE | (page_exec_supported ? FILE_MAP_EXECUTE : 0), 0, 0, 0);
3316 ok(base != NULL, "MapViewOfFile failed %d\n", GetLastError());
3317
3318 old_prot = 0xdeadbeef;
3319 SetLastError(0xdeadbeef);
3320 ret = VirtualProtect(base, si.dwPageSize, PAGE_NOACCESS, &old_prot);
3321 ok(ret, "VirtualProtect error %d\n", GetLastError());
3322 ok(old_prot == alloc_prot, "got %#x != expected %#x\n", old_prot, alloc_prot);
3323
3324 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3325 {
3326 SetLastError(0xdeadbeef);
3327 ret = VirtualQuery(base, &info, sizeof(info));
3328 ok(ret, "VirtualQuery failed %d\n", GetLastError());
3329 ok(info.BaseAddress == base, "%d: got %p != expected %p\n", i, info.BaseAddress, base);
3330 ok(info.RegionSize == si.dwPageSize, "%d: got %#lx != expected %#x\n", i, info.RegionSize, si.dwPageSize);
3331 ok(info.Protect == PAGE_NOACCESS, "%d: got %#x != expected PAGE_NOACCESS\n", i, info.Protect);
3332 ok(info.AllocationBase == base, "%d: %p != %p\n", i, info.AllocationBase, base);
3333 ok(info.AllocationProtect == alloc_prot, "%d: %#x != %#x\n", i, info.AllocationProtect, alloc_prot);
3334 ok(info.State == MEM_COMMIT, "%d: %#x != MEM_COMMIT\n", i, info.State);
3335 ok(info.Type == MEM_MAPPED, "%d: %#x != MEM_MAPPED\n", i, info.Type);
3336
3337 old_prot = 0xdeadbeef;
3338 SetLastError(0xdeadbeef);
3339 ret = VirtualProtect(base, si.dwPageSize, td[i].prot, &old_prot);
3340 if (td[i].success || td[i].prot == PAGE_NOACCESS || td[i].prot == PAGE_EXECUTE)
3341 {
3342 if (!ret)
3343 {
3344 /* win2k and XP don't support EXEC on file mappings */
3345 if (td[i].prot == PAGE_EXECUTE)
3346 {
3347 ok(broken(!ret), "%d: VirtualProtect doesn't support PAGE_EXECUTE\n", i);
3348 continue;
3349 }
3350 /* NT4 and win2k don't support EXEC on file mappings */
3351 if (td[i].prot == PAGE_EXECUTE_READ || td[i].prot == PAGE_EXECUTE_READWRITE)
3352 {
3353 ok(broken(!ret), "%d: VirtualProtect doesn't support PAGE_EXECUTE\n", i);
3354 continue;
3355 }
3356 /* Vista+ supports PAGE_EXECUTE_WRITECOPY, earlier versions don't */
3357 if (td[i].prot == PAGE_EXECUTE_WRITECOPY)
3358 {
3359 ok(broken(!ret), "%d: VirtualProtect doesn't support PAGE_EXECUTE_WRITECOPY\n", i);
3360 continue;
3361 }
3362 }
3363
3364 ok(ret, "%d: VirtualProtect error %d\n", i, GetLastError());
3365 ok(old_prot == PAGE_NOACCESS, "%d: got %#x != expected PAGE_NOACCESS\n", i, old_prot);
3366
3367 prot = td[i].prot;
3368 /* looks strange but Windows doesn't do this for PAGE_WRITECOPY */
3370
3371 SetLastError(0xdeadbeef);
3372 ret = VirtualQuery(base, &info, sizeof(info));
3373 ok(ret, "VirtualQuery failed %d\n", GetLastError());
3374 ok(info.BaseAddress == base, "%d: got %p != expected %p\n", i, info.BaseAddress, base);
3375 ok(info.RegionSize == si.dwPageSize, "%d: got %#lx != expected %#x\n", i, info.RegionSize, si.dwPageSize);
3376 /* FIXME: remove the condition below once Wine is fixed */
3378 ok(info.Protect == prot, "%d: got %#x != expected %#x\n", i, info.Protect, prot);
3379 ok(info.AllocationBase == base, "%d: %p != %p\n", i, info.AllocationBase, base);
3380 ok(info.AllocationProtect == alloc_prot, "%d: %#x != %#x\n", i, info.AllocationProtect, alloc_prot);
3381 ok(info.State == MEM_COMMIT, "%d: %#x != MEM_COMMIT\n", i, info.State);
3382 ok(info.Type == MEM_MAPPED, "%d: %#x != MEM_MAPPED\n", i, info.Type);
3383
3384 if (is_mem_writable(info.Protect))
3385 {
3386 base[0] = 0xfe;
3387
3388 SetLastError(0xdeadbeef);
3389 ret = VirtualQuery(base, &info, sizeof(info));
3390 ok(ret, "VirtualQuery failed %d\n", GetLastError());
3391 /* FIXME: remove the condition below once Wine is fixed */
3392 todo_wine_if (td[i].prot == PAGE_WRITECOPY || td[i].prot == PAGE_EXECUTE_WRITECOPY)
3393 ok(info.Protect == td[i].prot_after_write, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].prot_after_write);
3394 }
3395 }
3396 else
3397 {
3398 ok(!ret, "%d: VirtualProtect should fail\n", i);
3399 ok(GetLastError() == ERROR_INVALID_PARAMETER, "%d: expected ERROR_INVALID_PARAMETER, got %d\n", i, GetLastError());
3400 continue;
3401 }
3402
3403 old_prot = 0xdeadbeef;
3404 SetLastError(0xdeadbeef);
3405 ret = VirtualProtect(base, si.dwPageSize, PAGE_NOACCESS, &old_prot);
3406 ok(ret, "%d: VirtualProtect error %d\n", i, GetLastError());
3407 /* FIXME: remove the condition below once Wine is fixed */
3408 todo_wine_if (td[i].prot == PAGE_WRITECOPY || td[i].prot == PAGE_EXECUTE_WRITECOPY)
3409 ok(old_prot == td[i].prot_after_write, "%d: got %#x != expected %#x\n", i, old_prot, td[i].prot_after_write);
3410 }
3411
3413 CloseHandle(hmap);
3414
3415 CloseHandle(hfile);
3417}
#define trace
Definition: atltest.h:70
#define broken(x)
Definition: atltest.h:178
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define FILE_BEGIN
Definition: compat.h:761
#define UnmapViewOfFile
Definition: compat.h:746
#define SetFilePointer
Definition: compat.h:743
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define GENERIC_READ
Definition: compat.h:135
#define MapViewOfFile
Definition: compat.h:745
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2054
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:143
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define CREATE_ALWAYS
Definition: disk.h:72
static PVOID ptr
Definition: dispmode.c:27
static BOOL is_mem_writable(DWORD prot)
Definition: virtual.c:3059
#define todo_wine_if(is_todo)
Definition: custom.c:86
static LPCWSTR file_name
Definition: protocol.c:147
char temp_path[MAX_PATH]
Definition: mspatcha.c:123
#define MEM_MAPPED
Definition: nt_native.h:1319
#define GENERIC_WRITE
Definition: nt_native.h:90
#define GENERIC_EXECUTE
Definition: nt_native.h:91
DWORD dwPageSize
Definition: winbase.h:1198
BOOL NTAPI VirtualProtect(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flNewProtect, OUT PDWORD lpflOldProtect)
Definition: virtmem.c:135
SIZE_T NTAPI VirtualQuery(IN LPCVOID lpAddress, OUT PMEMORY_BASIC_INFORMATION lpBuffer, IN SIZE_T dwLength)
Definition: virtmem.c:211
#define success(from, fromstr, to, tostr)

Referenced by START_TEST().

◆ test_IsBadCodePtr()

static void test_IsBadCodePtr ( void  )
static

Definition at line 1541 of file virtual.c.

1542{
1543 BOOL ret;
1544 void *ptr = (void *)0xdeadbeef;
1545 char stackval;
1546
1548 ok(ret == TRUE, "Expected IsBadCodePtr to return TRUE, got %d\n", ret);
1549
1550 ret = IsBadCodePtr(ptr);
1551 ok(ret == TRUE, "Expected IsBadCodePtr to return TRUE, got %d\n", ret);
1552
1553 ret = IsBadCodePtr((void *)&stackval);
1554 ok(ret == FALSE, "Expected IsBadCodePtr to return FALSE, got %d\n", ret);
1555}
BOOL NTAPI IsBadCodePtr(FARPROC lpfn)
Definition: except.c:872

Referenced by START_TEST().

◆ test_IsBadReadPtr()

static void test_IsBadReadPtr ( void  )
static

Definition at line 1491 of file virtual.c.

1492{
1493 BOOL ret;
1494 void *ptr = (void *)0xdeadbeef;
1495 char stackvar;
1496
1497 ret = IsBadReadPtr(NULL, 0);
1498 ok(ret == FALSE, "Expected IsBadReadPtr to return FALSE, got %d\n", ret);
1499
1500 ret = IsBadReadPtr(NULL, 1);
1501 ok(ret == TRUE, "Expected IsBadReadPtr to return TRUE, got %d\n", ret);
1502
1503 ret = IsBadReadPtr(ptr, 0);
1504 ok(ret == FALSE, "Expected IsBadReadPtr to return FALSE, got %d\n", ret);
1505
1506 ret = IsBadReadPtr(ptr, 1);
1507 ok(ret == TRUE, "Expected IsBadReadPtr to return TRUE, got %d\n", ret);
1508
1509 ret = IsBadReadPtr(&stackvar, 0);
1510 ok(ret == FALSE, "Expected IsBadReadPtr to return FALSE, got %d\n", ret);
1511
1512 ret = IsBadReadPtr(&stackvar, sizeof(char));
1513 ok(ret == FALSE, "Expected IsBadReadPtr to return FALSE, got %d\n", ret);
1514}
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:805

Referenced by START_TEST().

◆ test_IsBadWritePtr()

static void test_IsBadWritePtr ( void  )
static

Definition at line 1516 of file virtual.c.

1517{
1518 BOOL ret;
1519 void *ptr = (void *)0xdeadbeef;
1520 char stackval;
1521
1522 ret = IsBadWritePtr(NULL, 0);
1523 ok(ret == FALSE, "Expected IsBadWritePtr to return FALSE, got %d\n", ret);
1524
1525 ret = IsBadWritePtr(NULL, 1);
1526 ok(ret == TRUE, "Expected IsBadWritePtr to return TRUE, got %d\n", ret);
1527
1528 ret = IsBadWritePtr(ptr, 0);
1529 ok(ret == FALSE, "Expected IsBadWritePtr to return FALSE, got %d\n", ret);
1530
1531 ret = IsBadWritePtr(ptr, 1);
1532 ok(ret == TRUE, "Expected IsBadWritePtr to return TRUE, got %d\n", ret);
1533
1534 ret = IsBadWritePtr(&stackval, 0);
1535 ok(ret == FALSE, "Expected IsBadWritePtr to return FALSE, got %d\n", ret);
1536
1537 ret = IsBadWritePtr(&stackval, sizeof(char));
1538 ok(ret == FALSE, "Expected IsBadWritePtr to return FALSE, got %d\n", ret);
1539}
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:883

Referenced by START_TEST().

◆ test_mapping()

static void test_mapping ( void  )
static

Definition at line 3547 of file virtual.c.

3548{
3549 static const DWORD page_prot[] =
3550 {
3553 };
3554 static const struct
3555 {
3556 DWORD access, prot;
3557 } view[] =
3558 {
3559 { 0, PAGE_NOACCESS }, /* 0x00 */
3560 { FILE_MAP_COPY, PAGE_WRITECOPY }, /* 0x01 */
3561 { FILE_MAP_WRITE, PAGE_READWRITE }, /* 0x02 */
3563 { FILE_MAP_READ, PAGE_READONLY }, /* 0x04 */
3564 { FILE_MAP_READ | FILE_MAP_COPY, PAGE_READONLY }, /* 0x05 */
3567 { SECTION_MAP_EXECUTE, PAGE_NOACCESS }, /* 0x08 */
3575 { FILE_MAP_EXECUTE, PAGE_NOACCESS }, /* 0x20 */
3591 };
3592 void *base, *nt_base, *ptr;
3593 DWORD i, j, k, ret, old_prot, prev_prot;
3594 SYSTEM_INFO si;
3595 char temp_path[MAX_PATH];
3596 char file_name[MAX_PATH];
3597 HANDLE hfile, hmap;
3599
3600 GetSystemInfo(&si);
3601 trace("system page size %#x\n", si.dwPageSize);
3602
3605
3606 SetLastError(0xdeadbeef);
3608 ok(hfile != INVALID_HANDLE_VALUE, "CreateFile(%s) error %d\n", file_name, GetLastError());
3610 SetEndOfFile(hfile);
3611
3612 for (i = 0; i < sizeof(page_prot)/sizeof(page_prot[0]); i++)
3613 {
3614 SetLastError(0xdeadbeef);
3615 hmap = CreateFileMappingW(hfile, NULL, page_prot[i] | SEC_COMMIT, 0, si.dwPageSize, NULL);
3616
3617 if (page_prot[i] == PAGE_NOACCESS)
3618 {
3619 HANDLE hmap2;
3620
3621 ok(!hmap, "CreateFileMapping(PAGE_NOACCESS) should fail\n");
3622 ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
3623
3624 /* A trick to create a not accessible mapping */
3625 SetLastError(0xdeadbeef);
3627 ok(hmap != 0, "CreateFileMapping(PAGE_READWRITE) error %d\n", GetLastError());
3628 SetLastError(0xdeadbeef);
3629 ret = DuplicateHandle(GetCurrentProcess(), hmap, GetCurrentProcess(), &hmap2, 0, FALSE, 0);
3630 ok(ret, "DuplicateHandle error %d\n", GetLastError());
3631 CloseHandle(hmap);
3632 hmap = hmap2;
3633 }
3634
3635 if (!hmap)
3636 {
3637 trace("%d: CreateFileMapping(%04x) failed: %d\n", i, page_prot[i], GetLastError());
3638
3639 /* NT4 and win2k don't support EXEC on file mappings */
3640 if (page_prot[i] == PAGE_EXECUTE_READ || page_prot[i] == PAGE_EXECUTE_READWRITE)
3641 {
3642 ok(broken(!hmap), "%d: CreateFileMapping doesn't support PAGE_EXECUTE\n", i);
3643 continue;
3644 }
3645 /* Vista+ supports PAGE_EXECUTE_WRITECOPY, earlier versions don't */
3646 if (page_prot[i] == PAGE_EXECUTE_WRITECOPY)
3647 {
3648 ok(broken(!hmap), "%d: CreateFileMapping doesn't support PAGE_EXECUTE_WRITECOPY\n", i);
3649 continue;
3650 }
3651 }
3652
3653 ok(hmap != 0, "%d: CreateFileMapping(%04x) error %d\n", i, page_prot[i], GetLastError());
3654
3655 for (j = 0; j < sizeof(view)/sizeof(view[0]); j++)
3656 {
3657 nt_base = map_view_of_file(hmap, view[j].access);
3658 if (nt_base)
3659 {
3660 SetLastError(0xdeadbeef);
3661 ret = VirtualQuery(nt_base, &nt_info, sizeof(nt_info));
3662 ok(ret, "%d: VirtualQuery failed %d\n", j, GetLastError());
3663 UnmapViewOfFile(nt_base);
3664 }
3665
3666 SetLastError(0xdeadbeef);
3667 base = MapViewOfFile(hmap, view[j].access, 0, 0, 0);
3668
3669 /* Vista+ supports FILE_MAP_EXECUTE properly, earlier versions don't */
3670 ok(!nt_base == !base ||
3671 broken((view[j].access & FILE_MAP_EXECUTE) && !nt_base != !base),
3672 "%d: (%04x/%04x) NT %p kernel %p\n", j, page_prot[i], view[j].access, nt_base, base);
3673
3674 if (!is_compatible_access(page_prot[i], view[j].access))
3675 {
3676 ok(!base, "%d: MapViewOfFile(%04x/%04x) should fail\n", j, page_prot[i], view[j].access);
3677 ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %d\n", GetLastError());
3678 continue;
3679 }
3680
3681 /* Vista+ properly supports FILE_MAP_EXECUTE, earlier versions don't */
3682 if (!base && (view[j].access & FILE_MAP_EXECUTE))
3683 {
3684 ok(broken(!base), "%d: MapViewOfFile(%04x/%04x) failed %d\n", j, page_prot[i], view[j].access, GetLastError());
3685 continue;
3686 }
3687
3688 ok(base != NULL, "%d: MapViewOfFile(%04x/%04x) failed %d\n", j, page_prot[i], view[j].access, GetLastError());
3689
3690 SetLastError(0xdeadbeef);
3691 ret = VirtualQuery(base, &info, sizeof(info));
3692 ok(ret, "%d: VirtualQuery failed %d\n", j, GetLastError());
3693 ok(info.BaseAddress == base, "%d: (%04x) got %p, expected %p\n", j, view[j].access, info.BaseAddress, base);
3694 ok(info.RegionSize == si.dwPageSize, "%d: (%04x) got %#lx != expected %#x\n", j, view[j].access, info.RegionSize, si.dwPageSize);
3695 ok(info.Protect == view[j].prot ||
3696 broken(view[j].prot == PAGE_EXECUTE_READ && info.Protect == PAGE_READONLY) || /* win2k */
3697 broken(view[j].prot == PAGE_EXECUTE_READWRITE && info.Protect == PAGE_READWRITE) || /* win2k */
3698 broken(view[j].prot == PAGE_EXECUTE_WRITECOPY && info.Protect == PAGE_NOACCESS), /* XP */
3699 "%d: (%04x) got %#x, expected %#x\n", j, view[j].access, info.Protect, view[j].prot);
3700 ok(info.AllocationBase == base, "%d: (%04x) got %p, expected %p\n", j, view[j].access, info.AllocationBase, base);
3701 ok(info.AllocationProtect == info.Protect, "%d: (%04x) got %#x, expected %#x\n", j, view[j].access, info.AllocationProtect, info.Protect);
3702 ok(info.State == MEM_COMMIT, "%d: (%04x) got %#x, expected MEM_COMMIT\n", j, view[j].access, info.State);
3703 ok(info.Type == MEM_MAPPED, "%d: (%04x) got %#x, expected MEM_MAPPED\n", j, view[j].access, info.Type);
3704
3705 if (nt_base && base)
3706 {
3707 ok(nt_info.RegionSize == info.RegionSize, "%d: (%04x) got %#lx != expected %#lx\n", j, view[j].access, nt_info.RegionSize, info.RegionSize);
3708 ok(nt_info.Protect == info.Protect /* Vista+ */ ||
3709 broken(nt_info.AllocationProtect == PAGE_EXECUTE_WRITECOPY && info.Protect == PAGE_NOACCESS), /* XP */
3710 "%d: (%04x) got %#x, expected %#x\n", j, view[j].access, nt_info.Protect, info.Protect);
3711 ok(nt_info.AllocationProtect == info.AllocationProtect /* Vista+ */ ||
3712 broken(nt_info.AllocationProtect == PAGE_EXECUTE_WRITECOPY && info.Protect == PAGE_NOACCESS), /* XP */
3713 "%d: (%04x) got %#x, expected %#x\n", j, view[j].access, nt_info.AllocationProtect, info.AllocationProtect);
3714 ok(nt_info.State == info.State, "%d: (%04x) got %#x, expected %#x\n", j, view[j].access, nt_info.State, info.State);
3715 ok(nt_info.Type == info.Type, "%d: (%04x) got %#x, expected %#x\n", j, view[j].access, nt_info.Type, info.Type);
3716 }
3717
3718 prev_prot = info.Protect;
3719
3720 for (k = 0; k < sizeof(page_prot)/sizeof(page_prot[0]); k++)
3721 {
3722 /*trace("map %#x, view %#x, requested prot %#x\n", page_prot[i], view[j].prot, page_prot[k]);*/
3723 SetLastError(0xdeadbeef);
3724 old_prot = 0xdeadbeef;
3725 ret = VirtualProtect(base, si.dwPageSize, page_prot[k], &old_prot);
3726 if (is_compatible_protection(page_prot[i], view[j].prot, page_prot[k]))
3727 {
3728 /* win2k and XP don't support EXEC on file mappings */
3729 if (!ret && page_prot[k] == PAGE_EXECUTE)
3730 {
3731 ok(broken(!ret), "VirtualProtect doesn't support PAGE_EXECUTE\n");
3732 continue;
3733 }
3734 /* NT4 and win2k don't support EXEC on file mappings */
3735 if (!ret && (page_prot[k] == PAGE_EXECUTE_READ || page_prot[k] == PAGE_EXECUTE_READWRITE))
3736 {
3737 ok(broken(!ret), "VirtualProtect doesn't support PAGE_EXECUTE\n");
3738 continue;
3739 }
3740 /* Vista+ supports PAGE_EXECUTE_WRITECOPY, earlier versions don't */
3741 if (!ret && page_prot[k] == PAGE_EXECUTE_WRITECOPY)
3742 {
3743 ok(broken(!ret), "VirtualProtect doesn't support PAGE_EXECUTE_WRITECOPY\n");
3744 continue;
3745 }
3746 /* win2k and XP don't support PAGE_EXECUTE_WRITECOPY views properly */
3747 if (!ret && view[j].prot == PAGE_EXECUTE_WRITECOPY)
3748 {
3749 ok(broken(!ret), "VirtualProtect doesn't support PAGE_EXECUTE_WRITECOPY view properly\n");
3750 continue;
3751 }
3752
3753 ok(ret, "VirtualProtect error %d, map %#x, view %#x, requested prot %#x\n", GetLastError(), page_prot[i], view[j].prot, page_prot[k]);
3754 ok(old_prot == prev_prot, "got %#x, expected %#x\n", old_prot, prev_prot);
3755 prev_prot = page_prot[k];
3756 }
3757 else
3758 {
3759 /* NT4 doesn't fail on incompatible map and view */
3760 if (ret)
3761 {
3762 ok(broken(ret), "VirtualProtect should fail, map %#x, view %#x, requested prot %#x\n", page_prot[i], view[j].prot, page_prot[k]);
3763 skip("Incompatible map and view are not properly handled on this platform\n");
3764 break; /* NT4 won't pass remaining tests */
3765 }
3766
3767 ok(!ret, "VirtualProtect should fail, map %#x, view %#x, requested prot %#x\n", page_prot[i], view[j].prot, page_prot[k]);
3768 ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
3769 }
3770 }
3771
3772 for (k = 0; k < sizeof(page_prot)/sizeof(page_prot[0]); k++)
3773 {
3774 /*trace("map %#x, view %#x, requested prot %#x\n", page_prot[i], view[j].prot, page_prot[k]);*/
3775 SetLastError(0xdeadbeef);
3776 ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, page_prot[k]);
3777 ok(!ptr, "VirtualAlloc(%02x) should fail\n", page_prot[k]);
3778 /* FIXME: remove once Wine is fixed */
3779 todo_wine_if (page_prot[k] == PAGE_WRITECOPY || page_prot[k] == PAGE_EXECUTE_WRITECOPY)
3780 ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
3781 }
3782
3784 }
3785
3786 CloseHandle(hmap);
3787 }
3788
3789 CloseHandle(hfile);
3791}
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static BOOL is_compatible_access(DWORD map_prot, DWORD view_prot)
Definition: virtual.c:3487
static void * map_view_of_file(HANDLE handle, DWORD access)
Definition: virtual.c:3494
static BOOL is_compatible_protection(DWORD map_prot, DWORD view_prot, DWORD prot)
Definition: virtual.c:3452
int k
Definition: mpi.c:3369

Referenced by START_TEST().

◆ test_MapViewOfFile()

static void test_MapViewOfFile ( void  )
static

Definition at line 430 of file virtual.c.

431{
432 static const char testfile[] = "testfile.xxx";
433 const char *name;
434 HANDLE file, mapping, map2;
435 void *ptr, *ptr2, *addr;
437 SECTION_IMAGE_INFORMATION image_info;
439 BOOL ret;
440 SIZE_T size;
442 ULONG info_size;
443 LARGE_INTEGER map_size;
444
445 SetLastError(0xdeadbeef);
447 ok( file != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
450
451 /* read/write mapping */
452
453 SetLastError(0xdeadbeef);
455 ok( mapping != 0, "CreateFileMapping error %u\n", GetLastError() );
456
457 SetLastError(0xdeadbeef);
458 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
459 ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
461
462 SetLastError(0xdeadbeef);
463 ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
464 ok( ptr != NULL, "MapViewOfFile FILE_MAP_COPY error %u\n", GetLastError() );
466
467 SetLastError(0xdeadbeef);
468 ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
469 ok( ptr != NULL, "MapViewOfFile 0 error %u\n", GetLastError() );
471
472 SetLastError(0xdeadbeef);
473 ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
474 ok( ptr != NULL, "MapViewOfFile FILE_MAP_WRITE error %u\n", GetLastError() );
476
479 ok( ret, "DuplicateHandle failed error %u\n", GetLastError());
480 ptr = MapViewOfFile( map2, FILE_MAP_WRITE, 0, 0, 4096 );
481 ok( ptr != NULL, "MapViewOfFile FILE_MAP_WRITE error %u\n", GetLastError() );
483 CloseHandle( map2 );
484
486 FILE_MAP_READ, FALSE, 0 );
487 ok( ret, "DuplicateHandle failed error %u\n", GetLastError());
488 SetLastError(0xdeadbeef);
489 ptr = MapViewOfFile( map2, FILE_MAP_WRITE, 0, 0, 4096 );
490 ok( !ptr, "MapViewOfFile succeeded\n" );
491 ok( GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
492 CloseHandle( map2 );
494 ok( ret, "DuplicateHandle failed error %u\n", GetLastError());
495 SetLastError(0xdeadbeef);
496 ptr = MapViewOfFile( map2, 0, 0, 0, 4096 );
497 ok( !ptr, "MapViewOfFile succeeded\n" );
498 ok( GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
499 CloseHandle( map2 );
501 FILE_MAP_READ, FALSE, 0 );
502 ok( ret, "DuplicateHandle failed error %u\n", GetLastError());
503 ptr = MapViewOfFile( map2, 0, 0, 0, 4096 );
504 ok( ptr != NULL, "MapViewOfFile NO_ACCESS error %u\n", GetLastError() );
505
507 CloseHandle( map2 );
509
510 /* read-only mapping */
511
512 SetLastError(0xdeadbeef);
514 ok( mapping != 0, "CreateFileMapping error %u\n", GetLastError() );
515
516 SetLastError(0xdeadbeef);
517 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
518 ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
520
521 SetLastError(0xdeadbeef);
522 ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
523 ok( ptr != NULL, "MapViewOfFile FILE_MAP_COPY error %u\n", GetLastError() );
525
526 SetLastError(0xdeadbeef);
527 ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
528 ok( ptr != NULL, "MapViewOfFile 0 error %u\n", GetLastError() );
530
531 SetLastError(0xdeadbeef);
532 ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
533 ok( !ptr, "MapViewOfFile FILE_MAP_WRITE succeeded\n" );
535 GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
537
538 /* copy-on-write mapping */
539
540 SetLastError(0xdeadbeef);
542 ok( mapping != 0, "CreateFileMapping error %u\n", GetLastError() );
543
544 SetLastError(0xdeadbeef);
545 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
546 ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
548
549 SetLastError(0xdeadbeef);
550 ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
551 ok( ptr != NULL, "MapViewOfFile FILE_MAP_COPY error %u\n", GetLastError() );
553
554 SetLastError(0xdeadbeef);
555 ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
556 ok( ptr != NULL, "MapViewOfFile 0 error %u\n", GetLastError() );
558
559 SetLastError(0xdeadbeef);
560 ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
561 ok( !ptr, "MapViewOfFile FILE_MAP_WRITE succeeded\n" );
563 GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
565
566 /* no access mapping */
567
568 SetLastError(0xdeadbeef);
570 ok( !mapping, "CreateFileMappingA succeeded\n" );
571 ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %d\n", GetLastError() );
572 CloseHandle( file );
573
574 /* now try read-only file */
575
576 SetLastError(0xdeadbeef);
577 file = CreateFileA( testfile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0 );
578 ok( file != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
579
580 SetLastError(0xdeadbeef);
582 ok( !mapping, "CreateFileMapping PAGE_READWRITE succeeded\n" );
584 GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
585
586 SetLastError(0xdeadbeef);
588 ok( mapping != 0, "CreateFileMapping PAGE_WRITECOPY error %u\n", GetLastError() );
590
591 SetLastError(0xdeadbeef);
593 ok( mapping != 0, "CreateFileMapping PAGE_READONLY error %u\n", GetLastError() );
595 CloseHandle( file );
596
597 /* now try no access file */
598
599 SetLastError(0xdeadbeef);
600 file = CreateFileA( testfile, 0, 0, NULL, OPEN_EXISTING, 0, 0 );
601 ok( file != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
602
603 SetLastError(0xdeadbeef);
605 ok( !mapping, "CreateFileMapping PAGE_READWRITE succeeded\n" );
607 GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
608
609 SetLastError(0xdeadbeef);
611 ok( !mapping, "CreateFileMapping PAGE_WRITECOPY succeeded\n" );
613 GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
614
615 SetLastError(0xdeadbeef);
617 ok( !mapping, "CreateFileMapping PAGE_READONLY succeeded\n" );
619 GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
620
621 CloseHandle( file );
622 DeleteFileA( testfile );
623
624 SetLastError(0xdeadbeef);
625 name = "Local\\Foo";
627 /* nt4 doesn't have Local\\ */
629 {
630 name = "Foo";
632 }
633 ok( file != 0, "CreateFileMapping PAGE_READWRITE error %u\n", GetLastError() );
634
635 SetLastError(0xdeadbeef);
637 ok( mapping != 0, "OpenFileMapping FILE_MAP_READ error %u\n", GetLastError() );
638 SetLastError(0xdeadbeef);
640 ok( !ptr, "MapViewOfFile FILE_MAP_WRITE succeeded\n" );
641 ok( GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
642 SetLastError(0xdeadbeef);
643 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
644 ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
645 SetLastError(0xdeadbeef);
646 size = VirtualQuery( ptr, &info, sizeof(info) );
647 ok( size == sizeof(info),
648 "VirtualQuery error %u\n", GetLastError() );
649 ok( info.BaseAddress == ptr, "%p != %p\n", info.BaseAddress, ptr );
650 ok( info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr );
651 ok( info.AllocationProtect == PAGE_READONLY, "%x != PAGE_READONLY\n", info.AllocationProtect );
652 ok( info.RegionSize == 4096, "%lx != 4096\n", info.RegionSize );
653 ok( info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State );
654 ok( info.Protect == PAGE_READONLY, "%x != PAGE_READONLY\n", info.Protect );
657 sizeof(section_info), &info_size );
658 ok( status == STATUS_ACCESS_DENIED, "NtQuerySection failed err %x\n", status );
661 ok( mapping != 0, "OpenFileMapping FILE_MAP_READ error %u\n", GetLastError() );
663 sizeof(section_info), &info_size );
664 ok( !status, "NtQuerySection failed err %x\n", status );
665 ok( info_size == sizeof(section_info), "NtQuerySection wrong size %u\n", info_size );
666 ok( section_info.Attributes == SEC_COMMIT, "NtQuerySection wrong attr %08x\n",
667 section_info.Attributes );
668 ok( section_info.BaseAddress == NULL, "NtQuerySection wrong base %p\n", section_info.BaseAddress );
669 ok( section_info.Size.QuadPart == info.RegionSize, "NtQuerySection wrong size %x%08x / %08lx\n",
670 section_info.Size.u.HighPart, section_info.Size.u.LowPart, info.RegionSize );
672
673 SetLastError(0xdeadbeef);
675 ok( mapping != 0, "OpenFileMapping FILE_MAP_WRITE error %u\n", GetLastError() );
676 SetLastError(0xdeadbeef);
677 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
678 ok( !ptr, "MapViewOfFile succeeded\n" );
679 ok( GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
680 SetLastError(0xdeadbeef);
682 ok( ptr != NULL, "MapViewOfFile FILE_MAP_WRITE error %u\n", GetLastError() );
683 SetLastError(0xdeadbeef);
684 size = VirtualQuery( ptr, &info, sizeof(info) );
685 ok( size == sizeof(info),
686 "VirtualQuery error %u\n", GetLastError() );
687 ok( info.BaseAddress == ptr, "%p != %p\n", info.BaseAddress, ptr );
688 ok( info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr );
689 ok( info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect );
690 ok( info.RegionSize == 4096, "%lx != 4096\n", info.RegionSize );
691 ok( info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State );
692 ok( info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect );
695 sizeof(section_info), &info_size );
696 ok( status == STATUS_ACCESS_DENIED, "NtQuerySection failed err %x\n", status );
698
700 ok( mapping != 0, "OpenFileMapping FILE_MAP_WRITE error %u\n", GetLastError() );
702 sizeof(section_info), &info_size );
703 ok( !status, "NtQuerySection failed err %x\n", status );
704 ok( info_size == sizeof(section_info), "NtQuerySection wrong size %u\n", info_size );
705 ok( section_info.Attributes == SEC_COMMIT, "NtQuerySection wrong attr %08x\n",
706 section_info.Attributes );
707 ok( section_info.BaseAddress == NULL, "NtQuerySection wrong base %p\n", section_info.BaseAddress );
708 ok( section_info.Size.QuadPart == info.RegionSize, "NtQuerySection wrong size %x%08x / %08lx\n",
709 section_info.Size.u.HighPart, section_info.Size.u.LowPart, info.RegionSize );
711
712 CloseHandle( file );
713
714 /* read/write mapping with SEC_RESERVE */
716 ok(mapping != INVALID_HANDLE_VALUE, "CreateFileMappingA failed with error %d\n", GetLastError());
718 sizeof(section_info), NULL );
719 ok( !status, "NtQuerySection failed err %x\n", status );
720 ok( section_info.Attributes == SEC_RESERVE, "NtQuerySection wrong attr %08x\n",
721 section_info.Attributes );
722 ok( section_info.BaseAddress == NULL, "NtQuerySection wrong base %p\n", section_info.BaseAddress );
723 ok( section_info.Size.QuadPart == MAPPING_SIZE, "NtQuerySection wrong size %x%08x / %08x\n",
724 section_info.Size.u.HighPart, section_info.Size.u.LowPart, MAPPING_SIZE );
725
727 ok(ptr != NULL, "MapViewOfFile failed with error %d\n", GetLastError());
728
729 ptr2 = MapViewOfFile(mapping, FILE_MAP_WRITE, 0, 0, 0);
730 ok( ptr2 != NULL, "MapViewOfFile failed with error %d\n", GetLastError());
731 ok( ptr != ptr2, "MapViewOfFile returned same pointer\n" );
732
733 ret = VirtualQuery(ptr, &info, sizeof(info));
734 ok(ret, "VirtualQuery failed with error %d\n", GetLastError());
735 ok(info.BaseAddress == ptr, "BaseAddress should have been %p but was %p instead\n", ptr, info.BaseAddress);
736 ok(info.AllocationBase == ptr, "AllocationBase should have been %p but was %p instead\n", ptr, info.AllocationBase);
737 ok(info.RegionSize == MAPPING_SIZE, "RegionSize should have been 0x%x but was 0x%lx\n", MAPPING_SIZE, info.RegionSize);
738 ok(info.State == MEM_RESERVE, "State should have been MEM_RESERVE instead of 0x%x\n", info.State);
739 ok(info.AllocationProtect == PAGE_READWRITE,
740 "AllocationProtect should have been PAGE_READWRITE but was 0x%x\n", info.AllocationProtect);
741 ok(info.Protect == 0, "Protect should have been 0 instead of 0x%x\n", info.Protect);
742 ok(info.Type == MEM_MAPPED, "Type should have been MEM_MAPPED instead of 0x%x\n", info.Type);
743
744 ret = VirtualQuery(ptr2, &info, sizeof(info));
745 ok(ret, "VirtualQuery failed with error %d\n", GetLastError());
746 ok(info.BaseAddress == ptr2,
747 "BaseAddress should have been %p but was %p instead\n", ptr2, info.BaseAddress);
748 ok(info.AllocationBase == ptr2,
749 "AllocationBase should have been %p but was %p instead\n", ptr2, info.AllocationBase);
750 ok(info.AllocationProtect == PAGE_READWRITE,
751 "AllocationProtect should have been PAGE_READWRITE but was 0x%x\n", info.AllocationProtect);
752 ok(info.RegionSize == MAPPING_SIZE,
753 "RegionSize should have been 0x%x but was 0x%lx\n", MAPPING_SIZE, info.RegionSize);
754 ok(info.State == MEM_RESERVE, "State should have been MEM_RESERVE instead of 0x%x\n", info.State);
755 ok(info.Protect == 0, "Protect should have been 0 instead of 0x%x\n", info.Protect);
756 ok(info.Type == MEM_MAPPED, "Type should have been MEM_MAPPED instead of 0x%x\n", info.Type);
757
759 ok(ptr != NULL, "VirtualAlloc failed with error %d\n", GetLastError());
760
761 ret = VirtualQuery(ptr, &info, sizeof(info));
762 ok(ret, "VirtualQuery failed with error %d\n", GetLastError());
763 ok(info.BaseAddress == ptr, "BaseAddress should have been %p but was %p instead\n", ptr, info.BaseAddress);
764 ok(info.AllocationBase == ptr, "AllocationBase should have been %p but was %p instead\n", ptr, info.AllocationBase);
765 ok(info.RegionSize == 0x10000, "RegionSize should have been 0x10000 but was 0x%lx\n", info.RegionSize);
766 ok(info.State == MEM_COMMIT, "State should have been MEM_COMMIT instead of 0x%x\n", info.State);
767 ok(info.Protect == PAGE_READONLY, "Protect should have been PAGE_READONLY instead of 0x%x\n", info.Protect);
768 ok(info.AllocationProtect == PAGE_READWRITE,
769 "AllocationProtect should have been PAGE_READWRITE but was 0x%x\n", info.AllocationProtect);
770 ok(info.Type == MEM_MAPPED, "Type should have been MEM_MAPPED instead of 0x%x\n", info.Type);
771
772 /* shows that the VirtualAlloc above affects the mapping, not just the
773 * virtual memory in this process - it also affects all other processes
774 * with a view of the mapping, but that isn't tested here */
775 ret = VirtualQuery(ptr2, &info, sizeof(info));
776 ok(ret, "VirtualQuery failed with error %d\n", GetLastError());
777 ok(info.BaseAddress == ptr2,
778 "BaseAddress should have been %p but was %p instead\n", ptr2, info.BaseAddress);
779 ok(info.AllocationBase == ptr2,
780 "AllocationBase should have been %p but was %p instead\n", ptr2, info.AllocationBase);
781 ok(info.AllocationProtect == PAGE_READWRITE,
782 "AllocationProtect should have been PAGE_READWRITE but was 0x%x\n", info.AllocationProtect);
783 ok(info.RegionSize == 0x10000,
784 "RegionSize should have been 0x10000 but was 0x%lx\n", info.RegionSize);
785 ok(info.State == MEM_COMMIT,
786 "State should have been MEM_COMMIT instead of 0x%x\n", info.State);
787 ok(info.Protect == PAGE_READWRITE,
788 "Protect should have been PAGE_READWRITE instead of 0x%x\n", info.Protect);
789 ok(info.Type == MEM_MAPPED, "Type should have been MEM_MAPPED instead of 0x%x\n", info.Type);
790
792 ok( addr == ptr, "VirtualAlloc failed with error %u\n", GetLastError() );
793
794 ret = VirtualFree( ptr, 0x10000, MEM_DECOMMIT );
795 ok( !ret, "VirtualFree succeeded\n" );
796 ok( GetLastError() == ERROR_INVALID_PARAMETER, "VirtualFree failed with %u\n", GetLastError() );
797
798 ret = UnmapViewOfFile(ptr2);
799 ok(ret, "UnmapViewOfFile failed with error %d\n", GetLastError());
801 ok(ret, "UnmapViewOfFile failed with error %d\n", GetLastError());
803
805 ok( addr != NULL, "VirtualAlloc failed with error %u\n", GetLastError() );
806
807 SetLastError(0xdeadbeef);
808 ok( !UnmapViewOfFile(addr), "UnmapViewOfFile should fail on VirtualAlloc mem\n" );
810 "got %u, expected ERROR_INVALID_ADDRESS\n", GetLastError());
811 SetLastError(0xdeadbeef);
812 ok( !UnmapViewOfFile((char *)addr + 0x3000), "UnmapViewOfFile should fail on VirtualAlloc mem\n" );
814 "got %u, expected ERROR_INVALID_ADDRESS\n", GetLastError());
815 SetLastError(0xdeadbeef);
816 ok( !UnmapViewOfFile((void *)0xdeadbeef), "UnmapViewOfFile should fail on VirtualAlloc mem\n" );
818 "got %u, expected ERROR_INVALID_ADDRESS\n", GetLastError());
819
820 ok( VirtualFree(addr, 0, MEM_RELEASE), "VirtualFree failed\n" );
821
822 /* close named mapping handle without unmapping */
823 name = "Foo";
824 SetLastError(0xdeadbeef);
826 ok( mapping != 0, "CreateFileMappingA failed with error %d\n", GetLastError() );
827 SetLastError(0xdeadbeef);
829 ok( ptr != NULL, "MapViewOfFile failed with error %d\n", GetLastError() );
830 SetLastError(0xdeadbeef);
832 ok( map2 != 0, "OpenFileMappingA failed with error %d\n", GetLastError() );
833 SetLastError(0xdeadbeef);
834 ret = CloseHandle(map2);
835 ok(ret, "CloseHandle error %d\n", GetLastError());
836 SetLastError(0xdeadbeef);
838 ok(ret, "CloseHandle error %d\n", GetLastError());
839
841 ok( !ret, "memory is not accessible\n" );
842
843 ret = VirtualQuery(ptr, &info, sizeof(info));
844 ok(ret, "VirtualQuery error %d\n", GetLastError());
845 ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
846 ok(info.RegionSize == MAPPING_SIZE, "got %#lx != expected %#x\n", info.RegionSize, MAPPING_SIZE);
847 ok(info.Protect == PAGE_READWRITE, "got %#x != expected PAGE_READWRITE\n", info.Protect);
848 ok(info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr);
849 ok(info.AllocationProtect == PAGE_READWRITE, "%#x != PAGE_READWRITE\n", info.AllocationProtect);
850 ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
851 ok(info.Type == MEM_MAPPED, "%#x != MEM_MAPPED\n", info.Type);
852
853 SetLastError(0xdeadbeef);
856 ok( map2 == 0, "OpenFileMappingA succeeded\n" );
858 ok( GetLastError() == ERROR_FILE_NOT_FOUND, "OpenFileMappingA set error %d\n", GetLastError() );
859 if (map2) CloseHandle(map2); /* FIXME: remove once Wine is fixed */
860 SetLastError(0xdeadbeef);
862 ok( mapping != 0, "CreateFileMappingA failed\n" );
864 ok( GetLastError() == ERROR_SUCCESS, "CreateFileMappingA set error %d\n", GetLastError() );
865 SetLastError(0xdeadbeef);
867 ok(ret, "CloseHandle error %d\n", GetLastError());
868
870 ok( !ret, "memory is not accessible\n" );
871
872 ret = VirtualQuery(ptr, &info, sizeof(info));
873 ok(ret, "VirtualQuery error %d\n", GetLastError());
874 ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
875 ok(info.RegionSize == MAPPING_SIZE, "got %#lx != expected %#x\n", info.RegionSize, MAPPING_SIZE);
876 ok(info.Protect == PAGE_READWRITE, "got %#x != expected PAGE_READWRITE\n", info.Protect);
877 ok(info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr);
878 ok(info.AllocationProtect == PAGE_READWRITE, "%#x != PAGE_READWRITE\n", info.AllocationProtect);
879 ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
880 ok(info.Type == MEM_MAPPED, "%#x != MEM_MAPPED\n", info.Type);
881
882 SetLastError(0xdeadbeef);
884 ok( ret, "UnmapViewOfFile failed with error %d\n", GetLastError() );
885
887 ok( ret, "memory is accessible\n" );
888
889 ret = VirtualQuery(ptr, &info, sizeof(info));
890 ok(ret, "VirtualQuery error %d\n", GetLastError());
891 ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
892 ok(info.Protect == PAGE_NOACCESS, "got %#x != expected PAGE_NOACCESS\n", info.Protect);
893 ok(info.AllocationBase == NULL, "%p != NULL\n", info.AllocationBase);
894 ok(info.AllocationProtect == 0, "%#x != 0\n", info.AllocationProtect);
895 ok(info.State == MEM_FREE, "%#x != MEM_FREE\n", info.State);
896 ok(info.Type == 0, "%#x != 0\n", info.Type);
897
898 SetLastError(0xdeadbeef);
900 ok( file != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
903
904 SetLastError(0xdeadbeef);
906 ok( mapping != 0, "CreateFileMappingA failed with error %d\n", GetLastError() );
907 SetLastError(0xdeadbeef);
909 ok( ptr != NULL, "MapViewOfFile failed with error %d\n", GetLastError() );
910 SetLastError(0xdeadbeef);
912 ok( map2 != 0, "OpenFileMappingA failed with error %d\n", GetLastError() );
913 SetLastError(0xdeadbeef);
914 ret = CloseHandle(map2);
915 ok(ret, "CloseHandle error %d\n", GetLastError());
917 sizeof(section_info), &info_size );
918 ok( !status, "NtQuerySection failed err %x\n", status );
919 ok( info_size == sizeof(section_info), "NtQuerySection wrong size %u\n", info_size );
920 ok( section_info.Attributes == SEC_FILE, "NtQuerySection wrong attr %08x\n",
921 section_info.Attributes );
922 ok( section_info.BaseAddress == NULL, "NtQuerySection wrong base %p\n", section_info.BaseAddress );
923 ok( section_info.Size.QuadPart == MAPPING_SIZE, "NtQuerySection wrong size %x%08x\n",
924 section_info.Size.u.HighPart, section_info.Size.u.LowPart );
925 SetLastError(0xdeadbeef);
927 ok(ret, "CloseHandle error %d\n", GetLastError());
928
930 ok( !ret, "memory is not accessible\n" );
931
932 ret = VirtualQuery(ptr, &info, sizeof(info));
933 ok(ret, "VirtualQuery error %d\n", GetLastError());
934 ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
935 ok(info.RegionSize == MAPPING_SIZE, "got %#lx != expected %#x\n", info.RegionSize, MAPPING_SIZE);
936 ok(info.Protect == PAGE_READWRITE, "got %#x != expected PAGE_READWRITE\n", info.Protect);
937 ok(info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr);
938 ok(info.AllocationProtect == PAGE_READWRITE, "%#x != PAGE_READWRITE\n", info.AllocationProtect);
939 ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
940 ok(info.Type == MEM_MAPPED, "%#x != MEM_MAPPED\n", info.Type);
941
942 SetLastError(0xdeadbeef);
945 ok( map2 == 0, "OpenFileMappingA succeeded\n" );
947 ok( GetLastError() == ERROR_FILE_NOT_FOUND, "OpenFileMappingA set error %d\n", GetLastError() );
948 CloseHandle(map2);
949 SetLastError(0xdeadbeef);
951 ok( mapping != 0, "CreateFileMappingA failed\n" );
953 ok( GetLastError() == ERROR_SUCCESS, "CreateFileMappingA set error %d\n", GetLastError() );
954 SetLastError(0xdeadbeef);
956 ok(ret, "CloseHandle error %d\n", GetLastError());
957
959 ok( !ret, "memory is not accessible\n" );
960
961 ret = VirtualQuery(ptr, &info, sizeof(info));
962 ok(ret, "VirtualQuery error %d\n", GetLastError());
963 ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
964 ok(info.RegionSize == MAPPING_SIZE, "got %#lx != expected %#x\n", info.RegionSize, MAPPING_SIZE);
965 ok(info.Protect == PAGE_READWRITE, "got %#x != expected PAGE_READWRITE\n", info.Protect);
966 ok(info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr);
967 ok(info.AllocationProtect == PAGE_READWRITE, "%#x != PAGE_READWRITE\n", info.AllocationProtect);
968 ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
969 ok(info.Type == MEM_MAPPED, "%#x != MEM_MAPPED\n", info.Type);
970
971 SetLastError(0xdeadbeef);
973 ok( ret, "UnmapViewOfFile failed with error %d\n", GetLastError() );
974
976 ok( ret, "memory is accessible\n" );
977
978 ret = VirtualQuery(ptr, &info, sizeof(info));
979 ok(ret, "VirtualQuery error %d\n", GetLastError());
980 ok(info.BaseAddress == ptr, "got %p != expected %p\n", info.BaseAddress, ptr);
981 ok(info.Protect == PAGE_NOACCESS, "got %#x != expected PAGE_NOACCESS\n", info.Protect);
982 ok(info.AllocationBase == NULL, "%p != NULL\n", info.AllocationBase);
983 ok(info.AllocationProtect == 0, "%#x != 0\n", info.AllocationProtect);
984 ok(info.State == MEM_FREE, "%#x != MEM_FREE\n", info.State);
985 ok(info.Type == 0, "%#x != 0\n", info.Type);
986
988 ok( mapping != NULL, "CreateFileMappingA failed with error %u\n", GetLastError() );
989
990 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 12288 );
991 ok( ptr != NULL, "MapViewOfFile failed with error %u\n", GetLastError() );
992
993 ret = UnmapViewOfFile( (char *)ptr + 100 );
994 ok( ret, "UnmapViewOfFile failed with error %u\n", GetLastError() );
995
996 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 12288 );
997 ok( ptr != NULL, "MapViewOfFile failed with error %u\n", GetLastError() );
998
999 ret = UnmapViewOfFile( (char *)ptr + 4096 );
1000 ok( ret, "UnmapViewOfFile failed with error %u\n", GetLastError() );
1001
1002 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 12288 );
1003 ok( ptr != NULL, "MapViewOfFile failed with error %u\n", GetLastError() );
1004
1005 ret = UnmapViewOfFile( (char *)ptr + 4096 + 100 );
1006 ok( ret, "UnmapViewOfFile failed with error %u\n", GetLastError() );
1007
1009
1011 ok( mapping != NULL, "CreateFileMappingA failed with error %u\n", GetLastError() );
1012 status = pNtQuerySection( mapping, SectionBasicInformation, &section_info,
1013 sizeof(section_info), &info_size );
1014 ok( !status, "NtQuerySection failed err %x\n", status );
1015 ok( info_size == sizeof(section_info), "NtQuerySection wrong size %u\n", info_size );
1016 ok( section_info.Attributes == SEC_FILE, "NtQuerySection wrong attr %08x\n",
1017 section_info.Attributes );
1018 ok( section_info.BaseAddress == NULL, "NtQuerySection wrong base %p\n", section_info.BaseAddress );
1019 ok( section_info.Size.QuadPart == 36, "NtQuerySection wrong size %x%08x\n",
1020 section_info.Size.u.HighPart, section_info.Size.u.LowPart );
1022
1026 ok( mapping != NULL, "CreateFileMappingA failed with error %u\n", GetLastError() );
1027 status = pNtQuerySection( mapping, SectionBasicInformation, &section_info,
1028 sizeof(section_info), &info_size );
1029 ok( !status, "NtQuerySection failed err %x\n", status );
1030 ok( info_size == sizeof(section_info), "NtQuerySection wrong size %u\n", info_size );
1031 ok( section_info.Attributes == SEC_FILE, "NtQuerySection wrong attr %08x\n",
1032 section_info.Attributes );
1033 ok( section_info.BaseAddress == NULL, "NtQuerySection wrong base %p\n", section_info.BaseAddress );
1034 ok( section_info.Size.QuadPart == 0x3456, "NtQuerySection wrong size %x%08x\n",
1035 section_info.Size.u.HighPart, section_info.Size.u.LowPart );
1037
1038 map_size.QuadPart = 0x3457;
1039 status = pNtCreateSection( &mapping, SECTION_QUERY | SECTION_MAP_READ, NULL,
1040 &map_size, PAGE_READONLY, SEC_COMMIT, file );
1041 ok( status == STATUS_SECTION_TOO_BIG, "NtCreateSection failed %x\n", status );
1042 status = pNtCreateSection( &mapping, SECTION_QUERY | SECTION_MAP_READ, NULL,
1043 &map_size, PAGE_READONLY, SEC_IMAGE, file );
1044 ok( status == STATUS_INVALID_IMAGE_NOT_MZ, "NtCreateSection failed %x\n", status );
1045 if (!status) CloseHandle( mapping );
1046 map_size.QuadPart = 0x3452;
1047 status = pNtCreateSection( &mapping, SECTION_QUERY | SECTION_MAP_READ, NULL,
1048 &map_size, PAGE_READONLY, SEC_COMMIT, file );
1049 ok( !status, "NtCreateSection failed %x\n", status );
1050 status = pNtQuerySection( mapping, SectionBasicInformation, &section_info, sizeof(section_info), NULL );
1051 ok( !status, "NtQuerySection failed err %x\n", status );
1052 ok( section_info.Attributes == SEC_FILE, "NtQuerySection wrong attr %08x\n",
1053 section_info.Attributes );
1054 ok( section_info.BaseAddress == NULL, "NtQuerySection wrong base %p\n", section_info.BaseAddress );
1055 ok( section_info.Size.QuadPart == 0x3452, "NtQuerySection wrong size %x%08x\n",
1056 section_info.Size.u.HighPart, section_info.Size.u.LowPart );
1057 size = map_size.QuadPart;
1058 status = pNtMapViewOfSection( mapping, GetCurrentProcess(), &ptr, 0, 0, NULL,
1060 ok( !status, "NtMapViewOfSection failed err %x\n", status );
1061 pNtUnmapViewOfSection( GetCurrentProcess(), ptr );
1062 size = map_size.QuadPart + 1;
1063 status = pNtMapViewOfSection( mapping, GetCurrentProcess(), &ptr, 0, 0, NULL,
1065 ok( status == STATUS_INVALID_VIEW_SIZE, "NtMapViewOfSection failed err %x\n", status );
1067
1068 status = pNtCreateSection( &mapping, SECTION_QUERY | SECTION_MAP_READ, NULL,
1069 &map_size, PAGE_READONLY, SEC_COMMIT, 0 );
1070 ok( !status, "NtCreateSection failed %x\n", status );
1071 status = pNtQuerySection( mapping, SectionBasicInformation, &section_info, sizeof(section_info), NULL );
1072 ok( !status, "NtQuerySection failed err %x\n", status );
1073 ok( section_info.Attributes == SEC_COMMIT, "NtQuerySection wrong attr %08x\n",
1074 section_info.Attributes );
1075 ok( section_info.BaseAddress == NULL, "NtQuerySection wrong base %p\n", section_info.BaseAddress );
1076 ok( section_info.Size.QuadPart == 0x4000, "NtQuerySection wrong size %x%08x\n",
1077 section_info.Size.u.HighPart, section_info.Size.u.LowPart );
1078 status = pNtQuerySection( mapping, SectionBasicInformation, &section_info, sizeof(section_info)-1, NULL );
1079 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySection failed err %x\n", status );
1080 status = pNtQuerySection( mapping, SectionBasicInformation, &section_info, sizeof(section_info)+1, NULL );
1081 ok( !status, "NtQuerySection failed err %x\n", status );
1082 status = pNtQuerySection( mapping, SectionImageInformation, &image_info, sizeof(image_info)-1, NULL );
1083 ok( status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySection failed err %x\n", status );
1084 status = pNtQuerySection( mapping, SectionImageInformation, &image_info, sizeof(image_info), NULL );
1085 ok( status == STATUS_SECTION_NOT_IMAGE, "NtQuerySection failed err %x\n", status );
1086 status = pNtQuerySection( mapping, SectionImageInformation, &image_info, sizeof(image_info)+1, NULL );
1087 ok( status == STATUS_SECTION_NOT_IMAGE, "NtQuerySection failed err %x\n", status );
1089
1092 status = pNtCreateSection( &mapping, SECTION_QUERY | SECTION_MAP_READ, NULL,
1094 ok( status == STATUS_MAPPED_FILE_SIZE_ZERO, "NtCreateSection failed %x\n", status );
1095 status = pNtCreateSection( &mapping, SECTION_QUERY | SECTION_MAP_READ, NULL,
1097 ok( status == STATUS_INVALID_FILE_FOR_SECTION, "NtCreateSection failed %x\n", status );
1098
1100 DeleteFileA(testfile);
1101}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_ADDRESS
Definition: compat.h:106
#define OPEN_EXISTING
Definition: compat.h:775
GLsizeiptr size
Definition: glext.h:5919
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
#define MAPPING_SIZE
Definition: virtual.c:26
#define todo_wine
Definition: custom.c:89
#define SEC_IMAGE
Definition: mmtypes.h:97
#define SEC_FILE
Definition: mmtypes.h:96
@ SectionBasicInformation
Definition: mmtypes.h:195
@ SectionImageInformation
Definition: mmtypes.h:196
#define MEM_FREE
Definition: nt_native.h:1317
#define MEM_DECOMMIT
Definition: nt_native.h:1315
#define MEM_RESET
Definition: nt_native.h:1320
#define SEC_RESERVE
Definition: nt_native.h:1323
@ ViewShare
Definition: nt_native.h:1278
#define STATUS_INVALID_VIEW_SIZE
Definition: ntstatus.h:268
#define STATUS_SECTION_NOT_IMAGE
Definition: ntstatus.h:309
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:539
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:269
#define STATUS_MAPPED_FILE_SIZE_ZERO
Definition: ntstatus.h:522
#define STATUS_SECTION_TOO_BIG
Definition: ntstatus.h:300
Definition: fci.c:127
Definition: name.c:39
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONGLONG QuadPart
Definition: typedefs.h:114
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106

Referenced by START_TEST().

◆ test_NtAreMappedFilesTheSame()

static void test_NtAreMappedFilesTheSame ( void  )
static

Definition at line 1312 of file virtual.c.

1313{
1314 static const char testfile[] = "testfile.xxx";
1315 HANDLE file, file2, mapping, map2;
1316 void *ptr, *ptr2;
1318 char path[MAX_PATH];
1319
1320 if (!pNtAreMappedFilesTheSame)
1321 {
1322 win_skip( "NtAreMappedFilesTheSame not available\n" );
1323 return;
1324 }
1325
1327 NULL, CREATE_ALWAYS, 0, 0 );
1328 ok( file != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
1330 SetEndOfFile( file );
1331
1333 ok( mapping != 0, "CreateFileMapping error %u\n", GetLastError() );
1334
1335 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
1336 ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
1337
1339 NULL, OPEN_EXISTING, 0, 0 );
1340 ok( file2 != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
1341
1342 map2 = CreateFileMappingA( file2, NULL, PAGE_READONLY, 0, 4096, NULL );
1343 ok( map2 != 0, "CreateFileMapping error %u\n", GetLastError() );
1344 ptr2 = MapViewOfFile( map2, FILE_MAP_READ, 0, 0, 4096 );
1345 ok( ptr2 != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
1346 status = pNtAreMappedFilesTheSame( ptr, ptr2 );
1347 ok( status == STATUS_NOT_SAME_DEVICE, "NtAreMappedFilesTheSame returned %x\n", status );
1348 UnmapViewOfFile( ptr2 );
1349
1350 ptr2 = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
1351 ok( ptr2 != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
1352 status = pNtAreMappedFilesTheSame( ptr, ptr2 );
1353 ok( status == STATUS_NOT_SAME_DEVICE, "NtAreMappedFilesTheSame returned %x\n", status );
1354 UnmapViewOfFile( ptr2 );
1355 CloseHandle( map2 );
1356
1357 map2 = CreateFileMappingA( file, NULL, PAGE_READONLY, 0, 4096, NULL );
1358 ok( map2 != 0, "CreateFileMapping error %u\n", GetLastError() );
1359 ptr2 = MapViewOfFile( map2, FILE_MAP_READ, 0, 0, 4096 );
1360 ok( ptr2 != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
1361 status = pNtAreMappedFilesTheSame( ptr, ptr2 );
1362 ok( status == STATUS_NOT_SAME_DEVICE, "NtAreMappedFilesTheSame returned %x\n", status );
1363 UnmapViewOfFile( ptr2 );
1364 CloseHandle( map2 );
1365 CloseHandle( file2 );
1366
1367 status = pNtAreMappedFilesTheSame( ptr, ptr );
1369 "NtAreMappedFilesTheSame returned %x\n", status );
1370
1371 status = pNtAreMappedFilesTheSame( ptr, (char *)ptr + 30 );
1373 "NtAreMappedFilesTheSame returned %x\n", status );
1374
1375 status = pNtAreMappedFilesTheSame( ptr, GetModuleHandleA("kernel32.dll") );
1376 ok( status == STATUS_NOT_SAME_DEVICE, "NtAreMappedFilesTheSame returned %x\n", status );
1377
1378 status = pNtAreMappedFilesTheSame( ptr, (void *)0xdeadbeef );
1380 "NtAreMappedFilesTheSame returned %x\n", status );
1381
1382 status = pNtAreMappedFilesTheSame( ptr, NULL );
1383 ok( status == STATUS_INVALID_ADDRESS, "NtAreMappedFilesTheSame returned %x\n", status );
1384
1385 status = pNtAreMappedFilesTheSame( ptr, (void *)GetProcessHeap() );
1386 ok( status == STATUS_CONFLICTING_ADDRESSES, "NtAreMappedFilesTheSame returned %x\n", status );
1387
1388 status = pNtAreMappedFilesTheSame( NULL, NULL );
1389 ok( status == STATUS_INVALID_ADDRESS, "NtAreMappedFilesTheSame returned %x\n", status );
1390
1391 ptr2 = VirtualAlloc( NULL, 0x10000, MEM_COMMIT, PAGE_READWRITE );
1392 ok( ptr2 != NULL, "VirtualAlloc error %u\n", GetLastError() );
1393 status = pNtAreMappedFilesTheSame( ptr, ptr2 );
1394 ok( status == STATUS_CONFLICTING_ADDRESSES, "NtAreMappedFilesTheSame returned %x\n", status );
1395 VirtualFree( ptr2, 0, MEM_RELEASE );
1396
1399 CloseHandle( file );
1400
1401 status = pNtAreMappedFilesTheSame( GetModuleHandleA("ntdll.dll"),
1402 GetModuleHandleA("kernel32.dll") );
1403 ok( status == STATUS_NOT_SAME_DEVICE, "NtAreMappedFilesTheSame returned %x\n", status );
1404 status = pNtAreMappedFilesTheSame( GetModuleHandleA("kernel32.dll"),
1405 GetModuleHandleA("kernel32.dll") );
1406 ok( status == STATUS_SUCCESS, "NtAreMappedFilesTheSame returned %x\n", status );
1407 status = pNtAreMappedFilesTheSame( GetModuleHandleA("kernel32.dll"),
1408 (char *)GetModuleHandleA("kernel32.dll") + 4096 );
1409 ok( status == STATUS_SUCCESS, "NtAreMappedFilesTheSame returned %x\n", status );
1410
1412 strcat( path, "\\kernel32.dll" );
1414 ok( file != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
1415
1417 ok( mapping != 0, "CreateFileMapping error %u\n", GetLastError() );
1418 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
1419 ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
1420 status = pNtAreMappedFilesTheSame( ptr, GetModuleHandleA("kernel32.dll") );
1421 ok( status == STATUS_NOT_SAME_DEVICE, "NtAreMappedFilesTheSame returned %x\n", status );
1424
1426 ok( mapping != 0, "CreateFileMapping error %u\n", GetLastError() );
1427 ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
1428 ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
1429 status = pNtAreMappedFilesTheSame( ptr, GetModuleHandleA("kernel32.dll") );
1430 todo_wine
1431 ok( status == STATUS_SUCCESS, "NtAreMappedFilesTheSame returned %x\n", status );
1432
1434 ok( file2 != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
1435 map2 = CreateFileMappingA( file2, NULL, PAGE_READONLY | SEC_IMAGE, 0, 0, NULL );
1436 ok( map2 != 0, "CreateFileMapping error %u\n", GetLastError() );
1437 ptr2 = MapViewOfFile( map2, FILE_MAP_READ, 0, 0, 0 );
1438 ok( ptr2 != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
1439 status = pNtAreMappedFilesTheSame( ptr, ptr2 );
1440 ok( status == STATUS_SUCCESS, "NtAreMappedFilesTheSame returned %x\n", status );
1441 UnmapViewOfFile( ptr2 );
1442 CloseHandle( map2 );
1443 CloseHandle( file2 );
1444
1447
1448 CloseHandle( file );
1449 DeleteFileA( testfile );
1450}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define GetProcessHeap()
Definition: compat.h:736
#define FILE_SHARE_READ
Definition: compat.h:136
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2283
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define STATUS_INVALID_ADDRESS
Definition: ntstatus.h:557
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
#define STATUS_NOT_SAME_DEVICE
Definition: ntstatus.h:448
#define win_skip
Definition: test.h:163
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by START_TEST().

◆ test_NtMapViewOfSection()

static void test_NtMapViewOfSection ( void  )
static

Definition at line 1103 of file virtual.c.

1104{
1106
1107 static const char testfile[] = "testfile.xxx";
1108 static const char data[] = "test data for NtMapViewOfSection";
1109 char buffer[sizeof(data)];
1111 void *ptr, *ptr2;
1112 BOOL is_wow64, ret;
1113 DWORD status, written;
1116
1117 if (!pNtMapViewOfSection || !pNtUnmapViewOfSection)
1118 {
1119 win_skip( "NtMapViewOfSection not available\n" );
1120 return;
1121 }
1122
1123 file = CreateFileA( testfile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1124 ok( file != INVALID_HANDLE_VALUE, "Failed to create test file\n" );
1125 WriteFile( file, data, sizeof(data), &written, NULL );
1127 SetEndOfFile( file );
1128
1129 /* read/write mapping */
1130
1132 ok( mapping != 0, "CreateFileMapping failed\n" );
1133
1135 ok(hProcess != NULL, "Can't start process\n");
1136
1137 ptr = NULL;
1138 size = 0;
1139 offset.QuadPart = 0;
1140 status = pNtMapViewOfSection( mapping, hProcess, &ptr, 0, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1141 ok( !status, "NtMapViewOfSection failed status %x\n", status );
1142 ok( !((ULONG_PTR)ptr & 0xffff), "returned memory %p is not aligned to 64k\n", ptr );
1143
1145 ok( ret, "ReadProcessMemory failed\n" );
1146 ok( result == sizeof(buffer), "ReadProcessMemory didn't read all data (%lx)\n", result );
1147 ok( !memcmp( buffer, data, sizeof(buffer) ), "Wrong data read\n" );
1148
1149 /* for some unknown reason NtMapViewOfSection fails with STATUS_NO_MEMORY when zero_bits != 0 ? */
1150 ptr2 = NULL;
1151 size = 0;
1152 offset.QuadPart = 0;
1153 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 12, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1154 todo_wine
1155 ok( status == STATUS_NO_MEMORY, "NtMapViewOfSection returned %x\n", status );
1156 if (status == STATUS_SUCCESS)
1157 {
1158 status = pNtUnmapViewOfSection( hProcess, ptr2 );
1159 ok( !status, "NtUnmapViewOfSection failed status %x\n", status );
1160 }
1161
1162 ptr2 = NULL;
1163 size = 0;
1164 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 16, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1165 todo_wine
1166 ok( status == STATUS_NO_MEMORY, "NtMapViewOfSection returned %x\n", status );
1167 if (status == STATUS_SUCCESS)
1168 {
1169 status = pNtUnmapViewOfSection( hProcess, ptr2 );
1170 ok( !status, "NtUnmapViewOfSection failed status %x\n", status );
1171 }
1172
1173 /* 22 zero bits isn't acceptable */
1174 ptr2 = NULL;
1175 size = 0;
1176 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 22, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1177 ok( status == STATUS_INVALID_PARAMETER_4, "NtMapViewOfSection returned %x\n", status );
1178 if (status == STATUS_SUCCESS)
1179 {
1180 status = pNtUnmapViewOfSection( hProcess, ptr2 );
1181 ok( !status, "NtUnmapViewOfSection failed status %x\n", status );
1182 }
1183
1184 /* mapping at the same page conflicts */
1185 ptr2 = ptr;
1186 size = 0;
1187 offset.QuadPart = 0;
1188 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1189 ok( status == STATUS_CONFLICTING_ADDRESSES, "NtMapViewOfSection returned %x\n", status );
1190
1191 /* offset has to be aligned */
1192 ptr2 = ptr;
1193 size = 0;
1194 offset.QuadPart = 1;
1195 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1196 ok( status == STATUS_MAPPED_ALIGNMENT, "NtMapViewOfSection returned %x\n", status );
1197
1198 /* ptr has to be aligned */
1199 ptr2 = (char *)ptr + 42;
1200 size = 0;
1201 offset.QuadPart = 0;
1202 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1203 ok( status == STATUS_MAPPED_ALIGNMENT, "NtMapViewOfSection returned %x\n", status );
1204
1205 /* still not 64k aligned */
1206 ptr2 = (char *)ptr + 0x1000;
1207 size = 0;
1208 offset.QuadPart = 0;
1209 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1210 ok( status == STATUS_MAPPED_ALIGNMENT, "NtMapViewOfSection returned %x\n", status );
1211
1212 /* zero_bits != 0 is not allowed when an address is set */
1213 ptr2 = (char *)ptr + 0x1000;
1214 size = 0;
1215 offset.QuadPart = 0;
1216 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 12, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1217 ok( status == STATUS_INVALID_PARAMETER_4, "NtMapViewOfSection returned %x\n", status );
1218
1219 ptr2 = (char *)ptr + 0x1000;
1220 size = 0;
1221 offset.QuadPart = 0;
1222 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 16, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1223 ok( status == STATUS_INVALID_PARAMETER_4, "NtMapViewOfSection returned %x\n", status );
1224
1225 ptr2 = (char *)ptr + 0x1001;
1226 size = 0;
1227 offset.QuadPart = 0;
1228 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 16, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1229 ok( status == STATUS_INVALID_PARAMETER_4, "NtMapViewOfSection returned %x\n", status );
1230
1231 ptr2 = (char *)ptr + 0x1000;
1232 size = 0;
1233 offset.QuadPart = 1;
1234 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 16, 0, &offset, &size, 1, 0, PAGE_READWRITE );
1235 ok( status == STATUS_INVALID_PARAMETER_4, "NtMapViewOfSection returned %x\n", status );
1236
1237 if (sizeof(void *) == sizeof(int) && (!pIsWow64Process ||
1238 !pIsWow64Process( GetCurrentProcess(), &is_wow64 ) || !is_wow64))
1239 {
1240 /* new memory region conflicts with previous mapping */
1241 ptr2 = ptr;
1242 size = 0;
1243 offset.QuadPart = 0;
1244 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset,
1246 ok( status == STATUS_CONFLICTING_ADDRESSES, "NtMapViewOfSection returned %x\n", status );
1247
1248 ptr2 = (char *)ptr + 42;
1249 size = 0;
1250 offset.QuadPart = 0;
1251 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset,
1253 ok( status == STATUS_CONFLICTING_ADDRESSES, "NtMapViewOfSection returned %x\n", status );
1254
1255 /* in contrary to regular NtMapViewOfSection, only 4kb align is enforced */
1256 ptr2 = (char *)ptr + 0x1000;
1257 size = 0;
1258 offset.QuadPart = 0;
1259 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset,
1261 ok( status == STATUS_SUCCESS, "NtMapViewOfSection returned %x\n", status );
1262 ok( (char *)ptr2 == (char *)ptr + 0x1000,
1263 "expected address %p, got %p\n", (char *)ptr + 0x1000, ptr2 );
1264 status = pNtUnmapViewOfSection( hProcess, ptr2 );
1265 ok( !status, "NtUnmapViewOfSection failed status %x\n", status );
1266
1267 /* the address is rounded down if not on a page boundary */
1268 ptr2 = (char *)ptr + 0x1001;
1269 size = 0;
1270 offset.QuadPart = 0;
1271 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset,
1273 ok( status == STATUS_SUCCESS, "NtMapViewOfSection returned %x\n", status );
1274 ok( (char *)ptr2 == (char *)ptr + 0x1000,
1275 "expected address %p, got %p\n", (char *)ptr + 0x1000, ptr2 );
1276 status = pNtUnmapViewOfSection( hProcess, ptr2 );
1277 ok( !status, "NtUnmapViewOfSection failed status %x\n", status );
1278
1279 ptr2 = (char *)ptr + 0x2000;
1280 size = 0;
1281 offset.QuadPart = 0;
1282 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset,
1284 ok( status == STATUS_SUCCESS, "NtMapViewOfSection returned %x\n", status );
1285 ok( (char *)ptr2 == (char *)ptr + 0x2000,
1286 "expected address %p, got %p\n", (char *)ptr + 0x2000, ptr2 );
1287 status = pNtUnmapViewOfSection( hProcess, ptr2 );
1288 ok( !status, "NtUnmapViewOfSection failed status %x\n", status );
1289 }
1290 else
1291 {
1292 ptr2 = (char *)ptr + 0x1000;
1293 size = 0;
1294 offset.QuadPart = 0;
1295 status = pNtMapViewOfSection( mapping, hProcess, &ptr2, 0, 0, &offset,
1297 todo_wine
1298 ok( status == STATUS_INVALID_PARAMETER_9, "NtMapViewOfSection returned %x\n", status );
1299 }
1300
1301 status = pNtUnmapViewOfSection( hProcess, ptr );
1302 ok( !status, "NtUnmapViewOfSection failed status %x\n", status );
1303
1305 CloseHandle( file );
1306 DeleteFileA( testfile );
1307
1310}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:758
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
BOOL is_wow64
Definition: msi.c:52
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint buffer
Definition: glext.h:5915
GLuint64EXT * result
Definition: glext.h:11304
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
static HANDLE create_target_process(const char *arg)
Definition: virtual.c:66
#define STATUS_MAPPED_ALIGNMENT
Definition: ntstatus.h:676
#define STATUS_INVALID_PARAMETER_9
Definition: ntstatus.h:483
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:478
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define AT_ROUND_TO_PAGE
Definition: winnt_old.h:590

Referenced by START_TEST().

◆ test_NtQuerySection()

static void test_NtQuerySection ( void  )
static

Definition at line 3880 of file virtual.c.

3881{
3882 char path[MAX_PATH];
3884 void *p;
3886 union
3887 {
3890 char buf[1024];
3891 } info;
3893 ULONG ret;
3895 SYSTEM_INFO si;
3896
3897 if (!pNtQuerySection)
3898 {
3899 win_skip("NtQuerySection is not available\n");
3900 return;
3901 }
3902
3903 GetSystemInfo(&si);
3904 page_mask = si.dwPageSize - 1;
3905
3906 GetSystemDirectoryA(path, sizeof(path));
3907 strcat(path, "\\kernel32.dll");
3908
3909 SetLastError(0xdeadbef);
3911 ok(file != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError());
3912
3914
3915 SetLastError(0xdeadbef);
3917 /* NT4 and win2k don't support EXEC on file mappings */
3918 if (!mapping)
3920 ok(mapping != 0, "CreateFileMapping error %u\n", GetLastError());
3921
3922 status = pNtQuerySection(mapping, SectionBasicInformation, NULL, sizeof(info), &ret);
3923 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %#x\n", status);
3924
3925 status = pNtQuerySection(mapping, SectionBasicInformation, &info, 0, NULL);
3926 ok(status == STATUS_INFO_LENGTH_MISMATCH, "expected STATUS_INFO_LENGTH_MISMATCH, got %#x\n", status);
3927
3928 status = pNtQuerySection(mapping, SectionBasicInformation, &info, 0, &ret);
3929 ok(status == STATUS_INFO_LENGTH_MISMATCH, "expected STATUS_INFO_LENGTH_MISMATCH, got %#x\n", status);
3930
3931 memset(&info, 0x55, sizeof(info));
3932 ret = 0xdeadbeef;
3933 status = pNtQuerySection(mapping, SectionBasicInformation, &info, sizeof(info), &ret);
3934 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
3935 ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
3936 ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
3937 ok(info.basic.Attributes == SEC_FILE, "expected SEC_FILE, got %#x\n", info.basic.Attributes);
3938 ok(info.basic.Size.QuadPart == fsize, "expected %#lx, got %#x/%08x\n", fsize, info.basic.Size.HighPart, info.basic.Size.LowPart);
3939
3940 status = pNtQuerySection(mapping, SectionImageInformation, &info, sizeof(info.basic), &ret);
3941 ok(status == STATUS_INFO_LENGTH_MISMATCH, "expected STATUS_INFO_LENGTH_MISMATCH, got %#x\n", status);
3942
3943 status = pNtQuerySection(mapping, SectionImageInformation, &info, sizeof(info), &ret);
3944 ok(status == STATUS_SECTION_NOT_IMAGE, "expected STATUS_SECTION_NOT_IMAGE, got %#x\n", status);
3945
3946 SetLastError(0xdeadbef);
3947 p = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
3948 ok(p != NULL, "MapViewOfFile error %u\n", GetLastError());
3949
3950 nt = image_nt_header(p);
3952
3953 memset(&info, 0x55, sizeof(info));
3954 ret = 0xdeadbeef;
3955 status = pNtQuerySection(mapping, SectionBasicInformation, &info, sizeof(info), &ret);
3956 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
3957 ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
3958 ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
3959 ok(info.basic.Attributes == SEC_FILE, "expected SEC_FILE, got %#x\n", info.basic.Attributes);
3960 ok(info.basic.Size.QuadPart == fsize, "expected %#lx, got %#x/%08x\n", fsize, info.basic.Size.HighPart, info.basic.Size.LowPart);
3961
3964
3965 SetLastError(0xdeadbef);
3967 /* NT4 and win2k don't support EXEC on file mappings */
3968 if (!mapping)
3970 ok(mapping != 0, "CreateFileMapping error %u\n", GetLastError());
3971
3972 memset(&info, 0x55, sizeof(info));
3973 ret = 0xdeadbeef;
3974 status = pNtQuerySection(mapping, SectionBasicInformation, &info, sizeof(info), &ret);
3975 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
3976 ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
3977 ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
3978 ok(info.basic.Attributes == (SEC_FILE|SEC_IMAGE), "expected SEC_FILE|SEC_IMAGE, got %#x\n", info.basic.Attributes);
3979 ok(info.basic.Size.QuadPart == image_size, "expected %#lx, got %#x/%08x\n", image_size, info.basic.Size.HighPart, info.basic.Size.LowPart);
3980
3981 status = pNtQuerySection(mapping, SectionImageInformation, NULL, sizeof(info), &ret);
3982 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %#x\n", status);
3983
3984 status = pNtQuerySection(mapping, SectionImageInformation, &info, 0, NULL);
3985 ok(status == STATUS_INFO_LENGTH_MISMATCH, "expected STATUS_INFO_LENGTH_MISMATCH, got %#x\n", status);
3986
3987 status = pNtQuerySection(mapping, SectionImageInformation, &info, 0, &ret);
3988 ok(status == STATUS_INFO_LENGTH_MISMATCH, "expected STATUS_INFO_LENGTH_MISMATCH, got %#x\n", status);
3989
3990 status = pNtQuerySection(mapping, SectionImageInformation, &info, sizeof(info.basic), &ret);
3991 ok(status == STATUS_INFO_LENGTH_MISMATCH, "expected STATUS_INFO_LENGTH_MISMATCH, got %#x\n", status);
3992
3993 SetLastError(0xdeadbef);
3994 p = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
3995 ok(p != NULL, "MapViewOfFile error %u\n", GetLastError());
3996
3997 nt = image_nt_header(p);
3998
3999 memset(&info, 0x55, sizeof(info));
4000 ret = 0xdeadbeef;
4001 status = pNtQuerySection(mapping, SectionImageInformation, &info, sizeof(info), &ret);
4002 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
4003 ok(ret == sizeof(info.image), "wrong returned size %u\n", ret);
4005 "expected %#lx, got %p\n", (SIZE_T)(nt->OptionalHeader.ImageBase + nt->OptionalHeader.AddressOfEntryPoint), info.image.TransferAddress);
4006 ok(info.image.ZeroBits == 0, "expected 0, got %#x\n", info.image.ZeroBits);
4007 ok(info.image.MaximumStackSize == nt->OptionalHeader.SizeOfStackReserve, "expected %#lx, got %#lx\n", (SIZE_T)nt->OptionalHeader.SizeOfStackReserve, info.image.MaximumStackSize);
4008 ok(info.image.CommittedStackSize == nt->OptionalHeader.SizeOfStackCommit, "expected %#lx, got %#lx\n", (SIZE_T)nt->OptionalHeader.SizeOfStackCommit, info.image.CommittedStackSize);
4009 ok(info.image.SubSystemType == nt->OptionalHeader.Subsystem, "expected %#x, got %#x\n", nt->OptionalHeader.Subsystem, info.image.SubSystemType);
4010 ok(info.image.SubsystemVersionLow == nt->OptionalHeader.MinorSubsystemVersion, "expected %#x, got %#x\n", nt->OptionalHeader.MinorSubsystemVersion, info.image.SubsystemVersionLow);
4011 ok(info.image.SubsystemVersionHigh == nt->OptionalHeader.MajorSubsystemVersion, "expected %#x, got %#x\n", nt->OptionalHeader.MajorSubsystemVersion, info.image.SubsystemVersionHigh);
4012 ok(info.image.ImageCharacteristics == nt->FileHeader.Characteristics, "expected %#x, got %#x\n", nt->FileHeader.Characteristics, info.image.ImageCharacteristics);
4013 ok(info.image.DllCharacteristics == nt->OptionalHeader.DllCharacteristics, "expected %#x, got %#x\n", nt->OptionalHeader.DllCharacteristics, info.image.DllCharacteristics);
4014 ok(info.image.Machine == nt->FileHeader.Machine, "expected %#x, got %#x\n", nt->FileHeader.Machine, info.image.Machine);
4016 ok(info.image.ImageContainsCode == TRUE, "expected 1, got %#x\n", info.image.ImageContainsCode);
4017
4018 memset(&info, 0x55, sizeof(info));
4019 ret = 0xdeadbeef;
4020 status = pNtQuerySection(mapping, SectionBasicInformation, &info, sizeof(info), &ret);
4021 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
4022 ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
4023 ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
4024 ok(info.basic.Attributes == (SEC_FILE|SEC_IMAGE), "expected SEC_FILE|SEC_IMAGE, got %#x\n", info.basic.Attributes);
4025 ok(info.basic.Size.QuadPart == image_size, "expected %#lx, got %#x/%08x\n", image_size, info.basic.Size.HighPart, info.basic.Size.LowPart);
4026
4029
4030 SetLastError(0xdeadbef);
4032 ok(mapping != 0, "CreateFileMapping error %u\n", GetLastError());
4033
4034 memset(&info, 0x55, sizeof(info));
4035 ret = 0xdeadbeef;
4036 status = pNtQuerySection(mapping, SectionBasicInformation, &info, sizeof(info), &ret);
4037 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
4038 ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
4039 ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
4041 ok(info.basic.Attributes == SEC_FILE, "expected SEC_FILE, got %#x\n", info.basic.Attributes);
4042 ok(info.basic.Size.QuadPart == fsize, "expected %#lx, got %#x/%08x\n", fsize, info.basic.Size.HighPart, info.basic.Size.LowPart);
4043
4045
4046 SetLastError(0xdeadbef);
4048 ok(mapping != 0, "CreateFileMapping error %u\n", GetLastError());
4049
4050 memset(&info, 0x55, sizeof(info));
4051 ret = 0xdeadbeef;
4052 status = pNtQuerySection(mapping, SectionBasicInformation, &info, sizeof(info), &ret);
4053 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
4054 ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
4055 ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
4056 ok(info.basic.Attributes == SEC_FILE, "expected SEC_FILE, got %#x\n", info.basic.Attributes);
4057 ok(info.basic.Size.QuadPart == fsize, "expected %#lx, got %#x/%08x\n", fsize, info.basic.Size.HighPart, info.basic.Size.LowPart);
4058
4061
4062 SetLastError(0xdeadbef);
4064 ok(mapping != 0, "CreateFileMapping error %u\n", GetLastError());
4065
4066 memset(&info, 0x55, sizeof(info));
4067 ret = 0xdeadbeef;
4068 status = pNtQuerySection(mapping, SectionBasicInformation, &info, sizeof(info), &ret);
4069 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
4070 ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
4071 ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
4072 ok(info.basic.Attributes == SEC_COMMIT, "expected SEC_COMMIT, got %#x\n", info.basic.Attributes);
4073 ok(info.basic.Size.QuadPart == 4096, "expected 4096, got %#x/%08x\n", info.basic.Size.HighPart, info.basic.Size.LowPart);
4074
4075 SetLastError(0xdeadbef);
4077 ok(p != NULL, "MapViewOfFile error %u\n", GetLastError());
4078
4079 memset(&info, 0x55, sizeof(info));
4080 ret = 0xdeadbeef;
4081 status = pNtQuerySection(mapping, SectionBasicInformation, &info, sizeof(info), &ret);
4082 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
4083 ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
4084 ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
4085 ok(info.basic.Attributes == SEC_COMMIT, "expected SEC_COMMIT, got %#x\n", info.basic.Attributes);
4086 ok(info.basic.Size.QuadPart == 4096, "expected 4096, got %#x/%08x\n", info.basic.Size.HighPart, info.basic.Size.LowPart);
4087
4090
4091 SetLastError(0xdeadbef);
4093 ok(mapping != 0, "CreateFileMapping error %u\n", GetLastError());
4094
4095 memset(&info, 0x55, sizeof(info));
4096 ret = 0xdeadbeef;
4097 status = pNtQuerySection(mapping, SectionBasicInformation, &info, sizeof(info), &ret);
4098 ok(status == STATUS_SUCCESS, "NtQuerySection error %#x\n", status);
4099 ok(ret == sizeof(info.basic), "wrong returned size %u\n", ret);
4100 ok(info.basic.BaseAddress == NULL, "expected NULL, got %p\n", info.basic.BaseAddress);
4101 ok(info.basic.Attributes == SEC_RESERVE, "expected SEC_RESERVE, got %#x\n", info.basic.Attributes);
4102 ok(info.basic.Size.QuadPart == 4096, "expected 4096, got %#x/%08x\n", info.basic.Size.HighPart, info.basic.Size.LowPart);
4103
4105}
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
GLeglImageOES image
Definition: gl.h:2204
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat p
Definition: glext.h:8902
GLint fsize
Definition: glext.h:9408
static GLint image_size(GLint width, GLint height, GLenum format, GLenum type)
Definition: mipmap.c:4858
IMAGE_NT_HEADERS nt
Definition: module.c:50
#define ROUND_SIZE(addr, size)
Definition: virtual.c:50
static PIMAGE_NT_HEADERS image_nt_header(HMODULE module)
Definition: virtual.c:53
static UINT_PTR page_mask
Definition: virtual.c:49
#define SEC_NOCACHE
Definition: mmtypes.h:101
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define memset(x, y, z)
Definition: compat.h:39
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183

Referenced by START_TEST().

◆ test_shared_memory()

static void test_shared_memory ( BOOL  is_child)
static

Definition at line 3793 of file virtual.c.

3794{
3796 LONG *p;
3797
3798 SetLastError(0xdeadbef);
3799 mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4096, "winetest_virtual.c");
3800 ok(mapping != 0, "CreateFileMapping error %d\n", GetLastError());
3801 if (is_child)
3802 ok(GetLastError() == ERROR_ALREADY_EXISTS, "expected ERROR_ALREADY_EXISTS, got %d\n", GetLastError());
3803
3804 SetLastError(0xdeadbef);
3806 ok(p != NULL, "MapViewOfFile error %d\n", GetLastError());
3807
3808 if (is_child)
3809 {
3810 ok(*p == 0x1a2b3c4d, "expected 0x1a2b3c4d in child, got %#x\n", *p);
3811 }
3812 else
3813 {
3814 char **argv;
3815 char cmdline[MAX_PATH];
3817 STARTUPINFOA si = { sizeof(si) };
3818 DWORD ret;
3819
3820 *p = 0x1a2b3c4d;
3821
3823 sprintf(cmdline, "\"%s\" virtual sharedmem", argv[0]);
3824 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
3825 ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
3827 CloseHandle(pi.hThread);
3828 CloseHandle(pi.hProcess);
3829 }
3830
3833}
long LONG
Definition: pedump.c:60
void winetest_wait_child_process(HANDLE process)

Referenced by START_TEST().

◆ test_shared_memory_ro()

static void test_shared_memory_ro ( BOOL  is_child,
DWORD  child_access 
)
static

Definition at line 3835 of file virtual.c.

3836{
3838 LONG *p;
3839
3840 SetLastError(0xdeadbef);
3841 mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4096, "winetest_virtual.c_ro");
3842 ok(mapping != 0, "CreateFileMapping error %d\n", GetLastError());
3843 if (is_child)
3844 ok(GetLastError() == ERROR_ALREADY_EXISTS, "expected ERROR_ALREADY_EXISTS, got %d\n", GetLastError());
3845
3846 SetLastError(0xdeadbef);
3847 p = MapViewOfFile(mapping, is_child ? child_access : FILE_MAP_READ, 0, 0, 4096);
3848 ok(p != NULL, "MapViewOfFile error %d\n", GetLastError());
3849
3850 if (is_child)
3851 {
3852 *p = 0xdeadbeef;
3853 }
3854 else
3855 {
3856 char **argv;
3857 char cmdline[MAX_PATH];
3859 STARTUPINFOA si = { sizeof(si) };
3860 DWORD ret;
3861
3863 sprintf(cmdline, "\"%s\" virtual sharedmemro %x", argv[0], child_access);
3864 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
3865 ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
3867 CloseHandle(pi.hThread);
3868 CloseHandle(pi.hProcess);
3869
3870 if(child_access & FILE_MAP_WRITE)
3871 ok(*p == 0xdeadbeef, "*p = %x, expected 0xdeadbeef\n", *p);
3872 else
3873 ok(!*p, "*p = %x, expected 0\n", *p);
3874 }
3875
3878}

Referenced by START_TEST().

◆ test_VirtualAlloc()

static void test_VirtualAlloc ( void  )
static

Definition at line 234 of file virtual.c.

235{
236 void *addr1, *addr2;
237 DWORD old_prot;
240 SIZE_T size;
241
242 SetLastError(0xdeadbeef);
243 addr1 = VirtualAlloc(0, 0, MEM_RESERVE, PAGE_NOACCESS);
244 ok(addr1 == NULL, "VirtualAlloc should fail on zero-sized allocation\n");
246 "got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
247
248 addr1 = VirtualAlloc(0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
249 ok(addr1 != NULL, "VirtualAlloc failed\n");
250
251 /* test a not committed memory */
252 ok(VirtualQuery(addr1, &info, sizeof(info)) == sizeof(info),
253 "VirtualQuery failed\n");
254 ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
255 ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
256 ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
257 ok(info.RegionSize == 0x10000, "%lx != 0x10000\n", info.RegionSize);
258 ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
259 ok(info.Protect == 0, "%x != PAGE_NOACCESS\n", info.Protect);
260 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
261
262 SetLastError(0xdeadbeef);
263 ok(!VirtualProtect(addr1, 0xFFFC, PAGE_READONLY, &old_prot),
264 "VirtualProtect should fail on a not committed memory\n");
266 "got %d, expected ERROR_INVALID_ADDRESS\n", GetLastError());
267
268 addr2 = VirtualAlloc(addr1, 0x1000, MEM_COMMIT, PAGE_NOACCESS);
269 ok(addr1 == addr2, "VirtualAlloc failed\n");
270
271 /* test a committed memory */
272 ok(VirtualQuery(addr1, &info, sizeof(info)) == sizeof(info),
273 "VirtualQuery failed\n");
274 ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
275 ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
276 ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
277 ok(info.RegionSize == 0x1000, "%lx != 0x1000\n", info.RegionSize);
278 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
279 /* this time NT reports PAGE_NOACCESS as well */
280 ok(info.Protect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.Protect);
281 ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
282
283 /* this should fail, since not the whole range is committed yet */
284 SetLastError(0xdeadbeef);
285 ok(!VirtualProtect(addr1, 0xFFFC, PAGE_READONLY, &old_prot),
286 "VirtualProtect should fail on a not committed memory\n");
288 "got %d, expected ERROR_INVALID_ADDRESS\n", GetLastError());
289
290 ok(VirtualProtect(addr1, 0x1000, PAGE_READONLY, &old_prot), "VirtualProtect failed\n");
291 ok(old_prot == PAGE_NOACCESS,
292 "wrong old protection: got %04x instead of PAGE_NOACCESS\n", old_prot);
293
294 ok(VirtualProtect(addr1, 0x1000, PAGE_READWRITE, &old_prot), "VirtualProtect failed\n");
295 ok(old_prot == PAGE_READONLY,
296 "wrong old protection: got %04x instead of PAGE_READONLY\n", old_prot);
297
298 ok(VirtualQuery(addr1, &info, sizeof(info)) == sizeof(info),
299 "VirtualQuery failed\n");
300 ok(info.RegionSize == 0x1000, "%lx != 0x1000\n", info.RegionSize);
301 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
302 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
303 memset( addr1, 0x55, 20 );
304 ok( *(DWORD *)addr1 == 0x55555555, "wrong data %x\n", *(DWORD *)addr1 );
305
306 addr2 = VirtualAlloc( addr1, 0x1000, MEM_RESET, PAGE_NOACCESS );
307 ok( addr2 == addr1, "VirtualAlloc failed err %u\n", GetLastError() );
308 ok( *(DWORD *)addr1 == 0x55555555 || *(DWORD *)addr1 == 0, "wrong data %x\n", *(DWORD *)addr1 );
309 ok(VirtualQuery(addr1, &info, sizeof(info)) == sizeof(info),
310 "VirtualQuery failed\n");
311 ok(info.RegionSize == 0x1000, "%lx != 0x1000\n", info.RegionSize);
312 ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
313 ok(info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect);
314
315 addr2 = VirtualAlloc( (char *)addr1 + 0x1000, 0x1000, MEM_RESET, PAGE_NOACCESS );
316 ok( (char *)addr2 == (char *)addr1 + 0x1000, "VirtualAlloc failed\n" );
317
318 ok(VirtualQuery(addr2, &info, sizeof(info)) == sizeof(info),
319 "VirtualQuery failed\n");
320 ok(info.RegionSize == 0xf000, "%lx != 0xf000\n", info.RegionSize);
321 ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
322 ok(info.Protect == 0, "%x != 0\n", info.Protect);
323
324 addr2 = VirtualAlloc( (char *)addr1 + 0xf000, 0x2000, MEM_RESET, PAGE_NOACCESS );
325 ok( !addr2, "VirtualAlloc failed\n" );
326 ok( GetLastError() == ERROR_INVALID_ADDRESS, "wrong error %u\n", GetLastError() );
327
328 /* invalid protection values */
329 SetLastError(0xdeadbeef);
330 addr2 = VirtualAlloc(NULL, 0x1000, MEM_RESERVE, 0);
331 ok(!addr2, "VirtualAlloc succeeded\n");
332 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
333
334 SetLastError(0xdeadbeef);
335 addr2 = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, 0);
336 ok(!addr2, "VirtualAlloc succeeded\n");
337 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
338
339 SetLastError(0xdeadbeef);
340 addr2 = VirtualAlloc(addr1, 0x1000, MEM_COMMIT, PAGE_READONLY | PAGE_EXECUTE);
341 ok(!addr2, "VirtualAlloc succeeded\n");
342 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
343
344 SetLastError(0xdeadbeef);
345 ok(!VirtualProtect(addr1, 0x1000, PAGE_READWRITE | PAGE_EXECUTE_WRITECOPY, &old_prot),
346 "VirtualProtect succeeded\n");
347 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
348
349 SetLastError(0xdeadbeef);
350 ok(!VirtualProtect(addr1, 0x1000, 0, &old_prot), "VirtualProtect succeeded\n");
351 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
352
353 SetLastError(0xdeadbeef);
354 ok(!VirtualFree(addr1, 0x10000, 0), "VirtualFree should fail with type 0\n");
356 "got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
357
358 SetLastError(0xdeadbeef);
359 ok(!VirtualFree(addr1, 0, MEM_FREE), "VirtualFree should fail with type MEM_FREE\n");
361 "got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
362
363 ok(VirtualFree(addr1, 0x10000, MEM_DECOMMIT), "VirtualFree failed\n");
364
365 /* if the type is MEM_RELEASE, size must be 0 */
366 ok(!VirtualFree(addr1, 1, MEM_RELEASE), "VirtualFree should fail\n");
368 "got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
369
370 ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
371
372 /* memory returned by VirtualAlloc should be aligned to 64k */
374 ok(addr1 != NULL, "VirtualAlloc failed\n");
375 ok(!((ULONG_PTR)addr1 & 0xffff), "returned memory %p is not aligned to 64k\n", addr1);
376 ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
378 ok(addr2 == addr1, "VirtualAlloc returned %p, expected %p\n", addr2, addr1);
379
380 /* allocation conflicts because of 64k align */
381 size = 0x1000;
382 addr2 = (char *)addr1 + 0x1000;
383 status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 0, &size,
385 ok(status == STATUS_CONFLICTING_ADDRESSES, "NtAllocateVirtualMemory returned %08x\n", status);
386
387 /* it should conflict, even when zero_bits is explicitly set */
388 size = 0x1000;
389 addr2 = (char *)addr1 + 0x1000;
390 status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 12, &size,
393 ok(status == STATUS_CONFLICTING_ADDRESSES, "NtAllocateVirtualMemory returned %08x\n", status);
394 if (status == STATUS_SUCCESS) ok(VirtualFree(addr2, 0, MEM_RELEASE), "VirtualFree failed\n");
395
396 /* 21 zero bits is valid */
397 size = 0x1000;
398 addr2 = NULL;
399 status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 21, &size,
402 "NtAllocateVirtualMemory returned %08x\n", status);
403 if (status == STATUS_SUCCESS) ok(VirtualFree(addr2, 0, MEM_RELEASE), "VirtualFree failed\n");
404
405 /* 22 zero bits is invalid */
406 size = 0x1000;
407 addr2 = NULL;
408 status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 22, &size,
410 ok(status == STATUS_INVALID_PARAMETER_3, "NtAllocateVirtualMemory returned %08x\n", status);
411 if (status == STATUS_SUCCESS) ok(VirtualFree(addr2, 0, MEM_RELEASE), "VirtualFree failed\n");
412
413 /* AT_ROUND_TO_PAGE flag is not supported for VirtualAlloc */
414 SetLastError(0xdeadbeef);
416 ok(!addr2, "VirtualAlloc unexpectedly succeeded\n");
417 ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
418
419 /* AT_ROUND_TO_PAGE flag is not supported for NtAllocateVirtualMemory */
420 size = 0x1000;
421 addr2 = (char *)addr1 + 0x1000;
422 status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 0, &size, MEM_RESERVE |
425 ok(status == STATUS_INVALID_PARAMETER_5, "NtAllocateVirtualMemory returned %08x\n", status);
426
427 ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
428}
#define MEM_PRIVATE
Definition: nt_native.h:1318
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
#define STATUS_INVALID_PARAMETER_5
Definition: ntstatus.h:479

Referenced by START_TEST().

◆ test_VirtualAlloc_protection()

static void test_VirtualAlloc_protection ( void  )
static

Definition at line 3074 of file virtual.c.

3075{
3076 static const struct test_data
3077 {
3078 DWORD prot;
3079 BOOL success;
3080 } td[] =
3081 {
3082 { 0, FALSE }, /* 0x00 */
3083 { PAGE_NOACCESS, TRUE }, /* 0x01 */
3084 { PAGE_READONLY, TRUE }, /* 0x02 */
3085 { PAGE_READONLY | PAGE_NOACCESS, FALSE }, /* 0x03 */
3086 { PAGE_READWRITE, TRUE }, /* 0x04 */
3087 { PAGE_READWRITE | PAGE_NOACCESS, FALSE }, /* 0x05 */
3088 { PAGE_READWRITE | PAGE_READONLY, FALSE }, /* 0x06 */
3089 { PAGE_READWRITE | PAGE_READONLY | PAGE_NOACCESS, FALSE }, /* 0x07 */
3090 { PAGE_WRITECOPY, FALSE }, /* 0x08 */
3091 { PAGE_WRITECOPY | PAGE_NOACCESS, FALSE }, /* 0x09 */
3092 { PAGE_WRITECOPY | PAGE_READONLY, FALSE }, /* 0x0a */
3093 { PAGE_WRITECOPY | PAGE_NOACCESS | PAGE_READONLY, FALSE }, /* 0x0b */
3094 { PAGE_WRITECOPY | PAGE_READWRITE, FALSE }, /* 0x0c */
3098
3099 { PAGE_EXECUTE, TRUE }, /* 0x10 */
3100 { PAGE_EXECUTE_READ, TRUE }, /* 0x20 */
3101 { PAGE_EXECUTE_READ | PAGE_EXECUTE, FALSE }, /* 0x30 */
3102 { PAGE_EXECUTE_READWRITE, TRUE }, /* 0x40 */
3103 { PAGE_EXECUTE_READWRITE | PAGE_EXECUTE, FALSE }, /* 0x50 */
3106 { PAGE_EXECUTE_WRITECOPY, FALSE }, /* 0x80 */
3107 { PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE, FALSE }, /* 0x90 */
3114 };
3115 char *base, *ptr;
3116 DWORD ret, i;
3118 SYSTEM_INFO si;
3119
3120 GetSystemInfo(&si);
3121 trace("system page size %#x\n", si.dwPageSize);
3122
3123 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
3124 {
3125 SetLastError(0xdeadbeef);
3126 base = VirtualAlloc(0, si.dwPageSize, MEM_COMMIT, td[i].prot);
3127
3128 if (td[i].success)
3129 {
3130 ok(base != NULL, "%d: VirtualAlloc failed %d\n", i, GetLastError());
3131
3132 SetLastError(0xdeadbeef);
3133 ret = VirtualQuery(base, &info, sizeof(info));
3134 ok(ret, "VirtualQuery failed %d\n", GetLastError());
3135 ok(info.BaseAddress == base, "%d: got %p != expected %p\n", i, info.BaseAddress, base);
3136 ok(info.RegionSize == si.dwPageSize, "%d: got %#lx != expected %#x\n", i, info.RegionSize, si.dwPageSize);
3137 ok(info.Protect == td[i].prot, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].prot);
3138 ok(info.AllocationBase == base, "%d: %p != %p\n", i, info.AllocationBase, base);
3139 ok(info.AllocationProtect == td[i].prot, "%d: %#x != %#x\n", i, info.AllocationProtect, td[i].prot);
3140 ok(info.State == MEM_COMMIT, "%d: %#x != MEM_COMMIT\n", i, info.State);
3141 ok(info.Type == MEM_PRIVATE, "%d: %#x != MEM_PRIVATE\n", i, info.Type);
3142
3143 if (is_mem_writable(info.Protect))
3144 {
3145 base[0] = 0xfe;
3146
3147 SetLastError(0xdeadbeef);
3148 ret = VirtualQuery(base, &info, sizeof(info));
3149 ok(ret, "VirtualQuery failed %d\n", GetLastError());
3150 ok(info.Protect == td[i].prot, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].prot);
3151 }
3152
3153 SetLastError(0xdeadbeef);
3154 ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, td[i].prot);
3155 ok(ptr == base, "%d: VirtualAlloc failed %d\n", i, GetLastError());
3156
3158 }
3159 else
3160 {
3161 ok(!base, "%d: VirtualAlloc should fail\n", i);
3162 ok(GetLastError() == ERROR_INVALID_PARAMETER, "%d: expected ERROR_INVALID_PARAMETER, got %d\n",