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


#1

On Linux and Mac OS, siginfo_t contains a field si_addr to show which memory address caused this signal.
See http://man7.org/linux/man-pages/man2/sigaction.2.html
and https://developer.apple.com/documentation/kernel/siginfo_t.

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).


#2

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

Instead of writing a wrapper, you should modify libc source (https://github.com/rust-lang/libc) to add other fields and propose a PR. The maintainer is very responsive !


#3

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.