2006-11-16 16:50:57 +01:00
|
|
|
/*
|
|
|
|
* Unit test suite for the PE loader.
|
|
|
|
*
|
2011-07-19 18:41:12 +02:00
|
|
|
* Copyright 2006,2011 Dmitry Timoshkov
|
2006-11-16 16:50:57 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2014-02-17 16:15:06 +01:00
|
|
|
#define NONAMELESSUNION
|
2018-02-13 20:08:49 +01:00
|
|
|
#define NONAMELESSSTRUCT
|
2006-11-16 16:50:57 +01:00
|
|
|
#include <stdarg.h>
|
2013-04-12 11:00:58 +02:00
|
|
|
#include <stdio.h>
|
2006-11-24 19:44:10 +01:00
|
|
|
#include <assert.h>
|
2006-11-16 16:50:57 +01:00
|
|
|
|
2012-02-20 09:01:25 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2006-11-16 16:50:57 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2012-02-20 09:01:25 +01:00
|
|
|
#include "winternl.h"
|
2006-11-16 16:50:57 +01:00
|
|
|
#include "wine/test.h"
|
2013-09-11 22:31:01 +02:00
|
|
|
#include "delayloadhandler.h"
|
2006-11-16 16:50:57 +01:00
|
|
|
|
2014-02-07 15:08:57 +01:00
|
|
|
/* PROCESS_ALL_ACCESS in Vista+ PSDKs is incompatible with older Windows versions */
|
|
|
|
#define PROCESS_ALL_ACCESS_NT4 (PROCESS_ALL_ACCESS & ~0xf000)
|
|
|
|
|
2006-11-24 19:44:10 +01:00
|
|
|
#define ALIGN_SIZE(size, alignment) (((size) + (alignment - 1)) & ~((alignment - 1)))
|
|
|
|
|
2013-04-26 10:56:59 +02:00
|
|
|
struct PROCESS_BASIC_INFORMATION_PRIVATE
|
|
|
|
{
|
|
|
|
DWORD_PTR ExitStatus;
|
|
|
|
PPEB PebBaseAddress;
|
|
|
|
DWORD_PTR AffinityMask;
|
|
|
|
DWORD_PTR BasePriority;
|
|
|
|
ULONG_PTR UniqueProcessId;
|
|
|
|
ULONG_PTR InheritedFromUniqueProcessId;
|
|
|
|
};
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
static LONG *child_failures;
|
2013-09-11 22:31:01 +02:00
|
|
|
static WORD cb_count;
|
2013-11-21 15:54:51 +01:00
|
|
|
static DWORD page_size;
|
2018-01-30 11:03:09 +01:00
|
|
|
static BOOL is_win64 = sizeof(void *) > sizeof(int);
|
2018-01-30 10:47:32 +01:00
|
|
|
static BOOL is_wow64;
|
2013-04-12 11:00:58 +02:00
|
|
|
|
2013-11-21 16:14:11 +01:00
|
|
|
static NTSTATUS (WINAPI *pNtCreateSection)(HANDLE *, ACCESS_MASK, const OBJECT_ATTRIBUTES *,
|
|
|
|
const LARGE_INTEGER *, ULONG, ULONG, HANDLE );
|
2017-12-28 13:04:20 +01:00
|
|
|
static NTSTATUS (WINAPI *pNtQuerySection)(HANDLE, SECTION_INFORMATION_CLASS, void *, SIZE_T, SIZE_T *);
|
2012-02-20 09:01:25 +01:00
|
|
|
static NTSTATUS (WINAPI *pNtMapViewOfSection)(HANDLE, HANDLE, PVOID *, ULONG, SIZE_T, const LARGE_INTEGER *, SIZE_T *, ULONG, ULONG, ULONG);
|
|
|
|
static NTSTATUS (WINAPI *pNtUnmapViewOfSection)(HANDLE, PVOID);
|
2013-04-26 10:56:59 +02:00
|
|
|
static NTSTATUS (WINAPI *pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
|
|
|
|
static NTSTATUS (WINAPI *pNtSetInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG);
|
2013-04-12 11:00:58 +02:00
|
|
|
static NTSTATUS (WINAPI *pNtTerminateProcess)(HANDLE, DWORD);
|
|
|
|
static void (WINAPI *pLdrShutdownProcess)(void);
|
|
|
|
static BOOLEAN (WINAPI *pRtlDllShutdownInProgress)(void);
|
2013-04-26 10:56:59 +02:00
|
|
|
static NTSTATUS (WINAPI *pNtAllocateVirtualMemory)(HANDLE, PVOID *, ULONG, SIZE_T *, ULONG, ULONG);
|
|
|
|
static NTSTATUS (WINAPI *pNtFreeVirtualMemory)(HANDLE, PVOID *, SIZE_T *, ULONG);
|
2014-05-28 06:58:59 +02:00
|
|
|
static NTSTATUS (WINAPI *pLdrLockLoaderLock)(ULONG, ULONG *, ULONG_PTR *);
|
|
|
|
static NTSTATUS (WINAPI *pLdrUnlockLoaderLock)(ULONG, ULONG_PTR);
|
2013-04-30 10:20:24 +02:00
|
|
|
static void (WINAPI *pRtlAcquirePebLock)(void);
|
|
|
|
static void (WINAPI *pRtlReleasePebLock)(void);
|
2013-09-11 22:31:01 +02:00
|
|
|
static PVOID (WINAPI *pResolveDelayLoadedAPI)(PVOID, PCIMAGE_DELAYLOAD_DESCRIPTOR,
|
|
|
|
PDELAYLOAD_FAILURE_DLL_CALLBACK, PVOID,
|
|
|
|
PIMAGE_THUNK_DATA ThunkAddress,ULONG);
|
2015-07-13 08:17:26 +02:00
|
|
|
static PVOID (WINAPI *pRtlImageDirectoryEntryToData)(HMODULE,BOOL,WORD,ULONG *);
|
2016-08-03 00:55:43 +02:00
|
|
|
static DWORD (WINAPI *pFlsAlloc)(PFLS_CALLBACK_FUNCTION);
|
|
|
|
static BOOL (WINAPI *pFlsSetValue)(DWORD, PVOID);
|
|
|
|
static PVOID (WINAPI *pFlsGetValue)(DWORD);
|
|
|
|
static BOOL (WINAPI *pFlsFree)(DWORD);
|
2017-12-19 14:33:25 +01:00
|
|
|
static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
|
2012-02-20 09:01:25 +01:00
|
|
|
|
2008-09-12 22:54:22 +02:00
|
|
|
static PVOID RVAToAddr(DWORD_PTR rva, HMODULE module)
|
|
|
|
{
|
|
|
|
if (rva == 0)
|
|
|
|
return NULL;
|
|
|
|
return ((char*) module) + rva;
|
|
|
|
}
|
|
|
|
|
2013-11-21 17:30:18 +01:00
|
|
|
static IMAGE_DOS_HEADER dos_header;
|
2006-11-16 16:50:57 +01:00
|
|
|
|
2015-01-27 23:02:58 +01:00
|
|
|
static const IMAGE_NT_HEADERS nt_header_template =
|
2006-11-16 16:50:57 +01:00
|
|
|
{
|
2006-11-24 19:44:10 +01:00
|
|
|
IMAGE_NT_SIGNATURE, /* Signature */
|
2007-08-04 03:23:56 +02:00
|
|
|
{
|
2007-05-24 10:15:03 +02:00
|
|
|
#if defined __i386__
|
2007-08-04 03:23:56 +02:00
|
|
|
IMAGE_FILE_MACHINE_I386, /* Machine */
|
2007-05-24 10:15:03 +02:00
|
|
|
#elif defined __x86_64__
|
2007-08-04 03:23:56 +02:00
|
|
|
IMAGE_FILE_MACHINE_AMD64, /* Machine */
|
2008-12-31 16:20:06 +01:00
|
|
|
#elif defined __powerpc__
|
|
|
|
IMAGE_FILE_MACHINE_POWERPC, /* Machine */
|
2010-09-18 18:01:59 +02:00
|
|
|
#elif defined __arm__
|
2012-08-16 22:39:46 +02:00
|
|
|
IMAGE_FILE_MACHINE_ARMNT, /* Machine */
|
2013-01-16 00:53:55 +01:00
|
|
|
#elif defined __aarch64__
|
|
|
|
IMAGE_FILE_MACHINE_ARM64, /* Machine */
|
2006-11-16 16:50:57 +01:00
|
|
|
#else
|
|
|
|
# error You must specify the machine type
|
|
|
|
#endif
|
|
|
|
1, /* NumberOfSections */
|
|
|
|
0, /* TimeDateStamp */
|
|
|
|
0, /* PointerToSymbolTable */
|
|
|
|
0, /* NumberOfSymbols */
|
|
|
|
sizeof(IMAGE_OPTIONAL_HEADER), /* SizeOfOptionalHeader */
|
|
|
|
IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DLL /* Characteristics */
|
|
|
|
},
|
|
|
|
{ IMAGE_NT_OPTIONAL_HDR_MAGIC, /* Magic */
|
|
|
|
1, /* MajorLinkerVersion */
|
|
|
|
0, /* MinorLinkerVersion */
|
|
|
|
0, /* SizeOfCode */
|
|
|
|
0, /* SizeOfInitializedData */
|
|
|
|
0, /* SizeOfUninitializedData */
|
|
|
|
0, /* AddressOfEntryPoint */
|
2006-12-09 13:26:30 +01:00
|
|
|
0x10, /* BaseOfCode, also serves as e_lfanew in the truncated MZ header */
|
2009-01-03 20:21:25 +01:00
|
|
|
#ifndef _WIN64
|
2006-11-16 16:50:57 +01:00
|
|
|
0, /* BaseOfData */
|
2009-01-03 20:21:25 +01:00
|
|
|
#endif
|
2006-11-16 16:50:57 +01:00
|
|
|
0x10000000, /* ImageBase */
|
|
|
|
0, /* SectionAlignment */
|
|
|
|
0, /* FileAlignment */
|
|
|
|
4, /* MajorOperatingSystemVersion */
|
|
|
|
0, /* MinorOperatingSystemVersion */
|
|
|
|
1, /* MajorImageVersion */
|
|
|
|
0, /* MinorImageVersion */
|
|
|
|
4, /* MajorSubsystemVersion */
|
|
|
|
0, /* MinorSubsystemVersion */
|
|
|
|
0, /* Win32VersionValue */
|
2015-01-27 23:02:58 +01:00
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0x1000, /* SizeOfImage */
|
|
|
|
sizeof(dos_header) + sizeof(nt_header_template), /* SizeOfHeaders */
|
2006-11-16 16:50:57 +01:00
|
|
|
0, /* CheckSum */
|
|
|
|
IMAGE_SUBSYSTEM_WINDOWS_CUI, /* Subsystem */
|
|
|
|
0, /* DllCharacteristics */
|
|
|
|
0, /* SizeOfStackReserve */
|
|
|
|
0, /* SizeOfStackCommit */
|
|
|
|
0, /* SizeOfHeapReserve */
|
|
|
|
0, /* SizeOfHeapCommit */
|
|
|
|
0, /* LoaderFlags */
|
|
|
|
0, /* NumberOfRvaAndSizes */
|
|
|
|
{ { 0 } } /* DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static IMAGE_SECTION_HEADER section =
|
|
|
|
{
|
|
|
|
".rodata", /* Name */
|
2016-08-07 22:15:45 +02:00
|
|
|
{ 0 }, /* Misc */
|
2006-11-16 16:50:57 +01:00
|
|
|
0, /* VirtualAddress */
|
2016-08-07 22:15:45 +02:00
|
|
|
0, /* SizeOfRawData */
|
2006-11-16 16:50:57 +01:00
|
|
|
0, /* PointerToRawData */
|
|
|
|
0, /* PointerToRelocations */
|
|
|
|
0, /* PointerToLinenumbers */
|
|
|
|
0, /* NumberOfRelocations */
|
|
|
|
0, /* NumberOfLinenumbers */
|
|
|
|
IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ, /* Characteristics */
|
|
|
|
};
|
|
|
|
|
2013-11-21 17:30:18 +01:00
|
|
|
|
|
|
|
static const char filler[0x1000];
|
|
|
|
static const char section_data[0x10] = "section data";
|
|
|
|
|
|
|
|
static DWORD create_test_dll( const IMAGE_DOS_HEADER *dos_header, UINT dos_size,
|
2017-12-27 18:36:34 +01:00
|
|
|
const IMAGE_NT_HEADERS *nt_header, char dll_name[MAX_PATH] )
|
2013-11-21 17:30:18 +01:00
|
|
|
{
|
2017-12-27 18:36:34 +01:00
|
|
|
char temp_path[MAX_PATH];
|
2013-11-21 17:30:18 +01:00
|
|
|
DWORD dummy, size, file_align;
|
|
|
|
HANDLE hfile;
|
|
|
|
BOOL ret;
|
|
|
|
|
2017-12-27 18:36:34 +01:00
|
|
|
GetTempPathA(MAX_PATH, temp_path);
|
|
|
|
GetTempFileNameA(temp_path, "ldr", 0, dll_name);
|
|
|
|
|
2013-11-21 17:30:18 +01:00
|
|
|
hfile = CreateFileA(dll_name, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, 0);
|
2017-12-27 18:36:34 +01:00
|
|
|
ok( hfile != INVALID_HANDLE_VALUE, "failed to create %s err %u\n", dll_name, GetLastError() );
|
2013-11-21 17:30:18 +01:00
|
|
|
if (hfile == INVALID_HANDLE_VALUE) return 0;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, dos_header, dos_size, &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, nt_header, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
if (nt_header->FileHeader.SizeOfOptionalHeader)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &nt_header->OptionalHeader,
|
|
|
|
min(nt_header->FileHeader.SizeOfOptionalHeader, sizeof(IMAGE_OPTIONAL_HEADER)),
|
|
|
|
&dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
if (nt_header->FileHeader.SizeOfOptionalHeader > sizeof(IMAGE_OPTIONAL_HEADER))
|
|
|
|
{
|
|
|
|
file_align = nt_header->FileHeader.SizeOfOptionalHeader - sizeof(IMAGE_OPTIONAL_HEADER);
|
|
|
|
assert(file_align < sizeof(filler));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, filler, file_align, &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(nt_header->FileHeader.NumberOfSections <= 1);
|
|
|
|
if (nt_header->FileHeader.NumberOfSections)
|
|
|
|
{
|
2016-08-07 22:15:45 +02:00
|
|
|
section.SizeOfRawData = 10;
|
|
|
|
|
2013-11-21 17:30:18 +01:00
|
|
|
if (nt_header->OptionalHeader.SectionAlignment >= page_size)
|
|
|
|
{
|
|
|
|
section.PointerToRawData = dos_size;
|
|
|
|
section.VirtualAddress = nt_header->OptionalHeader.SectionAlignment;
|
|
|
|
section.Misc.VirtualSize = section.SizeOfRawData * 10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
section.PointerToRawData = nt_header->OptionalHeader.SizeOfHeaders;
|
|
|
|
section.VirtualAddress = nt_header->OptionalHeader.SizeOfHeaders;
|
|
|
|
section.Misc.VirtualSize = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, §ion, sizeof(section), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* section data */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, section_data, sizeof(section_data), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
size = GetFileSize(hfile, NULL);
|
|
|
|
CloseHandle(hfile);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
static DWORD create_test_dll_sections( const IMAGE_DOS_HEADER *dos_header, const IMAGE_NT_HEADERS *nt_header,
|
|
|
|
const IMAGE_SECTION_HEADER *sections, const void *section_data,
|
|
|
|
char dll_name[MAX_PATH] )
|
2016-07-26 12:38:50 +02:00
|
|
|
{
|
2018-02-13 20:08:49 +01:00
|
|
|
char temp_path[MAX_PATH];
|
|
|
|
DWORD dummy, i, size;
|
|
|
|
HANDLE hfile;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
GetTempPathA(MAX_PATH, temp_path);
|
|
|
|
GetTempFileNameA(temp_path, "ldr", 0, dll_name);
|
|
|
|
|
|
|
|
hfile = CreateFileA(dll_name, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, 0);
|
|
|
|
ok( hfile != INVALID_HANDLE_VALUE, "failed to create %s err %u\n", dll_name, GetLastError() );
|
|
|
|
if (hfile == INVALID_HANDLE_VALUE) return 0;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, dos_header, sizeof(*dos_header), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, nt_header, offsetof(IMAGE_NT_HEADERS, OptionalHeader) + nt_header->FileHeader.SizeOfOptionalHeader, &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, sections, sizeof(*sections) * nt_header->FileHeader.NumberOfSections,
|
|
|
|
&dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
|
|
|
|
{
|
|
|
|
SetFilePointer(hfile, sections[i].PointerToRawData, NULL, FILE_BEGIN);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, section_data, sections[i].SizeOfRawData, &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
size = GetFileSize(hfile, NULL);
|
|
|
|
CloseHandle(hfile);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL query_image_section( int id, const char *dll_name, const IMAGE_NT_HEADERS *nt_header,
|
|
|
|
const void *section_data )
|
|
|
|
{
|
|
|
|
static BOOL is_winxp;
|
2016-07-27 09:49:37 +02:00
|
|
|
SECTION_BASIC_INFORMATION info;
|
2016-07-26 12:38:50 +02:00
|
|
|
SECTION_IMAGE_INFORMATION image;
|
2018-02-13 20:08:49 +01:00
|
|
|
const IMAGE_COR20_HEADER *cor_header = NULL;
|
2017-12-28 13:04:20 +01:00
|
|
|
SIZE_T info_size = (SIZE_T)0xdeadbeef << 16;
|
2016-07-26 12:38:50 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE file, mapping;
|
|
|
|
ULONG file_size;
|
2016-07-27 09:49:37 +02:00
|
|
|
LARGE_INTEGER map_size;
|
2017-12-19 14:33:25 +01:00
|
|
|
SIZE_T max_stack, commit_stack;
|
|
|
|
void *entry_point;
|
|
|
|
|
2016-07-27 09:09:40 +02:00
|
|
|
/* truncated header is not handled correctly in windows <= w2k3 */
|
2017-12-19 14:33:25 +01:00
|
|
|
BOOL truncated;
|
2016-07-26 12:38:50 +02:00
|
|
|
|
2016-07-27 09:09:40 +02:00
|
|
|
file = CreateFileA( dll_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE,
|
|
|
|
NULL, OPEN_EXISTING, 0, 0 );
|
2016-07-26 12:38:50 +02:00
|
|
|
ok( file != INVALID_HANDLE_VALUE, "%u: CreateFile error %d\n", id, GetLastError() );
|
|
|
|
file_size = GetFileSize( file, NULL );
|
|
|
|
|
|
|
|
status = pNtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_MAP_READ | SECTION_QUERY,
|
|
|
|
NULL, NULL, PAGE_READONLY, SEC_IMAGE, file );
|
|
|
|
ok( !status, "%u: NtCreateSection failed err %x\n", id, status );
|
2016-07-27 09:09:40 +02:00
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
CloseHandle( file );
|
2017-12-27 18:51:01 +01:00
|
|
|
return FALSE;
|
2016-07-27 09:09:40 +02:00
|
|
|
}
|
2016-07-26 12:38:50 +02:00
|
|
|
status = pNtQuerySection( mapping, SectionImageInformation, &image, sizeof(image), &info_size );
|
|
|
|
ok( !status, "%u: NtQuerySection failed err %x\n", id, status );
|
2017-12-28 13:04:20 +01:00
|
|
|
ok( info_size == sizeof(image), "%u: NtQuerySection wrong size %lu\n", id, info_size );
|
2018-01-30 11:03:09 +01:00
|
|
|
if (nt_header->OptionalHeader.Magic == (is_win64 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC
|
|
|
|
: IMAGE_NT_OPTIONAL_HDR32_MAGIC))
|
2017-12-19 14:33:25 +01:00
|
|
|
{
|
|
|
|
max_stack = nt_header->OptionalHeader.SizeOfStackReserve;
|
|
|
|
commit_stack = nt_header->OptionalHeader.SizeOfStackCommit;
|
|
|
|
entry_point = (char *)nt_header->OptionalHeader.ImageBase + nt_header->OptionalHeader.AddressOfEntryPoint;
|
|
|
|
truncated = nt_header->FileHeader.SizeOfOptionalHeader < sizeof(IMAGE_OPTIONAL_HEADER);
|
2018-02-13 20:08:49 +01:00
|
|
|
if (!truncated &&
|
|
|
|
nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress &&
|
|
|
|
nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size)
|
|
|
|
cor_header = section_data;
|
2017-12-19 14:33:25 +01:00
|
|
|
}
|
|
|
|
else if (nt_header->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
|
|
|
|
{
|
2018-02-13 20:08:49 +01:00
|
|
|
const IMAGE_NT_HEADERS64 *nt64 = (const IMAGE_NT_HEADERS64 *)nt_header;
|
2017-12-19 14:33:25 +01:00
|
|
|
max_stack = 0x100000;
|
|
|
|
commit_stack = 0x10000;
|
|
|
|
entry_point = (void *)0x81231234;
|
|
|
|
truncated = nt_header->FileHeader.SizeOfOptionalHeader < sizeof(IMAGE_OPTIONAL_HEADER64);
|
2018-02-13 20:08:49 +01:00
|
|
|
if (!truncated &&
|
|
|
|
nt64->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress &&
|
|
|
|
nt64->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size)
|
|
|
|
cor_header = section_data;
|
2017-12-19 14:33:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const IMAGE_NT_HEADERS32 *nt32 = (const IMAGE_NT_HEADERS32 *)nt_header;
|
|
|
|
max_stack = nt32->OptionalHeader.SizeOfStackReserve;
|
|
|
|
commit_stack = nt32->OptionalHeader.SizeOfStackCommit;
|
|
|
|
entry_point = (char *)(ULONG_PTR)nt32->OptionalHeader.ImageBase + nt32->OptionalHeader.AddressOfEntryPoint;
|
|
|
|
truncated = nt_header->FileHeader.SizeOfOptionalHeader < sizeof(IMAGE_OPTIONAL_HEADER32);
|
2018-02-13 20:08:49 +01:00
|
|
|
if (!truncated &&
|
|
|
|
nt32->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress &&
|
|
|
|
nt32->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size)
|
|
|
|
cor_header = section_data;
|
2017-12-19 14:33:25 +01:00
|
|
|
}
|
2018-02-13 20:08:49 +01:00
|
|
|
ok( (char *)image.TransferAddress == (char *)entry_point ||
|
|
|
|
(S(U(image)).ImageDynamicallyRelocated && LOWORD(image.TransferAddress) == LOWORD(entry_point)),
|
2017-12-19 14:33:25 +01:00
|
|
|
"%u: TransferAddress wrong %p / %p (%08x)\n", id,
|
|
|
|
image.TransferAddress, entry_point, nt_header->OptionalHeader.AddressOfEntryPoint );
|
2016-07-26 12:38:50 +02:00
|
|
|
ok( image.ZeroBits == 0, "%u: ZeroBits wrong %08x\n", id, image.ZeroBits );
|
2017-12-19 14:33:25 +01:00
|
|
|
ok( image.MaximumStackSize == max_stack || broken(truncated),
|
|
|
|
"%u: MaximumStackSize wrong %lx / %lx\n", id, image.MaximumStackSize, max_stack );
|
|
|
|
ok( image.CommittedStackSize == commit_stack || broken(truncated),
|
|
|
|
"%u: CommittedStackSize wrong %lx / %lx\n", id, image.CommittedStackSize, commit_stack );
|
2016-08-08 16:20:50 +02:00
|
|
|
if (truncated)
|
|
|
|
ok( !image.SubSystemType || broken(truncated),
|
|
|
|
"%u: SubSystemType wrong %08x / 00000000\n", id, image.SubSystemType );
|
|
|
|
else
|
|
|
|
ok( image.SubSystemType == nt_header->OptionalHeader.Subsystem,
|
|
|
|
"%u: SubSystemType wrong %08x / %08x\n", id,
|
|
|
|
image.SubSystemType, nt_header->OptionalHeader.Subsystem );
|
2016-07-26 12:38:50 +02:00
|
|
|
ok( image.SubsystemVersionLow == nt_header->OptionalHeader.MinorSubsystemVersion,
|
|
|
|
"%u: SubsystemVersionLow wrong %04x / %04x\n", id,
|
|
|
|
image.SubsystemVersionLow, nt_header->OptionalHeader.MinorSubsystemVersion );
|
|
|
|
ok( image.SubsystemVersionHigh == nt_header->OptionalHeader.MajorSubsystemVersion,
|
|
|
|
"%u: SubsystemVersionHigh wrong %04x / %04x\n", id,
|
|
|
|
image.SubsystemVersionHigh, nt_header->OptionalHeader.MajorSubsystemVersion );
|
|
|
|
ok( image.ImageCharacteristics == nt_header->FileHeader.Characteristics,
|
|
|
|
"%u: ImageCharacteristics wrong %04x / %04x\n", id,
|
|
|
|
image.ImageCharacteristics, nt_header->FileHeader.Characteristics );
|
2016-07-27 09:09:40 +02:00
|
|
|
ok( image.DllCharacteristics == nt_header->OptionalHeader.DllCharacteristics || broken(truncated),
|
2016-07-26 12:38:50 +02:00
|
|
|
"%u: DllCharacteristics wrong %04x / %04x\n", id,
|
|
|
|
image.DllCharacteristics, nt_header->OptionalHeader.DllCharacteristics );
|
|
|
|
ok( image.Machine == nt_header->FileHeader.Machine, "%u: Machine wrong %04x / %04x\n", id,
|
|
|
|
image.Machine, nt_header->FileHeader.Machine );
|
2018-02-13 20:08:49 +01:00
|
|
|
ok( image.LoaderFlags == (cor_header != NULL), "%u: LoaderFlags wrong %08x\n", id, image.LoaderFlags );
|
2016-07-27 09:09:40 +02:00
|
|
|
ok( image.ImageFileSize == file_size || broken(!image.ImageFileSize), /* winxpsp1 */
|
|
|
|
"%u: ImageFileSize wrong %08x / %08x\n", id, image.ImageFileSize, file_size );
|
2016-07-26 12:38:50 +02:00
|
|
|
ok( image.CheckSum == nt_header->OptionalHeader.CheckSum, "%u: CheckSum wrong %08x / %08x\n", id,
|
|
|
|
image.CheckSum, nt_header->OptionalHeader.CheckSum );
|
2018-02-13 20:08:49 +01:00
|
|
|
|
2017-12-27 18:37:56 +01:00
|
|
|
if (nt_header->OptionalHeader.SizeOfCode || nt_header->OptionalHeader.AddressOfEntryPoint)
|
|
|
|
ok( image.ImageContainsCode == TRUE, "%u: ImageContainsCode wrong %u\n", id,
|
|
|
|
image.ImageContainsCode );
|
|
|
|
else if ((nt_header->OptionalHeader.SectionAlignment % page_size) ||
|
|
|
|
(nt_header->FileHeader.NumberOfSections == 1 &&
|
|
|
|
(section.Characteristics & IMAGE_SCN_MEM_EXECUTE)))
|
|
|
|
ok( image.ImageContainsCode == TRUE || broken(!image.ImageContainsCode), /* <= win8 */
|
|
|
|
"%u: ImageContainsCode wrong %u\n", id, image.ImageContainsCode );
|
|
|
|
else
|
|
|
|
ok( !image.ImageContainsCode, "%u: ImageContainsCode wrong %u\n", id, image.ImageContainsCode );
|
2018-02-13 20:08:49 +01:00
|
|
|
|
|
|
|
if (cor_header &&
|
|
|
|
(cor_header->Flags & COMIMAGE_FLAGS_ILONLY) &&
|
|
|
|
(cor_header->MajorRuntimeVersion > 2 ||
|
|
|
|
(cor_header->MajorRuntimeVersion == 2 && cor_header->MinorRuntimeVersion >= 5)))
|
|
|
|
{
|
|
|
|
ok( S(U(image)).ComPlusILOnly || broken(is_winxp),
|
|
|
|
"%u: wrong ComPlusILOnly flags %02x\n", id, U(image).ImageFlags );
|
2018-02-15 08:07:09 +01:00
|
|
|
if (nt_header->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC &&
|
|
|
|
!(cor_header->Flags & COMIMAGE_FLAGS_32BITREQUIRED))
|
2018-02-13 20:08:49 +01:00
|
|
|
ok( S(U(image)).ComPlusNativeReady || broken(is_winxp),
|
|
|
|
"%u: wrong ComPlusNativeReady flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
else
|
|
|
|
ok( !S(U(image)).ComPlusNativeReady,
|
|
|
|
"%u: wrong ComPlusNativeReady flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok( !S(U(image)).ComPlusILOnly, "%u: wrong ComPlusILOnly flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
ok( !S(U(image)).ComPlusNativeReady, "%u: wrong ComPlusNativeReady flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
}
|
|
|
|
if (!(nt_header->OptionalHeader.SectionAlignment % page_size))
|
|
|
|
ok( !S(U(image)).ImageMappedFlat, "%u: wrong ImageMappedFlat flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* winxp doesn't support any of the loader flags */
|
|
|
|
if (!S(U(image)).ImageMappedFlat) is_winxp = TRUE;
|
|
|
|
ok( S(U(image)).ImageMappedFlat || broken(is_winxp),
|
|
|
|
"%u: wrong ImageMappedFlat flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
}
|
|
|
|
if (!(nt_header->OptionalHeader.DllCharacteristics & IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE))
|
|
|
|
ok( !S(U(image)).ImageDynamicallyRelocated || broken( S(U(image)).ComPlusILOnly ), /* <= win7 */
|
|
|
|
"%u: wrong ImageDynamicallyRelocated flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
else if (image.ImageContainsCode && !cor_header)
|
|
|
|
ok( S(U(image)).ImageDynamicallyRelocated || broken(is_winxp),
|
|
|
|
"%u: wrong ImageDynamicallyRelocated flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
else
|
|
|
|
ok( !S(U(image)).ImageDynamicallyRelocated || broken(TRUE), /* <= win8 */
|
|
|
|
"%u: wrong ImageDynamicallyRelocated flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
ok( !S(U(image)).BaseBelow4gb, "%u: wrong BaseBelow4gb flags %02x\n", id, U(image).ImageFlags );
|
|
|
|
|
2016-07-26 12:38:50 +02:00
|
|
|
/* FIXME: needs more work: */
|
2016-07-27 09:09:40 +02:00
|
|
|
/* image.GpValue */
|
2016-07-27 09:49:37 +02:00
|
|
|
|
|
|
|
map_size.QuadPart = (nt_header->OptionalHeader.SizeOfImage + page_size - 1) & ~(page_size - 1);
|
|
|
|
status = pNtQuerySection( mapping, SectionBasicInformation, &info, sizeof(info), NULL );
|
|
|
|
ok( !status, "NtQuerySection failed err %x\n", status );
|
|
|
|
ok( info.Size.QuadPart == map_size.QuadPart, "NtQuerySection wrong size %x%08x / %x%08x\n",
|
|
|
|
info.Size.u.HighPart, info.Size.u.LowPart, map_size.u.HighPart, map_size.u.LowPart );
|
|
|
|
CloseHandle( mapping );
|
|
|
|
|
|
|
|
map_size.QuadPart = (nt_header->OptionalHeader.SizeOfImage + page_size - 1) & ~(page_size - 1);
|
|
|
|
status = pNtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_MAP_READ | SECTION_QUERY,
|
|
|
|
NULL, &map_size, PAGE_READONLY, SEC_IMAGE, file );
|
|
|
|
ok( !status, "%u: NtCreateSection failed err %x\n", id, status );
|
|
|
|
status = pNtQuerySection( mapping, SectionBasicInformation, &info, sizeof(info), NULL );
|
|
|
|
ok( !status, "NtQuerySection failed err %x\n", status );
|
|
|
|
ok( info.Size.QuadPart == map_size.QuadPart, "NtQuerySection wrong size %x%08x / %x%08x\n",
|
|
|
|
info.Size.u.HighPart, info.Size.u.LowPart, map_size.u.HighPart, map_size.u.LowPart );
|
|
|
|
CloseHandle( mapping );
|
|
|
|
|
|
|
|
map_size.QuadPart++;
|
|
|
|
status = pNtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_MAP_READ | SECTION_QUERY,
|
|
|
|
NULL, &map_size, PAGE_READONLY, SEC_IMAGE, file );
|
|
|
|
ok( status == STATUS_SECTION_TOO_BIG, "%u: NtCreateSection failed err %x\n", id, status );
|
|
|
|
|
|
|
|
SetFilePointerEx( file, map_size, NULL, FILE_BEGIN );
|
|
|
|
SetEndOfFile( file );
|
|
|
|
status = pNtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_MAP_READ | SECTION_QUERY,
|
|
|
|
NULL, &map_size, PAGE_READONLY, SEC_IMAGE, file );
|
|
|
|
ok( status == STATUS_SECTION_TOO_BIG, "%u: NtCreateSection failed err %x\n", id, status );
|
|
|
|
|
|
|
|
map_size.QuadPart = 1;
|
|
|
|
status = pNtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_MAP_READ | SECTION_QUERY,
|
|
|
|
NULL, &map_size, PAGE_READONLY, SEC_IMAGE, file );
|
|
|
|
ok( !status, "%u: NtCreateSection failed err %x\n", id, status );
|
|
|
|
status = pNtQuerySection( mapping, SectionBasicInformation, &info, sizeof(info), NULL );
|
|
|
|
ok( !status, "NtQuerySection failed err %x\n", status );
|
|
|
|
ok( info.Size.QuadPart == map_size.QuadPart, "NtQuerySection wrong size %x%08x / %x%08x\n",
|
|
|
|
info.Size.u.HighPart, info.Size.u.LowPart, map_size.u.HighPart, map_size.u.LowPart );
|
2016-07-26 12:38:50 +02:00
|
|
|
CloseHandle( mapping );
|
2016-07-27 09:49:37 +02:00
|
|
|
|
2016-07-26 12:38:50 +02:00
|
|
|
CloseHandle( file );
|
2018-02-13 20:08:49 +01:00
|
|
|
return image.ImageContainsCode && (!cor_header || !(cor_header->Flags & COMIMAGE_FLAGS_ILONLY));
|
2016-07-26 12:38:50 +02:00
|
|
|
}
|
|
|
|
|
2013-11-21 16:14:11 +01:00
|
|
|
/* helper to test image section mapping */
|
2018-02-13 20:08:49 +01:00
|
|
|
static NTSTATUS map_image_section( const IMAGE_NT_HEADERS *nt_header, const IMAGE_SECTION_HEADER *sections,
|
|
|
|
const void *section_data, int line )
|
2013-11-21 16:14:11 +01:00
|
|
|
{
|
|
|
|
char dll_name[MAX_PATH];
|
|
|
|
LARGE_INTEGER size;
|
|
|
|
HANDLE file, map;
|
|
|
|
NTSTATUS status;
|
2016-07-28 06:45:15 +02:00
|
|
|
ULONG file_size;
|
2017-12-27 18:51:01 +01:00
|
|
|
BOOL has_code;
|
|
|
|
HMODULE mod;
|
2013-11-21 16:14:11 +01:00
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
file_size = create_test_dll_sections( &dos_header, nt_header, sections, section_data, dll_name );
|
2013-11-21 16:14:11 +01:00
|
|
|
|
|
|
|
file = CreateFileA(dll_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "CreateFile error %d\n", GetLastError());
|
|
|
|
|
2016-07-28 06:45:15 +02:00
|
|
|
size.QuadPart = file_size;
|
2016-07-26 07:43:02 +02:00
|
|
|
status = pNtCreateSection(&map, STANDARD_RIGHTS_REQUIRED | SECTION_MAP_READ | SECTION_QUERY,
|
|
|
|
NULL, &size, PAGE_READONLY, SEC_IMAGE, file );
|
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
SECTION_BASIC_INFORMATION info;
|
2017-12-28 13:04:20 +01:00
|
|
|
SIZE_T info_size = 0xdeadbeef;
|
2016-07-26 07:43:02 +02:00
|
|
|
NTSTATUS ret = pNtQuerySection( map, SectionBasicInformation, &info, sizeof(info), &info_size );
|
|
|
|
ok( !ret, "NtQuerySection failed err %x\n", ret );
|
2017-12-28 13:04:20 +01:00
|
|
|
ok( info_size == sizeof(info), "NtQuerySection wrong size %lu\n", info_size );
|
2016-07-26 07:43:02 +02:00
|
|
|
ok( info.Attributes == (SEC_IMAGE | SEC_FILE), "NtQuerySection wrong attr %x\n", info.Attributes );
|
|
|
|
ok( info.BaseAddress == NULL, "NtQuerySection wrong base %p\n", info.BaseAddress );
|
2016-07-28 06:45:15 +02:00
|
|
|
ok( info.Size.QuadPart == file_size, "NtQuerySection wrong size %x%08x / %08x\n",
|
|
|
|
info.Size.u.HighPart, info.Size.u.LowPart, file_size );
|
2018-02-13 20:08:49 +01:00
|
|
|
has_code = query_image_section( line, dll_name, nt_header, section_data );
|
2017-12-27 18:51:01 +01:00
|
|
|
/* test loading dll of wrong 32/64 bitness */
|
2018-01-30 11:03:09 +01:00
|
|
|
if (nt_header->OptionalHeader.Magic == (is_win64 ? IMAGE_NT_OPTIONAL_HDR32_MAGIC
|
|
|
|
: IMAGE_NT_OPTIONAL_HDR64_MAGIC))
|
2017-12-27 18:51:01 +01:00
|
|
|
{
|
|
|
|
SetLastError( 0xdeadbeef );
|
|
|
|
mod = LoadLibraryExA( dll_name, 0, DONT_RESOLVE_DLL_REFERENCES );
|
|
|
|
if (!has_code && nt_header->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
|
|
|
|
{
|
2018-02-13 20:08:49 +01:00
|
|
|
BOOL il_only = FALSE;
|
|
|
|
if (((const IMAGE_NT_HEADERS32 *)nt_header)->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress)
|
|
|
|
{
|
|
|
|
const IMAGE_COR20_HEADER *cor_header = section_data;
|
|
|
|
il_only = (cor_header->Flags & COMIMAGE_FLAGS_ILONLY) != 0;
|
|
|
|
}
|
|
|
|
ok( mod != NULL || broken(il_only), /* <= win7 */
|
|
|
|
"%u: loading failed err %u\n", line, GetLastError() );
|
2017-12-27 18:51:01 +01:00
|
|
|
}
|
2018-01-30 14:16:34 +01:00
|
|
|
else
|
2017-12-27 18:51:01 +01:00
|
|
|
{
|
|
|
|
ok( !mod, "%u: loading succeeded\n", line );
|
|
|
|
ok( GetLastError() == ERROR_BAD_EXE_FORMAT, "%u: wrong error %u\n", line, GetLastError() );
|
|
|
|
}
|
|
|
|
if (mod) FreeLibrary( mod );
|
|
|
|
}
|
2016-07-26 07:43:02 +02:00
|
|
|
}
|
2013-11-21 16:14:11 +01:00
|
|
|
if (map) CloseHandle( map );
|
|
|
|
CloseHandle( file );
|
|
|
|
DeleteFileA( dll_name );
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-11-21 17:30:18 +01:00
|
|
|
|
2008-09-12 22:54:22 +02:00
|
|
|
static void test_Loader(void)
|
2006-11-16 16:50:57 +01:00
|
|
|
{
|
|
|
|
static const struct test_data
|
|
|
|
{
|
2006-12-09 13:26:30 +01:00
|
|
|
DWORD size_of_dos_header;
|
2006-11-28 11:38:07 +01:00
|
|
|
WORD number_of_sections, size_of_optional_header;
|
2006-11-16 16:50:57 +01:00
|
|
|
DWORD section_alignment, file_alignment;
|
|
|
|
DWORD size_of_image, size_of_headers;
|
2011-01-02 20:28:05 +01:00
|
|
|
DWORD errors[4]; /* 0 means LoadLibrary should succeed */
|
2006-11-16 16:50:57 +01:00
|
|
|
} td[] =
|
|
|
|
{
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
1, 0, 0, 0, 0, 0,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_BAD_EXE_FORMAT }
|
2006-11-16 16:50:57 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x1000,
|
2015-01-27 23:02:58 +01:00
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0xe00,
|
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER),
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_BAD_EXE_FORMAT } /* XP doesn't like too small image size */
|
2006-11-16 16:50:57 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x1000,
|
2015-01-27 23:02:58 +01:00
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
|
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER),
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS }
|
2006-11-16 16:50:57 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x1000,
|
2006-11-24 19:44:10 +01:00
|
|
|
0x1f00,
|
|
|
|
0x1000,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS }
|
2006-11-24 19:44:10 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
1, sizeof(IMAGE_OPTIONAL_HEADER), 0x200, 0x200,
|
2015-01-27 23:02:58 +01:00
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0x200,
|
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER),
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS, ERROR_INVALID_ADDRESS } /* vista is more strict */
|
2006-11-16 16:50:57 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
1, sizeof(IMAGE_OPTIONAL_HEADER), 0x200, 0x1000,
|
2015-01-27 23:02:58 +01:00
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
|
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER),
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_BAD_EXE_FORMAT } /* XP doesn't like alignments */
|
2006-11-16 16:50:57 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x200,
|
2015-01-27 23:02:58 +01:00
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
|
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER),
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS }
|
2006-11-16 16:50:57 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
1, sizeof(IMAGE_OPTIONAL_HEADER), 0x1000, 0x200,
|
2015-01-27 23:02:58 +01:00
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
|
2006-11-16 16:50:57 +01:00
|
|
|
0x200,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS }
|
2006-11-24 19:44:10 +01:00
|
|
|
},
|
|
|
|
/* Mandatory are all fields up to SizeOfHeaders, everything else
|
|
|
|
* is really optional (at least that's true for XP).
|
|
|
|
*/
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
1, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
|
2006-11-24 19:44:10 +01:00
|
|
|
sizeof(dos_header) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum) + sizeof(IMAGE_SECTION_HEADER) + 0x10,
|
|
|
|
sizeof(dos_header) + sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER) + FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum) + sizeof(IMAGE_SECTION_HEADER),
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS, ERROR_BAD_EXE_FORMAT, ERROR_INVALID_ADDRESS,
|
|
|
|
ERROR_NOACCESS }
|
2006-11-28 11:38:07 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
|
2006-11-28 11:38:07 +01:00
|
|
|
0xd0, /* beyond of the end of file */
|
|
|
|
0xc0, /* beyond of the end of file */
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS, ERROR_BAD_EXE_FORMAT } /* vista is more strict */
|
2006-11-28 11:38:07 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
|
2006-11-28 11:38:07 +01:00
|
|
|
0x1000,
|
|
|
|
0,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS, ERROR_BAD_EXE_FORMAT } /* vista is more strict */
|
2006-11-28 11:38:07 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
|
2006-11-28 11:38:07 +01:00
|
|
|
1,
|
|
|
|
0,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS, ERROR_BAD_EXE_FORMAT } /* vista is more strict */
|
2006-11-28 11:38:07 +01:00
|
|
|
},
|
2006-12-18 12:14:36 +01:00
|
|
|
#if 0 /* not power of 2 alignments need more test cases */
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-18 12:14:36 +01:00
|
|
|
0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x300, 0x300,
|
|
|
|
1,
|
|
|
|
0,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_BAD_EXE_FORMAT } /* alignment is not power of 2 */
|
2006-12-18 12:14:36 +01:00
|
|
|
},
|
|
|
|
#endif
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 4, 4,
|
2006-12-07 14:39:16 +01:00
|
|
|
1,
|
|
|
|
0,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS, ERROR_BAD_EXE_FORMAT } /* vista is more strict */
|
2006-12-07 14:39:16 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 1, 1,
|
2006-12-07 14:39:16 +01:00
|
|
|
1,
|
|
|
|
0,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS, ERROR_BAD_EXE_FORMAT } /* vista is more strict */
|
2006-12-07 14:39:16 +01:00
|
|
|
},
|
2013-11-21 17:30:18 +01:00
|
|
|
{ sizeof(dos_header),
|
2006-12-09 13:26:30 +01:00
|
|
|
0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum), 0x200, 0x200,
|
2006-11-28 11:38:07 +01:00
|
|
|
0,
|
|
|
|
0,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_BAD_EXE_FORMAT } /* image size == 0 -> failure */
|
2006-12-09 13:26:30 +01:00
|
|
|
},
|
|
|
|
/* the following data mimics the PE image which upack creates */
|
2013-11-21 17:30:18 +01:00
|
|
|
{ 0x10,
|
2006-12-09 13:26:30 +01:00
|
|
|
1, 0x148, 0x1000, 0x200,
|
2015-01-27 23:02:58 +01:00
|
|
|
sizeof(dos_header) + sizeof(nt_header_template) + sizeof(IMAGE_SECTION_HEADER) + 0x1000,
|
2006-12-09 13:26:30 +01:00
|
|
|
0x200,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS }
|
2006-12-09 13:26:30 +01:00
|
|
|
},
|
2006-12-18 12:14:36 +01:00
|
|
|
/* Minimal PE image that XP is able to load: 92 bytes */
|
2013-11-21 17:30:18 +01:00
|
|
|
{ 0x04,
|
2006-12-18 12:14:36 +01:00
|
|
|
0, FIELD_OFFSET(IMAGE_OPTIONAL_HEADER, CheckSum),
|
|
|
|
0x04 /* also serves as e_lfanew in the truncated MZ header */, 0x04,
|
|
|
|
1,
|
|
|
|
0,
|
2011-01-02 20:28:05 +01:00
|
|
|
{ ERROR_SUCCESS, ERROR_BAD_EXE_FORMAT } /* vista is more strict */
|
2015-07-13 08:17:32 +02:00
|
|
|
},
|
|
|
|
/* Minimal PE image that Windows7 is able to load: 268 bytes */
|
|
|
|
{ 0x04,
|
|
|
|
0, 0xf0, /* optional header size just forces 0xf0 bytes to be written,
|
|
|
|
0 or another number don't change the behaviour, what really
|
|
|
|
matters is file size regardless of values in the headers */
|
|
|
|
0x04 /* also serves as e_lfanew in the truncated MZ header */, 0x04,
|
|
|
|
0x40, /* minimal image size that Windows7 accepts */
|
|
|
|
0,
|
|
|
|
{ ERROR_SUCCESS }
|
2006-12-18 12:14:36 +01:00
|
|
|
}
|
2006-11-16 16:50:57 +01:00
|
|
|
};
|
|
|
|
int i;
|
2013-11-21 17:30:18 +01:00
|
|
|
DWORD file_size;
|
2017-08-28 14:19:47 +02:00
|
|
|
HANDLE h;
|
2007-05-15 18:10:29 +02:00
|
|
|
HMODULE hlib, hlib_as_data_file;
|
2006-11-16 16:50:57 +01:00
|
|
|
char dll_name[MAX_PATH];
|
2011-01-02 20:28:05 +01:00
|
|
|
SIZE_T size;
|
|
|
|
BOOL ret;
|
2013-11-21 16:14:11 +01:00
|
|
|
NTSTATUS status;
|
2018-02-13 20:08:49 +01:00
|
|
|
WORD alt_machine, orig_machine = nt_header_template.FileHeader.Machine;
|
2015-01-27 23:02:58 +01:00
|
|
|
IMAGE_NT_HEADERS nt_header;
|
2018-02-13 20:08:49 +01:00
|
|
|
IMAGE_COR20_HEADER cor_header;
|
2006-11-16 16:50:57 +01:00
|
|
|
|
|
|
|
/* prevent displaying of the "Unable to load this DLL" message box */
|
|
|
|
SetErrorMode(SEM_FAILCRITICALERRORS);
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(td); i++)
|
2006-11-16 16:50:57 +01:00
|
|
|
{
|
2015-01-27 23:02:58 +01:00
|
|
|
nt_header = nt_header_template;
|
2006-11-28 11:38:07 +01:00
|
|
|
nt_header.FileHeader.NumberOfSections = td[i].number_of_sections;
|
2006-11-16 16:50:57 +01:00
|
|
|
nt_header.FileHeader.SizeOfOptionalHeader = td[i].size_of_optional_header;
|
|
|
|
|
|
|
|
nt_header.OptionalHeader.SectionAlignment = td[i].section_alignment;
|
|
|
|
nt_header.OptionalHeader.FileAlignment = td[i].file_alignment;
|
2006-11-24 19:44:10 +01:00
|
|
|
nt_header.OptionalHeader.SizeOfImage = td[i].size_of_image;
|
2006-11-16 16:50:57 +01:00
|
|
|
nt_header.OptionalHeader.SizeOfHeaders = td[i].size_of_headers;
|
|
|
|
|
2013-11-21 17:30:18 +01:00
|
|
|
file_size = create_test_dll( &dos_header, td[i].size_of_dos_header, &nt_header, dll_name );
|
2006-11-24 19:44:10 +01:00
|
|
|
|
2006-11-16 16:50:57 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-01 23:09:53 +02:00
|
|
|
hlib = LoadLibraryA(dll_name);
|
2008-09-16 22:36:42 +02:00
|
|
|
if (hlib)
|
2006-11-16 16:50:57 +01:00
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION info;
|
2013-06-24 14:36:49 +02:00
|
|
|
void *ptr;
|
2006-11-16 16:50:57 +01:00
|
|
|
|
2011-01-02 20:28:05 +01:00
|
|
|
ok( td[i].errors[0] == ERROR_SUCCESS, "%d: should have failed\n", i );
|
2007-06-23 16:44:36 +02:00
|
|
|
|
2006-11-16 16:50:57 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-02 20:28:05 +01:00
|
|
|
size = VirtualQuery(hlib, &info, sizeof(info));
|
|
|
|
ok(size == sizeof(info),
|
2006-11-16 16:50:57 +01:00
|
|
|
"%d: VirtualQuery error %d\n", i, GetLastError());
|
|
|
|
ok(info.BaseAddress == hlib, "%d: %p != %p\n", i, info.BaseAddress, hlib);
|
|
|
|
ok(info.AllocationBase == hlib, "%d: %p != %p\n", i, info.AllocationBase, hlib);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, page_size), "%d: got %lx != expected %x\n",
|
|
|
|
i, info.RegionSize, ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, page_size));
|
2006-11-16 16:50:57 +01:00
|
|
|
ok(info.State == MEM_COMMIT, "%d: %x != MEM_COMMIT\n", i, info.State);
|
2013-11-21 15:54:51 +01:00
|
|
|
if (nt_header.OptionalHeader.SectionAlignment < page_size)
|
2006-11-16 16:50:57 +01:00
|
|
|
ok(info.Protect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.Protect);
|
|
|
|
else
|
|
|
|
ok(info.Protect == PAGE_READONLY, "%d: %x != PAGE_READONLY\n", i, info.Protect);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%d: %x != SEC_IMAGE\n", i, info.Type);
|
|
|
|
|
2013-06-24 14:36:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-21 15:54:51 +01:00
|
|
|
ptr = VirtualAlloc(hlib, page_size, MEM_COMMIT, info.Protect);
|
2013-06-24 14:36:49 +02:00
|
|
|
ok(!ptr, "%d: VirtualAlloc should fail\n", i);
|
2013-07-19 07:01:16 +02:00
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
|
2013-06-24 14:36:49 +02:00
|
|
|
|
2006-11-16 16:50:57 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-02 20:28:05 +01:00
|
|
|
size = VirtualQuery((char *)hlib + info.RegionSize, &info, sizeof(info));
|
|
|
|
ok(size == sizeof(info),
|
2006-11-16 16:50:57 +01:00
|
|
|
"%d: VirtualQuery error %d\n", i, GetLastError());
|
2013-11-21 15:54:51 +01:00
|
|
|
if (nt_header.OptionalHeader.SectionAlignment == page_size ||
|
2006-11-16 16:50:57 +01:00
|
|
|
nt_header.OptionalHeader.SectionAlignment == nt_header.OptionalHeader.FileAlignment)
|
|
|
|
{
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.BaseAddress == (char *)hlib + ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, page_size), "%d: got %p != expected %p\n",
|
|
|
|
i, info.BaseAddress, (char *)hlib + ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, page_size));
|
2006-11-16 16:50:57 +01:00
|
|
|
ok(info.AllocationBase == 0, "%d: %p != 0\n", i, info.AllocationBase);
|
|
|
|
ok(info.AllocationProtect == 0, "%d: %x != 0\n", i, info.AllocationProtect);
|
|
|
|
/*ok(info.RegionSize == not_practical_value, "%d: %lx != not_practical_value\n", i, info.RegionSize);*/
|
|
|
|
ok(info.State == MEM_FREE, "%d: %x != MEM_FREE\n", i, info.State);
|
|
|
|
ok(info.Type == 0, "%d: %x != 0\n", i, info.Type);
|
|
|
|
ok(info.Protect == PAGE_NOACCESS, "%d: %x != PAGE_NOACCESS\n", i, info.Protect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(info.Protect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.Protect);
|
2006-12-09 13:26:30 +01:00
|
|
|
ok(info.BaseAddress == hlib, "%d: got %p != expected %p\n", i, info.BaseAddress, hlib);
|
2006-11-16 16:50:57 +01:00
|
|
|
ok(info.AllocationBase == hlib, "%d: %p != %p\n", i, info.AllocationBase, hlib);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == ALIGN_SIZE(file_size, page_size), "%d: got %lx != expected %x\n",
|
|
|
|
i, info.RegionSize, ALIGN_SIZE(file_size, page_size));
|
2006-11-16 16:50:57 +01:00
|
|
|
ok(info.State == MEM_COMMIT, "%d: %x != MEM_COMMIT\n", i, info.State);
|
|
|
|
ok(info.Protect == PAGE_READONLY, "%d: %x != PAGE_READONLY\n", i, info.Protect);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%d: %x != SEC_IMAGE\n", i, info.Type);
|
|
|
|
}
|
|
|
|
|
2006-12-09 13:26:30 +01:00
|
|
|
/* header: check the zeroing of alignment */
|
2013-11-21 15:54:51 +01:00
|
|
|
if (nt_header.OptionalHeader.SectionAlignment >= page_size)
|
2006-12-09 13:26:30 +01:00
|
|
|
{
|
|
|
|
const char *start;
|
|
|
|
|
|
|
|
start = (const char *)hlib + nt_header.OptionalHeader.SizeOfHeaders;
|
2013-11-21 15:54:51 +01:00
|
|
|
size = ALIGN_SIZE((ULONG_PTR)start, page_size) - (ULONG_PTR)start;
|
2006-12-09 13:26:30 +01:00
|
|
|
ok(!memcmp(start, filler, size), "%d: header alignment is not cleared\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nt_header.FileHeader.NumberOfSections)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-02 20:28:05 +01:00
|
|
|
size = VirtualQuery((char *)hlib + section.VirtualAddress, &info, sizeof(info));
|
|
|
|
ok(size == sizeof(info),
|
2006-12-09 13:26:30 +01:00
|
|
|
"%d: VirtualQuery error %d\n", i, GetLastError());
|
2013-11-21 15:54:51 +01:00
|
|
|
if (nt_header.OptionalHeader.SectionAlignment < page_size)
|
2006-12-09 13:26:30 +01:00
|
|
|
{
|
2009-03-11 09:39:16 +01:00
|
|
|
ok(info.BaseAddress == hlib, "%d: got %p != expected %p\n", i, info.BaseAddress, hlib);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, page_size), "%d: got %lx != expected %x\n",
|
|
|
|
i, info.RegionSize, ALIGN_SIZE(nt_header.OptionalHeader.SizeOfImage, page_size));
|
2006-12-09 13:26:30 +01:00
|
|
|
ok(info.Protect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.Protect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(info.BaseAddress == (char *)hlib + section.VirtualAddress, "%d: got %p != expected %p\n", i, info.BaseAddress, (char *)hlib + section.VirtualAddress);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == ALIGN_SIZE(section.Misc.VirtualSize, page_size), "%d: got %lx != expected %x\n",
|
|
|
|
i, info.RegionSize, ALIGN_SIZE(section.Misc.VirtualSize, page_size));
|
2006-12-09 13:26:30 +01:00
|
|
|
ok(info.Protect == PAGE_READONLY, "%d: %x != PAGE_READONLY\n", i, info.Protect);
|
|
|
|
}
|
|
|
|
ok(info.AllocationBase == hlib, "%d: %p != %p\n", i, info.AllocationBase, hlib);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
|
|
|
|
ok(info.State == MEM_COMMIT, "%d: %x != MEM_COMMIT\n", i, info.State);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%d: %x != SEC_IMAGE\n", i, info.Type);
|
|
|
|
|
2013-11-21 15:54:51 +01:00
|
|
|
if (nt_header.OptionalHeader.SectionAlignment >= page_size)
|
2006-12-09 13:26:30 +01:00
|
|
|
ok(!memcmp((const char *)hlib + section.VirtualAddress + section.PointerToRawData, &nt_header, section.SizeOfRawData), "wrong section data\n");
|
|
|
|
else
|
|
|
|
ok(!memcmp((const char *)hlib + section.PointerToRawData, section_data, section.SizeOfRawData), "wrong section data\n");
|
|
|
|
|
|
|
|
/* check the zeroing of alignment */
|
2013-11-21 15:54:51 +01:00
|
|
|
if (nt_header.OptionalHeader.SectionAlignment >= page_size)
|
2006-12-09 13:26:30 +01:00
|
|
|
{
|
|
|
|
const char *start;
|
|
|
|
|
|
|
|
start = (const char *)hlib + section.VirtualAddress + section.PointerToRawData + section.SizeOfRawData;
|
2013-11-21 15:54:51 +01:00
|
|
|
size = ALIGN_SIZE((ULONG_PTR)start, page_size) - (ULONG_PTR)start;
|
2006-12-22 10:05:45 +01:00
|
|
|
ok(memcmp(start, filler, size), "%d: alignment should not be cleared\n", i);
|
2006-12-09 13:26:30 +01:00
|
|
|
}
|
2013-06-24 14:36:49 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-21 15:54:51 +01:00
|
|
|
ptr = VirtualAlloc((char *)hlib + section.VirtualAddress, page_size, MEM_COMMIT, info.Protect);
|
2013-06-24 14:36:49 +02:00
|
|
|
ok(!ptr, "%d: VirtualAlloc should fail\n", i);
|
2013-07-19 07:01:16 +02:00
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == ERROR_INVALID_ADDRESS,
|
|
|
|
"%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
|
2006-12-09 13:26:30 +01:00
|
|
|
}
|
|
|
|
|
2007-05-15 18:10:29 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
hlib_as_data_file = LoadLibraryExA(dll_name, 0, LOAD_LIBRARY_AS_DATAFILE);
|
2007-05-15 18:10:29 +02:00
|
|
|
ok(hlib_as_data_file != 0, "LoadLibraryEx error %u\n", GetLastError());
|
2007-05-16 16:58:51 +02:00
|
|
|
ok(hlib_as_data_file == hlib, "hlib_as_file and hlib are different\n");
|
2007-05-15 18:10:29 +02:00
|
|
|
|
2006-11-16 16:50:57 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-02 20:28:05 +01:00
|
|
|
ret = FreeLibrary(hlib);
|
|
|
|
ok(ret, "FreeLibrary error %d\n", GetLastError());
|
2007-05-15 18:10:29 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
hlib = GetModuleHandleA(dll_name);
|
2007-05-16 16:58:51 +02:00
|
|
|
ok(hlib != 0, "GetModuleHandle error %u\n", GetLastError());
|
2007-05-15 18:10:29 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-02 20:28:05 +01:00
|
|
|
ret = FreeLibrary(hlib_as_data_file);
|
|
|
|
ok(ret, "FreeLibrary error %d\n", GetLastError());
|
2007-05-15 18:10:29 +02:00
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
hlib = GetModuleHandleA(dll_name);
|
2007-05-15 18:10:29 +02:00
|
|
|
ok(!hlib, "GetModuleHandle should fail\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
hlib_as_data_file = LoadLibraryExA(dll_name, 0, LOAD_LIBRARY_AS_DATAFILE);
|
2007-05-15 18:10:29 +02:00
|
|
|
ok(hlib_as_data_file != 0, "LoadLibraryEx error %u\n", GetLastError());
|
2018-03-01 17:18:03 +01:00
|
|
|
ok(((ULONG_PTR)hlib_as_data_file & 3) == 1, "hlib_as_data_file got %p\n", hlib_as_data_file);
|
2007-05-15 18:10:29 +02:00
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
hlib = GetModuleHandleA(dll_name);
|
2007-05-15 18:10:29 +02:00
|
|
|
ok(!hlib, "GetModuleHandle should fail\n");
|
|
|
|
|
2017-08-28 14:19:47 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
h = CreateFileA( dll_name, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
ok( h != INVALID_HANDLE_VALUE, "open failed err %u\n", GetLastError() );
|
|
|
|
CloseHandle( h );
|
|
|
|
|
2007-05-15 18:10:29 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-02 20:28:05 +01:00
|
|
|
ret = FreeLibrary(hlib_as_data_file);
|
|
|
|
ok(ret, "FreeLibrary error %d\n", GetLastError());
|
2016-07-26 12:38:50 +02:00
|
|
|
|
2017-08-28 14:19:47 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hlib_as_data_file = LoadLibraryExA(dll_name, 0, LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE);
|
2018-03-01 17:18:03 +01:00
|
|
|
if (!((ULONG_PTR)hlib_as_data_file & 3) || /* winxp */
|
2017-08-28 14:19:47 +02:00
|
|
|
(!hlib_as_data_file && GetLastError() == ERROR_INVALID_PARAMETER)) /* w2k3 */
|
|
|
|
{
|
|
|
|
win_skip( "LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE not supported\n" );
|
|
|
|
FreeLibrary(hlib_as_data_file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(hlib_as_data_file != 0, "LoadLibraryEx error %u\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
h = CreateFileA( dll_name, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
|
2018-03-01 17:21:32 +01:00
|
|
|
ok( h == INVALID_HANDLE_VALUE, "open succeeded\n" );
|
|
|
|
ok( GetLastError() == ERROR_SHARING_VIOLATION, "wrong error %u\n", GetLastError() );
|
|
|
|
CloseHandle( h );
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
h = CreateFileA( dll_name, GENERIC_READ | DELETE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
|
|
|
|
ok( h != INVALID_HANDLE_VALUE, "open failed err %u\n", GetLastError() );
|
2017-08-28 14:19:47 +02:00
|
|
|
CloseHandle( h );
|
|
|
|
|
2018-03-01 17:18:03 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = FreeLibrary(hlib_as_data_file);
|
|
|
|
ok(ret, "FreeLibrary error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hlib_as_data_file = LoadLibraryExA(dll_name, 0, LOAD_LIBRARY_AS_IMAGE_RESOURCE);
|
|
|
|
if (!((ULONG_PTR)hlib_as_data_file & 3) || /* winxp */
|
|
|
|
(!hlib_as_data_file && GetLastError() == ERROR_INVALID_PARAMETER)) /* w2k3 */
|
|
|
|
{
|
|
|
|
win_skip( "LOAD_LIBRARY_AS_IMAGE_RESOURCE not supported\n" );
|
|
|
|
FreeLibrary(hlib_as_data_file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(hlib_as_data_file != 0, "LoadLibraryEx error %u\n", GetLastError());
|
|
|
|
ok(((ULONG_PTR)hlib_as_data_file & 3) == 2, "hlib_as_data_file got %p\n",
|
|
|
|
hlib_as_data_file);
|
|
|
|
|
|
|
|
hlib = GetModuleHandleA(dll_name);
|
|
|
|
ok(!hlib, "GetModuleHandle should fail\n");
|
|
|
|
|
2017-08-28 14:19:47 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = FreeLibrary(hlib_as_data_file);
|
|
|
|
ok(ret, "FreeLibrary error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
query_image_section( i, dll_name, &nt_header, NULL );
|
2006-11-16 16:50:57 +01:00
|
|
|
}
|
|
|
|
else
|
2008-09-16 22:36:42 +02:00
|
|
|
{
|
2011-01-02 20:28:05 +01:00
|
|
|
BOOL error_match;
|
|
|
|
int error_index;
|
2006-11-24 19:44:10 +01:00
|
|
|
|
2011-01-02 20:28:05 +01:00
|
|
|
error_match = FALSE;
|
|
|
|
for (error_index = 0;
|
2018-06-27 20:56:45 +02:00
|
|
|
! error_match && error_index < ARRAY_SIZE(td[i].errors);
|
2011-01-02 20:28:05 +01:00
|
|
|
error_index++)
|
|
|
|
{
|
|
|
|
error_match = td[i].errors[error_index] == GetLastError();
|
|
|
|
}
|
|
|
|
ok(error_match, "%d: unexpected error %d\n", i, GetLastError());
|
2006-11-24 19:44:10 +01:00
|
|
|
}
|
2006-11-16 16:50:57 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = DeleteFileA(dll_name);
|
2011-01-11 20:30:00 +01:00
|
|
|
ok(ret, "DeleteFile error %d\n", GetLastError());
|
2006-11-16 16:50:57 +01:00
|
|
|
}
|
2013-11-21 16:14:11 +01:00
|
|
|
|
2015-01-27 23:02:58 +01:00
|
|
|
nt_header = nt_header_template;
|
2013-11-21 16:14:11 +01:00
|
|
|
nt_header.FileHeader.NumberOfSections = 1;
|
|
|
|
nt_header.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
|
|
|
|
|
|
|
|
nt_header.OptionalHeader.SectionAlignment = page_size;
|
2016-07-26 12:38:50 +02:00
|
|
|
nt_header.OptionalHeader.AddressOfEntryPoint = 0x1234;
|
|
|
|
nt_header.OptionalHeader.DllCharacteristics = IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
|
2013-11-21 16:14:11 +01:00
|
|
|
nt_header.OptionalHeader.FileAlignment = page_size;
|
|
|
|
nt_header.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER);
|
2015-01-27 23:02:58 +01:00
|
|
|
nt_header.OptionalHeader.SizeOfImage = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + page_size;
|
2013-11-21 16:14:11 +01:00
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
section.SizeOfRawData = sizeof(section_data);
|
|
|
|
section.PointerToRawData = page_size;
|
|
|
|
section.VirtualAddress = page_size;
|
|
|
|
section.Misc.VirtualSize = page_size;
|
|
|
|
|
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt_header.OptionalHeader.DllCharacteristics = IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE;
|
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
2013-11-21 16:14:11 +01:00
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
nt_header.OptionalHeader.SizeOfCode = 0x1000;
|
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
nt_header.OptionalHeader.SizeOfCode = 0;
|
|
|
|
nt_header.OptionalHeader.DllCharacteristics = IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
|
|
|
|
|
2013-11-21 16:14:11 +01:00
|
|
|
dos_header.e_magic = 0;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
2013-11-21 17:29:51 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_NOT_MZ, "NtCreateSection error %08x\n", status );
|
2013-11-21 16:14:11 +01:00
|
|
|
|
|
|
|
dos_header.e_magic = IMAGE_DOS_SIGNATURE;
|
|
|
|
nt_header.Signature = IMAGE_OS2_SIGNATURE;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
2013-11-21 17:29:51 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_NE_FORMAT, "NtCreateSection error %08x\n", status );
|
2013-11-21 16:14:11 +01:00
|
|
|
|
|
|
|
nt_header.Signature = 0xdeadbeef;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
2013-11-21 17:29:51 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_PROTECT, "NtCreateSection error %08x\n", status );
|
2013-11-21 16:14:11 +01:00
|
|
|
|
|
|
|
nt_header.Signature = IMAGE_NT_SIGNATURE;
|
|
|
|
nt_header.OptionalHeader.Magic = 0xdead;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
2013-11-21 17:29:51 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_FORMAT, "NtCreateSection error %08x\n", status );
|
2013-11-21 16:14:11 +01:00
|
|
|
|
|
|
|
nt_header.OptionalHeader.Magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
|
|
|
|
nt_header.FileHeader.Machine = 0xdead;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
2013-11-21 17:29:51 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_FORMAT || broken(status == STATUS_SUCCESS), /* win2k */
|
|
|
|
"NtCreateSection error %08x\n", status );
|
2013-11-21 16:14:11 +01:00
|
|
|
|
|
|
|
nt_header.FileHeader.Machine = IMAGE_FILE_MACHINE_UNKNOWN;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
2013-11-21 17:29:51 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_FORMAT || broken(status == STATUS_SUCCESS), /* win2k */
|
2018-01-11 09:56:44 +01:00
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
switch (orig_machine)
|
|
|
|
{
|
2018-02-13 20:08:49 +01:00
|
|
|
case IMAGE_FILE_MACHINE_I386: alt_machine = IMAGE_FILE_MACHINE_ARMNT; break;
|
|
|
|
case IMAGE_FILE_MACHINE_AMD64: alt_machine = IMAGE_FILE_MACHINE_ARM64; break;
|
|
|
|
case IMAGE_FILE_MACHINE_ARMNT: alt_machine = IMAGE_FILE_MACHINE_I386; break;
|
|
|
|
case IMAGE_FILE_MACHINE_ARM64: alt_machine = IMAGE_FILE_MACHINE_AMD64; break;
|
2018-01-11 09:56:44 +01:00
|
|
|
}
|
2018-02-13 20:08:49 +01:00
|
|
|
nt_header.FileHeader.Machine = alt_machine;
|
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
2018-01-11 09:56:44 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_FORMAT || broken(status == STATUS_SUCCESS), /* win2k */
|
2013-11-21 17:29:51 +01:00
|
|
|
"NtCreateSection error %08x\n", status );
|
2013-11-21 16:14:11 +01:00
|
|
|
|
|
|
|
switch (orig_machine)
|
|
|
|
{
|
2018-02-13 20:08:49 +01:00
|
|
|
case IMAGE_FILE_MACHINE_I386: alt_machine = IMAGE_FILE_MACHINE_AMD64; break;
|
|
|
|
case IMAGE_FILE_MACHINE_AMD64: alt_machine = IMAGE_FILE_MACHINE_I386; break;
|
|
|
|
case IMAGE_FILE_MACHINE_ARMNT: alt_machine = IMAGE_FILE_MACHINE_ARM64; break;
|
|
|
|
case IMAGE_FILE_MACHINE_ARM64: alt_machine = IMAGE_FILE_MACHINE_ARMNT; break;
|
2013-11-21 16:14:11 +01:00
|
|
|
}
|
2018-02-13 20:08:49 +01:00
|
|
|
nt_header.FileHeader.Machine = alt_machine;
|
|
|
|
status = map_image_section( &nt_header, §ion, section_data, __LINE__ );
|
2013-11-21 17:29:51 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_FORMAT || broken(status == STATUS_SUCCESS), /* win2k */
|
2013-11-21 16:14:11 +01:00
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
nt_header.FileHeader.Machine = orig_machine;
|
|
|
|
nt_header.OptionalHeader.NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES;
|
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress = page_size;
|
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size = sizeof(cor_header);
|
|
|
|
section.SizeOfRawData = sizeof(cor_header);
|
|
|
|
|
|
|
|
memset( &cor_header, 0, sizeof(cor_header) );
|
|
|
|
cor_header.cb = sizeof(cor_header);
|
|
|
|
cor_header.MajorRuntimeVersion = 2;
|
|
|
|
cor_header.MinorRuntimeVersion = 4;
|
|
|
|
cor_header.Flags = COMIMAGE_FLAGS_ILONLY;
|
|
|
|
U(cor_header).EntryPointToken = 0xbeef;
|
|
|
|
status = map_image_section( &nt_header, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
cor_header.MinorRuntimeVersion = 5;
|
|
|
|
status = map_image_section( &nt_header, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
cor_header.MajorRuntimeVersion = 3;
|
|
|
|
cor_header.MinorRuntimeVersion = 0;
|
|
|
|
status = map_image_section( &nt_header, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-15 08:07:09 +01:00
|
|
|
cor_header.Flags = COMIMAGE_FLAGS_ILONLY | COMIMAGE_FLAGS_32BITREQUIRED;
|
|
|
|
status = map_image_section( &nt_header, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
cor_header.Flags = COMIMAGE_FLAGS_ILONLY | COMIMAGE_FLAGS_32BITPREFERRED;
|
|
|
|
status = map_image_section( &nt_header, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
cor_header.Flags = 0;
|
|
|
|
status = map_image_section( &nt_header, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress = 1;
|
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size = 1;
|
|
|
|
status = map_image_section( &nt_header, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
2013-11-21 16:14:11 +01:00
|
|
|
if (nt_header.OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS64 nt64;
|
|
|
|
|
|
|
|
memset( &nt64, 0, sizeof(nt64) );
|
|
|
|
nt64.Signature = IMAGE_NT_SIGNATURE;
|
|
|
|
nt64.FileHeader.Machine = orig_machine;
|
|
|
|
nt64.FileHeader.NumberOfSections = 1;
|
|
|
|
nt64.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER64);
|
2017-12-19 14:33:25 +01:00
|
|
|
nt64.FileHeader.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DLL;
|
2013-11-21 16:14:11 +01:00
|
|
|
nt64.OptionalHeader.Magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
|
|
|
|
nt64.OptionalHeader.MajorLinkerVersion = 1;
|
2017-12-19 14:33:25 +01:00
|
|
|
nt64.OptionalHeader.SizeOfCode = 0x1000;
|
|
|
|
nt64.OptionalHeader.AddressOfEntryPoint = 0x1000;
|
2013-11-21 16:14:11 +01:00
|
|
|
nt64.OptionalHeader.ImageBase = 0x10000000;
|
2017-12-19 14:33:25 +01:00
|
|
|
nt64.OptionalHeader.SectionAlignment = 0x1000;
|
|
|
|
nt64.OptionalHeader.FileAlignment = 0x1000;
|
2013-11-21 16:14:11 +01:00
|
|
|
nt64.OptionalHeader.MajorOperatingSystemVersion = 4;
|
|
|
|
nt64.OptionalHeader.MajorImageVersion = 1;
|
|
|
|
nt64.OptionalHeader.MajorSubsystemVersion = 4;
|
|
|
|
nt64.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt64) + sizeof(IMAGE_SECTION_HEADER);
|
|
|
|
nt64.OptionalHeader.SizeOfImage = nt64.OptionalHeader.SizeOfHeaders + 0x1000;
|
|
|
|
nt64.OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
|
2017-12-19 14:33:25 +01:00
|
|
|
nt64.OptionalHeader.SizeOfStackReserve = 0x321000;
|
|
|
|
nt64.OptionalHeader.SizeOfStackCommit = 0x123000;
|
|
|
|
section.Characteristics = IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_EXECUTE;
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, section_data, __LINE__ );
|
2017-12-19 14:33:25 +01:00
|
|
|
ok( status == (is_wow64 ? STATUS_INVALID_IMAGE_FORMAT : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
switch (orig_machine)
|
|
|
|
{
|
|
|
|
case IMAGE_FILE_MACHINE_I386: nt64.FileHeader.Machine = IMAGE_FILE_MACHINE_ARM64; break;
|
|
|
|
case IMAGE_FILE_MACHINE_ARMNT: nt64.FileHeader.Machine = IMAGE_FILE_MACHINE_AMD64; break;
|
|
|
|
}
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, section_data, __LINE__ );
|
2017-12-19 14:33:25 +01:00
|
|
|
ok( status == (is_wow64 ? STATUS_INVALID_IMAGE_FORMAT : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
nt64.FileHeader.Machine = alt_machine;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, section_data, __LINE__ );
|
2017-12-19 14:33:25 +01:00
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
2017-12-27 18:37:56 +01:00
|
|
|
|
|
|
|
nt64.OptionalHeader.SizeOfCode = 0;
|
|
|
|
nt64.OptionalHeader.AddressOfEntryPoint = 0x1000;
|
|
|
|
section.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, section_data, __LINE__ );
|
2017-12-27 18:37:56 +01:00
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt64.OptionalHeader.SizeOfCode = 0;
|
|
|
|
nt64.OptionalHeader.AddressOfEntryPoint = 0;
|
|
|
|
section.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, section_data, __LINE__ );
|
2017-12-27 18:37:56 +01:00
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt64.OptionalHeader.SizeOfCode = 0x1000;
|
|
|
|
nt64.OptionalHeader.AddressOfEntryPoint = 0;
|
2018-02-13 20:08:49 +01:00
|
|
|
nt64.OptionalHeader.DllCharacteristics = IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE;
|
2017-12-27 18:37:56 +01:00
|
|
|
section.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, section_data, __LINE__ );
|
2017-12-27 18:37:56 +01:00
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt64.OptionalHeader.SizeOfCode = 0;
|
|
|
|
nt64.OptionalHeader.AddressOfEntryPoint = 0;
|
|
|
|
section.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, section_data, __LINE__ );
|
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt64.OptionalHeader.NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES;
|
|
|
|
nt64.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress = page_size;
|
|
|
|
nt64.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size = sizeof(cor_header);
|
|
|
|
cor_header.MajorRuntimeVersion = 2;
|
|
|
|
cor_header.MinorRuntimeVersion = 4;
|
|
|
|
cor_header.Flags = COMIMAGE_FLAGS_ILONLY;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt64.OptionalHeader.SizeOfCode = 0x1000;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
cor_header.MinorRuntimeVersion = 5;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-15 08:07:09 +01:00
|
|
|
cor_header.Flags = COMIMAGE_FLAGS_ILONLY | COMIMAGE_FLAGS_32BITREQUIRED;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
cor_header.Flags = COMIMAGE_FLAGS_ILONLY | COMIMAGE_FLAGS_32BITPREFERRED;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
cor_header.Flags = 0;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress = 1;
|
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size = 1;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt64, §ion, &cor_header, __LINE__ );
|
2017-12-27 18:37:56 +01:00
|
|
|
ok( status == (is_wow64 ? STATUS_SUCCESS : STATUS_INVALID_IMAGE_WIN_64),
|
|
|
|
"NtCreateSection error %08x\n", status );
|
2013-11-21 16:14:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS32 nt32;
|
|
|
|
|
|
|
|
memset( &nt32, 0, sizeof(nt32) );
|
|
|
|
nt32.Signature = IMAGE_NT_SIGNATURE;
|
|
|
|
nt32.FileHeader.Machine = orig_machine;
|
|
|
|
nt32.FileHeader.NumberOfSections = 1;
|
|
|
|
nt32.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER32);
|
2017-12-19 14:33:25 +01:00
|
|
|
nt32.FileHeader.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DLL;
|
2013-11-21 16:14:11 +01:00
|
|
|
nt32.OptionalHeader.Magic = IMAGE_NT_OPTIONAL_HDR32_MAGIC;
|
|
|
|
nt32.OptionalHeader.MajorLinkerVersion = 1;
|
2017-12-19 14:33:25 +01:00
|
|
|
nt32.OptionalHeader.SizeOfCode = 0x1000;
|
|
|
|
nt32.OptionalHeader.AddressOfEntryPoint = 0x1000;
|
2013-11-21 16:14:11 +01:00
|
|
|
nt32.OptionalHeader.ImageBase = 0x10000000;
|
2017-12-19 14:33:25 +01:00
|
|
|
nt32.OptionalHeader.SectionAlignment = 0x1000;
|
|
|
|
nt32.OptionalHeader.FileAlignment = 0x1000;
|
2013-11-21 16:14:11 +01:00
|
|
|
nt32.OptionalHeader.MajorOperatingSystemVersion = 4;
|
|
|
|
nt32.OptionalHeader.MajorImageVersion = 1;
|
|
|
|
nt32.OptionalHeader.MajorSubsystemVersion = 4;
|
|
|
|
nt32.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt32) + sizeof(IMAGE_SECTION_HEADER);
|
|
|
|
nt32.OptionalHeader.SizeOfImage = nt32.OptionalHeader.SizeOfHeaders + 0x1000;
|
|
|
|
nt32.OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
|
2017-12-19 14:33:25 +01:00
|
|
|
nt32.OptionalHeader.SizeOfStackReserve = 0x321000;
|
|
|
|
nt32.OptionalHeader.SizeOfStackCommit = 0x123000;
|
|
|
|
section.Characteristics = IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_EXECUTE;
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, section_data, __LINE__ );
|
2013-11-21 17:29:51 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_FORMAT, "NtCreateSection error %08x\n", status );
|
2017-12-19 14:33:25 +01:00
|
|
|
|
|
|
|
switch (orig_machine)
|
|
|
|
{
|
|
|
|
case IMAGE_FILE_MACHINE_AMD64: nt32.FileHeader.Machine = IMAGE_FILE_MACHINE_ARMNT; break;
|
|
|
|
case IMAGE_FILE_MACHINE_ARM64: nt32.FileHeader.Machine = IMAGE_FILE_MACHINE_I386; break;
|
|
|
|
}
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, section_data, __LINE__ );
|
2017-12-19 14:33:25 +01:00
|
|
|
ok( status == STATUS_INVALID_IMAGE_FORMAT || broken(!status) /* win8 */,
|
|
|
|
"NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
nt32.FileHeader.Machine = alt_machine;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, section_data, __LINE__ );
|
2017-12-19 14:33:25 +01:00
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
2017-12-27 18:37:56 +01:00
|
|
|
|
|
|
|
nt32.OptionalHeader.SizeOfCode = 0;
|
|
|
|
nt32.OptionalHeader.AddressOfEntryPoint = 0x1000;
|
|
|
|
section.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, section_data, __LINE__ );
|
2017-12-27 18:37:56 +01:00
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt32.OptionalHeader.SizeOfCode = 0;
|
|
|
|
nt32.OptionalHeader.AddressOfEntryPoint = 0;
|
|
|
|
section.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, section_data, __LINE__ );
|
2017-12-27 18:37:56 +01:00
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt32.OptionalHeader.SizeOfCode = 0x1000;
|
|
|
|
nt32.OptionalHeader.AddressOfEntryPoint = 0;
|
2018-02-13 20:08:49 +01:00
|
|
|
nt32.OptionalHeader.DllCharacteristics = IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE;
|
2017-12-27 18:37:56 +01:00
|
|
|
section.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, section_data, __LINE__ );
|
2017-12-27 18:37:56 +01:00
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt32.OptionalHeader.SizeOfCode = 0;
|
|
|
|
nt32.OptionalHeader.AddressOfEntryPoint = 0;
|
|
|
|
section.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_CODE;
|
2018-02-13 20:08:49 +01:00
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, section_data, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt32.OptionalHeader.NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES;
|
|
|
|
nt32.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress = page_size;
|
|
|
|
nt32.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size = sizeof(cor_header);
|
|
|
|
cor_header.MajorRuntimeVersion = 2;
|
|
|
|
cor_header.MinorRuntimeVersion = 4;
|
|
|
|
cor_header.Flags = COMIMAGE_FLAGS_ILONLY;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt32.OptionalHeader.SizeOfCode = 0x1000;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
cor_header.MinorRuntimeVersion = 5;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-15 08:07:09 +01:00
|
|
|
cor_header.Flags = COMIMAGE_FLAGS_ILONLY | COMIMAGE_FLAGS_32BITREQUIRED;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
cor_header.Flags = COMIMAGE_FLAGS_ILONLY | COMIMAGE_FLAGS_32BITPREFERRED;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
2018-02-13 20:08:49 +01:00
|
|
|
cor_header.Flags = 0;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, &cor_header, __LINE__ );
|
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
|
|
|
|
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress = 1;
|
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].Size = 1;
|
|
|
|
status = map_image_section( (IMAGE_NT_HEADERS *)&nt32, §ion, &cor_header, __LINE__ );
|
2017-12-27 18:37:56 +01:00
|
|
|
ok( status == STATUS_SUCCESS, "NtCreateSection error %08x\n", status );
|
2013-11-21 16:14:11 +01:00
|
|
|
}
|
|
|
|
|
2017-12-19 14:33:25 +01:00
|
|
|
section.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ;
|
2006-11-16 16:50:57 +01:00
|
|
|
}
|
2008-09-12 22:54:22 +02:00
|
|
|
|
2018-02-27 18:20:41 +01:00
|
|
|
static void test_filenames(void)
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS nt_header = nt_header_template;
|
|
|
|
char dll_name[MAX_PATH], long_path[MAX_PATH], short_path[MAX_PATH], buffer[MAX_PATH];
|
|
|
|
HMODULE mod, mod2;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
nt_header.FileHeader.NumberOfSections = 1;
|
|
|
|
nt_header.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
|
|
|
|
|
|
|
|
nt_header.OptionalHeader.SectionAlignment = page_size;
|
|
|
|
nt_header.OptionalHeader.DllCharacteristics = IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
|
|
|
|
nt_header.OptionalHeader.FileAlignment = page_size;
|
|
|
|
nt_header.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER);
|
|
|
|
nt_header.OptionalHeader.SizeOfImage = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + page_size;
|
|
|
|
|
|
|
|
create_test_dll( &dos_header, sizeof(dos_header), &nt_header, dll_name );
|
|
|
|
strcpy( long_path, dll_name );
|
|
|
|
strcpy( strrchr( long_path, '\\' ), "\\this-is-a-long-name.dll" );
|
|
|
|
ret = MoveFileA( dll_name, long_path );
|
|
|
|
ok( ret, "MoveFileA failed err %u\n", GetLastError() );
|
|
|
|
GetShortPathNameA( long_path, short_path, MAX_PATH );
|
|
|
|
|
|
|
|
mod = LoadLibraryA( short_path );
|
|
|
|
ok( mod != NULL, "loading failed err %u\n", GetLastError() );
|
|
|
|
GetModuleFileNameA( mod, buffer, MAX_PATH );
|
|
|
|
ok( !lstrcmpiA( buffer, short_path ), "got wrong path %s / %s\n", buffer, short_path );
|
|
|
|
mod2 = GetModuleHandleA( short_path );
|
|
|
|
ok( mod == mod2, "wrong module %p for %s\n", mod2, short_path );
|
|
|
|
mod2 = GetModuleHandleA( long_path );
|
|
|
|
ok( mod == mod2, "wrong module %p for %s\n", mod2, long_path );
|
|
|
|
mod2 = LoadLibraryA( long_path );
|
|
|
|
ok( mod2 != NULL, "loading failed err %u\n", GetLastError() );
|
|
|
|
ok( mod == mod2, "library loaded twice\n" );
|
|
|
|
GetModuleFileNameA( mod2, buffer, MAX_PATH );
|
|
|
|
ok( !lstrcmpiA( buffer, short_path ), "got wrong path %s / %s\n", buffer, short_path );
|
|
|
|
FreeLibrary( mod2 );
|
|
|
|
FreeLibrary( mod );
|
|
|
|
|
|
|
|
mod = LoadLibraryA( long_path );
|
|
|
|
ok( mod != NULL, "loading failed err %u\n", GetLastError() );
|
|
|
|
GetModuleFileNameA( mod, buffer, MAX_PATH );
|
|
|
|
ok( !lstrcmpiA( buffer, long_path ), "got wrong path %s / %s\n", buffer, long_path );
|
|
|
|
mod2 = GetModuleHandleA( short_path );
|
|
|
|
ok( mod == mod2, "wrong module %p for %s\n", mod2, short_path );
|
|
|
|
mod2 = GetModuleHandleA( long_path );
|
|
|
|
ok( mod == mod2, "wrong module %p for %s\n", mod2, long_path );
|
|
|
|
mod2 = LoadLibraryA( short_path );
|
|
|
|
ok( mod2 != NULL, "loading failed err %u\n", GetLastError() );
|
|
|
|
ok( mod == mod2, "library loaded twice\n" );
|
|
|
|
GetModuleFileNameA( mod2, buffer, MAX_PATH );
|
|
|
|
ok( !lstrcmpiA( buffer, long_path ), "got wrong path %s / %s\n", buffer, long_path );
|
|
|
|
FreeLibrary( mod2 );
|
|
|
|
FreeLibrary( mod );
|
|
|
|
|
|
|
|
strcpy( dll_name, long_path );
|
|
|
|
strcpy( strrchr( dll_name, '\\' ), "\\this-is-another-name.dll" );
|
|
|
|
ret = CreateHardLinkA( dll_name, long_path, NULL );
|
|
|
|
ok( ret, "CreateHardLinkA failed err %u\n", GetLastError() );
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
mod = LoadLibraryA( dll_name );
|
|
|
|
ok( mod != NULL, "loading failed err %u\n", GetLastError() );
|
|
|
|
GetModuleFileNameA( mod, buffer, MAX_PATH );
|
|
|
|
ok( !lstrcmpiA( buffer, dll_name ), "got wrong path %s / %s\n", buffer, dll_name );
|
|
|
|
mod2 = GetModuleHandleA( long_path );
|
|
|
|
ok( mod == mod2, "wrong module %p for %s\n", mod2, long_path );
|
|
|
|
mod2 = LoadLibraryA( long_path );
|
|
|
|
ok( mod2 != NULL, "loading failed err %u\n", GetLastError() );
|
|
|
|
ok( mod == mod2, "library loaded twice\n" );
|
|
|
|
GetModuleFileNameA( mod2, buffer, MAX_PATH );
|
|
|
|
ok( !lstrcmpiA( buffer, dll_name ), "got wrong path %s / %s\n", buffer, short_path );
|
|
|
|
FreeLibrary( mod2 );
|
|
|
|
FreeLibrary( mod );
|
|
|
|
DeleteFileA( dll_name );
|
|
|
|
}
|
|
|
|
DeleteFileA( long_path );
|
|
|
|
}
|
|
|
|
|
2008-09-12 22:54:22 +02:00
|
|
|
/* Verify linking style of import descriptors */
|
|
|
|
static void test_ImportDescriptors(void)
|
|
|
|
{
|
|
|
|
HMODULE kernel32_module = NULL;
|
|
|
|
PIMAGE_DOS_HEADER d_header;
|
|
|
|
PIMAGE_NT_HEADERS nt_headers;
|
|
|
|
DWORD import_dir_size;
|
|
|
|
DWORD_PTR dir_offset;
|
|
|
|
PIMAGE_IMPORT_DESCRIPTOR import_chunk;
|
|
|
|
|
|
|
|
/* Load kernel32 module */
|
|
|
|
kernel32_module = GetModuleHandleA("kernel32.dll");
|
|
|
|
assert( kernel32_module != NULL );
|
|
|
|
|
|
|
|
/* Get PE header info from module image */
|
|
|
|
d_header = (PIMAGE_DOS_HEADER) kernel32_module;
|
|
|
|
nt_headers = (PIMAGE_NT_HEADERS) (((char*) d_header) +
|
|
|
|
d_header->e_lfanew);
|
|
|
|
|
|
|
|
/* Get size of import entry directory */
|
|
|
|
import_dir_size = nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size;
|
|
|
|
if (!import_dir_size)
|
|
|
|
{
|
|
|
|
skip("Unable to continue testing due to missing import directory.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get address of first import chunk */
|
|
|
|
dir_offset = nt_headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
|
|
|
|
import_chunk = RVAToAddr(dir_offset, kernel32_module);
|
|
|
|
ok(import_chunk != 0, "Invalid import_chunk: %p\n", import_chunk);
|
|
|
|
if (!import_chunk) return;
|
|
|
|
|
|
|
|
/* Iterate through import descriptors and verify set name,
|
|
|
|
* OriginalFirstThunk, and FirstThunk. Core Windows DLLs, such as
|
|
|
|
* kernel32.dll, don't use Borland-style linking, where the table of
|
|
|
|
* imported names is stored directly in FirstThunk and overwritten
|
|
|
|
* by the relocation, instead of being stored in OriginalFirstThunk.
|
|
|
|
* */
|
|
|
|
for (; import_chunk->FirstThunk; import_chunk++)
|
|
|
|
{
|
2008-11-28 23:43:31 +01:00
|
|
|
LPCSTR module_name = RVAToAddr(import_chunk->Name, kernel32_module);
|
|
|
|
PIMAGE_THUNK_DATA name_table = RVAToAddr(
|
2008-09-20 13:26:20 +02:00
|
|
|
U(*import_chunk).OriginalFirstThunk, kernel32_module);
|
2008-11-28 23:43:31 +01:00
|
|
|
PIMAGE_THUNK_DATA iat = RVAToAddr(
|
2008-09-12 22:54:22 +02:00
|
|
|
import_chunk->FirstThunk, kernel32_module);
|
|
|
|
ok(module_name != NULL, "Imported module name should not be NULL\n");
|
|
|
|
ok(name_table != NULL,
|
|
|
|
"Name table for imported module %s should not be NULL\n",
|
|
|
|
module_name);
|
|
|
|
ok(iat != NULL, "IAT for imported module %s should not be NULL\n",
|
|
|
|
module_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-24 09:33:14 +01:00
|
|
|
static void test_image_mapping(const char *dll_name, DWORD scn_page_access, BOOL is_dll)
|
2012-02-20 09:01:25 +01:00
|
|
|
{
|
|
|
|
HANDLE hfile, hmap;
|
|
|
|
NTSTATUS status;
|
|
|
|
LARGE_INTEGER offset;
|
|
|
|
SIZE_T size;
|
|
|
|
void *addr1, *addr2;
|
|
|
|
MEMORY_BASIC_INFORMATION info;
|
|
|
|
|
|
|
|
if (!pNtMapViewOfSection) return;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
hfile = CreateFileA(dll_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
|
2012-02-20 09:01:25 +01:00
|
|
|
ok(hfile != INVALID_HANDLE_VALUE, "CreateFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
hmap = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_IMAGE, 0, 0, 0);
|
2012-02-20 09:01:25 +01:00
|
|
|
ok(hmap != 0, "CreateFileMapping error %d\n", GetLastError());
|
|
|
|
|
|
|
|
offset.u.LowPart = 0;
|
|
|
|
offset.u.HighPart = 0;
|
|
|
|
|
|
|
|
addr1 = NULL;
|
|
|
|
size = 0;
|
|
|
|
status = pNtMapViewOfSection(hmap, GetCurrentProcess(), &addr1, 0, 0, &offset,
|
|
|
|
&size, 1 /* ViewShare */, 0, PAGE_READONLY);
|
|
|
|
ok(status == STATUS_SUCCESS, "NtMapViewOfSection error %x\n", status);
|
|
|
|
ok(addr1 != 0, "mapped address should be valid\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = VirtualQuery((char *)addr1 + section.VirtualAddress, &info, sizeof(info));
|
|
|
|
ok(size == sizeof(info), "VirtualQuery error %d\n", GetLastError());
|
|
|
|
ok(info.BaseAddress == (char *)addr1 + section.VirtualAddress, "got %p != expected %p\n", info.BaseAddress, (char *)addr1 + section.VirtualAddress);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == page_size, "got %#lx != expected %#x\n", info.RegionSize, page_size);
|
2012-02-20 09:01:25 +01:00
|
|
|
ok(info.Protect == scn_page_access, "got %#x != expected %#x\n", info.Protect, scn_page_access);
|
|
|
|
ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%#x != PAGE_EXECUTE_WRITECOPY\n", info.AllocationProtect);
|
|
|
|
ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%#x != SEC_IMAGE\n", info.Type);
|
|
|
|
|
|
|
|
addr2 = NULL;
|
|
|
|
size = 0;
|
|
|
|
status = pNtMapViewOfSection(hmap, GetCurrentProcess(), &addr2, 0, 0, &offset,
|
|
|
|
&size, 1 /* ViewShare */, 0, PAGE_READONLY);
|
|
|
|
ok(status == STATUS_IMAGE_NOT_AT_BASE, "expected STATUS_IMAGE_NOT_AT_BASE, got %x\n", status);
|
|
|
|
ok(addr2 != 0, "mapped address should be valid\n");
|
|
|
|
ok(addr2 != addr1, "mapped addresses should be different\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = VirtualQuery((char *)addr2 + section.VirtualAddress, &info, sizeof(info));
|
|
|
|
ok(size == sizeof(info), "VirtualQuery error %d\n", GetLastError());
|
|
|
|
ok(info.BaseAddress == (char *)addr2 + section.VirtualAddress, "got %p != expected %p\n", info.BaseAddress, (char *)addr2 + section.VirtualAddress);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == page_size, "got %#lx != expected %#x\n", info.RegionSize, page_size);
|
2012-02-20 09:01:25 +01:00
|
|
|
ok(info.Protect == scn_page_access, "got %#x != expected %#x\n", info.Protect, scn_page_access);
|
|
|
|
ok(info.AllocationBase == addr2, "%p != %p\n", info.AllocationBase, addr2);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%#x != PAGE_EXECUTE_WRITECOPY\n", info.AllocationProtect);
|
|
|
|
ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%#x != SEC_IMAGE\n", info.Type);
|
|
|
|
|
|
|
|
status = pNtUnmapViewOfSection(GetCurrentProcess(), addr2);
|
|
|
|
ok(status == STATUS_SUCCESS, "NtUnmapViewOfSection error %x\n", status);
|
|
|
|
|
|
|
|
addr2 = MapViewOfFile(hmap, 0, 0, 0, 0);
|
2012-02-24 09:33:14 +01:00
|
|
|
ok(addr2 != 0, "mapped address should be valid\n");
|
2012-02-20 09:01:25 +01:00
|
|
|
ok(addr2 != addr1, "mapped addresses should be different\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = VirtualQuery((char *)addr2 + section.VirtualAddress, &info, sizeof(info));
|
|
|
|
ok(size == sizeof(info), "VirtualQuery error %d\n", GetLastError());
|
|
|
|
ok(info.BaseAddress == (char *)addr2 + section.VirtualAddress, "got %p != expected %p\n", info.BaseAddress, (char *)addr2 + section.VirtualAddress);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == page_size, "got %#lx != expected %#x\n", info.RegionSize, page_size);
|
2012-02-20 09:01:25 +01:00
|
|
|
ok(info.Protect == scn_page_access, "got %#x != expected %#x\n", info.Protect, scn_page_access);
|
|
|
|
ok(info.AllocationBase == addr2, "%p != %p\n", info.AllocationBase, addr2);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%#x != PAGE_EXECUTE_WRITECOPY\n", info.AllocationProtect);
|
|
|
|
ok(info.State == MEM_COMMIT, "%#x != MEM_COMMIT\n", info.State);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%#x != SEC_IMAGE\n", info.Type);
|
|
|
|
|
|
|
|
UnmapViewOfFile(addr2);
|
|
|
|
|
2012-02-24 09:33:14 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-01 23:09:53 +02:00
|
|
|
addr2 = LoadLibraryA(dll_name);
|
2012-02-24 09:33:14 +01:00
|
|
|
if (is_dll)
|
|
|
|
{
|
|
|
|
ok(!addr2, "LoadLibrary should fail, is_dll %d\n", is_dll);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_ADDRESS, "expected ERROR_INVALID_ADDRESS, got %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
ok(addr2 != 0, "LoadLibrary error %d, is_dll %d\n", GetLastError(), is_dll);
|
|
|
|
ok(addr2 != addr1, "mapped addresses should be different\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = FreeLibrary(addr2);
|
|
|
|
ok(ret, "FreeLibrary error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2012-02-20 09:01:25 +01:00
|
|
|
status = pNtUnmapViewOfSection(GetCurrentProcess(), addr1);
|
|
|
|
ok(status == STATUS_SUCCESS, "NtUnmapViewOfSection error %x\n", status);
|
|
|
|
|
|
|
|
CloseHandle(hmap);
|
|
|
|
CloseHandle(hfile);
|
|
|
|
}
|
|
|
|
|
2011-11-22 11:02:38 +01:00
|
|
|
static BOOL is_mem_writable(DWORD prot)
|
|
|
|
{
|
|
|
|
switch (prot & 0xff)
|
|
|
|
{
|
|
|
|
case PAGE_READWRITE:
|
|
|
|
case PAGE_WRITECOPY:
|
|
|
|
case PAGE_EXECUTE_READWRITE:
|
|
|
|
case PAGE_EXECUTE_WRITECOPY:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 07:45:01 +01:00
|
|
|
static void test_VirtualProtect(void *base, void *section)
|
|
|
|
{
|
|
|
|
static const struct test_data
|
|
|
|
{
|
|
|
|
DWORD prot_set, prot_get;
|
|
|
|
} td[] =
|
|
|
|
{
|
|
|
|
{ 0, 0 }, /* 0x00 */
|
|
|
|
{ PAGE_NOACCESS, PAGE_NOACCESS }, /* 0x01 */
|
|
|
|
{ PAGE_READONLY, PAGE_READONLY }, /* 0x02 */
|
|
|
|
{ PAGE_READONLY | PAGE_NOACCESS, 0 }, /* 0x03 */
|
|
|
|
{ PAGE_READWRITE, PAGE_WRITECOPY }, /* 0x04 */
|
|
|
|
{ PAGE_READWRITE | PAGE_NOACCESS, 0 }, /* 0x05 */
|
|
|
|
{ PAGE_READWRITE | PAGE_READONLY, 0 }, /* 0x06 */
|
|
|
|
{ PAGE_READWRITE | PAGE_READONLY | PAGE_NOACCESS, 0 }, /* 0x07 */
|
|
|
|
{ PAGE_WRITECOPY, PAGE_WRITECOPY }, /* 0x08 */
|
|
|
|
{ PAGE_WRITECOPY | PAGE_NOACCESS, 0 }, /* 0x09 */
|
|
|
|
{ PAGE_WRITECOPY | PAGE_READONLY, 0 }, /* 0x0a */
|
|
|
|
{ PAGE_WRITECOPY | PAGE_NOACCESS | PAGE_READONLY, 0 }, /* 0x0b */
|
|
|
|
{ PAGE_WRITECOPY | PAGE_READWRITE, 0 }, /* 0x0c */
|
|
|
|
{ PAGE_WRITECOPY | PAGE_READWRITE | PAGE_NOACCESS, 0 }, /* 0x0d */
|
|
|
|
{ PAGE_WRITECOPY | PAGE_READWRITE | PAGE_READONLY, 0 }, /* 0x0e */
|
|
|
|
{ PAGE_WRITECOPY | PAGE_READWRITE | PAGE_READONLY | PAGE_NOACCESS, 0 }, /* 0x0f */
|
|
|
|
|
|
|
|
{ PAGE_EXECUTE, PAGE_EXECUTE }, /* 0x10 */
|
|
|
|
{ PAGE_EXECUTE_READ, PAGE_EXECUTE_READ }, /* 0x20 */
|
|
|
|
{ PAGE_EXECUTE_READ | PAGE_EXECUTE, 0 }, /* 0x30 */
|
|
|
|
{ PAGE_EXECUTE_READWRITE, PAGE_EXECUTE_WRITECOPY }, /* 0x40 */
|
|
|
|
{ PAGE_EXECUTE_READWRITE | PAGE_EXECUTE, 0 }, /* 0x50 */
|
|
|
|
{ PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ, 0 }, /* 0x60 */
|
|
|
|
{ PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE, 0 }, /* 0x70 */
|
|
|
|
{ PAGE_EXECUTE_WRITECOPY, PAGE_EXECUTE_WRITECOPY }, /* 0x80 */
|
|
|
|
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE, 0 }, /* 0x90 */
|
|
|
|
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READ, 0 }, /* 0xa0 */
|
|
|
|
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READ | PAGE_EXECUTE, 0 }, /* 0xb0 */
|
|
|
|
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE, 0 }, /* 0xc0 */
|
|
|
|
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE, 0 }, /* 0xd0 */
|
|
|
|
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ, 0 }, /* 0xe0 */
|
|
|
|
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE, 0 } /* 0xf0 */
|
|
|
|
};
|
|
|
|
DWORD ret, orig_prot, old_prot, rw_prot, exec_prot, i, j;
|
|
|
|
MEMORY_BASIC_INFORMATION info;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-21 15:54:51 +01:00
|
|
|
ret = VirtualProtect(section, page_size, PAGE_NOACCESS, &old_prot);
|
2011-12-16 07:45:01 +01:00
|
|
|
ok(ret, "VirtualProtect error %d\n", GetLastError());
|
|
|
|
|
|
|
|
orig_prot = old_prot;
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(td); i++)
|
2011-12-16 07:45:01 +01:00
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = VirtualQuery(section, &info, sizeof(info));
|
|
|
|
ok(ret, "VirtualQuery failed %d\n", GetLastError());
|
|
|
|
ok(info.BaseAddress == section, "%d: got %p != expected %p\n", i, info.BaseAddress, section);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == page_size, "%d: got %#lx != expected %#x\n", i, info.RegionSize, page_size);
|
2011-12-16 07:45:01 +01:00
|
|
|
ok(info.Protect == PAGE_NOACCESS, "%d: got %#x != expected PAGE_NOACCESS\n", i, info.Protect);
|
|
|
|
ok(info.AllocationBase == base, "%d: %p != %p\n", i, info.AllocationBase, base);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %#x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
|
|
|
|
ok(info.State == MEM_COMMIT, "%d: %#x != MEM_COMMIT\n", i, info.State);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%d: %#x != SEC_IMAGE\n", i, info.Type);
|
|
|
|
|
|
|
|
old_prot = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-21 15:54:51 +01:00
|
|
|
ret = VirtualProtect(section, page_size, td[i].prot_set, &old_prot);
|
2011-12-16 07:45:01 +01:00
|
|
|
if (td[i].prot_get)
|
|
|
|
{
|
2012-01-24 10:45:54 +01:00
|
|
|
ok(ret, "%d: VirtualProtect error %d, requested prot %#x\n", i, GetLastError(), td[i].prot_set);
|
2011-12-16 07:45:01 +01:00
|
|
|
ok(old_prot == PAGE_NOACCESS, "%d: got %#x != expected PAGE_NOACCESS\n", i, old_prot);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = VirtualQuery(section, &info, sizeof(info));
|
|
|
|
ok(ret, "VirtualQuery failed %d\n", GetLastError());
|
|
|
|
ok(info.BaseAddress == section, "%d: got %p != expected %p\n", i, info.BaseAddress, section);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == page_size, "%d: got %#lx != expected %#x\n", i, info.RegionSize, page_size);
|
2011-12-16 07:45:01 +01:00
|
|
|
ok(info.Protect == td[i].prot_get, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].prot_get);
|
|
|
|
ok(info.AllocationBase == base, "%d: %p != %p\n", i, info.AllocationBase, base);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %#x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
|
|
|
|
ok(info.State == MEM_COMMIT, "%d: %#x != MEM_COMMIT\n", i, info.State);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%d: %#x != SEC_IMAGE\n", i, info.Type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok(!ret, "%d: VirtualProtect should fail\n", i);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "%d: expected ERROR_INVALID_PARAMETER, got %d\n", i, GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
old_prot = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-21 15:54:51 +01:00
|
|
|
ret = VirtualProtect(section, page_size, PAGE_NOACCESS, &old_prot);
|
2011-12-16 07:45:01 +01:00
|
|
|
ok(ret, "%d: VirtualProtect error %d\n", i, GetLastError());
|
|
|
|
if (td[i].prot_get)
|
|
|
|
ok(old_prot == td[i].prot_get, "%d: got %#x != expected %#x\n", i, old_prot, td[i].prot_get);
|
|
|
|
else
|
|
|
|
ok(old_prot == PAGE_NOACCESS, "%d: got %#x != expected PAGE_NOACCESS\n", i, old_prot);
|
|
|
|
}
|
|
|
|
|
|
|
|
exec_prot = 0;
|
|
|
|
|
|
|
|
for (i = 0; i <= 4; i++)
|
|
|
|
{
|
|
|
|
rw_prot = 0;
|
|
|
|
|
|
|
|
for (j = 0; j <= 4; j++)
|
|
|
|
{
|
|
|
|
DWORD prot = exec_prot | rw_prot;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-21 15:54:51 +01:00
|
|
|
ret = VirtualProtect(section, page_size, prot, &old_prot);
|
2011-12-16 07:45:01 +01:00
|
|
|
if ((rw_prot && exec_prot) || (!rw_prot && !exec_prot))
|
|
|
|
{
|
|
|
|
ok(!ret, "VirtualProtect(%02x) should fail\n", prot);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(ret, "VirtualProtect(%02x) error %d\n", prot, GetLastError());
|
|
|
|
|
|
|
|
rw_prot = 1 << j;
|
|
|
|
}
|
|
|
|
|
|
|
|
exec_prot = 1 << (i + 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-11-21 15:54:51 +01:00
|
|
|
ret = VirtualProtect(section, page_size, orig_prot, &old_prot);
|
2011-12-16 07:45:01 +01:00
|
|
|
ok(ret, "VirtualProtect error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2011-07-19 18:41:12 +02:00
|
|
|
static void test_section_access(void)
|
|
|
|
{
|
|
|
|
static const struct test_data
|
|
|
|
{
|
2011-11-22 11:02:38 +01:00
|
|
|
DWORD scn_file_access, scn_page_access, scn_page_access_after_write;
|
2011-07-19 18:41:12 +02:00
|
|
|
} td[] =
|
|
|
|
{
|
2011-11-22 11:02:38 +01:00
|
|
|
{ 0, PAGE_NOACCESS, 0 },
|
|
|
|
{ IMAGE_SCN_MEM_READ, PAGE_READONLY, 0 },
|
|
|
|
{ IMAGE_SCN_MEM_WRITE, PAGE_WRITECOPY, PAGE_READWRITE },
|
|
|
|
{ IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE, 0 },
|
|
|
|
{ IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE, PAGE_WRITECOPY, PAGE_READWRITE },
|
2011-07-19 18:41:12 +02:00
|
|
|
{ IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE_READ },
|
2011-11-22 11:02:38 +01:00
|
|
|
{ IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE_WRITECOPY, PAGE_EXECUTE_READWRITE },
|
|
|
|
{ IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE_WRITECOPY, PAGE_EXECUTE_READWRITE },
|
|
|
|
|
|
|
|
{ IMAGE_SCN_CNT_INITIALIZED_DATA, PAGE_NOACCESS, 0 },
|
|
|
|
{ IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ, PAGE_READONLY, 0 },
|
|
|
|
{ IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_WRITE, PAGE_WRITECOPY, PAGE_READWRITE },
|
|
|
|
{ IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE, 0 },
|
|
|
|
{ IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE, PAGE_WRITECOPY, PAGE_READWRITE },
|
|
|
|
{ IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE_READ, 0 },
|
|
|
|
{ IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE_WRITECOPY, PAGE_EXECUTE_READWRITE },
|
|
|
|
{ IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE_WRITECOPY, PAGE_EXECUTE_READWRITE },
|
|
|
|
|
|
|
|
{ IMAGE_SCN_CNT_UNINITIALIZED_DATA, PAGE_NOACCESS, 0 },
|
|
|
|
{ IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ, PAGE_READONLY, 0 },
|
|
|
|
{ IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_WRITE, PAGE_WRITECOPY, PAGE_READWRITE },
|
|
|
|
{ IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE, 0 },
|
|
|
|
{ IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE, PAGE_WRITECOPY, PAGE_READWRITE },
|
|
|
|
{ IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE_READ, 0 },
|
|
|
|
{ IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE_WRITECOPY, PAGE_EXECUTE_READWRITE },
|
|
|
|
{ IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_EXECUTE, PAGE_EXECUTE_WRITECOPY, PAGE_EXECUTE_READWRITE }
|
2011-07-19 18:41:12 +02:00
|
|
|
};
|
2011-11-22 11:02:51 +01:00
|
|
|
char buf[256];
|
2011-07-19 18:41:12 +02:00
|
|
|
int i;
|
|
|
|
DWORD dummy, file_align;
|
|
|
|
HANDLE hfile;
|
|
|
|
HMODULE hlib;
|
|
|
|
char temp_path[MAX_PATH];
|
|
|
|
char dll_name[MAX_PATH];
|
|
|
|
SIZE_T size;
|
|
|
|
MEMORY_BASIC_INFORMATION info;
|
2013-10-17 04:45:23 +02:00
|
|
|
STARTUPINFOA sti;
|
2011-11-22 11:02:51 +01:00
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
DWORD ret;
|
2011-07-19 18:41:12 +02:00
|
|
|
|
|
|
|
/* prevent displaying of the "Unable to load this DLL" message box */
|
|
|
|
SetErrorMode(SEM_FAILCRITICALERRORS);
|
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
GetTempPathA(MAX_PATH, temp_path);
|
2011-07-19 18:41:12 +02:00
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(td); i++)
|
2011-07-19 18:41:12 +02:00
|
|
|
{
|
2015-01-27 23:02:58 +01:00
|
|
|
IMAGE_NT_HEADERS nt_header;
|
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
GetTempFileNameA(temp_path, "ldr", 0, dll_name);
|
2011-07-19 18:41:12 +02:00
|
|
|
|
|
|
|
/*trace("creating %s\n", dll_name);*/
|
|
|
|
hfile = CreateFileA(dll_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
|
|
|
if (hfile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ok(0, "could not create %s\n", dll_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &dos_header, sizeof(dos_header), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
2015-01-27 23:02:58 +01:00
|
|
|
nt_header = nt_header_template;
|
2011-07-19 18:41:12 +02:00
|
|
|
nt_header.FileHeader.NumberOfSections = 1;
|
|
|
|
nt_header.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
|
2012-02-20 09:01:25 +01:00
|
|
|
nt_header.FileHeader.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DLL | IMAGE_FILE_RELOCS_STRIPPED;
|
2011-11-22 11:02:51 +01:00
|
|
|
|
2013-11-21 15:54:51 +01:00
|
|
|
nt_header.OptionalHeader.SectionAlignment = page_size;
|
2011-07-19 18:41:12 +02:00
|
|
|
nt_header.OptionalHeader.FileAlignment = 0x200;
|
2013-11-21 15:54:51 +01:00
|
|
|
nt_header.OptionalHeader.SizeOfImage = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + page_size;
|
2011-07-19 18:41:12 +02:00
|
|
|
nt_header.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &nt_header, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &nt_header.OptionalHeader, sizeof(IMAGE_OPTIONAL_HEADER), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
section.SizeOfRawData = sizeof(section_data);
|
|
|
|
section.PointerToRawData = nt_header.OptionalHeader.FileAlignment;
|
|
|
|
section.VirtualAddress = nt_header.OptionalHeader.SectionAlignment;
|
|
|
|
section.Misc.VirtualSize = section.SizeOfRawData;
|
|
|
|
section.Characteristics = td[i].scn_file_access;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, §ion, sizeof(section), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
file_align = nt_header.OptionalHeader.FileAlignment - nt_header.OptionalHeader.SizeOfHeaders;
|
|
|
|
assert(file_align < sizeof(filler));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, filler, file_align, &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* section data */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, section_data, sizeof(section_data), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(hfile);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-01 23:09:53 +02:00
|
|
|
hlib = LoadLibraryA(dll_name);
|
2011-09-30 13:06:02 +02:00
|
|
|
ok(hlib != 0, "LoadLibrary error %d\n", GetLastError());
|
2011-07-19 18:41:12 +02:00
|
|
|
|
2011-11-22 11:02:38 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2011-07-19 18:41:12 +02:00
|
|
|
size = VirtualQuery((char *)hlib + section.VirtualAddress, &info, sizeof(info));
|
|
|
|
ok(size == sizeof(info),
|
|
|
|
"%d: VirtualQuery error %d\n", i, GetLastError());
|
|
|
|
ok(info.BaseAddress == (char *)hlib + section.VirtualAddress, "%d: got %p != expected %p\n", i, info.BaseAddress, (char *)hlib + section.VirtualAddress);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == page_size, "%d: got %#lx != expected %#x\n", i, info.RegionSize, page_size);
|
2011-07-19 18:41:12 +02:00
|
|
|
ok(info.Protect == td[i].scn_page_access, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].scn_page_access);
|
|
|
|
ok(info.AllocationBase == hlib, "%d: %p != %p\n", i, info.AllocationBase, hlib);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %#x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
|
|
|
|
ok(info.State == MEM_COMMIT, "%d: %#x != MEM_COMMIT\n", i, info.State);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%d: %#x != SEC_IMAGE\n", i, info.Type);
|
|
|
|
if (info.Protect != PAGE_NOACCESS)
|
|
|
|
ok(!memcmp((const char *)info.BaseAddress, section_data, section.SizeOfRawData), "wrong section data\n");
|
|
|
|
|
2011-12-16 07:45:01 +01:00
|
|
|
test_VirtualProtect(hlib, (char *)hlib + section.VirtualAddress);
|
|
|
|
|
2011-11-22 11:02:38 +01:00
|
|
|
/* Windows changes the WRITECOPY to WRITE protection on an image section write (for a changed page only) */
|
|
|
|
if (is_mem_writable(info.Protect))
|
|
|
|
{
|
|
|
|
char *p = info.BaseAddress;
|
|
|
|
*p = 0xfe;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = VirtualQuery((char *)hlib + section.VirtualAddress, &info, sizeof(info));
|
|
|
|
ok(size == sizeof(info), "%d: VirtualQuery error %d\n", i, GetLastError());
|
|
|
|
/* FIXME: remove the condition below once Wine is fixed */
|
2016-02-15 21:06:44 +01:00
|
|
|
todo_wine_if (info.Protect == PAGE_WRITECOPY || info.Protect == PAGE_EXECUTE_WRITECOPY)
|
2011-11-22 11:02:38 +01:00
|
|
|
ok(info.Protect == td[i].scn_page_access_after_write, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].scn_page_access_after_write);
|
|
|
|
}
|
|
|
|
|
2011-07-19 18:41:12 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = FreeLibrary(hlib);
|
|
|
|
ok(ret, "FreeLibrary error %d\n", GetLastError());
|
|
|
|
|
2012-02-24 09:33:14 +01:00
|
|
|
test_image_mapping(dll_name, td[i].scn_page_access, TRUE);
|
2012-02-20 09:01:25 +01:00
|
|
|
|
|
|
|
/* reset IMAGE_FILE_DLL otherwise CreateProcess fails */
|
|
|
|
nt_header.FileHeader.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_RELOCS_STRIPPED;
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
hfile = CreateFileA(dll_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
2012-02-24 09:33:14 +01:00
|
|
|
/* LoadLibrary called on an already memory-mapped file in
|
|
|
|
* test_image_mapping() above leads to a file handle leak
|
|
|
|
* under nt4, and inability to overwrite and delete the file
|
|
|
|
* due to sharing violation error. Ignore it and skip the test,
|
|
|
|
* but leave a not deletable temporary file.
|
|
|
|
*/
|
|
|
|
ok(hfile != INVALID_HANDLE_VALUE || broken(hfile == INVALID_HANDLE_VALUE) /* nt4 */,
|
|
|
|
"CreateFile error %d\n", GetLastError());
|
|
|
|
if (hfile == INVALID_HANDLE_VALUE) goto nt4_is_broken;
|
2012-02-20 09:01:25 +01:00
|
|
|
SetFilePointer(hfile, sizeof(dos_header), NULL, FILE_BEGIN);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &nt_header, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
CloseHandle(hfile);
|
|
|
|
|
2011-11-22 11:02:51 +01:00
|
|
|
memset(&sti, 0, sizeof(sti));
|
|
|
|
sti.cb = sizeof(sti);
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = CreateProcessA(dll_name, NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &sti, &pi);
|
2011-11-22 11:02:51 +01:00
|
|
|
ok(ret, "CreateProcess() error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = VirtualQueryEx(pi.hProcess, (char *)hlib + section.VirtualAddress, &info, sizeof(info));
|
|
|
|
ok(size == sizeof(info),
|
|
|
|
"%d: VirtualQuery error %d\n", i, GetLastError());
|
|
|
|
ok(info.BaseAddress == (char *)hlib + section.VirtualAddress, "%d: got %p != expected %p\n", i, info.BaseAddress, (char *)hlib + section.VirtualAddress);
|
2013-11-21 15:54:51 +01:00
|
|
|
ok(info.RegionSize == page_size, "%d: got %#lx != expected %#x\n", i, info.RegionSize, page_size);
|
2011-11-22 11:02:51 +01:00
|
|
|
ok(info.Protect == td[i].scn_page_access, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].scn_page_access);
|
|
|
|
ok(info.AllocationBase == hlib, "%d: %p != %p\n", i, info.AllocationBase, hlib);
|
|
|
|
ok(info.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "%d: %#x != PAGE_EXECUTE_WRITECOPY\n", i, info.AllocationProtect);
|
|
|
|
ok(info.State == MEM_COMMIT, "%d: %#x != MEM_COMMIT\n", i, info.State);
|
|
|
|
ok(info.Type == SEC_IMAGE, "%d: %#x != SEC_IMAGE\n", i, info.Type);
|
|
|
|
if (info.Protect != PAGE_NOACCESS)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadProcessMemory(pi.hProcess, info.BaseAddress, buf, section.SizeOfRawData, NULL);
|
|
|
|
ok(ret, "ReadProcessMemory() error %d\n", GetLastError());
|
|
|
|
ok(!memcmp(buf, section_data, section.SizeOfRawData), "wrong section data\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = TerminateProcess(pi.hProcess, 0);
|
|
|
|
ok(ret, "TerminateProcess() error %d\n", GetLastError());
|
|
|
|
ret = WaitForSingleObject(pi.hProcess, 3000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed: %x\n", ret);
|
|
|
|
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
2012-02-24 09:33:14 +01:00
|
|
|
test_image_mapping(dll_name, td[i].scn_page_access, FALSE);
|
2012-02-20 09:01:25 +01:00
|
|
|
|
2012-02-24 09:33:14 +01:00
|
|
|
nt4_is_broken:
|
2011-07-19 18:41:12 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = DeleteFileA(dll_name);
|
2012-02-24 09:33:14 +01:00
|
|
|
ok(ret || broken(!ret) /* nt4 */, "DeleteFile error %d\n", GetLastError());
|
2011-07-19 18:41:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 16:15:06 +01:00
|
|
|
static void test_import_resolution(void)
|
|
|
|
{
|
|
|
|
char temp_path[MAX_PATH];
|
|
|
|
char dll_name[MAX_PATH];
|
|
|
|
DWORD dummy;
|
|
|
|
void *expect;
|
2014-02-17 17:33:30 +01:00
|
|
|
char *str;
|
2014-02-17 16:15:06 +01:00
|
|
|
HANDLE hfile;
|
|
|
|
HMODULE mod, mod2;
|
|
|
|
struct imports
|
|
|
|
{
|
|
|
|
IMAGE_IMPORT_DESCRIPTOR descr[2];
|
|
|
|
IMAGE_THUNK_DATA original_thunks[2];
|
|
|
|
IMAGE_THUNK_DATA thunks[2];
|
|
|
|
char module[16];
|
|
|
|
struct { WORD hint; char name[32]; } function;
|
2014-02-17 17:33:30 +01:00
|
|
|
IMAGE_TLS_DIRECTORY tls;
|
|
|
|
char tls_data[16];
|
|
|
|
SHORT tls_index;
|
2014-02-17 16:15:06 +01:00
|
|
|
} data, *ptr;
|
|
|
|
IMAGE_NT_HEADERS nt;
|
|
|
|
IMAGE_SECTION_HEADER section;
|
|
|
|
int test;
|
|
|
|
|
|
|
|
for (test = 0; test < 3; test++)
|
|
|
|
{
|
|
|
|
#define DATA_RVA(ptr) (page_size + ((char *)(ptr) - (char *)&data))
|
2015-01-27 23:02:58 +01:00
|
|
|
nt = nt_header_template;
|
2014-02-17 16:15:06 +01:00
|
|
|
nt.FileHeader.NumberOfSections = 1;
|
|
|
|
nt.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
|
|
|
|
nt.FileHeader.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_32BIT_MACHINE | IMAGE_FILE_RELOCS_STRIPPED;
|
|
|
|
if (test != 2) nt.FileHeader.Characteristics |= IMAGE_FILE_DLL;
|
2015-01-27 23:02:58 +01:00
|
|
|
nt.OptionalHeader.SectionAlignment = page_size;
|
|
|
|
nt.OptionalHeader.FileAlignment = 0x200;
|
2014-02-17 16:15:06 +01:00
|
|
|
nt.OptionalHeader.ImageBase = 0x12340000;
|
|
|
|
nt.OptionalHeader.SizeOfImage = 2 * page_size;
|
|
|
|
nt.OptionalHeader.SizeOfHeaders = nt.OptionalHeader.FileAlignment;
|
|
|
|
nt.OptionalHeader.NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES;
|
|
|
|
memset( nt.OptionalHeader.DataDirectory, 0, sizeof(nt.OptionalHeader.DataDirectory) );
|
|
|
|
nt.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size = sizeof(data.descr);
|
|
|
|
nt.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress = DATA_RVA(data.descr);
|
2014-02-17 17:33:30 +01:00
|
|
|
nt.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].Size = sizeof(data.tls);
|
|
|
|
nt.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress = DATA_RVA(&data.tls);
|
2014-02-17 16:15:06 +01:00
|
|
|
|
|
|
|
memset( &data, 0, sizeof(data) );
|
2018-02-13 20:08:49 +01:00
|
|
|
U(data.descr[0]).OriginalFirstThunk = DATA_RVA( data.original_thunks );
|
2014-02-17 16:15:06 +01:00
|
|
|
data.descr[0].FirstThunk = DATA_RVA( data.thunks );
|
|
|
|
data.descr[0].Name = DATA_RVA( data.module );
|
|
|
|
strcpy( data.module, "kernel32.dll" );
|
|
|
|
strcpy( data.function.name, "CreateEventA" );
|
|
|
|
data.original_thunks[0].u1.AddressOfData = DATA_RVA( &data.function );
|
|
|
|
data.thunks[0].u1.AddressOfData = 0xdeadbeef;
|
|
|
|
|
2014-02-17 17:33:30 +01:00
|
|
|
data.tls.StartAddressOfRawData = nt.OptionalHeader.ImageBase + DATA_RVA( data.tls_data );
|
|
|
|
data.tls.EndAddressOfRawData = data.tls.StartAddressOfRawData + sizeof(data.tls_data);
|
|
|
|
data.tls.AddressOfIndex = nt.OptionalHeader.ImageBase + DATA_RVA( &data.tls_index );
|
|
|
|
strcpy( data.tls_data, "hello world" );
|
|
|
|
data.tls_index = 9999;
|
|
|
|
|
2014-02-17 16:15:06 +01:00
|
|
|
GetTempPathA(MAX_PATH, temp_path);
|
|
|
|
GetTempFileNameA(temp_path, "ldr", 0, dll_name);
|
|
|
|
|
|
|
|
hfile = CreateFileA(dll_name, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, 0);
|
|
|
|
ok( hfile != INVALID_HANDLE_VALUE, "creation failed\n" );
|
|
|
|
|
|
|
|
memset( §ion, 0, sizeof(section) );
|
|
|
|
memcpy( section.Name, ".text", sizeof(".text") );
|
|
|
|
section.PointerToRawData = nt.OptionalHeader.FileAlignment;
|
|
|
|
section.VirtualAddress = nt.OptionalHeader.SectionAlignment;
|
|
|
|
section.Misc.VirtualSize = sizeof(data);
|
|
|
|
section.SizeOfRawData = sizeof(data);
|
|
|
|
section.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
|
|
|
|
|
|
|
|
WriteFile(hfile, &dos_header, sizeof(dos_header), &dummy, NULL);
|
|
|
|
WriteFile(hfile, &nt, sizeof(nt), &dummy, NULL);
|
|
|
|
WriteFile(hfile, §ion, sizeof(section), &dummy, NULL);
|
|
|
|
|
|
|
|
SetFilePointer( hfile, section.PointerToRawData, NULL, SEEK_SET );
|
|
|
|
WriteFile(hfile, &data, sizeof(data), &dummy, NULL);
|
|
|
|
|
|
|
|
CloseHandle( hfile );
|
|
|
|
|
|
|
|
switch (test)
|
|
|
|
{
|
|
|
|
case 0: /* normal load */
|
|
|
|
mod = LoadLibraryA( dll_name );
|
|
|
|
ok( mod != NULL, "failed to load err %u\n", GetLastError() );
|
|
|
|
if (!mod) break;
|
|
|
|
ptr = (struct imports *)((char *)mod + page_size);
|
|
|
|
expect = GetProcAddress( GetModuleHandleA( data.module ), data.function.name );
|
|
|
|
ok( (void *)ptr->thunks[0].u1.Function == expect, "thunk %p instead of %p for %s.%s\n",
|
|
|
|
(void *)ptr->thunks[0].u1.Function, expect, data.module, data.function.name );
|
2014-02-17 17:33:30 +01:00
|
|
|
ok( ptr->tls_index < 32 || broken(ptr->tls_index == 9999), /* before vista */
|
|
|
|
"wrong tls index %d\n", ptr->tls_index );
|
|
|
|
if (ptr->tls_index != 9999)
|
|
|
|
{
|
|
|
|
str = ((char **)NtCurrentTeb()->ThreadLocalStoragePointer)[ptr->tls_index];
|
|
|
|
ok( !strcmp( str, "hello world" ), "wrong tls data '%s' at %p\n", str, str );
|
|
|
|
}
|
2014-02-17 16:15:06 +01:00
|
|
|
FreeLibrary( mod );
|
|
|
|
break;
|
|
|
|
case 1: /* load with DONT_RESOLVE_DLL_REFERENCES doesn't resolve imports */
|
|
|
|
mod = LoadLibraryExA( dll_name, 0, DONT_RESOLVE_DLL_REFERENCES );
|
|
|
|
ok( mod != NULL, "failed to load err %u\n", GetLastError() );
|
|
|
|
if (!mod) break;
|
|
|
|
ptr = (struct imports *)((char *)mod + page_size);
|
|
|
|
ok( ptr->thunks[0].u1.Function == 0xdeadbeef, "thunk resolved to %p for %s.%s\n",
|
|
|
|
(void *)ptr->thunks[0].u1.Function, data.module, data.function.name );
|
2014-02-17 17:33:30 +01:00
|
|
|
ok( ptr->tls_index == 9999, "wrong tls index %d\n", ptr->tls_index );
|
|
|
|
|
2014-02-17 16:15:06 +01:00
|
|
|
mod2 = LoadLibraryA( dll_name );
|
|
|
|
ok( mod2 == mod, "loaded twice %p / %p\n", mod, mod2 );
|
|
|
|
ok( ptr->thunks[0].u1.Function == 0xdeadbeef, "thunk resolved to %p for %s.%s\n",
|
|
|
|
(void *)ptr->thunks[0].u1.Function, data.module, data.function.name );
|
2014-02-17 17:33:30 +01:00
|
|
|
ok( ptr->tls_index == 9999, "wrong tls index %d\n", ptr->tls_index );
|
2017-08-29 11:30:48 +02:00
|
|
|
FreeLibrary( mod2 );
|
2014-02-17 16:15:06 +01:00
|
|
|
FreeLibrary( mod );
|
|
|
|
break;
|
|
|
|
case 2: /* load without IMAGE_FILE_DLL doesn't resolve imports */
|
|
|
|
mod = LoadLibraryA( dll_name );
|
|
|
|
ok( mod != NULL, "failed to load err %u\n", GetLastError() );
|
|
|
|
if (!mod) break;
|
|
|
|
ptr = (struct imports *)((char *)mod + page_size);
|
|
|
|
ok( ptr->thunks[0].u1.Function == 0xdeadbeef, "thunk resolved to %p for %s.%s\n",
|
|
|
|
(void *)ptr->thunks[0].u1.Function, data.module, data.function.name );
|
2014-02-17 17:33:30 +01:00
|
|
|
ok( ptr->tls_index == 9999, "wrong tls index %d\n", ptr->tls_index );
|
2014-02-17 16:15:06 +01:00
|
|
|
FreeLibrary( mod );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DeleteFileA( dll_name );
|
|
|
|
#undef DATA_RVA
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
#define MAX_COUNT 10
|
2013-04-30 10:20:24 +02:00
|
|
|
static HANDLE attached_thread[MAX_COUNT];
|
2013-04-12 11:00:58 +02:00
|
|
|
static DWORD attached_thread_count;
|
2018-08-07 10:03:13 +02:00
|
|
|
static HANDLE event, mutex, semaphore;
|
|
|
|
static HANDLE stop_event, loader_lock_event, peb_lock_event, heap_lock_event, cs_lock_event, ack_event;
|
|
|
|
static CRITICAL_SECTION cs_lock;
|
|
|
|
static int test_dll_phase, inside_loader_lock, inside_peb_lock, inside_heap_lock, inside_cs_lock;
|
2016-08-03 00:55:43 +02:00
|
|
|
static LONG fls_callback_count;
|
2013-04-12 11:00:58 +02:00
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
static DWORD WINAPI mutex_thread_proc(void *param)
|
2013-04-12 11:00:58 +02:00
|
|
|
{
|
2018-08-07 10:03:13 +02:00
|
|
|
HANDLE wait_list[5];
|
2013-04-17 11:52:38 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = WaitForSingleObject(mutex, 0);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %#x\n", ret);
|
|
|
|
|
|
|
|
SetEvent(param);
|
|
|
|
|
2013-04-30 10:20:24 +02:00
|
|
|
wait_list[0] = stop_event;
|
|
|
|
wait_list[1] = loader_lock_event;
|
|
|
|
wait_list[2] = peb_lock_event;
|
2013-05-13 09:45:45 +02:00
|
|
|
wait_list[3] = heap_lock_event;
|
2018-08-07 10:03:13 +02:00
|
|
|
wait_list[4] = cs_lock_event;
|
2013-04-30 10:20:24 +02:00
|
|
|
|
2017-11-17 05:21:32 +01:00
|
|
|
trace("%04x: mutex_thread_proc: starting\n", GetCurrentThreadId());
|
2013-04-17 11:52:38 +02:00
|
|
|
while (1)
|
|
|
|
{
|
2018-06-27 20:56:45 +02:00
|
|
|
ret = WaitForMultipleObjects(ARRAY_SIZE(wait_list), wait_list, FALSE, 50);
|
2013-04-30 10:20:24 +02:00
|
|
|
if (ret == WAIT_OBJECT_0) break;
|
|
|
|
else if (ret == WAIT_OBJECT_0 + 1)
|
|
|
|
{
|
2014-05-28 06:58:59 +02:00
|
|
|
ULONG_PTR loader_lock_magic;
|
2017-11-17 05:21:32 +01:00
|
|
|
trace("%04x: mutex_thread_proc: Entering loader lock\n", GetCurrentThreadId());
|
2013-04-30 10:20:24 +02:00
|
|
|
ret = pLdrLockLoaderLock(0, NULL, &loader_lock_magic);
|
|
|
|
ok(!ret, "LdrLockLoaderLock error %#x\n", ret);
|
|
|
|
inside_loader_lock++;
|
|
|
|
SetEvent(ack_event);
|
|
|
|
}
|
|
|
|
else if (ret == WAIT_OBJECT_0 + 2)
|
|
|
|
{
|
2017-11-17 05:21:32 +01:00
|
|
|
trace("%04x: mutex_thread_proc: Entering PEB lock\n", GetCurrentThreadId());
|
2013-04-30 10:20:24 +02:00
|
|
|
pRtlAcquirePebLock();
|
|
|
|
inside_peb_lock++;
|
|
|
|
SetEvent(ack_event);
|
|
|
|
}
|
2013-05-13 09:45:45 +02:00
|
|
|
else if (ret == WAIT_OBJECT_0 + 3)
|
|
|
|
{
|
2017-11-17 05:21:32 +01:00
|
|
|
trace("%04x: mutex_thread_proc: Entering heap lock\n", GetCurrentThreadId());
|
2013-05-13 09:45:45 +02:00
|
|
|
HeapLock(GetProcessHeap());
|
|
|
|
inside_heap_lock++;
|
|
|
|
SetEvent(ack_event);
|
|
|
|
}
|
2018-08-07 10:03:13 +02:00
|
|
|
else if (ret == WAIT_OBJECT_0 + 4)
|
|
|
|
{
|
|
|
|
trace("%04x: mutex_thread_proc: Entering CS lock\n", GetCurrentThreadId());
|
|
|
|
EnterCriticalSection(&cs_lock);
|
|
|
|
inside_cs_lock++;
|
|
|
|
SetEvent(ack_event);
|
|
|
|
}
|
2013-04-17 11:52:38 +02:00
|
|
|
}
|
|
|
|
|
2017-11-17 05:21:32 +01:00
|
|
|
trace("%04x: mutex_thread_proc: exiting\n", GetCurrentThreadId());
|
2013-04-17 11:52:38 +02:00
|
|
|
return 196;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI semaphore_thread_proc(void *param)
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
ret = WaitForSingleObject(semaphore, 0);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %#x\n", ret);
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
SetEvent(param);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2015-05-08 17:46:30 +02:00
|
|
|
if (winetest_debug > 1)
|
2017-11-17 05:21:32 +01:00
|
|
|
trace("%04x: semaphore_thread_proc: still alive\n", GetCurrentThreadId());
|
2013-04-12 11:00:58 +02:00
|
|
|
if (WaitForSingleObject(stop_event, 50) != WAIT_TIMEOUT) break;
|
|
|
|
}
|
|
|
|
|
2017-11-17 05:21:32 +01:00
|
|
|
trace("%04x: semaphore_thread_proc: exiting\n", GetCurrentThreadId());
|
2013-04-12 11:00:58 +02:00
|
|
|
return 196;
|
|
|
|
}
|
|
|
|
|
2013-04-18 10:44:16 +02:00
|
|
|
static DWORD WINAPI noop_thread_proc(void *param)
|
|
|
|
{
|
2013-04-24 13:39:07 +02:00
|
|
|
if (param)
|
|
|
|
{
|
|
|
|
LONG *noop_thread_started = param;
|
|
|
|
InterlockedIncrement(noop_thread_started);
|
|
|
|
}
|
2013-04-18 10:44:16 +02:00
|
|
|
|
2017-11-17 05:21:32 +01:00
|
|
|
trace("%04x: noop_thread_proc: exiting\n", GetCurrentThreadId());
|
2013-04-24 13:39:07 +02:00
|
|
|
return 195;
|
2013-04-18 10:44:16 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 00:55:43 +02:00
|
|
|
static VOID WINAPI fls_callback(PVOID lpFlsData)
|
|
|
|
{
|
|
|
|
ok(lpFlsData == (void*) 0x31415, "lpFlsData is %p, expected %p\n", lpFlsData, (void*) 0x31415);
|
|
|
|
InterlockedIncrement(&fls_callback_count);
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
static BOOL WINAPI dll_entry_point(HINSTANCE hinst, DWORD reason, LPVOID param)
|
|
|
|
{
|
2013-04-24 13:39:07 +02:00
|
|
|
static LONG noop_thread_started;
|
2016-08-03 00:55:43 +02:00
|
|
|
static DWORD fls_index = FLS_OUT_OF_INDEXES;
|
|
|
|
static int fls_count = 0;
|
|
|
|
static int thread_detach_count = 0;
|
2013-04-17 11:52:38 +02:00
|
|
|
DWORD ret;
|
2013-04-12 11:00:58 +02:00
|
|
|
|
2013-04-30 10:20:24 +02:00
|
|
|
ok(!inside_loader_lock, "inside_loader_lock should not be set\n");
|
|
|
|
ok(!inside_peb_lock, "inside_peb_lock should not be set\n");
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
trace("dll: %p, DLL_PROCESS_ATTACH, %p\n", hinst, param);
|
|
|
|
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(!ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
|
2016-08-03 00:55:43 +02:00
|
|
|
/* Set up the FLS slot, if FLS is available */
|
|
|
|
if (pFlsGetValue)
|
|
|
|
{
|
|
|
|
void* value;
|
|
|
|
BOOL bret;
|
|
|
|
ret = pFlsAlloc(&fls_callback);
|
|
|
|
ok(ret != FLS_OUT_OF_INDEXES, "FlsAlloc returned %d\n", ret);
|
|
|
|
fls_index = ret;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
value = pFlsGetValue(fls_index);
|
|
|
|
ok(!value, "FlsGetValue returned %p, expected NULL\n", value);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "FlsGetValue failed with error %u\n", GetLastError());
|
|
|
|
bret = pFlsSetValue(fls_index, (void*) 0x31415);
|
|
|
|
ok(bret, "FlsSetValue failed\n");
|
|
|
|
fls_count++;
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
{
|
|
|
|
DWORD code, expected_code, i;
|
2013-04-18 10:44:16 +02:00
|
|
|
HANDLE handle, process;
|
|
|
|
void *addr;
|
|
|
|
SIZE_T size;
|
|
|
|
LARGE_INTEGER offset;
|
|
|
|
DEBUG_EVENT de;
|
2013-04-12 11:00:58 +02:00
|
|
|
|
|
|
|
trace("dll: %p, DLL_PROCESS_DETACH, %p\n", hinst, param);
|
|
|
|
|
2013-04-30 10:20:24 +02:00
|
|
|
if (test_dll_phase == 4 || test_dll_phase == 5)
|
|
|
|
{
|
|
|
|
ok(0, "dll_entry_point(DLL_PROCESS_DETACH) should not be called\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-13 09:45:45 +02:00
|
|
|
/* The process should already deadlock at this point */
|
|
|
|
if (test_dll_phase == 6)
|
|
|
|
{
|
|
|
|
/* In reality, code below never gets executed, probably some other
|
|
|
|
* code tries to access process heap and deadlocks earlier, even XP
|
|
|
|
* doesn't call the DLL entry point on process detach either.
|
|
|
|
*/
|
|
|
|
HeapLock(GetProcessHeap());
|
2018-08-07 10:03:16 +02:00
|
|
|
todo_wine
|
2013-05-13 09:45:45 +02:00
|
|
|
ok(0, "dll_entry_point: process should already deadlock\n");
|
|
|
|
break;
|
|
|
|
}
|
2018-08-07 10:03:13 +02:00
|
|
|
else if (test_dll_phase == 7)
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&cs_lock);
|
|
|
|
}
|
2013-05-13 09:45:45 +02:00
|
|
|
|
2018-08-07 10:03:13 +02:00
|
|
|
if (test_dll_phase == 0 || test_dll_phase == 1 || test_dll_phase == 3 || test_dll_phase == 7)
|
2013-04-25 09:37:06 +02:00
|
|
|
ok(param != NULL, "dll: param %p\n", param);
|
|
|
|
else
|
|
|
|
ok(!param, "dll: param %p\n", param);
|
|
|
|
|
2013-05-10 12:17:37 +02:00
|
|
|
if (test_dll_phase == 0 || test_dll_phase == 1) expected_code = 195;
|
2013-04-12 11:00:58 +02:00
|
|
|
else if (test_dll_phase == 3) expected_code = 196;
|
2018-08-07 10:03:13 +02:00
|
|
|
else if (test_dll_phase == 7) expected_code = 199;
|
2013-04-12 11:00:58 +02:00
|
|
|
else expected_code = STILL_ACTIVE;
|
|
|
|
|
2013-04-25 09:37:06 +02:00
|
|
|
if (test_dll_phase == 3)
|
2013-04-12 11:00:58 +02:00
|
|
|
{
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
|
|
|
|
/* FIXME: remove once Wine is fixed */
|
2016-02-15 21:06:44 +01:00
|
|
|
todo_wine_if (!(expected_code == STILL_ACTIVE || expected_code == 196))
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(!ret || broken(ret) /* before Vista */, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:55:43 +02:00
|
|
|
/* In the case that the process is terminating, FLS slots should still be accessible, but
|
|
|
|
* the callback should be already run for this thread and the contents already NULL.
|
|
|
|
* Note that this is broken for Win2k3, which runs the callbacks *after* the DLL entry
|
|
|
|
* point has already run.
|
|
|
|
*/
|
|
|
|
if (param && pFlsGetValue)
|
|
|
|
{
|
|
|
|
void* value;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
value = pFlsGetValue(fls_index);
|
|
|
|
todo_wine
|
|
|
|
{
|
|
|
|
ok(broken(value == (void*) 0x31415) || /* Win2k3 */
|
|
|
|
value == NULL, "FlsGetValue returned %p, expected NULL\n", value);
|
|
|
|
}
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "FlsGetValue failed with error %u\n", GetLastError());
|
|
|
|
todo_wine
|
|
|
|
{
|
|
|
|
ok(broken(fls_callback_count == thread_detach_count) || /* Win2k3 */
|
|
|
|
fls_callback_count == thread_detach_count + 1,
|
|
|
|
"wrong FLS callback count %d, expected %d\n", fls_callback_count, thread_detach_count + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pFlsFree)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
/* Call FlsFree now and run the remaining callbacks from uncleanly terminated threads */
|
|
|
|
ret = pFlsFree(fls_index);
|
|
|
|
ok(ret, "FlsFree failed with error %u\n", GetLastError());
|
|
|
|
fls_index = FLS_OUT_OF_INDEXES;
|
|
|
|
todo_wine
|
|
|
|
{
|
|
|
|
ok(fls_callback_count == fls_count,
|
|
|
|
"wrong FLS callback count %d, expected %d\n", fls_callback_count, fls_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:39:07 +02:00
|
|
|
ok(attached_thread_count >= 2, "attached thread count should be >= 2\n");
|
2013-04-12 11:00:58 +02:00
|
|
|
|
|
|
|
for (i = 0; i < attached_thread_count; i++)
|
|
|
|
{
|
2013-05-10 12:17:37 +02:00
|
|
|
/* Calling GetExitCodeThread() without waiting for thread termination
|
|
|
|
* leads to different results due to a race condition.
|
|
|
|
*/
|
|
|
|
if (expected_code != STILL_ACTIVE)
|
|
|
|
{
|
|
|
|
ret = WaitForSingleObject(attached_thread[i], 1000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %#x\n", ret);
|
|
|
|
}
|
2013-04-12 11:00:58 +02:00
|
|
|
ret = GetExitCodeThread(attached_thread[i], &code);
|
|
|
|
trace("dll: GetExitCodeThread(%u) => %d,%u\n", i, ret, code);
|
|
|
|
ok(ret == 1, "GetExitCodeThread returned %d, expected 1\n", ret);
|
2013-04-15 11:21:21 +02:00
|
|
|
ok(code == expected_code, "expected thread exit code %u, got %u\n", expected_code, code);
|
2013-04-12 11:00:58 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
ret = WaitForSingleObject(event, 0);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
|
|
|
|
ret = WaitForSingleObject(mutex, 0);
|
|
|
|
if (expected_code == STILL_ACTIVE)
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
else
|
2013-05-10 12:17:37 +02:00
|
|
|
ok(ret == WAIT_ABANDONED, "expected WAIT_ABANDONED, got %#x\n", ret);
|
2013-04-17 11:52:38 +02:00
|
|
|
|
|
|
|
/* semaphore is not abandoned on thread termination */
|
|
|
|
ret = WaitForSingleObject(semaphore, 0);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
|
|
|
|
if (expected_code == STILL_ACTIVE)
|
|
|
|
{
|
|
|
|
ret = WaitForSingleObject(attached_thread[0], 0);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
ret = WaitForSingleObject(attached_thread[1], 0);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = WaitForSingleObject(attached_thread[0], 0);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %#x\n", ret);
|
|
|
|
ret = WaitForSingleObject(attached_thread[1], 0);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %#x\n", ret);
|
|
|
|
}
|
|
|
|
|
2015-08-07 15:40:50 +02:00
|
|
|
/* win7 doesn't allow creating a thread during process shutdown but
|
2013-04-18 10:44:16 +02:00
|
|
|
* earlier Windows versions allow it.
|
|
|
|
*/
|
|
|
|
noop_thread_started = 0;
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-04-24 13:39:07 +02:00
|
|
|
handle = CreateThread(NULL, 0, noop_thread_proc, &noop_thread_started, 0, &ret);
|
2013-04-25 09:37:06 +02:00
|
|
|
if (param)
|
2013-04-18 10:44:16 +02:00
|
|
|
{
|
|
|
|
ok(!handle || broken(handle != 0) /* before win7 */, "CreateThread should fail\n");
|
|
|
|
if (!handle)
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
else
|
2013-04-24 13:39:07 +02:00
|
|
|
{
|
|
|
|
ret = WaitForSingleObject(handle, 1000);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
2013-04-18 10:44:16 +02:00
|
|
|
CloseHandle(handle);
|
2013-04-24 13:39:07 +02:00
|
|
|
}
|
2013-04-18 10:44:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-22 11:33:22 +02:00
|
|
|
ok(handle != 0, "CreateThread error %d\n", GetLastError());
|
|
|
|
ret = WaitForSingleObject(handle, 1000);
|
2013-04-18 10:44:16 +02:00
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
ok(!noop_thread_started || broken(noop_thread_started) /* XP64 */, "thread shouldn't start yet\n");
|
|
|
|
CloseHandle(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2014-02-07 15:08:57 +01:00
|
|
|
process = OpenProcess(PROCESS_ALL_ACCESS_NT4, FALSE, GetCurrentProcessId());
|
2013-04-18 10:44:16 +02:00
|
|
|
ok(process != NULL, "OpenProcess error %d\n", GetLastError());
|
|
|
|
|
|
|
|
noop_thread_started = 0;
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-04-24 13:39:07 +02:00
|
|
|
handle = CreateRemoteThread(process, NULL, 0, noop_thread_proc, &noop_thread_started, 0, &ret);
|
2013-04-25 09:37:06 +02:00
|
|
|
if (param)
|
2013-04-18 10:44:16 +02:00
|
|
|
{
|
|
|
|
ok(!handle || broken(handle != 0) /* before win7 */, "CreateRemoteThread should fail\n");
|
|
|
|
if (!handle)
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
else
|
2013-04-24 13:39:07 +02:00
|
|
|
{
|
|
|
|
ret = WaitForSingleObject(handle, 1000);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
2013-04-18 10:44:16 +02:00
|
|
|
CloseHandle(handle);
|
2013-04-24 13:39:07 +02:00
|
|
|
}
|
2013-04-18 10:44:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-22 11:33:22 +02:00
|
|
|
ok(handle != 0, "CreateRemoteThread error %d\n", GetLastError());
|
|
|
|
ret = WaitForSingleObject(handle, 1000);
|
2013-04-18 10:44:16 +02:00
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
ok(!noop_thread_started || broken(noop_thread_started) /* XP64 */, "thread shouldn't start yet\n");
|
2013-04-22 11:33:22 +02:00
|
|
|
CloseHandle(handle);
|
2013-04-18 10:44:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
handle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4096, NULL);
|
2013-04-18 10:44:16 +02:00
|
|
|
ok(handle != 0, "CreateFileMapping error %d\n", GetLastError());
|
|
|
|
|
|
|
|
offset.u.LowPart = 0;
|
|
|
|
offset.u.HighPart = 0;
|
|
|
|
addr = NULL;
|
|
|
|
size = 0;
|
|
|
|
ret = pNtMapViewOfSection(handle, process, &addr, 0, 0, &offset,
|
|
|
|
&size, 1 /* ViewShare */, 0, PAGE_READONLY);
|
|
|
|
ok(ret == STATUS_SUCCESS, "NtMapViewOfSection error %#x\n", ret);
|
|
|
|
ret = pNtUnmapViewOfSection(process, addr);
|
|
|
|
ok(ret == STATUS_SUCCESS, "NtUnmapViewOfSection error %#x\n", ret);
|
|
|
|
|
|
|
|
CloseHandle(handle);
|
|
|
|
CloseHandle(process);
|
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
handle = GetModuleHandleA("winver.exe");
|
2013-04-18 10:44:16 +02:00
|
|
|
ok(!handle, "winver.exe shouldn't be loaded yet\n");
|
2013-04-19 11:48:31 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-01 23:09:53 +02:00
|
|
|
handle = LoadLibraryA("winver.exe");
|
2013-04-18 10:44:16 +02:00
|
|
|
ok(handle != 0, "LoadLibrary error %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = FreeLibrary(handle);
|
2013-04-19 11:48:31 +02:00
|
|
|
ok(ret, "FreeLibrary error %d\n", GetLastError());
|
2013-10-17 04:45:23 +02:00
|
|
|
handle = GetModuleHandleA("winver.exe");
|
2013-04-25 09:37:06 +02:00
|
|
|
if (param)
|
2013-04-19 11:48:31 +02:00
|
|
|
ok(handle != 0, "winver.exe should not be unloaded\n");
|
|
|
|
else
|
|
|
|
todo_wine
|
|
|
|
ok(!handle || broken(handle != 0) /* before win7 */, "winver.exe should be unloaded\n");
|
2013-04-18 10:44:16 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WaitForDebugEvent(&de, 0);
|
|
|
|
ok(!ret, "WaitForDebugEvent should fail\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DebugActiveProcess(GetCurrentProcessId());
|
|
|
|
ok(!ret, "DebugActiveProcess should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WaitForDebugEvent(&de, 0);
|
|
|
|
ok(!ret, "WaitForDebugEvent should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_SEM_TIMEOUT, "expected ERROR_SEM_TIMEOUT, got %d\n", GetLastError());
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
if (test_dll_phase == 2)
|
|
|
|
{
|
|
|
|
trace("dll: call ExitProcess()\n");
|
|
|
|
*child_failures = winetest_get_failures();
|
|
|
|
ExitProcess(197);
|
|
|
|
}
|
2013-04-18 10:44:16 +02:00
|
|
|
trace("dll: %p, DLL_PROCESS_DETACH, %p => DONE\n", hinst, param);
|
2013-04-12 11:00:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
trace("dll: %p, DLL_THREAD_ATTACH, %p\n", hinst, param);
|
|
|
|
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(!ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
|
|
|
|
if (attached_thread_count < MAX_COUNT)
|
|
|
|
{
|
|
|
|
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &attached_thread[attached_thread_count],
|
|
|
|
0, TRUE, DUPLICATE_SAME_ACCESS);
|
|
|
|
attached_thread_count++;
|
|
|
|
}
|
2016-08-03 00:55:43 +02:00
|
|
|
|
|
|
|
/* Make sure the FLS slot is empty, if FLS is available */
|
|
|
|
if (pFlsGetValue)
|
|
|
|
{
|
|
|
|
void* value;
|
|
|
|
BOOL ret;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
value = pFlsGetValue(fls_index);
|
|
|
|
ok(!value, "FlsGetValue returned %p, expected NULL\n", value);
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "FlsGetValue failed with error %u\n", GetLastError());
|
|
|
|
ret = pFlsSetValue(fls_index, (void*) 0x31415);
|
|
|
|
ok(ret, "FlsSetValue failed\n");
|
|
|
|
fls_count++;
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
break;
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
trace("dll: %p, DLL_THREAD_DETACH, %p\n", hinst, param);
|
2016-08-03 00:55:43 +02:00
|
|
|
thread_detach_count++;
|
2013-04-12 11:00:58 +02:00
|
|
|
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
2015-08-07 15:40:50 +02:00
|
|
|
/* win7 doesn't allow creating a thread during process shutdown but
|
|
|
|
* earlier Windows versions allow it. In that case DLL_THREAD_DETACH is
|
2013-04-18 10:44:16 +02:00
|
|
|
* sent on thread exit, but DLL_THREAD_ATTACH is never received.
|
|
|
|
*/
|
|
|
|
if (noop_thread_started)
|
|
|
|
ok(ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
else
|
|
|
|
ok(!ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
2013-04-12 11:00:58 +02:00
|
|
|
|
2016-08-03 00:55:43 +02:00
|
|
|
/* FLS data should already be destroyed, if FLS is available.
|
|
|
|
* Note that this is broken for Win2k3, which runs the callbacks *after* the DLL entry
|
|
|
|
* point has already run.
|
|
|
|
*/
|
|
|
|
if (pFlsGetValue && fls_index != FLS_OUT_OF_INDEXES)
|
|
|
|
{
|
|
|
|
void* value;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
value = pFlsGetValue(fls_index);
|
|
|
|
todo_wine
|
|
|
|
{
|
|
|
|
ok(broken(value == (void*) 0x31415) || /* Win2k3 */
|
|
|
|
!value, "FlsGetValue returned %p, expected NULL\n", value);
|
|
|
|
}
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "FlsGetValue failed with error %u\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
trace("dll: %p, %d, %p\n", hinst, reason, param);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*child_failures = winetest_get_failures();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void child_process(const char *dll_name, DWORD target_offset)
|
|
|
|
{
|
|
|
|
void *target;
|
|
|
|
DWORD ret, dummy, i, code, expected_code;
|
2013-04-26 10:56:59 +02:00
|
|
|
HANDLE file, thread, process;
|
2013-04-12 11:00:58 +02:00
|
|
|
HMODULE hmod;
|
2013-04-26 10:56:59 +02:00
|
|
|
struct PROCESS_BASIC_INFORMATION_PRIVATE pbi;
|
|
|
|
DWORD_PTR affinity;
|
2013-04-12 11:00:58 +02:00
|
|
|
|
|
|
|
trace("phase %d: writing %p at %#x\n", test_dll_phase, dll_entry_point, target_offset);
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
mutex = CreateMutexW(NULL, FALSE, NULL);
|
2013-04-17 11:52:38 +02:00
|
|
|
ok(mutex != 0, "CreateMutex error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
semaphore = CreateSemaphoreW(NULL, 1, 1, NULL);
|
2013-04-17 11:52:38 +02:00
|
|
|
ok(semaphore != 0, "CreateSemaphore error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2013-04-17 11:52:38 +02:00
|
|
|
ok(event != 0, "CreateEvent error %d\n", GetLastError());
|
|
|
|
|
2013-04-30 10:20:24 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
loader_lock_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2013-04-30 10:20:24 +02:00
|
|
|
ok(loader_lock_event != 0, "CreateEvent error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
peb_lock_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2013-04-30 10:20:24 +02:00
|
|
|
ok(peb_lock_event != 0, "CreateEvent error %d\n", GetLastError());
|
|
|
|
|
2013-05-13 09:45:45 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
heap_lock_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2013-05-13 09:45:45 +02:00
|
|
|
ok(heap_lock_event != 0, "CreateEvent error %d\n", GetLastError());
|
|
|
|
|
2018-08-07 10:03:13 +02:00
|
|
|
InitializeCriticalSection(&cs_lock);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
cs_lock_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
|
|
|
ok(cs_lock_event != 0, "CreateEvent error %d\n", GetLastError());
|
|
|
|
|
2013-04-30 10:20:24 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
ack_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2013-04-30 10:20:24 +02:00
|
|
|
ok(ack_event != 0, "CreateEvent error %d\n", GetLastError());
|
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
file = CreateFileA(dll_name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
|
2013-04-12 11:00:58 +02:00
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ok(0, "could not open %s\n", dll_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetFilePointer(file, target_offset, NULL, FILE_BEGIN);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
target = dll_entry_point;
|
|
|
|
ret = WriteFile(file, &target, sizeof(target), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-01 23:09:53 +02:00
|
|
|
hmod = LoadLibraryA(dll_name);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(hmod != 0, "LoadLibrary error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
stop_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(stop_event != 0, "CreateEvent error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-04-17 11:52:38 +02:00
|
|
|
thread = CreateThread(NULL, 0, mutex_thread_proc, event, 0, &dummy);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(thread != 0, "CreateThread error %d\n", GetLastError());
|
|
|
|
WaitForSingleObject(event, 3000);
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
ResetEvent(event);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-04-17 11:52:38 +02:00
|
|
|
thread = CreateThread(NULL, 0, semaphore_thread_proc, event, 0, &dummy);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(thread != 0, "CreateThread error %d\n", GetLastError());
|
|
|
|
WaitForSingleObject(event, 3000);
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
ResetEvent(event);
|
2013-04-12 11:00:58 +02:00
|
|
|
Sleep(100);
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
ok(attached_thread_count == 2, "attached thread count should be 2\n");
|
2013-04-12 11:00:58 +02:00
|
|
|
for (i = 0; i < attached_thread_count; i++)
|
|
|
|
{
|
|
|
|
ret = GetExitCodeThread(attached_thread[i], &code);
|
|
|
|
trace("child: GetExitCodeThread(%u) => %d,%u\n", i, ret, code);
|
|
|
|
ok(ret == 1, "GetExitCodeThread returned %d, expected 1\n", ret);
|
|
|
|
ok(code == STILL_ACTIVE, "expected thread exit code STILL_ACTIVE, got %u\n", code);
|
|
|
|
}
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
ret = WaitForSingleObject(attached_thread[0], 0);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
ret = WaitForSingleObject(attached_thread[1], 0);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
|
|
|
|
ret = WaitForSingleObject(event, 0);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
ret = WaitForSingleObject(mutex, 0);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
ret = WaitForSingleObject(semaphore, 0);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
2013-04-12 11:00:58 +02:00
|
|
|
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(!ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
|
2013-04-26 10:56:59 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2014-02-07 15:08:57 +01:00
|
|
|
process = OpenProcess(PROCESS_ALL_ACCESS_NT4, FALSE, GetCurrentProcessId());
|
2013-04-26 10:56:59 +02:00
|
|
|
ok(process != NULL, "OpenProcess error %d\n", GetLastError());
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = TerminateProcess(0, 195);
|
|
|
|
ok(!ret, "TerminateProcess(0) should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
Sleep(100);
|
|
|
|
|
2013-04-26 10:56:59 +02:00
|
|
|
affinity = 1;
|
|
|
|
ret = pNtSetInformationProcess(process, ProcessAffinityMask, &affinity, sizeof(affinity));
|
|
|
|
ok(!ret, "NtSetInformationProcess error %#x\n", ret);
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
switch (test_dll_phase)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(!ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
trace("call NtTerminateProcess(0, 195)\n");
|
2013-04-26 10:56:59 +02:00
|
|
|
ret = pNtTerminateProcess(0, 195);
|
|
|
|
ok(!ret, "NtTerminateProcess error %#x\n", ret);
|
|
|
|
|
|
|
|
memset(&pbi, 0, sizeof(pbi));
|
|
|
|
ret = pNtQueryInformationProcess(process, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
|
|
|
|
ok(!ret, "NtQueryInformationProcess error %#x\n", ret);
|
2016-07-28 06:45:15 +02:00
|
|
|
ok(pbi.ExitStatus == STILL_ACTIVE || pbi.ExitStatus == 195,
|
|
|
|
"expected STILL_ACTIVE, got %lu\n", pbi.ExitStatus);
|
2013-04-26 10:56:59 +02:00
|
|
|
affinity = 1;
|
|
|
|
ret = pNtSetInformationProcess(process, ProcessAffinityMask, &affinity, sizeof(affinity));
|
|
|
|
ok(!ret, "NtSetInformationProcess error %#x\n", ret);
|
2013-04-12 11:00:58 +02:00
|
|
|
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(!ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
hmod = GetModuleHandleA(dll_name);
|
2013-04-25 09:37:06 +02:00
|
|
|
ok(hmod != 0, "DLL should not be unloaded\n");
|
|
|
|
|
2013-04-24 13:39:07 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
thread = CreateThread(NULL, 0, noop_thread_proc, &dummy, 0, &ret);
|
|
|
|
ok(!thread || broken(thread != 0) /* before win7 */, "CreateThread should fail\n");
|
|
|
|
if (!thread)
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = WaitForSingleObject(thread, 1000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %#x\n", ret);
|
|
|
|
CloseHandle(thread);
|
|
|
|
}
|
|
|
|
|
2013-04-25 09:37:06 +02:00
|
|
|
trace("call LdrShutdownProcess()\n");
|
|
|
|
pLdrShutdownProcess();
|
|
|
|
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
hmod = GetModuleHandleA(dll_name);
|
2013-04-25 09:37:06 +02:00
|
|
|
ok(hmod != 0, "DLL should not be unloaded\n");
|
2013-04-26 10:56:59 +02:00
|
|
|
|
|
|
|
memset(&pbi, 0, sizeof(pbi));
|
|
|
|
ret = pNtQueryInformationProcess(process, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
|
|
|
|
ok(!ret, "NtQueryInformationProcess error %#x\n", ret);
|
2016-07-28 06:45:15 +02:00
|
|
|
ok(pbi.ExitStatus == STILL_ACTIVE || pbi.ExitStatus == 195,
|
|
|
|
"expected STILL_ACTIVE, got %lu\n", pbi.ExitStatus);
|
2013-04-26 10:56:59 +02:00
|
|
|
affinity = 1;
|
|
|
|
ret = pNtSetInformationProcess(process, ProcessAffinityMask, &affinity, sizeof(affinity));
|
|
|
|
ok(!ret, "NtSetInformationProcess error %#x\n", ret);
|
2013-04-12 11:00:58 +02:00
|
|
|
break;
|
|
|
|
|
2013-05-10 12:17:37 +02:00
|
|
|
case 1: /* normal ExitProcess */
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(!ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
break;
|
|
|
|
|
2013-04-18 18:58:05 +02:00
|
|
|
case 2: /* ExitProcess will be called by the PROCESS_DETACH handler */
|
2013-04-12 11:00:58 +02:00
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(!ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
trace("call FreeLibrary(%p)\n", hmod);
|
2013-04-25 09:37:06 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = FreeLibrary(hmod);
|
|
|
|
ok(ret, "FreeLibrary error %d\n", GetLastError());
|
2013-10-17 04:45:23 +02:00
|
|
|
hmod = GetModuleHandleA(dll_name);
|
2013-04-25 09:37:06 +02:00
|
|
|
ok(!hmod, "DLL should be unloaded\n");
|
|
|
|
|
|
|
|
if (test_dll_phase == 2)
|
|
|
|
ok(0, "FreeLibrary+ExitProcess should never return\n");
|
2013-04-12 11:00:58 +02:00
|
|
|
|
|
|
|
ret = pRtlDllShutdownInProgress();
|
|
|
|
ok(!ret, "RtlDllShutdownInProgress returned %d\n", ret);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
trace("signalling thread exit\n");
|
|
|
|
SetEvent(stop_event);
|
|
|
|
break;
|
|
|
|
|
2013-04-30 10:20:24 +02:00
|
|
|
case 4:
|
|
|
|
trace("setting loader_lock_event\n");
|
|
|
|
SetEvent(loader_lock_event);
|
|
|
|
WaitForSingleObject(ack_event, 1000);
|
|
|
|
ok(inside_loader_lock != 0, "inside_loader_lock is not set\n");
|
|
|
|
|
|
|
|
/* calling NtTerminateProcess should not cause a deadlock */
|
|
|
|
trace("call NtTerminateProcess(0, 198)\n");
|
|
|
|
ret = pNtTerminateProcess(0, 198);
|
|
|
|
ok(!ret, "NtTerminateProcess error %#x\n", ret);
|
|
|
|
|
|
|
|
*child_failures = winetest_get_failures();
|
|
|
|
|
|
|
|
/* Windows fails to release loader lock acquired from another thread,
|
|
|
|
* so the LdrUnlockLoaderLock call fails here and ExitProcess deadlocks
|
|
|
|
* later on, so NtTerminateProcess is used instead.
|
|
|
|
*/
|
|
|
|
trace("call NtTerminateProcess(GetCurrentProcess(), 198)\n");
|
|
|
|
pNtTerminateProcess(GetCurrentProcess(), 198);
|
|
|
|
ok(0, "NtTerminateProcess should not return\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
trace("setting peb_lock_event\n");
|
|
|
|
SetEvent(peb_lock_event);
|
|
|
|
WaitForSingleObject(ack_event, 1000);
|
|
|
|
ok(inside_peb_lock != 0, "inside_peb_lock is not set\n");
|
|
|
|
|
|
|
|
*child_failures = winetest_get_failures();
|
|
|
|
|
|
|
|
/* calling ExitProcess should cause a deadlock */
|
|
|
|
trace("call ExitProcess(198)\n");
|
|
|
|
ExitProcess(198);
|
|
|
|
ok(0, "ExitProcess should not return\n");
|
|
|
|
break;
|
|
|
|
|
2013-05-13 09:45:45 +02:00
|
|
|
case 6:
|
|
|
|
trace("setting heap_lock_event\n");
|
|
|
|
SetEvent(heap_lock_event);
|
|
|
|
WaitForSingleObject(ack_event, 1000);
|
|
|
|
ok(inside_heap_lock != 0, "inside_heap_lock is not set\n");
|
|
|
|
|
|
|
|
*child_failures = winetest_get_failures();
|
|
|
|
|
|
|
|
/* calling ExitProcess should cause a deadlock */
|
|
|
|
trace("call ExitProcess(1)\n");
|
|
|
|
ExitProcess(1);
|
|
|
|
ok(0, "ExitProcess should not return\n");
|
|
|
|
break;
|
|
|
|
|
2018-08-07 10:03:13 +02:00
|
|
|
case 7:
|
|
|
|
trace("setting cs_lock_event\n");
|
|
|
|
SetEvent(cs_lock_event);
|
|
|
|
WaitForSingleObject(ack_event, 1000);
|
|
|
|
ok(inside_cs_lock != 0, "inside_cs_lock is not set\n");
|
|
|
|
|
|
|
|
*child_failures = winetest_get_failures();
|
|
|
|
|
|
|
|
/* calling ExitProcess should not cause a deadlock */
|
|
|
|
trace("call ExitProcess(199)\n");
|
|
|
|
ExitProcess(199);
|
|
|
|
ok(0, "ExitProcess should not return\n");
|
|
|
|
break;
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_dll_phase == 0) expected_code = 195;
|
|
|
|
else if (test_dll_phase == 3) expected_code = 196;
|
2013-04-30 10:20:24 +02:00
|
|
|
else if (test_dll_phase == 4) expected_code = 198;
|
2013-04-12 11:00:58 +02:00
|
|
|
else expected_code = STILL_ACTIVE;
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
if (expected_code == STILL_ACTIVE)
|
|
|
|
{
|
2013-04-25 09:37:06 +02:00
|
|
|
ret = WaitForSingleObject(attached_thread[0], 100);
|
2013-04-17 11:52:38 +02:00
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
2013-04-25 09:37:06 +02:00
|
|
|
ret = WaitForSingleObject(attached_thread[1], 100);
|
2013-04-17 11:52:38 +02:00
|
|
|
ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %#x\n", ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-18 17:28:11 +02:00
|
|
|
ret = WaitForSingleObject(attached_thread[0], 2000);
|
2013-04-17 11:52:38 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %#x\n", ret);
|
2017-07-18 17:28:11 +02:00
|
|
|
ret = WaitForSingleObject(attached_thread[1], 2000);
|
2013-04-17 11:52:38 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %#x\n", ret);
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:00:58 +02:00
|
|
|
for (i = 0; i < attached_thread_count; i++)
|
|
|
|
{
|
|
|
|
ret = GetExitCodeThread(attached_thread[i], &code);
|
|
|
|
trace("child: GetExitCodeThread(%u) => %d,%u\n", i, ret, code);
|
|
|
|
ok(ret == 1, "GetExitCodeThread returned %d, expected 1\n", ret);
|
2013-04-15 11:21:21 +02:00
|
|
|
ok(code == expected_code, "expected thread exit code %u, got %u\n", expected_code, code);
|
2013-04-12 11:00:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*child_failures = winetest_get_failures();
|
|
|
|
|
2013-04-30 10:20:24 +02:00
|
|
|
trace("call ExitProcess(195)\n");
|
2013-04-12 11:00:58 +02:00
|
|
|
ExitProcess(195);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_ExitProcess(void)
|
|
|
|
{
|
|
|
|
#include "pshpack1.h"
|
2013-04-15 11:10:00 +02:00
|
|
|
#ifdef __x86_64__
|
2013-04-12 11:00:58 +02:00
|
|
|
static struct section_data
|
|
|
|
{
|
2013-04-15 11:10:00 +02:00
|
|
|
BYTE mov_rax[2];
|
2013-04-12 11:00:58 +02:00
|
|
|
void *target;
|
2013-04-15 11:10:00 +02:00
|
|
|
BYTE jmp_rax[2];
|
|
|
|
} section_data = { { 0x48,0xb8 }, dll_entry_point, { 0xff,0xe0 } };
|
2013-04-12 11:00:58 +02:00
|
|
|
#else
|
|
|
|
static struct section_data
|
|
|
|
{
|
2013-04-15 11:10:00 +02:00
|
|
|
BYTE mov_eax;
|
2013-04-12 11:00:58 +02:00
|
|
|
void *target;
|
2013-04-15 11:10:00 +02:00
|
|
|
BYTE jmp_eax[2];
|
|
|
|
} section_data = { 0xb8, dll_entry_point, { 0xff,0xe0 } };
|
2013-04-12 11:00:58 +02:00
|
|
|
#endif
|
|
|
|
#include "poppack.h"
|
|
|
|
DWORD dummy, file_align;
|
2013-05-08 07:32:38 +02:00
|
|
|
HANDLE file, thread, process, hmap, hmap_dup;
|
2013-04-12 11:00:58 +02:00
|
|
|
char temp_path[MAX_PATH], dll_name[MAX_PATH], cmdline[MAX_PATH * 2];
|
2013-04-26 10:56:59 +02:00
|
|
|
DWORD ret, target_offset, old_prot;
|
|
|
|
char **argv, buf[256];
|
2013-04-12 11:00:58 +02:00
|
|
|
PROCESS_INFORMATION pi;
|
2013-10-17 04:45:23 +02:00
|
|
|
STARTUPINFOA si = { sizeof(si) };
|
2013-04-26 10:56:59 +02:00
|
|
|
CONTEXT ctx;
|
|
|
|
struct PROCESS_BASIC_INFORMATION_PRIVATE pbi;
|
2013-05-08 07:32:38 +02:00
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
2013-04-26 10:56:59 +02:00
|
|
|
DWORD_PTR affinity;
|
|
|
|
void *addr;
|
|
|
|
LARGE_INTEGER offset;
|
|
|
|
SIZE_T size;
|
2015-01-27 23:02:58 +01:00
|
|
|
IMAGE_NT_HEADERS nt_header;
|
2013-04-12 11:00:58 +02:00
|
|
|
|
2013-04-15 11:10:00 +02:00
|
|
|
#if !defined(__i386__) && !defined(__x86_64__)
|
2013-04-12 11:00:58 +02:00
|
|
|
skip("x86 specific ExitProcess test\n");
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!pRtlDllShutdownInProgress)
|
|
|
|
{
|
2013-04-26 10:56:59 +02:00
|
|
|
win_skip("RtlDllShutdownInProgress is not available on this platform (XP+)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!pNtQueryInformationProcess || !pNtSetInformationProcess)
|
|
|
|
{
|
|
|
|
win_skip("NtQueryInformationProcess/NtSetInformationProcess are not available on this platform\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!pNtAllocateVirtualMemory || !pNtFreeVirtualMemory)
|
|
|
|
{
|
|
|
|
win_skip("NtAllocateVirtualMemory/NtFreeVirtualMemory are not available on this platform\n");
|
2013-04-12 11:00:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* prevent displaying of the "Unable to load this DLL" message box */
|
|
|
|
SetErrorMode(SEM_FAILCRITICALERRORS);
|
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
GetTempPathA(MAX_PATH, temp_path);
|
|
|
|
GetTempFileNameA(temp_path, "ldr", 0, dll_name);
|
2013-04-12 11:00:58 +02:00
|
|
|
|
|
|
|
/*trace("creating %s\n", dll_name);*/
|
2013-10-17 04:45:23 +02:00
|
|
|
file = CreateFileA(dll_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
2013-04-12 11:00:58 +02:00
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ok(0, "could not create %s\n", dll_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(file, &dos_header, sizeof(dos_header), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
2015-01-27 23:02:58 +01:00
|
|
|
nt_header = nt_header_template;
|
2013-04-12 11:00:58 +02:00
|
|
|
nt_header.FileHeader.NumberOfSections = 1;
|
|
|
|
nt_header.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
|
|
|
|
nt_header.FileHeader.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DLL | IMAGE_FILE_RELOCS_STRIPPED;
|
|
|
|
|
|
|
|
nt_header.OptionalHeader.AddressOfEntryPoint = 0x1000;
|
|
|
|
nt_header.OptionalHeader.SectionAlignment = 0x1000;
|
|
|
|
nt_header.OptionalHeader.FileAlignment = 0x200;
|
|
|
|
nt_header.OptionalHeader.SizeOfImage = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0x1000;
|
|
|
|
nt_header.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(file, &nt_header, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(file, &nt_header.OptionalHeader, sizeof(IMAGE_OPTIONAL_HEADER), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
section.SizeOfRawData = sizeof(section_data);
|
|
|
|
section.PointerToRawData = nt_header.OptionalHeader.FileAlignment;
|
|
|
|
section.VirtualAddress = nt_header.OptionalHeader.SectionAlignment;
|
|
|
|
section.Misc.VirtualSize = sizeof(section_data);
|
|
|
|
section.Characteristics = IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_EXECUTE;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(file, §ion, sizeof(section), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
file_align = nt_header.OptionalHeader.FileAlignment - nt_header.OptionalHeader.SizeOfHeaders;
|
|
|
|
assert(file_align < sizeof(filler));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(file, filler, file_align, &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
target_offset = SetFilePointer(file, 0, NULL, FILE_CURRENT) + FIELD_OFFSET(struct section_data, target);
|
|
|
|
|
|
|
|
/* section data */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(file, §ion_data, sizeof(section_data), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
winetest_get_mainargs(&argv);
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
/* phase 0 */
|
2013-04-12 11:00:58 +02:00
|
|
|
*child_failures = -1;
|
|
|
|
sprintf(cmdline, "\"%s\" loader %s %u 0", argv[0], dll_name, target_offset);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
|
2013-04-30 10:20:24 +02:00
|
|
|
ret = WaitForSingleObject(pi.hProcess, 10000);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0, "child process failed to terminate\n");
|
2013-04-30 10:20:24 +02:00
|
|
|
if (ret != WAIT_OBJECT_0) TerminateProcess(pi.hProcess, 0);
|
2013-04-12 11:00:58 +02:00
|
|
|
GetExitCodeProcess(pi.hProcess, &ret);
|
|
|
|
ok(ret == 195, "expected exit code 195, got %u\n", ret);
|
2013-04-18 10:44:43 +02:00
|
|
|
if (*child_failures)
|
|
|
|
{
|
|
|
|
trace("%d failures in child process\n", *child_failures);
|
|
|
|
winetest_add_failures(*child_failures);
|
|
|
|
}
|
2013-04-12 11:00:58 +02:00
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
/* phase 1 */
|
2013-04-12 11:00:58 +02:00
|
|
|
*child_failures = -1;
|
|
|
|
sprintf(cmdline, "\"%s\" loader %s %u 1", argv[0], dll_name, target_offset);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
|
2013-04-30 10:20:24 +02:00
|
|
|
ret = WaitForSingleObject(pi.hProcess, 10000);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0, "child process failed to terminate\n");
|
2013-04-30 10:20:24 +02:00
|
|
|
if (ret != WAIT_OBJECT_0) TerminateProcess(pi.hProcess, 0);
|
2013-04-12 11:00:58 +02:00
|
|
|
GetExitCodeProcess(pi.hProcess, &ret);
|
|
|
|
ok(ret == 195, "expected exit code 195, got %u\n", ret);
|
2013-04-18 10:44:43 +02:00
|
|
|
if (*child_failures)
|
|
|
|
{
|
|
|
|
trace("%d failures in child process\n", *child_failures);
|
|
|
|
winetest_add_failures(*child_failures);
|
|
|
|
}
|
2013-04-12 11:00:58 +02:00
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
/* phase 2 */
|
2013-04-12 11:00:58 +02:00
|
|
|
*child_failures = -1;
|
|
|
|
sprintf(cmdline, "\"%s\" loader %s %u 2", argv[0], dll_name, target_offset);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
|
2013-04-30 10:20:24 +02:00
|
|
|
ret = WaitForSingleObject(pi.hProcess, 10000);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0, "child process failed to terminate\n");
|
2013-04-30 10:20:24 +02:00
|
|
|
if (ret != WAIT_OBJECT_0) TerminateProcess(pi.hProcess, 0);
|
2013-04-12 11:00:58 +02:00
|
|
|
GetExitCodeProcess(pi.hProcess, &ret);
|
|
|
|
ok(ret == 197, "expected exit code 197, got %u\n", ret);
|
2013-04-18 10:44:43 +02:00
|
|
|
if (*child_failures)
|
|
|
|
{
|
|
|
|
trace("%d failures in child process\n", *child_failures);
|
|
|
|
winetest_add_failures(*child_failures);
|
|
|
|
}
|
2013-04-12 11:00:58 +02:00
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
2013-04-17 11:52:38 +02:00
|
|
|
/* phase 3 */
|
2013-04-12 11:00:58 +02:00
|
|
|
*child_failures = -1;
|
|
|
|
sprintf(cmdline, "\"%s\" loader %s %u 3", argv[0], dll_name, target_offset);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
|
2013-04-30 10:20:24 +02:00
|
|
|
ret = WaitForSingleObject(pi.hProcess, 10000);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0, "child process failed to terminate\n");
|
2013-04-30 10:20:24 +02:00
|
|
|
if (ret != WAIT_OBJECT_0) TerminateProcess(pi.hProcess, 0);
|
2013-04-12 11:00:58 +02:00
|
|
|
GetExitCodeProcess(pi.hProcess, &ret);
|
|
|
|
ok(ret == 195, "expected exit code 195, got %u\n", ret);
|
2013-04-18 10:44:43 +02:00
|
|
|
if (*child_failures)
|
|
|
|
{
|
|
|
|
trace("%d failures in child process\n", *child_failures);
|
|
|
|
winetest_add_failures(*child_failures);
|
|
|
|
}
|
2013-04-12 11:00:58 +02:00
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
2013-04-30 10:20:24 +02:00
|
|
|
/* phase 4 */
|
|
|
|
if (pLdrLockLoaderLock && pLdrUnlockLoaderLock)
|
|
|
|
{
|
|
|
|
*child_failures = -1;
|
|
|
|
sprintf(cmdline, "\"%s\" loader %s %u 4", argv[0], dll_name, target_offset);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
2013-04-30 10:20:24 +02:00
|
|
|
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
|
|
|
|
ret = WaitForSingleObject(pi.hProcess, 10000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "child process failed to terminate\n");
|
|
|
|
if (ret != WAIT_OBJECT_0) TerminateProcess(pi.hProcess, 0);
|
|
|
|
GetExitCodeProcess(pi.hProcess, &ret);
|
|
|
|
ok(ret == 198, "expected exit code 198, got %u\n", ret);
|
|
|
|
if (*child_failures)
|
|
|
|
{
|
|
|
|
trace("%d failures in child process\n", *child_failures);
|
|
|
|
winetest_add_failures(*child_failures);
|
|
|
|
}
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
win_skip("LdrLockLoaderLock/LdrUnlockLoaderLock are not available on this platform\n");
|
|
|
|
|
|
|
|
/* phase 5 */
|
|
|
|
if (pRtlAcquirePebLock && pRtlReleasePebLock)
|
|
|
|
{
|
|
|
|
*child_failures = -1;
|
|
|
|
sprintf(cmdline, "\"%s\" loader %s %u 5", argv[0], dll_name, target_offset);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
2013-04-30 10:20:24 +02:00
|
|
|
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
|
|
|
|
ret = WaitForSingleObject(pi.hProcess, 5000);
|
|
|
|
ok(ret == WAIT_TIMEOUT, "child process should fail to terminate\n");
|
|
|
|
if (ret != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
trace("terminating child process\n");
|
|
|
|
TerminateProcess(pi.hProcess, 199);
|
|
|
|
}
|
|
|
|
ret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "child process failed to terminate\n");
|
|
|
|
GetExitCodeProcess(pi.hProcess, &ret);
|
|
|
|
ok(ret == 199, "expected exit code 199, got %u\n", ret);
|
|
|
|
if (*child_failures)
|
|
|
|
{
|
|
|
|
trace("%d failures in child process\n", *child_failures);
|
|
|
|
winetest_add_failures(*child_failures);
|
|
|
|
}
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
win_skip("RtlAcquirePebLock/RtlReleasePebLock are not available on this platform\n");
|
|
|
|
|
2013-05-13 09:45:45 +02:00
|
|
|
/* phase 6 */
|
|
|
|
*child_failures = -1;
|
|
|
|
sprintf(cmdline, "\"%s\" loader %s %u 6", argv[0], dll_name, target_offset);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
2013-05-13 09:45:45 +02:00
|
|
|
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
|
|
|
|
ret = WaitForSingleObject(pi.hProcess, 5000);
|
2018-08-07 10:03:16 +02:00
|
|
|
todo_wine
|
2013-05-13 09:45:45 +02:00
|
|
|
ok(ret == WAIT_TIMEOUT || broken(ret == WAIT_OBJECT_0) /* XP */, "child process should fail to terminate\n");
|
|
|
|
if (ret != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
trace("terminating child process\n");
|
|
|
|
TerminateProcess(pi.hProcess, 201);
|
|
|
|
}
|
|
|
|
ret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "child process failed to terminate\n");
|
|
|
|
GetExitCodeProcess(pi.hProcess, &ret);
|
2018-08-07 10:03:16 +02:00
|
|
|
todo_wine
|
2013-05-13 09:45:45 +02:00
|
|
|
ok(ret == 201 || broken(ret == 1) /* XP */, "expected exit code 201, got %u\n", ret);
|
|
|
|
if (*child_failures)
|
|
|
|
{
|
|
|
|
trace("%d failures in child process\n", *child_failures);
|
|
|
|
winetest_add_failures(*child_failures);
|
|
|
|
}
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
2018-08-07 10:03:13 +02:00
|
|
|
/* phase 7 */
|
|
|
|
*child_failures = -1;
|
|
|
|
sprintf(cmdline, "\"%s\" loader %s %u 7", argv[0], dll_name, target_offset);
|
|
|
|
ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
|
|
|
|
ret = WaitForSingleObject(pi.hProcess, 5000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "child process failed to terminate\n");
|
|
|
|
if (ret != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
trace("terminating child process\n");
|
|
|
|
TerminateProcess(pi.hProcess, 199);
|
|
|
|
}
|
|
|
|
ret = WaitForSingleObject(pi.hProcess, 1000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "child process failed to terminate\n");
|
|
|
|
GetExitCodeProcess(pi.hProcess, &ret);
|
|
|
|
ok(ret == 199, "expected exit code 199, got %u\n", ret);
|
|
|
|
if (*child_failures)
|
|
|
|
{
|
|
|
|
trace("%d failures in child process\n", *child_failures);
|
|
|
|
winetest_add_failures(*child_failures);
|
|
|
|
}
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
2013-04-26 10:56:59 +02:00
|
|
|
/* test remote process termination */
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = CreateProcessA(argv[0], NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
|
2013-04-26 10:56:59 +02:00
|
|
|
ok(ret, "CreateProcess(%s) error %d\n", argv[0], GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
addr = VirtualAllocEx(pi.hProcess, NULL, 4096, MEM_COMMIT, PAGE_READWRITE);
|
|
|
|
ok(addr != NULL, "VirtualAllocEx error %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = VirtualProtectEx(pi.hProcess, addr, 4096, PAGE_READONLY, &old_prot);
|
|
|
|
ok(ret, "VirtualProtectEx error %d\n", GetLastError());
|
|
|
|
ok(old_prot == PAGE_READWRITE, "expected PAGE_READWRITE, got %#x\n", old_prot);
|
2013-05-08 07:32:38 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = VirtualQueryEx(pi.hProcess, NULL, &mbi, sizeof(mbi));
|
|
|
|
ok(size == sizeof(mbi), "VirtualQueryEx error %d\n", GetLastError());
|
|
|
|
|
2013-04-26 10:56:59 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadProcessMemory(pi.hProcess, addr, buf, 4, &size);
|
|
|
|
ok(ret, "ReadProcessMemory error %d\n", GetLastError());
|
|
|
|
ok(size == 4, "expected 4, got %lu\n", size);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-17 04:45:23 +02:00
|
|
|
hmap = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4096, NULL);
|
2013-04-26 10:56:59 +02:00
|
|
|
ok(hmap != 0, "CreateFileMapping error %d\n", GetLastError());
|
|
|
|
|
2013-05-08 07:32:38 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DuplicateHandle(GetCurrentProcess(), hmap, pi.hProcess, &hmap_dup,
|
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS);
|
|
|
|
ok(ret, "DuplicateHandle error %d\n", GetLastError());
|
|
|
|
|
2013-04-26 10:56:59 +02:00
|
|
|
offset.u.LowPart = 0;
|
|
|
|
offset.u.HighPart = 0;
|
|
|
|
addr = NULL;
|
|
|
|
size = 0;
|
|
|
|
ret = pNtMapViewOfSection(hmap, pi.hProcess, &addr, 0, 0, &offset,
|
|
|
|
&size, 1 /* ViewShare */, 0, PAGE_READONLY);
|
|
|
|
ok(!ret, "NtMapViewOfSection error %#x\n", ret);
|
|
|
|
ret = pNtUnmapViewOfSection(pi.hProcess, addr);
|
|
|
|
ok(!ret, "NtUnmapViewOfSection error %#x\n", ret);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
thread = CreateRemoteThread(pi.hProcess, NULL, 0, (void *)0xdeadbeef, NULL, CREATE_SUSPENDED, &ret);
|
|
|
|
ok(thread != 0, "CreateRemoteThread error %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ctx.ContextFlags = CONTEXT_INTEGER;
|
|
|
|
ret = GetThreadContext(thread, &ctx);
|
|
|
|
ok(ret, "GetThreadContext error %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ctx.ContextFlags = CONTEXT_INTEGER;
|
|
|
|
ret = SetThreadContext(thread, &ctx);
|
|
|
|
ok(ret, "SetThreadContext error %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetThreadPriority(thread, 0);
|
|
|
|
ok(ret, "SetThreadPriority error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = TerminateThread(thread, 199);
|
|
|
|
ok(ret, "TerminateThread error %d\n", GetLastError());
|
|
|
|
/* Calling GetExitCodeThread() without waiting for thread termination
|
|
|
|
* leads to different results due to a race condition.
|
|
|
|
*/
|
2013-04-30 10:20:24 +02:00
|
|
|
ret = WaitForSingleObject(thread, 1000);
|
2013-04-26 10:56:59 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed: %x\n", ret);
|
|
|
|
GetExitCodeThread(thread, &ret);
|
|
|
|
ok(ret == 199, "expected exit code 199, got %u\n", ret);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = TerminateProcess(pi.hProcess, 198);
|
|
|
|
ok(ret, "TerminateProcess error %d\n", GetLastError());
|
|
|
|
/* Checking process state without waiting for process termination
|
|
|
|
* leads to different results due to a race condition.
|
|
|
|
*/
|
2013-05-06 08:40:34 +02:00
|
|
|
ret = WaitForSingleObject(pi.hProcess, 1000);
|
2013-04-26 10:56:59 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed: %x\n", ret);
|
|
|
|
|
2013-05-08 07:32:38 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2014-02-07 15:08:57 +01:00
|
|
|
process = OpenProcess(PROCESS_ALL_ACCESS_NT4, FALSE, pi.dwProcessId);
|
2013-05-08 07:32:38 +02:00
|
|
|
ok(process != NULL, "OpenProcess error %d\n", GetLastError());
|
|
|
|
CloseHandle(process);
|
|
|
|
|
2013-04-26 10:56:59 +02:00
|
|
|
memset(&pbi, 0, sizeof(pbi));
|
|
|
|
ret = pNtQueryInformationProcess(pi.hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
|
|
|
|
ok(!ret, "NtQueryInformationProcess error %#x\n", ret);
|
|
|
|
ok(pbi.ExitStatus == 198, "expected 198, got %lu\n", pbi.ExitStatus);
|
|
|
|
affinity = 1;
|
|
|
|
ret = pNtSetInformationProcess(pi.hProcess, ProcessAffinityMask, &affinity, sizeof(affinity));
|
|
|
|
ok(ret == STATUS_PROCESS_IS_TERMINATING, "expected STATUS_PROCESS_IS_TERMINATING, got %#x\n", ret);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ctx.ContextFlags = CONTEXT_INTEGER;
|
|
|
|
ret = GetThreadContext(thread, &ctx);
|
|
|
|
ok(!ret || broken(ret) /* XP 64-bit */, "GetThreadContext should fail\n");
|
|
|
|
if (!ret)
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER ||
|
|
|
|
GetLastError() == ERROR_GEN_FAILURE /* win7 64-bit */ ||
|
|
|
|
GetLastError() == ERROR_INVALID_FUNCTION /* vista 64-bit */,
|
|
|
|
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ctx.ContextFlags = CONTEXT_INTEGER;
|
|
|
|
ret = SetThreadContext(thread, &ctx);
|
|
|
|
ok(!ret || broken(ret) /* XP 64-bit */, "SetThreadContext should fail\n");
|
|
|
|
if (!ret)
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED ||
|
|
|
|
GetLastError() == ERROR_GEN_FAILURE /* win7 64-bit */ ||
|
|
|
|
GetLastError() == ERROR_INVALID_FUNCTION /* vista 64-bit */,
|
|
|
|
"expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetThreadPriority(thread, 0);
|
|
|
|
ok(ret, "SetThreadPriority error %d\n", GetLastError());
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ctx.ContextFlags = CONTEXT_INTEGER;
|
|
|
|
ret = GetThreadContext(pi.hThread, &ctx);
|
|
|
|
ok(!ret || broken(ret) /* XP 64-bit */, "GetThreadContext should fail\n");
|
|
|
|
if (!ret)
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER ||
|
|
|
|
GetLastError() == ERROR_GEN_FAILURE /* win7 64-bit */ ||
|
|
|
|
GetLastError() == ERROR_INVALID_FUNCTION /* vista 64-bit */,
|
|
|
|
"expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ctx.ContextFlags = CONTEXT_INTEGER;
|
|
|
|
ret = SetThreadContext(pi.hThread, &ctx);
|
|
|
|
ok(!ret || broken(ret) /* XP 64-bit */, "SetThreadContext should fail\n");
|
|
|
|
if (!ret)
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED ||
|
|
|
|
GetLastError() == ERROR_GEN_FAILURE /* win7 64-bit */ ||
|
|
|
|
GetLastError() == ERROR_INVALID_FUNCTION /* vista 64-bit */,
|
|
|
|
"expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = VirtualProtectEx(pi.hProcess, addr, 4096, PAGE_READWRITE, &old_prot);
|
|
|
|
ok(!ret, "VirtualProtectEx should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = 0;
|
|
|
|
ret = ReadProcessMemory(pi.hProcess, addr, buf, 4, &size);
|
|
|
|
ok(!ret, "ReadProcessMemory should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_PARTIAL_COPY || GetLastError() == ERROR_ACCESS_DENIED,
|
|
|
|
"expected ERROR_PARTIAL_COPY, got %d\n", GetLastError());
|
|
|
|
ok(!size, "expected 0, got %lu\n", size);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = VirtualFreeEx(pi.hProcess, addr, 0, MEM_RELEASE);
|
|
|
|
ok(!ret, "VirtualFreeEx should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
addr = VirtualAllocEx(pi.hProcess, NULL, 4096, MEM_COMMIT, PAGE_READWRITE);
|
|
|
|
ok(!addr, "VirtualAllocEx should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
2013-05-08 07:32:38 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
size = VirtualQueryEx(pi.hProcess, NULL, &mbi, sizeof(mbi));
|
|
|
|
ok(!size, "VirtualQueryEx should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* CloseHandle() call below leads to premature process termination
|
|
|
|
* under some Windows versions.
|
|
|
|
*/
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CloseHandle(hmap_dup);
|
|
|
|
ok(ret, "CloseHandle should not fail\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DuplicateHandle(GetCurrentProcess(), hmap, pi.hProcess, &hmap_dup,
|
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS);
|
|
|
|
ok(!ret, "DuplicateHandle should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
2013-04-26 10:56:59 +02:00
|
|
|
|
|
|
|
offset.u.LowPart = 0;
|
|
|
|
offset.u.HighPart = 0;
|
|
|
|
addr = NULL;
|
|
|
|
size = 0;
|
|
|
|
ret = pNtMapViewOfSection(hmap, pi.hProcess, &addr, 0, 0, &offset,
|
|
|
|
&size, 1 /* ViewShare */, 0, PAGE_READONLY);
|
|
|
|
ok(ret == STATUS_PROCESS_IS_TERMINATING, "expected STATUS_PROCESS_IS_TERMINATING, got %#x\n", ret);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
thread = CreateRemoteThread(pi.hProcess, NULL, 0, (void *)0xdeadbeef, NULL, CREATE_SUSPENDED, &ret);
|
|
|
|
ok(!thread, "CreateRemoteThread should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = DebugActiveProcess(pi.dwProcessId);
|
|
|
|
ok(!ret, "DebugActiveProcess should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED /* 64-bit */ || GetLastError() == ERROR_NOT_SUPPORTED /* 32-bit */,
|
|
|
|
"ERROR_ACCESS_DENIED, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
GetExitCodeProcess(pi.hProcess, &ret);
|
|
|
|
ok(ret == 198 || broken(ret != 198) /* some 32-bit XP version in a VM returns random exit code */,
|
|
|
|
"expected exit code 198, got %u\n", ret);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
ret = DeleteFileA(dll_name);
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(ret, "DeleteFile error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2013-09-11 22:31:01 +02:00
|
|
|
static PVOID WINAPI failuredllhook(ULONG ul, DELAYLOAD_INFO* pd)
|
|
|
|
{
|
2013-11-11 23:17:55 +01:00
|
|
|
ok(ul == 4, "expected 4, got %u\n", ul);
|
|
|
|
ok(!!pd, "no delayload info supplied\n");
|
|
|
|
if (pd)
|
|
|
|
{
|
|
|
|
ok(pd->Size == sizeof(*pd), "got %u\n", pd->Size);
|
|
|
|
ok(!!pd->DelayloadDescriptor, "no DelayloadDescriptor supplied\n");
|
|
|
|
if (pd->DelayloadDescriptor)
|
|
|
|
{
|
|
|
|
ok(pd->DelayloadDescriptor->Attributes.AllAttributes == 1,
|
|
|
|
"expected 1, got %u\n", pd->DelayloadDescriptor->Attributes.AllAttributes);
|
|
|
|
ok(pd->DelayloadDescriptor->DllNameRVA == 0x2000,
|
|
|
|
"expected 0x2000, got %x\n", pd->DelayloadDescriptor->DllNameRVA);
|
|
|
|
ok(pd->DelayloadDescriptor->ModuleHandleRVA == 0x201a,
|
|
|
|
"expected 0x201a, got %x\n", pd->DelayloadDescriptor->ModuleHandleRVA);
|
|
|
|
ok(pd->DelayloadDescriptor->ImportAddressTableRVA > pd->DelayloadDescriptor->ModuleHandleRVA,
|
|
|
|
"expected %x > %x\n", pd->DelayloadDescriptor->ImportAddressTableRVA,
|
|
|
|
pd->DelayloadDescriptor->ModuleHandleRVA);
|
|
|
|
ok(pd->DelayloadDescriptor->ImportNameTableRVA > pd->DelayloadDescriptor->ImportAddressTableRVA,
|
|
|
|
"expected %x > %x\n", pd->DelayloadDescriptor->ImportNameTableRVA,
|
|
|
|
pd->DelayloadDescriptor->ImportAddressTableRVA);
|
|
|
|
ok(pd->DelayloadDescriptor->BoundImportAddressTableRVA == 0,
|
|
|
|
"expected 0, got %x\n", pd->DelayloadDescriptor->BoundImportAddressTableRVA);
|
|
|
|
ok(pd->DelayloadDescriptor->UnloadInformationTableRVA == 0,
|
|
|
|
"expected 0, got %x\n", pd->DelayloadDescriptor->UnloadInformationTableRVA);
|
|
|
|
ok(pd->DelayloadDescriptor->TimeDateStamp == 0,
|
|
|
|
"expected 0, got %x\n", pd->DelayloadDescriptor->TimeDateStamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(!!pd->ThunkAddress, "no ThunkAddress supplied\n");
|
|
|
|
if (pd->ThunkAddress)
|
2016-08-15 17:52:53 +02:00
|
|
|
ok(pd->ThunkAddress->u1.Ordinal, "no ThunkAddress value supplied\n");
|
2013-11-11 23:17:55 +01:00
|
|
|
|
|
|
|
ok(!!pd->TargetDllName, "no TargetDllName supplied\n");
|
|
|
|
if (pd->TargetDllName)
|
|
|
|
ok(!strcmp(pd->TargetDllName, "secur32.dll"),
|
|
|
|
"expected \"secur32.dll\", got \"%s\"\n", pd->TargetDllName);
|
|
|
|
|
|
|
|
ok(pd->TargetApiDescriptor.ImportDescribedByName == 0,
|
|
|
|
"expected 0, got %x\n", pd->TargetApiDescriptor.ImportDescribedByName);
|
|
|
|
ok(pd->TargetApiDescriptor.Description.Ordinal == 0 ||
|
|
|
|
pd->TargetApiDescriptor.Description.Ordinal == 999,
|
|
|
|
"expected 0, got %x\n", pd->TargetApiDescriptor.Description.Ordinal);
|
|
|
|
|
|
|
|
ok(!!pd->TargetModuleBase, "no TargetModuleBase supplied\n");
|
|
|
|
ok(pd->Unused == NULL, "expected NULL, got %p\n", pd->Unused);
|
|
|
|
ok(pd->LastError, "no LastError supplied\n");
|
|
|
|
}
|
2013-09-11 22:31:01 +02:00
|
|
|
cb_count++;
|
2013-11-11 23:17:55 +01:00
|
|
|
return (void*)0xdeadbeef;
|
2013-09-11 22:31:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_ResolveDelayLoadedAPI(void)
|
|
|
|
{
|
2013-10-31 18:43:54 +01:00
|
|
|
static const char test_dll[] = "secur32.dll";
|
|
|
|
static const char test_func[] = "SealMessage";
|
|
|
|
char temp_path[MAX_PATH];
|
|
|
|
char dll_name[MAX_PATH];
|
|
|
|
IMAGE_DELAYLOAD_DESCRIPTOR idd, *delaydir;
|
|
|
|
IMAGE_THUNK_DATA itd32;
|
|
|
|
HANDLE hfile;
|
2013-09-11 22:31:01 +02:00
|
|
|
HMODULE hlib;
|
2013-10-31 18:43:54 +01:00
|
|
|
DWORD dummy, file_size, i;
|
|
|
|
WORD hint = 0;
|
|
|
|
BOOL ret;
|
2015-01-27 23:02:58 +01:00
|
|
|
IMAGE_NT_HEADERS nt_header;
|
|
|
|
|
2013-10-31 18:43:54 +01:00
|
|
|
static const struct test_data
|
2013-09-11 22:31:01 +02:00
|
|
|
{
|
2013-10-31 18:43:54 +01:00
|
|
|
BOOL func;
|
|
|
|
UINT_PTR ordinal;
|
|
|
|
BOOL succeeds;
|
|
|
|
} td[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TRUE, 0, TRUE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FALSE, IMAGE_ORDINAL_FLAG | 2, TRUE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FALSE, IMAGE_ORDINAL_FLAG | 5, TRUE
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FALSE, IMAGE_ORDINAL_FLAG | 0, FALSE
|
|
|
|
},
|
2013-11-11 23:17:55 +01:00
|
|
|
{
|
|
|
|
FALSE, IMAGE_ORDINAL_FLAG | 999, FALSE
|
|
|
|
},
|
2013-09-11 22:31:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!pResolveDelayLoadedAPI)
|
|
|
|
{
|
2015-01-27 23:29:20 +01:00
|
|
|
win_skip("ResolveDelayLoadedAPI is not available\n");
|
2013-09-11 22:31:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0) /* crashes on native */
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!pResolveDelayLoadedAPI(NULL, NULL, NULL, NULL, NULL, 0),
|
|
|
|
"ResolveDelayLoadedAPI succeeded\n");
|
|
|
|
ok(GetLastError() == 0xdeadbeef, "GetLastError changed to %x\n", GetLastError());
|
|
|
|
|
|
|
|
cb_count = 0;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!pResolveDelayLoadedAPI(NULL, NULL, failuredllhook, NULL, NULL, 0),
|
|
|
|
"ResolveDelayLoadedAPI succeeded\n");
|
|
|
|
ok(GetLastError() == 0xdeadbeef, "GetLastError changed to %x\n", GetLastError());
|
|
|
|
ok(cb_count == 1, "Wrong callback count: %d\n", cb_count);
|
|
|
|
}
|
|
|
|
|
2013-10-31 18:43:54 +01:00
|
|
|
GetTempPathA(MAX_PATH, temp_path);
|
|
|
|
GetTempFileNameA(temp_path, "ldr", 0, dll_name);
|
|
|
|
trace("creating %s\n", dll_name);
|
|
|
|
hfile = CreateFileA(dll_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
|
|
|
if (hfile == INVALID_HANDLE_VALUE)
|
2013-09-11 22:31:01 +02:00
|
|
|
{
|
2013-10-31 18:43:54 +01:00
|
|
|
ok(0, "could not create %s\n", dll_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &dos_header, sizeof(dos_header), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
2015-01-27 23:02:58 +01:00
|
|
|
nt_header = nt_header_template;
|
2013-10-31 18:43:54 +01:00
|
|
|
nt_header.FileHeader.NumberOfSections = 2;
|
|
|
|
nt_header.FileHeader.SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
|
2013-09-11 22:31:01 +02:00
|
|
|
|
2013-10-31 18:43:54 +01:00
|
|
|
nt_header.OptionalHeader.SectionAlignment = 0x1000;
|
|
|
|
nt_header.OptionalHeader.FileAlignment = 0x1000;
|
|
|
|
nt_header.OptionalHeader.SizeOfImage = sizeof(dos_header) + sizeof(nt_header) + sizeof(IMAGE_SECTION_HEADER) + 0x2200;
|
|
|
|
nt_header.OptionalHeader.SizeOfHeaders = sizeof(dos_header) + sizeof(nt_header) + 2 * sizeof(IMAGE_SECTION_HEADER);
|
2014-02-17 16:15:06 +01:00
|
|
|
nt_header.OptionalHeader.NumberOfRvaAndSizes = IMAGE_NUMBEROF_DIRECTORY_ENTRIES;
|
2013-10-31 18:43:54 +01:00
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress = 0x1000;
|
|
|
|
nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size = 0x100;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &nt_header, sizeof(DWORD) + sizeof(IMAGE_FILE_HEADER), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &nt_header.OptionalHeader, sizeof(IMAGE_OPTIONAL_HEADER), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* sections */
|
|
|
|
section.PointerToRawData = nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress;
|
|
|
|
section.VirtualAddress = nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress;
|
2016-08-07 22:15:45 +02:00
|
|
|
section.Misc.VirtualSize = 2 * sizeof(idd);
|
|
|
|
section.SizeOfRawData = section.Misc.VirtualSize;
|
2013-10-31 18:43:54 +01:00
|
|
|
section.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, §ion, sizeof(section), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
section.PointerToRawData = 0x2000;
|
|
|
|
section.VirtualAddress = 0x2000;
|
2018-06-27 20:56:45 +02:00
|
|
|
i = ARRAY_SIZE(td);
|
2013-10-31 18:43:54 +01:00
|
|
|
section.Misc.VirtualSize = sizeof(test_dll) + sizeof(hint) + sizeof(test_func) + sizeof(HMODULE) +
|
|
|
|
2 * (i + 1) * sizeof(IMAGE_THUNK_DATA);
|
|
|
|
ok(section.Misc.VirtualSize <= 0x1000, "Too much tests, add a new section!\n");
|
2016-08-07 22:15:45 +02:00
|
|
|
section.SizeOfRawData = section.Misc.VirtualSize;
|
2013-10-31 18:43:54 +01:00
|
|
|
section.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, §ion, sizeof(section), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* fill up to delay data */
|
2016-08-07 22:15:56 +02:00
|
|
|
SetFilePointer( hfile, nt_header.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress, NULL, SEEK_SET );
|
2013-10-31 18:43:54 +01:00
|
|
|
|
|
|
|
/* delay data */
|
|
|
|
idd.Attributes.AllAttributes = 1;
|
|
|
|
idd.DllNameRVA = 0x2000;
|
|
|
|
idd.ModuleHandleRVA = idd.DllNameRVA + sizeof(test_dll) + sizeof(hint) + sizeof(test_func);
|
|
|
|
idd.ImportAddressTableRVA = idd.ModuleHandleRVA + sizeof(HMODULE);
|
|
|
|
idd.ImportNameTableRVA = idd.ImportAddressTableRVA + (i + 1) * sizeof(IMAGE_THUNK_DATA);
|
|
|
|
idd.BoundImportAddressTableRVA = 0;
|
|
|
|
idd.UnloadInformationTableRVA = 0;
|
|
|
|
idd.TimeDateStamp = 0;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &idd, sizeof(idd), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, filler, sizeof(idd), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* fill up to extended delay data */
|
2016-08-07 22:15:56 +02:00
|
|
|
SetFilePointer( hfile, idd.DllNameRVA, NULL, SEEK_SET );
|
2013-10-31 18:43:54 +01:00
|
|
|
|
|
|
|
/* extended delay data */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, test_dll, sizeof(test_dll), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &hint, sizeof(hint), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, test_func, sizeof(test_func), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
2016-08-15 17:52:53 +02:00
|
|
|
SetFilePointer( hfile, idd.ImportAddressTableRVA, NULL, SEEK_SET );
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(td); i++)
|
2016-08-15 17:52:53 +02:00
|
|
|
{
|
|
|
|
/* 0x1a00 is an empty space between delay data and extended delay data, real thunks are not necessary */
|
|
|
|
itd32.u1.Function = nt_header.OptionalHeader.ImageBase + 0x1a00 + i * 0x20;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &itd32, sizeof(itd32), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
itd32.u1.Function = 0;
|
2013-10-31 18:43:54 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2016-08-15 17:52:53 +02:00
|
|
|
ret = WriteFile(hfile, &itd32, sizeof(itd32), &dummy, NULL);
|
2013-10-31 18:43:54 +01:00
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(td); i++)
|
2013-10-31 18:43:54 +01:00
|
|
|
{
|
|
|
|
if (td[i].func)
|
|
|
|
itd32.u1.AddressOfData = idd.DllNameRVA + sizeof(test_dll);
|
|
|
|
else
|
|
|
|
itd32.u1.Ordinal = td[i].ordinal;
|
2013-09-11 22:31:01 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-31 18:43:54 +01:00
|
|
|
ret = WriteFile(hfile, &itd32, sizeof(itd32), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
|
|
|
}
|
2013-09-11 22:31:01 +02:00
|
|
|
|
2013-10-31 18:43:54 +01:00
|
|
|
itd32.u1.Ordinal = 0;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = WriteFile(hfile, &itd32, sizeof(itd32), &dummy, NULL);
|
|
|
|
ok(ret, "WriteFile error %d\n", GetLastError());
|
2013-09-11 22:31:01 +02:00
|
|
|
|
2013-10-31 18:43:54 +01:00
|
|
|
/* fill up to eof */
|
2016-08-07 22:15:56 +02:00
|
|
|
SetFilePointer( hfile, section.VirtualAddress + section.Misc.VirtualSize, NULL, SEEK_SET );
|
|
|
|
SetEndOfFile( hfile );
|
2013-10-31 18:43:54 +01:00
|
|
|
CloseHandle(hfile);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hlib = LoadLibraryA(dll_name);
|
|
|
|
ok(hlib != NULL, "LoadLibrary error %u\n", GetLastError());
|
|
|
|
if (!hlib)
|
|
|
|
{
|
|
|
|
skip("couldn't load %s.\n", dll_name);
|
|
|
|
DeleteFileA(dll_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:17:26 +02:00
|
|
|
delaydir = pRtlImageDirectoryEntryToData(hlib, TRUE, IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT, &file_size);
|
2013-10-31 18:43:54 +01:00
|
|
|
if (!delaydir)
|
|
|
|
{
|
|
|
|
skip("haven't found section for delay import directory.\n");
|
|
|
|
FreeLibrary(hlib);
|
|
|
|
DeleteFileA(dll_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
IMAGE_THUNK_DATA *itdn, *itda;
|
|
|
|
HMODULE htarget;
|
|
|
|
|
|
|
|
if (!delaydir->DllNameRVA ||
|
|
|
|
!delaydir->ImportAddressTableRVA ||
|
|
|
|
!delaydir->ImportNameTableRVA) break;
|
|
|
|
|
|
|
|
itdn = RVAToAddr(delaydir->ImportNameTableRVA, hlib);
|
|
|
|
itda = RVAToAddr(delaydir->ImportAddressTableRVA, hlib);
|
|
|
|
htarget = LoadLibraryA(RVAToAddr(delaydir->DllNameRVA, hlib));
|
|
|
|
|
2018-06-27 20:56:45 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(td); i++)
|
2013-09-11 22:31:01 +02:00
|
|
|
{
|
2013-10-31 18:43:54 +01:00
|
|
|
void *ret, *load;
|
2013-09-11 22:31:01 +02:00
|
|
|
|
2013-10-31 18:43:54 +01:00
|
|
|
if (IMAGE_SNAP_BY_ORDINAL(itdn[i].u1.Ordinal))
|
|
|
|
load = (void *)GetProcAddress(htarget, (LPSTR)IMAGE_ORDINAL(itdn[i].u1.Ordinal));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const IMAGE_IMPORT_BY_NAME* iibn = RVAToAddr(itdn[i].u1.AddressOfData, hlib);
|
|
|
|
load = (void *)GetProcAddress(htarget, (char*)iibn->Name);
|
|
|
|
}
|
2013-09-11 22:31:01 +02:00
|
|
|
|
2013-10-31 18:43:54 +01:00
|
|
|
cb_count = 0;
|
|
|
|
ret = pResolveDelayLoadedAPI(hlib, delaydir, failuredllhook, NULL, &itda[i], 0);
|
|
|
|
if (td[i].succeeds)
|
|
|
|
{
|
|
|
|
ok(ret != NULL, "Test %u: ResolveDelayLoadedAPI failed\n", i);
|
|
|
|
ok(ret == load, "Test %u: expected %p, got %p\n", i, load, ret);
|
|
|
|
ok(ret == (void*)itda[i].u1.AddressOfData, "Test %u: expected %p, got %p\n",
|
|
|
|
i, ret, (void*)itda[i].u1.AddressOfData);
|
|
|
|
ok(!cb_count, "Test %u: Wrong callback count: %d\n", i, cb_count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 23:17:55 +01:00
|
|
|
ok(ret == (void*)0xdeadbeef, "Test %u: ResolveDelayLoadedAPI succeeded with %p\n", i, ret);
|
2013-10-31 18:43:54 +01:00
|
|
|
ok(cb_count, "Test %u: Wrong callback count: %d\n", i, cb_count);
|
2013-09-11 22:31:01 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-31 18:43:54 +01:00
|
|
|
delaydir++;
|
2013-09-11 22:31:01 +02:00
|
|
|
}
|
2013-10-31 18:43:54 +01:00
|
|
|
|
|
|
|
FreeLibrary(hlib);
|
|
|
|
trace("deleting %s\n", dll_name);
|
|
|
|
DeleteFileA(dll_name);
|
2013-09-11 22:31:01 +02:00
|
|
|
}
|
|
|
|
|
2016-07-07 06:44:15 +02:00
|
|
|
static void test_InMemoryOrderModuleList(void)
|
|
|
|
{
|
2017-04-23 23:17:00 +02:00
|
|
|
PEB_LDR_DATA *ldr = NtCurrentTeb()->Peb->LdrData;
|
|
|
|
LIST_ENTRY *entry1, *mark1 = &ldr->InLoadOrderModuleList;
|
|
|
|
LIST_ENTRY *entry2, *mark2 = &ldr->InMemoryOrderModuleList;
|
2016-07-07 06:44:15 +02:00
|
|
|
LDR_MODULE *module1, *module2;
|
|
|
|
|
2017-04-23 23:17:00 +02:00
|
|
|
ok(ldr->Initialized == TRUE, "expected TRUE, got %u\n", ldr->Initialized);
|
|
|
|
|
2016-07-07 06:44:15 +02:00
|
|
|
for (entry1 = mark1->Flink, entry2 = mark2->Flink;
|
|
|
|
entry1 != mark1 && entry2 != mark2;
|
|
|
|
entry1 = entry1->Flink, entry2 = entry2->Flink)
|
|
|
|
{
|
|
|
|
module1 = CONTAINING_RECORD(entry1, LDR_MODULE, InLoadOrderModuleList);
|
|
|
|
module2 = CONTAINING_RECORD(entry2, LDR_MODULE, InMemoryOrderModuleList);
|
|
|
|
ok(module1 == module2, "expected module1 == module2, got %p and %p\n", module1, module2);
|
|
|
|
}
|
|
|
|
ok(entry1 == mark1, "expected entry1 == mark1, got %p and %p\n", entry1, mark1);
|
|
|
|
ok(entry2 == mark2, "expected entry2 == mark2, got %p and %p\n", entry2, mark2);
|
|
|
|
}
|
|
|
|
|
2008-09-12 22:54:22 +02:00
|
|
|
START_TEST(loader)
|
|
|
|
{
|
2013-04-12 11:00:58 +02:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
2016-08-03 00:55:43 +02:00
|
|
|
HANDLE ntdll, mapping, kernel32;
|
2013-11-21 15:54:51 +01:00
|
|
|
SYSTEM_INFO si;
|
2013-10-17 04:45:23 +02:00
|
|
|
|
|
|
|
ntdll = GetModuleHandleA("ntdll.dll");
|
2016-08-03 00:55:43 +02:00
|
|
|
kernel32 = GetModuleHandleA("kernel32.dll");
|
2013-11-21 16:14:11 +01:00
|
|
|
pNtCreateSection = (void *)GetProcAddress(ntdll, "NtCreateSection");
|
2016-07-26 07:43:02 +02:00
|
|
|
pNtQuerySection = (void *)GetProcAddress(ntdll, "NtQuerySection");
|
2013-10-17 04:45:23 +02:00
|
|
|
pNtMapViewOfSection = (void *)GetProcAddress(ntdll, "NtMapViewOfSection");
|
|
|
|
pNtUnmapViewOfSection = (void *)GetProcAddress(ntdll, "NtUnmapViewOfSection");
|
|
|
|
pNtTerminateProcess = (void *)GetProcAddress(ntdll, "NtTerminateProcess");
|
|
|
|
pNtQueryInformationProcess = (void *)GetProcAddress(ntdll, "NtQueryInformationProcess");
|
|
|
|
pNtSetInformationProcess = (void *)GetProcAddress(ntdll, "NtSetInformationProcess");
|
|
|
|
pLdrShutdownProcess = (void *)GetProcAddress(ntdll, "LdrShutdownProcess");
|
|
|
|
pRtlDllShutdownInProgress = (void *)GetProcAddress(ntdll, "RtlDllShutdownInProgress");
|
|
|
|
pNtAllocateVirtualMemory = (void *)GetProcAddress(ntdll, "NtAllocateVirtualMemory");
|
|
|
|
pNtFreeVirtualMemory = (void *)GetProcAddress(ntdll, "NtFreeVirtualMemory");
|
|
|
|
pLdrLockLoaderLock = (void *)GetProcAddress(ntdll, "LdrLockLoaderLock");
|
|
|
|
pLdrUnlockLoaderLock = (void *)GetProcAddress(ntdll, "LdrUnlockLoaderLock");
|
|
|
|
pRtlAcquirePebLock = (void *)GetProcAddress(ntdll, "RtlAcquirePebLock");
|
|
|
|
pRtlReleasePebLock = (void *)GetProcAddress(ntdll, "RtlReleasePebLock");
|
2015-07-13 08:17:26 +02:00
|
|
|
pRtlImageDirectoryEntryToData = (void *)GetProcAddress(ntdll, "RtlImageDirectoryEntryToData");
|
2016-08-03 00:55:43 +02:00
|
|
|
pFlsAlloc = (void *)GetProcAddress(kernel32, "FlsAlloc");
|
|
|
|
pFlsSetValue = (void *)GetProcAddress(kernel32, "FlsSetValue");
|
|
|
|
pFlsGetValue = (void *)GetProcAddress(kernel32, "FlsGetValue");
|
|
|
|
pFlsFree = (void *)GetProcAddress(kernel32, "FlsFree");
|
2017-12-19 14:33:25 +01:00
|
|
|
pIsWow64Process = (void *)GetProcAddress(kernel32, "IsWow64Process");
|
2016-08-03 00:55:43 +02:00
|
|
|
pResolveDelayLoadedAPI = (void *)GetProcAddress(kernel32, "ResolveDelayLoadedAPI");
|
2013-10-17 04:45:23 +02:00
|
|
|
|
2018-01-30 10:47:32 +01:00
|
|
|
if (pIsWow64Process) pIsWow64Process( GetCurrentProcess(), &is_wow64 );
|
2013-11-21 15:54:51 +01:00
|
|
|
GetSystemInfo( &si );
|
|
|
|
page_size = si.dwPageSize;
|
2013-11-21 17:30:18 +01:00
|
|
|
dos_header.e_magic = IMAGE_DOS_SIGNATURE;
|
|
|
|
dos_header.e_lfanew = sizeof(dos_header);
|
|
|
|
|
2013-10-17 04:45:23 +02:00
|
|
|
mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4096, "winetest_loader");
|
2013-04-12 11:00:58 +02:00
|
|
|
ok(mapping != 0, "CreateFileMapping failed\n");
|
|
|
|
child_failures = MapViewOfFile(mapping, FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, 4096);
|
|
|
|
if (*child_failures == -1)
|
|
|
|
{
|
|
|
|
*child_failures = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*child_failures = -1;
|
|
|
|
|
|
|
|
argc = winetest_get_mainargs(&argv);
|
|
|
|
if (argc > 4)
|
|
|
|
{
|
|
|
|
test_dll_phase = atoi(argv[4]);
|
|
|
|
child_process(argv[2], atol(argv[3]));
|
|
|
|
return;
|
|
|
|
}
|
2012-02-20 09:01:25 +01:00
|
|
|
|
2008-09-12 22:54:22 +02:00
|
|
|
test_Loader();
|
2018-02-27 18:20:41 +01:00
|
|
|
test_filenames();
|
2013-10-31 18:43:54 +01:00
|
|
|
test_ResolveDelayLoadedAPI();
|
2008-09-12 22:54:22 +02:00
|
|
|
test_ImportDescriptors();
|
2011-07-19 18:41:12 +02:00
|
|
|
test_section_access();
|
2014-02-17 16:15:06 +01:00
|
|
|
test_import_resolution();
|
2013-04-12 11:00:58 +02:00
|
|
|
test_ExitProcess();
|
2016-07-07 06:44:15 +02:00
|
|
|
test_InMemoryOrderModuleList();
|
2008-09-12 22:54:22 +02:00
|
|
|
}
|