Fix signal and socket pal implementations on Redox

This commit is contained in:
Jeremy Soller
2018-08-25 09:21:08 -06:00
parent d1dabccdce
commit 34f5f57213
5 changed files with 31 additions and 17 deletions
+2 -2
View File
@@ -109,8 +109,8 @@ impl PalSocket for Sys {
e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int
}
fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
e(unsafe { syscall!(SOCKET, domain, kind, protocol) }) as c_int
unsafe fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
e(syscall!(SOCKET, domain, kind, protocol)) as c_int
}
fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int {
+1 -1
View File
@@ -72,7 +72,7 @@ pub trait PalSocket: Pal {
Self::no_pal("shutdown")
}
fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
unsafe fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
Self::no_pal("socket")
}
-9
View File
@@ -19,21 +19,12 @@ const EINVAL: c_int = 22;
const ENOSYS: c_int = 38;
const MAP_ANON: c_int = 1;
#[thread_local]
static mut SIG_HANDLER: Option<extern "C" fn(c_int)> = None;
static ANONYMOUS_MAPS: Once<Mutex<BTreeMap<usize, usize>>> = Once::new();
fn anonymous_maps() -> MutexGuard<'static, BTreeMap<usize, usize>> {
ANONYMOUS_MAPS.call_once(|| Mutex::new(BTreeMap::new())).lock()
}
extern "C" fn sig_handler(sig: usize) {
if let Some(ref callback) = unsafe { SIG_HANDLER } {
callback(sig as c_int);
}
}
fn e(sys: Result<usize>) -> usize {
match sys {
Ok(ok) => ok,
+16 -1
View File
@@ -1,3 +1,18 @@
use syscall;
use super::{e, Sys};
use {Pal, PalSignal};
use types::*;
#[thread_local]
static mut SIG_HANDLER: Option<extern "C" fn(c_int)> = None;
extern "C" fn sig_handler(sig: usize) {
if let Some(ref callback) = unsafe { SIG_HANDLER } {
callback(sig as c_int);
}
}
impl PalSignal for Sys {
fn kill(pid: pid_t, sig: c_int) -> c_int {
e(syscall::kill(pid as usize, sig as usize)) as c_int
@@ -8,7 +23,7 @@ impl PalSignal for Sys {
}
fn raise(sig: c_int) -> c_int {
kill(getpid(), sig)
Self::kill(Self::getpid(), sig)
}
unsafe fn sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int {
+12 -4
View File
@@ -1,3 +1,11 @@
use core::{mem, ptr, slice};
use syscall::{self, Result};
use syscall::flag::*;
use super::{e, Sys};
use {errno, Pal, PalSocket};
use types::*;
macro_rules! bind_or_connect {
(bind $path:expr) => {
concat!("/", $path)
@@ -75,7 +83,7 @@ impl PalSocket for Sys {
}
if address != ptr::null_mut()
&& address_len != ptr::null_mut()
&& getpeername(stream, address, address_len) < 0
&& Self::getpeername(stream, address, address_len) < 0
{
return -1;
}
@@ -120,11 +128,11 @@ impl PalSocket for Sys {
}
if address != ptr::null_mut()
&& address_len != ptr::null_mut()
&& getpeername(socket, address, address_len) < 0
&& Self::getpeername(socket, address, address_len) < 0
{
return -1;
}
read(socket, slice::from_raw_parts_mut(buf as *mut u8, len))
Self::read(socket, slice::from_raw_parts_mut(buf as *mut u8, len))
}
unsafe fn sendto(
@@ -143,7 +151,7 @@ impl PalSocket for Sys {
errno = syscall::EOPNOTSUPP;
return -1;
}
write(socket, slice::from_raw_parts(buf as *const u8, len))
Self::write(socket, slice::from_raw_parts(buf as *const u8, len))
}
unsafe fn socket(domain: c_int, mut kind: c_int, protocol: c_int) -> c_int {