From 46020f466ff56306e8e1c599f3e128dbadcc0d63 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 6 Jan 2019 07:30:42 -0700 Subject: [PATCH] Add dlfcn, fixes for glib and gstreamer --- src/header/dlfcn/cbindgen.toml | 7 +++++++ src/header/dlfcn/mod.rs | 34 ++++++++++++++++++++++++++++++++++ src/header/mod.rs | 1 + src/header/netinet_in/mod.rs | 2 ++ src/header/unistd/mod.rs | 8 ++++---- 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/header/dlfcn/cbindgen.toml create mode 100644 src/header/dlfcn/mod.rs diff --git a/src/header/dlfcn/cbindgen.toml b/src/header/dlfcn/cbindgen.toml new file mode 100644 index 0000000000..717062ce4c --- /dev/null +++ b/src/header/dlfcn/cbindgen.toml @@ -0,0 +1,7 @@ +sys_includes = [] +include_guard = "_DLFCN_H" +language = "C" +style = "Tag" + +[enum] +prefix_with_name = true diff --git a/src/header/dlfcn/mod.rs b/src/header/dlfcn/mod.rs new file mode 100644 index 0000000000..ca14d8c83b --- /dev/null +++ b/src/header/dlfcn/mod.rs @@ -0,0 +1,34 @@ +//! dlfcn implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/dlfcn.h.html + +use core::{ptr, str}; + +use c_str::CStr; +use platform::types::*; + +pub const RTLD_LAZY: c_int = 0x0001; +pub const RTLD_NOW: c_int = 0x0002; +pub const RTLD_GLOBAL: c_int = 0x0100; +pub const RTLD_LOCAL: c_int = 0x0000; + +#[no_mangle] +pub unsafe extern "C" fn dlopen(filename: *const c_char, flags: c_int) -> *mut c_void { + let filename_cstr = CStr::from_ptr(filename); + let filename_str = str::from_utf8_unchecked(filename_cstr.to_bytes()); + eprintln!("dlopen({}, {:#>04X})", filename_str, flags); + ptr::null_mut() +} + +#[no_mangle] +pub extern "C" fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void { + ptr::null_mut() +} + +#[no_mangle] +pub extern "C" fn dlclose(handle: *mut c_void) -> c_int { + 0 +} + +#[no_mangle] +pub extern "C" fn dlerror() -> *mut c_char { + ptr::null_mut() +} diff --git a/src/header/mod.rs b/src/header/mod.rs index 20fe667578..e2feb6bbac 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -3,6 +3,7 @@ pub mod arpa_inet; pub mod assert; pub mod ctype; pub mod dirent; +pub mod dlfcn; pub mod errno; pub mod fcntl; pub mod _fenv; diff --git a/src/header/netinet_in/mod.rs b/src/header/netinet_in/mod.rs index 78ff911b45..1587bccd9e 100644 --- a/src/header/netinet_in/mod.rs +++ b/src/header/netinet_in/mod.rs @@ -64,10 +64,12 @@ pub const INADDR_ALLHOSTS_GROUP: u32 = 0xE000_0001; pub const INADDR_ALLRTRS_GROUP: u32 = 0xE000_0002; pub const INADDR_MAX_LOCAL_GROUP: u32 = 0xE000_00FF; +#[no_mangle] pub static in6addr_any: in6_addr = in6_addr { s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }; +#[no_mangle] pub static in6addr_loopback: in6_addr = in6_addr { s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] }; diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 26a78fdf30..e0ee2e88f7 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -590,11 +590,11 @@ pub extern "C" fn ttyname_r(fildes: c_int, name: *mut c_char, namesize: size_t) } #[no_mangle] -pub extern "C" fn ualarm(value: useconds_t, interval: useconds_t) -> useconds_t { +pub extern "C" fn ualarm(usecs: useconds_t, interval: useconds_t) -> useconds_t { let mut timer = sys_time::itimerval { it_value: sys_time::timeval { tv_sec: 0, - tv_usec: value as suseconds_t, + tv_usec: usecs as suseconds_t, }, it_interval: sys_time::timeval { tv_sec: 0, @@ -602,7 +602,7 @@ pub extern "C" fn ualarm(value: useconds_t, interval: useconds_t) -> useconds_t }, }; let errno_backup = unsafe { platform::errno }; - let usecs = if sys_time::setitimer(sys_time::ITIMER_REAL, &timer, &mut timer) < 0 { + let ret = if sys_time::setitimer(sys_time::ITIMER_REAL, &timer, &mut timer) < 0 { 0 } else { timer.it_value.tv_sec as useconds_t * 1_000_000 + timer.it_value.tv_usec as useconds_t @@ -611,7 +611,7 @@ pub extern "C" fn ualarm(value: useconds_t, interval: useconds_t) -> useconds_t platform::errno = errno_backup; } - usecs + ret } #[no_mangle]