Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenutil.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/io/iomgr/util.c 00005 * PURPOSE: I/O Utility Functions 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 * Aleksey Bragin (aleksey@reactos.org) 00008 * Daniel Zimmerman (netzimme@aim.com) 00009 */ 00010 00011 /* INCLUDES *****************************************************************/ 00012 00013 #include <ntoskrnl.h> 00014 #define NDEBUG 00015 #include <debug.h> 00016 00017 VOID 00018 NTAPI 00019 RtlpGetStackLimits(PULONG_PTR StackBase, 00020 PULONG_PTR StackLimit); 00021 00022 /* FUNCTIONS *****************************************************************/ 00023 00024 /* 00025 * @implemented 00026 */ 00027 VOID 00028 NTAPI 00029 IoAcquireCancelSpinLock(OUT PKIRQL Irql) 00030 { 00031 /* Just acquire the internal lock */ 00032 *Irql = KeAcquireQueuedSpinLock(LockQueueIoCancelLock); 00033 } 00034 00035 /* 00036 * @implemented 00037 */ 00038 PVOID 00039 NTAPI 00040 IoGetInitialStack(VOID) 00041 { 00042 /* Return the initial stack from the TCB */ 00043 return PsGetCurrentThread()->Tcb.InitialStack; 00044 } 00045 00046 /* 00047 * @implemented 00048 */ 00049 VOID 00050 NTAPI 00051 IoGetStackLimits(OUT PULONG_PTR LowLimit, 00052 OUT PULONG_PTR HighLimit) 00053 { 00054 PKPRCB Prcb = KeGetCurrentPrcb(); 00055 ULONG_PTR DpcStack = (ULONG_PTR)(Prcb->DpcStack); 00056 volatile ULONG_PTR StackAddress; 00057 00058 /* Save our stack address so we always know it's valid */ 00059 StackAddress = (ULONG_PTR)(&StackAddress); 00060 00061 /* Get stack values */ 00062 RtlpGetStackLimits(LowLimit, HighLimit); 00063 00064 /* Check if we're outside the stack */ 00065 if ((StackAddress < *LowLimit) || (StackAddress > *HighLimit)) 00066 { 00067 /* Check if we may be in a DPC */ 00068 if (KeGetCurrentIrql() >= DISPATCH_LEVEL) 00069 { 00070 /* Check if we really are in a DPC */ 00071 if ((Prcb->DpcRoutineActive) && 00072 (StackAddress <= DpcStack) && 00073 (StackAddress >= DpcStack - KERNEL_STACK_SIZE)) 00074 { 00075 /* Use the DPC stack limits */ 00076 *HighLimit = DpcStack; 00077 *LowLimit = DpcStack - KERNEL_STACK_SIZE; 00078 } 00079 } 00080 } 00081 } 00082 00083 /* 00084 * @implemented 00085 */ 00086 BOOLEAN 00087 NTAPI 00088 IoIsSystemThread(IN PETHREAD Thread) 00089 { 00090 /* Call the Ps Function */ 00091 return PsIsSystemThread(Thread); 00092 } 00093 00094 /* 00095 * @implemented 00096 */ 00097 BOOLEAN 00098 NTAPI 00099 IoIsWdmVersionAvailable(IN UCHAR MajorVersion, 00100 IN UCHAR MinorVersion) 00101 { 00102 /* Return support for WDM 1.10 (Windows 2000) */ 00103 if (MajorVersion <= 1 && MinorVersion <= 0x10) return TRUE; 00104 return FALSE; 00105 } 00106 00107 /* 00108 * @implemented 00109 */ 00110 PEPROCESS 00111 NTAPI 00112 IoGetCurrentProcess(VOID) 00113 { 00114 /* Return the current thread's process */ 00115 return (PEPROCESS)PsGetCurrentThread()->Tcb.ApcState.Process; 00116 } 00117 00118 /* 00119 * @implemented 00120 */ 00121 VOID 00122 NTAPI 00123 IoReleaseCancelSpinLock(IN KIRQL Irql) 00124 { 00125 /* Release the internal lock */ 00126 KeReleaseQueuedSpinLock(LockQueueIoCancelLock, Irql); 00127 } 00128 00129 /* 00130 * @implemented 00131 */ 00132 PEPROCESS 00133 NTAPI 00134 IoThreadToProcess(IN PETHREAD Thread) 00135 { 00136 /* Return the thread's process */ 00137 return Thread->ThreadsProcess; 00138 } 00139 00140 /* 00141 * @implemented 00142 */ 00143 NTSTATUS 00144 NTAPI 00145 IoCheckDesiredAccess(IN OUT PACCESS_MASK DesiredAccess, 00146 IN ACCESS_MASK GrantedAccess) 00147 { 00148 PAGED_CODE(); 00149 00150 /* Map the generic mask */ 00151 RtlMapGenericMask(DesiredAccess, 00152 &IoFileObjectType->TypeInfo.GenericMapping); 00153 00154 /* Fail if the access masks don't grant full access */ 00155 if ((~(*DesiredAccess) & GrantedAccess)) return STATUS_ACCESS_DENIED; 00156 return STATUS_SUCCESS; 00157 } 00158 00159 /* 00160 * @implemented 00161 */ 00162 NTSTATUS 00163 NTAPI 00164 IoCheckEaBufferValidity(IN PFILE_FULL_EA_INFORMATION EaBuffer, 00165 IN ULONG EaLength, 00166 OUT PULONG ErrorOffset) 00167 { 00168 PFILE_FULL_EA_INFORMATION EaBufferEnd; 00169 ULONG NextEaBufferOffset; 00170 LONG IntEaLength; 00171 00172 PAGED_CODE(); 00173 00174 /* Lenght of the rest. Inital equal to EaLength */ 00175 IntEaLength = EaLength; 00176 00177 /* Inital EaBuffer equal to EaBuffer */ 00178 EaBufferEnd = EaBuffer; 00179 00180 /* The rest length of the buffer */ 00181 while (IntEaLength >= FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName[0])) 00182 { 00183 /* rest of buffer must greater then the 00184 sizeof(FILE_FULL_EA_INFORMATION) + buffer */ 00185 NextEaBufferOffset = 00186 EaBufferEnd->EaNameLength + EaBufferEnd->EaValueLength + 00187 FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName[0]) + 1; 00188 00189 if ((ULONG)IntEaLength >= NextEaBufferOffset) 00190 { 00191 /* is the EaBufferName terminated with zero? */ 00192 if (EaBufferEnd->EaName[EaBufferEnd->EaNameLength]==0) 00193 { 00194 /* more EaBuffers ahead */ 00195 if (EaBufferEnd->NextEntryOffset == 0) 00196 { 00197 /* test the rest buffersize */ 00198 IntEaLength = IntEaLength - NextEaBufferOffset; 00199 if (IntEaLength >= 0) 00200 { 00201 return STATUS_SUCCESS; 00202 } 00203 } 00204 else 00205 { 00206 /* From the MSDN 00207 http://msdn2.microsoft.com/en-us/library/ms795740.aspx 00208 For all entries except the last, the value of 00209 NextEntryOffset must be greater than zero and 00210 must fall on a ULONG boundary 00211 */ 00212 NextEaBufferOffset = ((NextEaBufferOffset + 3) & ~3); 00213 if ((EaBufferEnd->NextEntryOffset == NextEaBufferOffset) && 00214 ((LONG)EaBufferEnd->NextEntryOffset > 0)) 00215 { 00216 /* Rest of buffer must be greater then the 00217 next offset */ 00218 IntEaLength = 00219 IntEaLength - EaBufferEnd->NextEntryOffset; 00220 00221 if (IntEaLength >= 0) 00222 { 00223 EaBufferEnd = (PFILE_FULL_EA_INFORMATION) 00224 ((ULONG_PTR)EaBufferEnd + 00225 EaBufferEnd->NextEntryOffset); 00226 continue; 00227 } 00228 } 00229 } 00230 } 00231 } 00232 break; 00233 } 00234 00235 if (ErrorOffset != NULL) 00236 { 00237 /* Calculate the error offset */ 00238 *ErrorOffset = (ULONG)((ULONG_PTR)EaBufferEnd - (ULONG_PTR)EaBuffer); 00239 } 00240 00241 return STATUS_EA_LIST_INCONSISTENT; 00242 } 00243 00244 /* 00245 * @unimplemented 00246 */ 00247 NTSTATUS 00248 NTAPI 00249 IoCheckFunctionAccess(IN ACCESS_MASK GrantedAccess, 00250 IN UCHAR MajorFunction, 00251 IN UCHAR MinorFunction, 00252 IN ULONG IoControlCode, 00253 IN PVOID ExtraData OPTIONAL, 00254 IN PVOID ExtraData2 OPTIONAL) 00255 { 00256 UNIMPLEMENTED; 00257 return STATUS_NOT_IMPLEMENTED; 00258 } 00259 00260 /* 00261 * @unimplemented 00262 */ 00263 NTSTATUS 00264 NTAPI 00265 IoValidateDeviceIoControlAccess(IN PIRP Irp, 00266 IN ULONG RequiredAccess) 00267 { 00268 UNIMPLEMENTED; 00269 return STATUS_NOT_IMPLEMENTED; 00270 } 00271 00272 /* 00273 * @implemented 00274 */ 00275 VOID 00276 NTAPI 00277 IoSetDeviceToVerify(IN PETHREAD Thread, 00278 IN PDEVICE_OBJECT DeviceObject) 00279 { 00280 /* Set the pointer in the thread */ 00281 Thread->DeviceToVerify = DeviceObject; 00282 } 00283 00284 /* 00285 * @implemented 00286 */ 00287 VOID 00288 NTAPI 00289 IoSetHardErrorOrVerifyDevice(IN PIRP Irp, 00290 IN PDEVICE_OBJECT DeviceObject) 00291 { 00292 /* Set the pointer in the IRP */ 00293 Irp->Tail.Overlay.Thread->DeviceToVerify = DeviceObject; 00294 } 00295 00296 /* 00297 * @implemented 00298 */ 00299 PDEVICE_OBJECT 00300 NTAPI 00301 IoGetDeviceToVerify(IN PETHREAD Thread) 00302 { 00303 /* Return the pointer that was set with IoSetDeviceToVerify */ 00304 return Thread->DeviceToVerify; 00305 } 00306 00307 /* 00308 * @unimplemented 00309 */ 00310 NTSTATUS 00311 NTAPI 00312 IoCheckQuerySetVolumeInformation(IN FS_INFORMATION_CLASS FsInformationClass, 00313 IN ULONG Length, 00314 IN BOOLEAN SetOperation) 00315 { 00316 UNIMPLEMENTED; 00317 return STATUS_NOT_IMPLEMENTED; 00318 } Generated on Sun May 27 2012 04:22:12 for ReactOS by
1.7.6.1
|