Skip to content
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

Bugfixed support for compilation with musl without libfuse present #185

Merged
merged 2 commits into from
Nov 11, 2021

Conversation

gdox
Copy link

@gdox gdox commented Nov 4, 2021

An explanation of the unsafe block:

Musl has a different msghdr structure than glibc. It looks as follows:

pub struct msghdr {
    pub msg_name: *mut ::c_void,
    pub msg_namelen: ::socklen_t,
    pub msg_iov: *mut ::iovec,
    #[cfg(target_endian = "big")]
    __pad1: ::c_int,
    pub msg_iovlen: ::c_int,
    #[cfg(target_endian = "little")]
    __pad1: ::c_int,
    pub msg_control: *mut ::c_void,
    #[cfg(target_endian = "big")]
    __pad2: ::c_int,
    pub msg_controllen: ::socklen_t,
    #[cfg(target_endian = "little")]
    __pad2: ::c_int,
    pub msg_flags: ::c_int,
}

The padding fields are necessary due to memory layout, however they are also private, which in conjunction with the lack of constructor means it is impossible to construct a msghdr without resorting to unsafe code. On the other hand the padding guarantees that [0; size_of::<msghdr>()] is a valid representation, which is why I resorted to MaybeUninit::zeroed as unsafe constructor.

In addition struct update syntax (msghdr {..MaybeUninit::zeroed()}) sadly does not work with private fields, so I had to resort to first constructing a zeroed msghdr and then updating the individual fields.

@gdox gdox changed the title Added support for compilation with musl without libfuse present Bugfixed support for compilation with musl without libfuse present Nov 4, 2021
@cberner
Copy link
Owner

cberner commented Nov 6, 2021

Lgtm, but can you run cargo fmt and amend your commit to fix the CI?

@cberner cberner merged commit a222fc1 into cberner:master Nov 11, 2021
@cberner
Copy link
Owner

cberner commented Nov 11, 2021

Merged. Thanks!

@messense
Copy link
Contributor

messense commented Jan 6, 2022

Can we have a new release with this please?

@cberner
Copy link
Owner

cberner commented Jan 7, 2022

Yep. Just released 0.10.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants