ReactOS  0.4.15-dev-1197-g8081ba9
thredsup.c File Reference
#include <srv.h>
#include <debug.h>
Include dependency graph for thredsup.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define CsrHashThread(t)   (HandleToUlong(t) % NUMBER_THREAD_HASH_BUCKETS)
 

Functions

BOOLEAN NTAPI ProtectHandle (IN HANDLE ObjectHandle)
 
BOOLEAN NTAPI UnProtectHandle (IN HANDLE ObjectHandle)
 
PCSR_THREAD NTAPI CsrAllocateThread (IN PCSR_PROCESS CsrProcess)
 
VOID NTAPI CsrLockedReferenceThread (IN PCSR_THREAD CsrThread)
 
PCSR_THREAD NTAPI CsrLocateThreadByClientId (OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
 
PCSR_THREAD NTAPI CsrLocateThreadInProcess (IN PCSR_PROCESS CsrProcess OPTIONAL, IN PCLIENT_ID Cid)
 
NTSTATUS NTAPI CsrInsertThread (IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
 
VOID NTAPI CsrDeallocateThread (IN PCSR_THREAD CsrThread)
 
VOID NTAPI CsrRemoveThread (IN PCSR_THREAD CsrThread)
 
VOID NTAPI CsrThreadRefcountZero (IN PCSR_THREAD CsrThread)
 
VOID NTAPI CsrLockedDereferenceThread (IN PCSR_THREAD CsrThread)
 
PCSR_THREAD NTAPI CsrAddStaticServerThread (IN HANDLE hThread, IN PCLIENT_ID ClientId, IN ULONG ThreadFlags)
 
NTSTATUS NTAPI CsrCreateRemoteThread (IN HANDLE hThread, IN PCLIENT_ID ClientId)
 
NTSTATUS NTAPI CsrCreateThread (IN PCSR_PROCESS CsrProcess, IN HANDLE hThread, IN PCLIENT_ID ClientId, IN BOOLEAN HaveClient)
 
VOID NTAPI CsrDereferenceThread (IN PCSR_THREAD CsrThread)
 
NTSTATUS NTAPI CsrDestroyThread (IN PCLIENT_ID Cid)
 
NTSTATUS NTAPI CsrExecServerThread (IN PVOID ThreadHandler, IN ULONG Flags)
 
NTSTATUS NTAPI CsrLockThreadByClientId (IN HANDLE Tid, OUT PCSR_THREAD *CsrThread)
 
VOID NTAPI CsrReferenceThread (IN PCSR_THREAD CsrThread)
 
NTSTATUS NTAPI CsrUnlockThread (IN PCSR_THREAD CsrThread)
 

Variables

LIST_ENTRY CsrThreadHashTable [NUMBER_THREAD_HASH_BUCKETS]
 

Macro Definition Documentation

◆ CsrHashThread

#define CsrHashThread (   t)    (HandleToUlong(t) % NUMBER_THREAD_HASH_BUCKETS)

Definition at line 17 of file thredsup.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file thredsup.c.

Function Documentation

◆ CsrAddStaticServerThread()

PCSR_THREAD NTAPI CsrAddStaticServerThread ( IN HANDLE  hThread,
IN PCLIENT_ID  ClientId,
IN ULONG  ThreadFlags 
)

Definition at line 511 of file thredsup.c.

514 {
515  PCSR_THREAD CsrThread;
516 
517  /* Get the Lock */
519 
520  /* Allocate the Server Thread */
521  CsrThread = CsrAllocateThread(CsrRootProcess);
522  if (CsrThread)
523  {
524  /* Setup the Object */
525  CsrThread->ThreadHandle = hThread;
527  CsrThread->ClientId = *ClientId;
528  CsrThread->Flags = ThreadFlags;
529 
530  /* Insert it into the Thread List */
532 
533  /* Increment the thread count */
535  }
536  else
537  {
538  DPRINT1("CsrAddStaticServerThread: alloc failed for thread 0x%x\n", hThread);
539  }
540 
541  /* Release the Process Lock and return */
543  return CsrThread;
544 }
LIST_ENTRY Link
Definition: csrsrv.h:66
#define InsertTailList(ListHead, Entry)
#define CsrReleaseProcessLock()
Definition: api.h:15
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
ULONG ThreadCount
Definition: csrsrv.h:55
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
CLIENT_ID ClientId
Definition: csrsrv.h:68
HANDLE ThreadHandle
Definition: csrsrv.h:71
#define CsrAcquireProcessLock()
Definition: api.h:12
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
HANDLE hThread
Definition: wizard.c:27
#define DPRINT1
Definition: precomp.h:8
ULONG Flags
Definition: csrsrv.h:72
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119

Referenced by CsrApiPortInitialize(), CsrpCheckRequestThreads(), CsrSbApiPortInitialize(), and GuiInit().

◆ CsrAllocateThread()

PCSR_THREAD NTAPI CsrAllocateThread ( IN PCSR_PROCESS  CsrProcess)

Definition at line 119 of file thredsup.c.

120 {
121  PCSR_THREAD CsrThread;
122 
123  /* Allocate the structure */
124  CsrThread = RtlAllocateHeap(CsrHeap, HEAP_ZERO_MEMORY, sizeof(CSR_THREAD));
125  if (!CsrThread) return NULL;
126 
127  /* Reference the Thread and Process */
128  CsrLockedReferenceThread(CsrThread);
130 
131  /* Set the Parent Process */
132  CsrThread->Process = CsrProcess;
133 
134  /* Return Thread */
135  return CsrThread;
136 }
VOID NTAPI CsrLockedReferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:154
PKPROCESS CsrProcess
Definition: videoprt.c:39
PCSR_PROCESS Process
Definition: csrsrv.h:69
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
VOID NTAPI CsrLockedReferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:232
HANDLE CsrHeap
Definition: init.c:25

Referenced by CsrAddStaticServerThread(), CsrCreateProcess(), CsrCreateRemoteThread(), CsrCreateThread(), CsrExecServerThread(), and CsrSbCreateSession().

◆ CsrCreateRemoteThread()

NTSTATUS NTAPI CsrCreateRemoteThread ( IN HANDLE  hThread,
IN PCLIENT_ID  ClientId 
)

Definition at line 568 of file thredsup.c.

570 {
572  HANDLE ThreadHandle;
573  PCSR_THREAD CsrThread;
575  KERNEL_USER_TIMES KernelTimes;
576 
577  /* Get the Thread Create Time */
579  ThreadTimes,
580  &KernelTimes,
581  sizeof(KernelTimes),
582  NULL);
583  if (!NT_SUCCESS(Status))
584  {
585  DPRINT1("Failed to query thread times: %lx\n", Status);
586  return Status;
587  }
588 
589  /* Lock the Owner Process */
591  if (!NT_SUCCESS(Status))
592  {
593  DPRINT1("No known process for %lx\n", ClientId->UniqueProcess);
594  return Status;
595  }
596 
597  /* Make sure the thread didn't terminate */
598  if (KernelTimes.ExitTime.QuadPart)
599  {
600  /* Unlock the process and return */
602  DPRINT1("Dead thread: %I64x\n", KernelTimes.ExitTime.QuadPart);
604  }
605 
606  /* Allocate a CSR Thread Structure */
607  CsrThread = CsrAllocateThread(CsrProcess);
608  if (!CsrThread)
609  {
610  DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
612  return STATUS_NO_MEMORY;
613  }
614 
615  /* Duplicate the Thread Handle */
617  hThread,
619  &ThreadHandle,
620  0,
621  0,
623  /* Allow failure */
624  if (!NT_SUCCESS(Status))
625  {
626  DPRINT1("Thread duplication failed: %lx\n", Status);
627  ThreadHandle = hThread;
628  }
629 
630  /* Save the data we have */
631  CsrThread->CreateTime = KernelTimes.CreateTime;
632  CsrThread->ClientId = *ClientId;
633  CsrThread->ThreadHandle = ThreadHandle;
634  ProtectHandle(ThreadHandle);
635  CsrThread->Flags = 0;
636 
637  /* Insert the Thread into the Process */
638  Status = CsrInsertThread(CsrProcess, CsrThread);
639  if (!NT_SUCCESS(Status))
640  {
641  /* Bail out */
642  if (CsrThread->ThreadHandle != hThread) NtClose(CsrThread->ThreadHandle);
644  CsrDeallocateThread(CsrThread);
645  return Status;
646  }
647 
648  /* Release the lock and return */
650  return STATUS_SUCCESS;
651 }
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
LONG NTSTATUS
Definition: precomp.h:26
PKPROCESS CsrProcess
Definition: videoprt.c:39
HANDLE UniqueProcess
Definition: compat.h:573
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
LARGE_INTEGER ExitTime
Definition: winternl.h:1061
#define DUPLICATE_SAME_ACCESS
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI CsrLockProcessByClientId(IN HANDLE Pid, OUT PCSR_PROCESS *CsrProcess OPTIONAL)
#define NtCurrentProcess()
Definition: nt_native.h:1657
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
LARGE_INTEGER CreateTime
Definition: csrsrv.h:65
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID ClientId
Definition: csrsrv.h:68
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2501
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
HANDLE ThreadHandle
Definition: csrsrv.h:71
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
HANDLE hThread
Definition: wizard.c:27
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI NtDuplicateObject(IN HANDLE SourceProcessHandle, IN HANDLE SourceHandle, IN HANDLE TargetProcessHandle OPTIONAL, OUT PHANDLE TargetHandle OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG HandleAttributes, IN ULONG Options)
Definition: obhandle.c:3407
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define __FUNCTION__
Definition: types.h:112
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1409
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by CreateRemoteThread().

◆ CsrCreateThread()

NTSTATUS NTAPI CsrCreateThread ( IN PCSR_PROCESS  CsrProcess,
IN HANDLE  hThread,
IN PCLIENT_ID  ClientId,
IN BOOLEAN  HaveClient 
)

Definition at line 677 of file thredsup.c.

681 {
683  PCSR_THREAD CsrThread, CurrentThread;
685  CLIENT_ID CurrentCid;
686  KERNEL_USER_TIMES KernelTimes;
687 
688  if (HaveClient)
689  {
690  /* Get the current thread and CID */
691  CurrentThread = CsrGetClientThread();
692  CurrentCid = CurrentThread->ClientId;
693 
694  /* Acquire the Process Lock */
696 
697  /* Get the current Process and make sure the Thread is valid with this CID */
698  CurrentThread = CsrLocateThreadByClientId(&CurrentProcess, &CurrentCid);
699 
700  /* Something is wrong if we get an empty thread back */
701  if (!CurrentThread)
702  {
703  DPRINT1("CSRSRV: %s: invalid thread!\n", __FUNCTION__);
706  }
707  }
708  else
709  {
710  /* Acquire the Process Lock */
712  }
713 
714  /* Get the Thread Create Time */
716  ThreadTimes,
717  &KernelTimes,
718  sizeof(KernelTimes),
719  NULL);
720  if (!NT_SUCCESS(Status))
721  {
723  return Status;
724  }
725 
726  /* Allocate a CSR Thread Structure */
727  CsrThread = CsrAllocateThread(CsrProcess);
728  if (!CsrThread)
729  {
730  DPRINT1("CSRSRV: %s: out of memory!\n", __FUNCTION__);
732  return STATUS_NO_MEMORY;
733  }
734 
735  /* Save the data we have */
736  CsrThread->CreateTime = KernelTimes.CreateTime;
737  CsrThread->ClientId = *ClientId;
738  CsrThread->ThreadHandle = hThread;
740  CsrThread->Flags = 0;
741 
742  /* Insert the Thread into the Process */
743  Status = CsrInsertThread(CsrProcess, CsrThread);
744  if (!NT_SUCCESS(Status))
745  {
746  /* Bail out */
748  CsrDeallocateThread(CsrThread);
749  return Status;
750  }
751 
752  /* Release the lock and return */
754 
755  return STATUS_SUCCESS;
756 }
#define CsrGetClientThread()
Definition: csrsrv.h:77
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
LONG NTSTATUS
Definition: precomp.h:26
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
smooth NULL
Definition: ftsmooth.c:416
ULONG CurrentProcess
Definition: shell.c:125
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
LARGE_INTEGER CreateTime
Definition: csrsrv.h:65
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID ClientId
Definition: csrsrv.h:68
LARGE_INTEGER CreateTime
Definition: winternl.h:1060
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2501
HANDLE ThreadHandle
Definition: csrsrv.h:71
#define CsrAcquireProcessLock()
Definition: api.h:12
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
HANDLE hThread
Definition: wizard.c:27
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI CsrInsertThread(IN PCSR_PROCESS Process, IN PCSR_THREAD Thread)
Definition: thredsup.c:297
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define __FUNCTION__
Definition: types.h:112
NTSTATUS NTAPI CsrUnlockProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:1409
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119

Referenced by CSR_API().

◆ CsrDeallocateThread()

VOID NTAPI CsrDeallocateThread ( IN PCSR_THREAD  CsrThread)

Definition at line 345 of file thredsup.c.

346 {
347  /* Free the process object from the heap */
348  // ASSERT(CsrThread->WaitBlock == NULL);
349  RtlFreeHeap(CsrHeap, 0, CsrThread);
350 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
HANDLE CsrHeap
Definition: init.c:25

Referenced by CsrCreateProcess(), CsrCreateRemoteThread(), CsrCreateThread(), CsrExecServerThread(), CsrSbCreateSession(), and CsrThreadRefcountZero().

◆ CsrDereferenceThread()

VOID NTAPI CsrDereferenceThread ( IN PCSR_THREAD  CsrThread)

Definition at line 775 of file thredsup.c.

776 {
777  /* Acquire process lock */
779 
780  /* Decrease reference count */
781  ASSERT(CsrThread->ReferenceCount > 0);
782  if ((--CsrThread->ReferenceCount) == 0)
783  {
784  /* Call the generic cleanup code */
785  CsrThreadRefcountZero(CsrThread);
786  }
787  else
788  {
789  /* Just release the lock */
791  }
792 }
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:424
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12

Referenced by CsrApiRequestThread(), CsrDereferenceWait(), CsrNotifyWaitBlock(), GuiConsoleInputThread(), and NotifyUserProcessForShutdown().

◆ CsrDestroyThread()

NTSTATUS NTAPI CsrDestroyThread ( IN PCLIENT_ID  Cid)

Definition at line 813 of file thredsup.c.

814 {
815  CLIENT_ID ClientId = *Cid;
816  PCSR_THREAD CsrThread;
818 
819  /* Acquire lock */
821 
822  /* Find the thread */
824  &ClientId);
825 
826  /* Make sure we got one back, and that it's not already gone */
827  if (!CsrThread || (CsrThread->Flags & CsrThreadTerminated))
828  {
829  /* Release the lock and return failure */
832  }
833 
834  /* Set the terminated flag */
835  CsrThread->Flags |= CsrThreadTerminated;
836 
837  /* Acquire the Wait Lock */
839 
840  /* Do we have an active wait block? */
841  if (CsrThread->WaitBlock)
842  {
843  /* Notify waiters of termination */
844  CsrNotifyWaitBlock(CsrThread->WaitBlock,
845  NULL,
846  NULL,
847  NULL,
849  TRUE);
850  }
851 
852  /* Release the Wait Lock */
854 
855  /* Dereference the thread */
856  CsrLockedDereferenceThread(CsrThread);
857 
858  /* Release the Process Lock and return success */
860  return STATUS_SUCCESS;
861 }
BOOLEAN NTAPI CsrNotifyWaitBlock(IN PCSR_WAIT_BLOCK WaitBlock, IN PLIST_ENTRY WaitList, IN PVOID WaitArgument1, IN PVOID WaitArgument2, IN ULONG WaitFlags, IN BOOLEAN DereferenceThread)
Definition: wait.c:120
#define TRUE
Definition: types.h:120
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define CsrReleaseWaitLock()
Definition: api.h:24
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467
smooth NULL
Definition: ftsmooth.c:416
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
#define CsrAcquireProcessLock()
Definition: api.h:12
#define CsrAcquireWaitLock()
Definition: api.h:21
struct _CSR_WAIT_BLOCK * WaitBlock
Definition: csrsrv.h:70
PCSR_THREAD NTAPI CsrLocateThreadByClientId(OUT PCSR_PROCESS *Process OPTIONAL, IN PCLIENT_ID ClientId)
Definition: thredsup.c:182
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CsrApiRequestThread().

◆ CsrExecServerThread()

NTSTATUS NTAPI CsrExecServerThread ( IN PVOID  ThreadHandler,
IN ULONG  Flags 
)

Definition at line 885 of file thredsup.c.

887 {
888  PCSR_THREAD CsrThread;
889  HANDLE hThread;
892 
893  /* Acquire process lock */
895 
896  /* Allocate a CSR Thread in the Root Process */
898  CsrThread = CsrAllocateThread(CsrRootProcess);
899  if (!CsrThread)
900  {
901  /* Fail */
903  return STATUS_NO_MEMORY;
904  }
905 
906  /* Create the Thread */
908  NULL,
909  FALSE,
910  0,
911  0,
912  0,
913  ThreadHandler,
914  NULL,
915  &hThread,
916  &ClientId);
917  if (!NT_SUCCESS(Status))
918  {
919  /* Fail */
920  CsrDeallocateThread(CsrThread);
922  return Status;
923  }
924 
925  /* Setup the Thread Object */
926  CsrThread->ThreadHandle = hThread;
928  CsrThread->ClientId = ClientId;
929  CsrThread->Flags = Flags;
930 
931  /* Insert it into the Thread List */
933 
934  /* Increase the thread count */
936 
937  /* Return */
939  return Status;
940 }
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY Link
Definition: csrsrv.h:66
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
ULONG ThreadCount
Definition: csrsrv.h:55
#define NtCurrentProcess()
Definition: nt_native.h:1657
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CLIENT_ID ClientId
Definition: csrsrv.h:68
HANDLE ThreadHandle
Definition: csrsrv.h:71
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlCreateUserThread(_In_ PVOID ThreadContext, _Out_ HANDLE *OutThreadHandle, _Reserved_ PVOID Reserved1, _Reserved_ PVOID Reserved2, _Reserved_ PVOID Reserved3, _Reserved_ PVOID Reserved4, _Reserved_ PVOID Reserved5, _Reserved_ PVOID Reserved6, _Reserved_ PVOID Reserved7, _Reserved_ PVOID Reserved8)
LIST_ENTRY ThreadList
Definition: csrsrv.h:40
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
HANDLE hThread
Definition: wizard.c:27
ULONG Flags
Definition: csrsrv.h:72
BOOLEAN NTAPI ProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:39
PCSR_THREAD NTAPI CsrAllocateThread(IN PCSR_PROCESS CsrProcess)
Definition: thredsup.c:119

Referenced by CSR_API().

◆ CsrInsertThread()

NTSTATUS NTAPI CsrInsertThread ( IN PCSR_PROCESS  Process,
IN PCSR_THREAD  Thread 
)

Definition at line 297 of file thredsup.c.

299 {
300  ULONG i;
303  // ASSERT(ProcessStructureListLocked());
304 
305  /* Make sure the thread isn't already dead by the time we got this */
306  Status = NtQueryInformationThread(Thread->ThreadHandle,
308  &ThreadInfo,
309  sizeof(ThreadInfo),
310  NULL);
311  if (!NT_SUCCESS(Status)) return Status;
313 
314  /* Insert it into the Regular List */
315  InsertTailList(&Process->ThreadList, &Thread->Link);
316 
317  /* Increase Thread Count */
318  Process->ThreadCount++;
319 
320  /* Hash the Thread */
321  i = CsrHashThread(Thread->ClientId.UniqueThread);
322 
323  /* Insert it there too */
324  InsertHeadList(&CsrThreadHashTable[i], &Thread->HashLinks);
325  return STATUS_SUCCESS;
326 }
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
LONG NTSTATUS
Definition: precomp.h:26
struct _ThreadInfo ThreadInfo
#define InsertTailList(ListHead, Entry)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CsrHashThread(t)
Definition: thredsup.c:17
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2501
Status
Definition: gdiplustypes.h:24
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by CsrCreateProcess(), CsrCreateRemoteThread(), CsrCreateThread(), and CsrSbCreateSession().

◆ CsrLocateThreadByClientId()

PCSR_THREAD NTAPI CsrLocateThreadByClientId ( OUT PCSR_PROCESS *Process  OPTIONAL,
IN PCLIENT_ID  ClientId 
)

Definition at line 182 of file thredsup.c.

184 {
185  ULONG i;
186  PLIST_ENTRY ListHead, NextEntry;
187  PCSR_THREAD FoundThread;
188  // ASSERT(ProcessStructureListLocked());
189 
190  if (Process) *Process = NULL;
191 
192  /* Hash the Thread */
194 
195  /* Set the list pointers */
196  ListHead = &CsrThreadHashTable[i];
197  NextEntry = ListHead->Flink;
198 
199  /* Star the loop */
200  while (NextEntry != ListHead)
201  {
202  /* Get the thread */
203  FoundThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, HashLinks);
204 
205  /* Move to the next entry */
206  NextEntry = NextEntry->Flink;
207 
208  /* Compare the CID */
209  // if (*(PULONGLONG)&FoundThread->ClientId == *(PULONGLONG)ClientId)
210  if ( FoundThread->ClientId.UniqueProcess == ClientId->UniqueProcess &&
211  FoundThread->ClientId.UniqueThread == ClientId->UniqueThread )
212  {
213  /* Match found, return the process */
214  if (Process) *Process = FoundThread->Process;
215 
216  /* Return thread too */
217  return FoundThread;
218  }
219  }
220 
221  /* Nothing found */
222  return NULL;
223 }
HANDLE UniqueProcess
Definition: compat.h:573
PCSR_PROCESS Process
Definition: csrsrv.h:69
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1163
CLIENT_ID ClientId
Definition: csrsrv.h:68
#define CsrHashThread(t)
Definition: thredsup.c:17
HANDLE UniqueThread
Definition: compat.h:574
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21
Definition: typedefs.h:119
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1

Referenced by CsrApiHandleConnectionRequest(), CsrApiRequestThread(), CsrCreateProcess(), CsrCreateThread(), CsrDestroyProcess(), and CsrDestroyThread().

◆ CsrLocateThreadInProcess()

PCSR_THREAD NTAPI CsrLocateThreadInProcess ( IN PCSR_PROCESS CsrProcess  OPTIONAL,
IN PCLIENT_ID  Cid 
)

Definition at line 248 of file thredsup.c.

250 {
251  PLIST_ENTRY ListHead, NextEntry;
252  PCSR_THREAD FoundThread = NULL;
253 
254  /* Use the Root Process if none was specified */
256 
257  /* Save the List pointers */
258  ListHead = &CsrProcess->ThreadList;
259  NextEntry = ListHead->Flink;
260 
261  /* Start the Loop */
262  while (NextEntry != ListHead)
263  {
264  /* Get Thread Entry */
265  FoundThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
266 
267  /* Check for TID Match */
268  if (FoundThread->ClientId.UniqueThread == Cid->UniqueThread) break;
269 
270  /* Move to the next entry */
271  NextEntry = NextEntry->Flink;
272  }
273 
274  /* Return what we found */
275  return FoundThread;
276 }
PKPROCESS CsrProcess
Definition: videoprt.c:39
static int Link(const char **args)
Definition: vfdcmd.c:2414
PCSR_PROCESS CsrRootProcess
Definition: procsup.c:22
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
CLIENT_ID ClientId
Definition: csrsrv.h:68
HANDLE UniqueThread
Definition: compat.h:574
Definition: typedefs.h:119

Referenced by CsrConnectToUser().

◆ CsrLockedDereferenceThread()

VOID NTAPI CsrLockedDereferenceThread ( IN PCSR_THREAD  CsrThread)

Definition at line 467 of file thredsup.c.

468 {
469  LONG LockCount;
470 
471  /* Decrease reference count */
472  LockCount = --CsrThread->ReferenceCount;
473  ASSERT(LockCount >= 0);
474  if (LockCount == 0)
475  {
476  /* Call the generic cleanup code */
478  CsrThreadRefcountZero(CsrThread);
479  }
480 }
LONG LockCount
Definition: comsup.c:6
long LONG
Definition: pedump.c:60
VOID NTAPI CsrThreadRefcountZero(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:424
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12

Referenced by CsrApiRequestThread(), CsrDestroyProcess(), CsrDestroyThread(), and CsrUnlockThread().

◆ CsrLockedReferenceThread()

VOID NTAPI CsrLockedReferenceThread ( IN PCSR_THREAD  CsrThread)

Definition at line 154 of file thredsup.c.

155 {
156  /* Increment the reference count */
157  ++CsrThread->ReferenceCount;
158 }

Referenced by CsrAllocateThread(), CsrApiRequestThread(), and CsrLockThreadByClientId().

◆ CsrLockThreadByClientId()

NTSTATUS NTAPI CsrLockThreadByClientId ( IN HANDLE  Tid,
OUT PCSR_THREAD CsrThread 
)

Definition at line 964 of file thredsup.c.

966 {
967  PLIST_ENTRY NextEntry;
968  PCSR_THREAD CurrentThread = NULL;
970  ULONG i;
971 
972  /* Acquire the lock */
974 
975  /* Assume failure */
976  ASSERT(CsrThread != NULL);
977  *CsrThread = NULL;
978 
979  /* Convert to Hash */
980  i = CsrHashThread(Tid);
981 
982  /* Setup the List Pointers */
983  NextEntry = CsrThreadHashTable[i].Flink;
984 
985  /* Start Loop */
986  while (NextEntry != &CsrThreadHashTable[i])
987  {
988  /* Get the Thread */
989  CurrentThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, HashLinks);
990 
991  /* Check for TID Match */
992  if ((CurrentThread->ClientId.UniqueThread == Tid) &&
993  (CurrentThread->Flags & CsrThreadTerminated) == 0)
994  {
995  /* Get out of here */
996  break;
997  }
998 
999  /* Move to the next entry */
1000  NextEntry = NextEntry->Flink;
1001  }
1002 
1003  /* Nothing found if we got back to the list */
1004  if (NextEntry == &CsrThreadHashTable[i]) CurrentThread = NULL;
1005 
1006  /* Did the loop find something? */
1007  if (CurrentThread)
1008  {
1009  /* Reference the found thread */
1011  CsrLockedReferenceThread(CurrentThread);
1012  *CsrThread = CurrentThread;
1013  }
1014  else
1015  {
1016  /* Nothing found, release the lock */
1019  }
1020 
1021  /* Return the status */
1022  return Status;
1023 }
VOID NTAPI CsrLockedReferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:154
LONG NTSTATUS
Definition: precomp.h:26
#define CsrReleaseProcessLock()
Definition: api.h:15
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
CLIENT_ID ClientId
Definition: csrsrv.h:68
#define CsrHashThread(t)
Definition: thredsup.c:17
HANDLE UniqueThread
Definition: compat.h:574
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define CsrAcquireProcessLock()
Definition: api.h:12
Status
Definition: gdiplustypes.h:24
LIST_ENTRY CsrThreadHashTable[NUMBER_THREAD_HASH_BUCKETS]
Definition: thredsup.c:21
Definition: typedefs.h:119
unsigned int ULONG
Definition: retypes.h:1
ULONG Flags
Definition: csrsrv.h:72
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by GetThreadConsoleDesktop().

◆ CsrReferenceThread()

VOID NTAPI CsrReferenceThread ( IN PCSR_THREAD  CsrThread)

Definition at line 1042 of file thredsup.c.

1043 {
1044  /* Acquire process lock */
1046 
1047  /* Sanity checks */
1048  ASSERT((CsrThread->Flags & CsrThreadTerminated) == 0);
1049  ASSERT(CsrThread->ReferenceCount != 0);
1050 
1051  /* Increment reference count */
1052  CsrThread->ReferenceCount++;
1053 
1054  /* Release the lock */
1056 }
#define CsrReleaseProcessLock()
Definition: api.h:15
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CsrAcquireProcessLock()
Definition: api.h:12

Referenced by NotifyUserProcessForShutdown().

◆ CsrRemoveThread()

VOID NTAPI CsrRemoveThread ( IN PCSR_THREAD  CsrThread)

Definition at line 373 of file thredsup.c.

374 {
376 
377  /* Remove it from the List */
378  RemoveEntryList(&CsrThread->Link);
379 
380  /* Decreate the thread count of the process */
381  CsrThread->Process->ThreadCount--;
382 
383  /* Remove it from the Hash List as well */
384  if (CsrThread->HashLinks.Flink) RemoveEntryList(&CsrThread->HashLinks);
385 
386  /* Check if this is the last Thread */
387  if (CsrThread->Process->ThreadCount == 0)
388  {
389  /* Check if it's not already been marked for deletion */
390  if ((CsrThread->Process->Flags & CsrProcessLastThreadTerminated) == 0)
391  {
392  /* Let everyone know this process is about to lose the thread */
393  CsrThread->Process->Flags |= CsrProcessLastThreadTerminated;
394 
395  /* Reference the Process */
396  CsrLockedDereferenceProcess(CsrThread->Process);
397  }
398  }
399 
400  /* Mark the thread for deletion */
401  CsrThread->Flags |= CsrThreadInTermination;
402 }
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define ProcessStructureListLocked()
Definition: api.h:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI CsrLockedDereferenceProcess(PCSR_PROCESS CsrProcess)
Definition: procsup.c:159

Referenced by CsrThreadRefcountZero().

◆ CsrThreadRefcountZero()

VOID NTAPI CsrThreadRefcountZero ( IN PCSR_THREAD  CsrThread)

Definition at line 424 of file thredsup.c.

