Skip to content

Commit

Permalink
Merge branch 'nix-rust:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
richerfu authored Feb 5, 2025
2 parents 39c45bc + 299feba commit a0307df
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 71 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@ jobs:
armv7-unknown-linux-gnueabihf,
i686-unknown-linux-gnu,
i686-unknown-linux-musl,
mips-unknown-linux-gnu,
mips64-unknown-linux-gnuabi64,
mips64el-unknown-linux-gnuabi64,
mipsel-unknown-linux-gnu,

# Disable MIPS CIs, see https://github.com/nix-rust/nix/issues/2593
# for detailed info.
#
# mips-unknown-linux-gnu,
# mips64-unknown-linux-gnuabi64,
# mips64el-unknown-linux-gnuabi64,
# mipsel-unknown-linux-gnu,

powerpc64le-unknown-linux-gnu,
loongarch64-unknown-linux-gnu,
]
Expand Down
6 changes: 3 additions & 3 deletions src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ feature! {
/// # Safety
///
/// In a multithreaded program, only [async-signal-safe] functions like `pause`
/// and `_exit` may be called by the child (the parent isn't restricted). Note
/// that memory allocation may **not** be async-signal-safe and thus must be
/// prevented.
/// and `_exit` may be called by the child (the parent isn't restricted) until
/// a call of `execve(2)`. Note that memory allocation may **not** be
/// async-signal-safe and thus must be prevented.
///
/// Those functions are only a small subset of your operating system's API, so
/// special care must be taken to only invoke code you can control and audit.
Expand Down
43 changes: 28 additions & 15 deletions src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,30 +361,40 @@ unsafe fn to_exec_array<S: AsRef<CStr>>(args: &[S]) -> Vec<*mut libc::c_char> {

/// Create a new child process from the specified process image. See
/// [posix_spawn](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html).
pub fn posix_spawn<SA: AsRef<CStr>, SE: AsRef<CStr>>(
path: &CStr,
pub fn posix_spawn<P, SA, SE>(
path: &P,
file_actions: &PosixSpawnFileActions,
attr: &PosixSpawnAttr,
args: &[SA],
envp: &[SE],
) -> Result<Pid> {
) -> Result<Pid>
where
P: NixPath + ?Sized,
SA: AsRef<CStr>,
SE: AsRef<CStr>,
{
let mut pid = 0;

let res = unsafe {
let ret = unsafe {
let args_p = to_exec_array(args);
let env_p = to_exec_array(envp);

libc::posix_spawn(
&mut pid as *mut libc::pid_t,
path.as_ptr(),
&file_actions.fa as *const libc::posix_spawn_file_actions_t,
&attr.attr as *const libc::posix_spawnattr_t,
args_p.as_ptr(),
env_p.as_ptr(),
)
path.with_nix_path(|c_str| {
libc::posix_spawn(
&mut pid as *mut libc::pid_t,
c_str.as_ptr(),
&file_actions.fa as *const libc::posix_spawn_file_actions_t,
&attr.attr as *const libc::posix_spawnattr_t,
args_p.as_ptr(),
env_p.as_ptr(),
)
})?
};

Errno::result(res)?;
if ret != 0 {
return Err(Errno::from_raw(ret));
}

Ok(Pid::from_raw(pid))
}

Expand All @@ -399,7 +409,7 @@ pub fn posix_spawnp<SA: AsRef<CStr>, SE: AsRef<CStr>>(
) -> Result<Pid> {
let mut pid = 0;

let res = unsafe {
let ret = unsafe {
let args_p = to_exec_array(args);
let env_p = to_exec_array(envp);

Expand All @@ -413,6 +423,9 @@ pub fn posix_spawnp<SA: AsRef<CStr>, SE: AsRef<CStr>>(
)
};

Errno::result(res)?;
if ret != 0 {
return Err(Errno::from_raw(ret));
}

Ok(Pid::from_raw(pid))
}
23 changes: 9 additions & 14 deletions src/sys/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,9 @@ impl<'a> AioFsync<'a> {
/// * `fd`: File descriptor to sync.
/// * `mode`: Whether to sync file metadata too, or just data.
/// * `prio`: If POSIX Prioritized IO is supported, then the
/// operation will be prioritized at the process's
/// priority level minus `prio`.
/// * `sigev_notify`: Determines how you will be notified of event
/// completion.
/// operation will be prioritized at the process's priority level minus
/// `prio`.
/// * `sigev_notify`: Determines how you will be notified of event completion.
pub fn new(
fd: BorrowedFd<'a>,
mode: AioFsyncMode,
Expand Down Expand Up @@ -573,11 +572,9 @@ impl<'a> AioRead<'a> {
/// * `fd`: File descriptor to read from
/// * `offs`: File offset
/// * `buf`: A memory buffer. It must outlive the `AioRead`.
/// * `prio`: If POSIX Prioritized IO is supported, then the
/// operation will be prioritized at the process's
/// priority level minus `prio`
/// * `sigev_notify`: Determines how you will be notified of event
/// completion.
/// * `prio`: If POSIX Prioritized IO is supported, then the operation
/// will be prioritized at the process's priority level minus `prio`
/// * `sigev_notify`: Determines how you will be notified of event completion.
pub fn new(
fd: BorrowedFd<'a>,
offs: off_t,
Expand Down Expand Up @@ -805,11 +802,9 @@ impl<'a> AioWrite<'a> {
/// * `fd`: File descriptor to write to
/// * `offs`: File offset
/// * `buf`: A memory buffer. It must outlive the `AioWrite`.
/// * `prio`: If POSIX Prioritized IO is supported, then the
/// operation will be prioritized at the process's
/// priority level minus `prio`
/// * `sigev_notify`: Determines how you will be notified of event
/// completion.
/// * `prio`: If POSIX Prioritized IO is supported, then the operation
/// will be prioritized at the process's priority level minus `prio`
/// * `sigev_notify`: Determines how you will be notified of event completion.
pub fn new(
fd: BorrowedFd<'a>,
offs: off_t,
Expand Down
4 changes: 3 additions & 1 deletion src/sys/ioctl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,10 @@ macro_rules! ioctl_readwrite {
pub unsafe fn $name(fd: $crate::libc::c_int,
data: *mut $ty)
-> $crate::Result<$crate::libc::c_int> {
let ioty = $ioty;
let nr = $nr;
unsafe {
convert_ioctl_res!($crate::libc::ioctl(fd, request_code_readwrite!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
convert_ioctl_res!($crate::libc::ioctl(fd, request_code_readwrite!(ioty, nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
}
}
)
Expand Down
16 changes: 7 additions & 9 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,15 +655,13 @@ pub trait SockaddrLike: private::SockaddrLikePriv {
///
/// # Arguments
///
/// - `addr`: raw pointer to something that can be cast to a
/// `libc::sockaddr`. For example, `libc::sockaddr_in`,
/// `libc::sockaddr_in6`, etc.
/// - `len`: For fixed-width types like `sockaddr_in`, it will be
/// validated if present and ignored if not. For variable-width
/// types it is required and must be the total length of valid
/// data. For example, if `addr` points to a
/// named `sockaddr_un`, then `len` must be the length of the
/// structure up to but not including the trailing NUL.
/// - `addr`: raw pointer to something that can be cast to a `libc::sockaddr`.
/// For example, `libc::sockaddr_in`, `libc::sockaddr_in6`, etc.
/// - `len`: For fixed-width types like `sockaddr_in`, it will be validated
/// if present and ignored if not. For variable-width types it is required
/// and must be the total length of valid data. For example, if `addr`
/// points to a named `sockaddr_un`, then `len` must be the length of the
/// structure up to but not including the trailing NUL.
///
/// # Safety
///
Expand Down
38 changes: 19 additions & 19 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ const TCP_CA_NAME_MAX: usize = 16;
///
/// * `$name:ident`: name of the type you want to implement `SetSockOpt` for.
/// * `$level:expr` : socket layer, or a `protocol level`: could be *raw sockets*
/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
/// and more. Please refer to your system manual for more options. Will be passed as the second
/// argument (`level`) to the `setsockopt` call.
/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
/// and more. Please refer to your system manual for more options. Will be passed as the second
/// argument (`level`) to the `setsockopt` call.
/// * `$flag:path`: a flag name to set. Some examples: `libc::SO_REUSEADDR`, `libc::TCP_NODELAY`,
/// `libc::IP_ADD_MEMBERSHIP` and others. Will be passed as the third argument (`option_name`)
/// to the `setsockopt` call.
/// `libc::IP_ADD_MEMBERSHIP` and others. Will be passed as the third argument (`option_name`)
/// to the `setsockopt` call.
/// * Type of the value that you are going to set.
/// * Type that implements the `Set` trait for the type from the previous item (like `SetBool` for
/// `bool`, `SetUsize` for `usize`, etc.).
/// * Type that implements the `Set` trait for the type from the previous item
/// (like `SetBool` for `bool`, `SetUsize` for `usize`, etc.).
#[macro_export]
macro_rules! setsockopt_impl {
($name:ident, $level:expr, $flag:path, $ty:ty, $setter:ty) => {
Expand Down Expand Up @@ -87,15 +87,15 @@ macro_rules! setsockopt_impl {
///
/// * Name of the type you want to implement `GetSockOpt` for.
/// * Socket layer, or a `protocol level`: could be *raw sockets* (`lic::SOL_SOCKET`), *ip
/// protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`), and more. Please refer
/// to your system manual for more options. Will be passed as the second argument (`level`) to
/// the `getsockopt` call.
/// protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`), and more. Please refer
/// to your system manual for more options. Will be passed as the second argument (`level`) to
/// the `getsockopt` call.
/// * A flag to set. Some examples: `libc::SO_REUSEADDR`, `libc::TCP_NODELAY`,
/// `libc::SO_ORIGINAL_DST` and others. Will be passed as the third argument (`option_name`) to
/// the `getsockopt` call.
/// `libc::SO_ORIGINAL_DST` and others. Will be passed as the third argument (`option_name`) to
/// the `getsockopt` call.
/// * Type of the value that you are going to get.
/// * Type that implements the `Get` trait for the type from the previous item (`GetBool` for
/// `bool`, `GetUsize` for `usize`, etc.).
/// `bool`, `GetUsize` for `usize`, etc.).
#[macro_export]
macro_rules! getsockopt_impl {
($name:ident, $level:expr, $flag:path, $ty:ty, $getter:ty) => {
Expand Down Expand Up @@ -161,15 +161,15 @@ macro_rules! getsockopt_impl {
/// # Arguments
///
/// * `GetOnly`, `SetOnly` or `Both`: whether you want to implement only getter, only setter or
/// both of them.
/// both of them.
/// * `$name:ident`: name of type `GetSockOpt`/`SetSockOpt` will be implemented for.
/// * `$level:expr` : socket layer, or a `protocol level`: could be *raw sockets*
/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
/// and more. Please refer to your system manual for more options. Will be passed as the second
/// argument (`level`) to the `getsockopt`/`setsockopt` call.
/// (`libc::SOL_SOCKET`), *ip protocol* (libc::IPPROTO_IP), *tcp protocol* (`libc::IPPROTO_TCP`),
/// and more. Please refer to your system manual for more options. Will be passed as the second
/// argument (`level`) to the `getsockopt`/`setsockopt` call.
/// * `$flag:path`: a flag name to set. Some examples: `libc::SO_REUSEADDR`, `libc::TCP_NODELAY`,
/// `libc::IP_ADD_MEMBERSHIP` and others. Will be passed as the third argument (`option_name`)
/// to the `setsockopt`/`getsockopt` call.
/// `libc::IP_ADD_MEMBERSHIP` and others. Will be passed as the third argument (`option_name`)
/// to the `setsockopt`/`getsockopt` call.
/// * `$ty:ty`: type of the value that will be get/set.
/// * `$getter:ty`: `Get` implementation; optional; only for `GetOnly` and `Both`.
/// * `$setter:ty`: `Set` implementation; optional; only for `SetOnly` and `Both`.
Expand Down
6 changes: 3 additions & 3 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ impl ForkResult {
/// # Safety
///
/// In a multithreaded program, only [async-signal-safe] functions like `pause`
/// and `_exit` may be called by the child (the parent isn't restricted). Note
/// that memory allocation may **not** be async-signal-safe and thus must be
/// prevented.
/// and `_exit` may be called by the child (the parent isn't restricted) until
/// a call of `execve(2)`. Note that memory allocation may **not** be
/// async-signal-safe and thus must be prevented.
///
/// Those functions are only a small subset of your operating system's API, so
/// special care must be taken to only invoke code you can control and audit.
Expand Down
Loading

0 comments on commit a0307df

Please sign in to comment.