Skip to content

linux: complete siginfo_t definition - #5345

Open
dybucc wants to merge 8 commits into
rust-lang:mainfrom
dybucc:linux-siginfo_t-tweaks
Open

linux: complete siginfo_t definition#5345
dybucc wants to merge 8 commits into
rust-lang:mainfrom
dybucc:linux-siginfo_t-tweaks

Conversation

@dybucc

@dybucc dybucc commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

Completes the siginfo_t definition under Linux targets. Closes #716.

See the patch messages for details on each of the GNU targets, uClibc
targets and musl targets.

Checklist

  • Relevant tests in libc-test/semver have been updated
  • Commit messages permalink to headers for added or changed API
  • Placeholder or unstable values like *LAST or *MAX have the
    standard doc comment
  • Tested locally (cargo test -p libc-test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

@dybucc dybucc changed the title Linux: complete siginfo_t definition linux: complete siginfo_t definition Jul 31, 2026
@xtqqczze

This comment was marked as outdated.

@tgross35

tgross35 commented Aug 4, 2026

Copy link
Copy Markdown
Member

Would you mind using this as an opportunity to move signifo_t to src/new? At least on glibc, that should make things a lot easier with less duplication. No need to be perfect with siginfo-arch.h since that's tricky to replicate in Rust, cfg is fine.

Also fyi, @xtqqczze found https://github.com/sailfishos-mirror/glibc as a mirror for glibc that's much easier to search and less flaky, that's fine to link (as is sourceware, of course).

@tgross35

tgross35 commented Aug 4, 2026

Copy link
Copy Markdown
Member

There will be quite a bit less to review after that, so will hold off taking a closer look. Let me know if you need help figuring out the module structure.

@rustbot author

@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot

This comment has been minimized.

@dybucc
dybucc force-pushed the linux-siginfo_t-tweaks branch from a6ba6f4 to bd71182 Compare August 5, 2026 06:49
@rustbot

This comment has been minimized.

@dybucc
dybucc force-pushed the linux-siginfo_t-tweaks branch 7 times, most recently from b02986c to 08192fa Compare August 5, 2026 15:18
@dybucc
dybucc force-pushed the linux-siginfo_t-tweaks branch 6 times, most recently from 1e7631c to 72a1606 Compare August 5, 2026 17:25
@dybucc

dybucc commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

I'm not sure what, but I had something else to do in this patchset. Hopefully
the review will surface it.

@rustbot ready

@rustbot

This comment has been minimized.

@dybucc
dybucc force-pushed the linux-siginfo_t-tweaks branch from 72a1606 to a8ee195 Compare August 15, 2026 14:12
@rustbot

This comment has been minimized.

@dybucc
dybucc force-pushed the linux-siginfo_t-tweaks branch from a8ee195 to f920138 Compare August 15, 2026 15:02
@dybucc
dybucc force-pushed the linux-siginfo_t-tweaks branch 2 times, most recently from 61ec092 to 796c4ae Compare August 30, 2026 14:21
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@tgross35 tgross35 left a comment

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.

Sorry this has been on my todo list for a while, finally got through it

View changes since this review

Comment on lines +61 to +62
si_utime: crate::clock_t,
si_stime: crate::clock_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.

On x32, this needs some kind of alignment adjustment https://github.com/sailfishos-mirror/glibc/blob/4a07bb292f921c10e71fbf48c4a7f44391feb06c/sysdeps/unix/sysv/linux/x86/bits/siginfo-arch.h#L12-L14, maybe a struct __SI_CLOCK_T(crate::clock_t) that gets an alignment attribute on specific platforms.

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.

};

s_no_extra_traits! {
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.


#[cfg(target_pointer_width = "64")]
#[inline]
pub unsafe fn si_band(&self) -> c_int {

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.

This can be a type __SI_BAND_TYPE = ... to match the header

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.

Comment thread src/new/musl/signal.rs
Comment on lines +13 to +16
#[cfg(not(any(target_arch = "mips", target_arch = "mips64")))]
pub si_errno: c_int,
pub si_code: c_int,
#[cfg(any(target_arch = "mips", target_arch = "mips64"))]

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.

You'll also need mips32r6 and mips64r6 here, and everywhere mips is configured. Somewhat annoyingly #t-compiler > mipsr6 targets `target_arch` confusion.

Comment thread src/new/glibc/mod.rs
Comment on lines 41 to +52
// 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::{
bits as nptl_bits,
pthread,
};
#[cfg(target_os = "linux")]
pub(crate) use sysdeps::unix::linux::*;
pub(crate) use sysdeps::unix::linux::{
bits as linux_bits,
net,
};

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.

If bits isn't needed, can only pthread be reexported?

It might even be possible to just drop the pub(crate) from the bits modules, since they're not really needed at this level.

Comment thread src/new/mod.rs
Comment on lines +200 to +208
#[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::*;
pub use self::{
linux_bits::types::siginfo_t::*,
net::route::*,
signal::*,
};

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.

dybucc added 7 commits August 31, 2026 16:39
Replace references to `siginfo_t` in the regular repository layout with
a crate-relative path that uses the reexport from the `new` module. This
allows the next few patches to all work as individual revisions.
Replace alignment/padding fields with a one-to-one definition as that
used upstream. These have been incorporated as definitions in the `new`
module to avoid huge repetition across target triples without overrides.
The glibc definitions are mostly the same across target architectures
except for MIPS, SPARC and x86. x86 is confusing because there's only an
override when running under x86_64 and compiling for x32. I'm not sure
how Rust handles this, so the `#[path]`-redirected files for that
architecture are the same as the generic ones. See [^1] for the generic
file and the following list for the architecture-specific overrides.

- `mips`:
<https://github.com/sailfishos-mirror/glibc/blob/4a07bb292f921c10e71fbf48c4a7f44391feb06c/sysdeps/unix/sysv/linux/mips/bits/siginfo-arch.h>
- `sparc`:
<https://github.com/sailfishos-mirror/glibc/blob/4a07bb292f921c10e71fbf48c4a7f44391feb06c/sysdeps/unix/sysv/linux/sparc/bits/siginfo-arch.h>
- `x86`:
<https://github.com/sailfishos-mirror/glibc/blob/4a07bb292f921c10e71fbf48c4a7f44391feb06c/sysdeps/unix/sysv/linux/x86/bits/siginfo-arch.h>

[^1]:
<https://github.com/sailfishos-mirror/glibc/blob/4a07bb292f921c10e71fbf48c4a7f44391feb06c/sysdeps/unix/sysv/linux/bits/types/siginfo_t.h>
Remove older bindings to `siginfo_t` using dummy fields instead of the
upstream `union`. This follows from the patch providing a full
definition for glibc bindings.

Add reexports for `siginfo_t` under the `new` module. This has required
renaming the reexport for the `nptl` module as it also contains a `bits`
module of the same name as the `bits::types::siginfo_t` module path
under `sysdeps`.
Replace alignment/padding fields with a mirrored definition of the
upstream `union`. See [^1] for details.

[^1]: <https://github.com/kraj/musl/blob/a42e9dee266f398026a33d0793c66225c7997755/include/signal.h>
Remove older bindings to `siginfo_t` using dummy fields instead of the
upstream `union`. This follows from the patch providing a full
definition for musl bindings.

Add modified bindings under `new`.
Replace alignment/padding dummy fields with a mirrored definition
fitting that of upstream's `union`. uClibc supports targets for which we
have no support in Rust. No architecture-specific definition has been
provided for those. See [^1] for details on the generic definition and
[^2] for details on the MIPS definition.

[^1]: <https://github.com/wbx-github/uclibc-ng/blob/60d8e8c0cb9be8a241f6f2645daba260c8aec33c/libc/sysdeps/linux/common/bits/siginfo.h>
[^2]: <https://github.com/wbx-github/uclibc-ng/blob/60d8e8c0cb9be8a241f6f2645daba260c8aec33c/libc/sysdeps/linux/mips/bits/siginfo.h>
Remove older bindings to `siginfo_t` using dummy fields instead of the
upstream `union`. This follows from the patch providing a full
definition for uClibc bindings.

Add modified bindings to `new` module.
@dybucc
dybucc force-pushed the linux-siginfo_t-tweaks branch from 796c4ae to 2de5e62 Compare August 31, 2026 15:32
@rustbot

rustbot commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem in implementing siginfo_t for Linux

4 participants