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

probe.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1990-1993 Microsoft Corporation 00004 00005 Module Name: 00006 00007 probe.c 00008 00009 Abstract: 00010 00011 This module implements the probe for write function. 00012 00013 Author: 00014 00015 David N. Cutler (davec) 19-Jan-1990 00016 00017 Environment: 00018 00019 Any mode. 00020 00021 Revision History: 00022 00023 --*/ 00024 00025 #include "exp.h" 00026 00027 #if defined(ALLOC_PRAGMA) 00028 #pragma alloc_text(PAGE, ProbeForWrite) 00029 #pragma alloc_text(PAGE, ProbeForRead) 00030 #endif 00031 00032 00033 VOID 00034 ProbeForWrite ( 00035 IN PVOID Address, 00036 IN ULONG Length, 00037 IN ULONG Alignment 00038 ) 00039 00040 /*++ 00041 00042 Routine Description: 00043 00044 This function probes a structure for write accessibility and ensures 00045 correct alignment of the structure. If the structure is not accessible 00046 or has incorrect alignment, then an exception is raised. 00047 00048 Arguments: 00049 00050 Address - Supplies a pointer to the structure to be probed. 00051 00052 Length - Supplies the length of the structure. 00053 00054 Alignment - Supplies the required alignment of the structure expressed 00055 as the number of bytes in the primitive datatype (e.g., 1 for char, 00056 2 for short, 4 for long, and 8 for quad). 00057 00058 Return Value: 00059 00060 None. 00061 00062 --*/ 00063 00064 { 00065 00066 ULONG_PTR EndAddress; 00067 ULONG_PTR StartAddress; 00068 00069 // 00070 // If the structure has zero length, then do not probe the structure for 00071 // write accessibility or alignment. 00072 // 00073 00074 if (Length != 0) { 00075 00076 // 00077 // If the structure is not properly aligned, then raise a data 00078 // misalignment exception. 00079 // 00080 00081 ASSERT((Alignment == 1) || (Alignment == 2) || 00082 (Alignment == 4) || (Alignment == 8) || 00083 (Alignment == 16)); 00084 00085 StartAddress = (ULONG_PTR)Address; 00086 if ((StartAddress & (Alignment - 1)) == 0) { 00087 00088 // 00089 // Compute the ending address of the structure and probe for 00090 // write accessibility. 00091 // 00092 00093 EndAddress = StartAddress + Length - 1; 00094 if ((StartAddress <= EndAddress) && 00095 (EndAddress < MM_USER_PROBE_ADDRESS)) { 00096 00097 // 00098 // N.B. Only the contents of the buffer may be probed. 00099 // Therefore the starting byte is probed for the 00100 // first page, and then the first byte in the page 00101 // for each succeeding page. 00102 // 00103 00104 EndAddress = (EndAddress & ~(PAGE_SIZE - 1)) + PAGE_SIZE; 00105 00106 #if defined(_ALPHA_) 00107 00108 // 00109 // N.B. The address is truncated to a longword aligned 00110 // address since Alpha has no load or store byte 00111 // instructions. 00112 // 00113 00114 StartAddress &= ~((ULONG_PTR)sizeof(LONG) - 1); 00115 00116 do { 00117 *(volatile LONG *)StartAddress = *(volatile LONG *)StartAddress; 00118 StartAddress = (StartAddress & ~(PAGE_SIZE - 1)) + PAGE_SIZE; 00119 } while (StartAddress != EndAddress); 00120 00121 #else 00122 00123 do { 00124 *(volatile CHAR *)StartAddress = *(volatile CHAR *)StartAddress; 00125 00126 StartAddress = (StartAddress & ~(PAGE_SIZE - 1)) + PAGE_SIZE; 00127 } while (StartAddress != EndAddress); 00128 #endif 00129 00130 return; 00131 00132 } else { 00133 ExRaiseAccessViolation(); 00134 } 00135 00136 } else { 00137 ExRaiseDatatypeMisalignment(); 00138 } 00139 } 00140 00141 return; 00142 } 00143 00144 #undef ProbeForRead 00145 NTKERNELAPI 00146 VOID 00147 NTAPI 00148 ProbeForRead( 00149 IN CONST VOID *Address, 00150 IN ULONG Length, 00151 IN ULONG Alignment 00152 ) 00153 00154 /*++ 00155 00156 Routine Description: 00157 00158 This function probes a structure for read accessibility and ensures 00159 correct alignment of the structure. If the structure is not accessible 00160 or has incorrect alignment, then an exception is raised. 00161 00162 Arguments: 00163 00164 Address - Supplies a pointer to the structure to be probed. 00165 00166 Length - Supplies the length of the structure. 00167 00168 Alignment - Supplies the required alignment of the structure expressed 00169 as the number of bytes in the primitive datatype (e.g., 1 for char, 00170 2 for short, 4 for long, and 8 for quad). 00171 00172 Return Value: 00173 00174 None. 00175 00176 --*/ 00177 { 00178 PAGED_CODE(); 00179 00180 ASSERT(((Alignment) == 1) || ((Alignment) == 2) || 00181 ((Alignment) == 4) || ((Alignment) == 8) || 00182 ((Alignment) == 16)); 00183 00184 if ((Length) != 0) { 00185 if (((ULONG_PTR)(Address) & ((Alignment) - 1)) != 0) { 00186 ExRaiseDatatypeMisalignment(); 00187 00188 } else if ((((ULONG_PTR)(Address) + (Length)) < (ULONG_PTR)(Address)) || 00189 (((ULONG_PTR)(Address) + (Length)) > (ULONG_PTR)MM_USER_PROBE_ADDRESS)) { 00190 ExRaiseAccessViolation(); 00191 } 00192 } 00193 } 00194

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