libc: sync with abi changes
This commit is contained in:
parent
9fa940f011
commit
945c490fa7
6
userspace/lib/ygglibc/Cargo.lock
generated
6
userspace/lib/ygglibc/Cargo.lock
generated
@ -16,6 +16,10 @@ dependencies = [
|
||||
name = "abi-lib"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "abi-serde"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.18"
|
||||
@ -562,6 +566,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi-generator",
|
||||
"abi-lib",
|
||||
"abi-serde",
|
||||
"bytemuck",
|
||||
"prettyplease",
|
||||
]
|
||||
@ -572,6 +577,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"abi-generator",
|
||||
"abi-lib",
|
||||
"abi-serde",
|
||||
"cc",
|
||||
"prettyplease",
|
||||
"yggdrasil-abi",
|
||||
|
@ -2,8 +2,7 @@ use core::ffi::{c_int, c_void};
|
||||
|
||||
use yggdrasil_rt::{
|
||||
io::RawFd,
|
||||
net::{self as rt, SocketOption},
|
||||
sys as syscall,
|
||||
net::{self as rt, options},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -36,7 +35,7 @@ unsafe extern "C" fn getsockopt(
|
||||
*size = match (level, name) {
|
||||
(SOL_SOCKET, SO_RCVTIMEO) if space >= size_of::<timeval>() => {
|
||||
let timeout =
|
||||
rt::get_socket_option1!(fd, RecvTimeout: Option).e_map_err(Errno::from)?;
|
||||
rt::get_socket_option!(fd, options::RecvTimeout).e_map_err(Errno::from)?;
|
||||
let value = value.cast::<timeval>();
|
||||
match timeout {
|
||||
Some(timeout) => value.write(timeval::from(timeout)),
|
||||
@ -46,7 +45,7 @@ unsafe extern "C" fn getsockopt(
|
||||
}
|
||||
(SOL_SOCKET, SO_SNDTIMEO) => {
|
||||
let timeout =
|
||||
rt::get_socket_option1!(fd, SendTimeout: Option).e_map_err(Errno::from)?;
|
||||
rt::get_socket_option!(fd, options::SendTimeout).e_map_err(Errno::from)?;
|
||||
let value = value.cast::<timeval>();
|
||||
match timeout {
|
||||
Some(timeout) => value.write(timeval::from(timeout)),
|
||||
@ -55,7 +54,8 @@ unsafe extern "C" fn getsockopt(
|
||||
size_of::<timeval>()
|
||||
}
|
||||
(SOL_SOCKET, SO_BROADCAST) => {
|
||||
let broadcast = rt::get_socket_option1!(fd, Broadcast: bool).e_map_err(Errno::from)?;
|
||||
let broadcast =
|
||||
rt::get_socket_option!(fd, options::Broadcast).e_map_err(Errno::from)?;
|
||||
let value = value.cast::<c_int>();
|
||||
value.write(broadcast as c_int);
|
||||
size_of::<c_int>()
|
||||
@ -89,19 +89,16 @@ unsafe extern "C" fn setsockopt(
|
||||
(SOL_SOCKET, SO_RCVTIMEO) if size == size_of::<timeval>() => {
|
||||
let timeval = *value.cast::<timeval>();
|
||||
let timeout = timeval.to_duration_opt();
|
||||
syscall::set_socket_option(fd, &SocketOption::RecvTimeout(timeout))
|
||||
.e_map_err(Errno::from)?;
|
||||
rt::set_socket_option::<options::RecvTimeout>(fd, &timeout).e_map_err(Errno::from)?;
|
||||
}
|
||||
(SOL_SOCKET, SO_SNDTIMEO) if size == size_of::<timeval>() => {
|
||||
let timeval = *value.cast::<timeval>();
|
||||
let timeout = timeval.to_duration_opt();
|
||||
syscall::set_socket_option(fd, &SocketOption::SendTimeout(timeout))
|
||||
.e_map_err(Errno::from)?;
|
||||
rt::set_socket_option::<options::SendTimeout>(fd, &timeout).e_map_err(Errno::from)?;
|
||||
}
|
||||
(SOL_SOCKET, SO_BROADCAST) if size == size_of::<c_int>() => {
|
||||
let value = *value.cast::<c_int>() != 0;
|
||||
syscall::set_socket_option(fd, &SocketOption::Broadcast(value))
|
||||
.e_map_err(Errno::from)?;
|
||||
rt::set_socket_option::<options::Broadcast>(fd, &value).e_map_err(Errno::from)?;
|
||||
}
|
||||
_ => {
|
||||
yggdrasil_rt::debug_trace!("Unhandled setsockopt({level}, {name}, {size})");
|
||||
@ -125,7 +122,7 @@ unsafe extern "C" fn getpeername(
|
||||
}
|
||||
|
||||
let fd = RawFd::e_try_from(fd)?;
|
||||
let address = rt::get_socket_option1!(fd, PeerAddress: Option).e_map_err(Errno::from)?;
|
||||
let address = rt::get_socket_option!(fd, options::PeerAddress).e_map_err(Errno::from)?;
|
||||
let address = address.e_ok_or(Errno::ENOTCONN)?;
|
||||
|
||||
*len = address.to_c(remote, *len)?;
|
||||
@ -144,7 +141,7 @@ unsafe extern "C" fn getsockname(
|
||||
}
|
||||
|
||||
let fd = RawFd::e_try_from(fd)?;
|
||||
let address = rt::get_socket_option1!(fd, LocalAddress: Option).e_map_err(Errno::from)?;
|
||||
let address = rt::get_socket_option!(fd, options::LocalAddress).e_map_err(Errno::from)?;
|
||||
let address = address.e_ok_or(Errno::ENOTCONN)?;
|
||||
|
||||
*len = address.to_c(local, *len)?;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use core::{ffi::{c_char, c_int, c_void}, mem::MaybeUninit};
|
||||
|
||||
use yggdrasil_rt::{debug_trace, io::{PipeOptions, RawFd, SeekFrom}};
|
||||
use yggdrasil_rt::{debug_trace, io::{RawFd, SeekFrom}};
|
||||
|
||||
use crate::{
|
||||
error::{CFdResult, CIntZeroResult, CIsizeResult, COffsetResult, ResultExt, TryFromExt},
|
||||
@ -59,7 +59,7 @@ unsafe extern "C" fn lseek(fd: c_int, offset: off_t, whence: c_int) -> COffsetRe
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn pipe(fds: *mut c_int) -> CIntZeroResult {
|
||||
let fds = core::slice::from_raw_parts_mut(fds, 2);
|
||||
let (read, write) = io::create_pipe(PipeOptions::empty())?;
|
||||
let (read, write) = io::create_pipe(false, false)?;
|
||||
fds[0] = read.into_raw().try_into().unwrap();
|
||||
fds[1] = write.into_raw().try_into().unwrap();
|
||||
CIntZeroResult::SUCCESS
|
||||
|
@ -1,7 +1,7 @@
|
||||
use core::{ffi::c_int, mem::MaybeUninit};
|
||||
|
||||
use yggdrasil_rt::{
|
||||
io::{FileAttr, PipeOptions, RawFd, SeekFrom}, path::{Path, PathBuf}, sys as syscall
|
||||
io::{FileAttr, RawFd, SeekFrom}, path::{Path, PathBuf}, sys as syscall
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -116,11 +116,9 @@ impl TryFromExt<(off_t, c_int)> for SeekFrom {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_pipe(options: PipeOptions) -> EResult<(RawFd, RawFd)> {
|
||||
let mut fds = MaybeUninit::uninit_array();
|
||||
unsafe { syscall::create_pipe(&mut fds, options) }?;
|
||||
let fds = unsafe { MaybeUninit::array_assume_init(fds) };
|
||||
EResult::Ok((fds[0], fds[1]))
|
||||
pub fn create_pipe(read_nonblocking: bool, write_nonblocking: bool) -> EResult<(RawFd, RawFd)> {
|
||||
let (read, write) = yggdrasil_rt::io::create_pipe_pair(read_nonblocking, write_nonblocking)?;
|
||||
EResult::Ok((read, write))
|
||||
}
|
||||
|
||||
pub fn get_metadata(at: Option<RawFd>, path: &str, follow: bool) -> EResult<FileAttr> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user