Debugging SIGSEGV with no_std, no_main program running on x86_64 Linux

64 Views Asked by At

I have a simple program which is no_std and no_main. I want to run it on x86_64 with Linux. I have set panic = abort in Cargo.toml and provide following custom panic handler.

    #[panic_handler]
    #[no_mangle]
    fn panic_fault(panic_info: &PanicInfo) -> ! {
        let msg = rust_alloc::format!("{}", panic_info);
        unsafe {
            libc::write(1, msg.as_ptr() as *const libc::c_void, msg.len()); 
            libc::exit(255);
        }
        unreachable!();
    }

However it gets SIGSEGV on line let msg = rust_alloc::format!("{}", panic_info);

I checked that my custom allocator returns pointer of address 0x5555555710b0 for msg. with proc/[pid]/maps I check that the above address in heap 555555571000-555555572000 rw-p 00000000 00:00 0 [heap]

in /var/log/syslog I can see following line traps: fibonacci[1768947] general protection fault ip:5619f0d118a3 sp:7fff038b97a8 error:0 in fibonacci[5619f0d11000+13000]

why it is hitting error:0? which is perhaps division by 0.

Please guide how to get more information on this.

0

There are 0 best solutions below