Is a similar decorator or macros or something in rust like golang's //go:nosplit

Hi, I'm rewriting google's gvisor in rust and find one thing without proper parallel in rust, the go:nosplit annotation.

All I can find in the internet is like we can disable all stack check by adding rustc -C no-stack-check.

I'm still quite new to rust so it's quite possible that I missed some documentation. Do we have better alternative to provide more fine-grained control over behavior?

I have checked the option provided in rustc -W help, only two thing related to overflow I can find are arithmetic-overflow and overflowing-literals, which obviously is not what I need.

P.S.
//go:nosplit
The //go:nosplit directive specifies that the next function declared in the file must not include a stack overflow check. This is most commonly used by low-level runtime sources invoked at times when it is unsafe for the calling goroutine to be preempted.

ref: The GNU Go Compiler: Compiler Directives

I don't think your question applies to Rust. Rust doesn't use split stacks, and doesn't do any stack overflow checks of its own, relying on the OS access checks. The -C no-redzone=yes seems closest to the "disable stack checks", but it has quite different implementation and use cases.

3 Likes

ok, let me further check with the rust and golang's behavior, the most worrying problem I can see is that " -C no-stack-check=val -- this option is deprecated and does nothing" lol

If you're doing something super low-level that even a stack probe is unwanted, then perhaps you need naked functions?

https://rust-lang.github.io/rfcs/2972-constrained-naked.html

1 Like