Skip to content

Commit 0926314

Browse files
wan9chiclaude
andcommitted
fix(fspy): enable Windows shared memory access from injected DLLs
Create named shared memory mappings that can be opened from child processes without backing file access. This fixes rust_std tests on Windows where DLLs injected via Detours need to access the IPC channel. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 783c2b7 commit 0926314

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

  • crates/fspy_shared/src/ipc/channel

crates/fspy_shared/src/ipc/channel/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ pub fn channel(capacity: usize) -> io::Result<(ChannelConf, Receiver)> {
2727
let lock_file_path = temp_dir().join(format!("fspy_ipc_{}.lock", Uuid::new_v4()));
2828

2929
// Initialize the shared memory with a unique id.
30+
// Use a named shared memory so it can be opened from other processes.
31+
let shm_id = format!("fspy_shm_{}", Uuid::new_v4());
3032
let shm = ShmemConf::new()
3133
.size(capacity)
34+
.os_id(&shm_id)
3235
.create()
3336
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
3437

3538
let conf = ChannelConf {
3639
lock_file_path: lock_file_path.as_os_str().into(),
37-
shm_id: shm.get_os_id().into(),
40+
shm_id: shm_id.into(),
3841
shm_size: capacity,
3942
};
4043

@@ -49,11 +52,13 @@ impl ChannelConf {
4952
pub fn sender(&self) -> io::Result<Sender> {
5053
let lock_file = File::open(self.lock_file_path.to_cow_os_str())?;
5154
lock_file.try_lock_shared()?;
52-
let shm = ShmemConf::new()
53-
.size(self.shm_size)
54-
.os_id(&self.shm_id)
55-
.open()
56-
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
55+
let mut conf = ShmemConf::new().size(self.shm_size).os_id(&self.shm_id);
56+
// On Windows, allow opening raw shared memory (without backing file) for DLL injection scenarios
57+
#[cfg(target_os = "windows")]
58+
{
59+
conf = conf.allow_raw(true);
60+
}
61+
let shm = conf.open().map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
5762
let writer = unsafe { ShmWriter::new(shm) };
5863
Ok(Sender { writer, lock_file, lock_file_path: self.lock_file_path.clone() })
5964
}

0 commit comments

Comments
 (0)