Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

rustix

Package Overview
Dependencies
Maintainers
1
Versions
169
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rustix - npm Package Compare versions

Package version was removed
This package version has been unpublished, mostly likely due to security reasons
Comparing version
1.0.8
to
1.1.0
+1
-1
.cargo_vcs_info.json
{
"git": {
"sha1": "5b104ec6c0fd8855b341d6a2c8edf72843ad6cee"
"sha1": "0b695d2a2549242904e27ebfd659ac99c066a14c"
},
"path_in_vcs": ""
}

@@ -38,2 +38,6 @@ use std::env::var;

// Check for `RUSTFLAGS=--cfg=rustix_no_linux_raw`. This allows Linux users to
// enable the libc backend without the linux raw dependency.
let cfg_no_linux_raw = var("CARGO_CFG_RUSTIX_NO_LINUX_RAW").is_ok();
// Check for `--features=rustc-dep-of-std`.

@@ -83,2 +87,11 @@ let rustc_dep_of_std = var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();

// `LowerExp`/`UpperExp` for `NonZeroI32` etc.
if has_lower_upper_exp_for_non_zero() {
use_feature("lower_upper_exp_for_non_zero");
}
if can_compile("#[diagnostic::on_unimplemented()] trait Foo {}") {
use_feature("rustc_diagnostics")
}
// WASI support can utilize wasi_ext if present.

