ReactOS  0.4.14-dev-55-g2da92ac
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);
77  ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
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 CloseHandle
Definition: compat.h:398
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
TCHAR * cmdline
Definition: stretchblt.cpp:32
#define argv
Definition: mplay32.c:18
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
DWORD cb
Definition: winbase.h:796
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:4742
#define MAX_PATH
Definition: compat.h:26
int winetest_get_mainargs(char ***pargv)
static DWORD pi
Definition: protocol.c:150
int ret
#define ok(value,...)
Definition: atltest.h:57

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 }
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
smooth NULL
Definition: ftsmooth.c:416
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
int ret
IMAGE_DOS_HEADER dos
Definition: module.c:49

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 }
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SECTION_MAP_READ
Definition: compat.h:128
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
unsigned long DWORD
Definition: ntddk_ex.h:95

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 TRUE
Definition: types.h:120
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define PAGE_READWRITE
Definition: nt_native.h:1304

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 SECTION_QUERY
Definition: nt_native.h:1287
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_EXECUTE
Definition: nt_native.h:1306
#define SECTION_MAP_WRITE
Definition: nt_native.h:1288
#define SECTION_MAP_READ
Definition: compat.h:128
#define PAGE_READONLY
Definition: compat.h:127
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
#define SECTION_MAP_EXECUTE
Definition: nt_native.h:1290
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define SECTION_MAP_EXECUTE_EXPLICIT
Definition: mmtypes.h:51
#define PAGE_READWRITE
Definition: nt_native.h:1304

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 {
3496  NTSTATUS status;
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;
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 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
LONG NTSTATUS
Definition: precomp.h:26
GLintptr offset
Definition: glext.h:5920
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
#define PAGE_NOACCESS
Definition: nt_native.h:1302
smooth NULL
Definition: ftsmooth.c:416
#define FILE_MAP_READ
Definition: compat.h:427
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
#define FILE_MAP_WRITE
Definition: winbase.h:154
#define SetLastError(x)
Definition: compat.h:409
GLenum const GLvoid * addr
Definition: glext.h:9621
#define FILE_MAP_COPY
Definition: winbase.h:153
ULONG_PTR SIZE_T
Definition: typedefs.h:78
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define PAGE_READONLY
Definition: compat.h:127
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
unsigned int ULONG
Definition: retypes.h:1
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define FILE_MAP_EXECUTE
Definition: winbase.h:157
static SERVICE_STATUS status
Definition: service.c:31
#define PAGE_READWRITE
Definition: nt_native.h:1304
Definition: ps.c:97

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_EXECUTE
Definition: virtual.c:3421
#define ACCESS_WRITE
Definition: virtual.c:3420
#define PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
#define PAGE_EXECUTE
Definition: nt_native.h:1306
#define ACCESS_READ
Definition: virtual.c:3419
#define PAGE_READONLY
Definition: compat.h:127
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define PAGE_READWRITE
Definition: nt_native.h:1304

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 (argc >= 3)
4114  {
4115  if (!strcmp(argv[2], "sleep"))
4116  {
4117  Sleep(5000); /* spawned process runs for at most 5 seconds */
4118  return;
4119  }
4120  if (!strcmp(argv[2], "sharedmem"))
4121  {
4123  return;
4124  }
4125  if (!strcmp(argv[2], "sharedmemro"))
4126  {
4128  return;
4129  }
4130  while (1)
4131  {
4132  void *mem;
4133  BOOL ret;
4136  ok(mem != NULL, "VirtualAlloc failed %u\n", GetLastError());
4137  if (mem == NULL) break;
4138  ret = VirtualFree(mem, 0, MEM_RELEASE);
4139  ok(ret, "VirtualFree failed %u\n", GetLastError());
4140  if (!ret) break;
4141  }
4142  return;
4143  }
4144 
4145  hkernel32 = GetModuleHandleA("kernel32.dll");
4146  hntdll = GetModuleHandleA("ntdll.dll");
4147 
4148  pVirtualAllocEx = (void *) GetProcAddress(hkernel32, "VirtualAllocEx");
4149  pVirtualFreeEx = (void *) GetProcAddress(hkernel32, "VirtualFreeEx");
4150  pGetWriteWatch = (void *) GetProcAddress(hkernel32, "GetWriteWatch");
4151  pResetWriteWatch = (void *) GetProcAddress(hkernel32, "ResetWriteWatch");
4152  pGetProcessDEPPolicy = (void *)GetProcAddress( hkernel32, "GetProcessDEPPolicy" );
4153  pIsWow64Process = (void *)GetProcAddress( hkernel32, "IsWow64Process" );
4154  pNtAreMappedFilesTheSame = (void *)GetProcAddress( hntdll, "NtAreMappedFilesTheSame" );
4155  pNtCreateSection = (void *)GetProcAddress( hntdll, "NtCreateSection" );
4156  pNtMapViewOfSection = (void *)GetProcAddress( hntdll, "NtMapViewOfSection" );
4157  pNtUnmapViewOfSection = (void *)GetProcAddress( hntdll, "NtUnmapViewOfSection" );
4158  pNtQuerySection = (void *)GetProcAddress( hntdll, "NtQuerySection" );
4159  pRtlAddVectoredExceptionHandler = (void *)GetProcAddress( hntdll, "RtlAddVectoredExceptionHandler" );
4160  pRtlRemoveVectoredExceptionHandler = (void *)GetProcAddress( hntdll, "RtlRemoveVectoredExceptionHandler" );
4161  pNtProtectVirtualMemory = (void *)GetProcAddress( hntdll, "NtProtectVirtualMemory" );
4162  pNtAllocateVirtualMemory = (void *)GetProcAddress( hntdll, "NtAllocateVirtualMemory" );
4163  pNtFreeVirtualMemory = (void *)GetProcAddress( hntdll, "NtFreeVirtualMemory" );
4164 
4169  test_mapping();
4183  test_write_watch();
4184 #if defined(__i386__) || defined(__x86_64__)
4185  test_stack_commit();
4186 #endif
4187 #ifdef __i386__
4188  test_guard_page();
4189  /* The following tests should be executed as a last step, and in exactly this
4190  * order, since ATL thunk emulation cannot be enabled anymore on Windows. */
4191  test_atl_thunk_emulation( MEM_EXECUTE_OPTION_ENABLE );
4192  test_atl_thunk_emulation( MEM_EXECUTE_OPTION_DISABLE );
4194 #endif
4195 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
static void test_NtMapViewOfSection(void)
Definition: virtual.c:1103
static void test_IsBadReadPtr(void)
Definition: virtual.c:1491
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define argv
Definition: mplay32.c:18
static void test_write_watch(void)
Definition: virtual.c:1557
#define MEM_COMMIT
Definition: nt_native.h:1313
static HINSTANCE hntdll
Definition: virtual.c:28
static void test_MapViewOfFile(void)
Definition: virtual.c:430
static HINSTANCE hkernel32
Definition: virtual.c:28
static void test_shared_memory_ro(BOOL is_child, DWORD child_access)
Definition: virtual.c:3835
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:74
unsigned int BOOL
Definition: ntddk_ex.h:94
static void test_VirtualAlloc(void)
Definition: virtual.c:234
#define MEM_RESERVE
Definition: nt_native.h:1314
smooth NULL
Definition: ftsmooth.c:416
static void test_CreateFileMapping(void)
Definition: virtual.c:1452
#define FILE_MAP_READ
Definition: compat.h:427
static void test_IsBadCodePtr(void)
Definition: virtual.c:1541
static void test_VirtualProtect(void)
Definition: virtual.c:2878
#define MEM_EXECUTE_OPTION_ENABLE
Definition: mmtypes.h:74
static void test_VirtualAlloc_protection(void)
Definition: virtual.c:3074
static void test_NtAreMappedFilesTheSame(void)
Definition: virtual.c:1312
static void test_mapping(void)
Definition: virtual.c:3547
#define FILE_MAP_WRITE
Definition: winbase.h:154
int winetest_get_mainargs(char ***pargv)
int ret
#define FILE_MAP_COPY
Definition: winbase.h:153
static void test_CreateFileMapping_protection(void)
Definition: virtual.c:3167
static void test_IsBadWritePtr(void)
Definition: virtual.c:1516
static void test_shared_memory(BOOL is_child)
Definition: virtual.c:3793
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define MEM_EXECUTE_OPTION_DISABLE
Definition: mmtypes.h:73
#define MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION
Definition: mmtypes.h:75
#define ok(value,...)
Definition: atltest.h:57
static void test_NtQuerySection(void)
Definition: virtual.c:3880
Definition: mem.c:156
#define MEM_RELEASE
Definition: nt_native.h:1316
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define GetProcAddress(x, y)
Definition: compat.h:410
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:128
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
static void test_VirtualAllocEx(void)
Definition: virtual.c:84

◆ 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 
1488  CloseHandle( handle );
1489 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SEC_COMMIT
Definition: mmtypes.h:99
smooth NULL
Definition: ftsmooth.c:416
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:156
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define SetLastError(x)
Definition: compat.h:409
HANDLE NTAPI OpenFileMappingA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: filemap.c:284
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
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
#define PAGE_READWRITE
Definition: nt_native.h:1304

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 */
3179  { PAGE_READONLY | PAGE_NOACCESS, FALSE, PAGE_NOACCESS }, /* 0x03 */
3180  { PAGE_READWRITE, TRUE, PAGE_READWRITE }, /* 0x04 */
3181  { PAGE_READWRITE | PAGE_NOACCESS, FALSE, PAGE_NOACCESS }, /* 0x05 */
3182  { PAGE_READWRITE | PAGE_READONLY, FALSE, PAGE_NOACCESS }, /* 0x06 */
3184  { PAGE_WRITECOPY, TRUE, PAGE_READWRITE }, /* 0x08 */
3185  { PAGE_WRITECOPY | PAGE_NOACCESS, FALSE, PAGE_NOACCESS }, /* 0x09 */
3186  { PAGE_WRITECOPY | PAGE_READONLY, FALSE, PAGE_NOACCESS }, /* 0x0a */
3188  { PAGE_WRITECOPY | PAGE_READWRITE, FALSE, PAGE_NOACCESS }, /* 0x0c */
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 
3222  GetTempFileNameA(temp_path, "map", 0, file_name);
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 */
3369  if (prot == PAGE_EXECUTE_WRITECOPY) prot = PAGE_EXECUTE_READWRITE;
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 */
3377  todo_wine_if (td[i].prot == PAGE_EXECUTE_WRITECOPY)
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 ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define MapViewOfFile
Definition: compat.h:402
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1154
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define MEM_COMMIT
Definition: nt_native.h:1313
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
struct _test_info info[]
Definition: SetCursorPos.c:19
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 PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:74
#define SEC_COMMIT
Definition: mmtypes.h:99
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint base
Definition: 3dtext.c:35
#define GENERIC_WRITE
Definition: nt_native.h:90
static PVOID ptr
Definition: dispmode.c:27
#define PAGE_NOACCESS
Definition: nt_native.h:1302
smooth NULL
Definition: ftsmooth.c:416
#define PAGE_EXECUTE
Definition: nt_native.h:1306
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define FILE_MAP_READ
Definition: compat.h:427
#define todo_wine_if(is_todo)
Definition: test.h:155
#define trace
Definition: atltest.h:70
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:401
#define FILE_MAP_WRITE
Definition: winbase.h:154
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
SIZE_T NTAPI VirtualQuery(IN LPCVOID lpAddress, OUT PMEMORY_BASIC_INFORMATION lpBuffer, IN SIZE_T dwLength)
Definition: virtmem.c:220
BOOL NTAPI VirtualProtect(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flNewProtect, OUT PDWORD lpflOldProtect)
Definition: virtmem.c:144
#define success(from, fromstr, to, tostr)
#define SetLastError(x)
Definition: compat.h:409
int ret
#define GENERIC_READ
Definition: compat.h:124
#define broken(x)
Definition: _sntprintf.h:21
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD dwPageSize
Definition: winbase.h:1126
#define FILE_BEGIN
Definition: winbase.h:112
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
#define ok(value,...)
Definition: atltest.h:57
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
#define PAGE_READONLY
Definition: compat.h:127
#define MEM_MAPPED
Definition: nt_native.h:1319
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
static LPCWSTR file_name
Definition: protocol.c:146
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define FILE_MAP_EXECUTE
Definition: winbase.h:157
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define GENERIC_EXECUTE
Definition: nt_native.h:91
#define UnmapViewOfFile
Definition: compat.h:403
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
#define PAGE_READWRITE
Definition: nt_native.h:1304
static BOOL is_mem_writable(DWORD prot)
Definition: virtual.c:3059
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

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 
1547  ret = IsBadCodePtr(NULL);
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 }
#define TRUE
Definition: types.h:120
BOOL NTAPI IsBadCodePtr(FARPROC lpfn)
Definition: except.c:874
unsigned int BOOL
Definition: ntddk_ex.h:94
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
int ret
#define ok(value,...)
Definition: atltest.h:57

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 }
#define TRUE
Definition: types.h:120
unsigned int BOOL
Definition: ntddk_ex.h:94
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
int ret
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:807

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 }
#define TRUE
Definition: types.h:120
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:885
unsigned int BOOL
Definition: ntddk_ex.h:94
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
int ret
#define ok(value,...)
Definition: atltest.h:57

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 */
3562  { FILE_MAP_WRITE | FILE_MAP_COPY, PAGE_READWRITE }, /* 0x03 */
3563  { FILE_MAP_READ, PAGE_READONLY }, /* 0x04 */
3564  { FILE_MAP_READ | FILE_MAP_COPY, PAGE_READONLY }, /* 0x05 */
3565  { FILE_MAP_READ | FILE_MAP_WRITE, PAGE_READWRITE }, /* 0x06 */
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;
3598  MEMORY_BASIC_INFORMATION info, nt_info;
3599 
3600  GetSystemInfo(&si);
3601  trace("system page size %#x\n", si.dwPageSize);
3602 
3604  GetTempFileNameA(temp_path, "map", 0, file_name);
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);
3626  hmap = CreateFileMappingW(hfile, NULL, PAGE_READWRITE | SEC_COMMIT, 0, si.dwPageSize, NULL);
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 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define CloseHandle
Definition: compat.h:398
#define MapViewOfFile
Definition: compat.h:402
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1154
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static void * map_view_of_file(HANDLE handle, DWORD access)
Definition: virtual.c:3494
#define MEM_COMMIT
Definition: nt_native.h:1313
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
struct _test_info info[]
Definition: SetCursorPos.c:19
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 PAGE_EXECUTE_WRITECOPY
Definition: nt_native.h:1309
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:74
#define SEC_COMMIT
Definition: mmtypes.h:99
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
GLuint base
Definition: 3dtext.c:35
#define GENERIC_WRITE
Definition: nt_native.h:90
static PVOID ptr
Definition: dispmode.c:27
#define PAGE_NOACCESS
Definition: nt_native.h:1302
smooth NULL
Definition: ftsmooth.c:416
#define PAGE_EXECUTE
Definition: nt_native.h:1306
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define FILE_MAP_READ
Definition: compat.h:427
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
#define todo_wine_if(is_todo)
Definition: test.h:155
#define trace
Definition: atltest.h:70
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:401
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
#define FILE_MAP_WRITE
Definition: winbase.h:154
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
SIZE_T NTAPI VirtualQuery(IN LPCVOID lpAddress, OUT PMEMORY_BASIC_INFORMATION lpBuffer, IN SIZE_T dwLength)
Definition: virtmem.c:220
BOOL NTAPI VirtualProtect(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flNewProtect, OUT PDWORD lpflOldProtect)
Definition: virtmem.c:144
#define SetLastError(x)
Definition: compat.h:409
int ret
#define FILE_MAP_COPY
Definition: winbase.h:153
#define GENERIC_READ
Definition: compat.h:124
static BOOL is_compatible_protection(DWORD map_prot, DWORD view_prot, DWORD prot)
Definition: virtual.c:3452
#define broken(x)
Definition: _sntprintf.h:21
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD dwPageSize
Definition: winbase.h:1126
#define FILE_BEGIN
Definition: winbase.h:112
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define ok(value,...)
Definition: atltest.h:57
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
#define PAGE_READONLY
Definition: compat.h:127
#define MEM_MAPPED
Definition: nt_native.h:1319
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
static LPCWSTR file_name
Definition: protocol.c:146
#define skip(...)
Definition: atltest.h:64
#define SECTION_MAP_EXECUTE
Definition: nt_native.h:1290
static IOleDocumentView * view
Definition: activex.c:1749
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
#define FILE_MAP_EXECUTE
Definition: winbase.h:157
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define GENERIC_EXECUTE
Definition: nt_native.h:91
#define UnmapViewOfFile
Definition: compat.h:403
static BOOL is_compatible_access(DWORD map_prot, DWORD view_prot)
Definition: virtual.c:3487
int k
Definition: mpi.c:3369
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
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
#define PAGE_READWRITE
Definition: nt_native.h:1304
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

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;
436  SECTION_BASIC_INFORMATION section_info;
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);
446  file = CreateFileA( testfile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
447  ok( file != INVALID_HANDLE_VALUE, "CreateFile error %u\n", GetLastError() );
448  SetFilePointer( file, 12288, NULL, FILE_BEGIN );
449  SetEndOfFile( file );
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() );
460  UnmapViewOfFile( ptr );
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() );
465  UnmapViewOfFile( ptr );
466 
467  SetLastError(0xdeadbeef);
468  ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
469  ok( ptr != NULL, "MapViewOfFile 0 error %u\n", GetLastError() );
470  UnmapViewOfFile( ptr );
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() );
475  UnmapViewOfFile( ptr );
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() );
482  UnmapViewOfFile( ptr );
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 
506  UnmapViewOfFile( ptr );
507  CloseHandle( map2 );
508  CloseHandle( mapping );
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() );
519  UnmapViewOfFile( ptr );
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() );
524  UnmapViewOfFile( ptr );
525 
526  SetLastError(0xdeadbeef);
527  ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
528  ok( ptr != NULL, "MapViewOfFile 0 error %u\n", GetLastError() );
529  UnmapViewOfFile( ptr );
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() );
536  CloseHandle( mapping );
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() );
547  UnmapViewOfFile( ptr );
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() );
552  UnmapViewOfFile( ptr );
553 
554  SetLastError(0xdeadbeef);
555  ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
556  ok( ptr != NULL, "MapViewOfFile 0 error %u\n", GetLastError() );
557  UnmapViewOfFile( ptr );
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() );
564  CloseHandle( mapping );
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() );
589  CloseHandle( mapping );
590 
591  SetLastError(0xdeadbeef);
593  ok( mapping != 0, "CreateFileMapping PAGE_READONLY error %u\n", GetLastError() );
594  CloseHandle( mapping );
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);
639  ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 0 );
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 );
655  UnmapViewOfFile( ptr );
656  status = pNtQuerySection( mapping, SectionBasicInformation, &section_info,
657  sizeof(section_info), &info_size );
658  ok( status == STATUS_ACCESS_DENIED, "NtQuerySection failed err %x\n", status );
659  CloseHandle( mapping );
661  ok( mapping != 0, "OpenFileMapping FILE_MAP_READ error %u\n", GetLastError() );
662  status = pNtQuerySection( mapping, SectionBasicInformation, &section_info,
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 );
671  CloseHandle( mapping );
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);
681  ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 0 );
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 );
693  UnmapViewOfFile( ptr );
694  status = pNtQuerySection( mapping, SectionBasicInformation, &section_info,
695  sizeof(section_info), &info_size );
696  ok( status == STATUS_ACCESS_DENIED, "NtQuerySection failed err %x\n", status );
697  CloseHandle( mapping );
698 
700  ok( mapping != 0, "OpenFileMapping FILE_MAP_WRITE error %u\n", GetLastError() );
701  status = pNtQuerySection( mapping, SectionBasicInformation, &section_info,
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 );
710  CloseHandle( mapping );
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());
717  status = pNtQuerySection( mapping, SectionBasicInformation, &section_info,
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);
855  todo_wine
856  ok( map2 == 0, "OpenFileMappingA succeeded\n" );
857  todo_wine
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" );
863  todo_wine
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());
916  status = pNtQuerySection( mapping, SectionBasicInformation, &section_info,
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);
944  todo_wine
945  ok( map2 == 0, "OpenFileMappingA succeeded\n" );
946  todo_wine
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" );
952  todo_wine
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 
1023  SetFilePointer(file, 0x3456, NULL, FILE_BEGIN);
1024  SetEndOfFile(file);
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,
1059  &size, ViewShare, 0, PAGE_READONLY );
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,
1064  &size, ViewShare, 0, PAGE_READONLY );
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 
1091  SetEndOfFile(file);
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 
1099  CloseHandle(file);
1100  DeleteFileA(testfile);
1101 }
LARGE_INTEGER Size
Definition: mmtypes.h:327
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define CloseHandle
Definition: compat.h:398
#define MAPPING_SIZE
Definition: virtual.c:26
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define ERROR_SUCCESS
Definition: deptool.c:10
#define MapViewOfFile
Definition: compat.h:402
#define SECTION_QUERY
Definition: nt_native.h:1287
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1154
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define MEM_COMMIT
Definition: nt_native.h:1313
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
struct _test_info info[]
Definition: SetCursorPos.c:19
#define MEM_DECOMMIT
Definition: nt_native.h:1315
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:74
#define SEC_COMMIT
Definition: mmtypes.h:99
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SEC_RESERVE
Definition: nt_native.h:1323
struct _LARGE_INTEGER::@2201 u
#define GENERIC_WRITE
Definition: nt_native.h:90
#define MEM_RESERVE
Definition: nt_native.h:1314
static PVOID ptr
Definition: dispmode.c:27
#define PAGE_NOACCESS
Definition: nt_native.h:1302
#define STATUS_SECTION_TOO_BIG
Definition: ntstatus.h:286
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define FILE_MAP_READ
Definition: compat.h:427
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define OPEN_EXISTING
Definition: compat.h:426
#define MEM_FREE
Definition: nt_native.h:1317
#define MEM_RESET
Definition: nt_native.h:1320
#define STATUS_INVALID_IMAGE_NOT_MZ
Definition: ntstatus.h:525
GLsizeiptr size
Definition: glext.h:5919
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
#define FILE_MAP_WRITE
Definition: winbase.h:154
const char file[]
Definition: icontest.c:11
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
SIZE_T NTAPI VirtualQuery(IN LPCVOID lpAddress, OUT PMEMORY_BASIC_INFORMATION lpBuffer, IN SIZE_T dwLength)
Definition: virtmem.c:220
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define SetLastError(x)
Definition: compat.h:409
#define STATUS_INVALID_FILE_FOR_SECTION
Definition: ntstatus.h:255
int ret
#define ERROR_INVALID_ADDRESS
Definition: compat.h:96
#define STATUS_SECTION_NOT_IMAGE
Definition: ntstatus.h:295
GLenum const GLvoid * addr
Definition: glext.h:9621
#define todo_wine
Definition: test.h:154
#define FILE_MAP_COPY
Definition: winbase.h:153
#define SECTION_MAP_READ
Definition: compat.h:128
#define GENERIC_READ
Definition: compat.h:124
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_BEGIN
Definition: winbase.h:112
#define STATUS_INVALID_VIEW_SIZE
Definition: ntstatus.h:254
HANDLE NTAPI OpenFileMappingA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: filemap.c:284
#define ok(value,...)
Definition: atltest.h:57
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:807
#define PAGE_READONLY
Definition: compat.h:127
#define MEM_MAPPED
Definition: nt_native.h:1319
#define PAGE_WRITECOPY
Definition: nt_native.h:1305
#define SEC_FILE
Definition: mmtypes.h:95
#define MEM_RELEASE
Definition: nt_native.h:1316
Definition: name.c:36
unsigned int ULONG
Definition: retypes.h:1
#define SEC_IMAGE
Definition: mmtypes.h:96
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:128
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define STATUS_MAPPED_FILE_SIZE_ZERO
Definition: ntstatus.h:508
#define UnmapViewOfFile
Definition: compat.h:403
static SERVICE_STATUS status
Definition: service.c:31
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
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
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304
Definition: fci.c:126
Definition: ps.c:97
GLuint const GLchar * name
Definition: glext.h:6031

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;
1317  NTSTATUS status;
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() );
1329  SetFilePointer( file, 4096, NULL, FILE_BEGIN );
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 
1397  UnmapViewOfFile( ptr );
1398  CloseHandle( mapping );
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 );
1422  UnmapViewOfFile( ptr );
1423  CloseHandle( mapping );
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 
1445  UnmapViewOfFile( ptr );
1446  CloseHandle( mapping );
1447 
1448  CloseHandle( file );
1449  DeleteFileA( testfile );
1450 }
#define CloseHandle
Definition: compat.h:398
#define MapViewOfFile
Definition: compat.h:402
#define STATUS_NOT_SAME_DEVICE
Definition: ntstatus.h:434
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1154
LONG NTSTATUS
Definition: precomp.h:26
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2282
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define MEM_COMMIT
Definition: nt_native.h:1313
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:74
#define GENERIC_WRITE
Definition: nt_native.h:90
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define FILE_MAP_READ
Definition: compat.h:427
#define OPEN_EXISTING
Definition: compat.h:426
#define GetProcessHeap()
Definition: compat.h:395
#define MAX_PATH
Definition: compat.h:26
const char file[]
Definition: icontest.c:11
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
#define todo_wine
Definition: test.h:154
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
#define GENERIC_READ
Definition: compat.h:124
#define broken(x)
Definition: _sntprintf.h:21
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_BEGIN
Definition: winbase.h:112
#define STATUS_INVALID_ADDRESS
Definition: ntstatus.h:543
#define ok(value,...)
Definition: atltest.h:57
Definition: services.c:325
#define PAGE_READONLY
Definition: compat.h:127
#define MEM_RELEASE
Definition: nt_native.h:1316
#define SEC_IMAGE
Definition: mmtypes.h:96
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:128
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:247
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define UnmapViewOfFile
Definition: compat.h:403
static SERVICE_STATUS status
Definition: service.c:31
#define win_skip
Definition: test.h:141
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
#define PAGE_READWRITE
Definition: nt_native.h:1304
Definition: fci.c:126
Definition: ps.c:97

