Skip to content

Commit 29bdc15

Browse files
wan9chiGPT-5.6
andcommitted
refactor(fspy): own Windows shared-memory mapping
Co-authored-by: GPT-5.6 <gpt-5.6@openai.com>
1 parent 67534d3 commit 29bdc15

7 files changed

Lines changed: 646 additions & 12 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ wax = "0.7.0"
168168
which = "8.0.0"
169169
widestring = "1.2.0"
170170
winapi = "0.3.9"
171+
windows-sys = "0.61"
171172
winsafe = { version = "0.0.27", features = ["kernel"] }
172173
xxhash-rust = { version = "0.8.15", features = ["const_xxh3"] }
173174
ntest = "0.9.5"

crates/fspy_preload_windows/src/windows/winapi_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,13 @@ pub const fn access_mask_to_mode(desired_access: ACCESS_MASK) -> AccessMode {
9999
}
100100
}
101101

102+
#[link(name = "kernel32")]
102103
unsafe extern "system" {
103104
fn LocalFree(hmem: HLOCAL) -> HLOCAL;
105+
}
106+
107+
#[link(name = "pathcch")]
108+
unsafe extern "system" {
104109
fn PathAllocCombine(
105110
pszpathin: PCWSTR,
106111
pszmore: PCWSTR,

crates/fspy_shm/Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license.workspace = true
77
publish = false
88
rust-version.workspace = true
99

10-
[target.'cfg(not(target_os = "linux"))'.dependencies]
10+
[target.'cfg(not(any(target_os = "linux", target_os = "windows")))'.dependencies]
1111
shared_memory = { workspace = true, features = ["logging"] }
1212

1313
[target.'cfg(target_os = "linux")'.dependencies]
@@ -17,6 +17,16 @@ rustix = { workspace = true, features = ["fs", "net"] }
1717
tokio = { workspace = true, features = ["macros", "net", "rt", "time"] }
1818
uuid = { workspace = true, features = ["v4"] }
1919

20+
[target.'cfg(target_os = "windows")'.dependencies]
21+
base64 = { workspace = true }
22+
uuid = { workspace = true, features = ["v4"] }
23+
windows-sys = { workspace = true, features = [
24+
"Win32_Foundation",
25+
"Win32_Security",
26+
"Win32_Storage_FileSystem",
27+
"Win32_System_Memory",
28+
] }
29+
2030
[dev-dependencies]
2131
ctor = { workspace = true }
2232
subprocess_test = { workspace = true }

crates/fspy_shm/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
//! Platform shared-memory implementation for fspy channels.
22
3-
#[cfg(not(target_os = "linux"))]
3+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
44
use std::io;
55
#[cfg(target_os = "linux")]
66
use std::{future::Future, io, pin::Pin};
77

88
#[cfg(target_os = "linux")]
99
mod linux;
10+
#[cfg(target_os = "windows")]
11+
mod windows;
1012

1113
#[cfg(target_os = "linux")]
1214
pub use linux::{CreatedShm, Shm, create, open};
13-
#[cfg(not(target_os = "linux"))]
15+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
1416
use shared_memory::{Shmem, ShmemConf};
17+
#[cfg(target_os = "windows")]
18+
pub use windows::{CreatedShm, Shm, create, open};
1519

1620
/// A Linux service future that makes a shared-memory mapping available to other processes.
1721
#[cfg(target_os = "linux")]
1822
pub type ShmBroker = Pin<Box<dyn Future<Output = io::Result<()>> + Send + 'static>>;
1923

2024
/// An owned shared-memory mapping.
21-
#[cfg(not(target_os = "linux"))]
25+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
2226
pub struct Shm {
2327
inner: Shmem,
2428
}
2529

2630
/// A newly created shared-memory mapping and its platform service.
27-
#[cfg(not(target_os = "linux"))]
31+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
2832
pub struct CreatedShm {
2933
/// The owned shared-memory mapping.
3034
pub shm: Shm,
@@ -35,11 +39,9 @@ pub struct CreatedShm {
3539
/// # Errors
3640
///
3741
/// Returns an error if the platform cannot create or map the region.
38-
#[cfg(not(target_os = "linux"))]
42+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
3943
pub fn create(size: usize) -> io::Result<CreatedShm> {
4044
let conf = ShmemConf::new().size(size);
41-
#[cfg(target_os = "windows")]
42-
let conf = conf.allow_raw(true);
4345

4446
let inner = conf.create().map_err(io::Error::other)?;
4547
Ok(CreatedShm { shm: Shm { inner } })
@@ -50,17 +52,15 @@ pub fn create(size: usize) -> io::Result<CreatedShm> {
5052
/// # Errors
5153
///
5254
/// Returns an error if the mapping does not exist or cannot be mapped.
53-
#[cfg(not(target_os = "linux"))]
55+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
5456
pub fn open(id: &str, size: usize) -> io::Result<Shm> {
5557
let conf = ShmemConf::new().size(size).os_id(id);
56-
#[cfg(target_os = "windows")]
57-
let conf = conf.allow_raw(true);
5858

5959
let inner = conf.open().map_err(io::Error::other)?;
6060
Ok(Shm { inner })
6161
}
6262

63-
#[cfg(not(target_os = "linux"))]
63+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
6464
#[expect(clippy::len_without_is_empty, reason = "shared-memory mappings are always non-empty")]
6565
impl Shm {
6666
/// Returns this mapping's opaque platform identifier.

0 commit comments

Comments
 (0)