Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenexception.c
Go to the documentation of this file.
00001 /* COPYRIGHT: See COPYING in the top level directory 00002 * PROJECT: ReactOS Runtime Library 00003 * PURPOSE: User-Mode Exception Support 00004 * FILE: lib/rtl/exception.c 00005 * PROGRAMERS: Alex Ionescu (alex@relsoft.net) 00006 * David Welch <welch@cwcom.net> 00007 * Skywing <skywing@valhallalegends.com> 00008 * KJK::Hyperion <noog@libero.it> 00009 */ 00010 00011 /* INCLUDES *****************************************************************/ 00012 00013 #include <rtl.h> 00014 00015 #define NDEBUG 00016 #include <debug.h> 00017 00018 /* GLOBALS *****************************************************************/ 00019 00020 PRTLP_UNHANDLED_EXCEPTION_FILTER RtlpUnhandledExceptionFilter; 00021 00022 /* FUNCTIONS ***************************************************************/ 00023 00024 #if !defined(_M_IX86) && !defined(_M_AMD64) 00025 00026 /* 00027 * @implemented 00028 */ 00029 VOID 00030 NTAPI 00031 RtlRaiseException(IN PEXCEPTION_RECORD ExceptionRecord) 00032 { 00033 CONTEXT Context; 00034 NTSTATUS Status; 00035 00036 /* Capture the context */ 00037 RtlCaptureContext(&Context); 00038 00039 /* Save the exception address */ 00040 ExceptionRecord->ExceptionAddress = _ReturnAddress(); 00041 00042 /* Write the context flag */ 00043 Context.ContextFlags = CONTEXT_FULL; 00044 00045 /* Check if user mode debugger is active */ 00046 if (RtlpCheckForActiveDebugger()) 00047 { 00048 /* Raise an exception immediately */ 00049 Status = ZwRaiseException(ExceptionRecord, &Context, TRUE); 00050 } 00051 else 00052 { 00053 /* Dispatch the exception and check if we should continue */ 00054 if (!RtlDispatchException(ExceptionRecord, &Context)) 00055 { 00056 /* Raise the exception */ 00057 Status = ZwRaiseException(ExceptionRecord, &Context, FALSE); 00058 } 00059 else 00060 { 00061 /* Continue, go back to previous context */ 00062 Status = ZwContinue(&Context, FALSE); 00063 } 00064 } 00065 00066 /* If we returned, raise a status */ 00067 RtlRaiseStatus(Status); 00068 } 00069 00070 #endif 00071 00072 #if !defined(_M_IX86) 00073 00074 #ifdef _MSC_VER 00075 #pragma warning(push) 00076 #pragma warning(disable:4717) // RtlRaiseStatus is recursive by design 00077 #endif 00078 00079 /* 00080 * @implemented 00081 */ 00082 VOID 00083 NTAPI 00084 RtlRaiseStatus(IN NTSTATUS Status) 00085 { 00086 EXCEPTION_RECORD ExceptionRecord; 00087 CONTEXT Context; 00088 00089 /* Capture the context */ 00090 RtlCaptureContext(&Context); 00091 00092 /* Create an exception record */ 00093 ExceptionRecord.ExceptionAddress = _ReturnAddress(); 00094 ExceptionRecord.ExceptionCode = Status; 00095 ExceptionRecord.ExceptionRecord = NULL; 00096 ExceptionRecord.NumberParameters = 0; 00097 ExceptionRecord.ExceptionFlags = EXCEPTION_NONCONTINUABLE; 00098 00099 /* Write the context flag */ 00100 Context.ContextFlags = CONTEXT_FULL; 00101 00102 /* Check if user mode debugger is active */ 00103 if (RtlpCheckForActiveDebugger()) 00104 { 00105 /* Raise an exception immediately */ 00106 ZwRaiseException(&ExceptionRecord, &Context, TRUE); 00107 } 00108 else 00109 { 00110 /* Dispatch the exception */ 00111 RtlDispatchException(&ExceptionRecord, &Context); 00112 00113 /* Raise exception if we got here */ 00114 Status = ZwRaiseException(&ExceptionRecord, &Context, FALSE); 00115 } 00116 00117 /* If we returned, raise a status */ 00118 RtlRaiseStatus(Status); 00119 } 00120 00121 #ifdef _MSC_VER 00122 #pragma warning(pop) 00123 #endif 00124 00125 #endif 00126 00127 /* 00128 * @implemented 00129 */ 00130 USHORT 00131 NTAPI 00132 RtlCaptureStackBackTrace(IN ULONG FramesToSkip, 00133 IN ULONG FramesToCapture, 00134 OUT PVOID *BackTrace, 00135 OUT PULONG BackTraceHash OPTIONAL) 00136 { 00137 PVOID Frames[2 * 64]; 00138 ULONG FrameCount; 00139 ULONG Hash = 0, i; 00140 00141 /* Skip a frame for the caller */ 00142 FramesToSkip++; 00143 00144 /* Don't go past the limit */ 00145 if ((FramesToCapture + FramesToSkip) >= 128) return 0; 00146 00147 /* Do the back trace */ 00148 FrameCount = RtlWalkFrameChain(Frames, FramesToCapture + FramesToSkip, 0); 00149 00150 /* Make sure we're not skipping all of them */ 00151 if (FrameCount <= FramesToSkip) return 0; 00152 00153 /* Loop all the frames */ 00154 for (i = 0; i < FramesToCapture; i++) 00155 { 00156 /* Don't go past the limit */ 00157 if ((FramesToSkip + i) >= FrameCount) break; 00158 00159 /* Save this entry and hash it */ 00160 BackTrace[i] = Frames[FramesToSkip + i]; 00161 Hash += PtrToUlong(BackTrace[i]); 00162 } 00163 00164 /* Write the hash */ 00165 if (BackTraceHash) *BackTraceHash = Hash; 00166 00167 /* Clear the other entries and return count */ 00168 RtlFillMemoryUlong(Frames, 128, 0); 00169 return (USHORT)i; 00170 } 00171 00172 /* 00173 * @unimplemented 00174 */ 00175 LONG 00176 NTAPI 00177 RtlUnhandledExceptionFilter(IN struct _EXCEPTION_POINTERS* ExceptionInfo) 00178 { 00179 /* This is used by the security cookie checks, and calso called externally */ 00180 UNIMPLEMENTED; 00181 return ERROR_CALL_NOT_IMPLEMENTED; 00182 } 00183 00184 /* 00185 * @implemented 00186 */ 00187 VOID 00188 NTAPI 00189 RtlSetUnhandledExceptionFilter(IN PRTLP_UNHANDLED_EXCEPTION_FILTER TopLevelExceptionFilter) 00190 { 00191 /* Set the filter which is used by the CriticalSection package */ 00192 RtlpUnhandledExceptionFilter = RtlEncodePointer(TopLevelExceptionFilter); 00193 } Generated on Sat May 26 2012 04:35:21 for ReactOS by
1.7.6.1
|