2002-04-02 21:37:15 +02:00
|
|
|
/*
|
2010-01-23 16:46:09 +01:00
|
|
|
* Unit test suite for thread functions.
|
2002-04-02 21:37:15 +02:00
|
|
|
*
|
|
|
|
* Copyright 2002 Geoffrey Hausheer
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-04-02 21:37:15 +02:00
|
|
|
*/
|
|
|
|
|
2002-05-23 04:40:07 +02:00
|
|
|
/* Define _WIN32_WINNT to get SetThreadIdealProcessor on Windows */
|
2014-01-29 20:13:28 +01:00
|
|
|
#define _WIN32_WINNT 0x0600
|
2002-05-23 04:40:07 +02:00
|
|
|
|
2008-06-21 01:10:31 +02:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2007-01-03 14:22:02 +01:00
|
|
|
#include <stdio.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2013-10-21 10:02:45 +02:00
|
|
|
/* the tests intentionally pass invalid pointers and need an exception handler */
|
|
|
|
#define WINE_NO_INLINE_STRING
|
|
|
|
|
2015-08-20 08:55:21 +02:00
|
|
|
#include <ntstatus.h>
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <windef.h>
|
2002-04-02 21:37:15 +02:00
|
|
|
#include <winbase.h>
|
|
|
|
#include <winnt.h>
|
|
|
|
#include <winerror.h>
|
2013-09-05 09:27:45 +02:00
|
|
|
#include <winnls.h>
|
2015-08-20 08:55:21 +02:00
|
|
|
#include <winternl.h>
|
2013-10-21 10:02:45 +02:00
|
|
|
#include "wine/test.h"
|
2002-04-02 21:37:15 +02:00
|
|
|
|
2014-02-07 15:08:53 +01:00
|
|
|
/* THREAD_ALL_ACCESS in Vista+ PSDKs is incompatible with older Windows versions */
|
|
|
|
#define THREAD_ALL_ACCESS_NT4 (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3ff)
|
|
|
|
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Specify the number of simultaneous threads to test */
|
|
|
|
#define NUM_THREADS 4
|
|
|
|
/* Specify whether to test the extended priorities for Win2k/XP */
|
|
|
|
#define USE_EXTENDED_PRIORITIES 0
|
|
|
|
/* Specify whether to test the stack allocation in CreateThread */
|
|
|
|
#define CHECK_STACK 0
|
|
|
|
|
|
|
|
/* Set CHECK_STACK to 1 if you want to try to test the stack-limit from
|
|
|
|
CreateThread. So far I have been unable to make this work, and
|
|
|
|
I am in doubt as to how portable it is. Also, according to MSDN,
|
|
|
|
you shouldn't mix C-run-time-libraries (i.e. alloca) with CreateThread.
|
|
|
|
Anyhow, the check is currently commented out
|
|
|
|
*/
|
|
|
|
#if CHECK_STACK
|
2005-03-02 13:23:20 +01:00
|
|
|
# ifdef __try
|
|
|
|
# define __TRY __try
|
|
|
|
# define __EXCEPT __except
|
|
|
|
# define __ENDTRY
|
|
|
|
# else
|
|
|
|
# include "wine/exception.h"
|
|
|
|
# endif
|
2002-04-02 21:37:15 +02:00
|
|
|
#endif
|
2002-11-30 20:03:19 +01:00
|
|
|
|
2013-09-05 09:27:45 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
#define ARCH "x86"
|
|
|
|
#elif defined __x86_64__
|
|
|
|
#define ARCH "amd64"
|
2015-08-09 14:03:54 +02:00
|
|
|
#elif defined __arm__
|
|
|
|
#define ARCH "arm"
|
|
|
|
#elif defined __aarch64__
|
|
|
|
#define ARCH "arm64"
|
2013-09-05 09:27:45 +02:00
|
|
|
#else
|
|
|
|
#define ARCH "none"
|
|
|
|
#endif
|
|
|
|
|
2009-12-23 12:02:08 +01:00
|
|
|
static BOOL (WINAPI *pGetThreadPriorityBoost)(HANDLE,PBOOL);
|
|
|
|
static HANDLE (WINAPI *pOpenThread)(DWORD,BOOL,DWORD);
|
|
|
|
static BOOL (WINAPI *pQueueUserWorkItem)(LPTHREAD_START_ROUTINE,PVOID,ULONG);
|
|
|
|
static DWORD (WINAPI *pSetThreadIdealProcessor)(HANDLE,DWORD);
|
|
|
|
static BOOL (WINAPI *pSetThreadPriorityBoost)(HANDLE,BOOL);
|
|
|
|
static BOOL (WINAPI *pRegisterWaitForSingleObject)(PHANDLE,HANDLE,WAITORTIMERCALLBACK,PVOID,ULONG,ULONG);
|
|
|
|
static BOOL (WINAPI *pUnregisterWait)(HANDLE);
|
2009-12-23 12:13:32 +01:00
|
|
|
static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
|
2010-02-03 14:33:38 +01:00
|
|
|
static BOOL (WINAPI *pSetThreadErrorMode)(DWORD,PDWORD);
|
|
|
|
static DWORD (WINAPI *pGetThreadErrorMode)(void);
|
|
|
|
static DWORD (WINAPI *pRtlGetThreadErrorMode)(void);
|
2013-09-05 09:27:45 +02:00
|
|
|
static BOOL (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);
|
|
|
|
static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);
|
|
|
|
static BOOL (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);
|
|
|
|
static BOOL (WINAPI *pGetCurrentActCtx)(HANDLE *);
|
|
|
|
static void (WINAPI *pReleaseActCtx)(HANDLE);
|
2014-01-29 20:13:28 +01:00
|
|
|
static PTP_POOL (WINAPI *pCreateThreadpool)(PVOID);
|
2015-07-03 02:00:59 +02:00
|
|
|
static void (WINAPI *pCloseThreadpool)(PTP_POOL);
|
2014-01-29 20:13:28 +01:00
|
|
|
static PTP_WORK (WINAPI *pCreateThreadpoolWork)(PTP_WORK_CALLBACK,PVOID,PTP_CALLBACK_ENVIRON);
|
|
|
|
static void (WINAPI *pSubmitThreadpoolWork)(PTP_WORK);
|
|
|
|
static void (WINAPI *pWaitForThreadpoolWorkCallbacks)(PTP_WORK,BOOL);
|
|
|
|
static void (WINAPI *pCloseThreadpoolWork)(PTP_WORK);
|
2015-08-20 08:55:21 +02:00
|
|
|
static NTSTATUS (WINAPI *pNtQueryInformationThread)(HANDLE,THREADINFOCLASS,PVOID,ULONG,PULONG);
|
2015-09-23 22:51:23 +02:00
|
|
|
static BOOL (WINAPI *pGetThreadGroupAffinity)(HANDLE,GROUP_AFFINITY*);
|
|
|
|
static BOOL (WINAPI *pSetThreadGroupAffinity)(HANDLE,const GROUP_AFFINITY*,GROUP_AFFINITY*);
|
|
|
|
static NTSTATUS (WINAPI *pNtSetInformationThread)(HANDLE,THREADINFOCLASS,LPCVOID,ULONG);
|
2008-01-01 23:37:34 +01:00
|
|
|
|
2007-01-03 14:22:02 +01:00
|
|
|
static HANDLE create_target_process(const char *arg)
|
|
|
|
{
|
|
|
|
char **argv;
|
|
|
|
char cmdline[MAX_PATH];
|
|
|
|
PROCESS_INFORMATION pi;
|
2011-01-11 20:30:00 +01:00
|
|
|
BOOL ret;
|
2013-10-21 10:02:45 +02:00
|
|
|
STARTUPINFOA si = { 0 };
|
2007-01-03 14:22:02 +01:00
|
|
|
si.cb = sizeof(si);
|
|
|
|
|
|
|
|
winetest_get_mainargs( &argv );
|
|
|
|
sprintf(cmdline, "%s %s %s", argv[0], argv[1], arg);
|
2013-10-21 10:02:45 +02:00
|
|
|
ret = CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
2011-01-11 20:30:00 +01:00
|
|
|
ok(ret, "error: %u\n", GetLastError());
|
|
|
|
ret = CloseHandle(pi.hThread);
|
|
|
|
ok(ret, "error %u\n", GetLastError());
|
2007-01-03 14:22:02 +01:00
|
|
|
return pi.hProcess;
|
|
|
|
}
|
|
|
|
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Functions not tested yet:
|
|
|
|
AttachThreadInput
|
|
|
|
SetThreadContext
|
|
|
|
SwitchToThread
|
|
|
|
|
|
|
|
In addition there are no checks that the inheritance works properly in
|
|
|
|
CreateThread
|
|
|
|
*/
|
|
|
|
|
2008-06-21 01:10:31 +02:00
|
|
|
/* Functions to ensure that from a group of threads, only one executes
|
|
|
|
certain chunks of code at a time, and we know which one is executing
|
|
|
|
it. It basically makes multithreaded execution linear, which defeats
|
|
|
|
the purpose of multiple threads, but makes testing easy. */
|
2008-09-19 12:21:45 +02:00
|
|
|
static HANDLE start_event, stop_event;
|
2008-11-13 11:49:36 +01:00
|
|
|
static LONG num_synced;
|
2008-06-21 01:10:31 +02:00
|
|
|
|
2008-11-13 11:49:36 +01:00
|
|
|
static void init_thread_sync_helpers(void)
|
2008-06-21 01:10:31 +02:00
|
|
|
{
|
2013-10-21 10:02:45 +02:00
|
|
|
start_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2008-09-19 12:21:45 +02:00
|
|
|
ok(start_event != NULL, "CreateEvent failed\n");
|
2013-10-21 10:02:45 +02:00
|
|
|
stop_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2008-09-19 12:21:45 +02:00
|
|
|
ok(stop_event != NULL, "CreateEvent failed\n");
|
2008-11-13 11:49:36 +01:00
|
|
|
num_synced = -1;
|
2008-06-21 01:10:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL sync_threads_and_run_one(DWORD sync_id, DWORD my_id)
|
|
|
|
{
|
|
|
|
LONG num = InterlockedIncrement(&num_synced);
|
2008-11-13 11:49:36 +01:00
|
|
|
assert(-1 <= num && num <= 1);
|
|
|
|
if (num == 1)
|
2008-09-19 12:21:45 +02:00
|
|
|
{
|
|
|
|
ResetEvent( stop_event );
|
|
|
|
SetEvent( start_event );
|
|
|
|
}
|
2008-06-21 01:10:31 +02:00
|
|
|
else
|
|
|
|
{
|
2008-09-19 12:21:45 +02:00
|
|
|
DWORD ret = WaitForSingleObject(start_event, 10000);
|
2008-11-13 11:49:36 +01:00
|
|
|
ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed %x\n",ret);
|
2008-06-21 01:10:31 +02:00
|
|
|
}
|
|
|
|
return sync_id == my_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void resync_after_run(void)
|
|
|
|
{
|
|
|
|
LONG num = InterlockedDecrement(&num_synced);
|
2008-11-13 11:49:36 +01:00
|
|
|
assert(-1 <= num && num <= 1);
|
|
|
|
if (num == -1)
|
2008-09-19 12:21:45 +02:00
|
|
|
{
|
|
|
|
ResetEvent( start_event );
|
|
|
|
SetEvent( stop_event );
|
|
|
|
}
|
2008-06-21 01:10:31 +02:00
|
|
|
else
|
|
|
|
{
|
2008-09-19 12:21:45 +02:00
|
|
|
DWORD ret = WaitForSingleObject(stop_event, 10000);
|
2008-06-21 01:10:31 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup_thread_sync_helpers(void)
|
|
|
|
{
|
2008-09-19 12:21:45 +02:00
|
|
|
CloseHandle(start_event);
|
|
|
|
CloseHandle(stop_event);
|
2008-06-21 01:10:31 +02:00
|
|
|
}
|
|
|
|
|
2010-10-01 13:36:35 +02:00
|
|
|
static DWORD tlsIndex;
|
2002-04-02 21:37:15 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int threadnum;
|
|
|
|
HANDLE *event;
|
|
|
|
DWORD *threadmem;
|
|
|
|
} t1Struct;
|
|
|
|
|
2005-07-25 13:07:54 +02:00
|
|
|
/* WinME supports OpenThread but doesn't know about access restrictions so
|
2005-08-12 20:22:06 +02:00
|
|
|
we require them to be either completely ignored or always obeyed.
|
2005-07-25 13:07:54 +02:00
|
|
|
*/
|
2010-10-01 13:36:35 +02:00
|
|
|
static INT obeying_ars = 0; /* -1 == no, 0 == dunno yet, 1 == yes */
|
2005-07-25 13:07:54 +02:00
|
|
|
#define obey_ar(x) \
|
|
|
|
(obeying_ars == 0 \
|
|
|
|
? ((x) \
|
|
|
|
? (obeying_ars = +1) \
|
|
|
|
: ((obeying_ars = -1), \
|
|
|
|
trace("not restricted, assuming consistent behaviour\n"))) \
|
|
|
|
: (obeying_ars < 0) \
|
|
|
|
? ok(!(x), "access restrictions obeyed\n") \
|
|
|
|
: ok( (x), "access restrictions not obeyed\n"))
|
|
|
|
|
2005-08-12 20:22:06 +02:00
|
|
|
/* Basic test that simultaneous threads can access shared memory,
|
2002-04-02 21:37:15 +02:00
|
|
|
that the thread local storage routines work correctly, and that
|
|
|
|
threads actually run concurrently
|
|
|
|
*/
|
2005-06-14 13:40:04 +02:00
|
|
|
static DWORD WINAPI threadFunc1(LPVOID p)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
2009-03-11 09:39:16 +01:00
|
|
|
t1Struct *tstruct = p;
|
2002-04-02 21:37:15 +02:00
|
|
|
int i;
|
|
|
|
/* write our thread # into shared memory */
|
|
|
|
tstruct->threadmem[tstruct->threadnum]=GetCurrentThreadId();
|
2009-01-03 20:17:31 +01:00
|
|
|
ok(TlsSetValue(tlsIndex,(LPVOID)(INT_PTR)(tstruct->threadnum+1))!=0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"TlsSetValue failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* The threads synchronize before terminating. This is done by
|
|
|
|
Signaling an event, and waiting for all events to occur
|
|
|
|
*/
|
|
|
|
SetEvent(tstruct->event[tstruct->threadnum]);
|
|
|
|
WaitForMultipleObjects(NUM_THREADS,tstruct->event,TRUE,INFINITE);
|
|
|
|
/* Double check that all threads really did run by validating that
|
|
|
|
they have all written to the shared memory. There should be no race
|
|
|
|
here, since all threads were synchronized after the write.*/
|
2015-10-20 21:55:41 +02:00
|
|
|
for (i = 0; i < NUM_THREADS; i++)
|
|
|
|
ok(tstruct->threadmem[i] != 0, "expected threadmem[%d] != 0\n", i);
|
2005-12-05 20:43:33 +01:00
|
|
|
|
|
|
|
/* lstrlenA contains an exception handler so this makes sure exceptions work in threads */
|
|
|
|
ok( lstrlenA( (char *)0xdeadbeef ) == 0, "lstrlenA: unexpected success\n" );
|
|
|
|
|
2006-11-07 00:37:42 +01:00
|
|
|
/* Check that no one changed our tls memory */
|
2009-01-03 20:17:31 +01:00
|
|
|
ok((INT_PTR)TlsGetValue(tlsIndex)-1==tstruct->threadnum,
|
2004-02-06 06:24:34 +01:00
|
|
|
"TlsGetValue failed\n");
|
2004-11-03 23:18:44 +01:00
|
|
|
return NUM_THREADS+tstruct->threadnum;
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
2005-06-14 13:40:04 +02:00
|
|
|
static DWORD WINAPI threadFunc2(LPVOID p)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
2004-11-03 23:18:44 +01:00
|
|
|
return 99;
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
2005-06-14 13:40:04 +02:00
|
|
|
static DWORD WINAPI threadFunc3(LPVOID p)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
|
|
|
HANDLE thread;
|
|
|
|
thread=GetCurrentThread();
|
|
|
|
SuspendThread(thread);
|
2004-11-03 23:18:44 +01:00
|
|
|
return 99;
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
2005-06-14 13:40:04 +02:00
|
|
|
static DWORD WINAPI threadFunc4(LPVOID p)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
2009-03-11 09:39:16 +01:00
|
|
|
HANDLE event = p;
|
2002-11-30 20:03:19 +01:00
|
|
|
if(event != NULL) {
|
2002-04-03 04:33:13 +02:00
|
|
|
SetEvent(event);
|
|
|
|
}
|
2002-04-02 21:37:15 +02:00
|
|
|
Sleep(99000);
|
2004-11-03 23:18:44 +01:00
|
|
|
return 0;
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if CHECK_STACK
|
2005-06-14 13:40:04 +02:00
|
|
|
static DWORD WINAPI threadFunc5(LPVOID p)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
2009-03-11 09:39:16 +01:00
|
|
|
DWORD *exitCode = p;
|
2002-04-02 21:37:15 +02:00
|
|
|
SYSTEM_INFO sysInfo;
|
|
|
|
sysInfo.dwPageSize=0;
|
|
|
|
GetSystemInfo(&sysInfo);
|
|
|
|
*exitCode=0;
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
alloca(2*sysInfo.dwPageSize);
|
|
|
|
}
|
|
|
|
__EXCEPT(1) {
|
|
|
|
*exitCode=1;
|
|
|
|
}
|
|
|
|
__ENDTRY
|
2004-11-03 23:18:44 +01:00
|
|
|
return 0;
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-01-03 14:22:02 +01:00
|
|
|
static DWORD WINAPI threadFunc_SetEvent(LPVOID p)
|
|
|
|
{
|
2009-03-11 09:39:16 +01:00
|
|
|
SetEvent(p);
|
2007-01-03 14:22:02 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI threadFunc_CloseHandle(LPVOID p)
|
|
|
|
{
|
2009-03-11 09:39:16 +01:00
|
|
|
CloseHandle(p);
|
2007-01-03 14:22:02 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-05 09:27:45 +02:00
|
|
|
struct thread_actctx_param
|
|
|
|
{
|
|
|
|
HANDLE thread_context;
|
|
|
|
HANDLE handle;
|
|
|
|
};
|
|
|
|
|
|
|
|
static DWORD WINAPI thread_actctx_func(void *p)
|
|
|
|
{
|
|
|
|
struct thread_actctx_param *param = (struct thread_actctx_param*)p;
|
|
|
|
HANDLE cur;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
cur = (void*)0xdeadbeef;
|
|
|
|
ret = pGetCurrentActCtx(&cur);
|
|
|
|
ok(ret, "thread GetCurrentActCtx failed, %u\n", GetLastError());
|
|
|
|
ok(cur == param->handle, "got %p, expected %p\n", cur, param->handle);
|
|
|
|
param->thread_context = cur;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-19 16:45:54 +01:00
|
|
|
static void create_function_addr_events(HANDLE events[2])
|
|
|
|
{
|
|
|
|
char buffer[256];
|
|
|
|
|
|
|
|
sprintf(buffer, "threadFunc_SetEvent %p", threadFunc_SetEvent);
|
2013-10-21 10:02:45 +02:00
|
|
|
events[0] = CreateEventA(NULL, FALSE, FALSE, buffer);
|
2007-02-19 16:45:54 +01:00
|
|
|
|
|
|
|
sprintf(buffer, "threadFunc_CloseHandle %p", threadFunc_CloseHandle);
|
2013-10-21 10:02:45 +02:00
|
|
|
events[1] = CreateEventA(NULL, FALSE, FALSE, buffer);
|
2007-02-19 16:45:54 +01:00
|
|
|
}
|
|
|
|
|
2007-01-03 14:22:02 +01:00
|
|
|
/* check CreateRemoteThread */
|
|
|
|
static VOID test_CreateRemoteThread(void)
|
|
|
|
{
|
|
|
|
HANDLE hProcess, hThread, hEvent, hRemoteEvent;
|
|
|
|
DWORD tid, ret, exitcode;
|
2007-02-19 16:45:54 +01:00
|
|
|
HANDLE hAddrEvents[2];
|
2007-01-03 14:22:02 +01:00
|
|
|
|
|
|
|
hProcess = create_target_process("sleep");
|
|
|
|
ok(hProcess != NULL, "Can't start process\n");
|
|
|
|
|
2007-02-19 16:45:54 +01:00
|
|
|
/* ensure threadFunc_SetEvent & threadFunc_CloseHandle are the same
|
|
|
|
* address as in the child process */
|
|
|
|
create_function_addr_events(hAddrEvents);
|
|
|
|
ret = WaitForMultipleObjects(2, hAddrEvents, TRUE, 5000);
|
|
|
|
if (ret == WAIT_TIMEOUT)
|
|
|
|
{
|
|
|
|
skip("child process wasn't mapped at same address, so can't do CreateRemoteThread tests.\n");
|
|
|
|
return;
|
|
|
|
}
|
2011-07-23 22:02:19 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0 || broken(ret == WAIT_OBJECT_0+1 /* nt4,w2k */), "WaitForAllObjects 2 events %d\n", ret);
|
2007-02-19 16:45:54 +01:00
|
|
|
|
2013-10-21 10:02:45 +02:00
|
|
|
hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2007-01-03 14:22:02 +01:00
|
|
|
ok(hEvent != NULL, "Can't create event, err=%u\n", GetLastError());
|
|
|
|
ret = DuplicateHandle(GetCurrentProcess(), hEvent, hProcess, &hRemoteEvent,
|
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS);
|
|
|
|
ok(ret != 0, "DuplicateHandle failed, err=%u\n", GetLastError());
|
|
|
|
|
|
|
|
/* create suspended remote thread with entry point SetEvent() */
|
2007-04-25 13:04:03 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2007-01-03 14:22:02 +01:00
|
|
|
hThread = CreateRemoteThread(hProcess, NULL, 0, threadFunc_SetEvent,
|
|
|
|
hRemoteEvent, CREATE_SUSPENDED, &tid);
|
2007-04-25 13:04:03 +02:00
|
|
|
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("CreateRemoteThread is not implemented\n");
|
2007-04-25 13:04:03 +02:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(hThread != NULL, "CreateRemoteThread failed, err=%u\n", GetLastError());
|
2007-01-03 14:22:02 +01:00
|
|
|
ok(tid != 0, "null tid\n");
|
|
|
|
ret = SuspendThread(hThread);
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(ret == 1, "ret=%u, err=%u\n", ret, GetLastError());
|
2007-01-03 14:22:02 +01:00
|
|
|
ret = ResumeThread(hThread);
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(ret == 2, "ret=%u, err=%u\n", ret, GetLastError());
|
2007-01-03 14:22:02 +01:00
|
|
|
|
|
|
|
/* thread still suspended, so wait times out */
|
2010-10-25 03:56:48 +02:00
|
|
|
ret = WaitForSingleObject(hEvent, 1000);
|
2007-01-03 14:22:02 +01:00
|
|
|
ok(ret == WAIT_TIMEOUT, "wait did not time out, ret=%u\n", ret);
|
|
|
|
|
|
|
|
ret = ResumeThread(hThread);
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(ret == 1, "ret=%u, err=%u\n", ret, GetLastError());
|
2007-01-03 14:22:02 +01:00
|
|
|
|
|
|
|
/* wait that doesn't time out */
|
2010-10-25 03:56:48 +02:00
|
|
|
ret = WaitForSingleObject(hEvent, 1000);
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(ret == WAIT_OBJECT_0, "object not signaled, ret=%u\n", ret);
|
2007-01-03 14:22:02 +01:00
|
|
|
|
|
|
|
/* wait for thread end */
|
2010-10-25 03:56:48 +02:00
|
|
|
ret = WaitForSingleObject(hThread, 1000);
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(ret == WAIT_OBJECT_0, "waiting for thread failed, ret=%u\n", ret);
|
2007-01-03 14:22:02 +01:00
|
|
|
CloseHandle(hThread);
|
|
|
|
|
|
|
|
/* create and wait for remote thread with entry point CloseHandle() */
|
|
|
|
hThread = CreateRemoteThread(hProcess, NULL, 0,
|
|
|
|
threadFunc_CloseHandle,
|
|
|
|
hRemoteEvent, 0, &tid);
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(hThread != NULL, "CreateRemoteThread failed, err=%u\n", GetLastError());
|
2010-10-25 03:56:48 +02:00
|
|
|
ret = WaitForSingleObject(hThread, 1000);
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(ret == WAIT_OBJECT_0, "waiting for thread failed, ret=%u\n", ret);
|
2007-01-03 14:22:02 +01:00
|
|
|
CloseHandle(hThread);
|
|
|
|
|
|
|
|
/* create remote thread with entry point SetEvent() */
|
|
|
|
hThread = CreateRemoteThread(hProcess, NULL, 0,
|
|
|
|
threadFunc_SetEvent,
|
|
|
|
hRemoteEvent, 0, &tid);
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(hThread != NULL, "CreateRemoteThread failed, err=%u\n", GetLastError());
|
2007-01-03 14:22:02 +01:00
|
|
|
|
|
|
|
/* closed handle, so wait times out */
|
2010-10-25 03:56:48 +02:00
|
|
|
ret = WaitForSingleObject(hEvent, 1000);
|
2007-01-03 14:22:02 +01:00
|
|
|
ok(ret == WAIT_TIMEOUT, "wait did not time out, ret=%u\n", ret);
|
|
|
|
|
|
|
|
/* check that remote SetEvent() failed */
|
|
|
|
ret = GetExitCodeThread(hThread, &exitcode);
|
2007-01-18 15:02:55 +01:00
|
|
|
ok(ret != 0, "GetExitCodeThread failed, err=%u\n", GetLastError());
|
|
|
|
if (ret) ok(exitcode == 0, "SetEvent succeeded, expected to fail\n");
|
2007-01-03 14:22:02 +01:00
|
|
|
CloseHandle(hThread);
|
|
|
|
|
2007-04-25 13:04:03 +02:00
|
|
|
cleanup:
|
2007-01-03 14:22:02 +01:00
|
|
|
TerminateProcess(hProcess, 0);
|
|
|
|
CloseHandle(hEvent);
|
|
|
|
CloseHandle(hProcess);
|
|
|
|
}
|
|
|
|
|
2008-03-17 21:51:39 +01:00
|
|
|
/* Check basic functionality of CreateThread and Tls* functions */
|
2005-06-14 13:40:04 +02:00
|
|
|
static VOID test_CreateThread_basic(void)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
|
|
|
HANDLE thread[NUM_THREADS],event[NUM_THREADS];
|
|
|
|
DWORD threadid[NUM_THREADS],curthreadId;
|
|
|
|
DWORD threadmem[NUM_THREADS];
|
|
|
|
DWORD exitCode;
|
|
|
|
t1Struct tstruct[NUM_THREADS];
|
|
|
|
int error;
|
2002-11-30 20:03:19 +01:00
|
|
|
DWORD i,j;
|
2005-10-28 12:41:57 +02:00
|
|
|
DWORD GLE, ret;
|
2008-09-08 08:19:45 +02:00
|
|
|
DWORD tid;
|
2011-01-11 20:30:00 +01:00
|
|
|
BOOL bRet;
|
2005-10-28 12:41:57 +02:00
|
|
|
|
2005-12-05 20:43:33 +01:00
|
|
|
/* lstrlenA contains an exception handler so this makes sure exceptions work in the main thread */
|
|
|
|
ok( lstrlenA( (char *)0xdeadbeef ) == 0, "lstrlenA: unexpected success\n" );
|
|
|
|
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Retrieve current Thread ID for later comparisons */
|
|
|
|
curthreadId=GetCurrentThreadId();
|
|
|
|
/* Allocate some local storage */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok((tlsIndex=TlsAlloc())!=TLS_OUT_OF_INDEXES,"TlsAlloc failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Create events for thread synchronization */
|
|
|
|
for(i=0;i<NUM_THREADS;i++) {
|
|
|
|
threadmem[i]=0;
|
2008-03-17 21:51:39 +01:00
|
|
|
/* Note that it doesn't matter what type of event we choose here. This
|
2002-04-02 21:37:15 +02:00
|
|
|
test isn't trying to thoroughly test events
|
|
|
|
*/
|
|
|
|
event[i]=CreateEventA(NULL,TRUE,FALSE,NULL);
|
|
|
|
tstruct[i].threadnum=i;
|
|
|
|
tstruct[i].threadmem=threadmem;
|
|
|
|
tstruct[i].event=event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test that passing arguments to threads works okay */
|
|
|
|
for(i=0;i<NUM_THREADS;i++) {
|
2004-11-03 23:18:44 +01:00
|
|
|
thread[i] = CreateThread(NULL,0,threadFunc1,
|
2002-04-02 21:37:15 +02:00
|
|
|
&tstruct[i],0,&threadid[i]);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(thread[i]!=NULL,"Create Thread failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
/* Test that the threads actually complete */
|
|
|
|
for(i=0;i<NUM_THREADS;i++) {
|
|
|
|
error=WaitForSingleObject(thread[i],5000);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(error==WAIT_OBJECT_0, "Thread did not complete within timelimit\n");
|
2002-06-22 02:08:10 +02:00
|
|
|
if(error!=WAIT_OBJECT_0) {
|
|
|
|
TerminateThread(thread[i],i+NUM_THREADS);
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(GetExitCodeThread(thread[i],&exitCode),"Could not retrieve ext code\n");
|
|
|
|
ok(exitCode==i+NUM_THREADS,"Thread returned an incorrect exit code\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
/* Test that each thread executed in its parent's address space
|
|
|
|
(it was able to change threadmem and pass that change back to its parent)
|
2006-11-07 00:37:42 +01:00
|
|
|
and that each thread id was independent). Note that we prove that the
|
2002-04-02 21:37:15 +02:00
|
|
|
threads actually execute concurrently by having them block on each other
|
|
|
|
in threadFunc1
|
|
|
|
*/
|
|
|
|
for(i=0;i<NUM_THREADS;i++) {
|
|
|
|
error=0;
|
|
|
|
for(j=i+1;j<NUM_THREADS;j++) {
|
|
|
|
if (threadmem[i]==threadmem[j]) {
|
|
|
|
error=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(!error && threadmem[i]==threadid[i] && threadmem[i]!=curthreadId,
|
2004-02-06 06:24:34 +01:00
|
|
|
"Thread did not execute successfully\n");
|
|
|
|
ok(CloseHandle(thread[i])!=0,"CloseHandle failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
2010-03-02 22:29:48 +01:00
|
|
|
|
|
|
|
SetLastError(0xCAFEF00D);
|
2011-01-11 20:30:00 +01:00
|
|
|
bRet = TlsFree(tlsIndex);
|
|
|
|
ok(bRet, "TlsFree failed: %08x\n", GetLastError());
|
2010-03-02 22:29:48 +01:00
|
|
|
ok(GetLastError()==0xCAFEF00D,
|
|
|
|
"GetLastError: expected 0xCAFEF00D, got %08x\n", GetLastError());
|
|
|
|
|
|
|
|
/* Test freeing an already freed TLS index */
|
|
|
|
SetLastError(0xCAFEF00D);
|
|
|
|
ok(TlsFree(tlsIndex)==0,"TlsFree succeeded\n");
|
|
|
|
ok(GetLastError()==ERROR_INVALID_PARAMETER,
|
|
|
|
"GetLastError: expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
|
2005-10-28 12:41:57 +02:00
|
|
|
|
|
|
|
/* Test how passing NULL as a pointer to threadid works */
|
|
|
|
SetLastError(0xFACEaBAD);
|
2008-09-08 08:19:45 +02:00
|
|
|
thread[0] = CreateThread(NULL,0,threadFunc2,NULL,0,&tid);
|
2005-10-28 12:41:57 +02:00
|
|
|
GLE = GetLastError();
|
|
|
|
if (thread[0]) { /* NT */
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GLE==0xFACEaBAD, "CreateThread set last error to %d, expected 4207848365\n", GLE);
|
2005-10-28 12:41:57 +02:00
|
|
|
ret = WaitForSingleObject(thread[0],100);
|
|
|
|
ok(ret==WAIT_OBJECT_0, "threadFunc2 did not exit during 100 ms\n");
|
|
|
|
ret = GetExitCodeThread(thread[0],&exitCode);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret!=0, "GetExitCodeThread returned %d (expected nonzero)\n", ret);
|
|
|
|
ok(exitCode==99, "threadFunc2 exited with code: %d (expected 99)\n", exitCode);
|
2005-10-28 12:41:57 +02:00
|
|
|
ok(CloseHandle(thread[0])!=0,"Error closing thread handle\n");
|
|
|
|
}
|
|
|
|
else { /* 9x */
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GLE==ERROR_INVALID_PARAMETER, "CreateThread set last error to %d, expected 87\n", GLE);
|
2005-10-28 12:41:57 +02:00
|
|
|
}
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that using the CREATE_SUSPENDED flag works */
|
2005-06-14 13:40:04 +02:00
|
|
|
static VOID test_CreateThread_suspended(void)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
|
|
|
HANDLE thread;
|
|
|
|
DWORD threadId;
|
2008-07-22 23:54:39 +02:00
|
|
|
DWORD suspend_count;
|
2002-04-02 21:37:15 +02:00
|
|
|
int error;
|
|
|
|
|
2004-11-03 23:18:44 +01:00
|
|
|
thread = CreateThread(NULL,0,threadFunc2,NULL,
|
2002-04-02 21:37:15 +02:00
|
|
|
CREATE_SUSPENDED,&threadId);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(thread!=NULL,"Create Thread failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Check that the thread is suspended */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(SuspendThread(thread)==1,"Thread did not start suspended\n");
|
|
|
|
ok(ResumeThread(thread)==2,"Resume thread returned an invalid value\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Check that resume thread didn't actually start the thread. I can't think
|
|
|
|
of a better way of checking this than just waiting. I am not sure if this
|
|
|
|
will work on slow computers.
|
|
|
|
*/
|
|
|
|
ok(WaitForSingleObject(thread,1000)==WAIT_TIMEOUT,
|
2004-02-06 06:24:34 +01:00
|
|
|
"ResumeThread should not have actually started the thread\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Now actually resume the thread and make sure that it actually completes*/
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(ResumeThread(thread)==1,"Resume thread returned an invalid value\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
ok((error=WaitForSingleObject(thread,1000))==WAIT_OBJECT_0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"Thread did not resume\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
if(error!=WAIT_OBJECT_0) {
|
|
|
|
TerminateThread(thread,1);
|
|
|
|
}
|
2008-07-22 23:54:39 +02:00
|
|
|
|
|
|
|
suspend_count = SuspendThread(thread);
|
|
|
|
ok(suspend_count == -1, "SuspendThread returned %d, expected -1\n", suspend_count);
|
|
|
|
|
|
|
|
suspend_count = ResumeThread(thread);
|
2008-09-11 14:10:35 +02:00
|
|
|
ok(suspend_count == 0 ||
|
|
|
|
broken(suspend_count == -1), /* win9x */
|
|
|
|
"ResumeThread returned %d, expected 0\n", suspend_count);
|
2008-07-22 23:54:39 +02:00
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CloseHandle(thread)!=0,"CloseHandle failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that SuspendThread and ResumeThread work */
|
2005-06-14 13:40:04 +02:00
|
|
|
static VOID test_SuspendThread(void)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
|
|
|
HANDLE thread,access_thread;
|
2004-08-10 01:42:19 +02:00
|
|
|
DWORD threadId,exitCode,error;
|
|
|
|
int i;
|
2002-04-02 21:37:15 +02:00
|
|
|
|
2004-11-03 23:18:44 +01:00
|
|
|
thread = CreateThread(NULL,0,threadFunc3,NULL,
|
2002-04-02 21:37:15 +02:00
|
|
|
0,&threadId);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(thread!=NULL,"Create Thread failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Check that the thread is suspended */
|
|
|
|
/* Note that this is a polling method, and there is a race between
|
|
|
|
SuspendThread being called (in the child, and the loop below timing out,
|
|
|
|
so the test could fail on a heavily loaded or slow computer.
|
|
|
|
*/
|
|
|
|
error=0;
|
|
|
|
for(i=0;error==0 && i<100;i++) {
|
|
|
|
error=SuspendThread(thread);
|
|
|
|
ResumeThread(thread);
|
|
|
|
if(error==0) {
|
|
|
|
Sleep(50);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(error==1,"SuspendThread did not work\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* check that access restrictions are obeyed */
|
2002-11-30 20:03:19 +01:00
|
|
|
if (pOpenThread) {
|
2014-02-07 15:08:53 +01:00
|
|
|
access_thread=pOpenThread(THREAD_ALL_ACCESS_NT4 & (~THREAD_SUSPEND_RESUME),
|
2002-04-03 04:33:13 +02:00
|
|
|
0,threadId);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(access_thread!=NULL,"OpenThread returned an invalid handle\n");
|
2002-11-30 20:03:19 +01:00
|
|
|
if (access_thread!=NULL) {
|
2005-09-13 17:00:32 +02:00
|
|
|
obey_ar(SuspendThread(access_thread)==~0U);
|
|
|
|
obey_ar(ResumeThread(access_thread)==~0U);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CloseHandle(access_thread)!=0,"CloseHandle Failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Double check that the thread really is suspended */
|
|
|
|
ok((error=GetExitCodeThread(thread,&exitCode))!=0 && exitCode==STILL_ACTIVE,
|
2004-02-06 06:24:34 +01:00
|
|
|
"Thread did not really suspend\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Resume the thread, and make sure it actually completes */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(ResumeThread(thread)==1,"Resume thread returned an invalid value\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
ok((error=WaitForSingleObject(thread,1000))==WAIT_OBJECT_0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"Thread did not resume\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
if(error!=WAIT_OBJECT_0) {
|
|
|
|
TerminateThread(thread,1);
|
|
|
|
}
|
2002-11-30 20:03:19 +01:00
|
|
|
/* Trying to suspend a terminated thread should fail */
|
|
|
|
error=SuspendThread(thread);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(error==~0U, "wrong return code: %d\n", error);
|
|
|
|
ok(GetLastError()==ERROR_ACCESS_DENIED || GetLastError()==ERROR_NO_MORE_ITEMS, "unexpected error code: %d\n", GetLastError());
|
2002-11-30 20:03:19 +01:00
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CloseHandle(thread)!=0,"CloseHandle Failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that TerminateThread works properly
|
|
|
|
*/
|
2005-06-14 13:40:04 +02:00
|
|
|
static VOID test_TerminateThread(void)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
2002-04-03 04:33:13 +02:00
|
|
|
HANDLE thread,access_thread,event;
|
2002-04-02 21:37:15 +02:00
|
|
|
DWORD threadId,exitCode;
|
2002-04-03 04:33:13 +02:00
|
|
|
event=CreateEventA(NULL,TRUE,FALSE,NULL);
|
2009-03-11 09:39:16 +01:00
|
|
|
thread = CreateThread(NULL,0,threadFunc4,event,0,&threadId);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(thread!=NULL,"Create Thread failed\n");
|
2005-08-12 20:22:06 +02:00
|
|
|
/* TerminateThread has a race condition in Wine. If the thread is terminated
|
2002-04-03 04:33:13 +02:00
|
|
|
before it starts, it leaves a process behind. Therefore, we wait for the
|
|
|
|
thread to signal that it has started. There is no easy way to force the
|
|
|
|
race to occur, so we don't try to find it.
|
|
|
|
*/
|
|
|
|
ok(WaitForSingleObject(event,5000)==WAIT_OBJECT_0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"TerminateThread didn't work\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* check that access restrictions are obeyed */
|
2002-11-30 20:03:19 +01:00
|
|
|
if (pOpenThread) {
|
2014-02-07 15:08:53 +01:00
|
|
|
access_thread=pOpenThread(THREAD_ALL_ACCESS_NT4 & (~THREAD_TERMINATE),
|
2002-04-02 21:37:15 +02:00
|
|
|
0,threadId);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(access_thread!=NULL,"OpenThread returned an invalid handle\n");
|
2002-11-30 20:03:19 +01:00
|
|
|
if (access_thread!=NULL) {
|
2005-07-25 13:07:54 +02:00
|
|
|
obey_ar(TerminateThread(access_thread,99)==0);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CloseHandle(access_thread)!=0,"CloseHandle Failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* terminate a job and make sure it terminates */
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(TerminateThread(thread,99)!=0,"TerminateThread failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
ok(WaitForSingleObject(thread,5000)==WAIT_OBJECT_0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"TerminateThread didn't work\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
ok(GetExitCodeThread(thread,&exitCode)!=STILL_ACTIVE,
|
2004-02-06 06:24:34 +01:00
|
|
|
"TerminateThread should not leave the thread 'STILL_ACTIVE'\n");
|
|
|
|
ok(exitCode==99, "TerminateThread returned invalid exit code\n");
|
|
|
|
ok(CloseHandle(thread)!=0,"Error Closing thread handle\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if CreateThread obeys the specified stack size. This code does
|
|
|
|
not work properly, and is currently disabled
|
|
|
|
*/
|
2005-06-14 13:40:04 +02:00
|
|
|
static VOID test_CreateThread_stack(void)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
|
|
|
#if CHECK_STACK
|
|
|
|
/* The only way I know of to test the stack size is to use alloca
|
|
|
|
and __try/__except. However, this is probably not portable,
|
|
|
|
and I couldn't get it to work under Wine anyhow. However, here
|
|
|
|
is the code which should allow for testing that CreateThread
|
|
|
|
respects the stack-size limit
|
|
|
|
*/
|
|
|
|
HANDLE thread;
|
|
|
|
DWORD threadId,exitCode;
|
|
|
|
|
|
|
|
SYSTEM_INFO sysInfo;
|
|
|
|
sysInfo.dwPageSize=0;
|
|
|
|
GetSystemInfo(&sysInfo);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(sysInfo.dwPageSize>0,"GetSystemInfo should return a valid page size\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
thread = CreateThread(NULL,sysInfo.dwPageSize,
|
2004-11-03 23:18:44 +01:00
|
|
|
threadFunc5,&exitCode,
|
2002-04-02 21:37:15 +02:00
|
|
|
0,&threadId);
|
|
|
|
ok(WaitForSingleObject(thread,5000)==WAIT_OBJECT_0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"TerminateThread didn't work\n");
|
|
|
|
ok(exitCode==1,"CreateThread did not obey stack-size-limit\n");
|
|
|
|
ok(CloseHandle(thread)!=0,"CloseHandle failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-02-09 23:07:42 +01:00
|
|
|
/* Check whether setting/retrieving thread priorities works */
|
2005-06-14 13:40:04 +02:00
|
|
|
static VOID test_thread_priority(void)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
|
|
|
HANDLE curthread,access_thread;
|
|
|
|
DWORD curthreadId,exitCode;
|
|
|
|
int min_priority=-2,max_priority=2;
|
2005-07-30 21:03:46 +02:00
|
|
|
BOOL disabled,rc;
|
2003-01-21 00:26:09 +01:00
|
|
|
int i;
|
2002-04-02 21:37:15 +02:00
|
|
|
|
|
|
|
curthread=GetCurrentThread();
|
|
|
|
curthreadId=GetCurrentThreadId();
|
|
|
|
/* Check thread priority */
|
|
|
|
/* NOTE: on Win2k/XP priority can be from -7 to 6. All other platforms it
|
|
|
|
is -2 to 2. However, even on a real Win2k system, using thread
|
|
|
|
priorities beyond the -2 to 2 range does not work. If you want to try
|
|
|
|
anyway, enable USE_EXTENDED_PRIORITIES
|
|
|
|
*/
|
|
|
|
ok(GetThreadPriority(curthread)==THREAD_PRIORITY_NORMAL,
|
2004-02-06 06:24:34 +01:00
|
|
|
"GetThreadPriority Failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
|
2002-11-30 20:03:19 +01:00
|
|
|
if (pOpenThread) {
|
2002-04-02 21:37:15 +02:00
|
|
|
/* check that access control is obeyed */
|
2014-02-07 15:08:53 +01:00
|
|
|
access_thread=pOpenThread(THREAD_ALL_ACCESS_NT4 &
|
2002-04-02 21:37:15 +02:00
|
|
|
(~THREAD_QUERY_INFORMATION) & (~THREAD_SET_INFORMATION),
|
|
|
|
0,curthreadId);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(access_thread!=NULL,"OpenThread returned an invalid handle\n");
|
2002-11-30 20:03:19 +01:00
|
|
|
if (access_thread!=NULL) {
|
2005-07-25 13:07:54 +02:00
|
|
|
obey_ar(SetThreadPriority(access_thread,1)==0);
|
|
|
|
obey_ar(GetThreadPriority(access_thread)==THREAD_PRIORITY_ERROR_RETURN);
|
|
|
|
obey_ar(GetExitCodeThread(access_thread,&exitCode)==0);
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(CloseHandle(access_thread),"Error Closing thread handle\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
2006-12-30 20:18:58 +01:00
|
|
|
}
|
2002-04-02 21:37:15 +02:00
|
|
|
#if USE_EXTENDED_PRIORITIES
|
2006-12-30 20:18:58 +01:00
|
|
|
min_priority=-7; max_priority=6;
|
2002-04-02 21:37:15 +02:00
|
|
|
#endif
|
|
|
|
for(i=min_priority;i<=max_priority;i++) {
|
2002-04-03 04:33:13 +02:00
|
|
|
ok(SetThreadPriority(curthread,i)!=0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"SetThreadPriority Failed for priority: %d\n",i);
|
2002-04-03 04:33:13 +02:00
|
|
|
ok(GetThreadPriority(curthread)==i,
|
2004-02-06 06:24:34 +01:00
|
|
|
"GetThreadPriority Failed for priority: %d\n",i);
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
ok(SetThreadPriority(curthread,THREAD_PRIORITY_TIME_CRITICAL)!=0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"SetThreadPriority Failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
ok(GetThreadPriority(curthread)==THREAD_PRIORITY_TIME_CRITICAL,
|
2004-02-06 06:24:34 +01:00
|
|
|
"GetThreadPriority Failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
ok(SetThreadPriority(curthread,THREAD_PRIORITY_IDLE)!=0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"SetThreadPriority Failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
ok(GetThreadPriority(curthread)==THREAD_PRIORITY_IDLE,
|
2004-02-06 06:24:34 +01:00
|
|
|
"GetThreadPriority Failed\n");
|
|
|
|
ok(SetThreadPriority(curthread,0)!=0,"SetThreadPriority Failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
|
2007-07-24 22:20:40 +02:00
|
|
|
/* Check that the thread priority is not changed if SetThreadPriority
|
|
|
|
is called with a value outside of the max/min range */
|
|
|
|
SetThreadPriority(curthread,min_priority);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
rc = SetThreadPriority(curthread,min_priority-1);
|
|
|
|
|
2007-07-24 22:23:56 +02:00
|
|
|
ok(rc == FALSE, "SetThreadPriority passed with a bad argument\n");
|
2008-01-24 13:18:58 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER ||
|
|
|
|
GetLastError() == ERROR_INVALID_PRIORITY /* Win9x */,
|
|
|
|
"SetThreadPriority error %d, expected ERROR_INVALID_PARAMETER or ERROR_INVALID_PRIORITY\n",
|
|
|
|
GetLastError());
|
2007-07-24 22:23:56 +02:00
|
|
|
ok(GetThreadPriority(curthread)==min_priority,
|
|
|
|
"GetThreadPriority didn't return min_priority\n");
|
2007-07-24 22:20:40 +02:00
|
|
|
|
|
|
|
SetThreadPriority(curthread,max_priority);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
rc = SetThreadPriority(curthread,max_priority+1);
|
|
|
|
|
2007-07-24 22:23:56 +02:00
|
|
|
ok(rc == FALSE, "SetThreadPriority passed with a bad argument\n");
|
2008-01-24 13:18:58 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER ||
|
|
|
|
GetLastError() == ERROR_INVALID_PRIORITY /* Win9x */,
|
|
|
|
"SetThreadPriority error %d, expected ERROR_INVALID_PARAMETER or ERROR_INVALID_PRIORITY\n",
|
|
|
|
GetLastError());
|
2007-07-24 22:23:56 +02:00
|
|
|
ok(GetThreadPriority(curthread)==max_priority,
|
|
|
|
"GetThreadPriority didn't return max_priority\n");
|
2007-07-24 22:20:40 +02:00
|
|
|
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Check thread priority boost */
|
2005-07-30 21:03:46 +02:00
|
|
|
if (!pGetThreadPriorityBoost || !pSetThreadPriorityBoost)
|
|
|
|
return; /* Win9x */
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
rc=pGetThreadPriorityBoost(curthread,&disabled);
|
|
|
|
if (rc==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
|
2009-05-18 11:24:45 +02:00
|
|
|
{
|
|
|
|
win_skip("GetThreadPriorityBoost is not implemented on WinME\n");
|
|
|
|
return;
|
|
|
|
}
|
2005-07-30 21:03:46 +02:00
|
|
|
|
2009-08-29 12:22:13 +02:00
|
|
|
ok(rc!=0,"error=%d\n",GetLastError());
|
2006-12-30 20:19:07 +01:00
|
|
|
|
2006-12-30 20:19:24 +01:00
|
|
|
if (pOpenThread) {
|
2005-07-30 21:03:46 +02:00
|
|
|
/* check that access control is obeyed */
|
2014-02-07 15:08:53 +01:00
|
|
|
access_thread=pOpenThread(THREAD_ALL_ACCESS_NT4 &
|
2006-12-30 20:19:24 +01:00
|
|
|
(~THREAD_QUERY_INFORMATION) & (~THREAD_SET_INFORMATION),
|
|
|
|
0,curthreadId);
|
|
|
|
ok(access_thread!=NULL,"OpenThread returned an invalid handle\n");
|
|
|
|
if (access_thread!=NULL) {
|
2013-05-28 02:08:05 +02:00
|
|
|
todo_wine obey_ar(pSetThreadPriorityBoost(access_thread,1)==0);
|
2009-08-29 12:22:13 +02:00
|
|
|
todo_wine obey_ar(pGetThreadPriorityBoost(access_thread,&disabled)==0);
|
2006-12-30 20:19:24 +01:00
|
|
|
ok(CloseHandle(access_thread),"Error Closing thread handle\n");
|
|
|
|
}
|
2005-07-30 21:03:46 +02:00
|
|
|
}
|
|
|
|
|
2013-05-28 02:08:05 +02:00
|
|
|
rc = pSetThreadPriorityBoost(curthread,1);
|
|
|
|
ok( rc != 0, "error=%d\n",GetLastError());
|
2005-07-30 21:03:46 +02:00
|
|
|
todo_wine {
|
|
|
|
rc=pGetThreadPriorityBoost(curthread,&disabled);
|
|
|
|
ok(rc!=0 && disabled==1,
|
2006-10-10 01:06:48 +02:00
|
|
|
"rc=%d error=%d disabled=%d\n",rc,GetLastError(),disabled);
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
2013-05-28 02:08:05 +02:00
|
|
|
|
|
|
|
rc = pSetThreadPriorityBoost(curthread,0);
|
|
|
|
ok( rc != 0, "error=%d\n",GetLastError());
|
2009-08-29 12:22:13 +02:00
|
|
|
rc=pGetThreadPriorityBoost(curthread,&disabled);
|
|
|
|
ok(rc!=0 && disabled==0,
|
|
|
|
"rc=%d error=%d disabled=%d\n",rc,GetLastError(),disabled);
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check the GetThreadTimes function */
|
2005-06-14 13:40:04 +02:00
|
|
|
static VOID test_GetThreadTimes(void)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
2002-11-30 20:03:19 +01:00
|
|
|
HANDLE thread,access_thread=NULL;
|
2002-04-02 21:37:15 +02:00
|
|
|
FILETIME creationTime,exitTime,kernelTime,userTime;
|
|
|
|
DWORD threadId;
|
|
|
|
int error;
|
|
|
|
|
2004-11-03 23:18:44 +01:00
|
|
|
thread = CreateThread(NULL,0,threadFunc2,NULL,
|
2002-04-02 21:37:15 +02:00
|
|
|
CREATE_SUSPENDED,&threadId);
|
|
|
|
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(thread!=NULL,"Create Thread failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* check that access control is obeyed */
|
2002-11-30 20:03:19 +01:00
|
|
|
if (pOpenThread) {
|
2014-02-07 15:08:53 +01:00
|
|
|
access_thread=pOpenThread(THREAD_ALL_ACCESS_NT4 &
|
2002-04-02 21:37:15 +02:00
|
|
|
(~THREAD_QUERY_INFORMATION), 0,threadId);
|
2002-11-30 20:03:19 +01:00
|
|
|
ok(access_thread!=NULL,
|
2004-02-06 06:24:34 +01:00
|
|
|
"OpenThread returned an invalid handle\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(ResumeThread(thread)==1,"Resume thread returned an invalid value\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
ok(WaitForSingleObject(thread,5000)==WAIT_OBJECT_0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"ResumeThread didn't work\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
creationTime.dwLowDateTime=99; creationTime.dwHighDateTime=99;
|
|
|
|
exitTime.dwLowDateTime=99; exitTime.dwHighDateTime=99;
|
|
|
|
kernelTime.dwLowDateTime=99; kernelTime.dwHighDateTime=99;
|
|
|
|
userTime.dwLowDateTime=99; userTime.dwHighDateTime=99;
|
|
|
|
/* GetThreadTimes should set all of the parameters passed to it */
|
2002-11-25 02:34:23 +01:00
|
|
|
error=GetThreadTimes(thread,&creationTime,&exitTime,
|
|
|
|
&kernelTime,&userTime);
|
2009-05-18 11:24:45 +02:00
|
|
|
|
|
|
|
if (error == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
win_skip("GetThreadTimes is not implemented\n");
|
|
|
|
else {
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(error!=0,"GetThreadTimes failed\n");
|
2002-11-30 20:03:19 +01:00
|
|
|
ok(creationTime.dwLowDateTime!=99 || creationTime.dwHighDateTime!=99,
|
2004-02-06 06:24:34 +01:00
|
|
|
"creationTime was invalid\n");
|
2002-11-30 20:03:19 +01:00
|
|
|
ok(exitTime.dwLowDateTime!=99 || exitTime.dwHighDateTime!=99,
|
2004-02-06 06:24:34 +01:00
|
|
|
"exitTime was invalid\n");
|
2002-11-30 20:03:19 +01:00
|
|
|
ok(kernelTime.dwLowDateTime!=99 || kernelTime.dwHighDateTime!=99,
|
2004-02-06 06:24:34 +01:00
|
|
|
"kernelTimewas invalid\n");
|
2002-11-30 20:03:19 +01:00
|
|
|
ok(userTime.dwLowDateTime!=99 || userTime.dwHighDateTime!=99,
|
2004-02-06 06:24:34 +01:00
|
|
|
"userTime was invalid\n");
|
|
|
|
ok(CloseHandle(thread)!=0,"CloseHandle failed\n");
|
2005-07-30 21:03:46 +02:00
|
|
|
if(access_thread!=NULL)
|
|
|
|
{
|
|
|
|
error=GetThreadTimes(access_thread,&creationTime,&exitTime,
|
|
|
|
&kernelTime,&userTime);
|
|
|
|
obey_ar(error==0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(access_thread!=NULL) {
|
|
|
|
ok(CloseHandle(access_thread)!=0,"CloseHandle Failed\n");
|
2002-11-30 20:03:19 +01:00
|
|
|
}
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the processor affinity functions */
|
|
|
|
/* NOTE: These functions should also be checked that they obey access control
|
|
|
|
*/
|
2005-06-14 13:40:04 +02:00
|
|
|
static VOID test_thread_processor(void)
|
2002-04-02 21:37:15 +02:00
|
|
|
{
|
|
|
|
HANDLE curthread,curproc;
|
2010-02-20 03:07:57 +01:00
|
|
|
DWORD_PTR processMask,systemMask,retMask;
|
2002-04-02 21:37:15 +02:00
|
|
|
SYSTEM_INFO sysInfo;
|
|
|
|
int error=0;
|
2009-12-23 12:13:32 +01:00
|
|
|
BOOL is_wow64;
|
|
|
|
|
|
|
|
if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
|
2002-04-02 21:37:15 +02:00
|
|
|
|
|
|
|
sysInfo.dwNumberOfProcessors=0;
|
|
|
|
GetSystemInfo(&sysInfo);
|
|
|
|
ok(sysInfo.dwNumberOfProcessors>0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"GetSystemInfo failed to return a valid # of processors\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Use the current Thread/process for all tests */
|
|
|
|
curthread=GetCurrentThread();
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(curthread!=NULL,"GetCurrentThread failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
curproc=GetCurrentProcess();
|
2004-02-06 06:24:34 +01:00
|
|
|
ok(curproc!=NULL,"GetCurrentProcess failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
/* Check the Affinity Mask functions */
|
|
|
|
ok(GetProcessAffinityMask(curproc,&processMask,&systemMask)!=0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"GetProcessAffinityMask failed\n");
|
2005-03-25 11:25:11 +01:00
|
|
|
ok(SetThreadAffinityMask(curthread,processMask)==processMask,
|
2004-02-06 06:24:34 +01:00
|
|
|
"SetThreadAffinityMask failed\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
ok(SetThreadAffinityMask(curthread,processMask+1)==0,
|
2004-02-06 06:24:34 +01:00
|
|
|
"SetThreadAffinityMask passed for an illegal processor\n");
|
2010-02-20 03:07:57 +01:00
|
|
|
/* NOTE: Pre-Vista does not recognize the "all processors" flag (all bits set) */
|
2010-04-08 21:16:29 +02:00
|
|
|
retMask = SetThreadAffinityMask(curthread,~0);
|
2010-02-20 03:07:57 +01:00
|
|
|
ok(broken(retMask==0) || retMask==processMask,
|
|
|
|
"SetThreadAffinityMask(thread,-1) failed to request all processors.\n");
|
2015-09-23 22:51:23 +02:00
|
|
|
|
|
|
|
if (retMask == processMask)
|
|
|
|
{
|
|
|
|
/* Show that the "all processors" flag is handled in ntdll */
|
|
|
|
DWORD_PTR mask = ~0u;
|
|
|
|
NTSTATUS status = pNtSetInformationThread(curthread, ThreadAffinityMask, &mask, sizeof(mask));
|
|
|
|
ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS in NtSetInformationThread, got %x\n", status);
|
|
|
|
}
|
|
|
|
|
2010-04-08 21:16:29 +02:00
|
|
|
if (retMask == processMask && sizeof(ULONG_PTR) > sizeof(ULONG))
|
|
|
|
{
|
|
|
|
/* only the low 32-bits matter */
|
|
|
|
retMask = SetThreadAffinityMask(curthread,~(ULONG_PTR)0);
|
|
|
|
ok(retMask == processMask, "SetThreadAffinityMask failed\n");
|
|
|
|
retMask = SetThreadAffinityMask(curthread,~(ULONG_PTR)0 >> 3);
|
|
|
|
ok(retMask == processMask, "SetThreadAffinityMask failed\n");
|
|
|
|
}
|
2002-04-02 21:37:15 +02:00
|
|
|
/* NOTE: This only works on WinNT/2000/XP) */
|
2015-09-23 22:51:23 +02:00
|
|
|
if (pSetThreadIdealProcessor)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
error=pSetThreadIdealProcessor(curthread,0);
|
|
|
|
if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
ok(error!=-1, "SetThreadIdealProcessor failed\n");
|
|
|
|
|
|
|
|
if (is_wow64)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
error=pSetThreadIdealProcessor(curthread,MAXIMUM_PROCESSORS+1);
|
|
|
|
todo_wine
|
|
|
|
ok(error!=-1, "SetThreadIdealProcessor failed for %u on Wow64\n", MAXIMUM_PROCESSORS+1);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
error=pSetThreadIdealProcessor(curthread,65);
|
|
|
|
ok(error==-1, "SetThreadIdealProcessor succeeded with an illegal processor #\n");
|
|
|
|
ok(GetLastError()==ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
error=pSetThreadIdealProcessor(curthread,MAXIMUM_PROCESSORS+1);
|
|
|
|
ok(error==-1, "SetThreadIdealProcessor succeeded with an illegal processor #\n");
|
|
|
|
ok(GetLastError()==ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
error=pSetThreadIdealProcessor(curthread,MAXIMUM_PROCESSORS);
|
|
|
|
ok(error!=-1, "SetThreadIdealProcessor failed\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
win_skip("SetThreadIdealProcessor is not implemented\n");
|
|
|
|
}
|
2009-08-07 13:39:47 +02:00
|
|
|
|
2015-09-23 22:51:23 +02:00
|
|
|
if (pGetThreadGroupAffinity && pSetThreadGroupAffinity)
|
|
|
|
{
|
|
|
|
GROUP_AFFINITY affinity, affinity_new;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
memset(&affinity, 0, sizeof(affinity));
|
|
|
|
ok(pGetThreadGroupAffinity(curthread, &affinity), "GetThreadGroupAffinity failed\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!pGetThreadGroupAffinity(curthread, NULL), "GetThreadGroupAffinity succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == ERROR_NOACCESS), /* Win 7 and 8 */
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
ok(affinity.Group == 0, "Expected group 0 got %u\n", affinity.Group);
|
|
|
|
|
|
|
|
memset(&affinity_new, 0, sizeof(affinity_new));
|
|
|
|
affinity_new.Group = 0;
|
|
|
|
affinity_new.Mask = affinity.Mask;
|
|
|
|
ok(pSetThreadGroupAffinity(curthread, &affinity_new, &affinity), "SetThreadGroupAffinity failed\n");
|
|
|
|
ok(affinity_new.Mask == affinity.Mask, "Expected old affinity mask %lx, got %lx\n",
|
|
|
|
affinity_new.Mask, affinity.Mask);
|
|
|
|
|
|
|
|
/* show that the "all processors" flag is not supported for SetThreadGroupAffinity */
|
|
|
|
affinity_new.Group = 0;
|
|
|
|
affinity_new.Mask = ~0u;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!pSetThreadGroupAffinity(curthread, &affinity_new, NULL), "SetThreadGroupAffinity succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
affinity_new.Group = 1; /* assumes that you have less than 64 logical processors */
|
|
|
|
affinity_new.Mask = 0x1;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!pSetThreadGroupAffinity(curthread, &affinity_new, NULL), "SetThreadGroupAffinity succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!pSetThreadGroupAffinity(curthread, NULL, NULL), "SetThreadGroupAffinity succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_NOACCESS,
|
|
|
|
"Expected ERROR_NOACCESS, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* show that the access violation was detected in ntdll */
|
|
|
|
status = pNtSetInformationThread(curthread, ThreadGroupInformation, NULL, sizeof(affinity_new));
|
|
|
|
ok(status == STATUS_ACCESS_VIOLATION,
|
|
|
|
"Expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
|
|
|
|
|
|
|
|
/* restore original mask */
|
|
|
|
affinity_new.Group = 0;
|
|
|
|
affinity_new.Mask = affinity.Mask;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(pSetThreadGroupAffinity(curthread, &affinity_new, &affinity), "SetThreadGroupAffinity failed\n");
|
|
|
|
ok(affinity_new.Mask == affinity.Mask, "Expected old affinity mask %lx, got %lx\n",
|
|
|
|
affinity_new.Mask, affinity.Mask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
win_skip("Get/SetThreadGroupAffinity not available\n");
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|
|
|
|
|
2005-10-28 11:40:09 +02:00
|
|
|
static VOID test_GetThreadExitCode(void)
|
|
|
|
{
|
|
|
|
DWORD exitCode, threadid;
|
|
|
|
DWORD GLE, ret;
|
|
|
|
HANDLE thread;
|
|
|
|
|
|
|
|
ret = GetExitCodeThread((HANDLE)0x2bad2bad,&exitCode);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret==0, "GetExitCodeThread returned non zero value: %d\n", ret);
|
2005-10-28 11:40:09 +02:00
|
|
|
GLE = GetLastError();
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(GLE==ERROR_INVALID_HANDLE, "GetLastError returned %d (expected 6)\n", GLE);
|
2005-10-28 11:40:09 +02:00
|
|
|
|
|
|
|
thread = CreateThread(NULL,0,threadFunc2,NULL,0,&threadid);
|
|
|
|
ret = WaitForSingleObject(thread,100);
|
|
|
|
ok(ret==WAIT_OBJECT_0, "threadFunc2 did not exit during 100 ms\n");
|
|
|
|
ret = GetExitCodeThread(thread,&exitCode);
|
|
|
|
ok(ret==exitCode || ret==1,
|
2006-10-10 01:06:48 +02:00
|
|
|
"GetExitCodeThread returned %d (expected 1 or %d)\n", ret, exitCode);
|
|
|
|
ok(exitCode==99, "threadFunc2 exited with code %d (expected 99)\n", exitCode);
|
2005-10-28 11:40:09 +02:00
|
|
|
ok(CloseHandle(thread)!=0,"Error closing thread handle\n");
|
|
|
|
}
|
|
|
|
|
2005-11-02 21:54:12 +01:00
|
|
|
#ifdef __i386__
|
|
|
|
|
|
|
|
static int test_value = 0;
|
2005-11-18 16:06:38 +01:00
|
|
|
static HANDLE event;
|
2005-11-02 21:54:12 +01:00
|
|
|
|
2005-11-14 12:23:11 +01:00
|
|
|
static void WINAPI set_test_val( int val )
|
2005-11-02 21:54:12 +01:00
|
|
|
{
|
|
|
|
test_value += val;
|
2011-05-06 17:12:22 +02:00
|
|
|
ExitThread(0);
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI threadFunc6(LPVOID p)
|
|
|
|
{
|
2005-11-18 16:06:38 +01:00
|
|
|
SetEvent( event );
|
|
|
|
Sleep( 1000 );
|
2005-11-02 21:54:12 +01:00
|
|
|
test_value *= (int)p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SetThreadContext(void)
|
|
|
|
{
|
|
|
|
CONTEXT ctx;
|
|
|
|
int *stack;
|
2005-11-15 13:00:41 +01:00
|
|
|
HANDLE thread;
|
|
|
|
DWORD threadid;
|
|
|
|
DWORD prevcount;
|
2007-11-20 17:53:43 +01:00
|
|
|
BOOL ret;
|
2005-11-15 13:00:41 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-21 10:02:45 +02:00
|
|
|
event = CreateEventW( NULL, TRUE, FALSE, NULL );
|
2005-11-18 16:06:38 +01:00
|
|
|
thread = CreateThread( NULL, 0, threadFunc6, (void *)2, 0, &threadid );
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( thread != NULL, "CreateThread failed : (%d)\n", GetLastError() );
|
2005-11-15 13:00:41 +01:00
|
|
|
if (!thread)
|
|
|
|
{
|
|
|
|
trace("Thread creation failed, skipping rest of test\n");
|
|
|
|
return;
|
|
|
|
}
|
2005-11-18 16:06:38 +01:00
|
|
|
WaitForSingleObject( event, INFINITE );
|
|
|
|
SuspendThread( thread );
|
|
|
|
CloseHandle( event );
|
2005-11-02 21:54:12 +01:00
|
|
|
|
|
|
|
ctx.ContextFlags = CONTEXT_FULL;
|
2005-11-15 13:00:41 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2007-11-20 17:53:43 +01:00
|
|
|
ret = GetThreadContext( thread, &ctx );
|
|
|
|
ok( ret, "GetThreadContext failed : (%u)\n", GetLastError() );
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
/* simulate a call to set_test_val(10) */
|
|
|
|
stack = (int *)ctx.Esp;
|
|
|
|
stack[-1] = 10;
|
|
|
|
stack[-2] = ctx.Eip;
|
|
|
|
ctx.Esp -= 2 * sizeof(int *);
|
|
|
|
ctx.Eip = (DWORD)set_test_val;
|
|
|
|
SetLastError(0xdeadbeef);
|
2011-02-04 16:49:14 +01:00
|
|
|
ret = SetThreadContext( thread, &ctx );
|
|
|
|
ok( ret, "SetThreadContext failed : (%d)\n", GetLastError() );
|
2007-11-20 17:53:43 +01:00
|
|
|
}
|
2005-11-15 13:00:41 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
prevcount = ResumeThread( thread );
|
2006-10-10 01:06:48 +02:00
|
|
|
ok ( prevcount == 1, "Previous suspend count (%d) instead of 1, last error : (%d)\n",
|
2005-11-15 13:00:41 +01:00
|
|
|
prevcount, GetLastError() );
|
|
|
|
|
2005-11-02 21:54:12 +01:00
|
|
|
WaitForSingleObject( thread, INFINITE );
|
2011-05-06 21:10:29 +02:00
|
|
|
ok( test_value == 10, "test_value %d\n", test_value );
|
2011-05-06 13:06:52 +02:00
|
|
|
|
|
|
|
ctx.ContextFlags = CONTEXT_FULL;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetThreadContext( thread, &ctx );
|
2012-11-13 23:50:13 +01:00
|
|
|
ok( (!ret && (GetLastError() == ERROR_GEN_FAILURE)) ||
|
|
|
|
(!ret && broken(GetLastError() == ERROR_INVALID_HANDLE)) || /* win2k */
|
|
|
|
broken(ret), /* 32bit application on NT 5.x 64bit */
|
|
|
|
"got %d with %u (expected FALSE with ERROR_GEN_FAILURE)\n",
|
|
|
|
ret, GetLastError() );
|
2011-05-06 13:06:52 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = SetThreadContext( thread, &ctx );
|
2012-11-13 23:50:13 +01:00
|
|
|
ok( (!ret && ((GetLastError() == ERROR_GEN_FAILURE) || (GetLastError() == ERROR_ACCESS_DENIED))) ||
|
|
|
|
(!ret && broken(GetLastError() == ERROR_INVALID_HANDLE)) || /* win2k */
|
|
|
|
broken(ret), /* 32bit application on NT 5.x 64bit */
|
|
|
|
"got %d with %u (expected FALSE with ERROR_GEN_FAILURE or ERROR_ACCESS_DENIED)\n",
|
|
|
|
ret, GetLastError() );
|
2011-05-06 13:06:52 +02:00
|
|
|
|
|
|
|
CloseHandle( thread );
|
2005-11-02 21:54:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
2006-03-21 14:43:06 +01:00
|
|
|
static HANDLE finish_event;
|
|
|
|
static LONG times_executed;
|
|
|
|
|
|
|
|
static DWORD CALLBACK work_function(void *p)
|
|
|
|
{
|
|
|
|
LONG executed = InterlockedIncrement(×_executed);
|
|
|
|
|
|
|
|
if (executed == 100)
|
|
|
|
SetEvent(finish_event);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_QueueUserWorkItem(void)
|
|
|
|
{
|
2009-01-03 20:17:31 +01:00
|
|
|
INT_PTR i;
|
2006-03-21 14:43:06 +01:00
|
|
|
DWORD wait_result;
|
|
|
|
DWORD before, after;
|
|
|
|
|
2006-03-22 23:34:52 +01:00
|
|
|
/* QueueUserWorkItem not present on win9x */
|
|
|
|
if (!pQueueUserWorkItem) return;
|
|
|
|
|
2013-10-21 10:02:45 +02:00
|
|
|
finish_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2006-03-21 14:43:06 +01:00
|
|
|
|
|
|
|
before = GetTickCount();
|
|
|
|
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
{
|
2006-03-22 23:34:52 +01:00
|
|
|
BOOL ret = pQueueUserWorkItem(work_function, (void *)i, WT_EXECUTEDEFAULT);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret, "QueueUserWorkItem failed with error %d\n", GetLastError());
|
2006-03-21 14:43:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
wait_result = WaitForSingleObject(finish_event, 10000);
|
|
|
|
|
|
|
|
after = GetTickCount();
|
2006-10-10 01:06:48 +02:00
|
|
|
trace("100 QueueUserWorkItem calls took %dms\n", after - before);
|
|
|
|
ok(wait_result == WAIT_OBJECT_0, "wait failed with error 0x%x\n", wait_result);
|
2006-03-21 14:43:06 +01:00
|
|
|
|
|
|
|
ok(times_executed == 100, "didn't execute all of the work items\n");
|
|
|
|
}
|
2005-11-02 21:54:12 +01:00
|
|
|
|
2008-01-01 23:37:34 +01:00
|
|
|
static void CALLBACK signaled_function(PVOID p, BOOLEAN TimerOrWaitFired)
|
|
|
|
{
|
|
|
|
HANDLE event = p;
|
|
|
|
SetEvent(event);
|
|
|
|
ok(!TimerOrWaitFired, "wait shouldn't have timed out\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CALLBACK timeout_function(PVOID p, BOOLEAN TimerOrWaitFired)
|
|
|
|
{
|
|
|
|
HANDLE event = p;
|
|
|
|
SetEvent(event);
|
|
|
|
ok(TimerOrWaitFired, "wait should have timed out\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_RegisterWaitForSingleObject(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE wait_handle;
|
|
|
|
HANDLE handle;
|
|
|
|
HANDLE complete_event;
|
|
|
|
|
|
|
|
if (!pRegisterWaitForSingleObject || !pUnregisterWait)
|
|
|
|
{
|
2009-02-24 00:03:07 +01:00
|
|
|
win_skip("RegisterWaitForSingleObject or UnregisterWait not implemented\n");
|
2008-01-01 23:37:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test signaled case */
|
|
|
|
|
2013-10-21 10:02:45 +02:00
|
|
|
handle = CreateEventW(NULL, TRUE, TRUE, NULL);
|
|
|
|
complete_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2008-01-01 23:37:34 +01:00
|
|
|
|
|
|
|
ret = pRegisterWaitForSingleObject(&wait_handle, handle, signaled_function, complete_event, INFINITE, WT_EXECUTEONLYONCE);
|
|
|
|
ok(ret, "RegisterWaitForSingleObject failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
WaitForSingleObject(complete_event, INFINITE);
|
|
|
|
/* give worker thread chance to complete */
|
|
|
|
Sleep(100);
|
|
|
|
|
|
|
|
ret = pUnregisterWait(wait_handle);
|
|
|
|
ok(ret, "UnregisterWait failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* test cancel case */
|
|
|
|
|
|
|
|
ResetEvent(handle);
|
|
|
|
|
|
|
|
ret = pRegisterWaitForSingleObject(&wait_handle, handle, signaled_function, complete_event, INFINITE, WT_EXECUTEONLYONCE);
|
|
|
|
ok(ret, "RegisterWaitForSingleObject failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
ret = pUnregisterWait(wait_handle);
|
|
|
|
ok(ret, "UnregisterWait failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* test timeout case */
|
|
|
|
|
|
|
|
ret = pRegisterWaitForSingleObject(&wait_handle, handle, timeout_function, complete_event, 0, WT_EXECUTEONLYONCE);
|
|
|
|
ok(ret, "RegisterWaitForSingleObject failed with error %d\n", GetLastError());
|
|
|
|
|
|
|
|
WaitForSingleObject(complete_event, INFINITE);
|
|
|
|
/* give worker thread chance to complete */
|
|
|
|
Sleep(100);
|
|
|
|
|
|
|
|
ret = pUnregisterWait(wait_handle);
|
|
|
|
ok(ret, "UnregisterWait failed with error %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2008-06-21 01:10:31 +02:00
|
|
|
static DWORD TLS_main;
|
|
|
|
static DWORD TLS_index0, TLS_index1;
|
|
|
|
|
|
|
|
static DWORD WINAPI TLS_InheritanceProc(LPVOID p)
|
|
|
|
{
|
|
|
|
/* We should NOT inherit the TLS values from our parent or from the
|
|
|
|
main thread. */
|
|
|
|
LPVOID val;
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_main);
|
|
|
|
ok(val == NULL, "TLS inheritance failed\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index0);
|
|
|
|
ok(val == NULL, "TLS inheritance failed\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index1);
|
|
|
|
ok(val == NULL, "TLS inheritance failed\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Basic TLS usage test. Make sure we can create slots and the values we
|
|
|
|
store in them are separate among threads. Also test TLS value
|
|
|
|
inheritance with TLS_InheritanceProc. */
|
|
|
|
static DWORD WINAPI TLS_ThreadProc(LPVOID p)
|
|
|
|
{
|
2009-01-03 20:17:31 +01:00
|
|
|
LONG_PTR id = (LONG_PTR) p;
|
2008-06-21 01:10:31 +02:00
|
|
|
LPVOID val;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (sync_threads_and_run_one(0, id))
|
|
|
|
{
|
|
|
|
TLS_index0 = TlsAlloc();
|
|
|
|
ok(TLS_index0 != TLS_OUT_OF_INDEXES, "TlsAlloc failed\n");
|
|
|
|
}
|
|
|
|
resync_after_run();
|
|
|
|
|
|
|
|
if (sync_threads_and_run_one(1, id))
|
|
|
|
{
|
|
|
|
TLS_index1 = TlsAlloc();
|
|
|
|
ok(TLS_index1 != TLS_OUT_OF_INDEXES, "TlsAlloc failed\n");
|
|
|
|
|
|
|
|
/* Slot indices should be different even if created in different
|
|
|
|
threads. */
|
|
|
|
ok(TLS_index0 != TLS_index1, "TlsAlloc failed\n");
|
|
|
|
|
|
|
|
/* Both slots should be initialized to NULL */
|
|
|
|
val = TlsGetValue(TLS_index0);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == NULL, "TLS slot not initialized correctly\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index1);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == NULL, "TLS slot not initialized correctly\n");
|
|
|
|
}
|
|
|
|
resync_after_run();
|
|
|
|
|
|
|
|
if (sync_threads_and_run_one(0, id))
|
|
|
|
{
|
|
|
|
val = TlsGetValue(TLS_index0);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == NULL, "TLS slot not initialized correctly\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index1);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == NULL, "TLS slot not initialized correctly\n");
|
|
|
|
|
|
|
|
ret = TlsSetValue(TLS_index0, (LPVOID) 1);
|
|
|
|
ok(ret, "TlsSetValue failed\n");
|
|
|
|
|
|
|
|
ret = TlsSetValue(TLS_index1, (LPVOID) 2);
|
|
|
|
ok(ret, "TlsSetValue failed\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index0);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == (LPVOID) 1, "TLS slot not initialized correctly\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index1);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == (LPVOID) 2, "TLS slot not initialized correctly\n");
|
|
|
|
}
|
|
|
|
resync_after_run();
|
|
|
|
|
|
|
|
if (sync_threads_and_run_one(1, id))
|
|
|
|
{
|
|
|
|
val = TlsGetValue(TLS_index0);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == NULL, "TLS slot not initialized correctly\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index1);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == NULL, "TLS slot not initialized correctly\n");
|
|
|
|
|
|
|
|
ret = TlsSetValue(TLS_index0, (LPVOID) 3);
|
|
|
|
ok(ret, "TlsSetValue failed\n");
|
|
|
|
|
|
|
|
ret = TlsSetValue(TLS_index1, (LPVOID) 4);
|
|
|
|
ok(ret, "TlsSetValue failed\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index0);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == (LPVOID) 3, "TLS slot not initialized correctly\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index1);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == (LPVOID) 4, "TLS slot not initialized correctly\n");
|
|
|
|
}
|
|
|
|
resync_after_run();
|
|
|
|
|
|
|
|
if (sync_threads_and_run_one(0, id))
|
|
|
|
{
|
|
|
|
HANDLE thread;
|
2008-09-08 08:19:45 +02:00
|
|
|
DWORD waitret, tid;
|
2008-06-21 01:10:31 +02:00
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index0);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == (LPVOID) 1, "TLS slot not initialized correctly\n");
|
|
|
|
|
|
|
|
val = TlsGetValue(TLS_index1);
|
|
|
|
ok(GetLastError() == ERROR_SUCCESS, "TlsGetValue failed\n");
|
|
|
|
ok(val == (LPVOID) 2, "TLS slot not initialized correctly\n");
|
|
|
|
|
2008-09-08 08:19:45 +02:00
|
|
|
thread = CreateThread(NULL, 0, TLS_InheritanceProc, 0, 0, &tid);
|
2008-06-21 01:10:31 +02:00
|
|
|
ok(thread != NULL, "CreateThread failed\n");
|
|
|
|
waitret = WaitForSingleObject(thread, 60000);
|
|
|
|
ok(waitret == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
ret = TlsFree(TLS_index0);
|
|
|
|
ok(ret, "TlsFree failed\n");
|
|
|
|
}
|
|
|
|
resync_after_run();
|
|
|
|
|
|
|
|
if (sync_threads_and_run_one(1, id))
|
|
|
|
{
|
|
|
|
ret = TlsFree(TLS_index1);
|
|
|
|
ok(ret, "TlsFree failed\n");
|
|
|
|
}
|
|
|
|
resync_after_run();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_TLS(void)
|
|
|
|
{
|
|
|
|
HANDLE threads[2];
|
2009-01-03 20:17:31 +01:00
|
|
|
LONG_PTR i;
|
2008-06-21 01:10:31 +02:00
|
|
|
DWORD ret;
|
|
|
|
BOOL suc;
|
|
|
|
|
2008-11-13 11:49:36 +01:00
|
|
|
init_thread_sync_helpers();
|
2008-06-21 01:10:31 +02:00
|
|
|
|
|
|
|
/* Allocate a TLS slot in the main thread to test for inheritance. */
|
|
|
|
TLS_main = TlsAlloc();
|
|
|
|
ok(TLS_main != TLS_OUT_OF_INDEXES, "TlsAlloc failed\n");
|
|
|
|
suc = TlsSetValue(TLS_main, (LPVOID) 4114);
|
|
|
|
ok(suc, "TlsSetValue failed\n");
|
|
|
|
|
|
|
|
for (i = 0; i < 2; ++i)
|
|
|
|
{
|
2008-09-08 08:19:45 +02:00
|
|
|
DWORD tid;
|
|
|
|
|
|
|
|
threads[i] = CreateThread(NULL, 0, TLS_ThreadProc, (LPVOID) i, 0, &tid);
|
2008-06-21 01:10:31 +02:00
|
|
|
ok(threads[i] != NULL, "CreateThread failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = WaitForMultipleObjects(2, threads, TRUE, 60000);
|
2011-07-23 22:02:19 +02:00
|
|
|
ok(ret == WAIT_OBJECT_0 || broken(ret == WAIT_OBJECT_0+1 /* nt4,w2k */), "WaitForAllObjects 2 threads %d\n",ret);
|
2008-06-21 01:10:31 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 2; ++i)
|
|
|
|
CloseHandle(threads[i]);
|
|
|
|
|
|
|
|
suc = TlsFree(TLS_main);
|
|
|
|
ok(suc, "TlsFree failed\n");
|
|
|
|
cleanup_thread_sync_helpers();
|
|
|
|
}
|
|
|
|
|
2010-02-03 14:33:38 +01:00
|
|
|
static void test_ThreadErrorMode(void)
|
|
|
|
{
|
|
|
|
DWORD oldmode;
|
|
|
|
DWORD mode;
|
|
|
|
DWORD rtlmode;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!pSetThreadErrorMode || !pGetThreadErrorMode)
|
|
|
|
{
|
2010-02-03 14:37:35 +01:00
|
|
|
win_skip("SetThreadErrorMode and/or GetThreadErrorMode unavailable (added in Windows 7)\n");
|
2010-02-03 14:33:38 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pRtlGetThreadErrorMode) {
|
|
|
|
win_skip("RtlGetThreadErrorMode not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldmode = pGetThreadErrorMode();
|
|
|
|
|
|
|
|
ret = pSetThreadErrorMode(0, &mode);
|
|
|
|
ok(ret, "SetThreadErrorMode failed\n");
|
|
|
|
ok(mode == oldmode,
|
|
|
|
"SetThreadErrorMode returned old mode 0x%x, expected 0x%x\n",
|
|
|
|
mode, oldmode);
|
|
|
|
mode = pGetThreadErrorMode();
|
|
|
|
ok(mode == 0, "GetThreadErrorMode returned mode 0x%x, expected 0\n", mode);
|
|
|
|
rtlmode = pRtlGetThreadErrorMode();
|
|
|
|
ok(rtlmode == 0,
|
|
|
|
"RtlGetThreadErrorMode returned mode 0x%x, expected 0\n", mode);
|
|
|
|
|
|
|
|
ret = pSetThreadErrorMode(SEM_FAILCRITICALERRORS, &mode);
|
|
|
|
ok(ret, "SetThreadErrorMode failed\n");
|
|
|
|
ok(mode == 0,
|
|
|
|
"SetThreadErrorMode returned old mode 0x%x, expected 0\n", mode);
|
|
|
|
mode = pGetThreadErrorMode();
|
|
|
|
ok(mode == SEM_FAILCRITICALERRORS,
|
|
|
|
"GetThreadErrorMode returned mode 0x%x, expected SEM_FAILCRITICALERRORS\n",
|
|
|
|
mode);
|
|
|
|
rtlmode = pRtlGetThreadErrorMode();
|
|
|
|
ok(rtlmode == 0x10,
|
|
|
|
"RtlGetThreadErrorMode returned mode 0x%x, expected 0x10\n", mode);
|
|
|
|
|
|
|
|
ret = pSetThreadErrorMode(SEM_NOGPFAULTERRORBOX, &mode);
|
|
|
|
ok(ret, "SetThreadErrorMode failed\n");
|
|
|
|
ok(mode == SEM_FAILCRITICALERRORS,
|
|
|
|
"SetThreadErrorMode returned old mode 0x%x, expected SEM_FAILCRITICALERRORS\n",
|
|
|
|
mode);
|
|
|
|
mode = pGetThreadErrorMode();
|
|
|
|
ok(mode == SEM_NOGPFAULTERRORBOX,
|
|
|
|
"GetThreadErrorMode returned mode 0x%x, expected SEM_NOGPFAULTERRORBOX\n",
|
|
|
|
mode);
|
|
|
|
rtlmode = pRtlGetThreadErrorMode();
|
|
|
|
ok(rtlmode == 0x20,
|
|
|
|
"RtlGetThreadErrorMode returned mode 0x%x, expected 0x20\n", mode);
|
|
|
|
|
|
|
|
ret = pSetThreadErrorMode(SEM_NOOPENFILEERRORBOX, NULL);
|
|
|
|
ok(ret, "SetThreadErrorMode failed\n");
|
|
|
|
mode = pGetThreadErrorMode();
|
|
|
|
ok(mode == SEM_NOOPENFILEERRORBOX,
|
|
|
|
"GetThreadErrorMode returned mode 0x%x, expected SEM_NOOPENFILEERRORBOX\n",
|
|
|
|
mode);
|
|
|
|
rtlmode = pRtlGetThreadErrorMode();
|
|
|
|
ok(rtlmode == 0x40,
|
|
|
|
"RtlGetThreadErrorMode returned mode 0x%x, expected 0x40\n", rtlmode);
|
|
|
|
|
|
|
|
for (mode = 1; mode; mode <<= 1)
|
|
|
|
{
|
|
|
|
ret = pSetThreadErrorMode(mode, NULL);
|
|
|
|
if (mode & (SEM_FAILCRITICALERRORS |
|
|
|
|
SEM_NOGPFAULTERRORBOX |
|
|
|
|
SEM_NOOPENFILEERRORBOX))
|
|
|
|
{
|
|
|
|
ok(ret,
|
|
|
|
"SetThreadErrorMode(0x%x,NULL) failed with error %d\n",
|
|
|
|
mode, GetLastError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD GLE = GetLastError();
|
|
|
|
ok(!ret,
|
|
|
|
"SetThreadErrorMode(0x%x,NULL) succeeded, expected failure\n",
|
|
|
|
mode);
|
|
|
|
ok(GLE == ERROR_INVALID_PARAMETER,
|
|
|
|
"SetThreadErrorMode(0x%x,NULL) failed with %d, "
|
|
|
|
"expected ERROR_INVALID_PARAMETER\n",
|
|
|
|
mode, GLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pSetThreadErrorMode(oldmode, NULL);
|
|
|
|
}
|
|
|
|
|
2015-09-01 16:14:54 +02:00
|
|
|
#if (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) || (defined(_MSC_VER) && defined(__i386__))
|
2010-06-17 10:17:15 +02:00
|
|
|
static inline void set_fpu_cw(WORD cw)
|
|
|
|
{
|
2015-09-01 16:14:54 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
__asm { fnclex }
|
|
|
|
__asm { fldcw [cw] }
|
|
|
|
#else
|
2010-06-17 10:17:15 +02:00
|
|
|
__asm__ volatile ("fnclex; fldcw %0" : : "m" (cw));
|
2015-09-01 16:14:54 +02:00
|
|
|
#endif
|
2010-06-17 10:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline WORD get_fpu_cw(void)
|
|
|
|
{
|
|
|
|
WORD cw = 0;
|
2015-09-01 16:14:54 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
__asm { fnstcw [cw] }
|
|
|
|
#else
|
2010-06-17 10:17:15 +02:00
|
|
|
__asm__ volatile ("fnstcw %0" : "=m" (cw));
|
2015-09-01 16:14:54 +02:00
|
|
|
#endif
|
2010-06-17 10:17:15 +02:00
|
|
|
return cw;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct fpu_thread_ctx
|
|
|
|
{
|
|
|
|
WORD cw;
|
|
|
|
HANDLE finished;
|
|
|
|
};
|
|
|
|
|
|
|
|
static DWORD WINAPI fpu_thread(void *param)
|
|
|
|
{
|
|
|
|
struct fpu_thread_ctx *ctx = param;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ctx->cw = get_fpu_cw();
|
|
|
|
|
|
|
|
ret = SetEvent(ctx->finished);
|
|
|
|
ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WORD get_thread_fpu_cw(void)
|
|
|
|
{
|
|
|
|
struct fpu_thread_ctx ctx;
|
|
|
|
DWORD tid, res;
|
|
|
|
HANDLE thread;
|
|
|
|
|
2013-10-21 10:02:45 +02:00
|
|
|
ctx.finished = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2010-06-17 10:17:15 +02:00
|
|
|
ok(!!ctx.finished, "Failed to create event, last error %#x.\n", GetLastError());
|
|
|
|
|
|
|
|
thread = CreateThread(NULL, 0, fpu_thread, &ctx, 0, &tid);
|
|
|
|
ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
|
|
|
|
|
|
|
|
res = WaitForSingleObject(ctx.finished, INFINITE);
|
|
|
|
ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
|
|
|
|
|
|
|
|
res = CloseHandle(ctx.finished);
|
|
|
|
ok(!!res, "Failed to close event handle, last error %#x.\n", GetLastError());
|
|
|
|
|
|
|
|
return ctx.cw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_thread_fpu_cw(void)
|
|
|
|
{
|
2010-06-22 11:19:02 +02:00
|
|
|
WORD initial_cw, cw;
|
2010-06-17 10:17:15 +02:00
|
|
|
|
|
|
|
initial_cw = get_fpu_cw();
|
2010-06-22 11:19:02 +02:00
|
|
|
ok(initial_cw == 0x27f, "Expected FPU control word 0x27f, got %#x.\n", initial_cw);
|
2010-06-17 10:17:15 +02:00
|
|
|
|
|
|
|
cw = get_thread_fpu_cw();
|
|
|
|
ok(cw == 0x27f, "Expected FPU control word 0x27f, got %#x.\n", cw);
|
|
|
|
|
|
|
|
set_fpu_cw(0xf60);
|
|
|
|
cw = get_fpu_cw();
|
|
|
|
ok(cw == 0xf60, "Expected FPU control word 0xf60, got %#x.\n", cw);
|
|
|
|
|
|
|
|
cw = get_thread_fpu_cw();
|
|
|
|
ok(cw == 0x27f, "Expected FPU control word 0x27f, got %#x.\n", cw);
|
|
|
|
|
|
|
|
cw = get_fpu_cw();
|
|
|
|
ok(cw == 0xf60, "Expected FPU control word 0xf60, got %#x.\n", cw);
|
|
|
|
|
|
|
|
set_fpu_cw(initial_cw);
|
|
|
|
cw = get_fpu_cw();
|
|
|
|
ok(cw == initial_cw, "Expected FPU control word %#x, got %#x.\n", initial_cw, cw);
|
|
|
|
}
|
2011-07-06 20:08:40 +02:00
|
|
|
#endif
|
2010-06-17 10:17:15 +02:00
|
|
|
|
2013-09-05 09:27:45 +02:00
|
|
|
static const char manifest_dep[] =
|
|
|
|
"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
|
|
|
|
"<assemblyIdentity version=\"1.2.3.4\" name=\"testdep1\" type=\"win32\" processorArchitecture=\"" ARCH "\"/>"
|
|
|
|
" <file name=\"testdep.dll\" />"
|
|
|
|
"</assembly>";
|
|
|
|
|
|
|
|
static const char manifest_main[] =
|
|
|
|
"<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
|
|
|
|
"<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\" />"
|
|
|
|
"<dependency>"
|
|
|
|
" <dependentAssembly>"
|
|
|
|
" <assemblyIdentity type=\"win32\" name=\"testdep1\" version=\"1.2.3.4\" processorArchitecture=\"" ARCH "\" />"
|
|
|
|
" </dependentAssembly>"
|
|
|
|
"</dependency>"
|
|
|
|
"</assembly>";
|
|
|
|
|
|
|
|
static void create_manifest_file(const char *filename, const char *manifest)
|
|
|
|
{
|
|
|
|
WCHAR path[MAX_PATH];
|
|
|
|
HANDLE file;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
|
|
|
|
file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
|
|
|
|
WriteFile(file, manifest, strlen(manifest), &size, NULL);
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HANDLE test_create(const char *file)
|
|
|
|
{
|
|
|
|
WCHAR path[MAX_PATH];
|
|
|
|
ACTCTXW actctx;
|
|
|
|
HANDLE handle;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, file, -1, path, MAX_PATH);
|
|
|
|
memset(&actctx, 0, sizeof(ACTCTXW));
|
|
|
|
actctx.cbSize = sizeof(ACTCTXW);
|
|
|
|
actctx.lpSource = path;
|
|
|
|
|
|
|
|
handle = pCreateActCtxW(&actctx);
|
|
|
|
ok(handle != INVALID_HANDLE_VALUE, "failed to create context, error %u\n", GetLastError());
|
|
|
|
|
|
|
|
ok(actctx.cbSize == sizeof(actctx), "cbSize=%d\n", actctx.cbSize);
|
|
|
|
ok(actctx.dwFlags == 0, "dwFlags=%d\n", actctx.dwFlags);
|
|
|
|
ok(actctx.lpSource == path, "lpSource=%p\n", actctx.lpSource);
|
|
|
|
ok(actctx.wProcessorArchitecture == 0, "wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
|
|
|
|
ok(actctx.wLangId == 0, "wLangId=%d\n", actctx.wLangId);
|
|
|
|
ok(actctx.lpAssemblyDirectory == NULL, "lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
|
|
|
|
ok(actctx.lpResourceName == NULL, "lpResourceName=%p\n", actctx.lpResourceName);
|
|
|
|
ok(actctx.lpApplicationName == NULL, "lpApplicationName=%p\n", actctx.lpApplicationName);
|
|
|
|
ok(actctx.hModule == NULL, "hModule=%p\n", actctx.hModule);
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_thread_actctx(void)
|
|
|
|
{
|
|
|
|
struct thread_actctx_param param;
|
|
|
|
HANDLE thread, handle, context;
|
|
|
|
ULONG_PTR cookie;
|
|
|
|
DWORD tid, ret;
|
|
|
|
BOOL b;
|
|
|
|
|
|
|
|
if (!pActivateActCtx)
|
|
|
|
{
|
|
|
|
win_skip("skipping activation context tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
create_manifest_file("testdep1.manifest", manifest_dep);
|
|
|
|
create_manifest_file("main.manifest", manifest_main);
|
|
|
|
|
|
|
|
context = test_create("main.manifest");
|
|
|
|
DeleteFileA("testdep1.manifest");
|
|
|
|
DeleteFileA("main.manifest");
|
|
|
|
|
|
|
|
handle = (void*)0xdeadbeef;
|
|
|
|
b = pGetCurrentActCtx(&handle);
|
2016-06-02 22:50:20 +02:00
|
|
|
ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
|
2013-09-05 09:27:45 +02:00
|
|
|
ok(handle == 0, "active context %p\n", handle);
|
|
|
|
|
2013-09-05 09:35:17 +02:00
|
|
|
/* without active context */
|
|
|
|
param.thread_context = (void*)0xdeadbeef;
|
|
|
|
param.handle = NULL;
|
|
|
|
thread = CreateThread(NULL, 0, thread_actctx_func, ¶m, 0, &tid);
|
|
|
|
ok(thread != NULL, "failed, got %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = WaitForSingleObject(thread, 1000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "wait timeout\n");
|
|
|
|
ok(param.thread_context == NULL, "got wrong thread context %p\n", param.thread_context);
|
|
|
|
CloseHandle(thread);
|
|
|
|
|
2013-09-05 09:27:45 +02:00
|
|
|
b = pActivateActCtx(context, &cookie);
|
|
|
|
ok(b, "activation failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
handle = 0;
|
|
|
|
b = pGetCurrentActCtx(&handle);
|
2016-06-02 22:50:20 +02:00
|
|
|
ok(b, "GetCurrentActCtx failed: %u\n", GetLastError());
|
2013-09-05 09:27:45 +02:00
|
|
|
ok(handle != 0, "no active context\n");
|
2014-06-22 04:29:05 +02:00
|
|
|
pReleaseActCtx(handle);
|
2013-09-05 09:27:45 +02:00
|
|
|
|
|
|
|
param.handle = NULL;
|
|
|
|
b = pGetCurrentActCtx(¶m.handle);
|
|
|
|
ok(b && param.handle != NULL, "failed to get context, %u\n", GetLastError());
|
|
|
|
|
|
|
|
param.thread_context = (void*)0xdeadbeef;
|
|
|
|
thread = CreateThread(NULL, 0, thread_actctx_func, ¶m, 0, &tid);
|
|
|
|
ok(thread != NULL, "failed, got %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = WaitForSingleObject(thread, 1000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "wait timeout\n");
|
|
|
|
ok(param.thread_context == context, "got wrong thread context %p, %p\n", param.thread_context, context);
|
2014-06-22 04:29:05 +02:00
|
|
|
pReleaseActCtx(param.thread_context);
|
2013-09-05 09:27:45 +02:00
|
|
|
CloseHandle(thread);
|
|
|
|
|
|
|
|
/* similar test for CreateRemoteThread() */
|
|
|
|
param.thread_context = (void*)0xdeadbeef;
|
|
|
|
thread = CreateRemoteThread(GetCurrentProcess(), NULL, 0, thread_actctx_func, ¶m, 0, &tid);
|
|
|
|
ok(thread != NULL, "failed, got %u\n", GetLastError());
|
|
|
|
|
|
|
|
ret = WaitForSingleObject(thread, 1000);
|
|
|
|
ok(ret == WAIT_OBJECT_0, "wait timeout\n");
|
|
|
|
ok(param.thread_context == context, "got wrong thread context %p, %p\n", param.thread_context, context);
|
2014-06-22 04:29:05 +02:00
|
|
|
pReleaseActCtx(param.thread_context);
|
2013-09-05 09:27:45 +02:00
|
|
|
CloseHandle(thread);
|
|
|
|
|
2014-06-22 04:29:05 +02:00
|
|
|
pReleaseActCtx(param.handle);
|
|
|
|
|
2013-09-05 09:27:45 +02:00
|
|
|
b = pDeactivateActCtx(0, cookie);
|
|
|
|
ok(b, "DeactivateActCtx failed: %u\n", GetLastError());
|
|
|
|
pReleaseActCtx(context);
|
|
|
|
}
|
|
|
|
|
2014-01-29 20:13:28 +01:00
|
|
|
|
|
|
|
static void WINAPI threadpool_workcallback(PTP_CALLBACK_INSTANCE instance, void *context, PTP_WORK work) {
|
|
|
|
int *foo = (int*)context;
|
|
|
|
|
|
|
|
(*foo)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void test_threadpool(void)
|
|
|
|
{
|
|
|
|
PTP_POOL pool;
|
|
|
|
PTP_WORK work;
|
|
|
|
int workcalled = 0;
|
|
|
|
|
|
|
|
if (!pCreateThreadpool) {
|
2015-07-03 02:00:31 +02:00
|
|
|
win_skip("thread pool apis not supported.\n");
|
|
|
|
return;
|
2014-01-29 20:13:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
work = pCreateThreadpoolWork(threadpool_workcallback, &workcalled, NULL);
|
|
|
|
ok (work != NULL, "Error %d in CreateThreadpoolWork\n", GetLastError());
|
|
|
|
pSubmitThreadpoolWork(work);
|
|
|
|
pWaitForThreadpoolWorkCallbacks(work, FALSE);
|
|
|
|
pCloseThreadpoolWork(work);
|
|
|
|
|
|
|
|
ok (workcalled == 1, "expected work to be called once, got %d\n", workcalled);
|
|
|
|
|
|
|
|
pool = pCreateThreadpool(NULL);
|
2015-07-03 02:00:31 +02:00
|
|
|
ok (pool != NULL, "CreateThreadpool failed\n");
|
2015-07-03 02:00:59 +02:00
|
|
|
pCloseThreadpool(pool);
|
2014-01-29 20:13:28 +01:00
|
|
|
}
|
|
|
|
|
2014-03-28 13:46:17 +01:00
|
|
|
static void test_reserved_tls(void)
|
|
|
|
{
|
|
|
|
void *val;
|
|
|
|
DWORD tls;
|
|
|
|
BOOL ret;
|
|
|
|
|
2014-03-31 14:31:01 +02:00
|
|
|
/* This seems to be a WinXP SP2+ feature. */
|
|
|
|
if(!pIsWow64Process) {
|
2014-03-28 13:46:17 +01:00
|
|
|
win_skip("Skipping reserved TLS slot on too old Windows.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = TlsGetValue(0);
|
|
|
|
ok(!val, "TlsGetValue(0) = %p\n", val);
|
|
|
|
|
|
|
|
/* Also make sure that there is a TLS allocated. */
|
|
|
|
tls = TlsAlloc();
|
|
|
|
ok(tls && tls != TLS_OUT_OF_INDEXES, "tls = %x\n", tls);
|
|
|
|
TlsSetValue(tls, (void*)1);
|
|
|
|
|
|
|
|
val = TlsGetValue(0);
|
|
|
|
ok(!val, "TlsGetValue(0) = %p\n", val);
|
|
|
|
|
|
|
|
TlsFree(tls);
|
|
|
|
|
|
|
|
/* The following is too ugly to be run by default */
|
|
|
|
if(0) {
|
|
|
|
/* Set TLS index 0 value and see that this works and doesn't cause problems
|
|
|
|
* for remaining tests. */
|
|
|
|
ret = TlsSetValue(0, (void*)1);
|
|
|
|
ok(ret, "TlsSetValue(0, 1) failed: %u\n", GetLastError());
|
|
|
|
|
|
|
|
val = TlsGetValue(0);
|
|
|
|
ok(val == (void*)1, "TlsGetValue(0) = %p\n", val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-20 08:55:21 +02:00
|
|
|
static void test_thread_info(void)
|
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
static const ULONG info_size[] =
|
|
|
|
{
|
|
|
|
sizeof(THREAD_BASIC_INFORMATION), /* ThreadBasicInformation */
|
|
|
|
sizeof(KERNEL_USER_TIMES), /* ThreadTimes */
|
|
|
|
sizeof(ULONG), /* ThreadPriority */
|
|
|
|
sizeof(ULONG), /* ThreadBasePriority */
|
|
|
|
sizeof(ULONG_PTR), /* ThreadAffinityMask */
|
|
|
|
sizeof(HANDLE), /* ThreadImpersonationToken */
|
|
|
|
sizeof(THREAD_DESCRIPTOR_INFORMATION), /* ThreadDescriptorTableEntry */
|
|
|
|
sizeof(BOOLEAN), /* ThreadEnableAlignmentFaultFixup */
|
|
|
|
0, /* ThreadEventPair_Reusable */
|
|
|
|
sizeof(ULONG_PTR), /* ThreadQuerySetWin32StartAddress */
|
|
|
|
sizeof(ULONG), /* ThreadZeroTlsCell */
|
|
|
|
sizeof(LARGE_INTEGER), /* ThreadPerformanceCount */
|
|
|
|
sizeof(ULONG), /* ThreadAmILastThread */
|
|
|
|
sizeof(ULONG), /* ThreadIdealProcessor */
|
|
|
|
sizeof(ULONG), /* ThreadPriorityBoost */
|
|
|
|
sizeof(ULONG_PTR), /* ThreadSetTlsArrayAddress */
|
|
|
|
sizeof(ULONG), /* ThreadIsIoPending */
|
|
|
|
sizeof(BOOLEAN), /* ThreadHideFromDebugger */
|
|
|
|
/* FIXME: Add remaining classes */
|
|
|
|
};
|
|
|
|
HANDLE thread;
|
2015-08-23 08:12:52 +02:00
|
|
|
ULONG i, status, ret_len;
|
2015-08-20 08:55:21 +02:00
|
|
|
|
|
|
|
if (!pOpenThread)
|
|
|
|
{
|
|
|
|
win_skip("OpenThread is not available on this platform\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pNtQueryInformationThread)
|
|
|
|
{
|
|
|
|
win_skip("NtQueryInformationThread is not available on this platform\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
thread = pOpenThread(THREAD_QUERY_LIMITED_INFORMATION, FALSE, GetCurrentThreadId());
|
|
|
|
if (!thread)
|
|
|
|
{
|
|
|
|
win_skip("THREAD_QUERY_LIMITED_INFORMATION is not supported on this platform\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(info_size)/sizeof(info_size[0]); i++)
|
|
|
|
{
|
2015-08-23 08:12:52 +02:00
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
if (i == ThreadDescriptorTableEntry)
|
|
|
|
{
|
|
|
|
CONTEXT ctx;
|
|
|
|
THREAD_DESCRIPTOR_INFORMATION *tdi = (void *)buf;
|
|
|
|
|
|
|
|
ctx.ContextFlags = CONTEXT_SEGMENTS;
|
|
|
|
GetThreadContext(GetCurrentThread(), &ctx);
|
|
|
|
tdi->Selector = ctx.SegDs;
|
|
|
|
}
|
|
|
|
#endif
|
2015-08-20 08:55:21 +02:00
|
|
|
ret_len = 0;
|
|
|
|
status = pNtQueryInformationThread(thread, i, buf, info_size[i], &ret_len);
|
|
|
|
if (status == STATUS_NOT_IMPLEMENTED) continue;
|
|
|
|
if (status == STATUS_INVALID_INFO_CLASS) continue;
|
|
|
|
if (status == STATUS_UNSUCCESSFUL) continue;
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case ThreadBasicInformation:
|
|
|
|
case ThreadAmILastThread:
|
|
|
|
case ThreadPriorityBoost:
|
2015-08-21 06:14:23 +02:00
|
|
|
ok(status == STATUS_SUCCESS, "for info %u expected STATUS_SUCCESS, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
|
2015-08-23 08:12:52 +02:00
|
|
|
#ifdef __i386__
|
|
|
|
case ThreadDescriptorTableEntry:
|
|
|
|
ok(status == STATUS_SUCCESS || broken(status == STATUS_ACCESS_DENIED) /* testbot VM is broken */,
|
|
|
|
"for info %u expected STATUS_SUCCESS, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2015-08-21 06:14:23 +02:00
|
|
|
case ThreadTimes:
|
2015-08-20 08:55:21 +02:00
|
|
|
todo_wine
|
|
|
|
ok(status == STATUS_SUCCESS, "for info %u expected STATUS_SUCCESS, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
|
2015-08-21 06:14:23 +02:00
|
|
|
case ThreadAffinityMask:
|
|
|
|
case ThreadQuerySetWin32StartAddress:
|
2015-08-20 08:55:21 +02:00
|
|
|
todo_wine
|
|
|
|
ok(status == STATUS_ACCESS_DENIED, "for info %u expected STATUS_ACCESS_DENIED, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ok(status == STATUS_ACCESS_DENIED, "for info %u expected STATUS_ACCESS_DENIED, got %08x (ret_len %u)\n", i, status, ret_len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(thread);
|
|
|
|
}
|
|
|
|
|
2013-09-05 09:27:45 +02:00
|
|
|
static void init_funcs(void)
|
|
|
|
{
|
2013-10-21 10:02:45 +02:00
|
|
|
HMODULE hKernel32 = GetModuleHandleA("kernel32.dll");
|
2015-08-20 08:55:21 +02:00
|
|
|
HMODULE ntdll = GetModuleHandleA("ntdll.dll");
|
2013-09-05 09:27:45 +02:00
|
|
|
|
|
|
|
/* Neither Cygwin nor mingW export OpenThread, so do a dynamic check
|
|
|
|
so that the compile passes */
|
|
|
|
|
|
|
|
#define X(f) p##f = (void*)GetProcAddress(hKernel32, #f)
|
|
|
|
X(GetThreadPriorityBoost);
|
|
|
|
X(OpenThread);
|
|
|
|
X(QueueUserWorkItem);
|
|
|
|
X(SetThreadIdealProcessor);
|
|
|
|
X(SetThreadPriorityBoost);
|
|
|
|
X(RegisterWaitForSingleObject);
|
|
|
|
X(UnregisterWait);
|
|
|
|
X(IsWow64Process);
|
|
|
|
X(SetThreadErrorMode);
|
|
|
|
X(GetThreadErrorMode);
|
|
|
|
X(ActivateActCtx);
|
|
|
|
X(CreateActCtxW);
|
|
|
|
X(DeactivateActCtx);
|
|
|
|
X(GetCurrentActCtx);
|
|
|
|
X(ReleaseActCtx);
|
2014-01-29 20:13:28 +01:00
|
|
|
|
|
|
|
X(CreateThreadpool);
|
2015-07-03 02:00:59 +02:00
|
|
|
X(CloseThreadpool);
|
2014-01-29 20:13:28 +01:00
|
|
|
X(CreateThreadpoolWork);
|
|
|
|
X(SubmitThreadpoolWork);
|
|
|
|
X(WaitForThreadpoolWorkCallbacks);
|
|
|
|
X(CloseThreadpoolWork);
|
2015-09-23 22:51:23 +02:00
|
|
|
|
|
|
|
X(GetThreadGroupAffinity);
|
|
|
|
X(SetThreadGroupAffinity);
|
2013-09-05 09:27:45 +02:00
|
|
|
#undef X
|
2015-08-20 08:55:21 +02:00
|
|
|
|
|
|
|
#define X(f) p##f = (void*)GetProcAddress(ntdll, #f)
|
|
|
|
if (ntdll)
|
|
|
|
{
|
|
|
|
X(NtQueryInformationThread);
|
|
|
|
X(RtlGetThreadErrorMode);
|
2015-09-23 22:51:23 +02:00
|
|
|
X(NtSetInformationThread);
|
2015-08-20 08:55:21 +02:00
|
|
|
}
|
|
|
|
#undef X
|
2013-09-05 09:27:45 +02:00
|
|
|
}
|
|
|
|
|
2002-04-02 21:37:15 +02:00
|
|
|
START_TEST(thread)
|
|
|
|
{
|
2007-01-03 14:22:02 +01:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
argc = winetest_get_mainargs( &argv );
|
2013-09-05 09:27:45 +02:00
|
|
|
|
|
|
|
init_funcs();
|
2010-02-03 14:33:38 +01:00
|
|
|
|
2007-01-03 14:22:02 +01:00
|
|
|
if (argc >= 3)
|
|
|
|
{
|
|
|
|
if (!strcmp(argv[2], "sleep"))
|
|
|
|
{
|
2007-02-19 16:45:54 +01:00
|
|
|
HANDLE hAddrEvents[2];
|
|
|
|
create_function_addr_events(hAddrEvents);
|
|
|
|
SetEvent(hAddrEvents[0]);
|
|
|
|
SetEvent(hAddrEvents[1]);
|
2007-01-03 14:22:02 +01:00
|
|
|
Sleep(5000); /* spawned process runs for at most 5 seconds */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
HANDLE hThread;
|
2008-09-08 08:19:45 +02:00
|
|
|
DWORD tid;
|
|
|
|
hThread = CreateThread(NULL, 0, threadFunc2, NULL, 0, &tid);
|
2007-01-03 14:22:02 +01:00
|
|
|
ok(hThread != NULL, "CreateThread failed, error %u\n",
|
|
|
|
GetLastError());
|
|
|
|
ok(WaitForSingleObject(hThread, 200) == WAIT_OBJECT_0,
|
|
|
|
"Thread did not exit in time\n");
|
|
|
|
if (hThread == NULL) break;
|
|
|
|
CloseHandle(hThread);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-20 08:55:21 +02:00
|
|
|
test_thread_info();
|
2014-03-28 13:46:17 +01:00
|
|
|
test_reserved_tls();
|
2007-01-03 14:22:02 +01:00
|
|
|
test_CreateRemoteThread();
|
2002-11-30 20:03:19 +01:00
|
|
|
test_CreateThread_basic();
|
|
|
|
test_CreateThread_suspended();
|
|
|
|
test_SuspendThread();
|
|
|
|
test_TerminateThread();
|
|
|
|
test_CreateThread_stack();
|
|
|
|
test_thread_priority();
|
|
|
|
test_GetThreadTimes();
|
|
|
|
test_thread_processor();
|
2005-10-28 11:40:09 +02:00
|
|
|
test_GetThreadExitCode();
|
2005-11-02 21:54:12 +01:00
|
|
|
#ifdef __i386__
|
|
|
|
test_SetThreadContext();
|
|
|
|
#endif
|
2006-03-21 14:43:06 +01:00
|
|
|
test_QueueUserWorkItem();
|
2008-01-01 23:37:34 +01:00
|
|
|
test_RegisterWaitForSingleObject();
|
2008-06-21 01:10:31 +02:00
|
|
|
test_TLS();
|
2010-02-03 14:33:38 +01:00
|
|
|
test_ThreadErrorMode();
|
2015-09-01 16:14:54 +02:00
|
|
|
#if (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) || (defined(_MSC_VER) && defined(__i386__))
|
2010-06-17 10:17:15 +02:00
|
|
|
test_thread_fpu_cw();
|
|
|
|
#endif
|
2013-09-05 09:27:45 +02:00
|
|
|
test_thread_actctx();
|
2014-01-29 20:13:28 +01:00
|
|
|
|
|
|
|
test_threadpool();
|
2002-04-02 21:37:15 +02:00
|
|
|
}
|