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

setjmp/longjmp #1208

Closed
jeff-davis opened this issue Jan 14, 2019 · 2 comments
Closed

setjmp/longjmp #1208

jeff-davis opened this issue Jan 14, 2019 · 2 comments
Labels
E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Milestone

Comments

@jeff-davis
Copy link

I would like support for setjmp/longjmp (and friends sigsetjmp/siglongjmp). The use case is as follows:

I am trying to integrate with postgres (written in C), which means calling into postgres functions. The postgres exception mechanism uses sigsetjmp/siglongjmp.

The idea is, right before calling a postgres function via FFI call, I would do what postgres does in its PG_TRY() / PG_CATCH() macros, which involves sigsetjmp() and some local variable manipulation, and updating a global pointer. That would allow me to catch the siglongjmp() before it bypasses any rust frames, turn it into a rust panic, and properly unwind.

Later, before returning to postgres, I could catch this panic unwind in the highest rust frame, and turn it back into a siglongjmp(). I could be careful that all non-trivial variables have gone out of scope before the siglongjmp() takes place, so that no important destructors are skipped.

If this is a reasonable thing to do, I'd be willing to try to implement it for the libc crate and offer a patch, though I may need some help getting the platform stuff right (because the jmp_buf struct size is platform-dependent).

If it's not a reasonable thing to do, please let me know.

@alexcrichton
Copy link
Member

Seems reasonable to me to add!

@tgross35
Copy link
Contributor

Based on discussion at #1216, it sounds like the correct thing to do would be to add intrinsics rather than binding the functions in libc. And that if we were to add these to libc, we would first need an attribute to indicate that a function may return twice.

There is also an open RFC issue at rust-lang/rfcs#2625 and I think some resolution there is necessary in order to do anything here, so I am just going to close this for now.

@tgross35 tgross35 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

3 participants