-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem in implementing siginfo_t for Linux #716
Comments
Yes, I think the issue is that in C, the alignment is done for all the struct after union elements are inserted, then in C we do not align the union itself. We can force the union to be aligned in 4bytes by only using 4bytes fields or less, then for example It is passing the test now, but it's not a clean solution. We have then to define the size of these arrays conditionally in function of the target while the types which can be longer than 4 bytes are already defined conditionnaly in libc.(when The other bad point is that users of Maybe the solution would be to let this as is, and let higher-level crate as |
Thanks for the reply. I was a bit surprised as I thought with the introduction of Also |
Yeah right now the handling of |
@qinsoon Marking the |
Anyone interested on working on this anytime soon? It appears that @vojtechkral suggest a way to solve this. I can mentor. |
Should this be in the 1.0 roadmap? #547 |
I'd be interested in working on this, at least far enough to get |
@alex what do you mean by not solving this completely? the proposed change should just work, it will only need a bit of cfg-magic to be active on newer Rust versions. |
Not adding every single field :-) |
As long as the struct layout is correct, if the union field is private, we can do whatever we want (as long as we only use the union on toolchains that support it). If the question is whether we can make the field a public union, and then add newer union fields incrementally over time, I haven't thought about that, but I think it's a good question. I've asked it here: rust-lang/api-guidelines#196 |
Ah yes, that does suggest a good question: do we want to just expose the underlying unions, or add methods on |
If C exposes the union we should do that. If C has functions to expose the fields, we can add those. I don't think C has methods, so doing that would be something more appropriate for the |
In C the field containing a union has a name with an underscore
`_sifields`, and then there are macros like `#define si_addr
_sifields._sigfault._addr`. So you can do `some_siginfo_t.si_addr` (and
you can't really have a field named `si_addr` on any other struct, but oh
well).
…On Fri, Apr 12, 2019 at 8:35 AM gnzlbg ***@***.***> wrote:
If C exposes the union we should do that. If C has functions to expose the
fields, we can add those. I don't think C has methods, so doing that would
be something more appropriate for the nix crate.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#716 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAADBD10ePsPypLCiLRuXizwOZMTgjdXks5vgH2RgaJpZM4OxrDb>
.
--
All that is necessary for evil to succeed is for good people to do nothing.
|
We typically map those macros to Rust functions, so I think we can just keep the field private (in which case it does not matter whether it is implemented using an |
I'll try to get to it later today!
…On Fri, Apr 12, 2019, 9:07 AM gnzlbg ***@***.***> wrote:
We typically map those macros to Rust functions, so I think we can just
keep the field private (in which case it does not matter whether it is
implemented using an union or not), and just provide functions to access
the fields. We can probably make things a bit more concrete once we have a
PR open with an initial proposal.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#716 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAADBFnxwr7GrtUiL8FEVuVijnjFOtApks5vgIUegaJpZM4OxrDb>
.
|
So the padding field of |
Figured I'd drop by and leave my 2 cents here as well since I'm looking into The kernel's
The first 3 4-byte values are the fields
In the rust playground link, the forced 8-byte alignment throws off the padding calculation (which is actually garbage pre linux 4.20). It doesn't take into account that the compiler will add padding between the 3 integers and the union on 64 bit systems, which makes the padding 4 bytes too long. This isn't an issue in libc right now because those fields in the union are omitted. Recent versions of the linux kernel (since 4.20) have changed the definition of
Which is much clearer (despite that it could have been better described as a union at the top level...). This removes the bizarre So it would probably be better just to update the |
@nbsdx Thanks for investigating. FWIW I have no memory of that comment I wrote and, more specifically, why I thought so :) |
@vojtechkral no problem, packing it was my initial solution as well until I dug into it more once I wasn't able to access fields properly :) |
On Linux, siginfo_t cannot expose these fields directly due to rust-lang#716 , so expose them as functions, just like si_addr and si_value. Provide the same functions on other platforms that have these fields declared, for consistency.
On Linux, siginfo_t cannot expose these fields directly due to rust-lang#716 , so expose them as functions, just like si_addr and si_value.
On Linux, siginfo_t cannot expose these fields directly due to rust-lang#716 , so expose them as functions, just like si_addr and si_value. In order to get alignment correct on both 32-bit and 64-bit architectures, define the sifields union, which includes variants that start with a pointer. Update the existing si_addr and si_value functions to use that union.
On Linux, siginfo_t cannot expose these fields directly due to rust-lang#716 , so expose them as functions, just like si_addr and si_value. In order to get alignment correct on both 32-bit and 64-bit architectures, define the sifields union, which includes variants that start with a pointer. Update the existing si_addr and si_value functions to use that union.
On Linux, siginfo_t cannot expose these fields directly due to rust-lang#716 , so expose them as functions, just like si_addr and si_value. In order to get alignment correct on both 32-bit and 64-bit architectures, define an sifields union that includes a pointer field, to ensure that it has the same alignment as a pointer.
On Linux, siginfo_t cannot expose these fields directly due to rust-lang#716 , so expose them as functions, just like si_addr and si_value. In order to get alignment correct on both 32-bit and 64-bit architectures, define an sifields union that includes a pointer field, to ensure that it has the same alignment as a pointer.
If we receive SIGSYS and identify it as a seccomp violation then give friendly instructions on how to debug further. We are unable to decode the siginfo_t struct ourselves due to rust-lang/libc#716 Fixes: cloud-hypervisor#2139 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
If we receive SIGSYS and identify it as a seccomp violation then give friendly instructions on how to debug further. We are unable to decode the siginfo_t struct ourselves due to rust-lang/libc#716 Fixes: #2139 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
The definition of
siginfo_t
in Linux (https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/siginfo.h) uses a inlinedunion
type as its last field. Rust did not have support for union types, I guess that was why those fields were left as a padding array in currentlibc
implementation.I made some attempts to use
union
(introduced in Rust 1.19) to representsiginfo_t
. However the resulting struct is 8 bytes larger than the original one (the one currently in libc, which is the same size as the C struct type). See the code here: https://play.rust-lang.org/?gist=99630206fcc8fd44b452d22552b37793&version=stableMy guess is the 8 more bytes come from two places:
siginfo_t
are 12 bytes (3x 4-bytes integer), so the padding is needed after the first 3 fields, which makes the offset of the union type at 16 bytes (instead of 12 bytes)I am not sure why the C definition does not have issues like this (probably because it uses inlined
union
in the struct definition) and how to properly implementsiginfo_t
in Rust. Please correct me if I am wrong. For my project, I have to extract data from the padding array (which looks awful).The text was updated successfully, but these errors were encountered: