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 Tom Wood 23-Aug-1994 00026 Add stack limit parameters to RtlVirtualUnwind. 00027 00028 --*/ 00029 #include "ntrtlp.h" 00030 00031 // 00032 // Undefine get callers address since it is defined as a macro. 00033 // 00034 00035 #undef RtlGetCallersAddress 00036 00037 VOID 00038 RtlGetCallersAddress ( 00039 OUT PVOID *CallersPc, 00040 OUT PVOID *CallersCallersPc 00041 ) 00042 00043 /*++ 00044 00045 Routine Description: 00046 00047 This routine returns the address of the routine that called the routine 00048 that called this routine, and the routine that called the routine that 00049 called this routine. For example, if A called B called C which called 00050 this routine, the return addresses in A and B would be returned. 00051 00052 Arguments: 00053 00054 CallersPc - Supplies a pointer to a variable that receives the address 00055 of the caller of the caller of this routine (B). 00056 00057 CallersCallersPc - Supplies a pointer to a variable that receives the 00058 address of the caller of the caller of the caller of this routine 00059 (A). 00060 00061 Return Value: 00062 00063 None. 00064 00065 Note: 00066 00067 If either of the calling stack frames exceeds the limits of the stack, 00068 they are set to NULL. 00069 00070 --*/ 00071 00072 { 00073 00074 CONTEXT ContextRecord; 00075 ULONG EstablisherFrame; 00076 PRUNTIME_FUNCTION FunctionEntry; 00077 BOOLEAN InFunction; 00078 ULONG NextPc; 00079 ULONG HighLimit, LowLimit; 00080 00081 // 00082 // Assume the function table entries for the various routines cannot be 00083 // found or there are not four procedure activation records on the stack. 00084 // 00085 00086 *CallersPc = NULL; 00087 *CallersCallersPc = NULL; 00088 00089 // 00090 // Capture the current context. 00091 // 00092 00093 RtlCaptureContext(&ContextRecord); 00094 NextPc = ContextRecord.Lr; 00095 00096 // 00097 // Get the high and low limits of the current thread's stack. 00098 // 00099 00100 RtlpGetStackLimits(&LowLimit, &HighLimit); 00101 00102 // 00103 // Attempt to unwind to the caller of this routine (C). 00104 // 00105 00106 FunctionEntry = RtlLookupFunctionEntry(NextPc); 00107 if (FunctionEntry != NULL) { 00108 00109 // 00110 // A function entry was found for this routine. Virtually unwind 00111 // to the caller of this routine (C). 00112 // 00113 00114 NextPc = RtlVirtualUnwind(NextPc, 00115 FunctionEntry, 00116 &ContextRecord, 00117 &InFunction, 00118 &EstablisherFrame, 00119 NULL, 00120 0, 00121 0xffffffff); 00122 00123 // 00124 // Attempt to unwind to the caller of the caller of this routine (B). 00125 // 00126 00127 FunctionEntry = RtlLookupFunctionEntry(NextPc); 00128 if ((FunctionEntry != NULL) && (ContextRecord.Gpr1 < HighLimit)) { 00129 00130 // 00131 // A function table entry was found for the caller of the caller 00132 // of this routine (B). Virtually unwind to the caller of the 00133 // caller of this routine (B). 00134 // 00135 00136 NextPc = RtlVirtualUnwind(NextPc, 00137 FunctionEntry, 00138 &ContextRecord, 00139 &InFunction, 00140 &EstablisherFrame, 00141 NULL, 00142 0, 00143 0xffffffff); 00144 00145 *CallersPc = (PVOID)NextPc; 00146 00147 // 00148 // Attempt to unwind to the caller of the caller of the caller 00149 // of the caller of this routine (A). 00150 // 00151 00152 FunctionEntry = RtlLookupFunctionEntry(NextPc); 00153 if ((FunctionEntry != NULL) && (ContextRecord.Gpr1 < HighLimit)) { 00154 00155 // 00156 // A function table entry was found for the caller of the 00157 // caller of the caller of this routine (A). Virtually unwind 00158 // to the caller of the caller of the caller of this routine 00159 // (A). 00160 // 00161 00162 NextPc = RtlVirtualUnwind(NextPc, 00163 FunctionEntry, 00164 &ContextRecord, 00165 &InFunction, 00166 &EstablisherFrame, 00167 NULL, 00168 0, 00169 0xffffffff); 00170 00171 00172 *CallersCallersPc = (PVOID)NextPc; 00173 } 00174 } 00175 } 00176 00177 return; 00178 } 00179 00180 USHORT 00181 RtlCaptureStackBackTrace( 00182 IN ULONG FramesToSkip, 00183 IN ULONG FramesToCapture, 00184 OUT PVOID *BackTrace, 00185 OUT PULONG BackTraceHash 00186 ) 00187 { 00188 return 0; 00189 }

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