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

begin_unwind returns nomally in presence of foreign stack #30791

Closed
nagisa opened this issue Jan 9, 2016 · 5 comments
Closed

begin_unwind returns nomally in presence of foreign stack #30791

nagisa opened this issue Jan 9, 2016 · 5 comments

Comments

@nagisa
Copy link
Member

nagisa commented Jan 9, 2016

begin_unwind is a diverging function, but sometimes it does return normally, when the panicking happens across the FFI boundary. We can, and should, detect normal return somewhere in these diverging functions and abort the process so we do not hit the ud2 that’s generated after the call to begin_unwind.

cc @alexcrichton

@nagisa
Copy link
Member Author

nagisa commented Jan 9, 2016

With the linked issue, I’m aware of at least 2 cases where this behaviour was encountered.

@mahkoh
Copy link
Contributor

mahkoh commented Jan 9, 2016

When a diverging function returns, the behavior is undefined. Are you deliberately inserting an abort only after bugin_unwind or in general after every noreturn function?

We can, and should, detect normal return somewhere in these diverging functions

Which diverging functions are you referring to? In general the compiler cannot detect this and since the behavior is undefined if it happens it doesn't have to.

and abort the process so we do not hit the ud2

ud2 is how you abort the process on x86_64. You said that you wanted to replace trap by debugtrap, but debugtrap is itself not a noreturn function unlike trap. What do you have in mind that is noreturn and doesn't eventually emit a ud2?

@nagisa
Copy link
Member Author

nagisa commented Jan 9, 2016

@mahkoh

Are you deliberately inserting an abort only after bugin_unwind or in general after every noreturn function?

Deliberately inside begin_unwind, because the function(s) it is calling are marked diverging and they are not always diverging (and we want begin_unwind to be diverging).

Which diverging functions are you referring to?

Namely, the rust_panic (or something even deeper in the chain), which is marked as diverging, but, as was shown, isn’t always-diverging. I guess we would mark that function not-diverging and do an “abort” after rust_panic returns.

You said that you wanted to replace trap by debugtrap, but debugtrap is itself not a noreturn function unlike trap. What do you have in mind that is noreturn and doesn't eventually emit an ud2?

debugtrap was mostly me throwing ideas around. Seems like it won’t work, after all. Perhaps rt_print!("something something about UB, no cleanups and aborting; perhaps also about unwinding through FFI boundary") into ::std::proccess::exit(whatever code we use for panics)? I don’t know.

@alexcrichton
Copy link
Member

@nagisa what would the alternative be? Perhaps calling C's abort?

@nagisa nagisa closed this as completed Jan 11, 2016
@alexcrichton
Copy link
Member

(to clarify, we had some discussion on IRC, and the conclusion was to close)

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

No branches or pull requests

3 participants