ReactOS 0.4.17-dev-573-g8315b8c
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 */
25VOID
29 _Out_ PCONTEXT ThreadContext,
30 _In_opt_ PVOID ThreadStartParam,
31 _In_ PTHREAD_START_ROUTINE ThreadStartAddress,
32 _In_ PVOID StackBase)
33{
34 DPRINT("RtlInitializeContext: (hProcess: %p, ThreadContext: %p, StackBase: %p\n",
35 ProcessHandle, ThreadContext, StackBase);
36
37 /*
38 * Set the Initial Registers
39 * This is based on NT's default values -- crazy apps might expect this...
40 */
41 ThreadContext->Ebp = 0;
42 ThreadContext->Eax = 0;
43 ThreadContext->Ebx = 1;
44 ThreadContext->Ecx = 2;
45 ThreadContext->Edx = 3;
46 ThreadContext->Esi = 4;
47 ThreadContext->Edi = 5;
48
49 /* Set the Selectors */
50 ThreadContext->SegGs = 0;
51 ThreadContext->SegFs = KGDT_R3_TEB;
52 ThreadContext->SegEs = KGDT_R3_DATA;
53 ThreadContext->SegDs = KGDT_R3_DATA;
54 ThreadContext->SegSs = KGDT_R3_DATA;
55 ThreadContext->SegCs = KGDT_R3_CODE;
56
57 /* Enable Interrupts */
58 ThreadContext->EFlags = EFLAGS_INTERRUPT_MASK;
59
60 /* Settings passed */
61 ThreadContext->Eip = (ULONG)ThreadStartAddress;
62 ThreadContext->Esp = (ULONG)StackBase;
63
64 /* Only the basic Context is initialized */
65 ThreadContext->ContextFlags = CONTEXT_CONTROL |
68
69 /* Set up ESP to the right value */
70 ThreadContext->Esp -= sizeof(PVOID);
72 (PVOID)ThreadContext->Esp,
73 (PVOID)&ThreadStartParam,
74 sizeof(PVOID),
75 NULL);
76
77 /* Push it down one more notch for RETEIP */
78 ThreadContext->Esp -= sizeof(PVOID);
79}
80
84 _In_ HANDLE ThreadHandle,
86 _In_opt_ PVOID NormalContext,
89{
90 return NtQueueApcThread(ThreadHandle,
92 NormalContext,
95}
96
97/* EOF */
#define EFLAGS_INTERRUPT_MASK
#define KGDT_R3_DATA
#define KGDT_R3_CODE
#define KGDT_R3_TEB
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
static ULONG
Definition: thread.c:81
static PVOID
Definition: thread.c:81
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:726
VOID(NTAPI * PKNORMAL_ROUTINE)(IN PVOID NormalContext OPTIONAL, IN PVOID SystemArgument1 OPTIONAL, IN PVOID SystemArgument2 OPTIONAL)
Definition: ketypes.h:888
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:407
NTSYSAPI NTSTATUS NTAPI ZwWriteVirtualMemory(_In_ HANDLE ProcessHandle, _In_ PVOID BaseAddress, _In_ PVOID Buffer, _In_ SIZE_T NumberOfBytesToWrite, _Out_opt_ PSIZE_T NumberOfBytesWritten)
ULONG(NTAPI * PTHREAD_START_ROUTINE)(PVOID Parameter)
Definition: rtltypes.h:560
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
#define CONTEXT_CONTROL
Definition: nt_native.h:1372
#define CONTEXT_INTEGER
Definition: nt_native.h:1373
#define CONTEXT_SEGMENTS
Definition: nt_native.h:1374
NTSTATUS NTAPI NtQueueApcThread(IN HANDLE ThreadHandle, IN PKNORMAL_ROUTINE ApcRoutine, IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: state.c:600
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:83
VOID NTAPI RtlInitializeContext(_In_ HANDLE ProcessHandle, _Out_ PCONTEXT ThreadContext, _In_opt_ PVOID ThreadStartParam, _In_ PTHREAD_START_ROUTINE ThreadStartAddress, _In_ PVOID StackBase)
Definition: thread.c:27
#define DPRINT
Definition: sndvol32.h:73
#define NTAPI
Definition: typedefs.h:36
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:756
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:757