Ruby
4.1.0dev (2026-11-04 revision 9bfa7c99a6b4b115318e63d92438f1a92cfbb9ed)
prism
compiler
stack.h
Go to the documentation of this file.
1
4
#ifndef PRISM_COMPILER_STACK_H
5
#define PRISM_COMPILER_STACK_H
6
7
#include "
prism/compiler/inline.h
"
8
9
#include <stdint.h>
10
11
#if defined(__has_builtin)
12
#if __has_builtin(__builtin_stack_address)
13
#define PRISM_HAS_BUILTIN_STACK_ADDRESS
14
#endif
15
#endif
16
17
#if defined(_MSC_VER)
18
#include <intrin.h>
19
#endif
20
29
static
PRISM_INLINE
uintptr_t
30
pm_stack_address
(
void
) {
31
#if defined(PRISM_HAS_BUILTIN_STACK_ADDRESS)
32
return
(uintptr_t) __builtin_stack_address();
33
#elif defined(_MSC_VER) && defined(_M_ARM64)
34
return
(uintptr_t) __getReg(31);
35
#elif defined(_MSC_VER)
36
return
(uintptr_t) _AddressOfReturnAddress();
37
#elif defined(__GNUC__) && defined(__x86_64__)
38
uintptr_t sp;
39
__asm__ (
"{movq %%rsp, %0|mov %0, rsp}"
:
"=r"
(sp));
40
return
sp;
41
#elif defined(__GNUC__) && defined(__aarch64__)
42
/* The register is 64 bits even where pointers are 32 (arm64_32). */
43
uint64_t sp;
44
__asm__ (
"mov %0, sp"
:
"=r"
(sp));
45
return
(uintptr_t) sp;
46
#elif defined(__GNUC__)
47
return
(uintptr_t) __builtin_frame_address(0);
48
#else
49
volatile
char
marker = 0;
50
return
(uintptr_t) ▮
51
#endif
52
}
53
54
#endif
inline.h
PRISM_INLINE
#define PRISM_INLINE
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition
inline.h:12
pm_stack_address
static PRISM_INLINE uintptr_t pm_stack_address(void)
Returns the current position of the C stack, for measuring how much of it has been consumed since an ...
Definition
stack.h:30
Generated by
1.9.8