Use cbitset crate
This commit is contained in:
Generated
+16
@@ -35,6 +35,14 @@ dependencies = [
|
||||
"toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cbitset"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.22"
|
||||
@@ -120,6 +128,11 @@ dependencies = [
|
||||
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.2.3"
|
||||
@@ -194,6 +207,7 @@ dependencies = [
|
||||
name = "relibc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cbitset 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cc 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)",
|
||||
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -408,6 +422,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
|
||||
"checksum cbitset 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3a9afa72f63942dd7e7f01c67b863ce9df35c523ae10e3dddd3eec8f1e07eac"
|
||||
"checksum cc 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "4a6007c146fdd28d4512a794b07ffe9d8e89e6bf86e2e0c4ddff2e1fb54a0007"
|
||||
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
|
||||
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
|
||||
@@ -419,6 +434,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
|
||||
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
|
||||
"checksum log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cba860f648db8e6f269df990180c2217f333472b4a6e901e97446858487971e2"
|
||||
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
||||
"checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0"
|
||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
"checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd"
|
||||
|
||||
@@ -14,6 +14,7 @@ members = ["src/crt0", "cbindgen"]
|
||||
cc = "1.0.17"
|
||||
|
||||
[dependencies]
|
||||
cbitset = "0.1.0"
|
||||
lazy_static = { version = "*", features = ["nightly", "spin_no_std"] }
|
||||
rand = { version = "0.5.2", default-features = false }
|
||||
va_list = { path = "va_list", features = ["no_std"] }
|
||||
|
||||
+12
-10
@@ -2,6 +2,8 @@
|
||||
|
||||
use core::{mem, ptr};
|
||||
|
||||
use cbitset::BitSet;
|
||||
|
||||
use header::errno;
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
@@ -17,6 +19,8 @@ pub mod sys;
|
||||
#[path = "redox.rs"]
|
||||
pub mod sys;
|
||||
|
||||
type SigSet = BitSet<[c_ulong; 1]>;
|
||||
|
||||
const SIG_ERR: usize = !0;
|
||||
|
||||
pub const SIG_BLOCK: c_int = 0;
|
||||
@@ -81,9 +85,8 @@ pub extern "C" fn sigaddset(set: *mut sigset_t, signo: c_int) -> c_int {
|
||||
return -1;
|
||||
}
|
||||
|
||||
let signo = signo as usize - 1; // 0-indexed usize, please!
|
||||
unsafe {
|
||||
*set |= 1 << (signo & (8 * mem::size_of::<sigset_t>() - 1));
|
||||
if let Some(set) = unsafe { (set as *mut SigSet).as_mut() } {
|
||||
set.insert(signo as usize - 1); // 0-indexed usize, please!
|
||||
}
|
||||
0
|
||||
}
|
||||
@@ -97,25 +100,24 @@ pub extern "C" fn sigdelset(set: *mut sigset_t, signo: c_int) -> c_int {
|
||||
return -1;
|
||||
}
|
||||
|
||||
let signo = signo as usize - 1; // 0-indexed usize, please!
|
||||
unsafe {
|
||||
*set &= !(1 << (signo & (8 * mem::size_of::<sigset_t>() - 1)));
|
||||
if let Some(set) = unsafe { (set as *mut SigSet).as_mut() } {
|
||||
set.remove(signo as usize - 1); // 0-indexed usize, please!
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sigemptyset(set: *mut sigset_t) -> c_int {
|
||||
unsafe {
|
||||
*set = 0;
|
||||
if let Some(set) = unsafe { (set as *mut SigSet).as_mut() } {
|
||||
set.clear();
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sigfillset(set: *mut sigset_t) -> c_int {
|
||||
unsafe {
|
||||
*set = c_ulong::max_value();
|
||||
if let Some(set) = unsafe { (set as *mut SigSet).as_mut() } {
|
||||
set.fill(.., true);
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
+16
-16
@@ -4,6 +4,8 @@ use core::mem;
|
||||
use core::ptr;
|
||||
use core::usize;
|
||||
|
||||
use cbitset::BitSet256;
|
||||
|
||||
use header::errno::*;
|
||||
use header::signal;
|
||||
use platform;
|
||||
@@ -165,32 +167,30 @@ pub unsafe extern "C" fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_
|
||||
}
|
||||
|
||||
pub unsafe fn inner_strspn(s1: *const c_char, s2: *const c_char, cmp: bool) -> size_t {
|
||||
let s1 = s1 as *const u8;
|
||||
let s2 = s2 as *const u8;
|
||||
let mut s1 = s1 as *const u8;
|
||||
let mut s2 = s2 as *const u8;
|
||||
|
||||
// The below logic is effectively ripped from the musl implementation. It
|
||||
// works by placing each byte as it's own bit in an array of numbers. Each
|
||||
// number can hold up to 8 * mem::size_of::<usize>() bits. We need 256 bits
|
||||
// in total, to fit one byte.
|
||||
|
||||
const BITSIZE: usize = 8 * mem::size_of::<usize>();
|
||||
let mut byteset = [0usize; 256 / BITSIZE];
|
||||
let mut set = BitSet256::new();
|
||||
|
||||
while *s2 != 0 {
|
||||
set.insert(*s2 as usize);
|
||||
s2 = s2.offset(1);
|
||||
}
|
||||
|
||||
let mut i = 0;
|
||||
while *s2.offset(i) != 0 {
|
||||
byteset[(*s2.offset(i) as usize) / BITSIZE] |=
|
||||
1 << (*s2.offset(i) as usize & (BITSIZE - 1));
|
||||
while *s1 != 0 {
|
||||
if set.contains(*s1 as usize) != cmp {
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
s1 = s1.offset(1);
|
||||
}
|
||||
|
||||
i = 0; // reset
|
||||
while *s1.offset(i) != 0
|
||||
&& (byteset[(*s1.offset(i) as usize) / BITSIZE]
|
||||
& 1 << (*s1.offset(i) as usize & (BITSIZE - 1)) != 0) == cmp
|
||||
{
|
||||
i += 1;
|
||||
}
|
||||
i as size_t
|
||||
i
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
extern crate cbitset;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate rand;
|
||||
|
||||
+15
-32
@@ -1,6 +1,7 @@
|
||||
//! sys/socket implementation, following http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html
|
||||
|
||||
use alloc::btree_map::BTreeMap;
|
||||
use cbitset::BitSet;
|
||||
use core::fmt::Write;
|
||||
use core::{mem, ptr, slice};
|
||||
use spin::{Mutex, MutexGuard, Once};
|
||||
@@ -630,31 +631,9 @@ impl Pal for Sys {
|
||||
exceptfds: *mut fd_set,
|
||||
timeout: *mut timeval,
|
||||
) -> c_int {
|
||||
fn isset(set: *mut fd_set, fd: usize) -> bool {
|
||||
if set.is_null() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mask = 1 << (fd & 8 * mem::size_of::<c_ulong>() - 1);
|
||||
unsafe { (*set).fds_bits[fd / (8 * mem::size_of::<c_ulong>())] & mask == mask }
|
||||
}
|
||||
fn clearset(set: *mut fd_set) {
|
||||
if set.is_null() {
|
||||
return;
|
||||
}
|
||||
|
||||
for i in unsafe { &mut (*set).fds_bits } {
|
||||
*i = 0;
|
||||
}
|
||||
}
|
||||
fn set(set: *mut fd_set, fd: usize) {
|
||||
if set.is_null() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mask = 1 << (fd & 8 * mem::size_of::<c_ulong>() - 1);
|
||||
unsafe { (*set).fds_bits[fd / (8 * mem::size_of::<c_ulong>())] |= mask; }
|
||||
}
|
||||
let mut readfds = unsafe { readfds.as_mut() }.map(|s| BitSet::from_ref(&mut s.fds_bits));
|
||||
let mut writefds = unsafe { writefds.as_mut() }.map(|s| BitSet::from_ref(&mut s.fds_bits));
|
||||
let mut exceptfds = unsafe { exceptfds.as_mut() }.map(|s| BitSet::from_ref(&mut s.fds_bits));
|
||||
|
||||
let event_path = unsafe { CStr::from_bytes_with_nul_unchecked(b"event:\0") };
|
||||
let event_file = match RawFile::open(event_path, fcntl::O_RDWR | fcntl::O_CLOEXEC, 0) {
|
||||
@@ -678,10 +657,10 @@ impl Pal for Sys {
|
||||
}
|
||||
};
|
||||
}
|
||||
if isset(readfds, fd) {
|
||||
if readfds.as_mut().map(|s| s.contains(fd)).unwrap_or(false) {
|
||||
register!(fd, syscall::EVENT_READ);
|
||||
}
|
||||
if isset(writefds, fd) {
|
||||
if writefds.as_mut().map(|s| s.contains(fd)).unwrap_or(false) {
|
||||
register!(fd, syscall::EVENT_WRITE);
|
||||
}
|
||||
}
|
||||
@@ -750,9 +729,9 @@ impl Pal for Sys {
|
||||
|
||||
let mut total = 0;
|
||||
|
||||
clearset(readfds);
|
||||
clearset(writefds);
|
||||
clearset(exceptfds);
|
||||
if let Some(ref mut set) = readfds { set.clear(); }
|
||||
if let Some(ref mut set) = writefds { set.clear(); }
|
||||
if let Some(ref mut set) = exceptfds { set.clear(); }
|
||||
|
||||
for event in &events[..read] {
|
||||
if event.data == TIMEOUT_TOKEN {
|
||||
@@ -760,11 +739,15 @@ impl Pal for Sys {
|
||||
}
|
||||
|
||||
if event.flags & syscall::EVENT_READ == syscall::EVENT_READ {
|
||||
set(readfds, event.id);
|
||||
if let Some(ref mut set) = readfds {
|
||||
set.insert(event.id);
|
||||
}
|
||||
total += 1;
|
||||
}
|
||||
if event.flags & syscall::EVENT_WRITE == syscall::EVENT_WRITE {
|
||||
set(writefds, event.id);
|
||||
if let Some(ref mut set) = writefds {
|
||||
set.insert(event.id);
|
||||
}
|
||||
total += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user