1 #[cfg(all(unix, feature = "jit"))] 2 use std::ffi::c_int; 3 #[cfg(feature = "jit")] 4 use std::ffi::c_void; 5 6 // FIXME replace with core::ffi::c_size_t once stablized 7 #[allow(non_camel_case_types)] 8 #[cfg(feature = "jit")] 9 type size_t = usize; 10 11 macro_rules! builtin_functions { 12 ( 13 $register:ident; 14 $( 15 $(#[$attr:meta])? 16 fn $name:ident($($arg_name:ident: $arg_ty:ty),*) -> $ret_ty:ty; 17 )* 18 ) => { 19 #[cfg(feature = "jit")] 20 #[allow(improper_ctypes)] 21 extern "C" { 22 $( 23 $(#[$attr])? 24 fn $name($($arg_name: $arg_ty),*) -> $ret_ty; 25 )* 26 } 27 28 #[cfg(feature = "jit")] 29 pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) { 30 for (name, val) in [$($(#[$attr])? (stringify!($name), $name as *const u8)),*] { 31 builder.symbol(name, val); 32 } 33 } 34 }; 35 } 36 37 builtin_functions! { 38 register_functions_for_jit; 39 40 // integers 41 fn __multi3(a: i128, b: i128) -> i128; 42 fn __muloti4(n: i128, d: i128, oflow: &mut i32) -> i128; 43 fn __udivti3(n: u128, d: u128) -> u128; 44 fn __divti3(n: i128, d: i128) -> i128; 45 fn __umodti3(n: u128, d: u128) -> u128; 46 fn __modti3(n: i128, d: i128) -> i128; 47 fn __rust_u128_addo(a: u128, b: u128) -> (u128, bool); 48 fn __rust_i128_addo(a: i128, b: i128) -> (i128, bool); 49 fn __rust_u128_subo(a: u128, b: u128) -> (u128, bool); 50 fn __rust_i128_subo(a: i128, b: i128) -> (i128, bool); 51 fn __rust_u128_mulo(a: u128, b: u128) -> (u128, bool); 52 fn __rust_i128_mulo(a: i128, b: i128) -> (i128, bool); 53 54 // floats 55 fn __floattisf(i: i128) -> f32; 56 fn __floattidf(i: i128) -> f64; 57 fn __floatuntisf(i: u128) -> f32; 58 fn __floatuntidf(i: u128) -> f64; 59 fn __fixsfti(f: f32) -> i128; 60 fn __fixdfti(f: f64) -> i128; 61 fn __fixunssfti(f: f32) -> u128; 62 fn __fixunsdfti(f: f64) -> u128; 63 64 // allocator 65 // NOTE: These need to be mentioned here despite not being part of compiler_builtins because 66 // newer glibc resolve dlsym("malloc") to libc.so despite the override in the rustc binary to 67 // use jemalloc. Libraries opened with dlopen still get the jemalloc version, causing multiple 68 // allocators to be mixed, resulting in a crash. 69 fn calloc(nobj: size_t, size: size_t) -> *mut c_void; 70 #[cfg(unix)] 71 fn posix_memalign(memptr: *mut *mut c_void, align: size_t, size: size_t) -> c_int; 72 fn malloc(size: size_t) -> *mut c_void; 73 fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; 74 fn free(p: *mut c_void) -> (); 75 76 } 77