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

linux: Add open_how and related flags #2477

Merged
merged 1 commit into from Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.rs
Expand Up @@ -72,6 +72,11 @@ fn main() {
println!("cargo:rustc-cfg=libc_cfg_target_vendor");
}

// Rust >= 1.40 supports #[non_exhaustive].
if rustc_minor_ver >= 40 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_non_exhaustive");
}

if rustc_minor_ver >= 51 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_ptr_addr_of");
}
Expand Down
13 changes: 13 additions & 0 deletions libc-test/build.rs
Expand Up @@ -2653,6 +2653,8 @@ fn test_linux(target: &str) {
"linux/netfilter_ipv6.h",
"linux/netfilter_ipv6/ip6_tables.h",
"linux/netlink.h",
// FIXME: requires more recent kernel headers:
// "linux/openat2.h",
"linux/quota.h",
"linux/random.h",
"linux/reboot.h",
Expand Down Expand Up @@ -2794,6 +2796,9 @@ fn test_linux(target: &str) {
// Requires glibc 2.33 or newer.
"mallinfo2" => true,

// Might differ between kernel versions
"open_how" => true,

_ => false,
}
});
Expand Down Expand Up @@ -2932,6 +2937,14 @@ fn test_linux(target: &str) {
| "CLOSE_RANGE_UNSHARE"
| "CLOSE_RANGE_CLOEXEC" => true,

// FIXME: requires more recent kernel headers:
| "RESOLVE_BENEATH"
| "RESOLVE_CACHED"
| "RESOLVE_IN_ROOT"
| "RESOLVE_NO_MAGICLINKS"
| "RESOLVE_NO_SYMLINKS"
| "RESOLVE_NO_XDEV" => true,

// FIXME: Not currently available in headers on ARM, MIPS and musl.
"NETLINK_GET_STRICT_CHK" if arm || mips || musl => true,

Expand Down
7 changes: 7 additions & 0 deletions libc-test/semver/linux.txt
Expand Up @@ -1752,6 +1752,12 @@ RENAME_NOREPLACE
RENAME_WHITEOUT
REP_CNT
REP_MAX
RESOLVE_BENEATH
RESOLVE_CACHED
RESOLVE_IN_ROOT
RESOLVE_NO_MAGICLINKS
RESOLVE_NO_SYMLINKS
RESOLVE_NO_XDEV
RLIMIT_AS
RLIMIT_CORE
RLIMIT_CPU
Expand Down Expand Up @@ -2849,6 +2855,7 @@ nlmsgerr
nlmsghdr
off64_t
open64
open_how
open_memstream
openat
openat64
Expand Down
15 changes: 15 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Expand Up @@ -1824,6 +1824,14 @@ pub const MFD_HUGETLB: ::c_uint = 0x0004;
pub const CLOSE_RANGE_UNSHARE: ::c_uint = 1 << 1;
pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2;

// linux/openat2.h
pub const RESOLVE_NO_XDEV: ::__u64 = 0x01;
pub const RESOLVE_NO_MAGICLINKS: ::__u64 = 0x02;
pub const RESOLVE_NO_SYMLINKS: ::__u64 = 0x04;
pub const RESOLVE_BENEATH: ::__u64 = 0x08;
pub const RESOLVE_IN_ROOT: ::__u64 = 0x10;
pub const RESOLVE_CACHED: ::__u64 = 0x20;

// these are used in the p_type field of Elf32_Phdr and Elf64_Phdr, which has
// the type Elf32Word and Elf64Word respectively. Luckily, both of those are u32
// so we can use that type here to avoid having to cast.
Expand Down Expand Up @@ -3942,3 +3950,10 @@ cfg_if! {
}
}
expand_align!();

cfg_if! {
if #[cfg(libc_non_exhaustive)] {
mod non_exhaustive;
pub use self::non_exhaustive::*;
}
}
9 changes: 9 additions & 0 deletions src/unix/linux_like/linux/non_exhaustive.rs
@@ -0,0 +1,9 @@
s! {
// linux/openat2.h
#[non_exhaustive]
pub struct open_how {
pub flags: ::__u64,
pub mode: ::__u64,
pub resolve: ::__u64,
}
}