425 {
426  PCSR_PROCESS CsrProcess = CsrThread->Process;
429 
430  /* Remove this thread */
431  CsrRemoveThread(CsrThread);
432 
433  /* Release the Process Lock */
435 
436  /* Close the NT Thread Handle */
437  if (CsrThread->ThreadHandle)
438  {
439  UnProtectHandle(CsrThread->ThreadHandle);
440  Status = NtClose(CsrThread->ThreadHandle);
442  }
443 
444  /* De-allocate the CSR Thread Object */
445  CsrDeallocateThread(CsrThread);
446 
447  /* Remove a reference from the process */
449 }
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI CsrDereferenceProcess(IN PCSR_PROCESS CsrProcess)
Definition: procsup.c:690
PKPROCESS CsrProcess
Definition: videoprt.c:39
#define CsrReleaseProcessLock()
Definition: api.h:15
VOID NTAPI CsrDeallocateThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:345
#define ProcessStructureListLocked()
Definition: api.h:18
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI UnProtectHandle(IN HANDLE ObjectHandle)
Definition: thredsup.c:78
VOID NTAPI CsrRemoveThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:373

Referenced by CsrDereferenceThread(), and CsrLockedDereferenceThread().

◆ CsrUnlockThread()

NTSTATUS NTAPI CsrUnlockThread ( IN PCSR_THREAD  CsrThread)

Definition at line 1074 of file thredsup.c.

1075 {
1076  /* Dereference the Thread */
1078  CsrLockedDereferenceThread(CsrThread);
1079 
1080  /* Release the lock and return */
1082  return STATUS_SUCCESS;
1083 }
#define CsrReleaseProcessLock()
Definition: api.h:15
#define ProcessStructureListLocked()
Definition: api.h:18
VOID NTAPI CsrLockedDereferenceThread(IN PCSR_THREAD CsrThread)
Definition: thredsup.c:467
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by GetThreadConsoleDesktop().

◆ ProtectHandle()

BOOLEAN NTAPI ProtectHandle ( IN HANDLE  ObjectHandle)

Definition at line 39 of file thredsup.c.

40 {
43 
44  /* Query current state */
45  Status = NtQueryObject(ObjectHandle,
46  ObjectHandleFlagInformation,
47  &HandleInfo,
48  sizeof(HandleInfo),
49  NULL);
50  if (NT_SUCCESS(Status))
51  {
52  /* Enable protect from close */
53  HandleInfo.ProtectFromClose = TRUE;
54  Status = NtSetInformationObject(ObjectHandle,
55  ObjectHandleFlagInformation,
56  &HandleInfo,
57  sizeof(HandleInfo));
58  if (NT_SUCCESS(Status)) return TRUE;
59  }
60 
61  /* We failed to or set the state */
62  return FALSE;
63 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI NtSetInformationObject(IN HANDLE ObjectHandle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, IN PVOID ObjectInformation, IN ULONG Length)
Definition: oblife.c:1735
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NtQueryObject(IN HANDLE Handle, IN OBJECT_INFO_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OUT PULONG ReturnLength)
Status
Definition: gdiplustypes.h:24

Referenced by CsrAddStaticServerThread(), CsrCreateProcess(), CsrCreateRemoteThread(), CsrCreateThread(), CsrExecServerThread(), and CsrSbCreateSession().

◆ UnProtectHandle()

BOOLEAN NTAPI UnProtectHandle ( IN HANDLE  ObjectHandle)

Definition at line 78 of file thredsup.c.

79 {
82 
83  /* Query current state */
84  Status = NtQueryObject(ObjectHandle,
85  ObjectHandleFlagInformation,
86  &HandleInfo,
87  sizeof(HandleInfo),
88  NULL);
89  if (NT_SUCCESS(Status))
90  {
91  /* Disable protect from close */
92  HandleInfo.ProtectFromClose = FALSE;
93  Status = NtSetInformationObject(ObjectHandle,
94  ObjectHandleFlagInformation,
95  &HandleInfo,
96  sizeof(HandleInfo));
97  if (NT_SUCCESS(Status)) return TRUE;
98  }
99 
100  /* We failed to or set the state */
101  return FALSE;
102 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI NtSetInformationObject(IN HANDLE ObjectHandle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, IN PVOID ObjectInformation, IN ULONG Length)
Definition: oblife.c:1735
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NtQueryObject(IN HANDLE Handle, IN OBJECT_INFO_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OUT PULONG ReturnLength)
Status
Definition: gdiplustypes.h:24

Referenced by CsrThreadRefcountZero().

Variable Documentation

◆ CsrThreadHashTable