Skip to content

Commit

Permalink
linux: Add open_how and related flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanael committed Nov 4, 2021
1 parent 072d6de commit 93e85a3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
s! {
// linux/openat2.h
#[non_exhaustive]
pub struct open_how {
pub flags: ::__u64,
pub mode: ::__u64,
pub resolve: ::__u64,
}
}

0 comments on commit 93e85a3

Please sign in to comment.