ReactOS  0.4.15-dev-4857-g47842d7
stubs.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Run-Time Library
4  * PURPOSE: AMD64 stubs
5  * FILE: lib/rtl/amd64/stubs.c
6  * PROGRAMMERS: Stefan Ginsberg (stefan.ginsberg@reactos.org)
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include <rtl.h>
12 #define NDEBUG
13 #include <debug.h>
14 #include "amd64/ketypes.h"
15 
16 /* PUBLIC FUNCTIONS **********************************************************/
17 
18 /*
19  * @unimplemented
20  */
21 VOID
22 NTAPI
25  _Out_ PCONTEXT ThreadContext,
26  _In_ PVOID ThreadStartParam OPTIONAL,
27  _In_ PTHREAD_START_ROUTINE ThreadStartAddress,
28  _In_ PINITIAL_TEB StackBase)
29 {
30  /* Initialize everything to 0 */
31  RtlZeroMemory(ThreadContext, sizeof(*ThreadContext));
32 
33  /* Initialize StartAddress and Stack */
34  ThreadContext->Rip = (ULONG64)ThreadStartAddress;
35  ThreadContext->Rsp = (ULONG64)StackBase - 6 * sizeof(PVOID);
36 
37  /* Align stack by 16 and substract 8 (unaligned on function entry) */
38  ThreadContext->Rsp &= ~15;
39  ThreadContext->Rsp -= 8;
40 
41  /* Enable Interrupts */
42  ThreadContext->EFlags = EFLAGS_INTERRUPT_MASK;
43 
44  /* Set start parameter */
45  ThreadContext->Rcx = (ULONG64)ThreadStartParam;
46 
47  /* Set the Selectors */
48  if ((LONG64)ThreadStartAddress < 0)
49  {
50  /* Initialize kernel mode segments */
51  ThreadContext->SegCs = KGDT64_R0_CODE;
52  ThreadContext->SegDs = KGDT64_R3_DATA;
53  ThreadContext->SegEs = KGDT64_R3_DATA;
54  ThreadContext->SegFs = KGDT64_R3_CMTEB;
55  ThreadContext->SegGs = KGDT64_R3_DATA;
56  ThreadContext->SegSs = KGDT64_R0_DATA;
57  }
58  else
59  {
60  /* Initialize user mode segments */
61  ThreadContext->SegCs = KGDT64_R3_CODE | RPL_MASK;
62  ThreadContext->SegDs = KGDT64_R3_DATA | RPL_MASK;
63  ThreadContext->SegEs = KGDT64_R3_DATA | RPL_MASK;
64  ThreadContext->SegFs = KGDT64_R3_CMTEB | RPL_MASK;
65  ThreadContext->SegGs = KGDT64_R3_DATA | RPL_MASK;
66  ThreadContext->SegSs = KGDT64_R3_DATA | RPL_MASK;
67  }
68 
69  /* Only the basic Context is initialized */
70  ThreadContext->ContextFlags = CONTEXT_CONTROL |
73 
74  return;
75 }
76 
78 NTAPI
80  _In_ HANDLE ThreadHandle,
82  _In_opt_ PVOID NormalContext,
85 {
88 }
89 
#define KGDT64_R3_CODE
Definition: ketypes.h:76
#define CONTEXT_CONTROL
Definition: nt_native.h:1369
#define _In_opt_
Definition: ms_sal.h:309
#define _Out_
Definition: ms_sal.h:345
LONG NTSTATUS
Definition: precomp.h:26
#define KGDT64_R3_CMTEB
Definition: ketypes.h:78
#define UNIMPLEMENTED
Definition: stubs.c:20
#define CONTEXT_SEGMENTS
Definition: nt_native.h:1371
ULONG(NTAPI * PTHREAD_START_ROUTINE)(PVOID Parameter)
Definition: rtltypes.h:566
#define _Reserved_
Definition: ms_sal.h:295
return STATUS_NOT_IMPLEMENTED
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define KGDT64_R3_DATA
Definition: ketypes.h:75
#define RPL_MASK
Definition: ketypes.h:69
#define _In_
Definition: ms_sal.h:308
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
int64_t LONG64
Definition: typedefs.h:68
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:719
#define KGDT64_R0_CODE
Definition: ketypes.h:72
unsigned __int64 ULONG64
Definition: imports.h:198
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
VOID NTAPI RtlInitializeContext(_Reserved_ HANDLE ProcessHandle, _Out_ PCONTEXT ThreadContext, _In_ PVOID ThreadStartParam OPTIONAL, _In_ PTHREAD_START_ROUTINE ThreadStartAddress, _In_ PINITIAL_TEB StackBase)
Definition: stubs.c:23
#define KGDT64_R0_DATA
Definition: ketypes.h:73
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#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:684
NTSTATUS NTAPI RtlQueueApcWow64Thread(_In_ HANDLE ThreadHandle, _In_ PKNORMAL_ROUTINE ApcRoutine, _In_opt_ PVOID NormalContext, _In_opt_ PVOID SystemArgument1, _In_opt_ PVOID SystemArgument2)
Definition: stubs.c:79
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68