Skip to content

Commit

Permalink
add hypervisor::is_started() method
Browse files Browse the repository at this point in the history
Also, fixes bugcheck on DriverUnload.
  • Loading branch information
wbenny committed Oct 3, 2018
1 parent b66a439 commit 2bf148f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/hvpp/hvpp/hypervisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ auto hypervisor::initialize() noexcept -> error_code_t
vcpu_list_ = new vcpu_t[mp::cpu_count()];
handler_ = nullptr;
check_passed_ = false;
started_ = false;

if (!vcpu_list_)
{
Expand All @@ -47,12 +48,14 @@ void hypervisor::destroy() noexcept
delete[] vcpu_list_;
vcpu_list_ = nullptr;
check_passed_ = false;
started_ = false;
}
}

void hypervisor::start(vmexit_handler* handler) noexcept
{
hvpp_assert(vcpu_list_ && check_passed_ && handler);
hvpp_assert(!started_);

handler_ = handler;

Expand All @@ -61,15 +64,31 @@ void hypervisor::start(vmexit_handler* handler) noexcept
#else
mp::ipi_call(this, &hypervisor::start_ipi_callback);
#endif

started_ = true;
}

void hypervisor::stop() noexcept
{
hvpp_assert(started_);

if (!started_)
{
return;
}

#ifdef HVPP_SINGLE_VCPU
single_cpu_call(stop_ipi_callback);
#else
mp::ipi_call(this, &hypervisor::stop_ipi_callback);
#endif

started_ = false;
}

bool hypervisor::is_started() const noexcept
{
return started_;
}

//
Expand Down
3 changes: 3 additions & 0 deletions src/hvpp/hvpp/hypervisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class hypervisor
void start(vmexit_handler* handler) noexcept;
void stop() noexcept;

bool is_started() const noexcept;

private:
bool check_cpu_features() noexcept;

Expand All @@ -27,6 +29,7 @@ class hypervisor
vcpu_t* vcpu_list_;
vmexit_handler* handler_;
bool check_passed_;
bool started_;
};

}
6 changes: 5 additions & 1 deletion src/hvppdrv/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ namespace driver
//
if (hypervisor_)
{
hypervisor_->stop();
if (hypervisor_->is_started())
{
hypervisor_->stop();
}

hypervisor_->destroy();
delete hypervisor_;
}
Expand Down

0 comments on commit 2bf148f

Please sign in to comment.