AK: Use __builtin_frame_address to find current stack depth remaining

Instead of checking the address of a temporary, grab the address of the
current frame pointer to determine how much memory is left on the stack.

This better communicates to the compiler what we're trying to do, and
resolves some crashes with ASAN in test-js while the option
detect_stack_use_after_return is turned on.
This commit is contained in:
Andrew Kaster 2023-06-30 18:42:37 -06:00 committed by Andreas Kling
parent 96b197ef46
commit 7d71acf1bb
Notes: sideshowbarker 2024-07-16 23:08:48 +09:00

View file

@ -19,8 +19,8 @@ public:
size_t size() const { return m_size; }
size_t size_free() const
{
FlatPtr dummy;
return reinterpret_cast<FlatPtr>(&dummy) - m_base;
auto p = reinterpret_cast<FlatPtr>(__builtin_frame_address(0));
return p - m_base;
}
private: