|
Packit Service |
fa4841 |
/**
|
|
Packit Service |
fa4841 |
* WinPR: Windows Portable Runtime
|
|
Packit Service |
fa4841 |
* Process Thread Functions
|
|
Packit Service |
fa4841 |
*
|
|
Packit Service |
fa4841 |
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
Packit Service |
fa4841 |
*
|
|
Packit Service |
fa4841 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit Service |
fa4841 |
* you may not use this file except in compliance with the License.
|
|
Packit Service |
fa4841 |
* You may obtain a copy of the License at
|
|
Packit Service |
fa4841 |
*
|
|
Packit Service |
fa4841 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit Service |
fa4841 |
*
|
|
Packit Service |
fa4841 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit Service |
fa4841 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit Service |
fa4841 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit Service |
fa4841 |
* See the License for the specific language governing permissions and
|
|
Packit Service |
fa4841 |
* limitations under the License.
|
|
Packit Service |
fa4841 |
*/
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#ifndef WINPR_THREAD_H
|
|
Packit Service |
fa4841 |
#define WINPR_THREAD_H
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#include <winpr/winpr.h>
|
|
Packit Service |
fa4841 |
#include <winpr/wtypes.h>
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#include <winpr/spec.h>
|
|
Packit Service |
fa4841 |
#include <winpr/handle.h>
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#ifdef __cplusplus
|
|
Packit Service |
b1ea74 |
extern "C"
|
|
Packit Service |
b1ea74 |
{
|
|
Packit Service |
fa4841 |
#endif
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#ifndef _WIN32
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
typedef struct _STARTUPINFOA
|
|
Packit Service |
b1ea74 |
{
|
|
Packit Service |
b1ea74 |
DWORD cb;
|
|
Packit Service |
b1ea74 |
LPSTR lpReserved;
|
|
Packit Service |
b1ea74 |
LPSTR lpDesktop;
|
|
Packit Service |
b1ea74 |
LPSTR lpTitle;
|
|
Packit Service |
b1ea74 |
DWORD dwX;
|
|
Packit Service |
b1ea74 |
DWORD dwY;
|
|
Packit Service |
b1ea74 |
DWORD dwXSize;
|
|
Packit Service |
b1ea74 |
DWORD dwYSize;
|
|
Packit Service |
b1ea74 |
DWORD dwXCountChars;
|
|
Packit Service |
b1ea74 |
DWORD dwYCountChars;
|
|
Packit Service |
b1ea74 |
DWORD dwFillAttribute;
|
|
Packit Service |
b1ea74 |
DWORD dwFlags;
|
|
Packit Service |
b1ea74 |
WORD wShowWindow;
|
|
Packit Service |
b1ea74 |
WORD cbReserved2;
|
|
Packit Service |
b1ea74 |
LPBYTE lpReserved2;
|
|
Packit Service |
b1ea74 |
HANDLE hStdInput;
|
|
Packit Service |
b1ea74 |
HANDLE hStdOutput;
|
|
Packit Service |
b1ea74 |
HANDLE hStdError;
|
|
Packit Service |
b1ea74 |
} STARTUPINFOA, *LPSTARTUPINFOA;
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
typedef struct _STARTUPINFOW
|
|
Packit Service |
b1ea74 |
{
|
|
Packit Service |
b1ea74 |
DWORD cb;
|
|
Packit Service |
b1ea74 |
LPWSTR lpReserved;
|
|
Packit Service |
b1ea74 |
LPWSTR lpDesktop;
|
|
Packit Service |
b1ea74 |
LPWSTR lpTitle;
|
|
Packit Service |
b1ea74 |
DWORD dwX;
|
|
Packit Service |
b1ea74 |
DWORD dwY;
|
|
Packit Service |
b1ea74 |
DWORD dwXSize;
|
|
Packit Service |
b1ea74 |
DWORD dwYSize;
|
|
Packit Service |
b1ea74 |
DWORD dwXCountChars;
|
|
Packit Service |
b1ea74 |
DWORD dwYCountChars;
|
|
Packit Service |
b1ea74 |
DWORD dwFillAttribute;
|
|
Packit Service |
b1ea74 |
DWORD dwFlags;
|
|
Packit Service |
b1ea74 |
WORD wShowWindow;
|
|
Packit Service |
b1ea74 |
WORD cbReserved2;
|
|
Packit Service |
b1ea74 |
LPBYTE lpReserved2;
|
|
Packit Service |
b1ea74 |
HANDLE hStdInput;
|
|
Packit Service |
b1ea74 |
HANDLE hStdOutput;
|
|
Packit Service |
b1ea74 |
HANDLE hStdError;
|
|
Packit Service |
b1ea74 |
} STARTUPINFOW, *LPSTARTUPINFOW;
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#ifdef UNICODE
|
|
Packit Service |
b1ea74 |
typedef STARTUPINFOW STARTUPINFO;
|
|
Packit Service |
b1ea74 |
typedef LPSTARTUPINFOW LPSTARTUPINFO;
|
|
Packit Service |
fa4841 |
#else
|
|
Packit Service |
b1ea74 |
typedef STARTUPINFOA STARTUPINFO;
|
|
Packit Service |
b1ea74 |
typedef LPSTARTUPINFOA LPSTARTUPINFO;
|
|
Packit Service |
fa4841 |
#endif
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
#define STARTF_USESHOWWINDOW 0x00000001
|
|
Packit Service |
b1ea74 |
#define STARTF_USESIZE 0x00000002
|
|
Packit Service |
b1ea74 |
#define STARTF_USEPOSITION 0x00000004
|
|
Packit Service |
b1ea74 |
#define STARTF_USECOUNTCHARS 0x00000008
|
|
Packit Service |
b1ea74 |
#define STARTF_USEFILLATTRIBUTE 0x00000010
|
|
Packit Service |
b1ea74 |
#define STARTF_RUNFULLSCREEN 0x00000020
|
|
Packit Service |
b1ea74 |
#define STARTF_FORCEONFEEDBACK 0x00000040
|
|
Packit Service |
b1ea74 |
#define STARTF_FORCEOFFFEEDBACK 0x00000080
|
|
Packit Service |
b1ea74 |
#define STARTF_USESTDHANDLES 0x00000100
|
|
Packit Service |
b1ea74 |
#define STARTF_USEHOTKEY 0x00000200
|
|
Packit Service |
b1ea74 |
#define STARTF_TITLEISLINKNAME 0x00000800
|
|
Packit Service |
b1ea74 |
#define STARTF_TITLEISAPPID 0x00001000
|
|
Packit Service |
b1ea74 |
#define STARTF_PREVENTPINNING 0x00002000
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
/* Process */
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
#define LOGON_WITH_PROFILE 0x00000001
|
|
Packit Service |
b1ea74 |
#define LOGON_NETCREDENTIALS_ONLY 0x00000002
|
|
Packit Service |
b1ea74 |
#define LOGON_ZERO_PASSWORD_BUFFER 0x80000000
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine,
|
|
Packit Service |
b1ea74 |
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
|
Packit Service |
b1ea74 |
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
|
|
Packit Service |
b1ea74 |
DWORD dwCreationFlags, LPVOID lpEnvironment,
|
|
Packit Service |
b1ea74 |
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo,
|
|
Packit Service |
b1ea74 |
LPPROCESS_INFORMATION lpProcessInformation);
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
|
|
Packit Service |
b1ea74 |
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
|
Packit Service |
b1ea74 |
LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
|
|
Packit Service |
b1ea74 |
DWORD dwCreationFlags, LPVOID lpEnvironment,
|
|
Packit Service |
b1ea74 |
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo,
|
|
Packit Service |
b1ea74 |
LPPROCESS_INFORMATION lpProcessInformation);
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL CreateProcessAsUserA(HANDLE hToken, LPCSTR lpApplicationName,
|
|
Packit Service |
b1ea74 |
LPSTR lpCommandLine,
|
|
Packit Service |
b1ea74 |
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
|
Packit Service |
b1ea74 |
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
|
Packit Service |
b1ea74 |
BOOL bInheritHandles, DWORD dwCreationFlags,
|
|
Packit Service |
b1ea74 |
LPVOID lpEnvironment, LPCSTR lpCurrentDirectory,
|
|
Packit Service |
b1ea74 |
LPSTARTUPINFOA lpStartupInfo,
|
|
Packit Service |
b1ea74 |
LPPROCESS_INFORMATION lpProcessInformation);
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL CreateProcessAsUserW(HANDLE hToken, LPCWSTR lpApplicationName,
|
|
Packit Service |
b1ea74 |
LPWSTR lpCommandLine,
|
|
Packit Service |
b1ea74 |
LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
|
Packit Service |
b1ea74 |
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
|
Packit Service |
b1ea74 |
BOOL bInheritHandles, DWORD dwCreationFlags,
|
|
Packit Service |
b1ea74 |
LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory,
|
|
Packit Service |
b1ea74 |
LPSTARTUPINFOW lpStartupInfo,
|
|
Packit Service |
b1ea74 |
LPPROCESS_INFORMATION lpProcessInformation);
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL CreateProcessWithLogonA(LPCSTR lpUsername, LPCSTR lpDomain, LPCSTR lpPassword,
|
|
Packit Service |
b1ea74 |
DWORD dwLogonFlags, LPCSTR lpApplicationName,
|
|
Packit Service |
b1ea74 |
LPSTR lpCommandLine, DWORD dwCreationFlags,
|
|
Packit Service |
b1ea74 |
LPVOID lpEnvironment, LPCSTR lpCurrentDirectory,
|
|
Packit Service |
b1ea74 |
LPSTARTUPINFOA lpStartupInfo,
|
|
Packit Service |
b1ea74 |
LPPROCESS_INFORMATION lpProcessInformation);
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL CreateProcessWithLogonW(LPCWSTR lpUsername, LPCWSTR lpDomain, LPCWSTR lpPassword,
|
|
Packit Service |
b1ea74 |
DWORD dwLogonFlags, LPCWSTR lpApplicationName,
|
|
Packit Service |
b1ea74 |
LPWSTR lpCommandLine, DWORD dwCreationFlags,
|
|
Packit Service |
b1ea74 |
LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory,
|
|
Packit Service |
b1ea74 |
LPSTARTUPINFOW lpStartupInfo,
|
|
Packit Service |
b1ea74 |
LPPROCESS_INFORMATION lpProcessInformation);
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL CreateProcessWithTokenA(HANDLE hToken, DWORD dwLogonFlags,
|
|
Packit Service |
b1ea74 |
LPCSTR lpApplicationName, LPSTR lpCommandLine,
|
|
Packit Service |
b1ea74 |
DWORD dwCreationFlags, LPVOID lpEnvironment,
|
|
Packit Service |
b1ea74 |
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo,
|
|
Packit Service |
b1ea74 |
LPPROCESS_INFORMATION lpProcessInformation);
|
|
Packit Service |
b1ea74 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL CreateProcessWithTokenW(HANDLE hToken, DWORD dwLogonFlags,
|
|
Packit Service |
b1ea74 |
LPCWSTR lpApplicationName, LPWSTR lpCommandLine,
|
|
Packit Service |
b1ea74 |
DWORD dwCreationFlags, LPVOID lpEnvironment,
|
|
Packit Service |
b1ea74 |
LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo,
|
|
Packit Service |
b1ea74 |
LPPROCESS_INFORMATION lpProcessInformation);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#ifdef UNICODE
|
|
Packit Service |
b1ea74 |
#define CreateProcess CreateProcessW
|
|
Packit Service |
b1ea74 |
#define CreateProcessAsUser CreateProcessAsUserW
|
|
Packit Service |
b1ea74 |
#define CreateProcessWithLogon CreateProcessWithLogonW
|
|
Packit Service |
b1ea74 |
#define CreateProcessWithToken CreateProcessWithTokenW
|
|
Packit Service |
fa4841 |
#else
|
|
Packit Service |
b1ea74 |
#define CreateProcess CreateProcessA
|
|
Packit Service |
b1ea74 |
#define CreateProcessAsUser CreateProcessAsUserA
|
|
Packit Service |
b1ea74 |
#define CreateProcessWithLogon CreateProcessWithLogonA
|
|
Packit Service |
b1ea74 |
#define CreateProcessWithToken CreateProcessWithTokenA
|
|
Packit Service |
fa4841 |
#endif
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
DECLSPEC_NORETURN WINPR_API VOID ExitProcess(UINT uExitCode);
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API HANDLE _GetCurrentProcess(void);
|
|
Packit Service |
b1ea74 |
WINPR_API DWORD GetCurrentProcessId(void);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
/* Process Argument Vector Parsing */
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API LPWSTR* CommandLineToArgvW(LPCWSTR lpCmdLine, int* pNumArgs);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#ifdef UNICODE
|
|
Packit Service |
b1ea74 |
#define CommandLineToArgv CommandLineToArgvW
|
|
Packit Service |
fa4841 |
#else
|
|
Packit Service |
b1ea74 |
#define CommandLineToArgv CommandLineToArgvA
|
|
Packit Service |
fa4841 |
#endif
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
/* Thread */
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
#define CREATE_SUSPENDED 0x00000004
|
|
Packit Service |
b1ea74 |
#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize,
|
|
Packit Service |
b1ea74 |
LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter,
|
|
Packit Service |
b1ea74 |
DWORD dwCreationFlags, LPDWORD lpThreadId);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
|
Packit Service |
b1ea74 |
SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
|
|
Packit Service |
b1ea74 |
LPVOID lpParameter, DWORD dwCreationFlags,
|
|
Packit Service |
b1ea74 |
LPDWORD lpThreadId);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API DECLSPEC_NORETURN VOID ExitThread(DWORD dwExitCode);
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API HANDLE _GetCurrentThread(void);
|
|
Packit Service |
b1ea74 |
WINPR_API DWORD GetCurrentThreadId(void);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API DWORD ResumeThread(HANDLE hThread);
|
|
Packit Service |
b1ea74 |
WINPR_API DWORD SuspendThread(HANDLE hThread);
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL SwitchToThread(void);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
/* Processor */
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API DWORD GetCurrentProcessorNumber(void);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
/* Thread-Local Storage */
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
#define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API DWORD TlsAlloc(void);
|
|
Packit Service |
b1ea74 |
WINPR_API LPVOID TlsGetValue(DWORD dwTlsIndex);
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue);
|
|
Packit Service |
b1ea74 |
WINPR_API BOOL TlsFree(DWORD dwTlsIndex);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#else
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
/*
|
|
Packit Service |
fa4841 |
* GetCurrentProcess / GetCurrentThread cause a conflict on Mac OS X
|
|
Packit Service |
fa4841 |
*/
|
|
Packit Service |
b1ea74 |
#define _GetCurrentProcess GetCurrentProcess
|
|
Packit Service |
b1ea74 |
#define _GetCurrentThread GetCurrentThread
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#endif
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
/* CommandLineToArgvA is not present in the original Windows API, WinPR always exports it */
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
b1ea74 |
WINPR_API LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs);
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#if defined(WITH_DEBUG_THREADS)
|
|
Packit Service |
b1ea74 |
WINPR_API VOID DumpThreadHandles(void);
|
|
Packit Service |
fa4841 |
#endif
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#ifdef __cplusplus
|
|
Packit Service |
fa4841 |
}
|
|
Packit Service |
fa4841 |
#endif
|
|
Packit Service |
fa4841 |
|
|
Packit Service |
fa4841 |
#endif /* WINPR_THREAD_H */
|