Skip to content

Commit

Permalink
rustix replacement (cont)
Browse files Browse the repository at this point in the history
  • Loading branch information
thaodt committed Jun 28, 2023
1 parent 961aa6b commit 55c04f6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rt/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static PAGE_SIZE: AtomicUsize = AtomicUsize::new(0);
pub(crate) fn page_size() -> usize {
match PAGE_SIZE.load(Ordering::Relaxed) {
0 => {
let size = unsafe { rustix::param::page_size() };
let size = rustix::param::page_size();

PAGE_SIZE.store(size, Ordering::Relaxed);
size
Expand Down
2 changes: 1 addition & 1 deletion rt/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::process::{NativeAsyncMethod, Process};
use crate::scheduler::{number_of_cores, pin_thread_to_core};
use crate::stack::Stack;
use crate::state::{MethodCounts, RcState, State};
use rustix::process::Signal::Pipe;
//use rustix::process::Signal::Pipe;

use std::env::args_os;
use std::io::{stdout, Write as _};
Expand Down
4 changes: 4 additions & 0 deletions rt/src/runtime/time.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::mem::{Float, Int};
use crate::state::State;
//use rustix::time;
use std::mem::MaybeUninit;

fn utc() -> f64 {
Expand All @@ -9,6 +10,9 @@ fn utc() -> f64 {
if libc::clock_gettime(libc::CLOCK_REALTIME, ts.as_mut_ptr()) != 0 {
panic!("clock_gettime() failed");
}
/*if time::clock_gettime(time::ClockId::Realtime) {
panic!("clock_gettime() failed");
}*/

let ts = ts.assume_init();

Expand Down
7 changes: 2 additions & 5 deletions rt/src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ use std::thread::available_parallelism;

#[cfg(target_os = "linux")]
use {
// libc::{cpu_set_t, sched_setaffinity, CPU_SET},
rustix::process::{sched_setaffinity, CpuSet, Pid},
std::mem::{size_of, zeroed},
std::mem::zeroed,
};

#[cfg(target_os = "linux")]
pub(crate) fn pin_thread_to_core(core: usize) {
unsafe {
let mut set = zeroed();

// CPU_SET(core, &mut set);
CpuSet::set(&mut set, core);
// sched_setaffinity(0, size_of::<cpu_set_t>(), &set);
sched_setaffinity(Pid::from_raw(0), &set);
let _ = sched_setaffinity(Pid::from_raw(0), &set);
}
}

Expand Down
18 changes: 14 additions & 4 deletions rt/src/socket/socket_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@ fn unix_socket_path(sockaddr: &SockAddr) -> String {
let raw_addr = unsafe { &*(sockaddr.as_ptr() as *const sockaddr_un) };
let len = sockaddr.len() as usize - sun_path_offset(raw_addr);
let path = unsafe {
transmute::<&[c_char], &[u8]>(&*raw_addr.path().unwrap().as_ptr())
transmute::<&[c_char], &[u8]>(&[*raw_addr
.path()
.unwrap()
.as_ptr()
.cast::<i8>()])
};

if len == 0 || (cfg!(not(target_os = "linux")) && raw_addr.path()[0] == 0) {
if len == 0
|| (cfg!(not(target_os = "linux"))
&& raw_addr.path().unwrap().to_bytes()[0] == 0)
{
return String::new();
}

let (start, stop) =
if raw_addr.path()[0] == 0 { (1, len) } else { (0, len - 1) };
let (start, stop) = if raw_addr.path().unwrap().to_bytes()[0] == 0 {
(1, len)
} else {
(0, len - 1)
};

// Abstract names might contain NULL bytes and invalid UTF8. Since Inko
// doesn't provide any better types at the moment we'll use a string and
Expand Down

0 comments on commit 55c04f6

Please sign in to comment.