Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencapture.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS kernel 00004 * FILE: lib/ntdll/csr/capture.c 00005 * PURPOSE: Routines for probing and capturing CSR API Messages 00006 * PROGRAMMER: Alex Ionescu (alex@relsoft.net) 00007 */ 00008 00009 /* INCLUDES *****************************************************************/ 00010 00011 #include <ntdll.h> 00012 #define NDEBUG 00013 #include <debug.h> 00014 00015 /* GLOBALS *******************************************************************/ 00016 extern HANDLE CsrPortHeap; 00017 00018 /* FUNCTIONS *****************************************************************/ 00019 00020 /* 00021 * @implemented 00022 */ 00023 VOID 00024 NTAPI 00025 CsrProbeForRead(IN PVOID Address, 00026 IN ULONG Length, 00027 IN ULONG Alignment) 00028 { 00029 volatile UCHAR *Pointer; 00030 UCHAR Data; 00031 00032 /* Validate length */ 00033 if (Length == 0) return; 00034 00035 /* Validate alignment */ 00036 if ((ULONG_PTR)Address & (Alignment - 1)) 00037 { 00038 /* Raise exception if it doesn't match */ 00039 RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT); 00040 } 00041 00042 /* Probe first byte */ 00043 Pointer = Address; 00044 Data = *Pointer; 00045 00046 /* Probe last byte */ 00047 Pointer = (PUCHAR)Address + Length - 1; 00048 Data = *Pointer; 00049 (void)Data; 00050 } 00051 00052 /* 00053 * @implemented 00054 */ 00055 VOID 00056 NTAPI 00057 CsrProbeForWrite(IN PVOID Address, 00058 IN ULONG Length, 00059 IN ULONG Alignment) 00060 { 00061 volatile UCHAR *Pointer; 00062 00063 /* Validate length */ 00064 if (Length == 0) return; 00065 00066 /* Validate alignment */ 00067 if ((ULONG_PTR)Address & (Alignment - 1)) 00068 { 00069 /* Raise exception if it doesn't match */ 00070 RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT); 00071 } 00072 00073 /* Probe first byte */ 00074 Pointer = Address; 00075 *Pointer = *Pointer; 00076 00077 /* Probe last byte */ 00078 Pointer = (PUCHAR)Address + Length - 1; 00079 *Pointer = *Pointer; 00080 } 00081 00082 /* 00083 * @implemented 00084 */ 00085 PVOID 00086 NTAPI 00087 CsrAllocateCaptureBuffer(ULONG ArgumentCount, 00088 ULONG BufferSize) 00089 { 00090 PCSR_CAPTURE_BUFFER CaptureBuffer; 00091 00092 /* Validate size */ 00093 if (BufferSize >= MAXLONG) return NULL; 00094 00095 /* Add the size of the header and for each pointer to the pointers */ 00096 BufferSize += sizeof(CSR_CAPTURE_BUFFER) + (ArgumentCount * sizeof(PVOID)); 00097 00098 /* Allocate memory from the port heap */ 00099 CaptureBuffer = RtlAllocateHeap(CsrPortHeap, 0, BufferSize); 00100 if (CaptureBuffer == NULL) return NULL; 00101 00102 /* Initialize the header */ 00103 CaptureBuffer->Size = BufferSize; 00104 CaptureBuffer->PointerCount = 0; 00105 00106 /* Initialize all the pointers */ 00107 RtlZeroMemory(CaptureBuffer->PointerArray, 00108 ArgumentCount * sizeof(ULONG_PTR)); 00109 00110 /* Point the start of the free buffer */ 00111 CaptureBuffer->BufferEnd = (ULONG_PTR)CaptureBuffer->PointerArray + 00112 ArgumentCount * sizeof(ULONG_PTR); 00113 00114 /* Return the address of the buffer */ 00115 return CaptureBuffer; 00116 } 00117 00118 /* 00119 * @implemented 00120 */ 00121 ULONG 00122 NTAPI 00123 CsrAllocateMessagePointer(PCSR_CAPTURE_BUFFER CaptureBuffer, 00124 ULONG MessageLength, 00125 PVOID *CaptureData) 00126 { 00127 /* If there's no data, our job is easy. */ 00128 if (MessageLength == 0) 00129 { 00130 *CaptureData = NULL; 00131 CaptureData = NULL; 00132 } 00133 else 00134 { 00135 /* Set the capture data at our current available buffer */ 00136 *CaptureData = (PVOID)CaptureBuffer->BufferEnd; 00137 00138 /* Validate the size */ 00139 if (MessageLength >= MAXLONG) return 0; 00140 00141 /* Align it to a 4-byte boundary */ 00142 MessageLength = (MessageLength + 3) & ~3; 00143 00144 /* Move our available buffer beyond this space */ 00145 CaptureBuffer->BufferEnd += MessageLength; 00146 } 00147 00148 /* Write down this pointer in the array */ 00149 CaptureBuffer->PointerArray[CaptureBuffer->PointerCount] = (ULONG_PTR)CaptureData; 00150 00151 /* Increase the pointer count */ 00152 CaptureBuffer->PointerCount++; 00153 00154 /* Return the aligned length */ 00155 return MessageLength; 00156 } 00157 00158 /* 00159 * @implemented 00160 */ 00161 VOID 00162 NTAPI 00163 CsrCaptureMessageBuffer(PCSR_CAPTURE_BUFFER CaptureBuffer, 00164 PVOID MessageString, 00165 ULONG StringLength, 00166 PVOID *CapturedData) 00167 { 00168 /* Simply allocate a message pointer in the buffer */ 00169 CsrAllocateMessagePointer(CaptureBuffer, StringLength, CapturedData); 00170 00171 /* Check if there was any data */ 00172 if (!MessageString || !StringLength) return; 00173 00174 /* Copy the data into the buffer */ 00175 RtlMoveMemory(*CapturedData, MessageString, StringLength); 00176 } 00177 00178 /* 00179 * @implemented 00180 */ 00181 VOID 00182 NTAPI 00183 CsrFreeCaptureBuffer(PCSR_CAPTURE_BUFFER CaptureBuffer) 00184 { 00185 /* Free it from the heap */ 00186 RtlFreeHeap(CsrPortHeap, 0, CaptureBuffer); 00187 } 00188 00189 /* 00190 * @implemented 00191 */ 00192 NTSTATUS 00193 NTAPI 00194 CsrCaptureMessageMultiUnicodeStringsInPlace(IN PCSR_CAPTURE_BUFFER *CaptureBuffer, 00195 IN ULONG MessageCount, 00196 IN PVOID MessageStrings) 00197 { 00198 /* FIXME: allocate a buffer if we don't have one, and return it */ 00199 /* FIXME: call CsrCaptureMessageUnicodeStringInPlace for each string */ 00200 UNIMPLEMENTED; 00201 return STATUS_NOT_IMPLEMENTED; 00202 } 00203 00204 /* 00205 * @implemented 00206 */ 00207 VOID 00208 NTAPI 00209 CsrCaptureMessageString(PCSR_CAPTURE_BUFFER CaptureBuffer, 00210 LPSTR String, 00211 IN ULONG StringLength, 00212 IN ULONG MaximumLength, 00213 OUT PANSI_STRING CapturedString) 00214 { 00215 ULONG ReturnedLength; 00216 00217 /* If we don't have a string, initialize an empty one */ 00218 if (!String) 00219 { 00220 CapturedString->Length = 0; 00221 CapturedString->MaximumLength = (USHORT)MaximumLength; 00222 00223 /* Allocate a pointer for it */ 00224 CsrAllocateMessagePointer(CaptureBuffer, 00225 MaximumLength, 00226 (PVOID*)&CapturedString->Buffer); 00227 return; 00228 } 00229 00230 /* Initialize this string */ 00231 CapturedString->Length = (USHORT)StringLength; 00232 00233 /* Allocate a buffer and get its size */ 00234 ReturnedLength = CsrAllocateMessagePointer(CaptureBuffer, 00235 MaximumLength, 00236 (PVOID*)&CapturedString->Buffer); 00237 CapturedString->MaximumLength = (USHORT)ReturnedLength; 00238 00239 /* If the string had data */ 00240 if (StringLength) 00241 { 00242 /* Copy it into the capture buffer */ 00243 RtlMoveMemory(CapturedString->Buffer, String, MaximumLength); 00244 00245 /* If we don't take up the whole space */ 00246 if (CapturedString->Length < CapturedString->MaximumLength) 00247 { 00248 /* Null-terminate it */ 00249 CapturedString->Buffer[CapturedString->Length] = '\0'; 00250 } 00251 } 00252 } 00253 00254 /* 00255 * @implemented 00256 */ 00257 PLARGE_INTEGER 00258 NTAPI 00259 CsrCaptureTimeout(LONG Milliseconds, 00260 PLARGE_INTEGER Timeout) 00261 { 00262 /* Validate the time */ 00263 if (Milliseconds == -1) return NULL; 00264 00265 /* Convert to relative ticks */ 00266 Timeout->QuadPart = Milliseconds * -100000; 00267 return Timeout; 00268 } 00269 00270 /* EOF */ Generated on Sat May 26 2012 04:20:11 for ReactOS by
1.7.6.1
|