Skip to content

crash when using exit syscall using inline assembly #813

@BergmannAtmet

Description

@BergmannAtmet
use std::arch::asm;

fn getpid_syscall() -> i32 {
    let pid: i32;
    unsafe {
        asm!(
            "syscall",
            in("rax") 39,  // assuming x86_64 Linux
            lateout("rax") pid,
            options(nostack)
        );
    }
    pid
}

fn exit_syscall(status: i32) -> ! {
    unsafe {
        asm!(
            "syscall",
            in("rax") 60,  // assuming x86_64 Linux
            in("rdi") status,
            options(noreturn)
        );
    }
}

fn main() {
    //works
    dbg!(getpid_syscall());
    // crash with rustc_codegen_gcc
    exit_syscall(0);
    // unreachable
    std::process::exit(1);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions