This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix longjmp's fake return in x86_64
ClosedPublic

Authored by mikhail.ramalho on Mar 27 2023, 9:16 AM.

Details

Summary

This implements the fake return after a successful longjmp(), as
described in the linux man page:

Following a successful longjmp(), execution continues as if setjmp()
had returned for a second time. This "fake" return can be distin-
guished from a true setjmp() call because the "fake" return returns the
value provided in val. If the programmer mistakenly passes the value 0
in val, the "fake" return will instead return 1.

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 27 2023, 9:16 AM
mikhail.ramalho requested review of this revision.Mar 27 2023, 9:16 AM
sivachandra accepted this revision.Mar 27 2023, 11:58 AM
sivachandra added inline comments.
libc/test/src/setjmp/setjmp_test.cpp
41

We should have some check to ensure that longjmp is indeed being called?

48

Please fix.

This revision is now accepted and ready to land.Mar 27 2023, 11:58 AM

Added a variable to count how many times longjmp was called

mikhail.ramalho marked an inline comment as done.Mar 27 2023, 1:05 PM
mikhail.ramalho added inline comments.
libc/test/src/setjmp/setjmp_test.cpp
41

I added a variable to count how many times longjmp was called, and reused the longjmp function that was already there. WDY?

sivachandra accepted this revision.Mar 27 2023, 1:15 PM
sivachandra added inline comments.
libc/test/src/setjmp/setjmp_test.cpp
14

The libc style is to name it longjmp_called.

Fix variable name