Skip to content

Commit a61d548

Browse files
chore: resolve copilot comments
1 parent 1af6f82 commit a61d548

File tree

6 files changed

+31
-33
lines changed

6 files changed

+31
-33
lines changed

opentmk/src/arch/x86_64/interrupt_handler_register.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use x86_64::structures::idt::PageFaultErrorCode;
99
static mut COMMON_HANDLER: fn(InterruptStackFrame, u8) = common_handler;
1010
static COMMON_HANDLER_MUTEX: Mutex<()> = Mutex::new(());
1111

12-
#[unsafe(no_mangle)]
12+
#[no_mangle]
1313
fn abstraction_handle(stack_frame: InterruptStackFrame, interrupt: u8) {
1414
// SAFETY: COMMON_HANDLER is only set via set_common_handler which is protected by a mutex.
1515
unsafe { (COMMON_HANDLER)(stack_frame, interrupt) };

opentmk/src/platform/hyperv/arch/aarch64/hypercall.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ impl HvCall {
2929
.expect("size of start_virtual_processor header is not correct");
3030

3131
let output = self.dispatch_hvcall(hvdef::HypercallCode::HvCallStartVirtualProcessor, None);
32-
match output.result() {
33-
Ok(()) => Ok(()),
34-
err => panic!("Failed to start virtual processor: {:?}", err),
35-
}
32+
output.result()
3633
}
3734

3835
/// Enables a VTL for a specific virtual processor (VP) on aarch64.
@@ -55,10 +52,7 @@ impl HvCall {
5552
_ = header.write_to_prefix(self.input_page().buffer.as_mut_slice());
5653

5754
let output = self.dispatch_hvcall(hvdef::HypercallCode::HvCallEnableVpVtl, None);
58-
match output.result() {
59-
Ok(()) | Err(hvdef::HvError::VtlAlreadyEnabled) => Ok(()),
60-
err => err,
61-
}
55+
output.result()
6256
}
6357

6458
/// Placeholder for VTL call on aarch64.

opentmk/src/platform/hyperv/arch/x86_64/hypercall.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ impl HvCall {
5454
.expect("size of start_virtual_processor header is not correct");
5555

5656
let output = self.dispatch_hvcall(hvdef::HypercallCode::HvCallStartVirtualProcessor, None);
57-
match output.result() {
58-
Ok(()) => Ok(()),
59-
err => panic!("Failed to start virtual processor: {:?}", err),
60-
}
57+
output.result()
6158
}
6259

6360
/// Enables a VTL for a specific virtual processor (VP) on x86_64.
@@ -80,10 +77,7 @@ impl HvCall {
8077
.expect("size of enable_vp_vtl header is not correct");
8178

8279
let output = self.dispatch_hvcall(hvdef::HypercallCode::HvCallEnableVpVtl, None);
83-
match output.result() {
84-
Ok(()) | Err(hvdef::HvError::VtlAlreadyEnabled) => Ok(()),
85-
err => err,
86-
}
80+
output.result()
8781
}
8882

8983
/// Retrieves the current VTL context by reading the necessary registers.

opentmk/src/tests/hyperv/hv_register_intercept.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ where
7979
tmk_assert!(r.is_ok(), "get_register should succeed to read Control register");
8080

8181
let reg_values = r.unwrap();
82-
tmk_assert!(reg_values == 0x0000000000001000, format!("register value should be 0x0000000000000800, got {:x}", reg_values));
82+
tmk_assert!(reg_values == 0x0000000000001000, format!("register value should be 0x0000000000001000, got {:x}", reg_values));
8383

8484
log::info!("Switching to VTL0: attempting to read a protected register to verify security enforcement and intercept handling.");
8585

opentmk/src/tests/hyperv/test_helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// Licensed under the MIT License.
33

44
#[macro_export]
5-
/// Generates a function that calls the given symbol saving and restoring all registers around the call.
5+
/// Generates a function that calls the given symbol saving and restoring general purpose registers around the call.
66
macro_rules! create_function_with_restore {
77
($func_name:ident, $symbol:ident) => {
88
#[inline(never)]
99
// avoiding inline for debuggability in release builds.
1010
fn $func_name() {
11-
// SAFETY: we are calling a function pointer and restoring all registers.
11+
// SAFETY: we are calling a function pointer and restoring general purpose registers.
1212
unsafe {
1313
asm!("
1414
push rax

support/nostd_spin_channel/src/lib.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,30 @@ impl<T> Receiver<T> {
186186
/// Tries to receive an element from the front of the queue while blocking
187187
/// Returns Ok(value) if successful, Err(RecvError) otherwise
188188
pub fn recv(&self) -> Result<T, RecvError> {
189-
// Use a separate scope for the lock to ensure it's released promptly
190-
let result = {
191-
let mut buffer = self.inner.buffer.lock();
192-
buffer.pop_front()
193-
};
194-
match result {
195-
Some(val) => Ok(val),
196-
None => {
197-
// Check if there are any senders left
198-
if self.inner.senders.load(Ordering::SeqCst) == 0 {
199-
Err(RecvError::Disconnected)
200-
} else {
201-
Err(RecvError::Empty)
189+
loop {
190+
// Use a separate scope for the lock to ensure it's released promptly
191+
let result = {
192+
let mut buffer = self.inner.buffer.lock();
193+
buffer.pop_front()
194+
};
195+
let r = match result {
196+
Some(val) => Ok(val),
197+
None => {
198+
// Check if there are any senders left
199+
if self.inner.senders.load(Ordering::SeqCst) == 0 {
200+
Err(RecvError::Disconnected)
201+
} else {
202+
Err(RecvError::Empty)
203+
}
202204
}
205+
};
206+
207+
if let Err(err) = r {
208+
if err != RecvError::Empty {
209+
return Err(err);
210+
}
211+
} else {
212+
return r;
203213
}
204214
}
205215
}

0 commit comments

Comments
 (0)