Skip to content

Commit b929875

Browse files
wan9chiclaude
andcommitted
refactor(fspy-shared): route the shm id around OsStr
channel() serializes the shm id straight from the keeper's C string via IpcStr::from_os_c_str, and sender() decodes it with to_os_c_string_in backed by the fspy_nostd_alloc arena — removing the UTF-16 to WTF-8 to UTF-16 round trip and the global-allocator use on the preload attach path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c1d548b commit b929875

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

  • crates/fspy_shared/src/ipc/channel

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ pub fn channel(capacity: usize) -> io::Result<(ChannelConf, Receiver)> {
3737
// Initialize the lock file with a unique name.
3838
let lock_file_path = temp_dir().join(format!("fspy_ipc_{}.lock", Uuid::new_v4()));
3939

40-
let shm_path = shm_backing_path()?;
41-
let shm_c_path = os_c_string(shm_path.as_os_str())?;
40+
let shm_c_path = os_c_string(shm_backing_path()?.as_os_str())?;
4241
let handle =
4342
fspy_shm::create(shm_c_path.as_c_str().as_thin(), capacity).map_err(shm_error_to_io)?;
4443
// The keeper exists from here on, so every error path below cleans up.
@@ -47,7 +46,7 @@ pub fn channel(capacity: usize) -> io::Result<(ChannelConf, Receiver)> {
4746

4847
let conf = ChannelConf {
4948
lock_file_path: lock_file_path.as_os_str().into(),
50-
shm_id: shm_path.as_os_str().into(),
49+
shm_id: IpcStr::from_os_c_str(keeper.path.as_c_str()).to_boxed(),
5150
};
5251

5352
let receiver = Receiver::new(lock_file_path, keeper, mapping)?;
@@ -151,7 +150,13 @@ impl ChannelConf {
151150
let lock_file = File::open(self.lock_file_path.to_cow_os_str())?;
152151
lock_file.try_lock_shared()?;
153152

154-
let shm_path = os_c_string(&self.shm_id.to_cow_os_str())?;
153+
// The arena never touches the process heap, so this stays safe in
154+
// the preload contexts that create senders (pre-`main` constructors,
155+
// the Windows loader lock).
156+
let arena = fspy_nostd_alloc::arena();
157+
let shm_path = self.shm_id.to_os_c_string_in(&arena).ok_or_else(|| {
158+
io::Error::new(io::ErrorKind::InvalidData, "invalid shared-memory path")
159+
})?;
155160
let mapping = fspy_shm::open(shm_path.as_c_str().as_thin())
156161
.map_err(shm_error_to_io)?
157162
.map()

0 commit comments

Comments
 (0)