From c71088e768a082153feed0e382d1072cb9783943 Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jackpot51@gmail.com> Date: Mon, 14 Jan 2019 21:07:24 -0700 Subject: [PATCH] Cleanup and format --- src/header/dlfcn/mod.rs | 6 +- src/header/mod.rs | 4 +- src/header/netdb/db.rs | 31 ++++ src/header/netdb/lookup.rs | 252 ++++++++++++++++++++++++++++++ src/header/netdb/mod.rs | 280 +++------------------------------- src/header/netinet_in/mod.rs | 4 +- src/header/pwd/mod.rs | 12 +- src/header/regex/mod.rs | 9 +- src/header/signal/mod.rs | 11 +- src/header/stdio/mod.rs | 22 ++- src/header/stdlib/sort.rs | 4 +- src/header/sys_statvfs/mod.rs | 2 +- src/header/sys_timeb/mod.rs | 2 +- src/header/sys_uio/mod.rs | 5 +- src/header/unistd/mod.rs | 6 +- src/header/unistd/sysconf.rs | 4 +- src/header/wchar/mod.rs | 43 ++++-- src/lib.rs | 1 - src/macros.rs | 4 +- src/platform/linux/mod.rs | 30 ++-- src/platform/mod.rs | 6 +- src/platform/pte.rs | 57 ++++--- src/platform/redox/extra.rs | 21 ++- src/platform/redox/mod.rs | 37 ++++- src/platform/redox/signal.rs | 24 ++- src/start.rs | 8 +- 26 files changed, 507 insertions(+), 378 deletions(-) create mode 100644 src/header/netdb/db.rs create mode 100644 src/header/netdb/lookup.rs diff --git a/src/header/dlfcn/mod.rs b/src/header/dlfcn/mod.rs index 19089c423..173666564 100644 --- a/src/header/dlfcn/mod.rs +++ b/src/header/dlfcn/mod.rs @@ -1,7 +1,7 @@ //! dlfcn implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/dlfcn.h.html +use core::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; use core::{ptr, str}; -use core::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use c_str::CStr; use platform::types::*; @@ -38,7 +38,9 @@ pub unsafe extern "C" fn dlopen(filename: *const c_char, flags: c_int) -> *mut c let filename_opt = if filename.is_null() { None } else { - Some(str::from_utf8_unchecked(CStr::from_ptr(filename).to_bytes())) + Some(str::from_utf8_unchecked( + CStr::from_ptr(filename).to_bytes(), + )) }; eprintln!("dlopen({:?}, {:#>04x})", filename_opt, flags); diff --git a/src/header/mod.rs b/src/header/mod.rs index 1cda28dc9..ad9bba8f0 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -1,4 +1,5 @@ pub mod _aio; +pub mod _fenv; pub mod arpa_inet; pub mod assert; pub mod ctype; @@ -6,7 +7,6 @@ pub mod dirent; pub mod dlfcn; pub mod errno; pub mod fcntl; -pub mod _fenv; pub mod float; pub mod fnmatch; pub mod getopt; @@ -39,6 +39,7 @@ pub mod sys_statvfs; pub mod sys_time; pub mod sys_timeb; //pub mod sys_times; +pub mod _wctype; pub mod sys_uio; pub mod sys_un; pub mod sys_utsname; @@ -48,4 +49,3 @@ pub mod time; pub mod unistd; pub mod utime; pub mod wchar; -pub mod _wctype; diff --git a/src/header/netdb/db.rs b/src/header/netdb/db.rs new file mode 100644 index 000000000..77bca0207 --- /dev/null +++ b/src/header/netdb/db.rs @@ -0,0 +1,31 @@ +use alloc::string::{String, ToString}; +use alloc::vec::Vec; + +use c_str::CStr; +use fs::File; +use header::fcntl; +use io::{self, BufRead, BufReader}; + +pub struct Db(BufReader<File>); + +impl Db { + pub fn new(path: &CStr) -> io::Result<Self> { + File::open(path, fcntl::O_RDONLY) + .map(BufReader::new) + .map(Db) + } + + pub fn read(&mut self) -> io::Result<Vec<String>> { + let mut parts = Vec::new(); + + let mut line = String::new(); + self.0.read_line(&mut line)?; + if let Some(not_comment) = line.split('#').next() { + for part in not_comment.split_whitespace() { + parts.push(part.to_string()); + } + } + + Ok(parts) + } +} diff --git a/src/header/netdb/lookup.rs b/src/header/netdb/lookup.rs new file mode 100644 index 000000000..64ea239c2 --- /dev/null +++ b/src/header/netdb/lookup.rs @@ -0,0 +1,252 @@ +use alloc::boxed::Box; +use alloc::string::{String, ToString}; +use alloc::vec::{IntoIter, Vec}; +use core::mem; + +use platform::types::*; +use platform::{Pal, Sys}; + +use header::arpa_inet::htons; +use header::errno::*; +use header::netinet_in::{in_addr, sockaddr_in, IPPROTO_UDP}; +use header::sys_socket; +use header::sys_socket::constants::{AF_INET, SOCK_DGRAM}; +use header::sys_socket::{sockaddr, socklen_t}; +use header::time; +use header::time::timespec; + +use super::dns::{Dns, DnsQuery}; +use super::sys::get_dns_server; + +pub struct LookupHost(IntoIter<in_addr>); + +impl Iterator for LookupHost { + type Item = in_addr; + fn next(&mut self) -> Option<Self::Item> { + self.0.next() + } +} + +pub fn lookup_host(host: &str) -> Result<LookupHost, c_int> { + let dns_string = get_dns_server(); + + let dns_vec: Vec<u8> = dns_string + .trim() + .split(".") + .map(|octet| octet.parse::<u8>().unwrap_or(0)) + .collect(); + + if dns_vec.len() == 4 { + let mut dns_arr = [0u8; 4]; + for (i, octet) in dns_vec.iter().enumerate() { + dns_arr[i] = *octet; + } + let dns_addr = unsafe { mem::transmute::<[u8; 4], u32>(dns_arr) }; + + let mut timespec = timespec::default(); + Sys::clock_gettime(time::constants::CLOCK_REALTIME, &mut timespec); + let tid = (timespec.tv_nsec >> 16) as u16; + + let packet = Dns { + transaction_id: tid, + flags: 0x0100, + queries: vec![DnsQuery { + name: host.to_string(), + q_type: 0x0001, + q_class: 0x0001, + }], + answers: vec![], + }; + + let packet_data = packet.compile(); + let packet_data_len = packet_data.len(); + + let packet_data_box = packet_data.into_boxed_slice(); + let packet_data_ptr = Box::into_raw(packet_data_box) as *mut _ as *mut c_void; + + let dest = sockaddr_in { + sin_family: AF_INET as u16, + sin_port: htons(53), + sin_addr: in_addr { s_addr: dns_addr }, + ..Default::default() + }; + let dest_ptr = &dest as *const _ as *const sockaddr; + + let sock = unsafe { + let sock = sys_socket::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP as i32); + if sys_socket::connect(sock, dest_ptr, mem::size_of_val(&dest) as socklen_t) < 0 { + return Err(EIO); + } + if sys_socket::send(sock, packet_data_ptr, packet_data_len, 0) < 0 { + Box::from_raw(packet_data_ptr); + return Err(EIO); + } + sock + }; + + unsafe { + Box::from_raw(packet_data_ptr); + } + + let i = 0 as socklen_t; + let mut buf = [0u8; 65536]; + let buf_ptr = buf.as_mut_ptr() as *mut c_void; + + let count = unsafe { sys_socket::recv(sock, buf_ptr, 65536, 0) }; + if count < 0 { + return Err(EIO); + } + + match Dns::parse(&buf[..count as usize]) { + Ok(response) => { + let mut addrs = vec![]; + for answer in response.answers.iter() { + if answer.a_type == 0x0001 && answer.a_class == 0x0001 && answer.data.len() == 4 + { + let addr = in_addr { + s_addr: unsafe { + mem::transmute::<[u8; 4], u32>([ + answer.data[0], + answer.data[1], + answer.data[2], + answer.data[3], + ]) + }, + }; + addrs.push(addr); + } + } + Ok(LookupHost(addrs.into_iter())) + } + Err(_err) => Err(EINVAL), + } + } else { + Err(EINVAL) + } +} + +pub fn lookup_addr(addr: in_addr) -> Result<Vec<Vec<u8>>, c_int> { + let dns_string = get_dns_server(); + + let dns_vec: Vec<u8> = dns_string + .trim() + .split('.') + .map(|octet| octet.parse::<u8>().unwrap_or(0)) + .collect(); + + let mut dns_arr = [0u8; 4]; + + for (i, octet) in dns_vec.iter().enumerate() { + dns_arr[i] = *octet; + } + + let mut addr_vec: Vec<u8> = unsafe { mem::transmute::<u32, [u8; 4]>(addr.s_addr).to_vec() }; + addr_vec.reverse(); + let mut name: Vec<u8> = vec![]; + for octet in addr_vec { + for ch in format!("{}", octet).as_bytes() { + name.push(*ch); + } + name.push(b"."[0]); + } + name.pop(); + for ch in b".IN-ADDR.ARPA" { + name.push(*ch); + } + + if dns_vec.len() == 4 { + let mut timespec = timespec::default(); + Sys::clock_gettime(time::constants::CLOCK_REALTIME, &mut timespec); + let tid = (timespec.tv_nsec >> 16) as u16; + + let packet = Dns { + transaction_id: tid, + flags: 0x0100, + queries: vec![DnsQuery { + name: String::from_utf8(name).unwrap(), + q_type: 0x000C, + q_class: 0x0001, + }], + answers: vec![], + }; + + let packet_data = packet.compile(); + let packet_data_len = packet_data.len(); + let packet_data_box = packet_data.into_boxed_slice(); + let packet_data_ptr = Box::into_raw(packet_data_box) as *mut _ as *mut c_void; + + let dest = sockaddr_in { + sin_family: AF_INET as u16, + sin_port: htons(53), + sin_addr: in_addr { + s_addr: unsafe { mem::transmute::<[u8; 4], u32>(dns_arr) }, + }, + ..Default::default() + }; + + let dest_ptr = &dest as *const _ as *const sockaddr; + + let sock = unsafe { + let sock = sys_socket::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP as i32); + if sys_socket::connect(sock, dest_ptr, mem::size_of_val(&dest) as socklen_t) < 0 { + return Err(EIO); + } + sock + }; + + unsafe { + if sys_socket::send(sock, packet_data_ptr, packet_data_len, 0) < 0 { + return Err(EIO); + } + } + + unsafe { + Box::from_raw(packet_data_ptr); + } + + let i = mem::size_of::<sockaddr_in>() as socklen_t; + let mut buf = [0u8; 65536]; + let buf_ptr = buf.as_mut_ptr() as *mut c_void; + + let count = unsafe { sys_socket::recv(sock, buf_ptr, 65536, 0) }; + if count < 0 { + return Err(EIO); + } + + match Dns::parse(&buf[..count as usize]) { + Ok(response) => { + let mut names = vec![]; + for answer in response.answers.iter() { + if answer.a_type == 0x000C && answer.a_class == 0x0001 { + // answer.data is encoded kinda weird. + // Basically length-prefixed strings for each + // subsection of the domain. + // We need to parse this to insert periods where + // they belong (ie at the end of each string) + let data = parse_revdns_answer(&answer.data); + names.push(data); + } + } + Ok(names) + } + Err(_err) => Err(EINVAL), + } + } else { + Err(EINVAL) + } +} + +fn parse_revdns_answer(data: &[u8]) -> Vec<u8> { + let mut cursor = 0; + let mut index = 0; + let mut output = data.to_vec(); + while index < data.len() - 1 { + let offset = data[index] as usize; + index = cursor + offset + 1; + output[index] = b'.'; + cursor = index; + } + //we don't want an extra period at the end + output.pop(); + output +} diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs index b39a9f922..f8a0813c3 100644 --- a/src/header/netdb/mod.rs +++ b/src/header/netdb/mod.rs @@ -7,8 +7,7 @@ use core::{mem, ptr, slice, str}; use alloc::boxed::Box; use alloc::str::SplitWhitespace; -use alloc::string::{String, ToString}; -use alloc::vec::{IntoIter, Vec}; +use alloc::vec::Vec; use c_str::{CStr, CString}; @@ -17,19 +16,14 @@ use platform::rlb::{Line, RawLineBuffer}; use platform::types::*; use platform::{Pal, Sys}; -use self::dns::{Dns, DnsQuery}; - use header::arpa_inet::{htons, inet_aton}; use header::errno::*; use header::fcntl::O_RDONLY; -use header::netinet_in::{in_addr, sockaddr_in, IPPROTO_UDP}; +use header::netinet_in::{in_addr, sockaddr_in}; use header::stdlib::atoi; use header::strings::strcasecmp; -use header::sys_socket; -use header::sys_socket::constants::{AF_INET, SOCK_DGRAM}; +use header::sys_socket::constants::AF_INET; use header::sys_socket::{sockaddr, socklen_t}; -use header::time; -use header::time::timespec; use header::unistd::SEEK_SET; #[cfg(target_os = "linux")] @@ -40,17 +34,14 @@ pub mod sys; #[path = "redox.rs"] pub mod sys; -const MAXADDRS: usize = 35; -const MAXALIASES: usize = 35; +//TODO: use self::db::Db; +pub mod db; -struct LookupHost(IntoIter<in_addr>); +use self::lookup::{lookup_addr, lookup_host}; +pub mod lookup; -impl Iterator for LookupHost { - type Item = in_addr; - fn next(&mut self) -> Option<Self::Item> { - self.0.next() - } -} +const MAXADDRS: usize = 35; +const MAXALIASES: usize = 35; #[repr(C)] pub struct hostent { @@ -69,6 +60,13 @@ pub struct netent { n_net: c_ulong, /* network # */ } +#[repr(C)] +pub struct protoent { + p_name: *mut c_char, /* official protocol name */ + p_aliases: *mut *mut c_char, /* alias list */ + p_proto: c_int, /* protocol # */ +} + #[repr(C)] pub struct servent { s_name: *mut c_char, /* official service name */ @@ -77,13 +75,6 @@ pub struct servent { s_proto: *mut c_char, /* protocol to use */ } -#[repr(C)] -pub struct protoent { - p_name: *mut c_char, /* official protocol name */ - p_aliases: *mut *mut c_char, /* alias list */ - p_proto: c_int, /* protocol # */ -} - #[repr(C)] pub struct addrinfo { ai_flags: c_int, /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ @@ -196,230 +187,6 @@ fn bytes_to_box_str(bytes: &[u8]) -> Box<str> { Box::from(core::str::from_utf8(bytes).unwrap_or("")) } -fn lookup_host(host: &str) -> Result<LookupHost, c_int> { - let dns_string = sys::get_dns_server(); - - let dns_vec: Vec<u8> = dns_string - .trim() - .split(".") - .map(|octet| octet.parse::<u8>().unwrap_or(0)) - .collect(); - - if dns_vec.len() == 4 { - let mut dns_arr = [0u8; 4]; - for (i, octet) in dns_vec.iter().enumerate() { - dns_arr[i] = *octet; - } - let dns_addr = unsafe { mem::transmute::<[u8; 4], u32>(dns_arr) }; - - let mut timespec = timespec::default(); - Sys::clock_gettime(time::constants::CLOCK_REALTIME, &mut timespec); - let tid = (timespec.tv_nsec >> 16) as u16; - - let packet = Dns { - transaction_id: tid, - flags: 0x0100, - queries: vec![DnsQuery { - name: host.to_string(), - q_type: 0x0001, - q_class: 0x0001, - }], - answers: vec![], - }; - - let packet_data = packet.compile(); - let packet_data_len = packet_data.len(); - - let packet_data_box = packet_data.into_boxed_slice(); - let packet_data_ptr = Box::into_raw(packet_data_box) as *mut _ as *mut c_void; - - let dest = sockaddr_in { - sin_family: AF_INET as u16, - sin_port: htons(53), - sin_addr: in_addr { s_addr: dns_addr }, - ..Default::default() - }; - let dest_ptr = &dest as *const _ as *const sockaddr; - - let sock = unsafe { - let sock = sys_socket::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP as i32); - if sys_socket::connect(sock, dest_ptr, mem::size_of_val(&dest) as socklen_t) < 0 { - return Err(EIO); - } - if sys_socket::send(sock, packet_data_ptr, packet_data_len, 0) < 0 { - Box::from_raw(packet_data_ptr); - return Err(EIO); - } - sock - }; - - unsafe { - Box::from_raw(packet_data_ptr); - } - - let i = 0 as socklen_t; - let mut buf = [0u8; 65536]; - let buf_ptr = buf.as_mut_ptr() as *mut c_void; - - let count = unsafe { sys_socket::recv(sock, buf_ptr, 65536, 0) }; - if count < 0 { - return Err(EIO); - } - - match Dns::parse(&buf[..count as usize]) { - Ok(response) => { - let mut addrs = vec![]; - for answer in response.answers.iter() { - if answer.a_type == 0x0001 && answer.a_class == 0x0001 && answer.data.len() == 4 - { - let addr = in_addr { - s_addr: unsafe { - mem::transmute::<[u8; 4], u32>([ - answer.data[0], - answer.data[1], - answer.data[2], - answer.data[3], - ]) - }, - }; - addrs.push(addr); - } - } - Ok(LookupHost(addrs.into_iter())) - } - Err(_err) => Err(EINVAL), - } - } else { - Err(EINVAL) - } -} - -fn lookup_addr(addr: in_addr) -> Result<Vec<Vec<u8>>, c_int> { - let dns_string = sys::get_dns_server(); - - let dns_vec: Vec<u8> = dns_string - .trim() - .split('.') - .map(|octet| octet.parse::<u8>().unwrap_or(0)) - .collect(); - - let mut dns_arr = [0u8; 4]; - - for (i, octet) in dns_vec.iter().enumerate() { - dns_arr[i] = *octet; - } - - let mut addr_vec: Vec<u8> = unsafe { mem::transmute::<u32, [u8; 4]>(addr.s_addr).to_vec() }; - addr_vec.reverse(); - let mut name: Vec<u8> = vec![]; - for octet in addr_vec { - for ch in format!("{}", octet).as_bytes() { - name.push(*ch); - } - name.push(b"."[0]); - } - name.pop(); - for ch in b".IN-ADDR.ARPA" { - name.push(*ch); - } - - if dns_vec.len() == 4 { - let mut timespec = timespec::default(); - Sys::clock_gettime(time::constants::CLOCK_REALTIME, &mut timespec); - let tid = (timespec.tv_nsec >> 16) as u16; - - let packet = Dns { - transaction_id: tid, - flags: 0x0100, - queries: vec![DnsQuery { - name: String::from_utf8(name).unwrap(), - q_type: 0x000C, - q_class: 0x0001, - }], - answers: vec![], - }; - - let packet_data = packet.compile(); - let packet_data_len = packet_data.len(); - let packet_data_box = packet_data.into_boxed_slice(); - let packet_data_ptr = Box::into_raw(packet_data_box) as *mut _ as *mut c_void; - - let dest = sockaddr_in { - sin_family: AF_INET as u16, - sin_port: htons(53), - sin_addr: in_addr { - s_addr: unsafe { mem::transmute::<[u8; 4], u32>(dns_arr) }, - }, - ..Default::default() - }; - - let dest_ptr = &dest as *const _ as *const sockaddr; - - let sock = unsafe { - let sock = sys_socket::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP as i32); - if sys_socket::connect(sock, dest_ptr, mem::size_of_val(&dest) as socklen_t) < 0 { - return Err(EIO); - } - sock - }; - - unsafe { - if sys_socket::send(sock, packet_data_ptr, packet_data_len, 0) < 0 { - return Err(EIO); - } - } - - unsafe { - Box::from_raw(packet_data_ptr); - } - - let i = mem::size_of::<sockaddr_in>() as socklen_t; - let mut buf = [0u8; 65536]; - let buf_ptr = buf.as_mut_ptr() as *mut c_void; - - let count = unsafe { sys_socket::recv(sock, buf_ptr, 65536, 0) }; - if count < 0 { - return Err(EIO); - } - - match Dns::parse(&buf[..count as usize]) { - Ok(response) => { - let mut names = vec![]; - for answer in response.answers.iter() { - if answer.a_type == 0x000C && answer.a_class == 0x0001 { - // answer.data is encoded kinda weird. - // Basically length-prefixed strings for each - // subsection of the domain. - // We need to parse this to insert periods where - // they belong (ie at the end of each string) - let data = parse_revdns_answer(&answer.data); - names.push(data); - } - } - Ok(names) - } - Err(_err) => Err(EINVAL), - } - } else { - Err(EINVAL) - } -} - -fn parse_revdns_answer(data: &[u8]) -> Vec<u8> { - let mut cursor = 0; - let mut index = 0; - let mut output = data.to_vec(); - while index < data.len() - 1 { - let offset = data[index] as usize; - index = cursor + offset + 1; - output[index] = b'.'; - cursor = index; - } - //we don't want an extra period at the end - output.pop(); - output -} - #[no_mangle] pub unsafe extern "C" fn endhostent() { Sys::close(HOSTDB); @@ -800,10 +567,7 @@ pub unsafe extern "C" fn getprotoent() -> *mut protoent { } #[no_mangle] -pub unsafe extern "C" fn getservbyname( - name: *const c_char, - proto: *const c_char, -) -> *mut servent { +pub unsafe extern "C" fn getservbyname(name: *const c_char, proto: *const c_char) -> *mut servent { setservent(SERV_STAYOPEN); let mut p: *mut servent; if proto.is_null() { @@ -1012,11 +776,7 @@ pub unsafe extern "C" fn getaddrinfo( Some(CStr::from_ptr(service)) }; - let hints_opt = if hints.is_null() { - None - } else { - Some(&*hints) - }; + let hints_opt = if hints.is_null() { None } else { Some(&*hints) }; eprintln!( "getaddrinfo({:?}, {:?})", @@ -1038,6 +798,7 @@ pub unsafe extern "C" fn getnameinfo( servlen: socklen_t, flags: c_int, ) -> c_int { + //TODO: getnameinfo if addrlen as usize != mem::size_of::<sockaddr_in>() { return EAI_FAMILY; } @@ -1088,5 +849,6 @@ pub extern "C" fn gai_strerror(errcode: c_int) -> *const c_char { EAI_SYSTEM => c_str!("System error"), EAI_OVERFLOW => c_str!("Overflow"), _ => c_str!("Unknown error"), - }.as_ptr() + } + .as_ptr() } diff --git a/src/header/netinet_in/mod.rs b/src/header/netinet_in/mod.rs index 1587bccd9..807f5534a 100644 --- a/src/header/netinet_in/mod.rs +++ b/src/header/netinet_in/mod.rs @@ -66,10 +66,10 @@ 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] + 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] + s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], }; diff --git a/src/header/pwd/mod.rs b/src/header/pwd/mod.rs index f53b02a19..bd0a8ad42 100644 --- a/src/header/pwd/mod.rs +++ b/src/header/pwd/mod.rs @@ -169,15 +169,15 @@ pub unsafe extern "C" fn getpwnam_r( OptionPasswd::Error => { *result = ptr::null_mut(); -1 - }, + } OptionPasswd::NotFound => { *result = ptr::null_mut(); 0 - }, + } OptionPasswd::Found(_) => { *result = out; 0 - }, + } } } @@ -199,15 +199,15 @@ pub unsafe extern "C" fn getpwuid_r( OptionPasswd::Error => { *result = ptr::null_mut(); -1 - }, + } OptionPasswd::NotFound => { *result = ptr::null_mut(); 0 - }, + } OptionPasswd::Found(_) => { *result = out; 0 - }, + } } } diff --git a/src/header/regex/mod.rs b/src/header/regex/mod.rs index 2c9452ac4..f78767834 100644 --- a/src/header/regex/mod.rs +++ b/src/header/regex/mod.rs @@ -74,7 +74,7 @@ pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: }; mem::forget(branches); 0 - }, + } Err(CompileError::EmptyRepetition) | Err(CompileError::IntegerOverflow) | Err(CompileError::IllegalRange) => REG_BADBR, @@ -146,7 +146,12 @@ pub unsafe extern "C" fn regexec( #[no_mangle] #[linkage = "weak"] // redefined in GIT -pub extern "C" fn regerror(code: c_int, _regex: *const regex_t, out: *mut c_char, max: size_t) -> size_t { +pub extern "C" fn regerror( + code: c_int, + _regex: *const regex_t, + out: *mut c_char, + max: size_t, +) -> size_t { let string = match code { 0 => "No error\0", REG_NOMATCH => "No match\0", diff --git a/src/header/signal/mod.rs b/src/header/signal/mod.rs index da11aa197..b4b8989c0 100644 --- a/src/header/signal/mod.rs +++ b/src/header/signal/mod.rs @@ -49,7 +49,11 @@ pub extern "C" fn killpg(pgrp: pid_t, sig: c_int) -> c_int { } #[no_mangle] -pub extern "C" fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int { +pub extern "C" fn pthread_sigmask( + how: c_int, + set: *const sigset_t, + oldset: *mut sigset_t, +) -> c_int { // On Linux and Redox, pthread_sigmask and sigprocmask are equivalent if sigprocmask(how, set, oldset) == 0 { 0 @@ -165,10 +169,7 @@ extern "C" { } #[no_mangle] -pub extern "C" fn signal( - sig: c_int, - func: extern "C" fn(c_int), -) -> extern "C" fn(c_int) { +pub extern "C" fn signal(sig: c_int, func: extern "C" fn(c_int)) -> extern "C" fn(c_int) { let sa = sigaction { sa_handler: func, sa_flags: SA_RESTART as c_ulong, diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 19811a12c..1fb4c6977 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -3,9 +3,9 @@ use alloc::borrow::{Borrow, BorrowMut}; use alloc::boxed::Box; use alloc::vec::Vec; -use core::{fmt, mem, ptr, slice, str}; use core::fmt::Write as WriteFmt; use core::ops::{Deref, DerefMut}; +use core::{fmt, mem, ptr, slice, str}; use va_list::VaList as va_list; use c_str::CStr; @@ -291,7 +291,11 @@ pub unsafe extern "C" fn fgetpos(stream: *mut FILE, pos: *mut fpos_t) -> c_int { /// Get a string from the stream #[no_mangle] -pub unsafe extern "C" fn fgets(original: *mut c_char, max: c_int, stream: *mut FILE) -> *mut c_char { +pub unsafe extern "C" fn fgets( + original: *mut c_char, + max: c_int, + stream: *mut FILE, +) -> *mut c_char { let mut stream = (*stream).lock(); let mut out = original; let max = max as usize; @@ -343,9 +347,7 @@ pub unsafe extern "C" fn fgets(original: *mut c_char, max: c_int, stream: *mut F if max >= 1 { // Write the NUL byte - unsafe { - *out = 0; - } + *out = 0; } if wrote { original @@ -570,7 +572,7 @@ pub unsafe extern "C" fn fwrite( stream: *mut FILE, ) -> size_t { if size == 0 || nitems == 0 { - return 0 + return 0; } let mut stream = (*stream).lock(); let buf = slice::from_raw_parts_mut(ptr as *mut u8, size as usize * nitems as usize); @@ -865,7 +867,7 @@ pub unsafe extern "C" fn setvbuf( Buffer::Owned(vec![0; size as usize]) // } } else { - unsafe { Buffer::Borrowed(slice::from_raw_parts_mut(buf as *mut u8, size)) } + Buffer::Borrowed(slice::from_raw_parts_mut(buf as *mut u8, size)) }; stream.flags |= F_SVB; 0 @@ -928,7 +930,11 @@ pub unsafe extern "C" fn vprintf(format: *const c_char, ap: va_list) -> c_int { } #[no_mangle] -pub unsafe extern "C" fn vasprintf(strp: *mut *mut c_char, format: *const c_char, ap: va_list) -> c_int { +pub unsafe extern "C" fn vasprintf( + strp: *mut *mut c_char, + format: *const c_char, + ap: va_list, +) -> c_int { let mut alloc_writer = platform::AllocStringWriter(ptr::null_mut(), 0); let ret = printf::printf(&mut alloc_writer, format, ap); *strp = alloc_writer.0 as *mut c_char; diff --git a/src/header/stdlib/sort.rs b/src/header/stdlib/sort.rs index 81e3ba3d4..66713fa32 100644 --- a/src/header/stdlib/sort.rs +++ b/src/header/stdlib/sort.rs @@ -137,9 +137,7 @@ fn heap_sift_down( swap_idx = child; swap_ptr = first_child_ptr; } - if child < end - && comp(swap_ptr as *const c_void, second_child_ptr as *const c_void) < 0 - { + if child < end && comp(swap_ptr as *const c_void, second_child_ptr as *const c_void) < 0 { swap_idx = child + 1; swap_ptr = second_child_ptr; } diff --git a/src/header/sys_statvfs/mod.rs b/src/header/sys_statvfs/mod.rs index 27287c73f..6da8f6e43 100644 --- a/src/header/sys_statvfs/mod.rs +++ b/src/header/sys_statvfs/mod.rs @@ -1,7 +1,7 @@ //! statvfs implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstatvfs.h.html use c_str::CStr; -use header::fcntl::{O_PATH}; +use header::fcntl::O_PATH; use platform::types::*; use platform::{Pal, Sys}; diff --git a/src/header/sys_timeb/mod.rs b/src/header/sys_timeb/mod.rs index 4c1489f70..b3b6713a2 100644 --- a/src/header/sys_timeb/mod.rs +++ b/src/header/sys_timeb/mod.rs @@ -21,7 +21,7 @@ pub unsafe extern "C" fn ftime(tp: *mut timeb) -> c_int { } (*tp).time = tv.tv_sec; - (*tp).millitm = (tv.tv_usec/1000) as c_ushort; + (*tp).millitm = (tv.tv_usec / 1000) as c_ushort; (*tp).timezone = tz.tz_minuteswest as c_short; (*tp).dstflag = tz.tz_dsttime as c_short; diff --git a/src/header/sys_uio/mod.rs b/src/header/sys_uio/mod.rs index 3d137276c..2beda033e 100644 --- a/src/header/sys_uio/mod.rs +++ b/src/header/sys_uio/mod.rs @@ -17,10 +17,7 @@ pub struct iovec { impl iovec { unsafe fn to_slice(&self) -> &mut [u8] { - slice::from_raw_parts_mut( - self.iov_base as *mut u8, - self.iov_len as usize - ) + slice::from_raw_parts_mut(self.iov_base as *mut u8, self.iov_len as usize) } } diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 998970da7..1ca7a6c08 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -486,7 +486,11 @@ pub extern "C" fn read(fildes: c_int, buf: *const c_void, nbyte: size_t) -> ssiz } #[no_mangle] -pub unsafe extern "C" fn readlink(path: *const c_char, buf: *mut c_char, bufsize: size_t) -> ssize_t { +pub unsafe extern "C" fn readlink( + path: *const c_char, + buf: *mut c_char, + bufsize: size_t, +) -> ssize_t { let path = CStr::from_ptr(path); let buf = slice::from_raw_parts_mut(buf as *mut u8, bufsize as usize); Sys::readlink(path, buf) diff --git a/src/header/unistd/sysconf.rs b/src/header/unistd/sysconf.rs index 70f7694f3..c29056024 100644 --- a/src/header/unistd/sysconf.rs +++ b/src/header/unistd/sysconf.rs @@ -44,7 +44,9 @@ pub extern "C" fn sysconf(name: c_int) -> c_long { _SC_SYMLOOP_MAX => -1, _SC_HOST_NAME_MAX => 64, _ => { - unsafe { platform::errno = errno::EINVAL; } + unsafe { + platform::errno = errno::EINVAL; + } -1 } } diff --git a/src/header/wchar/mod.rs b/src/header/wchar/mod.rs index d6eb37a7e..9d1d245d2 100644 --- a/src/header/wchar/mod.rs +++ b/src/header/wchar/mod.rs @@ -169,12 +169,7 @@ pub unsafe extern "C" fn mbsnrtowcs( while (dst_ptr.is_null() || dst_offset < dst_len) && src_offset < src_len { let ps_copy = *ps; let mut wc: wchar_t = 0; - let amount = mbrtowc( - &mut wc, - src.add(src_offset), - src_len - src_offset, - ps, - ); + let amount = mbrtowc(&mut wc, src.add(src_offset), src_len - src_offset, ps); // Stop in the event a decoding error occured. if amount == -1isize as usize { @@ -363,7 +358,11 @@ pub unsafe extern "C" fn wcslen(ws: *const wchar_t) -> c_ulong { } #[no_mangle] -pub unsafe extern "C" fn wcsncat(ws1: *mut wchar_t, ws2: *const wchar_t, n: size_t) -> *mut wchar_t { +pub unsafe extern "C" fn wcsncat( + ws1: *mut wchar_t, + ws2: *const wchar_t, + n: size_t, +) -> *mut wchar_t { let len = wcslen(ws1); let dest = ws1.add(len as usize); let mut i = 0; @@ -396,7 +395,11 @@ pub unsafe extern "C" fn wcsncmp(ws1: *const wchar_t, ws2: *const wchar_t, n: si } #[no_mangle] -pub unsafe extern "C" fn wcsncpy(ws1: *mut wchar_t, ws2: *const wchar_t, n: size_t) -> *mut wchar_t { +pub unsafe extern "C" fn wcsncpy( + ws1: *mut wchar_t, + ws2: *const wchar_t, + n: size_t, +) -> *mut wchar_t { let mut i = 0; while i < n { let wc = *ws2.add(i); @@ -523,13 +526,29 @@ pub unsafe extern "C" fn wmemcmp(ws1: *const wchar_t, ws2: *const wchar_t, n: si } #[no_mangle] -pub unsafe extern "C" fn wmemcpy(ws1: *mut wchar_t, ws2: *const wchar_t, n: size_t) -> *mut wchar_t { - string::memcpy(ws1 as *mut c_void, ws2 as *const c_void, n * mem::size_of::<wchar_t>()) as *mut wchar_t +pub unsafe extern "C" fn wmemcpy( + ws1: *mut wchar_t, + ws2: *const wchar_t, + n: size_t, +) -> *mut wchar_t { + string::memcpy( + ws1 as *mut c_void, + ws2 as *const c_void, + n * mem::size_of::<wchar_t>(), + ) as *mut wchar_t } #[no_mangle] -pub unsafe extern "C" fn wmemmove(ws1: *mut wchar_t, ws2: *const wchar_t, n: size_t) -> *mut wchar_t { - string::memmove(ws1 as *mut c_void, ws2 as *const c_void, n * mem::size_of::<wchar_t>()) as *mut wchar_t +pub unsafe extern "C" fn wmemmove( + ws1: *mut wchar_t, + ws2: *const wchar_t, + n: size_t, +) -> *mut wchar_t { + string::memmove( + ws1 as *mut c_void, + ws2 as *const c_void, + n * mem::size_of::<wchar_t>(), + ) as *mut wchar_t } #[no_mangle] diff --git a/src/lib.rs b/src/lib.rs index 9116f0d5d..ddff3401e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,6 @@ #![feature(stmt_expr_attributes)] #![feature(str_internals)] #![feature(thread_local)] - #![allow(clippy::cast_lossless)] #![allow(clippy::cast_ptr_alignment)] #![allow(clippy::derive_hash_xor_eq)] diff --git a/src/macros.rs b/src/macros.rs index 9d7ca35e3..0d83ae135 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -3,9 +3,7 @@ macro_rules! c_str { ($lit:expr) => { #[allow(unused_unsafe)] unsafe { - $crate::c_str::CStr::from_bytes_with_nul_unchecked( - concat!($lit, "\0").as_bytes() - ) + $crate::c_str::CStr::from_bytes_with_nul_unchecked(concat!($lit, "\0").as_bytes()) } }; } diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 5a42cda89..96289aa29 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -36,16 +36,16 @@ const CLONE_SIGHAND: usize = 0x0800; #[repr(C)] #[derive(Default)] struct linux_statfs { - f_type: c_long, /* type of file system (see below) */ - f_bsize: c_long, /* optimal transfer block size */ + f_type: c_long, /* type of file system (see below) */ + f_bsize: c_long, /* optimal transfer block size */ f_blocks: fsblkcnt_t, /* total data blocks in file system */ - f_bfree: fsblkcnt_t, /* free blocks in fs */ + f_bfree: fsblkcnt_t, /* free blocks in fs */ f_bavail: fsblkcnt_t, /* free blocks available to unprivileged user */ - f_files: fsfilcnt_t, /* total file nodes in file system */ - f_ffree: fsfilcnt_t, /* free file nodes in fs */ - f_fsid: c_long, /* file system id */ - f_namelen: c_long, /* maximum length of filenames */ - f_frsize: c_long, /* fragment size (since Linux 2.6) */ + f_files: fsfilcnt_t, /* total file nodes in file system */ + f_ffree: fsfilcnt_t, /* free file nodes in fs */ + f_fsid: c_long, /* file system id */ + f_namelen: c_long, /* maximum length of filenames */ + f_frsize: c_long, /* fragment size (since Linux 2.6) */ f_flags: c_long, f_spare: [c_long; 4], } @@ -64,7 +64,6 @@ fn e(sys: usize) -> usize { pub struct Sys; impl Sys { - // fn getrusage(who: c_int, r_usage: *mut rusage) -> c_int { // e(unsafe { syscall!(GETRUSAGE, who, r_usage) }) as c_int // } @@ -163,7 +162,7 @@ impl Pal for Sys { let res = e(unsafe { syscall!(FSTATFS, fildes, kbuf_ptr) }) as c_int; if res == 0 { unsafe { - if ! buf.is_null() { + if !buf.is_null() { (*buf).f_bsize = kbuf.f_bsize as c_ulong; (*buf).f_frsize = if kbuf.f_frsize != 0 { kbuf.f_frsize @@ -327,7 +326,16 @@ impl Pal for Sys { } fn pte_clone() -> pid_t { - e(unsafe { syscall!(CLONE, CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0, 0, 0, 0) }) as pid_t + e(unsafe { + syscall!( + CLONE, + CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, + 0, + 0, + 0, + 0 + ) + }) as pid_t } fn read(fildes: c_int, buf: &mut [u8]) -> ssize_t { diff --git a/src/platform/mod.rs b/src/platform/mod.rs index f48a87c3f..0fb592706 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -104,13 +104,11 @@ impl Read for FileReader { pub struct AllocStringWriter(pub *mut u8, pub usize); impl Write for AllocStringWriter { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { - let ptr = unsafe { - realloc(self.0 as *mut c_void, self.1 + buf.len() + 1) as *mut u8 - }; + let ptr = unsafe { realloc(self.0 as *mut c_void, self.1 + buf.len() + 1) as *mut u8 }; if ptr.is_null() { return Err(io::Error::new( io::ErrorKind::Other, - "AllocStringWriter::write failed to allocate" + "AllocStringWriter::write failed to allocate", )); } self.0 = ptr; diff --git a/src/platform/pte.rs b/src/platform/pte.rs index e04f771df..cace946aa 100644 --- a/src/platform/pte.rs +++ b/src/platform/pte.rs @@ -2,13 +2,13 @@ use alloc::boxed::Box; use alloc::collections::BTreeMap; +use core::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; use core::{intrinsics, ptr}; -use core::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use header::time::timespec; use mutex::{FUTEX_WAIT, FUTEX_WAKE}; -use platform::{Pal, Sys}; use platform::types::{c_int, c_uint, c_void, pid_t}; +use platform::{Pal, Sys}; pub struct Semaphore { lock: i32, @@ -28,7 +28,7 @@ pub enum pte_osResult { PTE_OS_GENERAL_FAILURE, PTE_OS_TIMEOUT, PTE_OS_INTERRUPTED, - PTE_OS_INVALID_PARAM + PTE_OS_INVALID_PARAM, } use self::pte_osResult::*; @@ -55,12 +55,13 @@ pub unsafe extern "C" fn pte_osInit() -> pte_osResult { } #[no_mangle] -pub unsafe extern "C" fn pte_osThreadCreate(entryPoint: pte_osThreadEntryPoint, - _stackSize: c_int, - _initialPriority: c_int, - argv: *mut c_void, - ppte_osThreadHandle: *mut pte_osThreadHandle - ) -> pte_osResult { +pub unsafe extern "C" fn pte_osThreadCreate( + entryPoint: pte_osThreadEntryPoint, + _stackSize: c_int, + _initialPriority: c_int, + argv: *mut c_void, + ppte_osThreadHandle: *mut pte_osThreadHandle, +) -> pte_osResult { // XXX error handling let id = Sys::pte_clone(); if id < 0 { @@ -166,7 +167,10 @@ pub unsafe extern "C" fn pte_osThreadGetPriority(threadHandle: pte_osThreadHandl } #[no_mangle] -pub unsafe extern "C" fn pte_osThreadSetPriority(threadHandle: pte_osThreadHandle, newPriority: c_int) -> pte_osResult { +pub unsafe extern "C" fn pte_osThreadSetPriority( + threadHandle: pte_osThreadHandle, + newPriority: c_int, +) -> pte_osResult { PTE_OS_OK } @@ -237,7 +241,10 @@ pub unsafe extern "C" fn pte_osMutexUnlock(handle: pte_osMutexHandle) -> pte_osR } #[no_mangle] -pub unsafe extern "C" fn pte_osSemaphoreCreate(initialValue: c_int, pHandle: *mut pte_osSemaphoreHandle) -> pte_osResult { +pub unsafe extern "C" fn pte_osSemaphoreCreate( + initialValue: c_int, + pHandle: *mut pte_osSemaphoreHandle, +) -> pte_osResult { *pHandle = Box::into_raw(Box::new(Semaphore { lock: 0, count: initialValue, @@ -252,7 +259,10 @@ pub unsafe extern "C" fn pte_osSemaphoreDelete(handle: pte_osSemaphoreHandle) -> } #[no_mangle] -pub unsafe extern "C" fn pte_osSemaphorePost(handle: pte_osSemaphoreHandle, count: c_int) -> pte_osResult { +pub unsafe extern "C" fn pte_osSemaphorePost( + handle: pte_osSemaphoreHandle, + count: c_int, +) -> pte_osResult { let semaphore = &mut *handle; pte_osMutexLock(&mut semaphore.lock); intrinsics::atomic_xadd(&mut semaphore.count, 1); @@ -261,11 +271,14 @@ pub unsafe extern "C" fn pte_osSemaphorePost(handle: pte_osSemaphoreHandle, coun } #[no_mangle] -pub unsafe extern "C" fn pte_osSemaphorePend(handle: pte_osSemaphoreHandle, pTimeout: *mut c_uint) -> pte_osResult { +pub unsafe extern "C" fn pte_osSemaphorePend( + handle: pte_osSemaphoreHandle, + pTimeout: *mut c_uint, +) -> pte_osResult { //TODO: pTimeout let semaphore = &mut *handle; let mut acquired = false; - while ! acquired { + while !acquired { pte_osMutexLock(&mut semaphore.lock); if intrinsics::atomic_load(&mut semaphore.count) > 0 { intrinsics::atomic_xsub(&mut semaphore.count, 1); @@ -278,7 +291,10 @@ pub unsafe extern "C" fn pte_osSemaphorePend(handle: pte_osSemaphoreHandle, pTim } #[no_mangle] -pub unsafe extern "C" fn pte_osSemaphoreCancellablePend(handle: pte_osSemaphoreHandle, pTimeout: *mut c_uint) -> pte_osResult { +pub unsafe extern "C" fn pte_osSemaphoreCancellablePend( + handle: pte_osSemaphoreHandle, + pTimeout: *mut c_uint, +) -> pte_osResult { //TODO pte_osSemaphorePend(handle, pTimeout) } @@ -289,7 +305,11 @@ pub unsafe extern "C" fn pte_osAtomicExchange(ptarg: *mut c_int, val: c_int) -> } #[no_mangle] -pub unsafe extern "C" fn pte_osAtomicCompareExchange(pdest: *mut c_int, exchange: c_int, comp: c_int) -> c_int { +pub unsafe extern "C" fn pte_osAtomicCompareExchange( + pdest: *mut c_int, + exchange: c_int, + comp: c_int, +) -> c_int { intrinsics::atomic_cxchg(pdest, comp, exchange).0 } @@ -316,7 +336,10 @@ pub unsafe extern "C" fn pte_osTlsSetValue(index: c_uint, value: *mut c_void) -> #[no_mangle] pub unsafe extern "C" fn pte_osTlsGetValue(index: c_uint) -> *mut c_void { - locals().get_mut(&index).map(|x| *x).unwrap_or(ptr::null_mut()) + locals() + .get_mut(&index) + .map(|x| *x) + .unwrap_or(ptr::null_mut()) } #[no_mangle] diff --git a/src/platform/redox/extra.rs b/src/platform/redox/extra.rs index d0a50770e..f28bc7036 100644 --- a/src/platform/redox/extra.rs +++ b/src/platform/redox/extra.rs @@ -5,7 +5,10 @@ use platform::types::*; #[no_mangle] pub unsafe extern "C" fn redox_fpath(fd: c_int, buf: *mut c_void, count: size_t) -> ssize_t { - e(syscall::fpath(fd as usize, slice::from_raw_parts_mut(buf as *mut u8, count))) as ssize_t + e(syscall::fpath( + fd as usize, + slice::from_raw_parts_mut(buf as *mut u8, count), + )) as ssize_t } #[no_mangle] @@ -14,7 +17,7 @@ pub unsafe extern "C" fn redox_physalloc(size: size_t) -> *mut c_void { if res == !0 { return ptr::null_mut(); } else { - return res as *mut c_void + return res as *mut c_void; } } @@ -24,12 +27,20 @@ pub unsafe extern "C" fn redox_physfree(physical_address: *mut c_void, size: siz } #[no_mangle] -pub unsafe extern "C" fn redox_physmap(physical_address: *mut c_void, size: size_t, flags: c_int) -> *mut c_void { - let res = e(syscall::physmap(physical_address as usize, size, flags as usize)); +pub unsafe extern "C" fn redox_physmap( + physical_address: *mut c_void, + size: size_t, + flags: c_int, +) -> *mut c_void { + let res = e(syscall::physmap( + physical_address as usize, + size, + flags as usize, + )); if res == !0 { return ptr::null_mut(); } else { - return res as *mut c_void + return res as *mut c_void; } } diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 44233a8b2..6ab08a794 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -599,14 +599,22 @@ impl Pal for Sys { } fn mkdir(path: &CStr, mode: mode_t) -> c_int { - match File::create(path, fcntl::O_DIRECTORY | fcntl::O_EXCL | fcntl::O_CLOEXEC, 0o777) { + match File::create( + path, + fcntl::O_DIRECTORY | fcntl::O_EXCL | fcntl::O_CLOEXEC, + 0o777, + ) { Ok(_fd) => 0, Err(_) => -1, } } fn mkfifo(path: &CStr, mode: mode_t) -> c_int { - match File::create(path, fcntl::O_CREAT | fcntl::O_CLOEXEC, syscall::MODE_FIFO as mode_t | (mode & 0o777)) { + match File::create( + path, + fcntl::O_CREAT | fcntl::O_CLOEXEC, + syscall::MODE_FIFO as mode_t | (mode & 0o777), + ) { Ok(fd) => 0, Err(_) => -1, } @@ -623,11 +631,14 @@ impl Pal for Sys { let map = Map { offset: off as usize, size: len, - flags: ((prot as usize) << 16) | ((flags as usize) & 0xFFFF) + flags: ((prot as usize) << 16) | ((flags as usize) & 0xFFFF), }; if flags & MAP_ANON == MAP_ANON { - let fd = e(syscall::open("memory:", syscall::O_STAT | syscall::O_CLOEXEC)); // flags don't matter currently + let fd = e(syscall::open( + "memory:", + syscall::O_STAT | syscall::O_CLOEXEC, + )); // flags don't matter currently if fd == !0 { return !0 as *mut c_void; } @@ -815,7 +826,14 @@ impl Pal for Sys { } fn pte_clone() -> pid_t { - e(unsafe { syscall::clone(syscall::CLONE_VM | syscall::CLONE_FS | syscall::CLONE_FILES | syscall::CLONE_SIGHAND) }) as pid_t + e(unsafe { + syscall::clone( + syscall::CLONE_VM + | syscall::CLONE_FS + | syscall::CLONE_FILES + | syscall::CLONE_SIGHAND, + ) + }) as pid_t } fn read(fd: c_int, buf: &mut [u8]) -> ssize_t { @@ -823,7 +841,10 @@ impl Pal for Sys { } fn readlink(pathname: &CStr, out: &mut [u8]) -> ssize_t { - let file = match File::open(pathname, fcntl::O_PATH | fcntl::O_SYMLINK | fcntl::O_CLOEXEC) { + let file = match File::open( + pathname, + fcntl::O_PATH | fcntl::O_SYMLINK | fcntl::O_CLOEXEC, + ) { Ok(ok) => ok, Err(_) => return -1, }; @@ -1084,7 +1105,7 @@ impl Pal for Sys { fn uname(utsname: *mut utsname) -> c_int { fn gethostname(name: &mut [u8]) -> io::Result<()> { if name.is_empty() { - return Ok(()) + return Ok(()); } let mut file = File::open( @@ -1108,7 +1129,7 @@ impl Pal for Sys { match gethostname(unsafe { slice::from_raw_parts_mut( (*utsname).nodename.as_mut_ptr() as *mut u8, - (*utsname).nodename.len() + (*utsname).nodename.len(), ) }) { Ok(_) => (), diff --git a/src/platform/redox/signal.rs b/src/platform/redox/signal.rs index 1779505d1..28caf99c5 100644 --- a/src/platform/redox/signal.rs +++ b/src/platform/redox/signal.rs @@ -1,13 +1,13 @@ use core::mem; use syscall; -use platform::errno; use super::super::types::*; use super::super::{Pal, PalSignal}; use super::{e, Sys}; use header::errno::EINVAL; use header::signal::{sigaction, sigset_t}; -use header::sys_time::{ITIMER_REAL, itimerval}; +use header::sys_time::{itimerval, ITIMER_REAL}; +use platform::errno; impl PalSignal for Sys { fn getitimer(which: c_int, out: *mut itimerval) -> c_int { @@ -16,7 +16,7 @@ impl PalSignal for Sys { _ => unsafe { errno = EINVAL; return -1; - } + }, }; let fd = e(syscall::open(path, syscall::O_RDONLY | syscall::O_CLOEXEC)); @@ -35,9 +35,9 @@ impl PalSignal for Sys { unsafe { (*out).it_interval.tv_sec = spec.it_interval.tv_sec; - (*out).it_interval.tv_usec = spec.it_interval.tv_nsec/1000; + (*out).it_interval.tv_usec = spec.it_interval.tv_nsec / 1000; (*out).it_value.tv_sec = spec.it_value.tv_sec; - (*out).it_value.tv_usec = spec.it_value.tv_nsec/1000; + (*out).it_value.tv_usec = spec.it_value.tv_nsec / 1000; } 0 @@ -61,7 +61,7 @@ impl PalSignal for Sys { _ => unsafe { errno = EINVAL; return -1; - } + }, }; let fd = e(syscall::open(path, syscall::O_RDWR | syscall::O_CLOEXEC)); @@ -75,11 +75,11 @@ impl PalSignal for Sys { if count != !0 { unsafe { - if ! old.is_null() { + if !old.is_null() { (*old).it_interval.tv_sec = spec.it_interval.tv_sec; - (*old).it_interval.tv_usec = spec.it_interval.tv_nsec/1000; + (*old).it_interval.tv_usec = spec.it_interval.tv_nsec / 1000; (*old).it_value.tv_sec = spec.it_value.tv_sec; - (*old).it_value.tv_usec = spec.it_value.tv_nsec/1000; + (*old).it_value.tv_usec = spec.it_value.tv_nsec / 1000; } spec.it_interval.tv_sec = (*new).it_interval.tv_sec; @@ -136,11 +136,7 @@ impl PalSignal for Sys { } else { Some([unsafe { *set as u64 }, 0]) }; - let mut old_opt = if oset.is_null() { - None - } else { - Some([0, 0]) - }; + let mut old_opt = if oset.is_null() { None } else { Some([0, 0]) }; let ret = e(syscall::sigprocmask( how as usize, new_opt.as_ref(), diff --git a/src/start.rs b/src/start.rs index 7f88e4e72..884e67a75 100644 --- a/src/start.rs +++ b/src/start.rs @@ -67,7 +67,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! { // Set up envp let envp = sp.envp(); let mut len = 0; - while ! (*envp.add(len)).is_null() { + while !(*envp.add(len)).is_null() { len += 1; } platform::inner_environ = copy_string_array(envp, len); @@ -102,11 +102,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! { } // not argv or envp, because programs like bash try to modify this *const* pointer :| - stdlib::exit(main( - argc, - platform::argv, - platform::environ, - )); + stdlib::exit(main(argc, platform::argv, platform::environ)); unreachable!(); } -- GitLab