00067 :
00068
00069 This function initializes
the machine dependent context of a thread object.
00070
00071 N.B. This function does not check
the accessibility of
the context record.
00072 It
is assumed
the the caller of
this routine
is either prepared to
00073 handle access violations or has probed and copied
the context record
00074 as appropriate.
00075
00076 Arguments:
00077
00078 Thread - Supplies a pointer to a dispatcher object of
type thread.
00079
00080 SystemRoutine - Supplies a pointer to
the system function that
is to be
00081 called when
the thread
is first scheduled
for execution.
00082
00083 StartRoutine - Supplies an optional pointer to a function that
is to be
00084 called after
the system has finished initializing
the thread. This
00085 parameter
is specified
if the thread
is a system thread and will
00086 execute totally in kernel mode.
00087
00088 StartContext - Supplies an optional pointer to an arbitrary data structure
00089 which will be passed to
the StartRoutine as a parameter. This
00090 parameter
is specified
if the thread
is a system thread and will
00091 execute totally in kernel mode.
00092
00093 ContextRecord - Supplies an optional pointer a context frame which contains
00094
the initial user mode state of
the thread. This parameter
is specified
00095
if the thread
is a user thread and will execute in user mode. If
this
00096 parameter
is not specified, then
the Teb parameter
is ignored.
00097
00098 Return Value:
00099
00100 None.
00101
00102 --*/
00103
00104 {
00105
00106 PKEXCEPTION_FRAME CxFrame;
00107 PKEXCEPTION_FRAME ExFrame;
00108 ULONG_PTR InitialStack;
00109 PKTRAP_FRAME TrFrame;
00110
00111
00112
00113
00114
00115
00116 InitialStack = (ULONG_PTR)Thread->InitialStack;
00117
if (ARGUMENT_PRESENT(ContextRecord)) {
00118 TrFrame = (PKTRAP_FRAME)(((InitialStack) -
00119
sizeof(KTRAP_FRAME)) & ~((ULONG_PTR)15));
00120 ExFrame = (PKEXCEPTION_FRAME)(((ULONG_PTR)TrFrame -
00121
sizeof(KEXCEPTION_FRAME)) & ~((ULONG_PTR)15));
00122 CxFrame = (PKEXCEPTION_FRAME)(((ULONG_PTR)ExFrame -
00123
sizeof(KEXCEPTION_FRAME)) & ~((ULONG_PTR)15));
00124
00125
00126
00127
00128
00129
00130 RtlZeroMemory((PVOID)ExFrame,
sizeof(KEXCEPTION_FRAME));
00131 RtlZeroMemory((PVOID)TrFrame,
sizeof(KTRAP_FRAME));
00132
KeContextToKframes(TrFrame, ExFrame,
00133 ContextRecord,
00134 ContextRecord->ContextFlags | CONTEXT_CONTROL,
00135 UserMode);
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
if (TrFrame->Fpcr == 0) {
00146 ((PFPCR)(&TrFrame->Fpcr))->DynamicRoundingMode = ROUND_TO_NEAREST;
00147 }
00148
00149
00150
00151
00152
00153
00154 TrFrame->PreviousMode =
UserMode;
00155 Thread->PreviousMode =
UserMode;
00156
00157
00158
00159
00160
00161 ExFrame->IntRa = 0;
00162
00163 }
else {
00164 ExFrame =
NULL;
00165 CxFrame = (PKEXCEPTION_FRAME)(((InitialStack) -
00166
sizeof(KEXCEPTION_FRAME)) & ~((ULONG_PTR)15));
00167
00168
00169
00170
00171
00172 Thread->PreviousMode =
KernelMode;
00173 }
00174
00175
00176
00177
00178
00179
00180
00181 CxFrame->SwapReturn = (ULONGLONG)(LONG_PTR)
KiThreadStartup;
00182
if (ExFrame ==
NULL) {
00183 CxFrame->IntFp = (ULONGLONG)(LONG_PTR)ExFrame;
00184
00185 }
else {
00186 CxFrame->IntFp = (ULONGLONG)(LONG_PTR)TrFrame;
00187 }
00188
00189 CxFrame->IntS0 = (ULONGLONG)(LONG_PTR)ContextRecord;
00190 CxFrame->IntS1 = (ULONGLONG)(LONG_PTR)StartContext;
00191 CxFrame->IntS2 = (ULONGLONG)(LONG_PTR)StartRoutine;
00192 CxFrame->IntS3 = (ULONGLONG)(LONG_PTR)SystemRoutine;
00193
00194 CxFrame->Psr = 0;
00195 ((
PSR *)(&CxFrame->Psr))->INTERRUPT_ENABLE = 1;
00196 ((
PSR *)(&CxFrame->Psr))->IRQL =
DISPATCH_LEVEL;
00197 ((
PSR *)(&CxFrame->Psr))->MODE = 0;
00198
00199
00200
00201
00202
00203 Thread->KernelStack = (PVOID)(ULONGLONG)(LONG_PTR)CxFrame;
00204
return;
00205 }