00040 :
00041
00042 This function
is called to initialize
the context
for a user mode APC.
00043
00044 Arguments:
00045
00046 ExceptionFrame - Supplies a pointer to an exception frame.
00047
00048 TrapFrame - Supplies a pointer to a trap frame.
00049
00050 NormalRoutine - Supplies a pointer to
the user mode APC routine.
00051
00052 NormalContext - Supplies a pointer to
the user context
for the APC
00053 routine.
00054
00055 SystemArgument1 - Supplies
the first system supplied value.
00056
00057 SystemArgument2 - Supplies
the second system supplied value.
00058
00059 Return Value:
00060
00061 None.
00062
00063 --*/
00064
00065 {
00066
00067 EXCEPTION_RECORD ExceptionRecord;
00068 CONTEXT ContextFrame;
00069 LONG Length;
00070 ULONG UserStack;
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
if (TrapFrame->EFlags & EFLAGS_V86_MASK) {
00081
return ;
00082 }
00083
00084
00085
00086
00087
00088 ContextFrame.ContextFlags =
CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
00089
KeContextFromKframes(TrapFrame, ExceptionFrame, &ContextFrame);
00090
00091
00092
00093
00094
00095
00096
00097
00098
try {
00099
ASSERT((TrapFrame->SegCs & MODE_MASK) != KernelMode);
00100
00101
00102
00103
00104
00105 Length = ((
sizeof(CONTEXT) + CONTEXT_ROUND) &
00106 ~CONTEXT_ROUND) +
sizeof(
KAPC_RECORD);
00107 UserStack = (ContextFrame.Esp & ~CONTEXT_ROUND) - Length;
00108
00109
00110
00111
00112
00113
00114
ProbeForWrite((PCHAR)UserStack, Length, CONTEXT_ALIGN);
00115 RtlMoveMemory((PULONG)(UserStack + (
sizeof(
KAPC_RECORD))),
00116 &ContextFrame,
sizeof(CONTEXT));
00117
00118
00119
00120
00121
00122 TrapFrame->SegCs = SANITIZE_SEG(KGDT_R3_CODE, UserMode);
00123 TrapFrame->HardwareSegSs = SANITIZE_SEG(KGDT_R3_DATA, UserMode);
00124 TrapFrame->SegDs = SANITIZE_SEG(KGDT_R3_DATA, UserMode);
00125 TrapFrame->SegEs = SANITIZE_SEG(KGDT_R3_DATA, UserMode);
00126 TrapFrame->SegFs = SANITIZE_SEG(KGDT_R3_TEB, UserMode);
00127 TrapFrame->SegGs = 0;
00128 TrapFrame->EFlags = SANITIZE_FLAGS( ContextFrame.EFlags, UserMode );
00129
00130
00131
00132
00133
00134
if (
KeGetCurrentThread()->Iopl) {
00135 TrapFrame->EFlags |= (EFLAGS_IOPL_MASK & -1);
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145 TrapFrame->HardwareEsp = UserStack;
00146 TrapFrame->Eip = (ULONG)
KeUserApcDispatcher;
00147 TrapFrame->ErrCode = 0;
00148 *((PULONG)UserStack)++ = (ULONG)NormalRoutine;
00149 *((PULONG)UserStack)++ = (ULONG)NormalContext;
00150 *((PULONG)UserStack)++ = (ULONG)SystemArgument1;
00151 *((PULONG)UserStack)++ = (ULONG)SystemArgument2;
00152 } except (
KiCopyInformation(&ExceptionRecord,
00153 (GetExceptionInformation())->ExceptionRecord)) {
00154
00155
00156
00157
00158
00159
00160 ExceptionRecord.ExceptionAddress = (PVOID)(TrapFrame->Eip);
00161
KiDispatchException(&ExceptionRecord,
00162 ExceptionFrame,
00163 TrapFrame,
00164 UserMode,
00165 TRUE);
00166 }
00167
return;
00168 }
}