• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file is part of the mingw-w64 runtime package.
3  * No warranty is given; refer to the file DISCLAIMER within this package.
4  */
5 #ifndef _PROCESSTHREADSAPI_H_
6 #define _PROCESSTHREADSAPI_H_
7 
8 #include <apiset.h>
9 #include <apisetcconv.h>
10 #include <minwindef.h>
11 #include <minwinbase.h>
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #ifndef FLS_OUT_OF_INDEXES
18 #define FLS_OUT_OF_INDEXES ((DWORD)0xffffffff)
19 #endif
20 
21 #define TLS_OUT_OF_INDEXES ((DWORD)0xffffffff)
22 
23 #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) || defined(WINSTORECOMPAT)
24 WINBASEAPI WINBOOL WINAPI TerminateProcess (HANDLE hProcess, UINT uExitCode);
25 #endif
26 #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) || _WIN32_WINNT >= _WIN32_WINNT_WIN10
27   WINBASEAPI HANDLE WINAPI OpenProcess (DWORD dwDesiredAccess, WINBOOL bInheritHandle, DWORD dwProcessId);
28 
29   WINBASEAPI DWORD WINAPI QueueUserAPC (PAPCFUNC pfnAPC, HANDLE hThread, ULONG_PTR dwData);
30   WINBASEAPI WINBOOL WINAPI GetProcessTimes (HANDLE hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime);
31   WINBASEAPI DECLSPEC_NORETURN VOID WINAPI ExitProcess (UINT uExitCode);
32   WINBASEAPI WINBOOL WINAPI GetExitCodeProcess (HANDLE hProcess, LPDWORD lpExitCode);
33   WINBASEAPI WINBOOL WINAPI SwitchToThread (VOID);
34   WINBASEAPI HANDLE WINAPI OpenThread (DWORD dwDesiredAccess, WINBOOL bInheritHandle, DWORD dwThreadId);
35   WINBASEAPI WINBOOL WINAPI SetThreadPriorityBoost (HANDLE hThread, WINBOOL bDisablePriorityBoost);
36   WINBASEAPI WINBOOL WINAPI GetThreadPriorityBoost (HANDLE hThread, PBOOL pDisablePriorityBoost);
37   WINADVAPI WINBOOL APIENTRY SetThreadToken (PHANDLE Thread, HANDLE Token);
38   WINADVAPI WINBOOL WINAPI OpenProcessToken (HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);
39   WINADVAPI WINBOOL WINAPI OpenThreadToken (HANDLE ThreadHandle, DWORD DesiredAccess, WINBOOL OpenAsSelf, PHANDLE TokenHandle);
40   WINBASEAPI WINBOOL WINAPI SetPriorityClass (HANDLE hProcess, DWORD dwPriorityClass);
41   WINBASEAPI DWORD WINAPI GetPriorityClass (HANDLE hProcess);
42   WINBASEAPI DWORD WINAPI GetProcessId (HANDLE Process);
43   WINBASEAPI DWORD WINAPI GetThreadId (HANDLE Thread);
44   WINBASEAPI WINBOOL WINAPI GetThreadContext (HANDLE hThread, LPCONTEXT lpContext);
45   WINBASEAPI WINBOOL WINAPI FlushInstructionCache (HANDLE hProcess, LPCVOID lpBaseAddress, SIZE_T dwSize);
46   WINBASEAPI WINBOOL WINAPI GetThreadTimes (HANDLE hThread, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime);
47   WINBASEAPI DWORD WINAPI GetCurrentProcessorNumber (VOID);
48 
49 #endif
50 
51 #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
52 
53   typedef struct _PROCESS_INFORMATION {
54     HANDLE hProcess;
55     HANDLE hThread;
56     DWORD dwProcessId;
57     DWORD dwThreadId;
58   } PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION;
59 
60   typedef struct _PROC_THREAD_ATTRIBUTE_LIST *PPROC_THREAD_ATTRIBUTE_LIST, *LPPROC_THREAD_ATTRIBUTE_LIST;
61 
62   typedef struct _STARTUPINFOA {
63     DWORD cb;
64     LPSTR lpReserved;
65     LPSTR lpDesktop;
66     LPSTR lpTitle;
67     DWORD dwX;
68     DWORD dwY;
69     DWORD dwXSize;
70     DWORD dwYSize;
71     DWORD dwXCountChars;
72     DWORD dwYCountChars;
73     DWORD dwFillAttribute;
74     DWORD dwFlags;
75     WORD wShowWindow;
76     WORD cbReserved2;
77     LPBYTE lpReserved2;
78     HANDLE hStdInput;
79     HANDLE hStdOutput;
80     HANDLE hStdError;
81   } STARTUPINFOA, *LPSTARTUPINFOA;
82 
83   typedef struct _STARTUPINFOW {
84     DWORD cb;
85     LPWSTR lpReserved;
86     LPWSTR lpDesktop;
87     LPWSTR lpTitle;
88     DWORD dwX;
89     DWORD dwY;
90     DWORD dwXSize;
91     DWORD dwYSize;
92     DWORD dwXCountChars;
93     DWORD dwYCountChars;
94     DWORD dwFillAttribute;
95     DWORD dwFlags;
96     WORD wShowWindow;
97     WORD cbReserved2;
98     LPBYTE lpReserved2;
99     HANDLE hStdInput;
100     HANDLE hStdOutput;
101     HANDLE hStdError;
102   } STARTUPINFOW, *LPSTARTUPINFOW;
103 
104   __MINGW_TYPEDEF_AW(STARTUPINFO)
105   __MINGW_TYPEDEF_AW(LPSTARTUPINFO)
106 
107   WINBASEAPI HANDLE WINAPI CreateRemoteThread (HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
108   WINBASEAPI WINBOOL WINAPI TerminateThread (HANDLE hThread, DWORD dwExitCode);
109   WINBASEAPI WINBOOL WINAPI SetProcessShutdownParameters (DWORD dwLevel, DWORD dwFlags);
110   WINBASEAPI DWORD WINAPI GetProcessVersion (DWORD ProcessId);
111   WINBASEAPI VOID WINAPI GetStartupInfoW (LPSTARTUPINFOW lpStartupInfo);
112   WINBASEAPI WINBOOL WINAPI SetThreadStackGuarantee (PULONG StackSizeInBytes);
113   WINBASEAPI WINBOOL WINAPI ProcessIdToSessionId (DWORD dwProcessId, DWORD *pSessionId);
114   WINBASEAPI HANDLE WINAPI CreateRemoteThreadEx (HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, LPDWORD lpThreadId);
115   WINBASEAPI WINBOOL WINAPI SetThreadContext (HANDLE hThread, CONST CONTEXT *lpContext);
116   WINBASEAPI WINBOOL WINAPI GetProcessHandleCount (HANDLE hProcess, PDWORD pdwHandleCount);
117 
118 #ifdef UNICODE
119 #define GetStartupInfo GetStartupInfoW
120 #endif
121 
122 #ifndef _APISET_EXPORTS_FILTER
123   WINBASEAPI WINBOOL WINAPI CreateProcessA (LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, WINBOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation);
124   WINBASEAPI WINBOOL WINAPI CreateProcessW (LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, WINBOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation);
125 #define CreateProcess __MINGW_NAME_AW(CreateProcess)
126 #endif
127 
128 #ifndef _APISET_EXPORTS_FILTER
129   WINADVAPI WINBOOL WINAPI CreateProcessAsUserW (HANDLE hToken, LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, WINBOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation);
130 
131 #ifdef UNICODE
132 #define CreateProcessAsUser CreateProcessAsUserW
133 #endif
134 #endif
135 
136 #if _WIN32_WINNT >= 0x0600
137 #define PROCESS_AFFINITY_ENABLE_AUTO_UPDATE __MSABI_LONG(0x1U)
138 #define PROC_THREAD_ATTRIBUTE_REPLACE_VALUE 0x00000001
139 
140   WINBASEAPI DWORD WINAPI GetProcessIdOfThread (HANDLE Thread);
141   WINBASEAPI WINBOOL WINAPI InitializeProcThreadAttributeList (LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwAttributeCount, DWORD dwFlags, PSIZE_T lpSize);
142   WINBASEAPI VOID WINAPI DeleteProcThreadAttributeList (LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList);
143   WINBASEAPI WINBOOL WINAPI SetProcessAffinityUpdateMode (HANDLE hProcess, DWORD dwFlags);
144   WINBASEAPI WINBOOL WINAPI QueryProcessAffinityUpdateMode (HANDLE hProcess, LPDWORD lpdwFlags);
145   WINBASEAPI WINBOOL WINAPI UpdateProcThreadAttribute (LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwFlags, DWORD_PTR Attribute, PVOID lpValue, SIZE_T cbSize, PVOID lpPreviousValue, PSIZE_T lpReturnSize);
146 #endif
147 #if _WIN32_WINNT >= 0x0601
148   WINBASEAPI WINBOOL WINAPI GetThreadIdealProcessorEx (HANDLE hThread, PPROCESSOR_NUMBER lpIdealProcessor);
149   WINBASEAPI VOID WINAPI GetCurrentProcessorNumberEx (PPROCESSOR_NUMBER ProcNumber);
150 #endif
151 #if _WIN32_WINNT >= 0x0602
152   WINBASEAPI VOID WINAPI GetCurrentThreadStackLimits (PULONG_PTR LowLimit, PULONG_PTR HighLimit);
153   WINBASEAPI WINBOOL WINAPI SetProcessMitigationPolicy (PROCESS_MITIGATION_POLICY MitigationPolicy, PVOID lpBuffer, SIZE_T dwLength);
154   WINBASEAPI WINBOOL WINAPI GetProcessMitigationPolicy (HANDLE hProcess, PROCESS_MITIGATION_POLICY MitigationPolicy, PVOID lpBuffer, SIZE_T dwLength);
155 
GetCurrentProcessToken(VOID)156   FORCEINLINE HANDLE GetCurrentProcessToken (VOID)
157   {
158     return (HANDLE)(LONG_PTR) (-4);
159   }
GetCurrentThreadToken(VOID)160   FORCEINLINE HANDLE GetCurrentThreadToken (VOID)
161   {
162     return (HANDLE)(LONG_PTR) (-5);
163   }
GetCurrentThreadEffectiveToken(VOID)164   FORCEINLINE HANDLE GetCurrentThreadEffectiveToken (VOID)
165   {
166     return (HANDLE)(LONG_PTR) (-6);
167   }
168 
169   typedef struct _MEMORY_PRIORITY_INFORMATION {
170     ULONG MemoryPriority;
171   } MEMORY_PRIORITY_INFORMATION, *PMEMORY_PRIORITY_INFORMATION;
172 #endif
173 
174 #define MEMORY_PRIORITY_VERY_LOW      1
175 #define MEMORY_PRIORITY_LOW           2
176 #define MEMORY_PRIORITY_MEDIUM        3
177 #define MEMORY_PRIORITY_BELOW_NORMAL  4
178 #define MEMORY_PRIORITY_NORMAL        5
179 
180 #endif
181 
182 #if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_APP)
183   WINBASEAPI HANDLE WINAPI GetCurrentProcess (VOID);
184   WINBASEAPI DWORD WINAPI GetCurrentProcessId (VOID);
185   WINBASEAPI HANDLE WINAPI GetCurrentThread (VOID);
186   WINBASEAPI DWORD WINAPI GetCurrentThreadId (VOID);
187   WINBOOL WINAPI IsProcessorFeaturePresent (DWORD ProcessorFeature);
188 #if _WIN32_WINNT >= 0x0600
189   WINBASEAPI VOID WINAPI FlushProcessWriteBuffers (VOID);
190 #endif
191   WINBASEAPI HANDLE WINAPI CreateThread (LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
192   WINBASEAPI WINBOOL WINAPI SetThreadPriority (HANDLE hThread, int nPriority);
193   WINBASEAPI int WINAPI GetThreadPriority (HANDLE hThread);
194   WINBASEAPI DECLSPEC_NORETURN VOID WINAPI ExitThread (DWORD dwExitCode);
195   WINBASEAPI WINBOOL WINAPI GetExitCodeThread (HANDLE hThread, LPDWORD lpExitCode);
196 #if _WIN32_WINNT >= 0x0A00
197   WINBASEAPI DWORD WINAPI QueueUserAPC (PAPCFUNC pfnAPC, HANDLE hThread, ULONG_PTR dwData);
198   WINBASEAPI WINBOOL WINAPI SwitchToThread (VOID);
199 #endif
200   WINBASEAPI DWORD WINAPI SuspendThread (HANDLE hThread);
201   WINBASEAPI DWORD WINAPI ResumeThread (HANDLE hThread);
202   WINBASEAPI DWORD WINAPI TlsAlloc (VOID);
203   WINBASEAPI LPVOID WINAPI TlsGetValue (DWORD dwTlsIndex);
204   WINBASEAPI WINBOOL WINAPI TlsSetValue (DWORD dwTlsIndex, LPVOID lpTlsValue);
205   WINBASEAPI WINBOOL WINAPI TlsFree (DWORD dwTlsIndex);
206 #if _WIN32_WINNT >= 0x0601
207   WINBASEAPI WINBOOL WINAPI SetThreadIdealProcessorEx (HANDLE hThread, PPROCESSOR_NUMBER lpIdealProcessor, PPROCESSOR_NUMBER lpPreviousIdealProcessor);
208 #endif
209 
210 #endif
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 #endif
216