Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for crash related to call_ext_last/3 #518

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

pguyot
Copy link
Collaborator

@pguyot pguyot commented Apr 23, 2023

BEAM's compiler and especially beam_trim optimization pass can generate an
incorrect deallocation n_words parameter for call_ext_last/3.
As a workaround, deallocate after the nif call, and before any error handling
that may need the stack to find catch handlers.

See: erlang/otp#7152

Add test that currently crashes on master without this change

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@pguyot pguyot force-pushed the w16/fix-call_ext_last-throw-stack_base branch from a941456 to 661cf98 Compare April 23, 2023 19:28
src/libAtomVM/opcodesswitch.h Outdated Show resolved Hide resolved
@pguyot pguyot marked this pull request as draft April 24, 2023 07:08
@pguyot
Copy link
Collaborator Author

pguyot commented Apr 24, 2023

We actually may need to adopt OTP23+ stack model introduced in erlang/otp#2351 to fix this crash.

I am not totally sure of the semantics of call_ext_last, let's put on hold until we hear back from OTP team.
erlang/otp#7152

BEAM's compiler and especially beam_trim optimization pass can generate an
incorrect deallocation `n_words` parameter for `call_ext_last/3`.
As a workaround, deallocate after the nif call, and before any error handling
that may need the stack to find catch handlers.

See:  erlang/otp#7152

Add test that currently crashes on master without this change

Signed-off-by: Paul Guyot <pguyot@kallisys.net>
@pguyot pguyot force-pushed the w16/fix-call_ext_last-throw-stack_base branch from 661cf98 to b9ba453 Compare April 25, 2023 07:15
@pguyot pguyot changed the title Fix bug when handling errors from call_ext_last Add workaround for crash related to call_ext_last/3 Apr 25, 2023
@pguyot pguyot marked this pull request as ready for review April 25, 2023 07:18
@bettio bettio merged commit 9650244 into atomvm:master Apr 26, 2023
@pguyot pguyot deleted the w16/fix-call_ext_last-throw-stack_base branch April 27, 2023 05:08
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