Implementing signal handler: siginfo_t in libc for Linux does not contain si_addr field?

On Linux and Mac OS, siginfo_t contains a field si_addr to show which memory address caused this signal.
See sigaction(2) - Linux manual page
and Apple Developer Documentation.

However for Rust's libc crate, on Mac OS, siginfo_t contains a field of si_addr as expected (https://doc.rust-lang.org/libc/x86_64-apple-darwin/libc/struct.siginfo_t.html). But on linux, siginfo_t has no explicit si_addr field - it falls in one of the padding fields (https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc/struct.siginfo_t.html).

I don't quite understand the reason behind this. And I am wondering how I should access si_addr field on Linux (though I can access from some specific indices of the _pad field or create my own wrapper of siginfo_t for Linux, but this seems far away from a good solution).

Probably the person who wrote it didn't need the other fields.

Instead of writing a wrapper, you should modify libc source (GitHub - rust-lang/libc: Raw bindings to platform APIs for Rust) to add other fields and propose a PR. The maintainer is very responsive !

1 Like

Thanks a lot. I made some attempts to fix this but I met problems. I have submitted an issue on github: https://github.com/rust-lang/libc/issues/716.

1 Like