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

callback.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1994 Microsoft Corporation 00004 00005 Module Name: 00006 00007 callback.c 00008 00009 Abstract: 00010 00011 This module implements stubs for the user mode call back services. 00012 00013 Author: 00014 00015 David N. Cutler (davec) 29-Oct-1994 00016 00017 Environment: 00018 00019 Kernel mode only. 00020 00021 Revision History: 00022 00023 --*/ 00024 00025 #include "ki.h" 00026 00027 NTSTATUS 00028 KeUserModeCallback ( 00029 IN ULONG ApiNumber, 00030 IN PVOID InputBuffer, 00031 IN ULONG InputLength, 00032 OUT PVOID *OutputBuffer, 00033 IN PULONG OutputLength 00034 ) 00035 00036 /*++ 00037 00038 Routine Description: 00039 00040 This function call out from kernel mode to a user mode function. 00041 00042 Arguments: 00043 00044 ApiNumber - Supplies the API number. 00045 00046 InputBuffer - Supplies a pointer to a structure that is copied 00047 to the user stack. 00048 00049 InputLength - Supplies the length of the input structure. 00050 00051 Outputbuffer - Supplies a pointer to a variable that receives 00052 the address of the output buffer. 00053 00054 Outputlength - Supplies a pointer to a variable that receives 00055 the length of the output buffer. 00056 00057 Return Value: 00058 00059 If the callout cannot be executed, then an error status is 00060 returned. Otherwise, the status returned by the callback function 00061 is returned. 00062 00063 --*/ 00064 00065 { 00066 00067 PUCALLOUT_FRAME CalloutFrame; 00068 ULONG Length; 00069 ULONGLONG OldStack; 00070 NTSTATUS Status; 00071 PKTRAP_FRAME TrapFrame; 00072 PVOID ValueBuffer; 00073 ULONG ValueLength; 00074 00075 ASSERT(KeGetPreviousMode() == UserMode); 00076 00077 // 00078 // Get the user mode stack pointer and attempt to copy input buffer 00079 // to the user stack. 00080 // 00081 00082 TrapFrame = KeGetCurrentThread()->TrapFrame; 00083 OldStack = TrapFrame->IntSp; 00084 try { 00085 00086 // 00087 // Compute new user mode stack address, probe for writability, 00088 // and copy the input buffer to the user stack. 00089 // 00090 // N.B. Alpha requires stacks to be 16-byte aligned, therefore 00091 // the input length must be rounded up to a 16-byte boundary. 00092 // 00093 00094 Length = (InputLength + 00095 16 - 1 + sizeof(UCALLOUT_FRAME)) & ~(16 - 1); 00096 00097 CalloutFrame = (PUCALLOUT_FRAME)(OldStack - Length); 00098 ProbeForWrite(CalloutFrame, Length, sizeof(QUAD)); 00099 RtlCopyMemory(CalloutFrame + 1, InputBuffer, InputLength); 00100 00101 // 00102 // Allocate stack frame and fill in callout arguments. 00103 // 00104 00105 CalloutFrame->Buffer = (PVOID)(CalloutFrame + 1); 00106 CalloutFrame->Length = InputLength; 00107 CalloutFrame->ApiNumber = ApiNumber; 00108 CalloutFrame->Sp = OldStack; 00109 CalloutFrame->Ra = TrapFrame->IntRa; 00110 00111 // 00112 // If an exception occurs during the probe of the user stack, then 00113 // always handle the exception and return the exception code as the 00114 // status value. 00115 // 00116 00117 } except (EXCEPTION_EXECUTE_HANDLER) { 00118 return GetExceptionCode(); 00119 } 00120 00121 // 00122 // Call user mode. 00123 // 00124 00125 TrapFrame->IntSp = (ULONGLONG)(LONG_PTR)CalloutFrame; 00126 Status = KiCallUserMode(OutputBuffer, OutputLength); 00127 00128 // 00129 // When returning from user mode, any drawing done to the GDI TEB 00130 // batch must be flushed. 00131 // 00132 00133 if (((PTEB)KeGetCurrentThread()->Teb)->GdiBatchCount > 0) { 00134 TrapFrame->IntSp -= 256; 00135 KeGdiFlushUserBatch(); 00136 } 00137 00138 TrapFrame->IntSp = OldStack; 00139 return Status; 00140 } 00141 00142 NTSTATUS 00143 NtW32Call ( 00144 IN ULONG ApiNumber, 00145 IN PVOID InputBuffer, 00146 IN ULONG InputLength, 00147 OUT PVOID *OutputBuffer, 00148 OUT PULONG OutputLength 00149 ) 00150 00151 /*++ 00152 00153 Routine Description: 00154 00155 This function calls a W32 function. 00156 00157 Arguments: 00158 00159 ApiNumber - Supplies the API number. 00160 00161 InputBuffer - Supplies a pointer to a structure that is copied to 00162 the user stack. 00163 00164 InputLength - Supplies the length of the input structure. 00165 00166 Outputbuffer - Supplies a pointer to a variable that recevies the 00167 output buffer address. 00168 00169 Outputlength - Supplies a pointer to a variable that recevies the 00170 output buffer length. 00171 00172 Return Value: 00173 00174 TBS. 00175 00176 --*/ 00177 00178 { 00179 00180 PVOID ValueBuffer; 00181 ULONG ValueLength; 00182 NTSTATUS Status; 00183 00184 ASSERT(KeGetPreviousMode() == UserMode); 00185 00186 // 00187 // If the current thread is not a GUI thread, then fail the service 00188 // since the thread does not have a large stack. 00189 // 00190 00191 if (KeGetCurrentThread()->Win32Thread == (PVOID)&KeServiceDescriptorTable[0]) { 00192 return STATUS_NOT_IMPLEMENTED; 00193 } 00194 00195 // 00196 // Probe the output buffer address and length for writeability. 00197 // 00198 00199 try { 00200 ProbeForWriteUlong((PULONG)OutputBuffer); 00201 ProbeForWriteUlong(OutputLength); 00202 00203 // 00204 // If an exception occurs during the probe of the output buffer or 00205 // length, then always handle the exception and return the exception 00206 // code as the status value. 00207 // 00208 00209 } except(EXCEPTION_EXECUTE_HANDLER) { 00210 return GetExceptionCode(); 00211 } 00212 00213 // 00214 // Call out to user mode specifying the input buffer and API number. 00215 // 00216 00217 Status = KeUserModeCallback(ApiNumber, 00218 InputBuffer, 00219 InputLength, 00220 &ValueBuffer, 00221 &ValueLength); 00222 00223 // 00224 // If the callout is successful, then the output buffer address and 00225 // length. 00226 // 00227 00228 if (NT_SUCCESS(Status)) { 00229 try { 00230 *OutputBuffer = ValueBuffer; 00231 *OutputLength = ValueLength; 00232 00233 } except(EXCEPTION_EXECUTE_HANDLER) { 00234 } 00235 } 00236 00237 return Status; 00238 }

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