ReactOS  0.4.14-dev-833-g5f692ed
thread.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * PURPOSE: Rtl user thread functions
5  * FILE: lib/rtl/i386/thread.c
6  * PROGRAMERS:
7  * Alex Ionescu (alex@relsoft.net)
8  * Eric Kohl
9  * KJK::Hyperion
10  */
11 
12 /* INCLUDES *****************************************************************/
13 
14 #include <rtl.h>
15 #include "i386/ketypes.h"
16 
17 #define NDEBUG
18 #include <debug.h>
19 
20 /* PRIVATE FUNCTIONS *******************************************************/
21 
22 /*
23  * @implemented
24  */
25 VOID
26 NTAPI
28  OUT PCONTEXT ThreadContext,
29  IN PVOID ThreadStartParam OPTIONAL,
30  IN PTHREAD_START_ROUTINE ThreadStartAddress,
31  IN PINITIAL_TEB InitialTeb)
32 {
33  DPRINT("RtlInitializeContext: (hProcess: %p, ThreadContext: %p, Teb: %p\n",
34  ProcessHandle, ThreadContext, InitialTeb);
35 
36  /*
37  * Set the Initial Registers
38  * This is based on NT's default values -- crazy apps might expect this...
39  */
40  ThreadContext->Ebp = 0;
41  ThreadContext->Eax = 0;
42  ThreadContext->Ebx = 1;
43  ThreadContext->Ecx = 2;
44  ThreadContext->Edx = 3;
45  ThreadContext->Esi = 4;
46  ThreadContext->Edi = 5;
47 
48  /* Set the Selectors */
49  ThreadContext->SegGs = 0;
50  ThreadContext->SegFs = KGDT_R3_TEB;
51  ThreadContext->SegEs = KGDT_R3_DATA;
52  ThreadContext->SegDs = KGDT_R3_DATA;
53  ThreadContext->SegSs = KGDT_R3_DATA;
54  ThreadContext->SegCs = KGDT_R3_CODE;
55 
56  /* Enable Interrupts */
57  ThreadContext->EFlags = EFLAGS_INTERRUPT_MASK;
58 
59  /* Settings passed */
60  ThreadContext->Eip = (ULONG)ThreadStartAddress;
61  ThreadContext->Esp = (ULONG)InitialTeb;
62 
63  /* Only the basic Context is initialized */
64  ThreadContext->ContextFlags = CONTEXT_CONTROL |
67 
68  /* Set up ESP to the right value */
69  ThreadContext->Esp -= sizeof(PVOID);
71  (PVOID)ThreadContext->Esp,
72  (PVOID)&ThreadStartParam,
73  sizeof(PVOID),
74  NULL);
75 
76  /* Push it down one more notch for RETEIP */
77  ThreadContext->Esp -= sizeof(PVOID);
78 }
79 
81 NTAPI
83  _In_ HANDLE ThreadHandle,
85  _In_opt_ PVOID NormalContext,
88 {
89  return NtQueueApcThread(ThreadHandle,
90  ApcRoutine,
91  NormalContext,
94 }
95 
96 /* EOF */
NTSTATUS NTAPI RtlQueueApcWow64Thread(_In_ HANDLE ThreadHandle, _In_ PKNORMAL_ROUTINE ApcRoutine, _In_opt_ PVOID NormalContext, _In_opt_ PVOID SystemArgument1, _In_opt_ PVOID SystemArgument2)
Definition: thread.c:82
static ULONG
Definition: thread.c:83
#define CONTEXT_CONTROL
Definition: nt_native.h:1369
#define IN
Definition: typedefs.h:38
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI RtlInitializeContext(IN HANDLE ProcessHandle, OUT PCONTEXT ThreadContext, IN PVOID ThreadStartParam OPTIONAL, IN PTHREAD_START_ROUTINE ThreadStartAddress, IN PINITIAL_TEB InitialTeb)
Definition: thread.c:27
static PVOID
Definition: thread.c:83
NTSTATUS NTAPI NtQueueApcThread(IN HANDLE ThreadHandle, IN PKNORMAL_ROUTINE ApcRoutine, IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: state.c:600
#define CONTEXT_SEGMENTS
Definition: nt_native.h:1371
#define _In_opt_
Definition: no_sal2.h:213
ULONG(NTAPI * PTHREAD_START_ROUTINE)(PVOID Parameter)
Definition: rtltypes.h:562
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define KGDT_R3_DATA
Definition: ketypes.h:78
NTSYSAPI NTSTATUS NTAPI ZwWriteVirtualMemory(_In_ HANDLE ProcessHandle, _In_ PVOID BaseAddress, _In_ PVOID Buffer, _In_ SIZE_T NumberOfBytesToWrite, _Out_opt_ PSIZE_T NumberOfBytesWritten)
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
#define KGDT_R3_TEB
Definition: ketypes.h:81
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:719
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
#define _In_
Definition: no_sal2.h:204
#define KGDT_R3_CODE
Definition: ketypes.h:77
#define OUT
Definition: typedefs.h:39
#define CONTEXT_INTEGER
Definition: nt_native.h:1370
VOID(NTAPI * PKNORMAL_ROUTINE)(IN PVOID NormalContext OPTIONAL, IN PVOID SystemArgument1 OPTIONAL, IN PVOID SystemArgument2 OPTIONAL)
Definition: ketypes.h:632
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68