@@ -108,2 +121,6 @@ if os == "wasi" {

if libc {
if os != "android" && os == "linux" && !cfg_no_linux_raw {
use_feature("linux_raw_dep");
}
// Use the libc backend.

@@ -113,2 +130,3 @@ use_feature("libc");

// Use the linux_raw backend.
use_feature("linux_raw_dep");
use_feature("linux_raw");

@@ -195,2 +213,8 @@ if rustix_use_experimental_asm {

fn has_lower_upper_exp_for_non_zero() -> bool {
// LowerExp/UpperExp for NonZero* were added in Rust 1.84.
// <https://doc.rust-lang.org/stable/std/fmt/trait.LowerExp.html#impl-LowerExp-for-NonZero%3CT%3E>
can_compile("fn a(x: &core::num::NonZeroI32, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { core::fmt::LowerExp::fmt(x, f) }")
}
fn use_feature_or_nothing(feature: &str) {

@@ -242,3 +266,3 @@ if has_feature(feature) {

.arg("-o")
.arg("-")
.arg(std::env::temp_dir().join("rustix_test_can_compile"))
.stdout(Stdio::null()); // We don't care about the output (only whether it builds or not)

@@ -245,0 +269,0 @@

@@ -61,5 +61,5 @@ # This file is automatically @generated by Cargo.

name = "bumpalo"
version = "3.18.1"
version = "3.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee"
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"

@@ -74,5 +74,5 @@ [[package]]

name = "cfg-if"
version = "1.0.1"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"

@@ -135,5 +135,5 @@ [[package]]

name = "crc32fast"
version = "1.4.2"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
dependencies = [

@@ -206,5 +206,5 @@ "cfg-if",

name = "crunchy"
version = "0.2.3"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929"
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"

@@ -237,3 +237,3 @@ [[package]]

"libc",
"windows-sys 0.60.2",
"windows-sys",
]

@@ -404,5 +404,5 @@

name = "js-sys"
version = "0.3.77"
version = "0.3.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
checksum = "0c0b063578492ceec17683ef2f8c5e89121fbd0b172cbc280635ab7567db2738"
dependencies = [

@@ -421,5 +421,5 @@ "once_cell",

name = "libc"
version = "0.2.174"
version = "0.2.175"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"

@@ -437,2 +437,11 @@ [[package]]

[[package]]
name = "linux-raw-sys"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
dependencies = [
"rustc-std-workspace-core",
]
[[package]]
name = "lock_api"

@@ -449,5 +458,5 @@ version = "0.4.13"

name = "log"
version = "0.4.27"
version = "0.4.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"

@@ -570,5 +579,5 @@ [[package]]

name = "proc-macro2"
version = "1.0.95"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
dependencies = [

@@ -595,5 +604,5 @@ "unicode-ident",

name = "rayon"
version = "1.10.0"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f"
dependencies = [

@@ -606,5 +615,5 @@ "either",

name = "rayon-core"
version = "1.12.1"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
dependencies = [

@@ -617,5 +626,5 @@ "crossbeam-deque",

name = "redox_syscall"
version = "0.5.13"
version = "0.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77"
dependencies = [

@@ -627,5 +636,5 @@ "bitflags 2.9.1",

name = "regex"
version = "1.11.1"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912"
dependencies = [

@@ -640,5 +649,5 @@ "aho-corasick",

name = "regex-automata"
version = "0.4.9"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6"
dependencies = [

@@ -652,5 +661,5 @@ "aho-corasick",

name = "regex-syntax"
version = "0.8.5"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001"

@@ -671,5 +680,5 @@ [[package]]

name = "rustix"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"
dependencies = [

@@ -679,4 +688,4 @@ "bitflags 2.9.1",

"libc",
"linux-raw-sys",
"windows-sys 0.59.0",
"linux-raw-sys 0.9.4",
"windows-sys",
]

@@ -686,3 +695,3 @@

name = "rustix"
version = "1.0.8"
version = "1.1.0"
dependencies = [

@@ -694,3 +703,4 @@ "bitflags 2.9.1",

"libc",
"linux-raw-sys",
"linux-raw-sys 0.11.0",
"linux-raw-sys 0.9.4",
"memoffset",

@@ -703,3 +713,3 @@ "once_cell",

"tempfile",
"windows-sys 0.59.0",
"windows-sys",
]

@@ -709,5 +719,5 @@

name = "rustversion"
version = "1.0.21"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"

@@ -757,5 +767,5 @@ [[package]]

name = "serde_json"
version = "1.0.140"
version = "1.0.143"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a"
dependencies = [

@@ -795,5 +805,5 @@ "itoa",

name = "slab"
version = "0.4.10"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d"
checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589"

@@ -814,5 +824,5 @@ [[package]]

name = "syn"
version = "2.0.103"
version = "2.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8"
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
dependencies = [

@@ -826,5 +836,5 @@ "proc-macro2",

name = "tempfile"
version = "3.20.0"
version = "3.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1"
checksum = "15b61f8f20e3a6f7e0649d825294eaf317edce30f82cf6026e7e4cb9222a7d1e"
dependencies = [

@@ -834,4 +844,4 @@ "fastrand",

"once_cell",
"rustix 1.0.7",
"windows-sys 0.59.0",
"rustix 1.0.8",
"windows-sys",
]

@@ -873,7 +883,7 @@

name = "wasi"
version = "0.14.2+wasi-0.2.4"
version = "0.14.4+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
checksum = "88a5f4a424faf49c3c2c344f166f0662341d470ea185e939657aaff130f0ec4a"
dependencies = [
"wit-bindgen-rt",
"wit-bindgen",
]

@@ -883,5 +893,5 @@

name = "wasm-bindgen"
version = "0.2.100"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
checksum = "7e14915cadd45b529bb8d1f343c4ed0ac1de926144b746e2710f9cd05df6603b"
dependencies = [

@@ -892,2 +902,3 @@ "cfg-if",

"wasm-bindgen-macro",
"wasm-bindgen-shared",
]

@@ -897,5 +908,5 @@

name = "wasm-bindgen-backend"
version = "0.2.100"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
checksum = "e28d1ba982ca7923fd01448d5c30c6864d0a14109560296a162f80f305fb93bb"
dependencies = [

@@ -912,5 +923,5 @@ "bumpalo",

name = "wasm-bindgen-macro"
version = "0.2.100"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
checksum = "7c3d463ae3eff775b0c45df9da45d68837702ac35af998361e2c84e7c5ec1b0d"
dependencies = [

@@ -923,5 +934,5 @@ "quote",

name = "wasm-bindgen-macro-support"
version = "0.2.100"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
checksum = "7bb4ce89b08211f923caf51d527662b75bdc9c9c7aab40f86dcb9fb85ac552aa"
dependencies = [

@@ -937,5 +948,5 @@ "proc-macro2",

name = "wasm-bindgen-shared"
version = "0.2.100"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
checksum = "f143854a3b13752c6950862c906306adb27c7e839f7414cec8fea35beab624c1"
dependencies = [

@@ -947,5 +958,5 @@ "unicode-ident",

name = "web-sys"
version = "0.3.77"
version = "0.3.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2"
checksum = "77e4b637749ff0d92b8fad63aa1f7cff3cbe125fd49c175cd6345e7272638b12"
dependencies = [

@@ -974,7 +985,7 @@ "js-sys",

name = "winapi-util"
version = "0.1.9"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys 0.59.0",
"windows-sys",
]

@@ -989,9 +1000,6 @@

[[package]]
name = "windows-sys"
version = "0.59.0"
name = "windows-link"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets 0.52.6",
]
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"

@@ -1004,3 +1012,3 @@ [[package]]

dependencies = [
"windows-targets 0.53.2",
"windows-targets 0.53.3",
]

@@ -1026,6 +1034,7 @@

name = "windows-targets"
version = "0.53.2"
version = "0.53.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef"
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
dependencies = [
"windows-link",
"windows_aarch64_gnullvm 0.53.0",

@@ -1138,8 +1147,5 @@ "windows_aarch64_msvc 0.53.0",

[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
name = "wit-bindgen"
version = "0.45.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags 2.9.1",
]
checksum = "5c573471f125075647d03df72e026074b7203790d41351cd6edc96f46bcccd36"

@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO

name = "rustix"
version = "1.0.8"
version = "1.1.0"
authors = [

@@ -176,3 +176,3 @@ "Dan Gohman <dev@sunfishcode.online>",

[dev-dependencies.libc]
version = "0.2.168"
version = "0.2.171"

@@ -196,3 +196,3 @@ [dev-dependencies.libc_errno]

[target.'cfg(all(any(target_os = "android", target_os = "linux"), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies.linux-raw-sys]
[target.'cfg(all(any(target_os = "linux"), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies.linux-raw-sys]
version = "0.9.2"

@@ -210,3 +210,3 @@ features = [

[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies.libc]
version = "0.2.168"
version = "0.2.171"
optional = true

@@ -222,4 +222,5 @@ default-features = false

[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies.linux-raw-sys]
version = "0.9.2"
version = "0.11.0"
features = [
"auxvec",
"general",

@@ -234,3 +235,3 @@ "errno",

[target.'cfg(all(not(windows), any(rustix_use_libc, miri, not(all(target_os = "linux", any(target_endian = "little", any(target_arch = "s390x", target_arch = "powerpc")), any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc"), all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "s390x"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64")))))))'.dependencies.libc]
version = "0.2.168"
version = "0.2.171"
default-features = false

@@ -249,3 +250,3 @@

[target."cfg(windows)".dependencies.windows-sys]
version = ">=0.52, <0.61"
version = ">=0.52, <0.62"
features = [

@@ -280,4 +281,7 @@ "Win32_Foundation",

"cfg(linux_raw)",
"cfg(linux_raw_dep)",
"cfg(lower_upper_exp_for_non_zero)",
"cfg(netbsdlike)",
"cfg(rustc_attrs)",
"cfg(rustc_diagnostics)",
"cfg(solarish)",

@@ -284,0 +288,0 @@ "cfg(staged_api)",

@@ -22,46 +22,48 @@ //! Libc and supplemental types and constants.

// TODO: Upstream these.
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_TSN: c_int = linux_raw_sys::if_ether::ETH_P_TSN as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_ERSPAN2: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN2 as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_ERSPAN: c_int = linux_raw_sys::if_ether::ETH_P_ERSPAN as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_PROFINET: c_int = linux_raw_sys::if_ether::ETH_P_PROFINET as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_REALTEK: c_int = linux_raw_sys::if_ether::ETH_P_REALTEK as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_ETHERCAT: c_int = linux_raw_sys::if_ether::ETH_P_ETHERCAT as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_PREAUTH: c_int = linux_raw_sys::if_ether::ETH_P_PREAUTH as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_LLDP: c_int = linux_raw_sys::if_ether::ETH_P_LLDP as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_MRP: c_int = linux_raw_sys::if_ether::ETH_P_MRP as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_NCSI: c_int = linux_raw_sys::if_ether::ETH_P_NCSI as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_CFM: c_int = linux_raw_sys::if_ether::ETH_P_CFM as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_IBOE: c_int = linux_raw_sys::if_ether::ETH_P_IBOE as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_HSR: c_int = linux_raw_sys::if_ether::ETH_P_HSR as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_NSH: c_int = linux_raw_sys::if_ether::ETH_P_NSH as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_DSA_8021Q: c_int = linux_raw_sys::if_ether::ETH_P_DSA_8021Q as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_DSA_A5PSW: c_int = linux_raw_sys::if_ether::ETH_P_DSA_A5PSW as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_IFE: c_int = linux_raw_sys::if_ether::ETH_P_IFE as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_CAN: c_int = linux_raw_sys::if_ether::ETH_P_CAN as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_CANXL: c_int = linux_raw_sys::if_ether::ETH_P_CANXL as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_XDSA: c_int = linux_raw_sys::if_ether::ETH_P_XDSA as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_MAP: c_int = linux_raw_sys::if_ether::ETH_P_MAP as _;
#[cfg(all(linux_kernel, feature = "net"))]
#[cfg(all(linux_raw_dep, feature = "net"))]
pub(crate) const ETH_P_MCTP: c_int = linux_raw_sys::if_ether::ETH_P_MCTP as _;
#[cfg(all(linux_kernel, feature = "mount"))]
pub(crate) const MS_NOSYMFOLLOW: c_ulong = linux_raw_sys::general::MS_NOSYMFOLLOW as _;

@@ -93,3 +95,3 @@ #[cfg(all(

// so libc implementations may leave it undefined or defined to zero.
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
pub(crate) const O_LARGEFILE: c_int = linux_raw_sys::general::O_LARGEFILE as _;

@@ -494,3 +496,8 @@

linux_like,
not(any(target_os = "android", target_os = "emscripten", target_env = "gnu"))
linux_raw_dep,
not(any(
target_os = "emscripten",
target_env = "gnu",
all(target_arch = "loongarch64", target_env = "musl")
))
))]

@@ -513,3 +520,8 @@ mod statx_flags {

linux_like,
not(any(target_os = "android", target_os = "emscripten", target_env = "gnu"))
linux_raw_dep,
not(any(
target_os = "emscripten",
target_env = "gnu",
all(target_arch = "loongarch64", target_env = "musl")
))
))]

@@ -522,6 +534,56 @@ pub(crate) use statx_flags::*;

#[cfg(feature = "mm")]
#[cfg(target_os = "android")]
pub(crate) const MAP_DROPPABLE: c_int = bitcast!(linux_raw_sys::general::MAP_DROPPABLE);
// FreeBSD added `timerfd_*` in FreeBSD 14. NetBSD added then in NetBSD 10.
#[cfg(all(feature = "time", any(target_os = "freebsd", target_os = "netbsd")))]
syscall!(pub(crate) fn timerfd_create(
clockid: c_int,
flags: c_int
) via SYS_timerfd_create -> c_int);
#[cfg(all(feature = "time", any(target_os = "freebsd", target_os = "netbsd")))]
syscall!(pub(crate) fn timerfd_gettime(
fd: c_int,
curr_value: *mut itimerspec
) via SYS_timerfd_gettime -> c_int);
#[cfg(all(feature = "time", any(target_os = "freebsd", target_os = "netbsd")))]
syscall!(pub(crate) fn timerfd_settime(
fd: c_int,
flags: c_int,
new_value: *const itimerspec,
old_value: *mut itimerspec
) via SYS_timerfd_settime -> c_int);
#[cfg(all(feature = "time", target_os = "illumos"))]
extern "C" {
pub(crate) fn timerfd_create(clockid: c_int, flags: c_int) -> c_int;
pub(crate) fn timerfd_gettime(fd: c_int, curr_value: *mut itimerspec) -> c_int;
pub(crate) fn timerfd_settime(
fd: c_int,
flags: c_int,
new_value: *const itimerspec,
old_value: *mut itimerspec,
) -> c_int;
}
// illumos and NetBSD timerfd support.
// Submitted upstream in <https://github.com/rust-lang/libc/pull/4333>.
// <https://code.illumos.org/plugins/gitiles/illumos-gate/+/refs/heads/master/usr/src/uts/common/sys/timerfd.h#34>
#[cfg(all(feature = "time", target_os = "illumos"))]
pub(crate) const TFD_CLOEXEC: i32 = 0o2000000;
#[cfg(all(feature = "time", target_os = "illumos"))]
pub(crate) const TFD_NONBLOCK: i32 = 0o4000;
#[cfg(all(feature = "time", target_os = "illumos"))]
pub(crate) const TFD_TIMER_ABSTIME: i32 = 1 << 0;
#[cfg(all(feature = "time", target_os = "illumos"))]
pub(crate) const TFD_TIMER_CANCEL_ON_SET: i32 = 1 << 1;
// <https://nxr.netbsd.org/xref/src/sys/sys/timerfd.h#44>
#[cfg(all(feature = "time", target_os = "netbsd"))]
pub(crate) const TFD_CLOEXEC: i32 = O_CLOEXEC;
#[cfg(all(feature = "time", target_os = "netbsd"))]
pub(crate) const TFD_NONBLOCK: i32 = O_NONBLOCK;
#[cfg(all(feature = "time", target_os = "netbsd"))]
pub(crate) const TFD_TIMER_ABSTIME: i32 = O_WRONLY;
#[cfg(all(feature = "time", target_os = "netbsd"))]
pub(crate) const TFD_TIMER_CANCEL_ON_SET: i32 = O_RDWR;
#[cfg(test)]

@@ -528,0 +590,0 @@ mod tests {

@@ -27,9 +27,3 @@ #[cfg(not(any(

use crate::fs::{fstatfs, StatFs};
#[cfg(not(any(
solarish,
target_os = "haiku",
target_os = "redox",
target_os = "vita",
target_os = "wasi"
)))]
#[cfg(not(any(solarish, target_os = "vita", target_os = "wasi")))]
use crate::fs::{fstatvfs, StatVfs};

@@ -247,5 +241,3 @@ use crate::io;

solarish,
target_os = "haiku",
target_os = "horizon",
target_os = "redox",
target_os = "vita",

@@ -252,0 +244,0 @@ target_os = "wasi"

@@ -19,7 +19,10 @@ #[cfg(all(feature = "alloc", not(any(target_os = "espidf", target_os = "redox"))))]

// TODO: Fix linux-raw-sys to define ioctl codes for sparc.
#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))]
#[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))]
pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode = 0x8008_6610;
#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))]
#[cfg(all(
linux_raw_dep,
not(any(target_arch = "sparc", target_arch = "sparc64"))
))]
pub(crate) const EXT4_IOC_RESIZE_FS: crate::ioctl::Opcode =
linux_raw_sys::ioctl::EXT4_IOC_RESIZE_FS as crate::ioctl::Opcode;

@@ -739,2 +739,5 @@ use crate::backend::c;

const FUTURE_WRITE = bitcast!(c::F_SEAL_FUTURE_WRITE);
/// `F_SEAL_EXEC` (since Linux 6.3)
#[cfg(linux_kernel)]
const EXEC = bitcast!(c::F_SEAL_EXEC);

@@ -846,3 +849,3 @@ /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>

#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[cfg(not(target_os = "wasi"))]
bitflags! {

@@ -879,7 +882,7 @@ /// `ST_*` constants for use with [`StatVfs`].

/// `ST_NOSUID`
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))]
#[cfg(not(any(target_os = "espidf", target_os = "haiku", target_os = "horizon", target_os = "redox", target_os = "vita")))]
const NOSUID = c::ST_NOSUID as u64;
/// `ST_RDONLY`
#[cfg(not(any(target_os = "espidf", target_os = "horizon", target_os = "vita")))]
#[cfg(not(any(target_os = "espidf", target_os = "haiku", target_os = "horizon", target_os = "redox", target_os = "vita")))]
const RDONLY = c::ST_RDONLY as u64;

@@ -1080,3 +1083,3 @@

/// [`fstatvfs`]: crate::fs::fstatvfs
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[cfg(not(target_os = "wasi"))]
#[allow(missing_docs)]

@@ -1083,0 +1086,0 @@ pub struct StatVfs {

@@ -16,3 +16,3 @@ //! libc syscalls supporting `rustix::io`.

use crate::io::DupFlags;
#[cfg(linux_kernel)]
#[cfg(all(linux_kernel, not(target_os = "android")))]
use crate::io::ReadWriteFlags;

@@ -154,3 +154,3 @@ use crate::io::{self, FdFlags};

#[cfg(linux_kernel)]
#[cfg(all(linux_kernel, not(target_os = "android")))]
pub(crate) fn preadv2(

@@ -175,3 +175,3 @@ fd: BorrowedFd<'_>,

#[cfg(linux_kernel)]
#[cfg(all(linux_kernel, not(target_os = "android")))]
pub(crate) fn pwritev2(

@@ -178,0 +178,0 @@ fd: BorrowedFd<'_>,

@@ -20,3 +20,3 @@ use crate::backend::c;

#[cfg(linux_kernel)]
#[cfg(all(linux_kernel, not(target_os = "android")))]
bitflags! {

@@ -31,11 +31,11 @@ /// `RWF_*` constants for use with [`preadv2`] and [`pwritev2`].

/// `RWF_DSYNC` (since Linux 4.7)
const DSYNC = linux_raw_sys::general::RWF_DSYNC;
const DSYNC = libc::RWF_DSYNC as u32;
/// `RWF_HIPRI` (since Linux 4.6)
const HIPRI = linux_raw_sys::general::RWF_HIPRI;
const HIPRI = libc::RWF_HIPRI as u32;
/// `RWF_SYNC` (since Linux 4.7)
const SYNC = linux_raw_sys::general::RWF_SYNC;
const SYNC = libc::RWF_SYNC as u32;
/// `RWF_NOWAIT` (since Linux 4.14)
const NOWAIT = linux_raw_sys::general::RWF_NOWAIT;
const NOWAIT = libc::RWF_NOWAIT as u32;
/// `RWF_APPEND` (since Linux 4.16)
const APPEND = linux_raw_sys::general::RWF_APPEND;
const APPEND = libc::RWF_APPEND as u32;

@@ -42,0 +42,0 @@ /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>

@@ -47,15 +47,15 @@ use crate::backend::c;

/// `PROT_SEM`
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
const SEM = linux_raw_sys::general::PROT_SEM;
/// `PROT_BTI`
#[cfg(all(linux_kernel, target_arch = "aarch64"))]
#[cfg(all(linux_raw_dep, target_arch = "aarch64"))]
const BTI = linux_raw_sys::general::PROT_BTI;
/// `PROT_MTE`
#[cfg(all(linux_kernel, target_arch = "aarch64"))]
#[cfg(all(linux_raw_dep, target_arch = "aarch64"))]
const MTE = linux_raw_sys::general::PROT_MTE;
/// `PROT_SAO`
#[cfg(all(linux_kernel, any(target_arch = "powerpc", target_arch = "powerpc64")))]
#[cfg(all(linux_raw_dep, any(target_arch = "powerpc", target_arch = "powerpc64")))]
const SAO = linux_raw_sys::general::PROT_SAO;
/// `PROT_ADI`
#[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))]
#[cfg(all(linux_raw_dep, any(target_arch = "sparc", target_arch = "sparc64")))]
const ADI = linux_raw_sys::general::PROT_ADI;

@@ -256,3 +256,3 @@

/// `MAP_DROPPABLE`
#[cfg(linux_kernel)]
#[cfg(all(linux_kernel, not(target_os = "android")))]
const DROPPABLE = bitcast!(c::MAP_DROPPABLE);

@@ -259,0 +259,0 @@

@@ -59,2 +59,5 @@ use crate::backend::c;

/// `MS_NOSYMFOLLOW`
const NOSYMFOLLOW = c::MS_NOSYMFOLLOW;
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>

@@ -61,0 +64,0 @@ const _ = !0;

@@ -5,4 +5,2 @@ //! Wrappers for netdevice ioctls.

#[cfg(feature = "alloc")]
use crate::alloc::string::String;
use crate::backend::c;

@@ -12,5 +10,3 @@ use crate::backend::io::syscalls::ioctl;

use crate::io;
#[cfg(feature = "alloc")]
use c::SIOCGIFNAME;
use c::{__c_anonymous_ifr_ifru, c_char, ifreq, IFNAMSIZ, SIOCGIFINDEX};
use c::{__c_anonymous_ifr_ifru, c_char, ifreq, IFNAMSIZ, SIOCGIFINDEX, SIOCGIFNAME};

@@ -36,4 +32,3 @@ pub(crate) fn name_to_index(fd: BorrowedFd<'_>, if_name: &str) -> io::Result<u32> {

#[cfg(feature = "alloc")]
pub(crate) fn index_to_name(fd: BorrowedFd<'_>, index: u32) -> io::Result<String> {
pub(crate) fn index_to_name(fd: BorrowedFd<'_>, index: u32) -> io::Result<(usize, [u8; 16])> {
let mut ifreq = ifreq {

@@ -49,8 +44,8 @@ ifr_name: [0; 16],

if let Some(nul_byte) = ifreq.ifr_name.iter().position(|char| *char == 0) {
let name: String = ifreq.ifr_name[..nul_byte]
.iter()
.map(|v| *v as u8 as char)
.collect();
let mut buf = [0u8; 16];
ifreq.ifr_name.iter().enumerate().for_each(|(idx, c)| {
buf[idx] = *c as u8;
});
Ok(name)
Ok((nul_byte, buf))
} else {

@@ -57,0 +52,0 @@ Err(io::Errno::INVAL)

@@ -17,2 +17,4 @@ //! libc syscalls supporting `rustix::net::sockopt`.

use crate::net::sockopt::Timeout;
#[cfg(linux_kernel)]
use crate::net::sockopt::{Ipv4PathMtuDiscovery, Ipv6PathMtuDiscovery};
#[cfg(target_os = "linux")]

@@ -54,5 +56,9 @@ use crate::net::xdp::{XdpMmapOffsets, XdpOptionsFlags, XdpRingOffset, XdpStatistics, XdpUmemReg};

use crate::net::SocketAddrV4;
#[cfg(all(target_os = "linux", feature = "time"))]
use crate::net::TxTimeFlags;
use crate::net::{Ipv4Addr, Ipv6Addr, SocketType};
#[cfg(linux_kernel)]
use crate::net::{SocketAddrV6, UCred};
#[cfg(all(target_os = "linux", feature = "time"))]
use crate::time::ClockId;
use crate::utils::as_mut_ptr;

@@ -81,3 +87,3 @@ #[cfg(feature = "alloc")]

use core::time::Duration;
#[cfg(target_os = "linux")]
#[cfg(linux_raw_dep)]
use linux_raw_sys::xdp::{xdp_mmap_offsets, xdp_statistics, xdp_statistics_v1};

@@ -506,3 +512,33 @@

#[cfg(linux_kernel)]
#[inline]
pub(crate) fn set_ip_mtu_discover(
fd: BorrowedFd<'_>,
value: Ipv4PathMtuDiscovery,
) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IP, c::IP_MTU_DISCOVER, value)
}
#[cfg(linux_kernel)]
#[inline]
pub(crate) fn ip_mtu_discover(fd: BorrowedFd<'_>) -> io::Result<Ipv4PathMtuDiscovery> {
getsockopt(fd, c::IPPROTO_IP, c::IP_MTU_DISCOVER)
}
#[cfg(linux_kernel)]
#[inline]
pub(crate) fn set_ipv6_mtu_discover(
fd: BorrowedFd<'_>,
value: Ipv6PathMtuDiscovery,
) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_MTU_DISCOVER, value)
}
#[cfg(linux_kernel)]
#[inline]
pub(crate) fn ipv6_mtu_discover(fd: BorrowedFd<'_>) -> io::Result<Ipv6PathMtuDiscovery> {
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_MTU_DISCOVER)
}
#[inline]
pub(crate) fn set_ip_multicast_if(fd: BorrowedFd<'_>, value: &Ipv4Addr) -> io::Result<()> {

@@ -1065,2 +1101,31 @@ setsockopt(fd, c::IPPROTO_IP, c::IP_MULTICAST_IF, to_imr_addr(value))

#[cfg(all(target_os = "linux", feature = "time"))]
#[inline]
pub(crate) fn set_txtime(
fd: BorrowedFd<'_>,
clockid: ClockId,
flags: TxTimeFlags,
) -> io::Result<()> {
setsockopt(
fd,
c::SOL_SOCKET,
c::SO_TXTIME,
c::sock_txtime {
clockid: clockid as _,
flags: flags.bits(),
},
)
}
#[cfg(all(target_os = "linux", feature = "time"))]
#[inline]
pub(crate) fn get_txtime(fd: BorrowedFd<'_>) -> io::Result<(ClockId, TxTimeFlags)> {
let txtime: c::sock_txtime = getsockopt(fd, c::SOL_SOCKET, c::SO_TXTIME)?;
Ok((
txtime.clockid.try_into().map_err(|_| io::Errno::RANGE)?,
TxTimeFlags::from_bits(txtime.flags).ok_or(io::Errno::RANGE)?,
))
}
#[cfg(target_os = "linux")]

@@ -1096,3 +1161,3 @@ #[inline]

#[cfg(target_os = "linux")]
#[cfg(linux_raw_dep)]
#[inline]

@@ -1184,3 +1249,3 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets> {

#[cfg(target_os = "linux")]
#[cfg(linux_raw_dep)]
#[inline]

@@ -1187,0 +1252,0 @@ pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {

@@ -496,3 +496,16 @@ //! libc syscalls supporting `rustix::termios`.

pub(crate) fn cfmakeraw(termios: &mut Termios) {
unsafe { c::cfmakeraw(as_mut_ptr(termios).cast()) }
unsafe {
// On AIX, cfmakeraw() has a return type of 'int' instead of 'void'.
// If the argument 'termios' is NULL, it returns -1; otherwise, it returns 0.
// We believe it is safe to ignore the return value.
#[cfg(target_os = "aix")]
{
let _ = c::cfmakeraw(as_mut_ptr(termios).cast());
}
#[cfg(not(target_os = "aix"))]
{
c::cfmakeraw(as_mut_ptr(termios).cast());
}
}
}

@@ -499,0 +512,0 @@

@@ -401,5 +401,5 @@ //! libc syscalls supporting `rustix::thread`.

pub(crate) fn setresuid_thread(
ruid: crate::ugid::Uid,
euid: crate::ugid::Uid,
suid: crate::ugid::Uid,
ruid: Option<crate::ugid::Uid>,
euid: Option<crate::ugid::Uid>,
suid: Option<crate::ugid::Uid>,
) -> io::Result<()> {

@@ -415,3 +415,9 @@ #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))]

unsafe { ret(setresuid(ruid.as_raw(), euid.as_raw(), suid.as_raw())) }
unsafe {
ret(setresuid(
ruid.map_or(-1_i32 as u32, |x| x.as_raw()),
euid.map_or(-1_i32 as u32, |x| x.as_raw()),
suid.map_or(-1_i32 as u32, |x| x.as_raw()),
))
}
}

@@ -432,5 +438,5 @@

pub(crate) fn setresgid_thread(
rgid: crate::ugid::Gid,
egid: crate::ugid::Gid,
sgid: crate::ugid::Gid,
rgid: Option<crate::ugid::Gid>,
egid: Option<crate::ugid::Gid>,
sgid: Option<crate::ugid::Gid>,
) -> io::Result<()> {

@@ -446,3 +452,9 @@ #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))]

unsafe { ret(setresgid(rgid.as_raw(), egid.as_raw(), sgid.as_raw())) }
unsafe {
ret(setresgid(
rgid.map_or(-1_i32 as u32, |x| x.as_raw()),
egid.map_or(-1_i32 as u32, |x| x.as_raw()),
sgid.map_or(-1_i32 as u32, |x| x.as_raw()),
))
}
}

@@ -449,0 +461,0 @@

@@ -5,3 +5,9 @@ //! libc syscalls supporting `rustix::time`.

use crate::backend::conv::ret;
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(any(all(target_env = "gnu", fix_y2038), not(fix_y2038)))]

@@ -25,3 +31,9 @@ use crate::backend::time::types::LibcItimerspec;

use core::mem::MaybeUninit;
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
use {

@@ -39,6 +51,6 @@ crate::backend::conv::{borrowed_fd, ret_owned_fd},

weak!(fn __clock_getres64(c::clockid_t, *mut LibcTimespec) -> c::c_int);
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "fuchsia"))]
#[cfg(all(target_env = "gnu", fix_y2038))]
weak!(fn __timerfd_gettime64(c::c_int, *mut LibcItimerspec) -> c::c_int);
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "fuchsia"))]
#[cfg(all(target_env = "gnu", fix_y2038))]

@@ -178,3 +190,3 @@ weak!(fn __timerfd_settime64(c::c_int, c::c_int, *const LibcItimerspec, *mut LibcItimerspec) -> c::c_int);

#[cfg(linux_kernel)]
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
DynamicClockId::RealtimeAlarm => c::CLOCK_REALTIME_ALARM,

@@ -305,3 +317,9 @@

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
pub(crate) fn timerfd_create(id: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> {

@@ -311,3 +329,9 @@ unsafe { ret_owned_fd(c::timerfd_create(id as c::clockid_t, bitflags_bits!(flags))) }

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
pub(crate) fn timerfd_settime(

@@ -354,3 +378,9 @@ fd: BorrowedFd<'_>,

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(fix_y2038)]

@@ -422,3 +452,9 @@ fn timerfd_settime_old(

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> {

@@ -454,3 +490,9 @@ // Old 32-bit version: libc has `timerfd_gettime` but it is not y2038 safe

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(fix_y2038)]

@@ -457,0 +499,0 @@ fn timerfd_gettime_old(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> {

@@ -1,13 +0,43 @@

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
use crate::backend::c;
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
use crate::time::Itimerspec;
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(fix_y2038)]
use crate::timespec::LibcTimespec;
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
use bitflags::bitflags;
/// On most platforms, `LibcItimerspec` is just `Itimerspec`.
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(not(fix_y2038))]

@@ -18,3 +48,9 @@ pub(crate) type LibcItimerspec = Itimerspec;

/// define our own struct, with bidirectional `From` impls.
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(fix_y2038)]

@@ -28,3 +64,9 @@ #[repr(C)]

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(fix_y2038)]

@@ -41,3 +83,9 @@ impl From<LibcItimerspec> for Itimerspec {

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(fix_y2038)]

@@ -54,3 +102,9 @@ impl From<Itimerspec> for LibcItimerspec {

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(not(fix_y2038))]

@@ -65,3 +119,9 @@ pub(crate) fn as_libc_itimerspec_ptr(itimerspec: &Itimerspec) -> *const c::itimerspec {

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[cfg(not(fix_y2038))]

@@ -78,3 +138,9 @@ pub(crate) fn as_libc_itimerspec_mut_ptr(

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
bitflags! {

@@ -100,3 +166,9 @@ /// `TFD_*` flags for use with [`timerfd_create`].

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
bitflags! {

@@ -114,3 +186,3 @@ /// `TFD_TIMER_*` flags for use with [`timerfd_settime`].

/// `TFD_TIMER_CANCEL_ON_SET`
#[cfg(linux_kernel)]
#[cfg(not(target_os = "fuchsia"))]
#[doc(alias = "TFD_TIMER_CANCEL_ON_SET")]

@@ -127,3 +199,9 @@ const CANCEL_ON_SET = bitcast!(c::TFD_TIMER_CANCEL_ON_SET);

/// [`timerfd_create`]: crate::time::timerfd_create
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]

@@ -158,2 +236,3 @@ #[repr(u32)]

#[doc(alias = "CLOCK_BOOTTIME")]
#[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "openbsd"))]
Boottime = bitcast!(c::CLOCK_BOOTTIME),

@@ -166,2 +245,3 @@

/// Use of this clock requires the `CAP_WAKE_ALARM` Linux capability.
#[cfg(linux_kernel)]
#[doc(alias = "CLOCK_REALTIME_ALARM")]

@@ -175,2 +255,3 @@ RealtimeAlarm = bitcast!(c::CLOCK_REALTIME_ALARM),

/// Use of this clock requires the `CAP_WAKE_ALARM` Linux capability.
#[cfg(any(linux_kernel, target_os = "cygwin", target_os = "fuchsia"))]
#[doc(alias = "CLOCK_BOOTTIME_ALARM")]

@@ -185,3 +266,9 @@ BoottimeAlarm = bitcast!(c::CLOCK_BOOTTIME_ALARM),

#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
#[test]

@@ -188,0 +275,0 @@ fn test_types() {

@@ -13,3 +13,3 @@ //! Adapt the Linux API to resemble a POSIX-style libc API.

pub(crate) use linux_raw_sys::general::{__kernel_fd_set as fd_set, __FD_SETSIZE as FD_SETSIZE};
pub(crate) use linux_raw_sys::ioctl::{FIONBIO, FIONREAD};
pub(crate) use linux_raw_sys::ioctl::{FIOCLEX, FIONBIO, FIONCLEX, FIONREAD};
// Import the kernel's `uid_t` and `gid_t` if they're 32-bit.

@@ -88,10 +88,13 @@ #[cfg(feature = "thread")]

AF_LLC, AF_NETBEUI, AF_NETLINK, AF_NETROM, AF_PACKET, AF_PHONET, AF_PPPOX, AF_RDS, AF_ROSE,
AF_RXRPC, AF_SECURITY, AF_SNA, AF_TIPC, AF_UNIX, AF_UNSPEC, AF_WANPIPE, AF_X25, AF_XDP,
IP6T_SO_ORIGINAL_DST, IPPROTO_FRAGMENT, IPPROTO_ICMPV6, IPPROTO_MH, IPPROTO_ROUTING,
IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_FREEBIND, IPV6_MULTICAST_HOPS,
IPV6_MULTICAST_LOOP, IPV6_RECVTCLASS, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_V6ONLY,
IP_ADD_MEMBERSHIP, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
IP_FREEBIND, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_RECVTOS, IP_TOS, IP_TTL,
MSG_CMSG_CLOEXEC, MSG_CONFIRM, MSG_CTRUNC, MSG_DONTROUTE, MSG_DONTWAIT, MSG_EOR,
MSG_ERRQUEUE, MSG_MORE, MSG_NOSIGNAL, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL,
AF_RXRPC, AF_SECURITY, AF_SNA, AF_TIPC, AF_UNIX, AF_UNSPEC, AF_VSOCK, AF_WANPIPE, AF_X25,
AF_XDP, IP6T_SO_ORIGINAL_DST, IPPROTO_FRAGMENT, IPPROTO_ICMPV6, IPPROTO_MH,
IPPROTO_ROUTING, IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_FREEBIND,
IPV6_MULTICAST_HOPS, IPV6_MULTICAST_LOOP, IPV6_PMTUDISC_DO, IPV6_PMTUDISC_DONT,
IPV6_PMTUDISC_INTERFACE, IPV6_PMTUDISC_OMIT, IPV6_PMTUDISC_PROBE, IPV6_PMTUDISC_WANT,
IPV6_RECVTCLASS, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP,
IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP, IP_FREEBIND,
IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_PMTUDISC_DO, IP_PMTUDISC_DONT,
IP_PMTUDISC_INTERFACE, IP_PMTUDISC_OMIT, IP_PMTUDISC_PROBE, IP_PMTUDISC_WANT, IP_RECVTOS,
IP_TOS, IP_TTL, MSG_CMSG_CLOEXEC, MSG_CONFIRM, MSG_CTRUNC, MSG_DONTROUTE, MSG_DONTWAIT,
MSG_EOR, MSG_ERRQUEUE, MSG_MORE, MSG_NOSIGNAL, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL,
SCM_CREDENTIALS, SCM_RIGHTS, SHUT_RD, SHUT_RDWR, SHUT_WR, SOCK_DGRAM, SOCK_RAW, SOCK_RDM,

@@ -119,2 +122,15 @@ SOCK_SEQPACKET, SOCK_STREAM, SOL_SOCKET, SOL_XDP, SO_ACCEPTCONN, SO_BROADCAST, SO_COOKIE,

#[cfg(feature = "time")]
pub use linux_raw_sys::general::__kernel_clockid_t as clockid_t;
#[cfg(all(feature = "net", feature = "time"))]
pub use linux_raw_sys::net::{sock_txtime, SCM_TXTIME, SO_TXTIME};
#[cfg(all(feature = "net", feature = "time"))]
pub(crate) const SOF_TXTIME_DEADLINE_MODE: u32 =
linux_raw_sys::net::txtime_flags::SOF_TXTIME_DEADLINE_MODE as _;
#[cfg(all(feature = "net", feature = "time"))]
pub(crate) const SOF_TXTIME_REPORT_ERRORS: u32 =
linux_raw_sys::net::txtime_flags::SOF_TXTIME_REPORT_ERRORS as _;
// Cast away bindgen's `enum` type to make these consistent with the other

@@ -121,0 +137,0 @@ // `setsockopt`/`getsockopt` level values.

@@ -845,2 +845,10 @@ //! Convert values to [`ArgReg`] and from [`RetReg`].

#[cfg(feature = "thread")]
impl<'a, Num: ArgNumber> From<Option<crate::ugid::Uid>> for ArgReg<'a, Num> {
#[inline]
fn from(t: Option<crate::ugid::Uid>) -> Self {
c_uint(t.map_or(-1_i32 as u32, |x| x.as_raw()))
}
}
#[cfg(any(feature = "process", feature = "thread"))]

@@ -854,2 +862,10 @@ impl<'a, Num: ArgNumber> From<crate::ugid::Gid> for ArgReg<'a, Num> {

#[cfg(feature = "thread")]
impl<'a, Num: ArgNumber> From<Option<crate::ugid::Gid>> for ArgReg<'a, Num> {
#[inline]
fn from(t: Option<crate::ugid::Gid>) -> Self {
c_uint(t.map_or(-1_i32 as u32, |x| x.as_raw()))
}
}
#[cfg(feature = "runtime")]

@@ -856,0 +872,0 @@ impl<'a, Num: ArgNumber> From<crate::runtime::How> for ArgReg<'a, Num> {

@@ -499,2 +499,4 @@ use crate::ffi;

const FUTURE_WRITE = linux_raw_sys::general::F_SEAL_FUTURE_WRITE;
/// `F_SEAL_EXEC` (since Linux 6.3)
const EXEC = linux_raw_sys::general::F_SEAL_EXEC;

@@ -501,0 +503,0 @@ /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>

@@ -11,8 +11,4 @@ //! Wrappers for netdevice ioctls.

use linux_raw_sys::ctypes::c_char;
use linux_raw_sys::ioctl::SIOCGIFINDEX;
#[cfg(feature = "alloc")]
use linux_raw_sys::ioctl::SIOCGIFNAME;
use linux_raw_sys::ioctl::{SIOCGIFINDEX, SIOCGIFNAME};
use linux_raw_sys::net::{ifreq, ifreq__bindgen_ty_1, ifreq__bindgen_ty_2, IFNAMSIZ};
#[cfg(feature = "alloc")]
use {alloc::borrow::ToOwned, alloc::string::String};

@@ -44,4 +40,3 @@ pub(crate) fn name_to_index(fd: BorrowedFd<'_>, if_name: &str) -> io::Result<u32> {

#[cfg(feature = "alloc")]
pub(crate) fn index_to_name(fd: BorrowedFd<'_>, index: u32) -> io::Result<String> {
pub(crate) fn index_to_name(fd: BorrowedFd<'_>, index: u32) -> io::Result<(usize, [u8; 16])> {
let mut ifreq = ifreq {

@@ -66,5 +61,6 @@ ifr_ifrn: ifreq__bindgen_ty_1 { ifrn_name: [0; 16] },

str::from_utf8(ifrn_name)
.map_err(|_| io::Errno::ILSEQ)
.map(ToOwned::to_owned)
let mut name_buf = [0; 16];
name_buf[..ifrn_name.len()].copy_from_slice(ifrn_name);
Ok((nul_byte, name_buf))
} else {

@@ -71,0 +67,0 @@ Err(io::Errno::INVAL)

@@ -10,2 +10,4 @@ //! linux_raw syscalls supporting `rustix::net::sockopt`.

use crate::backend::conv::{by_mut, c_uint, ret, socklen_t};
#[cfg(all(target_os = "linux", feature = "time"))]
use crate::clockid::ClockId;
use crate::fd::BorrowedFd;

@@ -15,5 +17,7 @@ #[cfg(feature = "alloc")]

use crate::io;
use crate::net::sockopt::Timeout;
use crate::net::sockopt::{Ipv4PathMtuDiscovery, Ipv6PathMtuDiscovery, Timeout};
#[cfg(target_os = "linux")]
use crate::net::xdp::{XdpMmapOffsets, XdpOptionsFlags, XdpRingOffset, XdpStatistics, XdpUmemReg};
#[cfg(all(target_os = "linux", feature = "time"))]
use crate::net::TxTimeFlags;
use crate::net::{

@@ -30,3 +34,5 @@ AddressFamily, Ipv4Addr, Ipv6Addr, Protocol, RawProtocol, SocketAddrBuf, SocketAddrV4,

use linux_raw_sys::general::{__kernel_old_timeval, __kernel_sock_timeval};
use linux_raw_sys::net::{IPV6_MTU, IPV6_MULTICAST_IF, IP_MTU, IP_MULTICAST_IF};
use linux_raw_sys::net::{
IPV6_MTU, IPV6_MTU_DISCOVER, IPV6_MULTICAST_IF, IP_MTU, IP_MTU_DISCOVER, IP_MULTICAST_IF,
};
#[cfg(target_os = "linux")]

@@ -469,2 +475,28 @@ use linux_raw_sys::xdp::{xdp_mmap_offsets, xdp_statistics, xdp_statistics_v1};

#[inline]
pub(crate) fn set_ip_mtu_discover(
fd: BorrowedFd<'_>,
value: Ipv4PathMtuDiscovery,
) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IP, IP_MTU_DISCOVER, value)
}
#[inline]
pub(crate) fn ip_mtu_discover(fd: BorrowedFd<'_>) -> io::Result<Ipv4PathMtuDiscovery> {
getsockopt(fd, c::IPPROTO_IP, IP_MTU_DISCOVER)
}
#[inline]
pub(crate) fn set_ipv6_mtu_discover(
fd: BorrowedFd<'_>,
value: Ipv6PathMtuDiscovery,
) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IPV6, IPV6_MTU_DISCOVER, value)
}
#[inline]
pub(crate) fn ipv6_mtu_discover(fd: BorrowedFd<'_>) -> io::Result<Ipv6PathMtuDiscovery> {
getsockopt(fd, c::IPPROTO_IPV6, IPV6_MTU_DISCOVER)
}
#[inline]
pub(crate) fn set_ip_multicast_if_with_ifindex(

@@ -855,2 +887,31 @@ fd: BorrowedFd<'_>,

#[cfg(all(target_os = "linux", feature = "time"))]
#[inline]
pub(crate) fn set_txtime(
fd: BorrowedFd<'_>,
clockid: ClockId,
flags: TxTimeFlags,
) -> io::Result<()> {
setsockopt(
fd,
c::SOL_SOCKET,
c::SO_TXTIME,
c::sock_txtime {
clockid: clockid as _,
flags: flags.bits(),
},
)
}
#[cfg(all(target_os = "linux", feature = "time"))]
#[inline]
pub(crate) fn get_txtime(fd: BorrowedFd<'_>) -> io::Result<(ClockId, TxTimeFlags)> {
let txtime: c::sock_txtime = getsockopt(fd, c::SOL_SOCKET, c::SO_TXTIME)?;
Ok((
txtime.clockid.try_into().map_err(|_| io::Errno::RANGE)?,
TxTimeFlags::from_bits(txtime.flags).ok_or(io::Errno::RANGE)?,
))
}
#[cfg(target_os = "linux")]

@@ -857,0 +918,0 @@ #[inline]

@@ -23,10 +23,10 @@ //! Linux auxv support.

use core::sync::atomic::{AtomicPtr, AtomicUsize};
use linux_raw_sys::elf::*;
use linux_raw_sys::general::{
use linux_raw_sys::auxvec::{
AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_MINSIGSTKSZ, AT_NULL, AT_PAGESZ, AT_SYSINFO_EHDR,
};
#[cfg(feature = "runtime")]
use linux_raw_sys::general::{
use linux_raw_sys::auxvec::{
AT_EGID, AT_ENTRY, AT_EUID, AT_GID, AT_PHDR, AT_PHENT, AT_PHNUM, AT_RANDOM, AT_SECURE, AT_UID,
};
use linux_raw_sys::elf::*;
#[cfg(feature = "alloc")]

@@ -33,0 +33,0 @@ use {alloc::borrow::Cow, alloc::vec};

@@ -16,8 +16,8 @@ //! Linux auxv `init` function, for "use-explicitly-provided-auxv" mode.

use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering};
use linux_raw_sys::elf::*;
use linux_raw_sys::general::{
use linux_raw_sys::auxvec::{
AT_CLKTCK, AT_EXECFN, AT_HWCAP, AT_HWCAP2, AT_MINSIGSTKSZ, AT_NULL, AT_PAGESZ, AT_SYSINFO_EHDR,
};
#[cfg(feature = "runtime")]
use linux_raw_sys::general::{AT_ENTRY, AT_PHDR, AT_PHENT, AT_PHNUM, AT_RANDOM, AT_SECURE};
use linux_raw_sys::auxvec::{AT_ENTRY, AT_PHDR, AT_PHENT, AT_PHNUM, AT_RANDOM, AT_SECURE};
use linux_raw_sys::elf::*;

@@ -24,0 +24,0 @@ #[cfg(feature = "param")]

@@ -408,5 +408,5 @@ //! linux_raw syscalls supporting `rustix::thread`.

pub(crate) fn setresuid_thread(
ruid: crate::ugid::Uid,
euid: crate::ugid::Uid,
suid: crate::ugid::Uid,
ruid: Option<crate::ugid::Uid>,
euid: Option<crate::ugid::Uid>,
suid: Option<crate::ugid::Uid>,
) -> io::Result<()> {

@@ -430,5 +430,5 @@ #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))]

pub(crate) fn setresgid_thread(
rgid: crate::ugid::Gid,
egid: crate::ugid::Gid,
sgid: crate::ugid::Gid,
rgid: Option<crate::ugid::Gid>,
egid: Option<crate::ugid::Gid>,
sgid: Option<crate::ugid::Gid>,
) -> io::Result<()> {

@@ -435,0 +435,0 @@ #[cfg(any(target_arch = "x86", target_arch = "arm", target_arch = "sparc"))]

@@ -97,2 +97,11 @@ //! Utilities for functions that return data via buffers.

/// that. See `error_retry_closure_uninit` in examples/buffer_errors.rs.
#[cfg_attr(
rustc_diagnostics,
diagnostic::on_unimplemented(
message = "rustix does not accept `{Self}` buffers",
label = "Unsupported buffer type",
note = "only (potentially uninitialized) byte arrays, slices, and Vecs are supported",
note = "please read the docs: https://docs.rs/rustix/latest/rustix/buffer/trait.Buffer.html"
)
)]
pub trait Buffer<T>: private::Sealed<T> {}

@@ -99,0 +108,0 @@

use crate::backend::c;
use crate::fd::BorrowedFd;
use crate::io;

@@ -100,2 +101,47 @@ /// `CLOCK_*` constants for use with [`clock_gettime`].

#[cfg(not(any(apple, target_os = "wasi")))]
impl TryFrom<c::clockid_t> for ClockId {
type Error = io::Errno;
fn try_from(value: c::clockid_t) -> Result<Self, Self::Error> {
match value {
c::CLOCK_REALTIME => Ok(ClockId::Realtime),
c::CLOCK_MONOTONIC => Ok(ClockId::Monotonic),
#[cfg(any(freebsdlike, target_os = "openbsd"))]
c::CLOCK_UPTIME => Ok(ClockId::Uptime),
#[cfg(not(any(
solarish,
target_os = "horizon",
target_os = "netbsd",
target_os = "redox",
target_os = "vita"
)))]
c::CLOCK_PROCESS_CPUTIME_ID => Ok(ClockId::ProcessCPUTime),
#[cfg(not(any(
solarish,
target_os = "horizon",
target_os = "netbsd",
target_os = "redox",
target_os = "vita"
)))]
c::CLOCK_THREAD_CPUTIME_ID => Ok(ClockId::ThreadCPUTime),
#[cfg(any(linux_kernel, target_os = "freebsd"))]
c::CLOCK_REALTIME_COARSE => Ok(ClockId::RealtimeCoarse),
#[cfg(any(linux_kernel, target_os = "freebsd"))]
c::CLOCK_MONOTONIC_COARSE => Ok(ClockId::MonotonicCoarse),
#[cfg(linux_kernel)]
c::CLOCK_MONOTONIC_RAW => Ok(ClockId::MonotonicRaw),
#[cfg(linux_kernel)]
c::CLOCK_REALTIME_ALARM => Ok(ClockId::RealtimeAlarm),
#[cfg(all(linux_kernel, feature = "linux_4_11"))]
c::CLOCK_TAI => Ok(ClockId::Tai),
#[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "openbsd"))]
c::CLOCK_BOOTTIME => Ok(ClockId::Boottime),
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
c::CLOCK_BOOTTIME_ALARM => Ok(ClockId::BoottimeAlarm),
_ => Err(io::Errno::RANGE),
}
}
}
/// `CLOCK_*` constants for use with [`clock_gettime`].

@@ -131,2 +177,17 @@ ///

#[cfg(apple)]
impl TryFrom<c::clockid_t> for ClockId {
type Error = io::Errno;
fn try_from(value: c::clockid_t) -> Result<Self, Self::Error> {
match value {
c::CLOCK_REALTIME => Ok(ClockId::Realtime),
c::CLOCK_MONOTONIC => Ok(ClockId::Monotonic),
c::CLOCK_PROCESS_CPUTIME_ID => Ok(ClockId::ProcessCPUTime),
c::CLOCK_THREAD_CPUTIME_ID => Ok(ClockId::ThreadCPUTime),
_ => Err(io::Errno::RANGE),
}
}
}
/// `CLOCK_*` constants for use with [`clock_gettime_dynamic`].

@@ -150,3 +211,3 @@ ///

/// `CLOCK_REALTIME_ALARM`
#[cfg(linux_kernel)]
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[doc(alias = "CLOCK_REALTIME_ALARM")]

@@ -153,0 +214,0 @@ RealtimeAlarm,

@@ -18,3 +18,3 @@ //! POSIX-style filesystem functions which operate on bare paths.

use crate::fs::StatFs;
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "haiku", target_os = "wasi")))]
use crate::fs::StatVfs;

@@ -287,3 +287,3 @@ use crate::fs::{Mode, OFlags, Stat};

/// [Linux]: https://man7.org/linux/man-pages/man2/statvfs.2.html
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "haiku", target_os = "wasi")))]
#[inline]

@@ -290,0 +290,0 @@ pub fn statvfs<P: path::Arg>(path: P) -> io::Result<StatVfs> {

@@ -472,2 +472,20 @@ //! POSIX-style `*at` functions.

/// `mkfifoat(dirfd, path, mode)`—Make a FIFO special file.
///
/// # References
/// - [POSIX]
///
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/mkfifoat.html
#[cfg(not(any(
apple,
target_os = "espidf",
target_os = "horizon",
target_os = "vita",
target_os = "wasi"
)))]
#[inline]
pub fn mkfifoat<P: path::Arg, Fd: AsFd>(dirfd: Fd, path: P, mode: Mode) -> io::Result<()> {
mknodat(dirfd, path, FileType::Fifo, mode, 0)
}
/// `fchownat(dirfd, path, owner, group, flags)`—Sets file or directory

@@ -474,0 +492,0 @@ /// ownership.

@@ -59,3 +59,3 @@ //! Filesystem API constants, translated into `bitflags` constants.

fn test_layouts() {
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
assert_eq_size!(FsWord, linux_raw_sys::general::__fsword_t);

@@ -65,3 +65,3 @@

// `u16`.
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
#[cfg(not(any(

@@ -75,3 +75,3 @@ target_arch = "x86",

#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
#[cfg(any(

@@ -353,4 +353,8 @@ target_arch = "x86",

#[cfg(linux_raw)]
check_renamed_struct_field!(Statx, statx, __spare1);
check_renamed_struct_field!(Statx, statx, stx_dio_read_offset_align);
#[cfg(linux_raw)]
check_renamed_struct_field!(Statx, statx, stx_atomic_write_unit_max_opt);
#[cfg(linux_raw)]
check_renamed_struct_field!(Statx, statx, __spare2);
#[cfg(linux_raw)]
check_renamed_struct_field!(Statx, statx, __spare3);

@@ -357,0 +361,0 @@ }

@@ -43,3 +43,3 @@ //! Functions which operate on file descriptors.

use backend::fs::types::StatFs;
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[cfg(not(target_os = "wasi"))]
use backend::fs::types::StatVfs;

@@ -200,3 +200,3 @@

/// [Linux]: https://man7.org/linux/man-pages/man2/fstatvfs.2.html
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
#[cfg(not(target_os = "wasi"))]
#[inline]

@@ -203,0 +203,0 @@ pub fn fstatvfs<Fd: AsFd>(fd: Fd) -> io::Result<StatVfs> {

@@ -61,3 +61,3 @@ //! Filesystem-oriented `ioctl` functions.

/// `ioctl(fd, EXT4_IOC_RESIZE_FS, blocks)`—Resize ext4 filesystem on fd.
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
#[inline]

@@ -98,3 +98,3 @@ #[doc(alias = "EXT4_IOC_RESIZE_FS")]

#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
bitflags! {

@@ -141,3 +141,3 @@ /// `FS_*` constants for use with [`ioctl_getflags`].

/// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
#[inline]

@@ -159,3 +159,3 @@ #[doc(alias = "FS_IOC_GETFLAGS")]

/// [inode flags]: https://man7.org/linux/man-pages/man2/ioctl_iflags.2.html
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
#[inline]

@@ -162,0 +162,0 @@ #[doc(alias = "FS_IOC_SETFLAGS")]

@@ -33,3 +33,3 @@ //! Filesystem operations.

mod id;
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
pub mod inotify;

@@ -49,3 +49,3 @@ #[cfg(linux_kernel)]

mod memfd_create;
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
mod openat2;

@@ -115,3 +115,3 @@ #[cfg(linux_kernel)]

pub use memfd_create::memfd_create;
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
pub use openat2::openat2;

@@ -118,0 +118,0 @@ #[cfg(linux_kernel)]

@@ -10,2 +10,6 @@ //! `RawDir` and `RawDirEntry`.

use core::mem::{align_of, MaybeUninit};
#[cfg(not(linux_raw_dep))]
use libc::dirent64 as linux_dirent64;
#[cfg(linux_raw_dep)]
use linux_raw_sys::general::linux_dirent64;

@@ -12,0 +16,0 @@

@@ -47,4 +47,6 @@ //! Linux `statx`.

pub stx_atomic_write_segments_max: u32,
pub(crate) __spare1: [u32; 1],
pub(crate) __spare3: [u64; 9],
pub stx_dio_read_offset_align: u32,
pub stx_atomic_write_unit_max_opt: u32,
pub __spare2: [u32; 1usize],
pub __spare3: [u64; 8usize],
}

@@ -51,0 +53,0 @@

@@ -19,3 +19,6 @@ //! The Unix `ioctl` function is effectively lots of different functions hidden

/// clearing any other flags that might be set.
#[cfg(apple)]
///
/// Linux: Note that `ioctl` can not be used on `OFlags::PATH` file
/// descriptors.
#[cfg(any(apple, linux_kernel))]
#[inline]

@@ -32,2 +35,20 @@ #[doc(alias = "FIOCLEX")]

/// `ioctl(fd, FIONCLEX, NULL)`—Remove the close-on-exec flag.
///
/// This is similar to `fcntl_setfd(fd, FdFlags::empty())`, except that it avoids
/// clearing any other flags that might be set.
///
/// Linux: Note that `ioctl` can not be used on `OFlags::PATH` file
/// descriptors.
#[cfg(any(apple, linux_kernel))]
#[inline]
#[doc(alias = "FIONCLEX")]
pub fn ioctl_fionclex<Fd: AsFd>(fd: Fd) -> io::Result<()> {
// SAFETY: `FIONCLEX` is a no-argument setter opcode.
unsafe {
let ctl = ioctl::NoArg::<{ c::FIONCLEX }>::new();
ioctl::ioctl(fd, ctl)
}
}
/// `ioctl(fd, FIONBIO, &value)`—Enables or disables non-blocking mode.

@@ -34,0 +55,0 @@ ///

@@ -13,3 +13,3 @@ //! `read` and `write`, optionally positioned, optionally vectored.

#[cfg(linux_kernel)]
#[cfg(all(linux_kernel, not(target_os = "android")))]
pub use backend::io::types::ReadWriteFlags;

@@ -281,3 +281,3 @@

/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Scatter_002dGather.html#index-preadv64v2
#[cfg(linux_kernel)]
#[cfg(all(linux_kernel, not(target_os = "android")))]
#[inline]

@@ -303,3 +303,3 @@ pub fn preadv2<Fd: AsFd>(

/// [glibc]: https://sourceware.org/glibc/manual/latest/html_node/Scatter_002dGather.html#index-pwritev64v2
#[cfg(linux_kernel)]
#[cfg(all(linux_kernel, not(target_os = "android")))]
#[inline]

@@ -306,0 +306,0 @@ pub fn pwritev2<Fd: AsFd>(

@@ -91,3 +91,3 @@ //! `ioctl` opcode behavior for Linux platforms.

#[cfg(not(any(
#[cfg(all(linux_raw_dep, not(any(
// These have no ioctl opcodes defined in linux_raw_sys so we can't use

@@ -97,3 +97,3 @@ // that as a known-good value for this test.

target_arch = "sparc64"
)))]
))))]
#[test]

