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

callback.c File Reference

#include "ki.h"

Go to the source code of this file.

Functions

NTSTATUS KeUserModeCallback (IN ULONG ApiNumber, IN PVOID InputBuffer, IN ULONG InputLength, OUT PVOID *OutputBuffer, IN PULONG OutputLength)
NTSTATUS NtW32Call (IN ULONG ApiNumber, IN PVOID InputBuffer, IN ULONG InputLength, OUT PVOID *OutputBuffer, OUT PULONG OutputLength)


Function Documentation

NTSTATUS KeUserModeCallback IN ULONG  ApiNumber,
IN PVOID  InputBuffer,
IN ULONG  InputLength,
OUT PVOID *  OutputBuffer,
IN PULONG  OutputLength
 

Definition at line 28 of file ke/alpha/callback.c.

References ASSERT, EXCEPTION_EXECUTE_HANDLER, KeGdiFlushUserBatch, KeGetCurrentThread, KiCallUserMode(), NTSTATUS(), ProbeForWrite(), Status, UserMode, and ValueBuffer.

00038 : 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 }

NTSTATUS NtW32Call IN ULONG  ApiNumber,
IN PVOID  InputBuffer,
IN ULONG  InputLength,
OUT PVOID *  OutputBuffer,
OUT PULONG  OutputLength
 

Definition at line 143 of file ke/alpha/callback.c.

References ASSERT, EXCEPTION_EXECUTE_HANDLER, KeGetCurrentThread, KeServiceDescriptorTable, KeUserModeCallback(), NT_SUCCESS, NTSTATUS(), ProbeForWriteUlong, Status, UserMode, and ValueBuffer.

00153 : 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:43:02 2004 for test by doxygen 1.3.7