Referenced by START_TEST().

◆ test_NtMapViewOfSection()

static void test_NtMapViewOfSection ( void  )
static

Definition at line 1103 of file virtual.c.

1104 {
1105  HANDLE hProcess;
1106 
1107  static const char testfile[] = "testfile.xxx";
1108  static const char data[] = "test data for NtMapViewOfSection";
1109  char buffer[sizeof(data)];
1110  HANDLE file, mapping;
1111  void *ptr, *ptr2;
1112  BOOL is_wow64, ret;
1113  DWORD status, written;
1114  SIZE_T size, result;
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 );
1126  SetFilePointer( file, 4096, NULL, FILE_BEGIN );
1127  SetEndOfFile( file );
1128 
1129  /* read/write mapping */
1130 
1132  ok( mapping != 0, "CreateFileMapping failed\n" );
1133 
1134  hProcess = create_target_process("sleep");
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 
1144  ret = ReadProcessMemory( hProcess, ptr, buffer, sizeof(buffer), &result );
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 
1304  CloseHandle( mapping );
1305  CloseHandle( file );
1306  DeleteFileA( testfile );
1307 
1310 }
static HANDLE create_target_process(const char *arg)
Definition: virtual.c:66
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CloseHandle
Definition: compat.h:398
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1154
GLintptr offset
Definition: glext.h:5920
#define STATUS_INVALID_PARAMETER_9
Definition: ntstatus.h:469
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
GLuint buffer
Definition: glext.h:5915
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:415
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
uint32_t ULONG_PTR
Definition: typedefs.h:63
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define STATUS_MAPPED_ALIGNMENT
Definition: ntstatus.h:662
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
GLsizeiptr size
Definition: glext.h:5919
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
static BOOL is_wow64
Definition: loader.c:55
const char file[]
Definition: icontest.c:11
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
int ret
#define todo_wine
Definition: test.h:154
#define GENERIC_READ
Definition: compat.h:124
#define AT_ROUND_TO_PAGE
Definition: winnt_old.h:594
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_BEGIN
Definition: winbase.h:112
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
#define ok(value,...)
Definition: atltest.h:57
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:464
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:247
return STATUS_SUCCESS
Definition: btrfs.c:2966
GLuint64EXT * result
Definition: glext.h:11304
static SERVICE_STATUS status
Definition: service.c:31
#define win_skip
Definition: test.h:141
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
#define PAGE_READWRITE
Definition: nt_native.h:1304
Definition: fci.c:126
Definition: ps.c:97

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];
3883  HANDLE file, mapping;
3884  void *p;
3885  NTSTATUS status;
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 
3913  fsize = GetFileSize(file, NULL);
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 
3962  UnmapViewOfFile(p);
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);
4015 todo_wine
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 
4027  UnmapViewOfFile(p);
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);
4040 todo_wine
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 
4060  CloseHandle(file);
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 
4088  UnmapViewOfFile(p);
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 }
GLeglImageOES image
Definition: gl.h:2204
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define MapViewOfFile
Definition: compat.h:402
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
LONG NTSTATUS
Definition: precomp.h:26
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2282
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SEC_NOCACHE
Definition: mmtypes.h:100
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
IMAGE_NT_HEADERS nt
Definition: module.c:50
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
#define FILE_SHARE_READ
Definition: compat.h:125
struct _test_info info[]
Definition: SetCursorPos.c:19
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define SEC_COMMIT
Definition: mmtypes.h:99
#define SEC_RESERVE
Definition: nt_native.h:1323
smooth NULL
Definition: ftsmooth.c:416
#define FILE_MAP_READ
Definition: compat.h:427