ok(old_prot == PAGE_READONLY,
"wrong old protection: got %04x instead of PAGE_READONLY\n", old_prot);
+ /* invalid protection values */
+ SetLastError(0xdeadbeef);
+ addr2 = VirtualAlloc(NULL, 0x1000, MEM_RESERVE, 0);
+ ok(!addr2, "VirtualAlloc succeeded\n");
+ ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+ SetLastError(0xdeadbeef);
+ addr2 = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, 0);
+ ok(!addr2, "VirtualAlloc succeeded\n");
+ ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+ SetLastError(0xdeadbeef);
+ addr2 = VirtualAlloc(addr1, 0x1000, MEM_COMMIT, PAGE_READONLY | PAGE_EXECUTE);
+ ok(!addr2, "VirtualAlloc succeeded\n");
+ ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+ SetLastError(0xdeadbeef);
+ ok(!VirtualProtect(addr1, 0x1000, PAGE_READWRITE | PAGE_EXECUTE_WRITECOPY, &old_prot),
+ "VirtualProtect succeeded\n");
+ ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+ SetLastError(0xdeadbeef);
+ ok(!VirtualProtect(addr1, 0x1000, 0, &old_prot), "VirtualProtect succeeded\n");
+ ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
+
+ SetLastError(0xdeadbeef);
ok(!VirtualFree(addr1, 0x10000, 0), "VirtualFree should fail with type 0\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER,
"got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
/***********************************************************************
- * VIRTUAL_GetProt
+ * get_vprot_flags
*
* Build page protections from Win32 flags.
*
* RETURNS
* Value of page protection flags
*/
-static BYTE VIRTUAL_GetProt( DWORD protect )
+static NTSTATUS get_vprot_flags( DWORD protect, unsigned int *vprot )
{
- BYTE vprot;
-
switch(protect & 0xff)
{
case PAGE_READONLY:
- vprot = VPROT_READ;
+ *vprot = VPROT_READ;
break;
case PAGE_READWRITE:
- vprot = VPROT_READ | VPROT_WRITE;
+ *vprot = VPROT_READ | VPROT_WRITE;
break;
case PAGE_WRITECOPY:
- vprot = VPROT_READ | VPROT_WRITECOPY;
+ *vprot = VPROT_READ | VPROT_WRITECOPY;
break;
case PAGE_EXECUTE:
- vprot = VPROT_EXEC;
+ *vprot = VPROT_EXEC;
break;
case PAGE_EXECUTE_READ:
- vprot = VPROT_EXEC | VPROT_READ;
+ *vprot = VPROT_EXEC | VPROT_READ;
break;
case PAGE_EXECUTE_READWRITE:
- vprot = VPROT_EXEC | VPROT_READ | VPROT_WRITE;
+ *vprot = VPROT_EXEC | VPROT_READ | VPROT_WRITE;
break;
case PAGE_EXECUTE_WRITECOPY:
- vprot = VPROT_EXEC | VPROT_READ | VPROT_WRITECOPY;
+ *vprot = VPROT_EXEC | VPROT_READ | VPROT_WRITECOPY;
break;
case PAGE_NOACCESS:
- default:
- vprot = 0;
+ *vprot = 0;
break;
+ default:
+ return STATUS_INVALID_PARAMETER;
}
- if (protect & PAGE_GUARD) vprot |= VPROT_GUARD;
- if (protect & PAGE_NOCACHE) vprot |= VPROT_NOCACHE;
- return vprot;
+ if (protect & PAGE_GUARD) *vprot |= VPROT_GUARD;
+ if (protect & PAGE_NOCACHE) *vprot |= VPROT_NOCACHE;
+ return STATUS_SUCCESS;
}
if (is_beyond_limit( 0, size, working_set_limit )) return STATUS_WORKING_SET_LIMIT_RANGE;
- vprot = VIRTUAL_GetProt( protect ) | VPROT_VALLOC;
+ if ((status = get_vprot_flags( protect, &vprot ))) return status;
+ vprot |= VPROT_VALLOC;
if (type & MEM_COMMIT) vprot |= VPROT_COMMITTED;
if (*ret)
NTSTATUS status = STATUS_SUCCESS;
char *base;
BYTE vprot;
+ unsigned int new_vprot;
SIZE_T size = *size_ptr;
LPVOID addr = *addr_ptr;
size = ROUND_SIZE( addr, size );
base = ROUND_ADDR( addr, page_mask );
+ if ((status = get_vprot_flags( new_prot, &new_vprot ))) return status;
+ new_vprot |= VPROT_COMMITTED;
server_enter_uninterrupted_section( &csVirtual, &sigset );
if (get_committed_size( view, base, &vprot ) >= size && (vprot & VPROT_COMMITTED))
{
if (old_prot) *old_prot = VIRTUAL_GetWin32Prot( vprot );
- vprot = VIRTUAL_GetProt( new_prot ) | VPROT_COMMITTED;
- if (!VIRTUAL_SetProt( view, base, size, vprot )) status = STATUS_ACCESS_DENIED;
+ if (!VIRTUAL_SetProt( view, base, size, new_vprot )) status = STATUS_ACCESS_DENIED;
}
else status = STATUS_NOT_COMMITTED;
}
if (len > MAX_PATH*sizeof(WCHAR)) return STATUS_NAME_TOO_LONG;
+ if ((ret = get_vprot_flags( protect, &vprot ))) return ret;
+
objattr.rootdir = wine_server_obj_handle( attr ? attr->RootDirectory : 0 );
objattr.sd_len = 0;
objattr.name_len = len;
if (ret != STATUS_SUCCESS) return ret;
}
- vprot = VIRTUAL_GetProt( protect );
if (!(sec_flags & SEC_RESERVE)) vprot |= VPROT_COMMITTED;
if (sec_flags & SEC_NOCACHE) vprot |= VPROT_NOCACHE;
if (sec_flags & SEC_IMAGE) vprot |= VPROT_IMAGE;
server_enter_uninterrupted_section( &csVirtual, &sigset );
- vprot = VIRTUAL_GetProt( protect ) | (map_vprot & VPROT_COMMITTED);
+ get_vprot_flags( protect, &vprot );
+ vprot |= (map_vprot & VPROT_COMMITTED);
res = map_view( &view, *addr_ptr, size, mask, FALSE, vprot );
if (res)
{