What the process of changing unsafe code restrictions?

I want to have panics allowed in inline assembly blocks in some cases.

Simple example (which de facto works correctly):

// I wrote this to inspect the code in IDA
#[inline(never)]
#[no_mangle]
fn wrapper_for_ida(arg: usize) -> usize {
    i_have_asm_block(arg)
}

extern "sysv64-unwind"
fn i_would_maybe_panic(arg: usize) -> usize {
    assert_ne!(arg, 0);
    20 / arg
}

extern "sysv64-unwind" 
fn i_have_asm_block(arg: usize) -> usize {
    unsafe {
        let mut res: usize;
        arch::asm! {
            "shl rdi, 1",
            "call {to_call}",
            in("rdi") arg,
            to_call = sym i_would_maybe_panic,
            out("rax") res,
            clobber_abi("sysv64"),
        }
        res
    }
}

How can I propose this change?

P.S. In case if you are wondering why it may be needed, this allows to implement bytecode interpreter with computed goto without waiting until analog of #[clang::musttail] implemented. Currently, the most convenient way to implement this is to write code with this optimization in C++ and compile it using GCC or Clang (which leaves out Windows MSVC target), and link it with Rust. It is more convenient because FFI supports unwinding if we use "*-unwind" ABI while panicking in inline asm block or in any callee of asm block is undefined behaviour.

You are probably looking for options(may_unwind) which is unstable behind the #![feature(asm_unwind)] feature gate.

2 Likes

Nice! I don't even have to do anything. Thanks!