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

error.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1991 Microsoft Corporation 00004 00005 Module Name: 00006 00007 error.c 00008 00009 Abstract: 00010 00011 This module contains a routine for converting NT status codes 00012 to DOS/OS|2 error codes. 00013 00014 Author: 00015 00016 David Treadwell (davidtr) 04-Apr-1991 00017 00018 Revision History: 00019 00020 --*/ 00021 00022 #include <ntrtlp.h> 00023 #include "winerror.h" 00024 #include "error.h" 00025 00026 #if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME) 00027 #pragma alloc_text(PAGE, RtlNtStatusToDosError) 00028 #endif 00029 00030 // 00031 // Ensure that the Registry ERROR_SUCCESS error code and the 00032 // NO_ERROR error code remain equal and zero. 00033 // 00034 00035 #if ERROR_SUCCESS != 0 || NO_ERROR != 0 00036 #error Invalid value for ERROR_SUCCESS. 00037 #endif 00038 00039 ULONG 00040 RtlNtStatusToDosError ( 00041 IN NTSTATUS Status 00042 ) 00043 00044 /*++ 00045 00046 Routine Description: 00047 00048 This routine converts an NT status code to its DOS/OS|2 equivalent. 00049 Remembers the Status code value in the TEB. 00050 00051 Arguments: 00052 00053 Status - Supplies the status value to convert. 00054 00055 Return Value: 00056 00057 The matching DOS/OS|2 error code. 00058 00059 --*/ 00060 00061 { 00062 PTEB Teb; 00063 00064 Teb = NtCurrentTeb(); 00065 if ( Teb ) { 00066 Teb->LastStatusValue = Status; 00067 } 00068 00069 return RtlNtStatusToDosErrorNoTeb( Status ); 00070 } 00071 00072 ULONG 00073 RtlNtStatusToDosErrorNoTeb ( 00074 IN NTSTATUS Status 00075 ) 00076 00077 /*++ 00078 00079 Routine Description: 00080 00081 This routine converts an NT status code to its DOS/OS 2 equivalent 00082 and returns the translated value. 00083 00084 Arguments: 00085 00086 Status - Supplies the status value to convert. 00087 00088 Return Value: 00089 00090 The matching DOS/OS 2 error code. 00091 00092 --*/ 00093 00094 { 00095 00096 ULONG Offset; 00097 ULONG Entry; 00098 ULONG Index; 00099 00100 // 00101 // Convert any HRESULTs to their original form of a NTSTATUS or a 00102 // WIN32 error 00103 // 00104 00105 00106 if (Status & 0x20000000) { 00107 00108 // 00109 // The customer bit is set so lets just pass the 00110 // error code on thru 00111 // 00112 00113 return Status; 00114 00115 } 00116 else if ((Status & 0xffff0000) == 0x80070000) { 00117 00118 // 00119 // The status code was a win32 error already. 00120 // 00121 00122 return(Status & 0x0000ffff); 00123 } 00124 else if ((Status & 0xf0000000) == 0xd0000000) { 00125 00126 // 00127 // The status code is a HRESULT from NTSTATUS 00128 // 00129 00130 Status &= 0xcfffffff; 00131 } 00132 00133 // 00134 // Scan the run length table and compute the entry in the translation 00135 // table that maps the specified status code to a DOS error code. 00136 // 00137 00138 Entry = 0; 00139 Index = 0; 00140 do { 00141 if ((ULONG)Status >= RtlpRunTable[Entry + 1].BaseCode) { 00142 Index += (RtlpRunTable[Entry].RunLength * RtlpRunTable[Entry].CodeSize); 00143 00144 } else { 00145 Offset = (ULONG)Status - RtlpRunTable[Entry].BaseCode; 00146 if (Offset >= RtlpRunTable[Entry].RunLength) { 00147 break; 00148 00149 } else { 00150 Index += (Offset * (ULONG)RtlpRunTable[Entry].CodeSize); 00151 if (RtlpRunTable[Entry].CodeSize == 1) { 00152 return (ULONG)RtlpStatusTable[Index]; 00153 00154 } else { 00155 return (((ULONG)RtlpStatusTable[Index + 1] << 16) | 00156 (ULONG)RtlpStatusTable[Index]); 00157 } 00158 } 00159 } 00160 00161 Entry += 1; 00162 } while (Entry < (sizeof(RtlpRunTable) / sizeof(RUN_ENTRY))); 00163 00164 // 00165 // The translation to a DOS error code failed. 00166 // 00167 // The redirector maps unknown OS/2 error codes by ORing 0xC001 into 00168 // the high 16 bits. Detect this and return the low 16 bits if true. 00169 // 00170 00171 if (((ULONG)Status >> 16) == 0xC001) { 00172 return ((ULONG)Status & 0xFFFF); 00173 } 00174 00175 #ifndef NTOS_KERNEL_RUNTIME 00176 DbgPrint("RTL: RtlNtStatusToDosError(0x%lx): No Valid Win32 Error Mapping\n",Status); 00177 DbgPrint("RTL: Edit ntos\\rtl\\generr.c to correct the problem\n"); 00178 DbgPrint("RTL: ERROR_MR_MID_NOT_FOUND is being returned\n"); 00179 00180 #if DBG 00181 DbgBreakPoint(); 00182 #endif // DBG 00183 00184 #endif // NTOS_KERNEL_RUNTIME 00185 00186 return ERROR_MR_MID_NOT_FOUND; 00187 }

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