A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Remove winx/cap-primitives dependencies (#14370)
Alex Crichton652f9cb63f30
diff --git a/Cargo.lock b/Cargo.lockindex 6ecdf51eff..fa09d1476c 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -61,12 +61,6 @@ version = "0.2.20"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9"-[[package]]-name = "ambient-authority"-version = "0.0.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e9d4ee0d472d1cd2e28c97dfa124b3d8d992e10eb0a035f33f5d12e3a177ba3b"-[[package]]name = "anes"version = "0.1.6"@@ -345,24 +339,6 @@ dependencies = ["serde",]-[[package]]-name = "cap-primitives"-version = "4.0.3"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "8b5f74729fd2f44701d1a8eb47e906cdb3ccd9ec0f02baad85a744b791940b18"-dependencies = [- "ambient-authority",- "fs-set-times",- "io-extras",- "io-lifetimes 3.0.1",- "ipnet",- "maybe-owned",- "rustix 1.1.4",- "rustix-linux-procfs",- "windows-sys 0.61.2",- "winx",-]-[[package]]name = "capstone"version = "0.14.0"@@ -1491,17 +1467,6 @@ dependencies = ["percent-encoding",]-[[package]]-name = "fs-set-times"-version = "0.20.3"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "94e7099f6313ecacbe1256e8ff9d617b75d1bcb16a6fddef94866d225a01a14a"-dependencies = [- "io-lifetimes 2.0.3",- "rustix 1.1.4",- "windows-sys 0.52.0",-]-[[package]]name = "fslock"version = "0.2.1"@@ -2102,34 +2067,6 @@ dependencies = ["cfg-if",]-[[package]]-name = "io-extras"-version = "0.19.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "20fd6de4ccfcc187e38bc21cfa543cb5a302cb86a8b114eb7f0bf0dc9f8ac00f"-dependencies = [- "io-lifetimes 3.0.1",- "windows-sys 0.52.0",-]--[[package]]-name = "io-lifetimes"-version = "2.0.3"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c"--[[package]]-name = "io-lifetimes"-version = "3.0.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2f0fb0570afe1fed943c5c3d4102d5358592d8625fda6a0007fdbe65a92fba96"--[[package]]-name = "ipnet"-version = "2.5.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b"-[[package]]name = "is-terminal"version = "0.4.17"@@ -2402,12 +2339,6 @@ dependencies = ["rawpointer",]-[[package]]-name = "maybe-owned"-version = "0.3.4"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "4facc753ae494aeb6e3c22f839b158aebd4f9270f55cd3c79906c45476c47ab4"-[[package]]name = "memchr"version = "2.7.6"@@ -5169,7 +5100,6 @@ dependencies = ["async-trait","bitflags 2.11.1","bytes",- "cap-primitives","env_logger 0.11.5","futures","rand 0.10.1",@@ -5188,7 +5118,6 @@ dependencies = ["wasmtime-wasi-io","wiggle","windows-sys 0.61.2",- "winx",][[package]]@@ -5635,16 +5564,6 @@ version = "0.0.19"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"-[[package]]-name = "winx"-version = "0.36.4"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "3f3fd376f71958b862e7afb20cfe5a22830e1963462f3a17f49d82a6c1d1f42d"-dependencies = [- "bitflags 2.11.1",- "windows-sys 0.52.0",-]-[[package]]name = "wit-bindgen"version = "0.45.1"diff --git a/crates/wasi/Cargo.toml b/crates/wasi/Cargo.tomlindex 43020d9d07..5dc3167d24 100644--- a/crates/wasi/Cargo.toml+++ b/crates/wasi/Cargo.toml@@ -25,7 +25,6 @@ tokio = { workspace = true, features = ["time", "sync", "io-std", "io-util", "rbytes = { workspace = true }thiserror = { workspace = true }tracing = { workspace = true, features = ["std", "attributes"] }-public-cap-primitives = { version = "4.0.3", package = 'cap-primitives' }bitflags = { workspace = true }async-trait = { workspace = true }futures = { workspace = true }@@ -43,12 +42,11 @@ wasmtime-test-util = { workspace = true }env_logger = { workspace = true }[target.'cfg(unix)'.dependencies]-rustix = { workspace = true, features = ["event", "fs", "net"] }+rustix = { workspace = true, features = ["event", "fs", "net", "time"] }rustix-linux-procfs = "0.1.1"[target.'cfg(windows)'.dependencies]rustix = { workspace = true, features = ["event", "net"] }-winx = "0.36.0"[target.'cfg(windows)'.dependencies.windows-sys]workspace = truediff --git a/crates/wasi/src/filesystem/primitives/windows/get_path.rs b/crates/wasi/src/filesystem/primitives/windows/get_path.rsindex c2b44ad883..3800c92a87 100644--- a/crates/wasi/src/filesystem/primitives/windows/get_path.rs+++ b/crates/wasi/src/filesystem/primitives/windows/get_path.rs@@ -1,7 +1,14 @@use std::ffi::OsString;use std::os::windows::ffi::{OsStrExt, OsStringExt};+use std::os::windows::io::AsRawHandle;use std::path::{Path, PathBuf};use std::{fs, io};+use windows_sys::Win32::Foundation::*;+use windows_sys::Win32::Storage::FileSystem::*;++/// Maximum total path length for Unicode in Windows.+/// [Maximum path length limitation]: https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation+const WIDE_MAX_PATH: u32 = 0x7fff;/// Calculates system path of `file`.///@@ -10,7 +17,7 @@ use std::{fs, io};/// components.pub(crate) fn get_path(file: &fs::File) -> io::Result<PathBuf> {// get system path to the handle- let path = winx::file::get_file_path(file)?;+ let path = get_final_path_name_by_handle(file)?;// strip extended prefix; otherwise we will error out on any relative// components with `out_path`@@ -29,3 +36,23 @@ pub(super) fn concatenate(file: &fs::File, path: &Path) -> io::Result<PathBuf> {let file_path = get_path(file)?;Ok(file_path.join(path))}++fn get_final_path_name_by_handle(file: &fs::File) -> io::Result<PathBuf> {+ let mut raw_path = vec![0u16; WIDE_MAX_PATH as usize];++ let handle = file.as_raw_handle();+ let res = unsafe {+ GetFinalPathNameByHandleW(handle, raw_path.as_mut_ptr(), raw_path.capacity() as u32, 0)+ };+ if res == 0 {+ return Err(io::Error::last_os_error());+ }++ // obtain a slice containing the written bytes, and check for it being too long+ // (practically probably impossible)+ let written_bytes = raw_path+ .get(..res as usize)+ .ok_or(io::Error::from_raw_os_error(ERROR_BUFFER_OVERFLOW as i32))?;++ Ok(PathBuf::from(OsString::from_wide(written_bytes)))+}diff --git a/crates/wasi/src/filesystem/primitives/windows/read_link.rs b/crates/wasi/src/filesystem/primitives/windows/read_link.rsindex c42981039f..834a9145e3 100644--- a/crates/wasi/src/filesystem/primitives/windows/read_link.rs+++ b/crates/wasi/src/filesystem/primitives/windows/read_link.rs@@ -1,20 +1,10 @@-use crate::filesystem::primitives::{FollowSymlinks, OpenOptions, OpenOptionsExt, open};+use super::get_path::concatenate;use std::path::{Path, PathBuf};use std::{fs, io};-use windows_sys::Win32::Storage::FileSystem::{- FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT,-};/// *Unsandboxed* function similar to `read_link`, but which does not perform/// sandboxing.pub(crate) fn read_link(start: &fs::File, path: &Path) -> io::Result<PathBuf> {- // Open the link with no access mode, instead of generic read.- // By default FILE_LIST_DIRECTORY is denied for the junction "C:\Documents and- // Settings", so this is needed for a common case.- let mut opts = OpenOptions::new();- opts.access_mode(0);- opts.custom_flags(FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS);- opts.follow(FollowSymlinks::No);- let file = open(start, path, &opts)?;- winx::file::read_link(&file)+ let out_path = concatenate(start, path)?;+ fs::read_link(out_path)}diff --git a/crates/wasi/src/lib.rs b/crates/wasi/src/lib.rsindex 5c582225e8..483d97ab15 100644--- a/crates/wasi/src/lib.rs+++ b/crates/wasi/src/lib.rs@@ -59,8 +59,6 @@ pub use self::view::*;#[doc(no_inline)]pub use async_trait::async_trait;#[doc(no_inline)]-pub use public_cap_primitives::fs::SystemTimeSpec;-#[doc(no_inline)]pub use rand::Rng;#[doc(no_inline)]pub use wasmtime::component::{ResourceTable, ResourceTableError};