Ruby 4.1.0dev (2026-11-24 revision a469c88bf4bfbe7729d04b72db9a3e56d753c55e)
stack.h
Go to the documentation of this file.
1
4#ifndef PRISM_COMPILER_STACK_H
5#define PRISM_COMPILER_STACK_H
6
8
9#include <stdint.h>
10
11#if defined(__FILC__)
12 #include <stdfil.h>
13#endif
14
15#if defined(__has_builtin)
16 #if __has_builtin(__builtin_stack_address)
17 #define PRISM_HAS_BUILTIN_STACK_ADDRESS
18 #endif
19#endif
20
21#if defined(_MSC_VER)
22 #include <intrin.h>
23#endif
24
33static PRISM_INLINE uintptr_t
35#if defined(__FILC__)
36 return (uintptr_t) zstack_pointer();
37#elif defined(PRISM_HAS_BUILTIN_STACK_ADDRESS)
38 return (uintptr_t) __builtin_stack_address();
39#elif defined(_MSC_VER) && defined(_M_ARM64)
40 return (uintptr_t) __getReg(31);
41#elif defined(_MSC_VER)
42 return (uintptr_t) _AddressOfReturnAddress();
43#elif defined(__GNUC__) && defined(__x86_64__)
44 uintptr_t sp;
45 __asm__ ("{movq %%rsp, %0|mov %0, rsp}" : "=r" (sp));
46 return sp;
47#elif defined(__GNUC__) && defined(__aarch64__)
48 /* The register is 64 bits even where pointers are 32 (arm64_32). */
49 uint64_t sp;
50 __asm__ ("mov %0, sp" : "=r" (sp));
51 return (uintptr_t) sp;
52#elif defined(__GNUC__)
53 return (uintptr_t) __builtin_frame_address(0);
54#else
55 volatile char marker = 0;
56 return (uintptr_t) &marker;
57#endif
58}
59
60#endif
#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
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:34