Skip to content

#21 call asan on setjmp#22

Open
balupillai wants to merge 3 commits intomainfrom
lua-21
Open

#21 call asan on setjmp#22
balupillai wants to merge 3 commits intomainfrom
lua-21

Conversation

@balupillai
Copy link
Copy Markdown
Contributor

@balupillai balupillai commented Apr 2, 2026

Note

Low Risk
Low risk because behavior only changes when building with __SANITIZE_ADDRESS__, swapping in standard setjmp/longjmp to avoid ASAN false positives; non-ASAN builds keep the existing asm fast-paths.

Overview
When building under AddressSanitizer, the runtime now avoids the custom asm setjmp/longjmp implementations and instead uses the system setjmp/longjmp so ASAN can correctly intercept them and unpoison skipped stack frames.

Non-ASAN builds continue to use the architecture-specific asm versions (x86_64, i386, aarch64) as before.

Written by Cursor Bugbot for commit d6b2e67. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Lua’s longjmp-based error handling to better cooperate with AddressSanitizer by invoking an ASan “no return” hook before performing longjmp.

Changes:

  • Adds a declaration for __asan_handle_no_return.
  • Wraps LUAI_THROW (for _longjmp/_setjmp and longjmp/setjmp configurations) to call __asan_handle_no_return() before lua_do_longjmp.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

src/luaconf.h Outdated
Comment on lines +695 to +697

void __asan_handle_no_return(void);

Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__asan_handle_no_return is declared unconditionally, but the symbol is only provided when linking with the ASan runtime. In non-ASan builds this will either cause a link error once referenced, or at minimum introduces an undocumented dependency. Consider wrapping the declaration (and any calls) in an ASan feature check (e.g. __SANITIZE_ADDRESS__ or __has_feature(address_sanitizer)), and define a no-op fallback when ASan is not enabled; alternatively include sanitizer/asan_interface.h conditionally when available.

Copilot uses AI. Check for mistakes.
Comment on lines 706 to 708
/* in Unix, try _longjmp/_setjmp (more efficient) */
#define LUAI_THROW(L,c) lua_do_longjmp((c)->b, 1)
#define LUAI_THROW(L,c) do { __asan_handle_no_return(); lua_do_longjmp((c)->b, 1); } while(0)
#define LUAI_TRY(L,c,a) if (lua_do_setjmp((c)->b) == 0) { a }
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LUAI_THROW now unconditionally calls __asan_handle_no_return(). Without guarding this call behind an AddressSanitizer-enabled compile check (or providing a no-op fallback), non-ASan builds can fail to link or may inadvertently require the ASan runtime. Gate the call behind an __SANITIZE_ADDRESS__/__has_feature(address_sanitizer) check or similar.

Copilot uses AI. Check for mistakes.
Comment on lines 712 to 714
/* default handling with long jumps */
#define LUAI_THROW(L,c) lua_do_longjmp((c)->b, 1)
#define LUAI_THROW(L,c) do { __asan_handle_no_return(); lua_do_longjmp((c)->b, 1); } while(0)
#define LUAI_TRY(L,c,a) if (lua_do_setjmp((c)->b) == 0) { a }
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above: this LUAI_THROW variant calls __asan_handle_no_return() unconditionally, which can break non-ASan builds. Please guard it behind an ASan-enabled macro check or provide a no-op fallback when ASan is not active.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants