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

getcalr.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1991 Microsoft Corporation 00004 00005 Module Name: 00006 00007 getcalr.c 00008 00009 Abstract: 00010 00011 This module implements the routine RtlGetCallerAddress. It will 00012 return the address of the caller, and the callers caller to the 00013 specified procedure. 00014 00015 Author: 00016 00017 Larry Osterman (larryo) 18-Mar-1991 (with help from DaveC) 00018 00019 Revision History: 00020 00021 18-Mar-1991 larryo 00022 00023 Created 00024 00025 --*/ 00026 #include "ntrtlp.h" 00027 00028 // 00029 // Undefine get callers address since it is defined as a macro. 00030 // 00031 00032 #undef RtlGetCallersAddress 00033 00034 VOID 00035 RtlGetCallersAddress ( 00036 OUT PVOID *CallersPc, 00037 OUT PVOID *CallersCallersPc 00038 ) 00039 00040 /*++ 00041 00042 Routine Description: 00043 00044 This routine returns the address of the routine that called the routine 00045 that called this routine, and the routine that called the routine that 00046 called this routine. For example, if A called B called C which called 00047 this routine, the return addresses in A and B would be returned. 00048 00049 Arguments: 00050 00051 CallersPc - Supplies a pointer to a variable that receives the address 00052 of the caller of the caller of this routine (B). 00053 00054 CallersCallersPc - Supplies a pointer to a variable that receives the 00055 address of the caller of the caller of the caller of this routine 00056 (A). 00057 00058 Return Value: 00059 00060 None. 00061 00062 Note: 00063 00064 If either of the calling stack frames exceeds the limits of the stack, 00065 they are set to NULL. 00066 00067 --*/ 00068 00069 { 00070 00071 CONTEXT ContextRecord; 00072 ULONG EstablisherFrame; 00073 PRUNTIME_FUNCTION FunctionEntry; 00074 BOOLEAN InFunction; 00075 ULONG NextPc; 00076 ULONG HighLimit, LowLimit; 00077 00078 // 00079 // Assume the function table entries for the various routines cannot be 00080 // found or there are not four procedure activation records on the stack. 00081 // 00082 00083 *CallersPc = NULL; 00084 *CallersCallersPc = NULL; 00085 00086 // 00087 // Capture the current context. 00088 // 00089 00090 RtlCaptureContext(&ContextRecord); 00091 NextPc = (ULONG)ContextRecord.XIntRa; 00092 00093 // 00094 // Get the high and low limits of the current thread's stack. 00095 // 00096 00097 RtlpGetStackLimits(&LowLimit, &HighLimit); 00098 00099 // 00100 // Attempt to unwind to the caller of this routine (C). 00101 // 00102 00103 FunctionEntry = RtlLookupFunctionEntry(NextPc); 00104 if (FunctionEntry != NULL) { 00105 00106 // 00107 // A function entry was found for this routine. Virtually unwind 00108 // to the caller of this routine (C). 00109 // 00110 00111 NextPc = RtlVirtualUnwind(NextPc | 1, 00112 FunctionEntry, 00113 &ContextRecord, 00114 &InFunction, 00115 &EstablisherFrame, 00116 NULL); 00117 00118 // 00119 // Attempt to unwind to the caller of the caller of this routine (B). 00120 // 00121 00122 FunctionEntry = RtlLookupFunctionEntry(NextPc); 00123 if ((FunctionEntry != NULL) && ((ULONG)ContextRecord.XIntSp < HighLimit)) { 00124 00125 // 00126 // A function table entry was found for the caller of the caller 00127 // of this routine (B). Virtually unwind to the caller of the 00128 // caller of this routine (B). 00129 // 00130 00131 NextPc = RtlVirtualUnwind(NextPc | 1, 00132 FunctionEntry, 00133 &ContextRecord, 00134 &InFunction, 00135 &EstablisherFrame, 00136 NULL); 00137 00138 *CallersPc = (PVOID)NextPc; 00139 00140 // 00141 // Attempt to unwind to the caller of the caller of the caller 00142 // of the caller of this routine (A). 00143 // 00144 00145 FunctionEntry = RtlLookupFunctionEntry(NextPc); 00146 if ((FunctionEntry != NULL) && ((ULONG)ContextRecord.XIntSp < HighLimit)) { 00147 00148 // 00149 // A function table entry was found for the caller of the 00150 // caller of the caller of this routine (A). Virtually unwind 00151 // to the caller of the caller of the caller of this routine 00152 // (A). 00153 // 00154 00155 NextPc = RtlVirtualUnwind(NextPc | 1, 00156 FunctionEntry, 00157 &ContextRecord, 00158 &InFunction, 00159 &EstablisherFrame, 00160 NULL); 00161 00162 *CallersCallersPc = (PVOID)NextPc; 00163 } 00164 } 00165 } 00166 00167 return; 00168 } 00169 00170 USHORT 00171 RtlCaptureStackBackTrace( 00172 IN ULONG FramesToSkip, 00173 IN ULONG FramesToCapture, 00174 OUT PVOID *BackTrace, 00175 OUT PULONG BackTraceHash 00176 ) 00177 { 00178 return 0; 00179 }

Generated on Sat May 15 19:40:11 2004 for test by doxygen 1.3.7