Skip to content

Is longjmp through rust code UB #404

Description

@chorman0773

What is the result of using setjmp in C, entering rust code, then calling longjmp, either from Rust, or after first returning into C. Is this considered undefined behaviour or defined behaviour.

Because of Pin (and likely others, things like replace_with), this cannot be sound in general, but there is a question of whether it is considered immediately undefined behaviour or whether it is defined in Rust.

This intersects with @rust-lang/wg-ffi-unwind. From https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/cost.20of.20supporting.20longjmp.20without.20annotations and https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/longjmp.20rules the likely answer is "Undefined Behaviour" even through frames without destructors/catch_unwind.

In addition to determining the desired behaviour, we should consider what guarantees we've made that would make longjmp unsound (beyond Pin).

(Cc prior broader discussion: #211)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions