Skip to content

Commit 480fa71

Browse files
committed
gdb: update comments
Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent 5dc2313 commit 480fa71

File tree

3 files changed

+35
-43
lines changed

3 files changed

+35
-43
lines changed

src/hyperlight_host/src/hypervisor/gdb/event_loop.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,23 @@ impl run_blocking::BlockingEventLoop for GdbBlockingEventLoop {
5555
VcpuStopReason::EntryPointBp => BaseStopReason::HwBreak(()),
5656
// This is a consequence of the GDB client sending an interrupt signal
5757
// to the target thread
58-
VcpuStopReason::Interrupt => BaseStopReason::SignalWithThread {
59-
tid: (),
58+
VcpuStopReason::Interrupt => {
6059
#[cfg(target_os = "linux")]
61-
signal: Signal(SIGRTMIN() as u8),
60+
let rsp = BaseStopReason::SignalWithThread {
61+
tid: (),
62+
signal: Signal(SIGRTMIN() as u8),
63+
};
64+
65+
// For Windows we don't send a signal, this should not be happen
6266
#[cfg(target_os = "windows")]
63-
// TODO: Handle the signal properly
64-
signal: Signal(53u8),
65-
},
67+
let rsp = BaseStopReason::SignalWithThread {
68+
tid: (),
69+
// This is a placeholder signal, we don't have a real signal
70+
signal: Signal(53u8),
71+
};
72+
73+
rsp
74+
}
6675
VcpuStopReason::Unknown => {
6776
log::warn!("Unknown stop reason received");
6877

@@ -111,8 +120,15 @@ impl run_blocking::BlockingEventLoop for GdbBlockingEventLoop {
111120

112121
#[cfg(target_os = "windows")]
113122
let ret = {
114-
// TODO: Implement Windows signal sending
115-
libc::ESRCH
123+
// pthread_kill is not implemented on Windows
124+
// We need to use a different method to send a signal to the target thread
125+
// For now, we just log a warning and return an error
126+
// NOTE: The way we make a vCPU stop on windows is to make a windows API call
127+
// to suspend the thread, but for that we need a handle to the thread which we don't have
128+
log::warn!("Windows signal sending not implemented");
129+
130+
// For now, we just return an error
131+
-1
116132
};
117133

118134
log::info!("pthread_kill returned {}", ret);

src/hyperlight_host/src/hypervisor/hypervisor_handler.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,9 @@ fn set_up_hypervisor_partition(
901901
#[cfg(target_os = "linux")]
902902
let thread_id = unsafe { pthread_self() };
903903
#[cfg(target_os = "windows")]
904-
// TODO: Implement Windows thread id retrieval
904+
// On Windows, we need to get the thread id from the thread handle because
905+
// we cannot send a signal to the thread without a handle
906+
// This is a placeholder, as we don't have the actual thread handle here
905907
let thread_id = 0;
906908

907909
let gdb_conn = create_gdb_thread(*port, thread_id);

src/hyperlight_host/src/hypervisor/windows_hypervisor_platform.rs

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -498,42 +498,16 @@ impl VMProcessor {
498498

499499
#[cfg(gdb)]
500500
pub(super) fn set_debug_regs(&self, regs: &WHvDebugRegisters) -> Result<()> {
501-
const LEN: usize = 6;
502-
503-
let names: [WHV_REGISTER_NAME; LEN] = [
504-
WHvX64RegisterDr0,
505-
WHvX64RegisterDr1,
506-
WHvX64RegisterDr2,
507-
WHvX64RegisterDr3,
508-
WHvX64RegisterDr6,
509-
WHvX64RegisterDr7,
510-
];
511-
512-
let values: [WHV_REGISTER_VALUE; LEN] = [
513-
WHV_REGISTER_VALUE { Reg64: regs.dr0 },
514-
WHV_REGISTER_VALUE { Reg64: regs.dr1 },
515-
WHV_REGISTER_VALUE { Reg64: regs.dr2 },
516-
WHV_REGISTER_VALUE { Reg64: regs.dr3 },
517-
WHV_REGISTER_VALUE { Reg64: regs.dr6 },
518-
WHV_REGISTER_VALUE { Reg64: regs.dr7 },
501+
let registers = vec![
502+
(WHvX64RegisterDr0, WHV_REGISTER_VALUE { Reg64: regs.dr0 }),
503+
(WHvX64RegisterDr1, WHV_REGISTER_VALUE { Reg64: regs.dr1 }),
504+
(WHvX64RegisterDr2, WHV_REGISTER_VALUE { Reg64: regs.dr2 }),
505+
(WHvX64RegisterDr3, WHV_REGISTER_VALUE { Reg64: regs.dr3 }),
506+
(WHvX64RegisterDr6, WHV_REGISTER_VALUE { Reg64: regs.dr6 }),
507+
(WHvX64RegisterDr7, WHV_REGISTER_VALUE { Reg64: regs.dr7 }),
519508
];
520509

521-
let ret_val = unsafe {
522-
WHvSetVirtualProcessorRegisters(
523-
self.get_partition_hdl(),
524-
0,
525-
names.as_ptr(),
526-
LEN as u32,
527-
values.as_ptr(),
528-
)
529-
};
530-
531-
if ret_val.is_err() {
532-
println!("Failed to set debug registers: {:?}", ret_val);
533-
return Err(new_error!("Call to WHvSetVirtualProcessorRegisters failed"));
534-
}
535-
536-
Ok(())
510+
self.set_registers(&registers)
537511
}
538512

539513
#[cfg(gdb)]

0 commit comments

Comments
 (0)