Suspend some host threads that make guest callbacks.

This commit is contained in:
Ben Vanik
2015-09-21 21:24:26 -07:00
parent 4c8634bc31
commit 3fc1d02a09
8 changed files with 25 additions and 8 deletions

View File

@@ -263,6 +263,8 @@ void KernelState::SetExecutableModule(object_ref<UserModule> module) {
}
return 0;
}));
// As we run guest callbacks the debugger must be able to suspend us.
dispatch_thread_->set_can_debugger_suspend(true);
dispatch_thread_->set_name("Kernel Dispatch Thread");
dispatch_thread_->Create();
}

View File

@@ -702,7 +702,11 @@ X_STATUS XThread::Delay(uint32_t processor_mode, uint32_t alertable,
XHostThread::XHostThread(KernelState* kernel_state, uint32_t stack_size,
uint32_t creation_flags, std::function<int()> host_fn)
: XThread(kernel_state, stack_size, 0, 0, 0, creation_flags, false),
host_fn_(host_fn) {}
host_fn_(host_fn) {
// By default host threads are not debugger suspendable. If the thread runs
// any guest code this must be overridden.
can_debugger_suspend_ = false;
}
void XHostThread::Execute() {
XELOGKERNEL(

View File

@@ -125,7 +125,13 @@ class XThread : public XObject {
const CreationParams* creation_params() const { return &creation_params_; }
uint32_t tls_ptr() const { return tls_address_; }
uint32_t pcr_ptr() const { return pcr_address_; }
// True if the thread is created by the guest app.
bool is_guest_thread() const { return guest_thread_; }
// True if the thread should be paused by the debugger.
// All threads that can run guest code must be stopped for the debugger to
// work properly.
bool can_debugger_suspend() const { return can_debugger_suspend_; }
void set_can_debugger_suspend(bool value) { can_debugger_suspend_ = value; }
bool is_running() const { return running_; }
cpu::ThreadState* thread_state() const { return thread_state_; }
@@ -182,7 +188,8 @@ class XThread : public XObject {
uint32_t tls_address_ = 0;
uint32_t pcr_address_ = 0;
cpu::ThreadState* thread_state_ = nullptr;
bool guest_thread_ = false; // Launched into guest code?
bool guest_thread_ = false;
bool can_debugger_suspend_ = true;
bool running_ = false;
std::string name_;