Changeset View
Changeset View
Standalone View
Standalone View
sys/x86/include/stack.h
Context not available. | |||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#ifndef _X86_STACK_H | #ifndef _X86_STACK_H | ||||
#define _X86_STACK_H | #define _X86_STACK_H | ||||
Context not available. | |||||
uint32_t f_retaddr; | uint32_t f_retaddr; | ||||
uint32_t f_arg0; | uint32_t f_arg0; | ||||
}; | }; | ||||
typedef const struct amd64_frame *stack_frame_ptr; | |||||
struct __call_instruction { unsigned char c; }; | |||||
typedef const struct __call_instruction *instruction_ptr; | |||||
/** | |||||
* @return instruction pointer of the caller of the given stack | |||||
*/ | |||||
instruction_ptr stack_frame_caller_ip(stack_frame_ptr frame); | |||||
/** | |||||
* current_stack_frame() is a macro instead of an inline function so | |||||
* cannot possibly have its own stack frame. | |||||
*/ | |||||
#define _current_stack_frame(fp) \ | |||||
({ stack_frame_ptr fp; __asm("movq %%rbp,%0;" : "=r" (fp)); fp; }) | |||||
#define current_stack_frame() _current_stack_frame(__UNIQ) | |||||
/** | |||||
* This macro evaluates to the caller of the current function. It is a macro so | |||||
* that it cannot possibly have its own stack frame. | |||||
*/ | |||||
#define get_caller_ip() stack_frame_caller_ip(current_stack_frame()) | |||||
cem: Why not use the GCC function `__builtin_return_address()` instead? That should be somewhat… | |||||
darius-dons.net.auAuthorUnsubmitted Not Done Inline ActionsWow, that looks like exactly what I want :) darius-dons.net.au: Wow, that looks like exactly what I want :)
I'll update the patch.
| |||||
#endif /* __amd64__ */ | #endif /* __amd64__ */ | ||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
Context not available. |
Why not use the GCC function __builtin_return_address() instead? That should be somewhat portable to non-x86?
https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html
Clang/LLVM support the macros as well (for X86 since LLVM2.5):
https://github.com/llvm-mirror/clang/blob/master/test/Sema/builtin-stackaddress.c