ReactOS 0.4.16-dev-197-g92996da
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
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
83 _In_ HANDLE ThreadHandle,
85 _In_opt_ PVOID NormalContext,
88{
89 return NtQueueApcThread(ThreadHandle,
91 NormalContext,
94}
95
96/* EOF */
#define EFLAGS_INTERRUPT_MASK
Definition: SystemCall.c:11
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
static ULONG
Definition: thread.c:78
static PVOID
Definition: thread.c:78
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
#define KGDT_R3_DATA
Definition: ketypes.h:126
#define KGDT_R3_CODE
Definition: ketypes.h:125
#define KGDT_R3_TEB
Definition: ketypes.h:129
_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:744
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
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:566
#define CONTEXT_CONTROL
Definition: nt_native.h:1369
#define CONTEXT_INTEGER
Definition: nt_native.h:1370
#define CONTEXT_SEGMENTS
Definition: nt_native.h:1371
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:82
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
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:688
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:689