Skip to content

Commit

Permalink
make cr3_guard non-copyable, but movable
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenny committed Oct 31, 2019
1 parent e2e25b5 commit 408622a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/hvpp/hvpp/lib/cr3_guard.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
// since we don't have control over Windows' internal PFN lock, the return
// value of this function might be unreliable.
//
// Note:
// This class is non-copyable, but movable.
//

namespace detail
{
Expand All @@ -31,8 +34,20 @@ class cr3_guard
: previous_cr3_{ ia32::read<ia32::cr3_t>() }
{ ia32::write<ia32::cr3_t>(::detail::kernel_cr3(new_cr3)); }

cr3_guard(const cr3_guard& other) noexcept = delete;

cr3_guard(cr3_guard&& other) noexcept
: previous_cr3_{ other.previous_cr3_ }
{ other.previous_cr3_.flags = 0; }

~cr3_guard() noexcept
{ ia32::write<ia32::cr3_t>(previous_cr3_); }
{ if (previous_cr3_.flags) ia32::write<ia32::cr3_t>(previous_cr3_); }

cr3_guard& operator=(const cr3_guard& other) noexcept = delete;

cr3_guard& operator=(cr3_guard&& other) noexcept
{ previous_cr3_ = other.previous_cr3_;
other.previous_cr3_.flags = 0; }

private:
ia32::cr3_t previous_cr3_;
Expand Down

0 comments on commit 408622a

Please sign in to comment.