-
Notifications
You must be signed in to change notification settings - Fork 235
refactor(fspy): use shared memory IPC on Windows #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wan9chi
merged 6 commits into
main
from
10-21-refactor_fspy_use_shared_memory_ipc_on_windows
Oct 23, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6098cc8
refactor(fspy): use shared memory IPC on Windows
wan9chi ed5d438
fix(fspy): enable Windows shared memory access from injected DLLs
wan9chi c05cace
remove explicitly generating shm name
wan9chi 84b136b
allow unused_mut
wan9chi fa71bcd
fix typo
wan9chi 7d676a0
address review comments
wan9chi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| use std::io; | ||
|
|
||
| use bincode::borrow_decode_from_slice; | ||
| use fspy_shared::ipc::{ | ||
| BINCODE_CONFIG, PathAccess, | ||
| channel::{Receiver, ReceiverLockGuard}, | ||
| }; | ||
| use tokio::task::spawn_blocking; | ||
|
|
||
| // Shared memory size for storing path accesses. | ||
| // 4 GiB is large enough to store path accesses in almost any realistic scenario. | ||
| // This doesn't allocate physical memory until it's actually used. | ||
| pub const SHM_CAPACITY: usize = 4 * 1024 * 1024 * 1024; | ||
|
|
||
| #[ouroboros::self_referencing] | ||
| pub struct OwnedReceiverLockGuard { | ||
| /// Owns the shared memory | ||
| receiver: Receiver, | ||
| /// Borrows the shared memory and owns the file lock | ||
| #[borrows(receiver)] | ||
| #[covariant] | ||
| lock_guard: ReceiverLockGuard<'this>, | ||
| } | ||
|
|
||
| impl OwnedReceiverLockGuard { | ||
| pub fn lock(receiver: Receiver) -> io::Result<Self> { | ||
| OwnedReceiverLockGuard::try_new(receiver, |receiver| receiver.lock()) | ||
| } | ||
|
|
||
| pub async fn lock_async(receiver: Receiver) -> io::Result<Self> { | ||
| spawn_blocking(move || Self::lock(receiver)).await.expect("lock task panicked") | ||
| } | ||
|
|
||
| pub fn iter_path_accesses(&self) -> impl Iterator<Item = PathAccess<'_>> { | ||
| self.borrow_lock_guard().iter_frames().map(|frame| { | ||
| let (path_access, decoded_size) = | ||
| borrow_decode_from_slice::<PathAccess<'_>, _>(frame, BINCODE_CONFIG).unwrap(); | ||
| assert_eq!(decoded_size, frame.len()); | ||
| path_access | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.