-
Notifications
You must be signed in to change notification settings - Fork 13
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
follow-up: longjmp annotations and optimization #30
Comments
It occurs to me that this optimization might be unsound even without |
@Amanieu Yes, so I brought up the idea that |
I also suggested We discussed whether an annotation is sufficient and agreed that it probably is. This prevents annotating function pointers as We also agreed that when the annotation is introduced, we can specify that using |
One common case for longjumps is jumping from code cache (jitted code produced by any system that does interpretation and needs to speed up it in common cases, e.g. simulator) to regular code on exceptional situations (e.g. some access violation in the simulated system). The handler for exceptional situations normally resides somewhere at the top of the code tree, so if functions that can terminate with longjump need to be annotated explicitly, then pretty much whole codebase will have to be annotated. EDIT: Unless some inference is done for code that we see and know, and annotations are needed only for the cases of "external" code, which includes function jumping into the code cache. EDIT2: The longjump in this case is required to be a "teleportation" rather than unwinding in this case, since there's no common stack between the code cache and regular code, so you have to tweak the lingjump behavior on platforms where it unwinds by default. |
I was actually thinking about that: a global annotation like
`#![cancelable]` could make all the functions longjmp-safe, couldn't it?
…On Fri, Jun 12, 2020 at 2:18 AM Vadim Petrochenkov ***@***.***> wrote:
One common case for longjumps is jumping from code cache (jitted code
produced by any system that does interpretation and needs to speed up it in
common cases, e.g. simulator) to regular code on exceptional situations
(e.g. some access violation in the simulated system).
The handler for exceptional situations normally resides somewhere at the
top of the code tree, so if functions that can terminate with longjump need
to be annotated explicitly, then pretty much whole codebase will have to be
annotated.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#30 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARU4TZW3SHRGKKZFMXHFLDRWHQG3ANCNFSM4N3UY6KQ>
.
|
That won't make dependencies longjmp-safe, while making it much easier to forget about longjmp-safety when you use it. |
Per Niko's suggested warning scheme, it would emit a warning for every single call into a non-longjmp-safe dependency. So in practice, it would only be convenient to use in isolation or with other dependencies designed with longjmp-safety in mind. |
I imagine the "async" in "async cancel safe" refers to whether an asynchronous signal could cancel the function at any point (versus saying that it can be canceled at each point where it invokes another function). The lint we were proposing (check that no dtors are in scope at each function call) would therefore make things "cancel safe" but not "async cancel safe". |
I feel like the "annotate a ton of code" use case might also be handled by procedural macros at the module level, though I don't know how well that works. It feels like a bit of an edge case to me I guess. Still, we could permit it at the module level for sure. |
As discussed in this week's meeting, we realized that permitting
longjmp
out of a"C"
function will lose optimization potential in a case like this:At least at present, we should be able to move the
x
down below the call tobar()
, so long as we do it also on unwinding. However, longjmp would make that observable.We discussed an idea where people annotate functions that "may longjmp" in some way -- two ideas were
#[longjmp]
and#[pof]
, though neither is ideal. It would be UB for a function that is to be deallocated unless it carries this annotation. Further:#[longjmp]
function calls another longjmp fn (or a fn that may be longjmp, i.e., by fn pointer) with pending destructors in scope. This carries a risk of false warning since the fn may in fact not longjmp.We would also suppress reordering optimizations around function calls in longjmp-functions.
The text was updated successfully, but these errors were encountered: