Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

apcuser.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1990 Microsoft Corporation 00004 00005 Module Name: 00006 00007 apcuser.c 00008 00009 Abstract: 00010 00011 This module implements the machine dependent code necessary to initialize 00012 a user mode APC. 00013 00014 Author: 00015 00016 David N. Cutler (davec) 23-Apr-1990 00017 00018 Environment: 00019 00020 Kernel mode only, IRQL APC_LEVEL. 00021 00022 Revision History: 00023 00024 Thomas Van Baak (tvb) 13-May-1992 00025 00026 Adapted for Alpha AXP. 00027 00028 --*/ 00029 00030 #include "ki.h" 00031 00032 VOID 00033 KiInitializeUserApc ( 00034 IN PKEXCEPTION_FRAME ExceptionFrame, 00035 IN PKTRAP_FRAME TrapFrame, 00036 IN PKNORMAL_ROUTINE NormalRoutine, 00037 IN PVOID NormalContext, 00038 IN PVOID SystemArgument1, 00039 IN PVOID SystemArgument2 00040 ) 00041 00042 /*++ 00043 00044 Routine Description: 00045 00046 This function is called to initialize the context for a user mode APC. 00047 00048 Arguments: 00049 00050 ExceptionFrame - Supplies a pointer to an exception frame. 00051 00052 TrapFrame - Supplies a pointer to a trap frame. 00053 00054 NormalRoutine - Supplies a pointer to the user mode APC routine. 00055 00056 NormalContext - Supplies a pointer to the user context for the APC 00057 routine. 00058 00059 SystemArgument1 - Supplies the first system supplied value. 00060 00061 SystemArgument2 - Supplies the second system supplied value. 00062 00063 Return Value: 00064 00065 None. 00066 00067 --*/ 00068 00069 { 00070 00071 CONTEXT ContextRecord; 00072 EXCEPTION_RECORD ExceptionRecord; 00073 LONG_PTR Length; 00074 ULONG_PTR UserStack; 00075 00076 // 00077 // Move the user mode state from the trap and exception frames to the 00078 // context frame. 00079 // 00080 00081 ContextRecord.ContextFlags = CONTEXT_FULL; 00082 KeContextFromKframes(TrapFrame, ExceptionFrame, &ContextRecord); 00083 00084 // 00085 // Transfer the context information to the user stack, initialize the 00086 // APC routine parameters, and modify the trap frame so execution will 00087 // continue in user mode at the user mode APC dispatch routine. 00088 // 00089 00090 try { 00091 00092 // 00093 // Compute length of context record and new aligned user stack pointer. 00094 // 00095 00096 Length = (sizeof(CONTEXT) + 15) & (~15); 00097 UserStack = ((ULONG_PTR)ContextRecord.IntSp & (~15)) - Length; 00098 00099 // 00100 // Probe user stack area for writeability and then transfer the 00101 // context record to the user stack. 00102 // 00103 00104 ProbeForWrite((PVOID)UserStack, (ULONG)Length, sizeof(QUAD)); 00105 RtlMoveMemory((PVOID)UserStack, &ContextRecord, sizeof(CONTEXT)); 00106 00107 // 00108 // Set the address of the user APC routine, the APC parameters, the 00109 // new frame pointer, and the new stack pointer in the current trap 00110 // frame. Set the continuation address so control will be transferred 00111 // to the user APC dispatcher. 00112 // 00113 // N.B. It is not possible to pass 64 bit arguments to the routine. 00114 // N.B. ULONG becomes canonical longword with (ULONGLONG)(LONG) cast. 00115 // 00116 // 00117 00118 TrapFrame->IntSp = (ULONGLONG)(LONG_PTR)UserStack; 00119 TrapFrame->IntFp = (ULONGLONG)(LONG_PTR)UserStack; 00120 TrapFrame->IntA0 = (ULONGLONG)(LONG_PTR)NormalContext; 00121 TrapFrame->IntA1 = (ULONGLONG)(LONG_PTR)SystemArgument1; 00122 TrapFrame->IntA2 = (ULONGLONG)(LONG_PTR)SystemArgument2; 00123 TrapFrame->IntA3 = (ULONGLONG)(LONG_PTR)NormalRoutine; 00124 TrapFrame->Fir = (ULONGLONG)(LONG_PTR)KeUserApcDispatcher; 00125 00126 // 00127 // If an exception occurs, then copy the exception information to an 00128 // exception record and handle the exception. 00129 // 00130 00131 } except (KiCopyInformation(&ExceptionRecord, 00132 (GetExceptionInformation())->ExceptionRecord)) { 00133 00134 // 00135 // Set the address of the exception to the current program address 00136 // and raise the exception by calling the exception dispatcher. 00137 // 00138 00139 ExceptionRecord.ExceptionAddress = (PVOID)(TrapFrame->Fir); 00140 KiDispatchException(&ExceptionRecord, 00141 ExceptionFrame, 00142 TrapFrame, 00143 UserMode, 00144 TRUE); 00145 } 00146 00147 return; 00148 }

Generated on Sat May 15 19:39:15 2004 for test by doxygen 1.3.7