-
Notifications
You must be signed in to change notification settings - Fork 741
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
journald: fix memfd_create_syscall for 32 bit targets #1982
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this works, I don't think it's really the most correct solution. The memfd_create
system call returns a C int
type, so I think that, instead of calling .into()
on the return value, we should just change the definition of the memfd_create_syscall
function so that, rather than returning an i64
, it returns the c_int
type from libc
. This will always be the correct type on the current platform, and we can remove the into()
call.
Unfortunately Edit: But i would also like a better solution. But i did not find any type that is either a i32 or i64 depending on the target platform. |
Ah, sorry, my bad, I meant to say that it should be |
Yes, Thus it should be perfectly safe to force the |
On 32 bit targets (e.g. armv7) the syscall in memfd_create_syscall() returns an i32, so this compilation error is printed: | error[E0308]: mismatched types | --> .../tracing-journald-0.2.3/src/memfd.rs:27:9 | | | 25 | fn memfd_create_syscall(flags: c_uint) -> i64 { | | --- expected `i64` | | because of return type | 26 | unsafe { | 27 | / syscall( | 28 | | SYS_memfd_create, | 29 | | "tracing-journald\0".as_ptr() as *const c_char, | 30 | | flags, | 31 | | ) | | |_________^ expected `i64`, found `i32` | | | help: you can convert an `i32` to an `i64` | | | 31 | ).into() | | +++++++ | | For more information about this error, try `rustc --explain E0308`. | error: could not compile `tracing-journald` due to previous error | This commit fixes this issue.
7bf53bf
to
30ea42a
Compare
Thank you for the explanations, i am completely new to rust, so this is a little bit more difficult for me. I retried with converting the returned c_long into a c_int, because in the create() function the fd is expected to be convertible into RawFd. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the cast to c_int
seems fine to me, i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
On 32 bit targets (e.g. armv7) the syscall in memfd_create_syscall() returns an i32, so this compilation error is printed: | error[E0308]: mismatched types | --> .../tracing-journald-0.2.3/src/memfd.rs:27:9 | | | 25 | fn memfd_create_syscall(flags: c_uint) -> i64 { | | --- expected `i64` | | because of return type | 26 | unsafe { | 27 | / syscall( | 28 | | SYS_memfd_create, | 29 | | "tracing-journald\0".as_ptr() as *const c_char, | 30 | | flags, | 31 | | ) | | |_________^ expected `i64`, found `i32` | | | help: you can convert an `i32` to an `i64` | | | 31 | ).into() | | +++++++ | | For more information about this error, try `rustc --explain E0308`. | error: could not compile `tracing-journald` due to previous error | This commit fixes this issue.
On 32 bit targets (e.g. armv7) the syscall in memfd_create_syscall() returns an i32, so this compilation error is printed: | error[E0308]: mismatched types | --> .../tracing-journald-0.2.3/src/memfd.rs:27:9 | | | 25 | fn memfd_create_syscall(flags: c_uint) -> i64 { | | --- expected `i64` | | because of return type | 26 | unsafe { | 27 | / syscall( | 28 | | SYS_memfd_create, | 29 | | "tracing-journald\0".as_ptr() as *const c_char, | 30 | | flags, | 31 | | ) | | |_________^ expected `i64`, found `i32` | | | help: you can convert an `i32` to an `i64` | | | 31 | ).into() | | +++++++ | | For more information about this error, try `rustc --explain E0308`. | error: could not compile `tracing-journald` due to previous error | This commit fixes this issue. Co-authored-by: Christian Taedcke <[email protected]>
# 0.2.4 (March 17, 2022) ### Fixed - Fixed compilation error in `memfd_create_syscall` on 32-bit targets ([tokio-rs#1982]) Thanks to new contributor @chrta for contributing to this release! [tokio-rs#1982]: tokio-rs#1982
Motivation
I would like to use tracing-journald on a 32 bit target (armv7).
Solution
On 32 bit targets (e.g. armv7) the syscall in memfd_create_syscall()
returns an i32, so this compilation error is printed: