- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/*
|
1999-01-16 02:11:45 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
2013-08-29 12:20:29 +00:00
|
|
|
* FILE: dll/win32/kernel32/client/thread.c
|
1999-01-16 02:11:45 +00:00
|
|
|
* PURPOSE: Thread functions
|
2013-08-29 12:20:29 +00:00
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
* Ariadne (ariadne@xs4all.nl)
|
1999-01-16 02:11:45 +00:00
|
|
|
*/
|
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
1999-05-29 00:15:17 +00:00
|
|
|
|
2003-01-15 21:24:36 +00:00
|
|
|
#include <k32.h>
|
1999-01-16 02:11:45 +00:00
|
|
|
|
1999-12-13 22:04:41 +00:00
|
|
|
#define NDEBUG
|
2007-09-02 19:42:22 +00:00
|
|
|
#include <debug.h>
|
1999-09-05 10:22:05 +00:00
|
|
|
|
2009-12-07 03:34:25 +00:00
|
|
|
#define SXS_SUPPORT_FIXME
|
2005-08-09 08:02:05 +00:00
|
|
|
|
2012-02-19 20:09:49 +00:00
|
|
|
typedef NTSTATUS (NTAPI *PCSR_CREATE_REMOTE_THREAD)(IN HANDLE ThreadHandle, IN PCLIENT_ID ClientId);
|
|
|
|
|
2018-08-23 19:44:53 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
2010-03-09 20:23:22 +00:00
|
|
|
NTSTATUS
|
|
|
|
WINAPI
|
|
|
|
BasepNotifyCsrOfThread(IN HANDLE ThreadHandle,
|
2018-08-23 19:44:53 +00:00
|
|
|
IN PCLIENT_ID ClientId)
|
|
|
|
{
|
|
|
|
BASE_API_MESSAGE ApiMessage;
|
|
|
|
PBASE_CREATE_THREAD CreateThreadRequest = &ApiMessage.Data.CreateThreadRequest;
|
|
|
|
|
|
|
|
DPRINT("BasepNotifyCsrOfThread: Thread: %p, Handle %p\n",
|
|
|
|
ClientId->UniqueThread, ThreadHandle);
|
|
|
|
|
|
|
|
/* Fill out the request */
|
|
|
|
CreateThreadRequest->ClientId = *ClientId;
|
|
|
|
CreateThreadRequest->ThreadHandle = ThreadHandle;
|
|
|
|
|
|
|
|
/* Call CSR */
|
|
|
|
CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
|
|
|
|
NULL,
|
|
|
|
CSR_CREATE_API_NUMBER(BASESRV_SERVERDLL_INDEX, BasepCreateThread),
|
|
|
|
sizeof(*CreateThreadRequest));
|
|
|
|
if (!NT_SUCCESS(ApiMessage.Status))
|
|
|
|
{
|
|
|
|
DPRINT1("Failed to tell CSRSS about new thread: %lx\n", ApiMessage.Status);
|
|
|
|
return ApiMessage.Status;
|
|
|
|
}
|
2010-03-09 20:23:22 +00:00
|
|
|
|
2018-08-23 19:44:53 +00:00
|
|
|
/* Return Success */
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2012-05-23 17:35:25 +00:00
|
|
|
|
2005-07-19 21:04:19 +00:00
|
|
|
__declspec(noreturn)
|
|
|
|
VOID
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
BaseThreadStartup(IN LPTHREAD_START_ROUTINE lpStartAddress,
|
|
|
|
IN LPVOID lpParameter)
|
2002-12-02 21:28:40 +00:00
|
|
|
{
|
2005-07-19 21:04:19 +00:00
|
|
|
/* Attempt to call the Thread Start Address */
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_TRY
|
2005-07-19 21:04:19 +00:00
|
|
|
{
|
2011-07-23 11:38:58 +00:00
|
|
|
/* Legacy check which is still used today for Win32 threads */
|
|
|
|
if (NtCurrentTeb()->NtTib.Version == (30 << 8)) // OS/2 V3.0 ("Cruiser")
|
|
|
|
{
|
|
|
|
/* This registers the termination port with CSRSS */
|
|
|
|
if (!BaseRunningInServerProcess) CsrNewThread();
|
|
|
|
}
|
|
|
|
|
2005-07-19 21:04:19 +00:00
|
|
|
/* Get the exit code from the Thread Start */
|
2011-07-23 11:38:58 +00:00
|
|
|
ExitThread((lpStartAddress)((PVOID)lpParameter));
|
2005-07-19 21:04:19 +00:00
|
|
|
}
|
2018-10-18 20:07:37 +00:00
|
|
|
_SEH2_EXCEPT(UnhandledExceptionFilter(_SEH2_GetExceptionInformation()))
|
2005-07-19 21:04:19 +00:00
|
|
|
{
|
|
|
|
/* Get the Exit code from the SEH Handler */
|
2011-07-23 11:38:58 +00:00
|
|
|
if (!BaseRunningInServerProcess)
|
|
|
|
{
|
|
|
|
/* Kill the whole process, usually */
|
|
|
|
ExitProcess(_SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If running inside CSRSS, kill just this thread */
|
|
|
|
ExitThread(_SEH2_GetExceptionCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
1999-09-06 21:32:57 +00:00
|
|
|
}
|
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
BaseDispatchApc(IN PAPCFUNC ApcRoutine,
|
|
|
|
IN PVOID Data,
|
|
|
|
IN PACTIVATION_CONTEXT ActivationContext)
|
|
|
|
{
|
|
|
|
RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME ActivationFrame;
|
|
|
|
|
|
|
|
/* Setup the activation context */
|
|
|
|
ActivationFrame.Size = sizeof(ActivationFrame);
|
|
|
|
ActivationFrame.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER;
|
|
|
|
|
|
|
|
/* Check if caller wanted one */
|
|
|
|
if (ActivationContext == INVALID_ACTIVATION_CONTEXT)
|
|
|
|
{
|
|
|
|
/* Do the APC directly */
|
|
|
|
ApcRoutine((ULONG_PTR)Data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then activate it */
|
|
|
|
RtlActivateActivationContextUnsafeFast(&ActivationFrame, ActivationContext);
|
|
|
|
|
|
|
|
/* Call the routine under SEH */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
ApcRoutine((ULONG_PTR)Data);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
/* Now de-activate and release the activation context */
|
|
|
|
RtlDeactivateActivationContextUnsafeFast(&ActivationFrame);
|
|
|
|
RtlReleaseActivationContext(ActivationContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
HANDLE
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2014-03-05 11:45:39 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
2012-05-23 17:35:25 +00:00
|
|
|
CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
|
|
|
IN DWORD dwStackSize,
|
|
|
|
IN LPTHREAD_START_ROUTINE lpStartAddress,
|
|
|
|
IN LPVOID lpParameter,
|
|
|
|
IN DWORD dwCreationFlags,
|
|
|
|
OUT LPDWORD lpThreadId)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Act as if we're going to create a remote thread in ourselves */
|
|
|
|
return CreateRemoteThread(NtCurrentProcess(),
|
|
|
|
lpThreadAttributes,
|
|
|
|
dwStackSize,
|
|
|
|
lpStartAddress,
|
|
|
|
lpParameter,
|
|
|
|
dwCreationFlags,
|
|
|
|
lpThreadId);
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
HANDLE
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2012-05-24 19:20:33 +00:00
|
|
|
CreateRemoteThread(IN HANDLE hProcess,
|
|
|
|
IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
|
|
|
IN DWORD dwStackSize,
|
|
|
|
IN LPTHREAD_START_ROUTINE lpStartAddress,
|
|
|
|
IN LPVOID lpParameter,
|
|
|
|
IN DWORD dwCreationFlags,
|
|
|
|
OUT LPDWORD lpThreadId)
|
2001-08-03 17:21:38 +00:00
|
|
|
{
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
INITIAL_TEB InitialTeb;
|
|
|
|
CONTEXT Context;
|
|
|
|
CLIENT_ID ClientId;
|
|
|
|
OBJECT_ATTRIBUTES LocalObjectAttributes;
|
|
|
|
POBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
HANDLE hThread;
|
|
|
|
ULONG Dummy;
|
2012-05-24 19:20:33 +00:00
|
|
|
PTEB Teb;
|
|
|
|
THREAD_BASIC_INFORMATION ThreadBasicInfo;
|
2013-03-17 22:50:51 +00:00
|
|
|
PACTIVATION_CONTEXT_STACK ActivationContextStack = NULL;
|
2012-05-24 19:20:33 +00:00
|
|
|
ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
|
|
|
|
ULONG_PTR Cookie;
|
|
|
|
ULONG ReturnLength;
|
2018-04-23 09:42:32 +00:00
|
|
|
SIZE_T ReturnSize;
|
2018-08-23 19:44:53 +00:00
|
|
|
|
2013-08-29 20:37:02 +00:00
|
|
|
DPRINT("CreateRemoteThread: hProcess: %p dwStackSize: %lu lpStartAddress"
|
2018-08-23 19:44:53 +00:00
|
|
|
": %p lpParameter: %p, dwCreationFlags: %lx\n", hProcess,
|
|
|
|
dwStackSize, lpStartAddress, lpParameter, dwCreationFlags);
|
2008-11-30 19:28:11 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Clear the Context */
|
2018-08-23 19:44:53 +00:00
|
|
|
RtlZeroMemory(&Context, sizeof(Context));
|
2008-11-30 19:28:11 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Write PID */
|
|
|
|
ClientId.UniqueProcess = hProcess;
|
2008-11-30 19:28:11 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Create the Stack */
|
2011-11-03 06:46:22 +00:00
|
|
|
Status = BaseCreateStack(hProcess,
|
2016-05-26 02:44:25 +00:00
|
|
|
(dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION) ?
|
|
|
|
0 : dwStackSize,
|
|
|
|
(dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION) ?
|
|
|
|
dwStackSize : 0,
|
2012-05-24 19:20:33 +00:00
|
|
|
&InitialTeb);
|
2013-03-17 22:50:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
|
2018-08-23 19:44:53 +00:00
|
|
|
/* Create the Initial Context */
|
2011-11-03 00:30:44 +00:00
|
|
|
BaseInitializeContext(&Context,
|
2012-05-24 19:20:33 +00:00
|
|
|
lpParameter,
|
|
|
|
lpStartAddress,
|
|
|
|
InitialTeb.StackBase,
|
|
|
|
1);
|
2008-11-30 19:28:11 +00:00
|
|
|
|
2018-08-23 19:44:53 +00:00
|
|
|
/* Initialize the attributes for the thread object */
|
2011-11-03 00:30:44 +00:00
|
|
|
ObjectAttributes = BaseFormatObjectAttributes(&LocalObjectAttributes,
|
2012-05-24 19:20:33 +00:00
|
|
|
lpThreadAttributes,
|
|
|
|
NULL);
|
2008-11-30 19:28:11 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Create the Kernel Thread Object */
|
|
|
|
Status = NtCreateThread(&hThread,
|
|
|
|
THREAD_ALL_ACCESS,
|
|
|
|
ObjectAttributes,
|
|
|
|
hProcess,
|
|
|
|
&ClientId,
|
|
|
|
&Context,
|
|
|
|
&InitialTeb,
|
|
|
|
TRUE);
|
2012-05-24 19:20:33 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
{
|
2012-05-24 19:20:33 +00:00
|
|
|
/* Fail the kernel create */
|
2011-11-03 00:30:44 +00:00
|
|
|
BaseFreeThreadStack(hProcess, &InitialTeb);
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Are we in the same process? */
|
2009-12-01 11:48:06 +00:00
|
|
|
if (hProcess == NtCurrentProcess())
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
{
|
|
|
|
/* Get the TEB */
|
|
|
|
Status = NtQueryInformationThread(hThread,
|
2009-12-01 11:48:06 +00:00
|
|
|
ThreadBasicInformation,
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
&ThreadBasicInfo,
|
|
|
|
sizeof(ThreadBasicInfo),
|
2012-05-24 19:20:33 +00:00
|
|
|
&ReturnLength);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
2018-08-23 19:44:53 +00:00
|
|
|
DPRINT1("SXS: %s - Failing thread create because "
|
|
|
|
"NtQueryInformationThread() failed with status %08lx\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
goto Quit;
|
2012-05-24 19:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the Activation Context Stack */
|
|
|
|
Status = RtlAllocateActivationContextStack(&ActivationContextStack);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
2018-08-23 19:44:53 +00:00
|
|
|
DPRINT1("SXS: %s - Failing thread create because "
|
|
|
|
"RtlAllocateActivationContextStack() failed with status %08lx\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
goto Quit;
|
2012-05-24 19:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save it */
|
|
|
|
Teb = ThreadBasicInfo.TebBaseAddress;
|
|
|
|
Teb->ActivationContextStackPointer = ActivationContextStack;
|
|
|
|
|
|
|
|
/* Query the Context */
|
2013-08-29 04:34:00 +00:00
|
|
|
Status = RtlQueryInformationActivationContext(RTL_QUERY_ACTIVATION_CONTEXT_FLAG_USE_ACTIVE_ACTIVATION_CONTEXT,
|
2012-05-24 19:20:33 +00:00
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
ActivationContextBasicInformation,
|
|
|
|
&ActCtxInfo,
|
|
|
|
sizeof(ActCtxInfo),
|
2018-04-23 09:42:32 +00:00
|
|
|
&ReturnSize);
|
2012-05-24 19:20:33 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
{
|
2012-05-24 19:20:33 +00:00
|
|
|
/* Fail */
|
2018-08-23 19:44:53 +00:00
|
|
|
DPRINT1("SXS: %s - Failing thread create because "
|
|
|
|
"RtlQueryInformationActivationContext() failed with status %08lx\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
goto Quit;
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
}
|
2009-12-01 11:48:06 +00:00
|
|
|
|
2012-05-24 19:20:33 +00:00
|
|
|
/* Does it need to be activated? */
|
|
|
|
if ((ActCtxInfo.hActCtx) && !(ActCtxInfo.dwFlags & 1))
|
2009-12-01 11:48:06 +00:00
|
|
|
{
|
2012-05-24 19:20:33 +00:00
|
|
|
/* Activate it */
|
|
|
|
Status = RtlActivateActivationContextEx(RTL_ACTIVATE_ACTIVATION_CONTEXT_EX_FLAG_RELEASE_ON_STACK_DEALLOCATION,
|
|
|
|
Teb,
|
|
|
|
ActCtxInfo.hActCtx,
|
|
|
|
&Cookie);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2009-12-01 11:48:06 +00:00
|
|
|
{
|
2012-05-24 19:20:33 +00:00
|
|
|
/* Fail */
|
2018-08-23 19:44:53 +00:00
|
|
|
DPRINT1("SXS: %s - Failing thread create because "
|
|
|
|
"RtlActivateActivationContextEx() failed with status %08lx\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
goto Quit;
|
2009-12-01 11:48:06 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-23 19:44:53 +00:00
|
|
|
|
|
|
|
/* Sync the service tag with the parent thread's one */
|
|
|
|
Teb->SubProcessTag = NtCurrentTeb()->SubProcessTag;
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
|
2010-03-09 20:23:22 +00:00
|
|
|
/* Notify CSR */
|
2012-02-19 20:09:49 +00:00
|
|
|
if (!BaseRunningInServerProcess)
|
|
|
|
{
|
|
|
|
Status = BasepNotifyCsrOfThread(hThread, &ClientId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (hProcess != NtCurrentProcess())
|
|
|
|
{
|
|
|
|
PCSR_CREATE_REMOTE_THREAD CsrCreateRemoteThread;
|
2012-05-23 17:35:25 +00:00
|
|
|
|
2012-02-19 20:09:49 +00:00
|
|
|
/* Get the direct CSRSRV export */
|
|
|
|
CsrCreateRemoteThread = (PCSR_CREATE_REMOTE_THREAD)
|
|
|
|
GetProcAddress(GetModuleHandleA("csrsrv"),
|
|
|
|
"CsrCreateRemoteThread");
|
|
|
|
if (CsrCreateRemoteThread)
|
|
|
|
{
|
|
|
|
/* Call it instead of going through LPC */
|
|
|
|
Status = CsrCreateRemoteThread(hThread, &ClientId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-23 17:35:25 +00:00
|
|
|
|
2018-08-23 19:44:53 +00:00
|
|
|
Quit:
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Failed to create the thread */
|
|
|
|
|
|
|
|
/* Free the activation context stack */
|
|
|
|
if (ActivationContextStack)
|
|
|
|
RtlFreeActivationContextStack(ActivationContextStack);
|
|
|
|
|
|
|
|
NtTerminateThread(hThread, Status);
|
|
|
|
// FIXME: Wait for the thread to terminate?
|
|
|
|
BaseFreeThreadStack(hProcess, &InitialTeb);
|
|
|
|
NtClose(hThread);
|
|
|
|
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Success */
|
2018-08-23 19:44:53 +00:00
|
|
|
if (lpThreadId)
|
|
|
|
*lpThreadId = HandleToUlong(ClientId.UniqueThread);
|
2008-11-30 19:28:11 +00:00
|
|
|
|
2018-08-23 19:44:53 +00:00
|
|
|
/* Resume the thread if asked */
|
|
|
|
if (!(dwCreationFlags & CREATE_SUSPENDED))
|
|
|
|
NtResumeThread(hThread, &Dummy);
|
2008-11-30 19:28:11 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Return handle to thread */
|
|
|
|
return hThread;
|
|
|
|
}
|
2005-05-09 01:46:57 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
ExitThread(IN DWORD uExitCode)
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2010-01-01 23:14:10 +00:00
|
|
|
ULONG LastThread;
|
2012-05-23 17:35:25 +00:00
|
|
|
PRTL_CRITICAL_SECTION LoaderLock;
|
|
|
|
|
|
|
|
/* Make sure loader lock isn't held */
|
|
|
|
LoaderLock = NtCurrentPeb()->LoaderLock;
|
|
|
|
if (LoaderLock) ASSERT(NtCurrentTeb()->ClientId.UniqueThread != LoaderLock->OwningThread);
|
2008-11-30 19:28:11 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/*
|
|
|
|
* Terminate process if this is the last thread
|
|
|
|
* of the current process
|
|
|
|
*/
|
|
|
|
Status = NtQueryInformationThread(NtCurrentThread(),
|
|
|
|
ThreadAmILastThread,
|
|
|
|
&LastThread,
|
2010-01-01 23:14:10 +00:00
|
|
|
sizeof(LastThread),
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
NULL);
|
2012-05-23 17:35:25 +00:00
|
|
|
if ((NT_SUCCESS(Status)) && (LastThread)) ExitProcess(uExitCode);
|
My biggest commit so far (everything compiles and apparently runs fine):
- replaced DWORD with ULONG in a couple of places
- replaced some ULONGs with LONGs in the KD GDB stub
- replaced INITIAL_TEB with USER_STACK, as per Nebbet's book, to support both fixed size and expandable stacks
- added InterlockedExchangePointer
- added the ASM_BREAKPOINT macro as the architecture-dependent assembler code to raise a breakpoint exception
- corrected definitions of INT, LONG, DWORD, UINT, ULONG and ULONG32
- corrected IoSetCancelRoutine to use InterlockedExchangePointer
- corrected definition of NtCurrentTeb and NtCurrentPeb
- corrected DbgBreakPoint and DbgUserBreakPoint not to set up a stack frame (temporary fix with inline assembler - why doesn't GCC understand __declspec(naked)?)
- corrected various calls to Interlocked* functions to cast OUT operands to LONG *
- corrected various printf format strings
- corrected DbgUiIssueRemoteBreakin to use the smallest possible stack (this is what started everything)
- removed a DPRINT that accessed pageable memory at non-PASSIVE_LEVEL IRQL
- beautified CreateProcessA (another temporary fix - all the new functions will be isolated in the upcoming stand-alone RTL)
- prefixed LdrInitializeThunk with a nop that can be overwritten with a breakpoint for debugging purposes (temporary debugging aid until we have user-mode debugger support). Will add support for this to the breakin utility soon
- thread creation code rewritten from scratch (some glitches documented inline, but works fine)
- thread creation code now duplicated just twice, as opposed to five times (temporary fix - three new, non standard functions have been exported from NTDLL.DLL, will fix later)
svn path=/trunk/; revision=4595
2003-04-26 23:13:33 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Notify DLLs and TLS Callbacks of termination */
|
|
|
|
LdrShutdownThread();
|
2008-11-30 19:28:11 +00:00
|
|
|
|
- Final ROSRTL removal patch. The next patch will remove the actual library and code.
- Changes:
- CreateProcess
* Cleanup creation of the initial thread using new utility functions and remove rosrtl
* Almost entirely rewrote the function to support features such as:
- SxS (locally only, patch will follow),
- SFP (SAFER) (locally only, patch will follow),
- DllPaths (locally only, patch will follow),
- Proper process environment/paramter block creation
- Proper console handle management (needs more work in kernel32/csr),
- Tokens/CreateProcessAsUser (locally only, patch will follow),
- Simpler code for path lookup, and more robust.
- Support for "auto-correction" (see Raymond Chen's blog)
- 16-bit/NE detection
- A variety of creation flags are now properly supported
- Added support for an undocumented-yet-known (see comment) shell flag
- Alert for flags we don't support yet
- Catch invalid flag combinations and other caller errors
- Improve and correct path searcing to use documented behaviours
- Created a multitude of helper functions to make the code easier to read
and allow them to be used for other apis as time goes on.
- BaseProcessStartup
* Call NtSetThreadInformation to let the Kernel know of the Thread's Start Address.
* Correct prototype of Thread Startup function for this case.
This fixes MANY things, some of which may not be evident, and possibly creates regressions which I have not yet seen but will try to correct. Some of these may be caused by the fact that I've seen code send CreateProcessW incorrect flags. Some things of note: DO NOT send partial names as "lpApplicationName". It's not supposed to work unless you're in the same current directory. Also, do NOT send CREATE_UNICODE_ENVIRONMENT if you don't have a unicode environement, and vice-versa. I've seen lots of code doing mistakes related to this. I hope you appreciate this patch and won't all jump on me for possbile regressions :(.
svn path=/trunk/; revision=16730
2005-07-26 04:14:10 +00:00
|
|
|
/* Tell the Kernel to free the Stack */
|
|
|
|
NtCurrentTeb()->FreeStackOnTermination = TRUE;
|
|
|
|
NtTerminateThread(NULL, uExitCode);
|
2008-11-30 19:28:11 +00:00
|
|
|
|
2010-01-01 23:14:10 +00:00
|
|
|
/* We should never reach this place */
|
2013-01-08 00:35:26 +00:00
|
|
|
ERROR_FATAL("It should not happen\n");
|
|
|
|
while (TRUE); /* 'noreturn' function */
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2004-07-30 19:18:39 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
HANDLE
|
2007-01-25 22:39:32 +00:00
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
OpenThread(IN DWORD dwDesiredAccess,
|
|
|
|
IN BOOL bInheritHandle,
|
|
|
|
IN DWORD dwThreadId)
|
2004-07-30 19:18:39 +00:00
|
|
|
{
|
2009-07-17 18:42:12 +00:00
|
|
|
NTSTATUS Status;
|
2007-01-25 22:39:32 +00:00
|
|
|
HANDLE ThreadHandle;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
2012-05-23 17:35:25 +00:00
|
|
|
CLIENT_ID ClientId;
|
2007-01-25 22:39:32 +00:00
|
|
|
|
|
|
|
ClientId.UniqueProcess = 0;
|
2009-07-17 18:42:12 +00:00
|
|
|
ClientId.UniqueThread = ULongToHandle(dwThreadId);
|
2007-01-25 22:39:32 +00:00
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
NULL,
|
|
|
|
(bInheritHandle ? OBJ_INHERIT : 0),
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2009-07-17 18:42:12 +00:00
|
|
|
Status = NtOpenThread(&ThreadHandle,
|
|
|
|
dwDesiredAccess,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&ClientId);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2007-01-25 22:39:32 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-07-30 19:18:39 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
return ThreadHandle;
|
|
|
|
}
|
2004-07-30 19:18:39 +00:00
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2001-08-03 17:21:38 +00:00
|
|
|
PTEB
|
|
|
|
GetTeb(VOID)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
return NtCurrentTeb();
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2001-08-03 17:21:38 +00:00
|
|
|
SwitchToThread(VOID)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2009-07-17 18:42:12 +00:00
|
|
|
return NtYieldExecution() != STATUS_NO_YIELD_PERFORMED;
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
2002-12-02 21:28:40 +00:00
|
|
|
GetCurrentThreadId(VOID)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
[KERNEL32]
Merge r34770, r36475, r36990, r37019, r43852, r43952, r43954, r43979, r43981, r46868 from amd64 branch:
- Multiple ULONG / SIZE_T fixes
- Use UlongToHandle / HandleToUlong to convert between DWORD ProcessId and ClientId.UniqueProcess
- implement amd64 version of _dump_context
- Make IsConsoleHandle 64bit safe
- Update kernel32.pspec with a lot of Win7 (commented out) and some amd64 specific exports, add some more comments and fix sorting
- Implement amd64 version of BaseThreadStartupThunk and BaseProcessStartThunk
- Stub amd64 version of SwitchToFiber
- Implement amd64 version of BasepInitializeContext
svn path=/trunk/; revision=48119
2010-07-19 18:52:18 +00:00
|
|
|
return HandleToUlong(NtCurrentTeb()->ClientId.UniqueThread);
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
BOOL
|
|
|
|
NTAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
GetThreadTimes(IN HANDLE hThread,
|
|
|
|
OUT LPFILETIME lpCreationTime,
|
|
|
|
OUT LPFILETIME lpExitTime,
|
|
|
|
OUT LPFILETIME lpKernelTime,
|
|
|
|
OUT LPFILETIME lpUserTime)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
KERNEL_USER_TIMES KernelUserTimes;
|
|
|
|
NTSTATUS Status;
|
2003-01-22 02:24:36 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtQueryInformationThread(hThread,
|
|
|
|
ThreadTimes,
|
|
|
|
&KernelUserTimes,
|
|
|
|
sizeof(KERNEL_USER_TIMES),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-01-22 02:24:36 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2012-05-23 17:35:25 +00:00
|
|
|
return FALSE;
|
2003-01-22 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
*lpCreationTime = *(LPFILETIME)&KernelUserTimes.CreateTime;
|
|
|
|
*lpExitTime = *(LPFILETIME)&KernelUserTimes.ExitTime;
|
|
|
|
*lpKernelTime = *(LPFILETIME)&KernelUserTimes.KernelTime;
|
|
|
|
*lpUserTime = *(LPFILETIME)&KernelUserTimes.UserTime;
|
|
|
|
return TRUE;
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
GetThreadContext(IN HANDLE hThread,
|
|
|
|
OUT LPCONTEXT lpContext)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
NTSTATUS Status;
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtGetContextThread(hThread, lpContext);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2002-12-02 21:28:40 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return FALSE;
|
2002-12-02 21:28:40 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
return TRUE;
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
SetThreadContext(IN HANDLE hThread,
|
|
|
|
IN CONST CONTEXT *lpContext)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
NTSTATUS Status;
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtSetContextThread(hThread, (PCONTEXT)lpContext);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2002-12-02 21:28:40 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return FALSE;
|
2002-12-02 21:28:40 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
return TRUE;
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
GetExitCodeThread(IN HANDLE hThread,
|
|
|
|
OUT LPDWORD lpExitCode)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
THREAD_BASIC_INFORMATION ThreadBasic;
|
|
|
|
NTSTATUS Status;
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtQueryInformationThread(hThread,
|
|
|
|
ThreadBasicInformation,
|
|
|
|
&ThreadBasic,
|
|
|
|
sizeof(THREAD_BASIC_INFORMATION),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2002-12-02 21:28:40 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2012-05-23 17:35:25 +00:00
|
|
|
return FALSE;
|
2002-12-02 21:28:40 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
*lpExitCode = ThreadBasic.ExitStatus;
|
|
|
|
return TRUE;
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
ResumeThread(IN HANDLE hThread)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
ULONG PreviousResumeCount;
|
|
|
|
NTSTATUS Status;
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtResumeThread(hThread, &PreviousResumeCount);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2002-12-02 21:28:40 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return -1;
|
2002-12-02 21:28:40 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
return PreviousResumeCount;
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
TerminateThread(IN HANDLE hThread,
|
|
|
|
IN DWORD dwExitCode)
|
1999-10-02 20:20:44 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
NTSTATUS Status;
|
2013-09-04 19:53:59 +00:00
|
|
|
#if DBG
|
2012-05-23 17:35:25 +00:00
|
|
|
PRTL_CRITICAL_SECTION LoaderLock;
|
|
|
|
THREAD_BASIC_INFORMATION ThreadInfo;
|
2013-09-04 19:53:59 +00:00
|
|
|
#endif /* DBG */
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/* Check for invalid thread handle */
|
2007-01-25 22:39:32 +00:00
|
|
|
if (!hThread)
|
2001-08-15 20:35:39 +00:00
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
/* Fail if one was passed */
|
2007-01-25 22:39:32 +00:00
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
2001-08-15 20:35:39 +00:00
|
|
|
}
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2013-09-04 19:53:59 +00:00
|
|
|
#if DBG
|
2012-05-23 17:35:25 +00:00
|
|
|
/* Get the loader lock */
|
|
|
|
LoaderLock = NtCurrentPeb()->LoaderLock;
|
|
|
|
if (LoaderLock)
|
|
|
|
{
|
|
|
|
/* Get our TID */
|
|
|
|
Status = NtQueryInformationThread(hThread,
|
|
|
|
ThreadBasicInformation,
|
|
|
|
&ThreadInfo,
|
|
|
|
sizeof(ThreadInfo),
|
|
|
|
NULL);
|
2013-09-04 19:53:59 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
2012-05-23 17:35:25 +00:00
|
|
|
{
|
2013-09-04 19:53:59 +00:00
|
|
|
/* If terminating the current thread, we must not hold the loader lock */
|
|
|
|
if (NtCurrentTeb()->ClientId.UniqueThread == ThreadInfo.ClientId.UniqueThread)
|
|
|
|
ASSERT(NtCurrentTeb()->ClientId.UniqueThread != LoaderLock->OwningThread);
|
2012-05-23 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-04 19:53:59 +00:00
|
|
|
#endif /* DBG */
|
2012-05-23 17:35:25 +00:00
|
|
|
|
|
|
|
/* Now terminate the thread */
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtTerminateThread(hThread, dwExitCode);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2001-08-15 20:35:39 +00:00
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
/* Fail */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return FALSE;
|
2001-08-15 20:35:39 +00:00
|
|
|
}
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/* All done */
|
2007-01-25 22:39:32 +00:00
|
|
|
return TRUE;
|
1999-10-02 20:20:44 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
SuspendThread(IN HANDLE hThread)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
ULONG PreviousSuspendCount;
|
|
|
|
NTSTATUS Status;
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtSuspendThread(hThread, &PreviousSuspendCount);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2002-12-02 21:28:40 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return -1;
|
2002-12-02 21:28:40 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
return PreviousSuspendCount;
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-12-08 18:58:42 +00:00
|
|
|
DWORD_PTR
|
2007-01-25 22:39:32 +00:00
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
SetThreadAffinityMask(IN HANDLE hThread,
|
|
|
|
IN DWORD_PTR dwThreadAffinityMask)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
THREAD_BASIC_INFORMATION ThreadBasic;
|
|
|
|
KAFFINITY AffinityMask;
|
|
|
|
NTSTATUS Status;
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
AffinityMask = (KAFFINITY)dwThreadAffinityMask;
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtQueryInformationThread(hThread,
|
|
|
|
ThreadBasicInformation,
|
|
|
|
&ThreadBasic,
|
|
|
|
sizeof(THREAD_BASIC_INFORMATION),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2002-12-02 21:28:40 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return 0;
|
2002-12-02 21:28:40 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtSetInformationThread(hThread,
|
|
|
|
ThreadAffinityMask,
|
|
|
|
&AffinityMask,
|
|
|
|
sizeof(KAFFINITY));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
ThreadBasic.AffinityMask = 0;
|
|
|
|
}
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
return ThreadBasic.AffinityMask;
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-08-09 08:02:05 +00:00
|
|
|
BOOL
|
2007-01-25 22:39:32 +00:00
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
SetThreadPriority(IN HANDLE hThread,
|
|
|
|
IN int nPriority)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2008-12-07 21:52:22 +00:00
|
|
|
LONG Prio = nPriority;
|
2005-08-09 08:02:05 +00:00
|
|
|
NTSTATUS Status;
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2005-08-09 08:02:05 +00:00
|
|
|
/* Check if values forcing saturation should be used */
|
|
|
|
if (Prio == THREAD_PRIORITY_TIME_CRITICAL)
|
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
/* This is 16 */
|
2005-08-09 08:02:05 +00:00
|
|
|
Prio = (HIGH_PRIORITY + 1) / 2;
|
|
|
|
}
|
|
|
|
else if (Prio == THREAD_PRIORITY_IDLE)
|
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
/* This is -16 */
|
2005-08-09 08:02:05 +00:00
|
|
|
Prio = -((HIGH_PRIORITY + 1) / 2);
|
|
|
|
}
|
2003-04-30 22:00:41 +00:00
|
|
|
|
2005-08-09 08:02:05 +00:00
|
|
|
/* Set the Base Priority */
|
|
|
|
Status = NtSetInformationThread(hThread,
|
|
|
|
ThreadBasePriority,
|
|
|
|
&Prio,
|
2008-12-07 21:52:22 +00:00
|
|
|
sizeof(LONG));
|
2005-08-09 08:02:05 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2002-12-02 21:28:40 +00:00
|
|
|
{
|
2005-08-09 08:02:05 +00:00
|
|
|
/* Failure */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2005-08-09 08:02:05 +00:00
|
|
|
return FALSE;
|
2002-12-02 21:28:40 +00:00
|
|
|
}
|
|
|
|
|
2005-08-09 08:02:05 +00:00
|
|
|
/* Return */
|
|
|
|
return TRUE;
|
1999-01-16 02:11:45 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-08-09 08:02:05 +00:00
|
|
|
int
|
2007-01-25 22:39:32 +00:00
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
GetThreadPriority(IN HANDLE hThread)
|
1999-01-16 02:11:45 +00:00
|
|
|
{
|
2005-08-09 08:02:05 +00:00
|
|
|
THREAD_BASIC_INFORMATION ThreadBasic;
|
|
|
|
NTSTATUS Status;
|
2002-12-02 21:28:40 +00:00
|
|
|
|
2005-08-09 08:02:05 +00:00
|
|
|
/* Query the Base Priority Increment */
|
|
|
|
Status = NtQueryInformationThread(hThread,
|
|
|
|
ThreadBasicInformation,
|
|
|
|
&ThreadBasic,
|
|
|
|
sizeof(THREAD_BASIC_INFORMATION),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2002-12-02 21:28:40 +00:00
|
|
|
{
|
2005-08-09 08:02:05 +00:00
|
|
|
/* Failure */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2005-08-09 08:02:05 +00:00
|
|
|
return THREAD_PRIORITY_ERROR_RETURN;
|
2002-12-02 21:28:40 +00:00
|
|
|
}
|
|
|
|
|
[KERNEL32]: Bug #42: GetThreadPriority was only returning -2, -1, 0, 1, 2 or 15 and -15. For realtime threads, priorities of 3, 4, 5, 6, 7, and their negatives, are also valid. Also, GetThreadPriority was returning -15/15 for any priorty outside the -2/2 range, instead of just the special saturation values (I should count this as a separate bug, really...)
svn path=/trunk/; revision=52802
2011-07-23 11:43:57 +00:00
|
|
|
/* Do some conversions for saturation values */
|
|
|
|
if (ThreadBasic.BasePriority == ((HIGH_PRIORITY + 1) / 2))
|
2005-08-09 08:02:05 +00:00
|
|
|
{
|
[KERNEL32]: Bug #42: GetThreadPriority was only returning -2, -1, 0, 1, 2 or 15 and -15. For realtime threads, priorities of 3, 4, 5, 6, 7, and their negatives, are also valid. Also, GetThreadPriority was returning -15/15 for any priorty outside the -2/2 range, instead of just the special saturation values (I should count this as a separate bug, really...)
svn path=/trunk/; revision=52802
2011-07-23 11:43:57 +00:00
|
|
|
/* Win32 calls this "time critical" */
|
2005-08-09 08:02:05 +00:00
|
|
|
ThreadBasic.BasePriority = THREAD_PRIORITY_TIME_CRITICAL;
|
|
|
|
}
|
[KERNEL32]: Bug #42: GetThreadPriority was only returning -2, -1, 0, 1, 2 or 15 and -15. For realtime threads, priorities of 3, 4, 5, 6, 7, and their negatives, are also valid. Also, GetThreadPriority was returning -15/15 for any priorty outside the -2/2 range, instead of just the special saturation values (I should count this as a separate bug, really...)
svn path=/trunk/; revision=52802
2011-07-23 11:43:57 +00:00
|
|
|
else if (ThreadBasic.BasePriority == -((HIGH_PRIORITY + 1) / 2))
|
2005-08-09 08:02:05 +00:00
|
|
|
{
|
[KERNEL32]: Bug #42: GetThreadPriority was only returning -2, -1, 0, 1, 2 or 15 and -15. For realtime threads, priorities of 3, 4, 5, 6, 7, and their negatives, are also valid. Also, GetThreadPriority was returning -15/15 for any priorty outside the -2/2 range, instead of just the special saturation values (I should count this as a separate bug, really...)
svn path=/trunk/; revision=52802
2011-07-23 11:43:57 +00:00
|
|
|
/* Win32 calls this "idle" */
|
2005-08-09 08:02:05 +00:00
|
|
|
ThreadBasic.BasePriority = THREAD_PRIORITY_IDLE;
|
|
|
|
}
|
2000-04-14 01:50:38 +00:00
|
|
|
|
2005-08-09 08:02:05 +00:00
|
|
|
/* Return the final result */
|
|
|
|
return ThreadBasic.BasePriority;
|
|
|
|
}
|
2003-01-22 02:24:36 +00:00
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2003-01-22 02:24:36 +00:00
|
|
|
GetThreadPriorityBoost(IN HANDLE hThread,
|
2007-01-25 22:39:32 +00:00
|
|
|
OUT PBOOL pDisablePriorityBoost)
|
2003-01-22 02:24:36 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
ULONG PriorityBoost;
|
|
|
|
NTSTATUS Status;
|
2003-01-22 02:24:36 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtQueryInformationThread(hThread,
|
|
|
|
ThreadPriorityBoost,
|
|
|
|
&PriorityBoost,
|
|
|
|
sizeof(ULONG),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-01-22 02:24:36 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return FALSE;
|
2003-01-22 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
*pDisablePriorityBoost = PriorityBoost;
|
|
|
|
return TRUE;
|
2003-01-22 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
BOOL
|
|
|
|
NTAPI
|
2003-01-22 02:24:36 +00:00
|
|
|
SetThreadPriorityBoost(IN HANDLE hThread,
|
2007-01-25 22:39:32 +00:00
|
|
|
IN BOOL bDisablePriorityBoost)
|
2003-01-22 02:24:36 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
ULONG PriorityBoost;
|
|
|
|
NTSTATUS Status;
|
2003-01-22 02:24:36 +00:00
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
PriorityBoost = bDisablePriorityBoost != FALSE;
|
2003-01-22 02:24:36 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtSetInformationThread(hThread,
|
|
|
|
ThreadPriorityBoost,
|
|
|
|
&PriorityBoost,
|
|
|
|
sizeof(ULONG));
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-01-22 02:24:36 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return FALSE;
|
2003-01-22 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
return TRUE;
|
2003-01-22 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2009-10-29 10:04:15 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
2003-01-22 02:24:36 +00:00
|
|
|
GetThreadSelectorEntry(IN HANDLE hThread,
|
2009-10-29 10:04:15 +00:00
|
|
|
IN DWORD dwSelector,
|
|
|
|
OUT LPLDT_ENTRY lpSelectorEntry)
|
2003-01-22 02:24:36 +00:00
|
|
|
{
|
2008-07-25 11:09:07 +00:00
|
|
|
#ifdef _M_IX86
|
2009-10-29 10:04:15 +00:00
|
|
|
DESCRIPTOR_TABLE_ENTRY DescriptionTableEntry;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Set the selector and do the query */
|
|
|
|
DescriptionTableEntry.Selector = dwSelector;
|
|
|
|
Status = NtQueryInformationThread(hThread,
|
|
|
|
ThreadDescriptorTableEntry,
|
|
|
|
&DescriptionTableEntry,
|
|
|
|
sizeof(DESCRIPTOR_TABLE_ENTRY),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2009-10-29 10:04:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Success, return the selector */
|
|
|
|
*lpSelectorEntry = DescriptionTableEntry.Descriptor;
|
|
|
|
return TRUE;
|
2008-07-25 11:09:07 +00:00
|
|
|
#else
|
|
|
|
DPRINT1("Calling GetThreadSelectorEntry!\n");
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
2003-01-22 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 18:50:51 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-01-25 22:39:32 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
SetThreadIdealProcessor(IN HANDLE hThread,
|
|
|
|
IN DWORD dwIdealProcessor)
|
2003-02-03 14:20:24 +00:00
|
|
|
{
|
2007-01-25 22:39:32 +00:00
|
|
|
NTSTATUS Status;
|
2003-02-03 14:20:24 +00:00
|
|
|
|
2007-01-25 22:39:32 +00:00
|
|
|
Status = NtSetInformationThread(hThread,
|
|
|
|
ThreadIdealProcessor,
|
|
|
|
&dwIdealProcessor,
|
|
|
|
sizeof(ULONG));
|
|
|
|
if (!NT_SUCCESS(Status))
|
2003-02-03 14:20:24 +00:00
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2007-01-25 22:39:32 +00:00
|
|
|
return -1;
|
2003-02-03 14:20:24 +00:00
|
|
|
}
|
|
|
|
|
2009-06-14 16:51:48 +00:00
|
|
|
return (DWORD)Status;
|
2003-02-03 14:20:24 +00:00
|
|
|
}
|
|
|
|
|
2004-11-02 21:51:25 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2012-05-23 17:35:25 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetProcessIdOfThread(IN HANDLE Thread)
|
2004-11-02 21:51:25 +00:00
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
THREAD_BASIC_INFORMATION ThreadBasic;
|
|
|
|
NTSTATUS Status;
|
2004-11-02 21:51:25 +00:00
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
Status = NtQueryInformationThread(Thread,
|
|
|
|
ThreadBasicInformation,
|
|
|
|
&ThreadBasic,
|
|
|
|
sizeof(THREAD_BASIC_INFORMATION),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HandleToUlong(ThreadBasic.ClientId.UniqueProcess);
|
2004-11-02 21:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2012-05-23 17:35:25 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetThreadId(IN HANDLE Thread)
|
2004-11-02 21:51:25 +00:00
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
THREAD_BASIC_INFORMATION ThreadBasic;
|
|
|
|
NTSTATUS Status;
|
2004-11-02 21:51:25 +00:00
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
Status = NtQueryInformationThread(Thread,
|
|
|
|
ThreadBasicInformation,
|
|
|
|
&ThreadBasic,
|
|
|
|
sizeof(THREAD_BASIC_INFORMATION),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HandleToUlong(ThreadBasic.ClientId.UniqueThread);
|
2004-11-02 21:51:25 +00:00
|
|
|
}
|
|
|
|
|
2004-11-02 20:42:06 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2012-05-23 17:35:25 +00:00
|
|
|
LANGID
|
|
|
|
WINAPI
|
|
|
|
SetThreadUILanguage(IN LANGID LangId)
|
2004-12-04 19:30:09 +00:00
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
UNIMPLEMENTED;
|
2013-09-14 10:20:11 +00:00
|
|
|
return (LANGID)NtCurrentTeb()->CurrentLocale;
|
2004-12-04 19:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2012-05-23 17:35:25 +00:00
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
QueueUserAPC(IN PAPCFUNC pfnAPC,
|
|
|
|
IN HANDLE hThread,
|
|
|
|
IN ULONG_PTR dwData)
|
2004-12-04 19:30:09 +00:00
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
|
|
|
|
|
|
|
|
/* Zero the activation context and query information on it */
|
|
|
|
RtlZeroMemory(&ActCtxInfo, sizeof(ActCtxInfo));
|
2013-08-29 04:34:00 +00:00
|
|
|
Status = RtlQueryInformationActivationContext(RTL_QUERY_ACTIVATION_CONTEXT_FLAG_USE_ACTIVE_ACTIVATION_CONTEXT,
|
2012-05-23 17:35:25 +00:00
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
ActivationContextBasicInformation,
|
|
|
|
&ActCtxInfo,
|
|
|
|
sizeof(ActCtxInfo),
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Fail due to SxS */
|
|
|
|
DbgPrint("SXS: %s failing because RtlQueryInformationActivationContext()"
|
|
|
|
"returned status %08lx\n", __FUNCTION__, Status);
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-04 19:30:09 +00:00
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/* Queue the APC */
|
|
|
|
Status = NtQueueApcThread(hThread,
|
|
|
|
(PKNORMAL_ROUTINE)BaseDispatchApc,
|
|
|
|
pfnAPC,
|
|
|
|
(PVOID)dwData,
|
|
|
|
(ActCtxInfo.dwFlags & 1) ?
|
|
|
|
INVALID_ACTIVATION_CONTEXT : ActCtxInfo.hActCtx);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-12-04 19:30:09 +00:00
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/* All good */
|
|
|
|
return TRUE;
|
2004-12-04 19:30:09 +00:00
|
|
|
}
|
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/*
|
2018-08-23 19:30:56 +00:00
|
|
|
* @unimplemented
|
2012-05-23 17:35:25 +00:00
|
|
|
*/
|
2011-07-22 02:13:57 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
SetThreadStackGuarantee(IN OUT PULONG StackSizeInBytes)
|
|
|
|
{
|
2018-08-23 19:30:56 +00:00
|
|
|
PTEB Teb = NtCurrentTeb();
|
|
|
|
ULONG GuaranteedStackBytes;
|
|
|
|
ULONG AllocationSize;
|
|
|
|
|
|
|
|
if (!StackSizeInBytes)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
AllocationSize = *StackSizeInBytes;
|
|
|
|
|
|
|
|
/* Retrieve the current stack size */
|
|
|
|
GuaranteedStackBytes = Teb->GuaranteedStackBytes;
|
|
|
|
|
|
|
|
/* Return the size of the previous stack */
|
|
|
|
*StackSizeInBytes = GuaranteedStackBytes;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the new stack size is either zero or is less than the current size,
|
|
|
|
* the previous stack size is returned and we return success.
|
|
|
|
*/
|
|
|
|
if ((AllocationSize == 0) || (AllocationSize < GuaranteedStackBytes))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Unimplemented!
|
|
|
|
UNIMPLEMENTED_ONCE;
|
|
|
|
|
2019-04-29 20:51:35 +00:00
|
|
|
// Temporary HACK for supporting applications!
|
|
|
|
return TRUE; // FALSE;
|
2011-07-22 02:13:57 +00:00
|
|
|
}
|
|
|
|
|
2004-12-09 19:11:07 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2012-05-23 17:35:25 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
GetThreadIOPendingFlag(IN HANDLE hThread,
|
|
|
|
OUT PBOOL lpIOIsPending)
|
2009-07-21 16:38:50 +00:00
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
ULONG IoPending;
|
|
|
|
NTSTATUS Status;
|
2009-07-21 16:38:50 +00:00
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/* Query the flag */
|
|
|
|
Status = NtQueryInformationThread(hThread,
|
|
|
|
ThreadIsIoPending,
|
|
|
|
&IoPending,
|
|
|
|
sizeof(IoPending),
|
|
|
|
NULL);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Return the flag */
|
|
|
|
*lpIOIsPending = IoPending ? TRUE : FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-07-21 16:38:50 +00:00
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/* Fail */
|
|
|
|
BaseSetLastNTError(Status);
|
|
|
|
return FALSE;
|
2009-07-21 16:38:50 +00:00
|
|
|
}
|
|
|
|
|
2006-07-03 20:26:58 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2012-05-23 17:35:25 +00:00
|
|
|
QueueUserWorkItem(IN LPTHREAD_START_ROUTINE Function,
|
|
|
|
IN PVOID Context,
|
|
|
|
IN ULONG Flags)
|
2006-07-03 20:26:58 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/* NOTE: Rtl needs to safely call the function using a trampoline */
|
|
|
|
Status = RtlQueueWorkItem((WORKERCALLBACKFUNC)Function, Context, Flags);
|
2006-07-03 20:26:58 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2012-05-23 17:35:25 +00:00
|
|
|
/* Failed */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2006-07-03 20:26:58 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-23 17:35:25 +00:00
|
|
|
/* All good */
|
2006-07-03 20:26:58 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-20 15:54:21 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
TlsAlloc(VOID)
|
|
|
|
{
|
|
|
|
ULONG Index;
|
2011-07-23 11:28:35 +00:00
|
|
|
PTEB Teb;
|
|
|
|
PPEB Peb;
|
2011-07-20 15:54:21 +00:00
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Get the PEB and TEB, lock the PEB */
|
|
|
|
Teb = NtCurrentTeb();
|
|
|
|
Peb = Teb->ProcessEnvironmentBlock;
|
2011-07-20 15:54:21 +00:00
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Try to get regular TEB slot */
|
|
|
|
Index = RtlFindClearBitsAndSet(Peb->TlsBitmap, 1, 0);
|
|
|
|
if (Index != 0xFFFFFFFF)
|
|
|
|
{
|
|
|
|
/* Clear the value. */
|
|
|
|
Teb->TlsSlots[Index] = 0;
|
|
|
|
RtlReleasePebLock();
|
|
|
|
return Index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it fails, try to find expansion TEB slot. */
|
|
|
|
Index = RtlFindClearBitsAndSet(Peb->TlsExpansionBitmap, 1, 0);
|
|
|
|
if (Index != 0xFFFFFFFF)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Is there no expansion slot yet? */
|
|
|
|
if (!Teb->TlsExpansionSlots)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Allocate an array */
|
|
|
|
Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
TLS_EXPANSION_SLOTS *
|
|
|
|
sizeof(PVOID));
|
|
|
|
}
|
2011-07-20 15:54:21 +00:00
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Did we get an array? */
|
|
|
|
if (!Teb->TlsExpansionSlots)
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
RtlClearBits(Peb->TlsExpansionBitmap, Index, 1);
|
|
|
|
Index = 0xFFFFFFFF;
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(STATUS_NO_MEMORY);
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Clear the value. */
|
|
|
|
Teb->TlsExpansionSlots[Index] = 0;
|
|
|
|
Index += TLS_MINIMUM_AVAILABLE;
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Fail */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(STATUS_NO_MEMORY);
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Release the lock and return */
|
2011-07-20 15:54:21 +00:00
|
|
|
RtlReleasePebLock();
|
|
|
|
return Index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-23 11:28:35 +00:00
|
|
|
TlsFree(IN DWORD Index)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
|
|
|
BOOL BitSet;
|
2011-07-23 11:28:35 +00:00
|
|
|
PPEB Peb;
|
|
|
|
ULONG TlsIndex;
|
|
|
|
PVOID TlsBitmap;
|
|
|
|
NTSTATUS Status;
|
2011-07-20 15:54:21 +00:00
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Acquire the PEB lock and grab the PEB */
|
|
|
|
Peb = NtCurrentPeb();
|
2011-07-20 15:54:21 +00:00
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Check if the index is too high */
|
2011-07-20 15:54:21 +00:00
|
|
|
if (Index >= TLS_MINIMUM_AVAILABLE)
|
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Check if it can fit in the expansion slots */
|
|
|
|
TlsIndex = Index - TLS_MINIMUM_AVAILABLE;
|
|
|
|
if (TlsIndex >= TLS_EXPANSION_SLOTS)
|
|
|
|
{
|
|
|
|
/* It's invalid */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
2011-07-23 11:28:35 +00:00
|
|
|
RtlReleasePebLock();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use the expansion bitmap */
|
|
|
|
TlsBitmap = Peb->TlsExpansionBitmap;
|
|
|
|
Index = TlsIndex;
|
|
|
|
}
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Use the normal bitmap */
|
|
|
|
TlsBitmap = Peb->TlsBitmap;
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Check if the index was set */
|
|
|
|
BitSet = RtlAreBitsSet(TlsBitmap, Index, 1);
|
2011-07-20 15:54:21 +00:00
|
|
|
if (BitSet)
|
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Tell the kernel to free the TLS cells */
|
|
|
|
Status = NtSetInformationThread(NtCurrentThread(),
|
|
|
|
ThreadZeroTlsCell,
|
|
|
|
&Index,
|
|
|
|
sizeof(DWORD));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
2011-07-24 14:57:14 +00:00
|
|
|
RtlReleasePebLock();
|
2011-07-23 11:28:35 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the bit */
|
|
|
|
RtlClearBits(TlsBitmap, Index, 1);
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Fail */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
2011-07-24 14:57:14 +00:00
|
|
|
RtlReleasePebLock();
|
2011-07-23 11:28:35 +00:00
|
|
|
return FALSE;
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Done! */
|
2011-07-24 14:57:14 +00:00
|
|
|
RtlReleasePebLock();
|
2011-07-23 11:28:35 +00:00
|
|
|
return TRUE;
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
LPVOID
|
|
|
|
WINAPI
|
2011-07-23 11:28:35 +00:00
|
|
|
TlsGetValue(IN DWORD Index)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
PTEB Teb;
|
|
|
|
|
|
|
|
/* Get the TEB and clear the last error */
|
|
|
|
Teb = NtCurrentTeb();
|
|
|
|
Teb->LastErrorValue = 0;
|
|
|
|
|
|
|
|
/* Check for simple TLS index */
|
|
|
|
if (Index < TLS_MINIMUM_AVAILABLE)
|
|
|
|
{
|
|
|
|
/* Return it */
|
|
|
|
return Teb->TlsSlots[Index];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for valid index */
|
2011-07-20 15:54:21 +00:00
|
|
|
if (Index >= TLS_EXPANSION_SLOTS + TLS_MINIMUM_AVAILABLE)
|
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Fail */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
2011-07-20 15:54:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* The expansion slots are allocated on demand, so check for it. */
|
|
|
|
Teb->LastErrorValue = 0;
|
|
|
|
if (!Teb->TlsExpansionSlots) return NULL;
|
2011-07-20 15:54:21 +00:00
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Return the value from the expansion slots */
|
|
|
|
return Teb->TlsExpansionSlots[Index - TLS_MINIMUM_AVAILABLE];
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-23 11:28:35 +00:00
|
|
|
TlsSetValue(IN DWORD Index,
|
|
|
|
IN LPVOID Value)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
DWORD TlsIndex;
|
|
|
|
PTEB Teb = NtCurrentTeb();
|
|
|
|
|
|
|
|
/* Check for simple TLS index */
|
|
|
|
if (Index < TLS_MINIMUM_AVAILABLE)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Return it */
|
|
|
|
Teb->TlsSlots[Index] = Value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this is an expansion slot */
|
|
|
|
TlsIndex = Index - TLS_MINIMUM_AVAILABLE;
|
|
|
|
if (TlsIndex >= TLS_EXPANSION_SLOTS)
|
|
|
|
{
|
|
|
|
/* Fail */
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
2011-07-20 15:54:21 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Do we not have expansion slots? */
|
|
|
|
if (!Teb->TlsExpansionSlots)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Get the PEB lock to see if we still need them */
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
if (!Teb->TlsExpansionSlots)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Allocate them */
|
|
|
|
Teb->TlsExpansionSlots = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
TLS_EXPANSION_SLOTS *
|
|
|
|
sizeof(PVOID));
|
|
|
|
if (!Teb->TlsExpansionSlots)
|
2011-07-20 15:54:21 +00:00
|
|
|
{
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Fail */
|
|
|
|
RtlReleasePebLock();
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(STATUS_NO_MEMORY);
|
2011-07-20 15:54:21 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Release the lock */
|
|
|
|
RtlReleasePebLock();
|
2011-07-20 15:54:21 +00:00
|
|
|
}
|
|
|
|
|
2011-07-23 11:28:35 +00:00
|
|
|
/* Write the value */
|
|
|
|
Teb->TlsExpansionSlots[TlsIndex] = Value;
|
|
|
|
|
|
|
|
/* Success */
|
2011-07-20 15:54:21 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-04-14 01:50:38 +00:00
|
|
|
/* EOF */
|