@@ -100,0 +100,0 @@ fn check_known_opcodes() {

@@ -347,3 +347,3 @@ //! Unsafe `ioctl` API.

#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
#[cfg(not(any(target_arch = "sparc", target_arch = "sparc64")))]

@@ -350,0 +350,0 @@ #[cfg(test)]

@@ -6,3 +6,3 @@ //! `fsopen` and related functions in Linux's `mount` API.

};
use crate::fd::{BorrowedFd, OwnedFd};
use crate::fd::{AsFd, OwnedFd};
use crate::{backend, io, path};

@@ -28,8 +28,8 @@

#[inline]
pub fn fsmount(
fs_fd: BorrowedFd<'_>,
pub fn fsmount<Fd: AsFd>(
fs_fd: Fd,
flags: FsMountFlags,
attr_flags: MountAttrFlags,
) -> io::Result<OwnedFd> {
backend::mount::syscalls::fsmount(fs_fd, flags, attr_flags)
backend::mount::syscalls::fsmount(fs_fd.as_fd(), flags, attr_flags)
}

@@ -48,9 +48,11 @@

#[inline]
pub fn move_mount<From: path::Arg, To: path::Arg>(
from_dfd: BorrowedFd<'_>,
pub fn move_mount<From: path::Arg, To: path::Arg, FromFd: AsFd, ToFd: AsFd>(
from_dfd: FromFd,
from_pathname: From,
to_dfd: BorrowedFd<'_>,
to_dfd: ToFd,
to_pathname: To,
flags: MoveMountFlags,
) -> io::Result<()> {
let from_dfd = from_dfd.as_fd();
let to_dfd = to_dfd.as_fd();
from_pathname.into_with_c_str(|from_pathname| {

@@ -76,7 +78,8 @@ to_pathname.into_with_c_str(|to_pathname| {

#[inline]
pub fn open_tree<Path: path::Arg>(
dfd: BorrowedFd<'_>,
pub fn open_tree<Path: path::Arg, Fd: AsFd>(
dfd: Fd,
filename: Path,
flags: OpenTreeFlags,
) -> io::Result<OwnedFd> {
let dfd = dfd.as_fd();
filename.into_with_c_str(|filename| backend::mount::syscalls::open_tree(dfd, filename, flags))

@@ -92,7 +95,8 @@ }

#[inline]
pub fn fspick<Path: path::Arg>(
dfd: BorrowedFd<'_>,
pub fn fspick<Path: path::Arg, Fd: AsFd>(
dfd: Fd,
path: Path,
flags: FsPickFlags,
) -> io::Result<OwnedFd> {
let dfd = dfd.as_fd();
path.into_with_c_str(|path| backend::mount::syscalls::fspick(dfd, path, flags))

@@ -109,3 +113,4 @@ }

#[doc(alias = "fsconfig")]
pub fn fsconfig_set_flag<Key: path::Arg>(fs_fd: BorrowedFd<'_>, key: Key) -> io::Result<()> {
pub fn fsconfig_set_flag<Key: path::Arg, Fd: AsFd>(fs_fd: Fd, key: Key) -> io::Result<()> {
let fs_fd = fs_fd.as_fd();
key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_flag(fs_fd, key))

@@ -122,7 +127,8 @@ }

#[doc(alias = "fsconfig")]
pub fn fsconfig_set_string<Key: path::Arg, Value: path::Arg>(
fs_fd: BorrowedFd<'_>,
pub fn fsconfig_set_string<Key: path::Arg, Value: path::Arg, Fd: AsFd>(
fs_fd: Fd,
key: Key,
value: Value,
) -> io::Result<()> {
let fs_fd = fs_fd.as_fd();
key.into_with_c_str(|key| {

@@ -143,7 +149,8 @@ value.into_with_c_str(|value| {

#[doc(alias = "fsconfig")]
pub fn fsconfig_set_binary<Key: path::Arg>(
fs_fd: BorrowedFd<'_>,
pub fn fsconfig_set_binary<Key: path::Arg, Fd: AsFd>(
fs_fd: Fd,
key: Key,
value: &[u8],
) -> io::Result<()> {
let fs_fd = fs_fd.as_fd();
key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_binary(fs_fd, key, value))

@@ -160,8 +167,10 @@ }

#[doc(alias = "fsconfig")]
pub fn fsconfig_set_path<Key: path::Arg, Path: path::Arg>(
fs_fd: BorrowedFd<'_>,
pub fn fsconfig_set_path<Key: path::Arg, Path: path::Arg, Fd: AsFd, AuxFd: AsFd>(
fs_fd: Fd,
key: Key,
path: Path,
fd: BorrowedFd<'_>,
fd: AuxFd,
) -> io::Result<()> {
let fs_fd = fs_fd.as_fd();
let fd = fd.as_fd();
key.into_with_c_str(|key| {

@@ -182,7 +191,9 @@ path.into_with_c_str(|path| {

#[doc(alias = "fsconfig")]
pub fn fsconfig_set_path_empty<Key: path::Arg>(
fs_fd: BorrowedFd<'_>,
pub fn fsconfig_set_path_empty<Key: path::Arg, Fd: AsFd, AuxFd: AsFd>(
fs_fd: Fd,
key: Key,
fd: BorrowedFd<'_>,
fd: AuxFd,
) -> io::Result<()> {
let fs_fd = fs_fd.as_fd();
let fd = fd.as_fd();
key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_path_empty(fs_fd, key, fd))

@@ -199,7 +210,9 @@ }

#[doc(alias = "fsconfig")]
pub fn fsconfig_set_fd<Key: path::Arg>(
fs_fd: BorrowedFd<'_>,
pub fn fsconfig_set_fd<Key: path::Arg, Fd: AsFd, AuxFd: AsFd>(
fs_fd: Fd,
key: Key,
fd: BorrowedFd<'_>,
fd: AuxFd,
) -> io::Result<()> {
let fs_fd = fs_fd.as_fd();
let fd = fd.as_fd();
key.into_with_c_str(|key| backend::mount::syscalls::fsconfig_set_fd(fs_fd, key, fd))

@@ -216,4 +229,4 @@ }

#[doc(alias = "fsconfig")]
pub fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
backend::mount::syscalls::fsconfig_create(fs_fd)
pub fn fsconfig_create<Fd: AsFd>(fs_fd: Fd) -> io::Result<()> {
backend::mount::syscalls::fsconfig_create(fs_fd.as_fd())
}

@@ -229,4 +242,4 @@

#[doc(alias = "fsconfig")]
pub fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
backend::mount::syscalls::fsconfig_reconfigure(fs_fd)
pub fn fsconfig_reconfigure<Fd: AsFd>(fs_fd: Fd) -> io::Result<()> {
backend::mount::syscalls::fsconfig_reconfigure(fs_fd.as_fd())
}

@@ -244,4 +257,4 @@

#[doc(alias = "fsconfig")]
pub fn fsconfig_create_exclusive(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
backend::mount::syscalls::fsconfig_create_excl(fs_fd)
pub fn fsconfig_create_exclusive<Fd: AsFd>(fs_fd: Fd) -> io::Result<()> {
backend::mount::syscalls::fsconfig_create_excl(fs_fd.as_fd())
}

@@ -22,3 +22,3 @@ //! Low-level Linux network device access

#[cfg(feature = "alloc")]
use alloc::string::String;
use alloc::{borrow::ToOwned, string::String};

@@ -46,2 +46,4 @@ /// `ioctl(fd, SIOCGIFINDEX, ifreq)`—Returns the interface index for a given

///
/// See also [`index_to_name_inlined`] which does not require `alloc` feature.
///
/// # References

@@ -57,8 +59,80 @@ /// - [Linux]

pub fn index_to_name<Fd: AsFd>(fd: Fd, index: u32) -> io::Result<String> {
crate::backend::net::netdevice::index_to_name(fd.as_fd(), index)
let (len, ifrn_name) = crate::backend::net::netdevice::index_to_name(fd.as_fd(), index)?;
core::str::from_utf8(&ifrn_name[..len])
.map_err(|_| io::Errno::ILSEQ)
.map(ToOwned::to_owned)
}
/// `ioctl(fd, SIOCGIFNAME, ifreq)`—Returns the interface name for a given
/// index.
///
/// See the [module-level documentation] for information about `fd` usage.
///
/// # References
/// - [Linux]
///
/// [module-level documentation]: self
/// [Linux]: https://man7.org/linux/man-pages/man7/netdevice.7.html
#[inline]
#[doc(alias = "SIOCGIFNAME")]
pub fn index_to_name_inlined<Fd: AsFd>(fd: Fd, index: u32) -> io::Result<InlinedName> {
let (len, ifrn_name) = crate::backend::net::netdevice::index_to_name(fd.as_fd(), index)?;
// Check if the name is valid UTF-8.
core::str::from_utf8(&ifrn_name[..len])
.map_err(|_| io::Errno::ILSEQ)
.map(|_| InlinedName {
len,
name: ifrn_name,
})
}
/// The inlined interface name.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct InlinedName {
len: usize,
name: [u8; 16],
}
impl InlinedName {
/// Returns the str representation of the inlined name.
pub fn as_str(&self) -> &str {
self.as_ref()
}
/// Returns the bytes representation of the inlined name.
pub fn as_bytes(&self) -> &[u8] {
self.as_ref()
}
}
impl AsRef<[u8]> for InlinedName {
fn as_ref(&self) -> &[u8] {
&self.name[..self.len]
}
}
impl AsRef<str> for InlinedName {
fn as_ref(&self) -> &str {
// SAFETY: `InlinedName` is constructed with valid UTF-8.
core::str::from_utf8(&self.name[..self.len]).unwrap()
}
}
impl core::borrow::Borrow<str> for InlinedName {
fn borrow(&self) -> &str {
self.as_ref()
}
}
impl core::fmt::Display for InlinedName {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.as_str().fmt(f)
}
}
#[cfg(test)]
mod tests {
use crate::backend::net::netdevice::{index_to_name, name_to_index};
use super::{index_to_name, index_to_name_inlined, name_to_index};
use crate::fd::AsFd;

@@ -88,2 +162,27 @@ use crate::net::{AddressFamily, SocketFlags, SocketType};

#[test]
fn test_index_to_name_inlined() {
let fd = crate::net::socket_with(
AddressFamily::INET,
SocketType::DGRAM,
SocketFlags::CLOEXEC,
None,
)
.unwrap();
let loopback_index = std::fs::read_to_string("/sys/class/net/lo/ifindex")
.unwrap()
.as_str()
.split_at(1)
.0
.parse::<u32>()
.unwrap();
assert_eq!(
"lo",
index_to_name_inlined(fd.as_fd(), loopback_index)
.unwrap()
.as_str(),
);
}
#[test]
#[cfg(feature = "alloc")]

@@ -90,0 +189,0 @@ fn test_index_to_name() {

@@ -69,2 +69,7 @@ //! [`recvmsg`], [`sendmsg`], and related functions.

};
(TxTime($len:expr)) => {
$crate::net::__cmsg_space(
$len * ::core::mem::size_of::<u64>(),
)
};

@@ -98,2 +103,7 @@ // Combo Rules

};
(TxTime($len:expr)) => {
$crate::net::__cmsg_aligned_space(
$len * ::core::mem::size_of::<u64>(),
)
};

@@ -143,2 +153,9 @@ // Combo Rules

ScmCredentials(UCred),
/// Transmission time, in nanoseconds. The value will be interpreted by
/// whichever clock was configured on the socket with [`set_txtime`].
///
/// [`set_txtime`]: crate::net::sockopt::set_txtime
#[cfg(target_os = "linux")]
#[doc(alias = "SCM_TXTIME")]
TxTime(u64),
}

@@ -156,2 +173,4 @@

Self::ScmCredentials(_) => cmsg_space!(ScmCredentials(1)),
#[cfg(target_os = "linux")]
Self::TxTime(_) => cmsg_space!(TxTime(1)),
}

@@ -298,2 +317,9 @@ }

}
#[cfg(target_os = "linux")]
SendAncillaryMessage::TxTime(tx_time) => {
let tx_time_bytes = unsafe {
slice::from_raw_parts(addr_of!(tx_time).cast::<u8>(), size_of_val(&tx_time))
};
self.push_ancillary(tx_time_bytes, c::SOL_SOCKET as _, c::SO_TXTIME as _)
}
}

@@ -300,0 +326,0 @@ }

@@ -146,2 +146,4 @@ //! `getsockopt` and `setsockopt` functions.

#[cfg(all(target_os = "linux", feature = "time"))]
use crate::clockid::ClockId;
#[cfg(target_os = "linux")]

@@ -176,2 +178,4 @@ use crate::net::xdp::{XdpMmapOffsets, XdpOptionsFlags, XdpStatistics, XdpUmemReg};

use crate::net::SocketAddrV6;
#[cfg(all(target_os = "linux", feature = "time"))]
use crate::net::TxTimeFlags;
use crate::net::{Ipv4Addr, Ipv6Addr, SocketType};

@@ -203,2 +207,106 @@ use crate::{backend, io};

/// A type for holding raw integer IPv4 Path MTU Discovery options.
#[cfg(linux_kernel)]
pub type RawIpv4PathMtuDiscovery = i32;
/// IPv4 Path MTU Discovery option values (`IP_PMTUDISC_*`) for use with
/// [`set_ip_mtu_discover`] and [`ip_mtu_discover`].
///
/// # References
/// - [Linux]
/// - [Linux INET header]
///
/// [Linux]: https://man7.org/linux/man-pages/man7/ip.7.html
/// [Linux INET header]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/in.h?h=v6.14#n135
#[cfg(linux_kernel)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct Ipv4PathMtuDiscovery(RawIpv4PathMtuDiscovery);
#[cfg(linux_kernel)]
impl Ipv4PathMtuDiscovery {
/// `IP_PMTUDISC_DONT`
#[doc(alias = "IP_PMTUDISC_DONT")]
pub const DONT: Self = Self(c::IP_PMTUDISC_DONT as _);
/// `IP_PMTUDISC_WANT`
#[doc(alias = "IP_PMTUDISC_WANT")]
pub const WANT: Self = Self(c::IP_PMTUDISC_WANT as _);
/// `IP_PMTUDISC_DO`
#[doc(alias = "IP_PMTUDISC_DO")]
pub const DO: Self = Self(c::IP_PMTUDISC_DO as _);
/// `IP_PMTUDISC_PROBE`
#[doc(alias = "IP_PMTUDISC_PROBE")]
pub const PROBE: Self = Self(c::IP_PMTUDISC_PROBE as _);
/// `IP_PMTUDISC_INTERFACE`
#[doc(alias = "IP_PMTUDISC_INTERFACE")]
pub const INTERFACE: Self = Self(c::IP_PMTUDISC_INTERFACE as _);
/// `IP_PMTUDISC_OMIT`
#[doc(alias = "IP_PMTUDISC_OMIT")]
pub const OMIT: Self = Self(c::IP_PMTUDISC_OMIT as _);
/// Constructs an option from a raw integer.
#[inline]
pub const fn from_raw(raw: RawIpv4PathMtuDiscovery) -> Self {
Self(raw)
}
/// Returns the raw integer for this option.
#[inline]
pub const fn as_raw(self) -> RawIpv4PathMtuDiscovery {
self.0
}
}
/// A type for holding raw integer IPv6 Path MTU Discovery options.
#[cfg(linux_kernel)]
pub type RawIpv6PathMtuDiscovery = i32;
/// IPv6 Path MTU Discovery option values (`IPV6_PMTUDISC_*`) for use with
/// [`set_ipv6_mtu_discover`] and [`ipv6_mtu_discover`].
///
/// # References
/// - [Linux]
/// - [Linux INET6 header]
///
/// [Linux]: https://man7.org/linux/man-pages/man7/ipv6.7.html
/// [Linux INET6 header]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/in6.h?h=v6.14#n185
#[cfg(linux_kernel)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct Ipv6PathMtuDiscovery(RawIpv6PathMtuDiscovery);
#[cfg(linux_kernel)]
impl Ipv6PathMtuDiscovery {
/// `IPV6_PMTUDISC_DONT`
#[doc(alias = "IPV6_PMTUDISC_DONT")]
pub const DONT: Self = Self(c::IPV6_PMTUDISC_DONT as _);
/// `IPV6_PMTUDISC_WANT`
#[doc(alias = "IPV6_PMTUDISC_WANT")]
pub const WANT: Self = Self(c::IPV6_PMTUDISC_WANT as _);
/// `IPV6_PMTUDISC_DO`
#[doc(alias = "IPV6_PMTUDISC_DO")]
pub const DO: Self = Self(c::IPV6_PMTUDISC_DO as _);
/// `IPV6_PMTUDISC_PROBE`
#[doc(alias = "IPV6_PMTUDISC_PROBE")]
pub const PROBE: Self = Self(c::IPV6_PMTUDISC_PROBE as _);
/// `IPV6_PMTUDISC_INTERFACE`
#[doc(alias = "IPV6_PMTUDISC_INTERFACE")]
pub const INTERFACE: Self = Self(c::IPV6_PMTUDISC_INTERFACE as _);
/// `IPV6_PMTUDISC_OMIT`
#[doc(alias = "IPV6_PMTUDISC_OMIT")]
pub const OMIT: Self = Self(c::IPV6_PMTUDISC_OMIT as _);
/// Constructs an option from a raw integer.
#[inline]
pub const fn from_raw(raw: RawIpv6PathMtuDiscovery) -> Self {
Self(raw)
}
/// Returns the raw integer for this option.
#[inline]
pub const fn as_raw(self) -> RawIpv6PathMtuDiscovery {
self.0
}
}
/// `getsockopt(fd, SOL_SOCKET, SO_TYPE)`—Returns the type of a socket.

@@ -692,2 +800,50 @@ ///

/// `setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER, value)`
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IP_MTU_DISCOVER")]
pub fn set_ip_mtu_discover<Fd: AsFd>(fd: Fd, value: Ipv4PathMtuDiscovery) -> io::Result<()> {
backend::net::sockopt::set_ip_mtu_discover(fd.as_fd(), value)
}
/// `getsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER)`
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ip_-and-set_ip_-functions
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IP_MTU_DISCOVER")]
pub fn ip_mtu_discover<Fd: AsFd>(fd: Fd) -> io::Result<Ipv4PathMtuDiscovery> {
backend::net::sockopt::ip_mtu_discover(fd.as_fd())
}
/// `setsockopt(fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, value)`
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IPV6_MTU_DISCOVER")]
pub fn set_ipv6_mtu_discover<Fd: AsFd>(fd: Fd, value: Ipv6PathMtuDiscovery) -> io::Result<()> {
backend::net::sockopt::set_ipv6_mtu_discover(fd.as_fd(), value)
}
/// `getsockopt(fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER)`
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
#[cfg(linux_kernel)]
#[inline]
#[doc(alias = "IPV6_MTU_DISCOVER")]
pub fn ipv6_mtu_discover<Fd: AsFd>(fd: Fd) -> io::Result<Ipv6PathMtuDiscovery> {
backend::net::sockopt::ipv6_mtu_discover(fd.as_fd())
}
/// `setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, value)`

@@ -1543,2 +1699,16 @@ ///

/// `getsockopt(fd, SOL_SOCKET, SO_TXTIME)` — Get transmission timing configuration.
#[cfg(all(target_os = "linux", feature = "time"))]
#[doc(alias = "SO_TXTIME")]
pub fn get_txtime<Fd: AsFd>(fd: Fd) -> io::Result<(ClockId, TxTimeFlags)> {
backend::net::sockopt::get_txtime(fd.as_fd())
}
/// `setsockopt(fd, SOL_SOCKET, SO_TXTIME)` — Configure transmission timing.
#[cfg(all(target_os = "linux", feature = "time"))]
#[doc(alias = "SO_TXTIME")]
pub fn set_txtime<Fd: AsFd>(fd: Fd, clockid: ClockId, flags: TxTimeFlags) -> io::Result<()> {
backend::net::sockopt::set_txtime(fd.as_fd(), clockid, flags)
}
/// `setsockopt(fd, SOL_XDP, XDP_UMEM_REG, value)`

@@ -1612,3 +1782,3 @@ ///

/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html
#[cfg(target_os = "linux")]
#[cfg(linux_raw_dep)]
#[doc(alias = "XDP_MMAP_OFFSETS")]

@@ -1625,3 +1795,3 @@ pub fn xdp_mmap_offsets<Fd: AsFd>(fd: Fd) -> io::Result<XdpMmapOffsets> {

/// [Linux]: https://www.kernel.org/doc/html/next/networking/af_xdp.html#xdp-statistics-getsockopt
#[cfg(target_os = "linux")]
#[cfg(linux_raw_dep)]
#[doc(alias = "XDP_STATISTICS")]

@@ -1628,0 +1798,0 @@ pub fn xdp_statistics<Fd: AsFd>(fd: Fd) -> io::Result<XdpStatistics> {

@@ -5,3 +5,3 @@ //! The `Pid` type.

use core::num::NonZeroI32;
use core::{fmt, num::NonZeroI32};

@@ -82,2 +82,10 @@ /// A process identifier as a raw integer.

/// Converts a `Pid` into a `RawPid`.
///
/// This is the same as `self.as_raw_nonzero().get()`.
#[inline]
pub const fn as_raw_pid(self) -> RawPid {
self.0.get()
}
/// Converts an `Option<Pid>` into a `RawPid`.

@@ -99,2 +107,40 @@ #[inline]

impl fmt::Display for Pid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::Binary for Pid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::Octal for Pid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::LowerHex for Pid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::UpperHex for Pid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
#[cfg(lower_upper_exp_for_non_zero)]
impl fmt::LowerExp for Pid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
#[cfg(lower_upper_exp_for_non_zero)]
impl fmt::UpperExp for Pid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
#[cfg(test)]

@@ -130,2 +176,3 @@ mod tests {

);
assert_eq!(Pid::from_raw(77).unwrap().as_raw_pid(), 77);
assert_eq!(Pid::as_raw(Pid::from_raw(77)), 77);

@@ -132,0 +179,0 @@ }

@@ -108,4 +108,9 @@ //! CPU and thread identifiers.

#[inline]
pub fn set_thread_res_uid(ruid: Uid, euid: Uid, suid: Uid) -> io::Result<()> {
backend::thread::syscalls::setresuid_thread(ruid, euid, suid)
pub fn set_thread_res_uid<R, E, S>(ruid: R, euid: E, suid: S) -> io::Result<()>
where
R: Into<Option<Uid>>,
E: Into<Option<Uid>>,
S: Into<Option<Uid>>,
{
backend::thread::syscalls::setresuid_thread(ruid.into(), euid.into(), suid.into())
}

@@ -158,4 +163,9 @@

#[inline]
pub fn set_thread_res_gid(rgid: Gid, egid: Gid, sgid: Gid) -> io::Result<()> {
backend::thread::syscalls::setresgid_thread(rgid, egid, sgid)
pub fn set_thread_res_gid<R, E, S>(rgid: R, egid: E, sgid: S) -> io::Result<()>
where
R: Into<Option<Gid>>,
E: Into<Option<Gid>>,
S: Into<Option<Gid>>,
{
backend::thread::syscalls::setresgid_thread(rgid.into(), egid.into(), sgid.into())
}

@@ -162,0 +172,0 @@

@@ -11,9 +11,13 @@ use bitflags::bitflags;

/// `__user_cap_data_struct.effective`
pub effective: CapabilityFlags,
pub effective: CapabilitySet,
/// `__user_cap_data_struct.permitted`
pub permitted: CapabilityFlags,
pub permitted: CapabilitySet,
/// `__user_cap_data_struct.inheritable`
pub inheritable: CapabilityFlags,
pub inheritable: CapabilitySet,
}
/// Previous name of `CapabilitySet`.
#[deprecated(since = "1.1.0", note = "Renamed to CapabilitySet")]
pub type CapabilityFlags = CapabilitySet;
bitflags! {

@@ -23,3 +27,3 @@ /// `CAP_*` constants.

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CapabilityFlags: u64 {
pub struct CapabilitySet: u64 {
/// `CAP_CHOWN`

@@ -161,5 +165,5 @@ const CHOWN = 1 << linux_raw_sys::general::CAP_CHOWN;

Ok(CapabilitySets {
effective: CapabilityFlags::from_bits_retain(effective),
permitted: CapabilityFlags::from_bits_retain(permitted),
inheritable: CapabilityFlags::from_bits_retain(inheritable),
effective: CapabilitySet::from_bits_retain(effective),
permitted: CapabilitySet::from_bits_retain(permitted),
inheritable: CapabilitySet::from_bits_retain(inheritable),
})

@@ -166,0 +170,0 @@ }

@@ -26,3 +26,5 @@ //! Thread-associated operations.

#[cfg(linux_kernel)]
pub use libcap::{capabilities, set_capabilities, CapabilityFlags, CapabilitySets};
// #[expect(deprecated, reason = "CapabilityFlags is deprecated")]
#[allow(deprecated)]
pub use libcap::{capabilities, set_capabilities, CapabilityFlags, CapabilitySet, CapabilitySets};
#[cfg(linux_kernel)]

@@ -29,0 +31,0 @@ pub use membarrier::*;

@@ -24,2 +24,3 @@ //! Linux `prctl` wrappers.

use crate::io;
use crate::io::Errno;
use crate::pid::Pid;

@@ -31,2 +32,4 @@ use crate::prctl::{

use super::CapabilitySet;
//

@@ -183,2 +186,3 @@ // PR_GET_KEEPCAPS/PR_SET_KEEPCAPS

/// Linux per-thread capability.
#[deprecated(since = "1.1.0", note = "Use CapabilitySet with a single bit instead")]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]

@@ -389,2 +393,71 @@ #[repr(u32)]

mod private {
pub trait Sealed {}
pub struct Token;
#[allow(deprecated)]
impl Sealed for crate::thread::Capability {}
impl Sealed for crate::thread::CapabilitySet {}
}
/// Compatibility trait to keep existing code that uses the deprecated [`Capability`] type working.
///
/// This trait and its methods are sealed. It must not be used downstream.
pub trait CompatCapability: private::Sealed + Copy {
#[doc(hidden)]
fn as_capability_set(self, _: private::Token) -> CapabilitySet;
}
#[allow(deprecated)]
impl CompatCapability for Capability {
fn as_capability_set(self, _: private::Token) -> CapabilitySet {
match self {
Self::ChangeOwnership => CapabilitySet::CHOWN,
Self::DACOverride => CapabilitySet::DAC_OVERRIDE,
Self::DACReadSearch => CapabilitySet::DAC_READ_SEARCH,
Self::FileOwner => CapabilitySet::FOWNER,
Self::FileSetID => CapabilitySet::FSETID,
Self::Kill => CapabilitySet::KILL,
Self::SetGroupID => CapabilitySet::SETGID,
Self::SetUserID => CapabilitySet::SETUID,
Self::SetPermittedCapabilities => CapabilitySet::SETPCAP,
Self::LinuxImmutable => CapabilitySet::LINUX_IMMUTABLE,
Self::NetBindService => CapabilitySet::NET_BIND_SERVICE,
Self::NetBroadcast => CapabilitySet::NET_BROADCAST,
Self::NetAdmin => CapabilitySet::NET_ADMIN,
Self::NetRaw => CapabilitySet::NET_RAW,
Self::IPCLock => CapabilitySet::IPC_LOCK,
Self::IPCOwner => CapabilitySet::IPC_OWNER,
Self::SystemModule => CapabilitySet::SYS_MODULE,
Self::SystemRawIO => CapabilitySet::SYS_RAWIO,
Self::SystemChangeRoot => CapabilitySet::SYS_CHROOT,
Self::SystemProcessTrace => CapabilitySet::SYS_PTRACE,
Self::SystemProcessAccounting => CapabilitySet::SYS_PACCT,
Self::SystemAdmin => CapabilitySet::SYS_ADMIN,
Self::SystemBoot => CapabilitySet::SYS_BOOT,
Self::SystemNice => CapabilitySet::SYS_NICE,
Self::SystemResource => CapabilitySet::SYS_RESOURCE,
Self::SystemTime => CapabilitySet::SYS_TIME,
Self::SystemTTYConfig => CapabilitySet::SYS_TTY_CONFIG,
Self::MakeNode => CapabilitySet::MKNOD,
Self::Lease => CapabilitySet::LEASE,
Self::AuditWrite => CapabilitySet::AUDIT_WRITE,
Self::AuditControl => CapabilitySet::AUDIT_CONTROL,
Self::SetFileCapabilities => CapabilitySet::SETFCAP,
Self::MACOverride => CapabilitySet::MAC_OVERRIDE,
Self::MACAdmin => CapabilitySet::MAC_ADMIN,
Self::SystemLog => CapabilitySet::SYSLOG,
Self::WakeAlarm => CapabilitySet::WAKE_ALARM,
Self::BlockSuspend => CapabilitySet::BLOCK_SUSPEND,
Self::AuditRead => CapabilitySet::AUDIT_READ,
Self::PerformanceMonitoring => CapabilitySet::PERFMON,
Self::BerkeleyPacketFilters => CapabilitySet::BPF,
Self::CheckpointRestore => CapabilitySet::CHECKPOINT_RESTORE,
}
}
}
impl CompatCapability for CapabilitySet {
fn as_capability_set(self, _: private::Token) -> CapabilitySet {
self
}
}
/// Check if the specified capability is in the calling thread's capability

@@ -398,4 +471,11 @@ /// bounding set.

#[inline]
pub fn capability_is_in_bounding_set(capability: Capability) -> io::Result<bool> {
unsafe { prctl_2args(PR_CAPBSET_READ, capability as usize as *mut _) }.map(|r| r != 0)
pub fn capability_is_in_bounding_set(capability: impl CompatCapability) -> io::Result<bool> {
let capset = capability.as_capability_set(private::Token).bits();
if capset.count_ones() != 1 {
return Err(Errno::INVAL);
}
let cap = capset.trailing_zeros();
// as *mut _ should be ptr::without_provenance_mut but our MSRV does not allow it.
unsafe { prctl_2args(PR_CAPBSET_READ, cap as usize as *mut _) }.map(|r| r != 0)
}

@@ -414,4 +494,11 @@

#[inline]
pub fn remove_capability_from_bounding_set(capability: Capability) -> io::Result<()> {
unsafe { prctl_2args(PR_CAPBSET_DROP, capability as usize as *mut _) }.map(|_r| ())
pub fn remove_capability_from_bounding_set(capability: impl CompatCapability) -> io::Result<()> {
let capset = capability.as_capability_set(private::Token).bits();
if capset.count_ones() != 1 {
return Err(Errno::INVAL);
}
let cap = capset.trailing_zeros();
// as *mut _ should be ptr::without_provenance_mut but our MSRV does not allow it.
unsafe { prctl_2args(PR_CAPBSET_DROP, cap as usize as *mut _) }.map(|_r| ())
}

@@ -617,5 +704,18 @@

#[inline]
pub fn capability_is_in_ambient_set(capability: Capability) -> io::Result<bool> {
let cap = capability as usize as *mut _;
unsafe { prctl_3args(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET as *mut _, cap) }.map(|r| r != 0)
pub fn capability_is_in_ambient_set(capability: impl CompatCapability) -> io::Result<bool> {
let capset = capability.as_capability_set(private::Token).bits();
if capset.count_ones() != 1 {
return Err(Errno::INVAL);
}
let cap = capset.trailing_zeros();
unsafe {
prctl_3args(
PR_CAP_AMBIENT,
PR_CAP_AMBIENT_IS_SET as *mut _,
// as *mut _ should be ptr::without_provenance_mut but our MSRV does not allow it.
cap as usize as *mut _,
)
}
.map(|r| r != 0)
}

@@ -646,3 +746,6 @@

#[inline]
pub fn configure_capability_in_ambient_set(capability: Capability, enable: bool) -> io::Result<()> {
pub fn configure_capability_in_ambient_set(
capability: impl CompatCapability,
enable: bool,
) -> io::Result<()> {
let sub_operation = if enable {

@@ -653,5 +756,17 @@ PR_CAP_AMBIENT_RAISE

};
let cap = capability as usize as *mut _;
let capset = capability.as_capability_set(private::Token).bits();
if capset.count_ones() != 1 {
return Err(Errno::INVAL);
}
let cap = capset.trailing_zeros();
unsafe { prctl_3args(PR_CAP_AMBIENT, sub_operation as *mut _, cap) }.map(|_r| ())
unsafe {
prctl_3args(
PR_CAP_AMBIENT,
sub_operation as *mut _,
// as *mut _ should be ptr::without_provenance_mut but our MSRV does not allow it.
cap as usize as *mut _,
)
}
.map(|_r| ())
}

@@ -658,0 +773,0 @@

//! Time-related operations.
mod clock;
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
mod timerfd;

@@ -10,3 +16,9 @@

pub use clock::*;
#[cfg(any(linux_kernel, target_os = "fuchsia"))]
#[cfg(any(
linux_kernel,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "illumos",
target_os = "netbsd"
))]
pub use timerfd::*;

@@ -28,4 +28,10 @@ use crate::fd::{AsFd, OwnedFd};

/// - [Linux]
/// - [FreeBSD]
/// - [illumos]
/// - [NetBSD]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_create.2.html
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=timerfd_create&sektion=2
/// [illumos]: https://illumos.org/man/3C/timerfd_create
/// [NetBSD]: https://man.netbsd.org/timerfd_create.2
#[inline]

@@ -40,4 +46,10 @@ pub fn timerfd_create(clockid: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> {

/// - [Linux]
/// - [FreeBSD]
/// - [illumos]
/// - [NetBSD]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_settime.2.html
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=timerfd_settime&sektion=2
/// [illumos]: https://illumos.org/man/3C/timerfd_settime
/// [NetBSD]: https://man.netbsd.org/timerfd_settime.2
#[inline]

@@ -56,4 +68,10 @@ pub fn timerfd_settime<Fd: AsFd>(

/// - [Linux]
/// - [FreeBSD]
/// - [illumos]
/// - [NetBSD]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_gettime.2.html
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=timerfd_gettime&sektion=2
/// [illumos]: https://illumos.org/man/3C/timerfd_gettime
/// [NetBSD]: https://man.netbsd.org/timerfd_gettime.2
#[inline]

@@ -60,0 +78,0 @@ pub fn timerfd_gettime<Fd: AsFd>(fd: Fd) -> io::Result<Itimerspec> {

@@ -414,3 +414,3 @@ //! `Timespec` and related types, which are used by multiple public API

// Test that `Timespec` matches Linux's `__kernel_timespec`.
#[cfg(linux_kernel)]
#[cfg(linux_raw_dep)]
#[test]

@@ -417,0 +417,0 @@ fn test_against_kernel_timespec() {

//! User and Group ID types.
use core::fmt;
use crate::backend::c;

@@ -89,2 +91,74 @@ use crate::ffi;

impl fmt::Display for Uid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::Binary for Uid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::Octal for Uid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::LowerHex for Uid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::UpperHex for Uid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::LowerExp for Uid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::UpperExp for Uid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::Display for Gid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::Binary for Gid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::Octal for Gid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::LowerHex for Gid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::UpperHex for Gid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::LowerExp for Gid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl fmt::UpperExp for Gid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
// Return the raw value of the IDs. In case of `None` it returns `!0` since it

@@ -91,0 +165,0 @@ // has the same bit pattern as `-1` indicating no change to the owner/group ID.

@@ -149,4 +149,4 @@ // Implementation derived from `weak` in Rust's

macro_rules! syscall {
(fn $name:ident($($arg_name:ident: $t:ty),*) via $_sys_name:ident -> $ret:ty) => (
unsafe fn $name($($arg_name: $t),*) -> $ret {
($vis:vis fn $name:ident($($arg_name:ident: $t:ty),*) via $_sys_name:ident -> $ret:ty) => (
$vis unsafe fn $name($($arg_name: $t),*) -> $ret {
weak! { fn $name($($t),*) -> $ret }

@@ -166,4 +166,4 @@

macro_rules! syscall {
(fn $name:ident($($arg_name:ident: $t:ty),*) via $sys_name:ident -> $ret:ty) => (
unsafe fn $name($($arg_name:$t),*) -> $ret {
($vis:vis fn $name:ident($($arg_name:ident: $t:ty),*) via $sys_name:ident -> $ret:ty) => (
$vis unsafe fn $name($($arg_name:$t),*) -> $ret {
// This looks like a hack, but `concat_idents` only accepts idents

@@ -170,0 +170,0 @@ // (not paths).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display