Skip to main content

luaur_analysis/methods/
native_stack_guard_is_ok_native_stack_guard.rs

1use crate::records::native_stack_guard::NativeStackGuard;
2use luaur_common::{FFlag, FInt};
3
4impl NativeStackGuard {
5    pub fn is_ok_2(&self) -> bool {
6        if !FFlag::LuauUseNativeStackGuard.get() || FInt::LuauStackGuardThreshold.get() <= 0 {
7            return true;
8        }
9
10        // C++: const uintptr_t sp = uintptr_t(_AddressOfReturnAddress());
11        // _AddressOfReturnAddress yields an address within the current stack
12        // frame; the portable equivalent is the address of a stack local.
13        let probe: u8 = 0;
14        let sp = &probe as *const u8 as usize;
15
16        let remaining = sp.wrapping_sub(self.low);
17
18        remaining > FInt::LuauStackGuardThreshold.get() as usize
19    }
20}