Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/new/glibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod sysdeps {
pub(crate) use posix::*;
// FIXME(pthread): eventually all platforms should use this module
#[cfg(target_os = "linux")]
pub(crate) use sysdeps::nptl::*;
#[allow(unused)]
pub(crate) use sysdeps::nptl::pthread;
#[cfg(target_os = "linux")]
pub(crate) use sysdeps::unix::linux::*;
pub(crate) use sysdeps::unix::linux::net;
1 change: 1 addition & 0 deletions src/new/glibc/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub use super::bits::signum_generic::*;
pub use super::sysdeps::unix::linux::bits::sigaction::*;
pub use super::sysdeps::unix::linux::bits::types::siginfo_t::*;
use crate::prelude::*;

extern "C" {
Expand Down
5 changes: 5 additions & 0 deletions src/new/glibc/sysdeps/unix/linux/bits/types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Source directory: `sysdeps/unix/sysv/linux/bits/types`
//!
//! <https://github.com/sailfishos-mirror/glibc/tree/master/sysdeps/unix/sysv/linux/bits/types>

pub(crate) mod siginfo_t;
265 changes: 265 additions & 0 deletions src/new/glibc/sysdeps/unix/linux/bits/types/siginfo_t.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you merge the siginfo_arch files into siginfo_t? Since there are just a few changed fields we may as well reduce the duplication, and it's easier to see the differences (like the original source).

You could keep the files separate for __SI_BAND_TYPE and __SI_CLOCK_T but I don't think that's worth it for 1-2 cfg_ifs. Just make a note that this one file represents multiple headers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
//! Source header: `sysdeps/unix/sysv/linux/bits/types/siginfo_t.h`
//!
//! Note this module corresponds with multiple header files upstream. The above
//! header file contains the generic definition, while other
//! architecture-specific definitions live upstream at
//! `sysdeps/unix/sysv/linux/<arch>/bits/siginfo-arch.h`. Currently, the
//! following set of header files are contained in this one Rust module:
//!
//! - `sysdeps/unix/sysv/linux/bits/types/siginfo_t.h`
//! - `sysdeps/unix/sysv/linux/x86/bits/siginfo-arch.h`
//! - `sysdeps/unix/sysv/linux/mips/bits/siginfo-arch.h`
//! - `sysdeps/unix/sysv/linux/sparc/bits/siginfo-arch.h`
//!
//! <https://github.com/sailfishos-mirror/glibc/blob/master/sysdeps/unix/sysv/linux/bits/types/siginfo_t.h>

use crate::prelude::*;

const __SI_MAX_SIZE: usize = 128;
const __SI_PAD_SIZE: usize = if cfg!(target_pointer_width = "64") {
__SI_MAX_SIZE / size_of::<c_int>() - 4
} else {
__SI_MAX_SIZE / size_of::<c_int>() - 3
};

cfg_if! {
if #[cfg(target_arch = "sparc64")] {
type __SI_BAND_TYPE = c_int;
} else {
type __SI_BAND_TYPE = c_long;
}
}

#[repr(C)]
#[cfg_attr(
all(target_arch = "x86_64", target_pointer_width = "32"),
repr(align(4))
)]
#[derive(Clone, Copy, Debug)]
struct __SI_CLOCK_T(crate::clock_t);

s_no_extra_traits! {
#[cfg_attr(
all(target_arch = "x86_64", target_pointer_width = "32"),
repr(align(8))
)]
pub struct siginfo_t {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly it needs an alignment attribute on x32 for __SI_ALIGNMENT. I guess these were preexisting but may as well be fixed here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

pub si_signo: c_int,

#[cfg(any(
target_arch = "mips",
target_arch = "mips64",
target_arch = "mips32r6",
target_arch = "mips64r6"
))]
pub si_code: c_int,

pub si_errno: c_int,

#[cfg(not(any(
target_arch = "mips",
target_arch = "mips64",
target_arch = "mips32r6",
target_arch = "mips64r6"
)))]
pub si_code: c_int,

#[cfg(target_pointer_width = "64")]
__pad0: Padding<c_int>,
_sifields: __c_anonymous_siginfo_t__si_fields,
}

union __c_anonymous_siginfo_t__si_fields {
_pad: [c_int; __SI_PAD_SIZE],
_kill: __c_anonymous__si_fields__kill,
_timer: __c_anonymous__si_fields__timer,
_rt: __c_anonymous__si_fields__rt,
_sigchld: __c_anonymous__si_fields__sigchld,
_sigfault: __c_anonymous__si_fields__sigfault,
_sigpoll: __c_anonymous__si_fields__sigpoll,
_sigsys: __c_anonymous__si_fields__sigsys,
}

struct __c_anonymous__si_fields__kill {
si_pid: crate::pid_t,
si_uid: crate::uid_t,
}

struct __c_anonymous__si_fields__timer {
si_tid: c_int,
si_overrun: c_int,
si_sigval: crate::sigval,
}

struct __c_anonymous__si_fields__rt {
si_pid: crate::pid_t,
si_uid: crate::uid_t,
si_sigval: crate::sigval,
}

struct __c_anonymous__si_fields__sigchld {
si_pid: crate::pid_t,
si_uid: crate::uid_t,
si_status: c_int,
si_utime: __SI_CLOCK_T,
si_stime: __SI_CLOCK_T,
}

struct __c_anonymous__si_fields__sigfault {
si_addr: *mut c_void,
#[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
_si_trapno: c_int,
si_addr_lsb: c_short,
_bounds: __c_anonymous__sigfault__bounds,
}

struct __c_anonymous__si_fields__sigpoll {
si_band: __SI_BAND_TYPE,
si_fd: c_int,
}

struct __c_anonymous__si_fields__sigsys {
_call_addr: *mut c_void,
_syscall: c_int,
_arch: c_uint,
}

union __c_anonymous__sigfault__bounds {
_addr_bnd: __c_anonymous__bounds__addr_bnd,
_pkey: u32,
}

struct __c_anonymous__bounds__addr_bnd {
_lower: *mut c_void,
_upper: *mut c_void,
}
}

impl siginfo_t {
#[inline]
pub const unsafe fn si_pid(&self) -> crate::pid_t {
unsafe { self._sifields._kill.si_pid }
}

#[inline]
pub const unsafe fn si_uid(&self) -> crate::uid_t {
unsafe { self._sifields._kill.si_uid }
}

#[inline]
pub const unsafe fn si_timerid(&self) -> c_int {
unsafe { self._sifields._timer.si_tid }
}

#[inline]
pub const unsafe fn si_overrun(&self) -> c_int {
unsafe { self._sifields._timer.si_overrun }
}

#[inline]
pub const unsafe fn si_status(&self) -> c_int {
unsafe { self._sifields._sigchld.si_status }
}

#[inline]
pub const unsafe fn si_utime(&self) -> crate::clock_t {
unsafe { self._sifields._sigchld.si_utime.0 }
}

#[inline]
pub const unsafe fn si_stime(&self) -> crate::clock_t {
unsafe { self._sifields._sigchld.si_stime.0 }
}

#[inline]
pub const unsafe fn si_value(&self) -> crate::sigval {
unsafe { self._sifields._rt.si_sigval }
}

#[inline]
pub const unsafe fn si_int(&self) -> c_int {
unsafe { self._sifields._rt.si_sigval.sival_int }
}

#[inline]
pub const unsafe fn si_ptr(&self) -> *mut c_void {
unsafe { self._sifields._rt.si_sigval.sival_ptr }
}

#[inline]
pub const unsafe fn si_addr(&self) -> *mut c_void {
unsafe { self._sifields._sigfault.si_addr }
}

#[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
#[inline]
pub const unsafe fn si_trapno(&self) -> c_int {
unsafe { self._sifields._sigfault._si_trapno }
}

#[inline]
pub const unsafe fn si_addr_lsb(&self) -> c_short {
unsafe { self._sifields._sigfault.si_addr_lsb }
}

#[inline]
pub const unsafe fn si_lower(&self) -> *mut c_void {
unsafe { self._sifields._sigfault._bounds._addr_bnd._lower }
}

#[inline]
pub const unsafe fn si_upper(&self) -> *mut c_void {
unsafe { self._sifields._sigfault._bounds._addr_bnd._upper }
}

#[inline]
pub const unsafe fn si_pkey(&self) -> u32 {
unsafe { self._sifields._sigfault._bounds._pkey }
}

#[inline]
pub const unsafe fn si_band(&self) -> __SI_BAND_TYPE {
unsafe { self._sifields._sigpoll.si_band }
}

#[inline]
pub const unsafe fn si_fd(&self) -> c_int {
unsafe { self._sifields._sigpoll.si_fd }
}

#[inline]
pub const unsafe fn si_call_addr(&self) -> *mut c_void {
unsafe { self._sifields._sigsys._call_addr }
}

#[inline]
pub const unsafe fn si_syscall(&self) -> c_int {
unsafe { self._sifields._sigsys._syscall }
}

#[inline]
pub const unsafe fn si_arch(&self) -> c_uint {
unsafe { self._sifields._sigsys._arch }
}
}

cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for siginfo_t {
fn eq(&self, other: &Self) -> bool {
(self.si_signo, self.si_errno, self.si_code)
== (other.si_signo, other.si_errno, other.si_code)
}
}

impl Eq for siginfo_t {}

impl core::hash::Hash for siginfo_t {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.si_signo.hash(state);
self.si_errno.hash(state);
self.si_code.hash(state);
}
}
}
}
4 changes: 4 additions & 0 deletions src/new/glibc/sysdeps/unix/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub(crate) mod bits {
path = "../sparc/bits/sigaction.rs"
)]
pub(crate) mod sigaction;

#[cfg_attr(
any(
target_arch = "mips",
Expand All @@ -33,7 +34,10 @@ pub(crate) mod bits {
path = "../sparc/bits/signum_arch.rs"
)]
pub(crate) mod signum_arch;

pub(crate) mod statvfs;

pub(crate) mod types;
}

/// Directory: `net/`
Expand Down
14 changes: 9 additions & 5 deletions src/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,15 @@ cfg_if! {
pub use linux::sctp::*;
pub use linux::tls::*;
pub use linux::types::*;
#[cfg(target_env = "uclibc")]
pub use sysdeps::linux::common::bits::siginfo::*;

#[cfg(target_env = "gnu")]
pub use net::route::*;
#[cfg(target_env = "gnu")]
pub use signal::*;
#[cfg(target_env = "gnu")]
pub use sys::statvfs::*;
pub use self::{
net::route::*,
signal::*,
sys::statvfs::*,
};
Comment on lines +200 to +208

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loose idea is that the modules reexported here should correspond to headers that are used. That is, #include <linux/tls.h> maps to pub use linux::tls::*;, and #include <signal.h> maps to pub use signal::*. So these probably need a mod signal somewhere that reexports from bits, since users don't import sysdeps/linux/common/bits/signinfo.h directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's done now. I removed the reexports and instead used the
existing signal reexport by reexporting the sigaction_t module items
within the signal module.

} else if #[cfg(target_vendor = "apple")] {
#[cfg(target_os = "macos")]
pub use net::bpf::*;
Expand Down Expand Up @@ -261,6 +264,7 @@ cfg_if! {
// Per-env headers we export
cfg_if! {
if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
pub use signal::*;
pub use sys::socket::*;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/new/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ pub(crate) mod sys {
}

pub(crate) mod sched;
pub(crate) mod signal;
pub(crate) mod unistd;
Loading