kernel32: Add ACTCTX field limit checks to CreateActCtxA().
[wine.git] / dlls / kernel32 / process.c
blobd56118a0fe387fa631e89512eff06896154dd362
1 /*
2 * Win32 processes
4 * Copyright 1996, 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <ctype.h>
23 #include <errno.h>
24 #include <signal.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <time.h>
29 #include "ntstatus.h"
30 #define WIN32_NO_STATUS
31 #include "winternl.h"
32 #include "winbase.h"
33 #include "winnls.h"
34 #include "wincon.h"
35 #include "kernel_private.h"
36 #include "psapi.h"
37 #include "ddk/wdm.h"
38 #include "wine/asm.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(process);
43 static const struct _KUSER_SHARED_DATA *user_shared_data = (struct _KUSER_SHARED_DATA *)0x7ffe0000;
45 typedef struct
47 LPSTR lpEnvAddress;
48 LPSTR lpCmdLine;
49 LPSTR lpCmdShow;
50 DWORD dwReserved;
51 } LOADPARMS32;
53 SYSTEM_BASIC_INFORMATION system_info = { 0 };
55 /* Process flags */
56 #define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
57 #define PDB32_WIN16_PROC 0x0008 /* Win16 process */
58 #define PDB32_DOS_PROC 0x0010 /* Dos process */
59 #define PDB32_CONSOLE_PROC 0x0020 /* Console process */
60 #define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
61 #define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
64 /***********************************************************************
65 * wait_input_idle
67 * Wrapper to call WaitForInputIdle USER function
69 typedef DWORD (WINAPI *WaitForInputIdle_ptr)( HANDLE hProcess, DWORD dwTimeOut );
71 static DWORD wait_input_idle( HANDLE process, DWORD timeout )
73 HMODULE mod = GetModuleHandleA( "user32.dll" );
74 if (mod)
76 WaitForInputIdle_ptr ptr = (WaitForInputIdle_ptr)GetProcAddress( mod, "WaitForInputIdle" );
77 if (ptr) return ptr( process, timeout );
79 return 0;
83 /***********************************************************************
84 * WinExec (KERNEL32.@)
86 UINT WINAPI DECLSPEC_HOTPATCH WinExec( LPCSTR lpCmdLine, UINT nCmdShow )
88 PROCESS_INFORMATION info;
89 STARTUPINFOA startup;
90 char *cmdline;
91 UINT ret;
93 memset( &startup, 0, sizeof(startup) );
94 startup.cb = sizeof(startup);
95 startup.dwFlags = STARTF_USESHOWWINDOW;
96 startup.wShowWindow = nCmdShow;
98 /* cmdline needs to be writable for CreateProcess */
99 if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(lpCmdLine)+1 ))) return 0;
100 strcpy( cmdline, lpCmdLine );
102 if (CreateProcessA( NULL, cmdline, NULL, NULL, FALSE,
103 0, NULL, NULL, &startup, &info ))
105 /* Give 30 seconds to the app to come up */
106 if (wait_input_idle( info.hProcess, 30000 ) == WAIT_FAILED)
107 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
108 ret = 33;
109 /* Close off the handles */
110 CloseHandle( info.hThread );
111 CloseHandle( info.hProcess );
113 else if ((ret = GetLastError()) >= 32)
115 FIXME("Strange error set by CreateProcess: %d\n", ret );
116 ret = 11;
118 HeapFree( GetProcessHeap(), 0, cmdline );
119 return ret;
123 /**********************************************************************
124 * LoadModule (KERNEL32.@)
126 DWORD WINAPI LoadModule( LPCSTR name, LPVOID paramBlock )
128 LOADPARMS32 *params = paramBlock;
129 PROCESS_INFORMATION info;
130 STARTUPINFOA startup;
131 DWORD ret;
132 LPSTR cmdline, p;
133 char filename[MAX_PATH];
134 BYTE len;
136 if (!name) return ERROR_FILE_NOT_FOUND;
138 if (!SearchPathA( NULL, name, ".exe", sizeof(filename), filename, NULL ) &&
139 !SearchPathA( NULL, name, NULL, sizeof(filename), filename, NULL ))
140 return GetLastError();
142 len = (BYTE)params->lpCmdLine[0];
143 if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + len + 2 )))
144 return ERROR_NOT_ENOUGH_MEMORY;
146 strcpy( cmdline, filename );
147 p = cmdline + strlen(cmdline);
148 *p++ = ' ';
149 memcpy( p, params->lpCmdLine + 1, len );
150 p[len] = 0;
152 memset( &startup, 0, sizeof(startup) );
153 startup.cb = sizeof(startup);
154 if (params->lpCmdShow)
156 startup.dwFlags = STARTF_USESHOWWINDOW;
157 startup.wShowWindow = ((WORD *)params->lpCmdShow)[1];
160 if (CreateProcessA( filename, cmdline, NULL, NULL, FALSE, 0,
161 params->lpEnvAddress, NULL, &startup, &info ))
163 /* Give 30 seconds to the app to come up */
164 if (wait_input_idle( info.hProcess, 30000 ) == WAIT_FAILED)
165 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
166 ret = 33;
167 /* Close off the handles */
168 CloseHandle( info.hThread );
169 CloseHandle( info.hProcess );
171 else if ((ret = GetLastError()) >= 32)
173 FIXME("Strange error set by CreateProcess: %lu\n", ret );
174 ret = 11;
177 HeapFree( GetProcessHeap(), 0, cmdline );
178 return ret;
182 /***********************************************************************
183 * ExitProcess (KERNEL32.@)
185 * Exits the current process.
187 * PARAMS
188 * status [I] Status code to exit with.
190 * RETURNS
191 * Nothing.
193 #ifdef __i386__
194 __ASM_STDCALL_FUNC( ExitProcess, 4, /* Shrinker depend on this particular ExitProcess implementation */
195 "pushl %ebp\n\t"
196 ".byte 0x8B, 0xEC\n\t" /* movl %esp, %ebp */
197 ".byte 0x6A, 0x00\n\t" /* pushl $0 */
198 ".byte 0x68, 0x00, 0x00, 0x00, 0x00\n\t" /* pushl $0 - 4 bytes immediate */
199 "pushl 8(%ebp)\n\t"
200 "call " __ASM_STDCALL("RtlExitUserProcess",4) "\n\t"
201 "leave\n\t"
202 "ret $4" )
203 #else
205 void WINAPI ExitProcess( DWORD status )
207 RtlExitUserProcess( status );
210 #endif
212 /***********************************************************************
213 * GetExitCodeProcess [KERNEL32.@]
215 * Gets termination status of specified process.
217 * PARAMS
218 * hProcess [in] Handle to the process.
219 * lpExitCode [out] Address to receive termination status.
221 * RETURNS
222 * Success: TRUE
223 * Failure: FALSE
225 BOOL WINAPI GetExitCodeProcess( HANDLE hProcess, LPDWORD lpExitCode )
227 PROCESS_BASIC_INFORMATION pbi;
229 if (!set_ntstatus( NtQueryInformationProcess( hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), NULL )))
230 return FALSE;
231 if (lpExitCode) *lpExitCode = pbi.ExitStatus;
232 return TRUE;
236 /**************************************************************************
237 * FatalExit (KERNEL32.@)
239 void WINAPI FatalExit( int code )
241 WARN( "FatalExit\n" );
242 ExitProcess( code );
246 /***********************************************************************
247 * GetProcessFlags (KERNEL32.@)
249 DWORD WINAPI GetProcessFlags( DWORD processid )
251 IMAGE_NT_HEADERS *nt;
252 DWORD flags = 0;
254 if (processid && processid != GetCurrentProcessId()) return 0;
256 if ((nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
258 if (nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
259 flags |= PDB32_CONSOLE_PROC;
261 if (!AreFileApisANSI()) flags |= PDB32_FILE_APIS_OEM;
262 if (IsDebuggerPresent()) flags |= PDB32_DEBUGGED;
263 return flags;
267 /***********************************************************************
268 * ConvertToGlobalHandle (KERNEL32.@)
270 HANDLE WINAPI ConvertToGlobalHandle(HANDLE hSrc)
272 HANDLE ret = INVALID_HANDLE_VALUE;
273 DuplicateHandle( GetCurrentProcess(), hSrc, GetCurrentProcess(), &ret, 0, FALSE,
274 DUPLICATE_MAKE_GLOBAL | DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE );
275 return ret;
279 /***********************************************************************
280 * SetHandleContext (KERNEL32.@)
282 BOOL WINAPI SetHandleContext(HANDLE hnd,DWORD context)
284 FIXME("(%p,%ld), stub. In case this got called by WSOCK32/WS2_32: "
285 "the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd,context);
286 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
287 return FALSE;
291 /***********************************************************************
292 * GetHandleContext (KERNEL32.@)
294 DWORD WINAPI GetHandleContext(HANDLE hnd)
296 FIXME("(%p), stub. In case this got called by WSOCK32/WS2_32: "
297 "the external WINSOCK DLLs won't work with WINE, don't use them.\n",hnd);
298 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
299 return 0;
303 /***********************************************************************
304 * CreateSocketHandle (KERNEL32.@)
306 HANDLE WINAPI CreateSocketHandle(void)
308 FIXME("(), stub. In case this got called by WSOCK32/WS2_32: "
309 "the external WINSOCK DLLs won't work with WINE, don't use them.\n");
310 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
311 return INVALID_HANDLE_VALUE;
315 /***********************************************************************
316 * SetProcessAffinityMask (KERNEL32.@)
318 BOOL WINAPI SetProcessAffinityMask( HANDLE hProcess, DWORD_PTR affmask )
320 return set_ntstatus( NtSetInformationProcess( hProcess, ProcessAffinityMask,
321 &affmask, sizeof(DWORD_PTR) ));
325 /**********************************************************************
326 * GetProcessAffinityMask (KERNEL32.@)
328 BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess, PDWORD_PTR process_mask, PDWORD_PTR system_mask )
330 if (process_mask)
332 if (!set_ntstatus( NtQueryInformationProcess( hProcess, ProcessAffinityMask,
333 process_mask, sizeof(*process_mask), NULL )))
334 return FALSE;
336 if (system_mask)
338 SYSTEM_BASIC_INFORMATION info;
340 if (!set_ntstatus( NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )))
341 return FALSE;
342 *system_mask = info.ActiveProcessorsAffinityMask;
344 return TRUE;
348 /***********************************************************************
349 * SetProcessWorkingSetSize [KERNEL32.@]
350 * Sets the min/max working set sizes for a specified process.
352 * PARAMS
353 * process [I] Handle to the process of interest
354 * minset [I] Specifies minimum working set size
355 * maxset [I] Specifies maximum working set size
357 * RETURNS
358 * Success: TRUE
359 * Failure: FALSE
361 BOOL WINAPI SetProcessWorkingSetSize(HANDLE process, SIZE_T minset, SIZE_T maxset)
363 return SetProcessWorkingSetSizeEx(process, minset, maxset, 0);
366 /***********************************************************************
367 * GetProcessWorkingSetSize (KERNEL32.@)
369 BOOL WINAPI GetProcessWorkingSetSize(HANDLE process, SIZE_T *minset, SIZE_T *maxset)
371 return GetProcessWorkingSetSizeEx(process, minset, maxset, NULL);
375 /******************************************************************
376 * GetProcessIoCounters (KERNEL32.@)
378 BOOL WINAPI GetProcessIoCounters(HANDLE hProcess, PIO_COUNTERS ioc)
380 return set_ntstatus( NtQueryInformationProcess(hProcess, ProcessIoCounters, ioc, sizeof(*ioc), NULL ));
383 /***********************************************************************
384 * RegisterServiceProcess (KERNEL32.@)
386 * A service process calls this function to ensure that it continues to run
387 * even after a user logged off.
389 DWORD WINAPI RegisterServiceProcess(DWORD dwProcessId, DWORD dwType)
391 /* I don't think that Wine needs to do anything in this function */
392 return 1; /* success */
396 /***********************************************************************
397 * GetCurrentProcess (KERNEL32.@)
399 * Get a handle to the current process.
401 * PARAMS
402 * None.
404 * RETURNS
405 * A handle representing the current process.
407 HANDLE WINAPI KERNEL32_GetCurrentProcess(void)
409 return (HANDLE)~(ULONG_PTR)0;
413 /***********************************************************************
414 * CreateActCtxA (KERNEL32.@)
416 HANDLE WINAPI DECLSPEC_HOTPATCH CreateActCtxA( const ACTCTXA *actctx )
418 ACTCTXW actw;
419 SIZE_T len;
420 HANDLE ret = INVALID_HANDLE_VALUE;
421 LPWSTR src = NULL, assdir = NULL, resname = NULL, appname = NULL;
423 TRACE("%p %08lx\n", actctx, actctx ? actctx->dwFlags : 0);
425 #define CHECK_LIMIT( field ) (actctx->cbSize >= RTL_SIZEOF_THROUGH_FIELD( ACTCTXA, field ))
426 if (!actctx || !CHECK_LIMIT( lpSource ) ||
427 ((actctx->dwFlags & ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID) && !CHECK_LIMIT( wProcessorArchitecture )) ||
428 ((actctx->dwFlags & ACTCTX_FLAG_LANGID_VALID) && !CHECK_LIMIT( wLangId )) ||
429 ((actctx->dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID) && !CHECK_LIMIT( lpAssemblyDirectory )) ||
430 ((actctx->dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID) && !CHECK_LIMIT( lpResourceName )) ||
431 ((actctx->dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID) && !CHECK_LIMIT( lpApplicationName )) ||
432 ((actctx->dwFlags & ACTCTX_FLAG_HMODULE_VALID) && !CHECK_LIMIT( hModule )))
434 SetLastError(ERROR_INVALID_PARAMETER);
435 return INVALID_HANDLE_VALUE;
437 #undef CHECK_LIMIT
439 actw.cbSize = sizeof(actw);
440 actw.dwFlags = actctx->dwFlags;
441 if (actctx->lpSource)
443 len = MultiByteToWideChar(CP_ACP, 0, actctx->lpSource, -1, NULL, 0);
444 src = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
445 if (!src) return INVALID_HANDLE_VALUE;
446 MultiByteToWideChar(CP_ACP, 0, actctx->lpSource, -1, src, len);
448 actw.lpSource = src;
450 if (actw.dwFlags & ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID)
451 actw.wProcessorArchitecture = actctx->wProcessorArchitecture;
452 if (actw.dwFlags & ACTCTX_FLAG_LANGID_VALID)
453 actw.wLangId = actctx->wLangId;
454 if (actw.dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID)
456 len = MultiByteToWideChar(CP_ACP, 0, actctx->lpAssemblyDirectory, -1, NULL, 0);
457 assdir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
458 if (!assdir) goto done;
459 MultiByteToWideChar(CP_ACP, 0, actctx->lpAssemblyDirectory, -1, assdir, len);
460 actw.lpAssemblyDirectory = assdir;
462 if (actw.dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID)
464 if ((ULONG_PTR)actctx->lpResourceName >> 16)
466 len = MultiByteToWideChar(CP_ACP, 0, actctx->lpResourceName, -1, NULL, 0);
467 resname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
468 if (!resname) goto done;
469 MultiByteToWideChar(CP_ACP, 0, actctx->lpResourceName, -1, resname, len);
470 actw.lpResourceName = resname;
472 else actw.lpResourceName = (LPCWSTR)actctx->lpResourceName;
474 if (actw.dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID)
476 len = MultiByteToWideChar(CP_ACP, 0, actctx->lpApplicationName, -1, NULL, 0);
477 appname = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
478 if (!appname) goto done;
479 MultiByteToWideChar(CP_ACP, 0, actctx->lpApplicationName, -1, appname, len);
480 actw.lpApplicationName = appname;
482 if (actw.dwFlags & ACTCTX_FLAG_HMODULE_VALID)
483 actw.hModule = actctx->hModule;
485 ret = CreateActCtxW(&actw);
487 done:
488 HeapFree(GetProcessHeap(), 0, src);
489 HeapFree(GetProcessHeap(), 0, assdir);
490 HeapFree(GetProcessHeap(), 0, resname);
491 HeapFree(GetProcessHeap(), 0, appname);
492 return ret;
495 /***********************************************************************
496 * FindActCtxSectionStringA (KERNEL32.@)
498 BOOL WINAPI FindActCtxSectionStringA( DWORD flags, const GUID *guid, ULONG id, const char *search,
499 ACTCTX_SECTION_KEYED_DATA *info )
501 LPWSTR searchW;
502 DWORD len;
503 BOOL ret;
505 TRACE("%08lx %s %lu %s %p\n", flags, debugstr_guid(guid), id, debugstr_a(search), info);
507 if (!search || !info)
509 SetLastError(ERROR_INVALID_PARAMETER);
510 return FALSE;
512 len = MultiByteToWideChar(CP_ACP, 0, search, -1, NULL, 0);
513 searchW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
514 MultiByteToWideChar(CP_ACP, 0, search, -1, searchW, len);
515 ret = FindActCtxSectionStringW( flags, guid, id, searchW, info );
516 HeapFree(GetProcessHeap(), 0, searchW);
517 return ret;
521 /***********************************************************************
522 * CmdBatNotification (KERNEL32.@)
524 * Notifies the system that a batch file has started or finished.
526 * PARAMS
527 * bBatchRunning [I] TRUE if a batch file has started or
528 * FALSE if a batch file has finished executing.
530 * RETURNS
531 * Unknown.
533 BOOL WINAPI CmdBatNotification( BOOL bBatchRunning )
535 FIXME("%d\n", bBatchRunning);
536 return FALSE;
539 /***********************************************************************
540 * RegisterApplicationRestart (KERNEL32.@)
542 HRESULT WINAPI RegisterApplicationRestart(PCWSTR pwzCommandLine, DWORD dwFlags)
544 FIXME("(%s,%ld)\n", debugstr_w(pwzCommandLine), dwFlags);
546 return S_OK;
549 /**********************************************************************
550 * WTSGetActiveConsoleSessionId (KERNEL32.@)
552 DWORD WINAPI WTSGetActiveConsoleSessionId(void)
554 static int once;
555 if (!once++) FIXME("stub\n");
556 /* Return current session id. */
557 return NtCurrentTeb()->Peb->SessionId;
560 /**********************************************************************
561 * GetSystemDEPPolicy (KERNEL32.@)
563 DEP_SYSTEM_POLICY_TYPE WINAPI GetSystemDEPPolicy(void)
565 return user_shared_data->NXSupportPolicy;
568 /**********************************************************************
569 * SetProcessDEPPolicy (KERNEL32.@)
571 BOOL WINAPI SetProcessDEPPolicy( DWORD flags )
573 ULONG dep_flags = 0;
575 TRACE("%#lx\n", flags);
577 if (flags & PROCESS_DEP_ENABLE)
578 dep_flags |= MEM_EXECUTE_OPTION_DISABLE | MEM_EXECUTE_OPTION_PERMANENT;
579 if (flags & PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION)
580 dep_flags |= MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION;
582 return set_ntstatus( NtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
583 &dep_flags, sizeof(dep_flags) ) );
586 /**********************************************************************
587 * ApplicationRecoveryFinished (KERNEL32.@)
589 VOID WINAPI ApplicationRecoveryFinished(BOOL success)
591 FIXME(": stub\n");
592 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
595 /**********************************************************************
596 * ApplicationRecoveryInProgress (KERNEL32.@)
598 HRESULT WINAPI ApplicationRecoveryInProgress(PBOOL canceled)
600 FIXME(":%p stub\n", canceled);
601 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
602 return E_FAIL;
605 /**********************************************************************
606 * RegisterApplicationRecoveryCallback (KERNEL32.@)
608 HRESULT WINAPI RegisterApplicationRecoveryCallback(APPLICATION_RECOVERY_CALLBACK callback, PVOID param, DWORD pingint, DWORD flags)
610 FIXME("%p, %p, %ld, %ld: stub, faking success\n", callback, param, pingint, flags);
611 return S_OK;
614 static SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *get_logical_processor_info(void)
616 DWORD size = 0;
617 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *info;
619 GetLogicalProcessorInformationEx( RelationGroup, NULL, &size );
620 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return NULL;
621 if (!(info = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
622 if (!GetLogicalProcessorInformationEx( RelationGroup, info, &size ))
624 HeapFree( GetProcessHeap(), 0, info );
625 return NULL;
627 return info;
631 /***********************************************************************
632 * GetActiveProcessorGroupCount (KERNEL32.@)
634 WORD WINAPI GetActiveProcessorGroupCount(void)
636 WORD groups;
637 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *info;
639 TRACE("()\n");
641 if (!(info = get_logical_processor_info())) return 0;
643 groups = info->Group.ActiveGroupCount;
645 HeapFree(GetProcessHeap(), 0, info);
646 return groups;
649 /***********************************************************************
650 * GetActiveProcessorCount (KERNEL32.@)
652 DWORD WINAPI GetActiveProcessorCount(WORD group)
654 DWORD cpus = 0;
655 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *info;
657 TRACE("(0x%x)\n", group);
659 if (!(info = get_logical_processor_info())) return 0;
661 if (group == ALL_PROCESSOR_GROUPS)
663 for (group = 0; group < info->Group.ActiveGroupCount; group++)
664 cpus += info->Group.GroupInfo[group].ActiveProcessorCount;
666 else
668 if (group < info->Group.ActiveGroupCount)
669 cpus = info->Group.GroupInfo[group].ActiveProcessorCount;
672 HeapFree(GetProcessHeap(), 0, info);
673 return cpus;
676 /***********************************************************************
677 * GetMaximumProcessorCount (KERNEL32.@)
679 DWORD WINAPI GetMaximumProcessorCount(WORD group)
681 DWORD cpus = 0;
682 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *info;
684 TRACE("(0x%x)\n", group);
686 if (!(info = get_logical_processor_info())) return 0;
688 if (group == ALL_PROCESSOR_GROUPS)
690 for (group = 0; group < info->Group.MaximumGroupCount; group++)
691 cpus += info->Group.GroupInfo[group].MaximumProcessorCount;
693 else
695 if (group < info->Group.MaximumGroupCount)
696 cpus = info->Group.GroupInfo[group].MaximumProcessorCount;
699 HeapFree(GetProcessHeap(), 0, info);
700 return cpus;
703 /***********************************************************************
704 * GetMaximumProcessorGroupCount (KERNEL32.@)
706 WORD WINAPI GetMaximumProcessorGroupCount(void)
708 WORD groups;
709 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *info;
711 TRACE("()\n");
713 if (!(info = get_logical_processor_info())) return 0;
715 groups = info->Group.MaximumGroupCount;
717 HeapFree(GetProcessHeap(), 0, info);
718 return groups;
721 /***********************************************************************
722 * GetFirmwareEnvironmentVariableA (KERNEL32.@)
724 DWORD WINAPI GetFirmwareEnvironmentVariableA(LPCSTR name, LPCSTR guid, PVOID buffer, DWORD size)
726 FIXME("stub: %s %s %p %lu\n", debugstr_a(name), debugstr_a(guid), buffer, size);
727 SetLastError(ERROR_INVALID_FUNCTION);
728 return 0;
731 /***********************************************************************
732 * GetFirmwareEnvironmentVariableW (KERNEL32.@)
734 DWORD WINAPI GetFirmwareEnvironmentVariableW(LPCWSTR name, LPCWSTR guid, PVOID buffer, DWORD size)
736 FIXME("stub: %s %s %p %lu\n", debugstr_w(name), debugstr_w(guid), buffer, size);
737 SetLastError(ERROR_INVALID_FUNCTION);
738 return 0;
741 /***********************************************************************
742 * SetFirmwareEnvironmentVariableW (KERNEL32.@)
744 BOOL WINAPI SetFirmwareEnvironmentVariableW(const WCHAR *name, const WCHAR *guid, void *buffer, DWORD size)
746 FIXME("stub: %s %s %p %lu\n", debugstr_w(name), debugstr_w(guid), buffer, size);
747 SetLastError(ERROR_INVALID_FUNCTION);
748 return FALSE;
751 /***********************************************************************
752 * GetFirmwareType (KERNEL32.@)
754 BOOL WINAPI GetFirmwareType(FIRMWARE_TYPE *type)
756 if (!type)
757 return FALSE;
759 *type = FirmwareTypeUnknown;
760 return TRUE;
763 /**********************************************************************
764 * GetNumaNodeProcessorMask (KERNEL32.@)
766 BOOL WINAPI GetNumaNodeProcessorMask(UCHAR node, PULONGLONG mask)
768 FIXME("(%c %p): stub\n", node, mask);
769 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
770 return FALSE;
773 /**********************************************************************
774 * GetNumaAvailableMemoryNode (KERNEL32.@)
776 BOOL WINAPI GetNumaAvailableMemoryNode(UCHAR node, PULONGLONG available_bytes)
778 FIXME("(%c %p): stub\n", node, available_bytes);
779 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
780 return FALSE;
783 /**********************************************************************
784 * GetNumaAvailableMemoryNodeEx (KERNEL32.@)
786 BOOL WINAPI GetNumaAvailableMemoryNodeEx(USHORT node, PULONGLONG available_bytes)
788 FIXME("(%hu %p): stub\n", node, available_bytes);
789 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
790 return FALSE;
793 /***********************************************************************
794 * GetNumaProcessorNode (KERNEL32.@)
796 BOOL WINAPI GetNumaProcessorNode(UCHAR processor, PUCHAR node)
798 TRACE("(%d, %p)\n", processor, node);
800 if (processor < system_info.NumberOfProcessors)
802 *node = 0;
803 return TRUE;
806 *node = 0xFF;
807 SetLastError(ERROR_INVALID_PARAMETER);
808 return FALSE;
811 /***********************************************************************
812 * GetNumaProcessorNodeEx (KERNEL32.@)
814 BOOL WINAPI GetNumaProcessorNodeEx(PPROCESSOR_NUMBER processor, PUSHORT node_number)
816 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
817 return FALSE;
820 /***********************************************************************
821 * GetNumaProximityNode (KERNEL32.@)
823 BOOL WINAPI GetNumaProximityNode(ULONG proximity_id, PUCHAR node_number)
825 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
826 return FALSE;
829 /**********************************************************************
830 * GetProcessDEPPolicy (KERNEL32.@)
832 BOOL WINAPI GetProcessDEPPolicy(HANDLE process, LPDWORD flags, PBOOL permanent)
834 ULONG dep_flags;
836 TRACE("(%p %p %p)\n", process, flags, permanent);
838 if (!set_ntstatus( NtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
839 &dep_flags, sizeof(dep_flags), NULL )))
840 return FALSE;
842 if (flags)
844 *flags = 0;
845 if (dep_flags & MEM_EXECUTE_OPTION_DISABLE)
846 *flags |= PROCESS_DEP_ENABLE;
847 if (dep_flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION)
848 *flags |= PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION;
851 if (permanent) *permanent = (dep_flags & MEM_EXECUTE_OPTION_PERMANENT) != 0;
852 return TRUE;
855 /***********************************************************************
856 * UnregisterApplicationRestart (KERNEL32.@)
858 HRESULT WINAPI UnregisterApplicationRestart(void)
860 FIXME(": stub\n");
861 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
862 return S_OK;
865 /***********************************************************************
866 * CreateUmsCompletionList (KERNEL32.@)
868 BOOL WINAPI CreateUmsCompletionList(PUMS_COMPLETION_LIST *list)
870 FIXME( "%p: stub\n", list );
871 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
872 return FALSE;
875 /***********************************************************************
876 * CreateUmsThreadContext (KERNEL32.@)
878 BOOL WINAPI CreateUmsThreadContext(PUMS_CONTEXT *ctx)
880 FIXME( "%p: stub\n", ctx );
881 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
882 return FALSE;
885 /***********************************************************************
886 * DeleteUmsCompletionList (KERNEL32.@)
888 BOOL WINAPI DeleteUmsCompletionList(PUMS_COMPLETION_LIST list)
890 FIXME( "%p: stub\n", list );
891 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
892 return FALSE;
895 /***********************************************************************
896 * DeleteUmsThreadContext (KERNEL32.@)
898 BOOL WINAPI DeleteUmsThreadContext(PUMS_CONTEXT ctx)
900 FIXME( "%p: stub\n", ctx );
901 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
902 return FALSE;
905 /***********************************************************************
906 * DequeueUmsCompletionListItems (KERNEL32.@)
908 BOOL WINAPI DequeueUmsCompletionListItems(void *list, DWORD timeout, PUMS_CONTEXT *ctx)
910 FIXME( "%p,%08lx,%p: stub\n", list, timeout, ctx );
911 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
912 return FALSE;
915 /***********************************************************************
916 * EnterUmsSchedulingMode (KERNEL32.@)
918 BOOL WINAPI EnterUmsSchedulingMode(UMS_SCHEDULER_STARTUP_INFO *info)
920 FIXME( "%p: stub\n", info );
921 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
922 return FALSE;
925 /***********************************************************************
926 * ExecuteUmsThread (KERNEL32.@)
928 BOOL WINAPI ExecuteUmsThread(PUMS_CONTEXT ctx)
930 FIXME( "%p: stub\n", ctx );
931 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
932 return FALSE;
935 /***********************************************************************
936 * GetCurrentUmsThread (KERNEL32.@)
938 PUMS_CONTEXT WINAPI GetCurrentUmsThread(void)
940 FIXME( "stub\n" );
941 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
942 return FALSE;
945 /***********************************************************************
946 * GetNextUmsListItem (KERNEL32.@)
948 PUMS_CONTEXT WINAPI GetNextUmsListItem(PUMS_CONTEXT ctx)
950 FIXME( "%p: stub\n", ctx );
951 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
952 return NULL;
955 /***********************************************************************
956 * GetUmsCompletionListEvent (KERNEL32.@)
958 BOOL WINAPI GetUmsCompletionListEvent(PUMS_COMPLETION_LIST list, HANDLE *event)
960 FIXME( "%p,%p: stub\n", list, event );
961 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
962 return FALSE;
965 /***********************************************************************
966 * QueryUmsThreadInformation (KERNEL32.@)
968 BOOL WINAPI QueryUmsThreadInformation(PUMS_CONTEXT ctx, UMS_THREAD_INFO_CLASS class,
969 void *buf, ULONG length, ULONG *ret_length)
971 FIXME( "%p,%08x,%p,%08lx,%p: stub\n", ctx, class, buf, length, ret_length );
972 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
973 return FALSE;
976 /***********************************************************************
977 * SetUmsThreadInformation (KERNEL32.@)
979 BOOL WINAPI SetUmsThreadInformation(PUMS_CONTEXT ctx, UMS_THREAD_INFO_CLASS class,
980 void *buf, ULONG length)
982 FIXME( "%p,%08x,%p,%08lx: stub\n", ctx, class, buf, length );
983 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
984 return FALSE;
987 /***********************************************************************
988 * UmsThreadYield (KERNEL32.@)
990 BOOL WINAPI UmsThreadYield(void *param)
992 FIXME( "%p: stub\n", param );
993 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
994 return FALSE;