libc: sync with abi changes

This commit is contained in:
Mark Poliakov 2025-01-12 14:54:37 +02:00
parent 9fa940f011
commit 945c490fa7
4 changed files with 22 additions and 21 deletions

View File

@ -16,6 +16,10 @@ dependencies = [
name = "abi-lib" name = "abi-lib"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "abi-serde"
version = "0.1.0"
[[package]] [[package]]
name = "anstream" name = "anstream"
version = "0.6.18" version = "0.6.18"
@ -562,6 +566,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"abi-generator", "abi-generator",
"abi-lib", "abi-lib",
"abi-serde",
"bytemuck", "bytemuck",
"prettyplease", "prettyplease",
] ]
@ -572,6 +577,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"abi-generator", "abi-generator",
"abi-lib", "abi-lib",
"abi-serde",
"cc", "cc",
"prettyplease", "prettyplease",
"yggdrasil-abi", "yggdrasil-abi",

View File

@ -2,8 +2,7 @@ use core::ffi::{c_int, c_void};
use yggdrasil_rt::{ use yggdrasil_rt::{
io::RawFd, io::RawFd,
net::{self as rt, SocketOption}, net::{self as rt, options},
sys as syscall,
}; };
use crate::{ use crate::{
@ -36,7 +35,7 @@ unsafe extern "C" fn getsockopt(
*size = match (level, name) { *size = match (level, name) {
(SOL_SOCKET, SO_RCVTIMEO) if space >= size_of::<timeval>() => { (SOL_SOCKET, SO_RCVTIMEO) if space >= size_of::<timeval>() => {
let timeout = 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>(); let value = value.cast::<timeval>();
match timeout { match timeout {
Some(timeout) => value.write(timeval::from(timeout)), Some(timeout) => value.write(timeval::from(timeout)),
@ -46,7 +45,7 @@ unsafe extern "C" fn getsockopt(
} }
(SOL_SOCKET, SO_SNDTIMEO) => { (SOL_SOCKET, SO_SNDTIMEO) => {
let timeout = 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>(); let value = value.cast::<timeval>();
match timeout { match timeout {
Some(timeout) => value.write(timeval::from(timeout)), Some(timeout) => value.write(timeval::from(timeout)),
@ -55,7 +54,8 @@ unsafe extern "C" fn getsockopt(
size_of::<timeval>() size_of::<timeval>()
} }
(SOL_SOCKET, SO_BROADCAST) => { (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>(); let value = value.cast::<c_int>();
value.write(broadcast as c_int); value.write(broadcast as c_int);
size_of::<c_int>() size_of::<c_int>()
@ -89,19 +89,16 @@ unsafe extern "C" fn setsockopt(
(SOL_SOCKET, SO_RCVTIMEO) if size == size_of::<timeval>() => { (SOL_SOCKET, SO_RCVTIMEO) if size == size_of::<timeval>() => {
let timeval = *value.cast::<timeval>(); let timeval = *value.cast::<timeval>();
let timeout = timeval.to_duration_opt(); let timeout = timeval.to_duration_opt();
syscall::set_socket_option(fd, &SocketOption::RecvTimeout(timeout)) rt::set_socket_option::<options::RecvTimeout>(fd, &timeout).e_map_err(Errno::from)?;
.e_map_err(Errno::from)?;
} }
(SOL_SOCKET, SO_SNDTIMEO) if size == size_of::<timeval>() => { (SOL_SOCKET, SO_SNDTIMEO) if size == size_of::<timeval>() => {
let timeval = *value.cast::<timeval>(); let timeval = *value.cast::<timeval>();
let timeout = timeval.to_duration_opt(); let timeout = timeval.to_duration_opt();
syscall::set_socket_option(fd, &SocketOption::SendTimeout(timeout)) rt::set_socket_option::<options::SendTimeout>(fd, &timeout).e_map_err(Errno::from)?;
.e_map_err(Errno::from)?;
} }
(SOL_SOCKET, SO_BROADCAST) if size == size_of::<c_int>() => { (SOL_SOCKET, SO_BROADCAST) if size == size_of::<c_int>() => {
let value = *value.cast::<c_int>() != 0; let value = *value.cast::<c_int>() != 0;
syscall::set_socket_option(fd, &SocketOption::Broadcast(value)) rt::set_socket_option::<options::Broadcast>(fd, &value).e_map_err(Errno::from)?;
.e_map_err(Errno::from)?;
} }
_ => { _ => {
yggdrasil_rt::debug_trace!("Unhandled setsockopt({level}, {name}, {size})"); 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 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)?; let address = address.e_ok_or(Errno::ENOTCONN)?;
*len = address.to_c(remote, *len)?; *len = address.to_c(remote, *len)?;
@ -144,7 +141,7 @@ unsafe extern "C" fn getsockname(
} }
let fd = RawFd::e_try_from(fd)?; 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)?; let address = address.e_ok_or(Errno::ENOTCONN)?;
*len = address.to_c(local, *len)?; *len = address.to_c(local, *len)?;

View File

@ -1,6 +1,6 @@
use core::{ffi::{c_char, c_int, c_void}, mem::MaybeUninit}; 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::{ use crate::{
error::{CFdResult, CIntZeroResult, CIsizeResult, COffsetResult, ResultExt, TryFromExt}, 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] #[no_mangle]
unsafe extern "C" fn pipe(fds: *mut c_int) -> CIntZeroResult { unsafe extern "C" fn pipe(fds: *mut c_int) -> CIntZeroResult {
let fds = core::slice::from_raw_parts_mut(fds, 2); 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[0] = read.into_raw().try_into().unwrap();
fds[1] = write.into_raw().try_into().unwrap(); fds[1] = write.into_raw().try_into().unwrap();
CIntZeroResult::SUCCESS CIntZeroResult::SUCCESS

View File

@ -1,7 +1,7 @@
use core::{ffi::c_int, mem::MaybeUninit}; use core::{ffi::c_int, mem::MaybeUninit};
use yggdrasil_rt::{ 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::{ use crate::{
@ -116,11 +116,9 @@ impl TryFromExt<(off_t, c_int)> for SeekFrom {
} }
} }
pub fn create_pipe(options: PipeOptions) -> EResult<(RawFd, RawFd)> { pub fn create_pipe(read_nonblocking: bool, write_nonblocking: bool) -> EResult<(RawFd, RawFd)> {
let mut fds = MaybeUninit::uninit_array(); let (read, write) = yggdrasil_rt::io::create_pipe_pair(read_nonblocking, write_nonblocking)?;
unsafe { syscall::create_pipe(&mut fds, options) }?; EResult::Ok((read, write))
let fds = unsafe { MaybeUninit::array_assume_init(fds) };
EResult::Ok((fds[0], fds[1]))
} }
pub fn get_metadata(at: Option<RawFd>, path: &str, follow: bool) -> EResult<FileAttr> { pub fn get_metadata(at: Option<RawFd>, path: &str, follow: bool) -> EResult<FileAttr> {