Skip to content

Commit adc5221

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 308b887 commit adc5221

7 files changed

Lines changed: 477 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
@@ -167,6 +167,7 @@ wax = "0.7.0"
167167
which = "8.0.0"
168168
widestring = "1.2.0"
169169
winapi = "0.3.9"
170+
windows-sys = "0.61"
170171
winsafe = { version = "0.0.27", features = ["kernel"] }
171172
xxhash-rust = { version = "0.8.15", features = ["const_xxh3"] }
172173
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: 10 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]
@@ -18,6 +18,15 @@ tempfile = { workspace = true }
1818
tokio = { workspace = true, features = ["macros", "net", "rt", "sync", "time"] }
1919
uuid = { workspace = true, features = ["v4"] }
2020

21+
[target.'cfg(target_os = "windows")'.dependencies]
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+
2130
[dev-dependencies]
2231
ctor = { workspace = true }
2332
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,24 +1,28 @@
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

66
#[cfg(target_os = "linux")]
77
mod linux;
8+
#[cfg(target_os = "windows")]
9+
mod windows;
810

911
#[cfg(target_os = "linux")]
1012
pub use linux::{CreatedShm, Shm, ShmBroker, ShmBrokerHandle, create, open};
11-
#[cfg(not(target_os = "linux"))]
13+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
1214
use shared_memory::{Shmem, ShmemConf};
15+
#[cfg(target_os = "windows")]
16+
pub use windows::{CreatedShm, Shm, create, open};
1317

1418
/// An owned shared-memory mapping.
15-
#[cfg(not(target_os = "linux"))]
19+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
1620
pub struct Shm {
1721
inner: Shmem,
1822
}
1923

2024
/// A newly created shared-memory mapping and its platform service.
21-
#[cfg(not(target_os = "linux"))]
25+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
2226
pub struct CreatedShm {
2327
/// The owned shared-memory mapping.
2428
pub shm: Shm,
@@ -29,11 +33,9 @@ pub struct CreatedShm {
2933
/// # Errors
3034
///
3135
/// Returns an error if the platform cannot create or map the region.
32-
#[cfg(not(target_os = "linux"))]
36+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
3337
pub fn create(size: usize) -> io::Result<CreatedShm> {
3438
let conf = ShmemConf::new().size(size);
35-
#[cfg(target_os = "windows")]
36-
let conf = conf.allow_raw(true);
3739

3840
let inner = conf.create().map_err(io::Error::other)?;
3941
Ok(CreatedShm { shm: Shm { inner } })
@@ -44,17 +46,15 @@ pub fn create(size: usize) -> io::Result<CreatedShm> {
4446
/// # Errors
4547
///
4648
/// Returns an error if the mapping does not exist or cannot be mapped.
47-
#[cfg(not(target_os = "linux"))]
49+
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
4850
pub fn open(id: &str, size: usize) -> io::Result<Shm> {
4951
let conf = ShmemConf::new().size(size).os_id(id);
50-
#[cfg(target_os = "windows")]
51-
let conf = conf.allow_raw(true);
5252

5353
let inner = conf.open().map_err(io::Error::other)?;
5454
Ok(Shm { inner })
5555
}
5656

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

0 commit comments

Comments
 (0)