#![allow(non_upper_case_globals)]

#[no_mangle]
static mut __stack_chk_guard: usize = 0;

extern "C" {
    #[link_name = "llvm.returnaddress"]
    fn return_address(arg: i32) -> *const u8;
}

#[no_mangle]
unsafe extern "C" fn __stack_chk_fail() -> ! {
    let return_address = return_address(0).addr();
    panic!("!!! Stack smashing detected @ {:#x} !!!", return_address)
}

#[allow(static_mut_refs)]
pub unsafe fn init() {
    // TODO generate random
    __stack_chk_guard = 1234;
}
