Skip to content

Commit 93e85a3

Browse files
committed
linux: Add open_how and related flags
1 parent 072d6de commit 93e85a3

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ fn main() {
7272
println!("cargo:rustc-cfg=libc_cfg_target_vendor");
7373
}
7474

75+
// Rust >= 1.40 supports #[non_exhaustive].
76+
if rustc_minor_ver >= 40 || rustc_dep_of_std {
77+
println!("cargo:rustc-cfg=libc_non_exhaustive");
78+
}
79+
7580
if rustc_minor_ver >= 51 || rustc_dep_of_std {
7681
println!("cargo:rustc-cfg=libc_ptr_addr_of");
7782
}

libc-test/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2653,6 +2653,8 @@ fn test_linux(target: &str) {
26532653
"linux/netfilter_ipv6.h",
26542654
"linux/netfilter_ipv6/ip6_tables.h",
26552655
"linux/netlink.h",
2656+
// FIXME: requires more recent kernel headers:
2657+
// "linux/openat2.h",
26562658
"linux/quota.h",
26572659
"linux/random.h",
26582660
"linux/reboot.h",
@@ -2794,6 +2796,9 @@ fn test_linux(target: &str) {
27942796
// Requires glibc 2.33 or newer.
27952797
"mallinfo2" => true,
27962798

2799+
// Might differ between kernel versions
2800+
"open_how" => true,
2801+
27972802
_ => false,
27982803
}
27992804
});
@@ -2932,6 +2937,14 @@ fn test_linux(target: &str) {
29322937
| "CLOSE_RANGE_UNSHARE"
29332938
| "CLOSE_RANGE_CLOEXEC" => true,
29342939

2940+
// FIXME: requires more recent kernel headers:
2941+
| "RESOLVE_BENEATH"
2942+
| "RESOLVE_CACHED"
2943+
| "RESOLVE_IN_ROOT"
2944+
| "RESOLVE_NO_MAGICLINKS"
2945+
| "RESOLVE_NO_SYMLINKS"
2946+
| "RESOLVE_NO_XDEV" => true,
2947+
29352948
// FIXME: Not currently available in headers on ARM, MIPS and musl.
29362949
"NETLINK_GET_STRICT_CHK" if arm || mips || musl => true,
29372950

libc-test/semver/linux.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,12 @@ RENAME_NOREPLACE
17521752
RENAME_WHITEOUT
17531753
REP_CNT
17541754
REP_MAX
1755+
RESOLVE_BENEATH
1756+
RESOLVE_CACHED
1757+
RESOLVE_IN_ROOT
1758+
RESOLVE_NO_MAGICLINKS
1759+
RESOLVE_NO_SYMLINKS
1760+
RESOLVE_NO_XDEV
17551761
RLIMIT_AS
17561762
RLIMIT_CORE
17571763
RLIMIT_CPU
@@ -2849,6 +2855,7 @@ nlmsgerr
28492855
nlmsghdr
28502856
off64_t
28512857
open64
2858+
open_how
28522859
open_memstream
28532860
openat
28542861
openat64

src/unix/linux_like/linux/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,14 @@ pub const MFD_HUGETLB: ::c_uint = 0x0004;
18241824
pub const CLOSE_RANGE_UNSHARE: ::c_uint = 1 << 1;
18251825
pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2;
18261826

1827+
// linux/openat2.h
1828+
pub const RESOLVE_NO_XDEV: ::__u64 = 0x01;
1829+
pub const RESOLVE_NO_MAGICLINKS: ::__u64 = 0x02;
1830+
pub const RESOLVE_NO_SYMLINKS: ::__u64 = 0x04;
1831+
pub const RESOLVE_BENEATH: ::__u64 = 0x08;
1832+
pub const RESOLVE_IN_ROOT: ::__u64 = 0x10;
1833+
pub const RESOLVE_CACHED: ::__u64 = 0x20;
1834+
18271835
// these are used in the p_type field of Elf32_Phdr and Elf64_Phdr, which has
18281836
// the type Elf32Word and Elf64Word respectively. Luckily, both of those are u32
18291837
// so we can use that type here to avoid having to cast.
@@ -3942,3 +3950,10 @@ cfg_if! {
39423950
}
39433951
}
39443952
expand_align!();
3953+
3954+
cfg_if! {
3955+
if #[cfg(libc_non_exhaustive)] {
3956+
mod non_exhaustive;
3957+
pub use self::non_exhaustive::*;
3958+
}
3959+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
s! {
2+
// linux/openat2.h
3+
#[non_exhaustive]
4+
pub struct open_how {
5+
pub flags: ::__u64,
6+
pub mode: ::__u64,
7+
pub resolve: ::__u64,
8+
}
9+
}

0 commit comments

Comments
 (0)