On compilers, like clang, that support frame pointers it is possible to walk the frame programmatically. So __builtin_return_address(n) works on the entire frame. So why don’t we add an argument to RETURN_ADDRESS().
For VC++ you can do this: #define RETURN_ADDRESS(_level) ((_level == 0) ? _ReturnAddress() : 0) We should also add FRAME_ADDRESS() __builtin_frame_address Thanks, Andrew Fish > On Nov 7, 2014, at 3:04 AM, Zeng, Star <[email protected]> wrote: > > Hi, > > Please help review this patch. > > MdePkg: Add RETURN_ADDRESS macro into Base.h > Based on compiler intrinsic function. > MSVC: _ReturnAddress > GCC: __builtin_return_address > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Zeng, Star <[email protected] <mailto:[email protected]>> > > Index: MdePkg/Include/Base.h > =================================================================== > --- MdePkg/Include/Base.h (revision 16230) > +++ MdePkg/Include/Base.h (working copy) > @@ -6,7 +6,7 @@ > environment. There are a set of base libraries in the Mde Package that can > be used to implement base modules. > -Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> > +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> > Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> > This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD > License > @@ -1016,5 +1016,26 @@ > #define SIGNATURE_64(A, B, C, D, E, F, G, H) \ > (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << > 32)) > +#if defined(_MSC_EXTENSIONS) > + // > + // Intrinsic function provides the address of the instruction in the > calling > + // function that will be executed after control returns to the caller. > + // > + #pragma intrinsic(_ReturnAddress) > + #define RETURN_ADDRESS _ReturnAddress() > +#elif defined(__GNUC__) > + // > + // Built-in Function returns the return address of the current function, > + // or of one of its callers. > + // > + void * __builtin_return_address (unsigned int level); > + #define RETURN_ADDRESS __builtin_return_address (0) > +#else > + // > + // Compilers don't support this feature. > + // > + #define RETURN_ADDRESS ((VOID *) 0) > #endif > +#endif > + > <RETURN_ADDRESS.patch>------------------------------------------------------------------------------ > _______________________________________________ > edk2-devel mailing list > [email protected] <mailto:[email protected]> > https://lists.sourceforge.net/lists/listinfo/edk2-devel > <https://lists.sourceforge.net/lists/listinfo/edk2-devel>
------------------------------------------------------------------------------
_______________________________________________ edk2-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/edk2-devel
