Skip to content

Commit 4bf3cca

Browse files
CopilotCBenoit
andcommitted
Make dump_interfaces non-unsafe and improve safety comments
The dump_interfaces function doesn't impose any safety requirements on callers - all unsafe operations are properly contained in inner unsafe blocks. Updated safety comments to be more descriptive about what operations are being performed rather than just stating "unsafe by contract" Co-authored-by: CBenoit <3809077+CBenoit@users.noreply.github.com>
1 parent 490d319 commit 4bf3cca

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

crates/devolutions-pedm-hook/src/appinfo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,23 @@ pub unsafe fn ai_disable_desktop_rpc_interface() {
142142
unsafe { FUN.get_or_init(init)() }
143143
}
144144

145-
pub unsafe fn dump_interfaces() -> Result<Box<[RpcServerInterfacePointer]>> {
145+
pub fn dump_interfaces() -> Result<Box<[RpcServerInterfacePointer]>> {
146146
// TODO: This is not clean. Add another mutex to guard the actual handles
147147
{
148148
let mut handles = INTERFACE_HANDLES.lock();
149149
handles.clear();
150150
}
151151

152-
// SAFETY: Function is unsafe by contract.
152+
// SAFETY: Calling Windows API function to disable RPC interface.
153153
unsafe { ai_disable_desktop_rpc_interface() };
154154
// SAFETY: Enabling the hook to intercept RPC calls.
155155
if let Err(err) = unsafe { rpc_server_register_if_ex_hook().enable() } {
156-
// SAFETY: Function is unsafe by contract.
156+
// SAFETY: Calling Windows API function to enable RPC interface.
157157
let _ = unsafe { ai_enable_desktop_rpc_interface() };
158158
bail!(err);
159159
}
160160

161-
// SAFETY: Function is unsafe by contract.
161+
// SAFETY: Calling Windows API function to enable RPC interface.
162162
let _ = unsafe { ai_enable_desktop_rpc_interface() };
163163
// SAFETY: Disabling the hook after capturing interface information.
164164
if let Err(err) = unsafe { rpc_server_register_if_ex_hook().disable() } {

crates/devolutions-pedm-hook/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mod lib_win {
3636
bail!("appinfo.dll not loaded");
3737
}
3838

39-
let mut interfaces = unsafe { dump_interfaces() }?;
39+
let mut interfaces = dump_interfaces()?;
4040

4141
let mut origs = original_handlers().lock();
4242
for interface in interfaces.iter_mut() {
@@ -67,7 +67,7 @@ mod lib_win {
6767
bail!("appinfo.dll not loaded");
6868
}
6969

70-
let mut interfaces = unsafe { dump_interfaces() }?;
70+
let mut interfaces = dump_interfaces()?;
7171

7272
let mut origs = original_handlers().lock();
7373
for interface in interfaces.iter_mut() {

0 commit comments

Comments
 (0)