예제 #1
0
PRIVATE inline
bool NO_INSTRUMENT
Switch_lock::set_lock_owner(Context *o)
{
  bool have_no_locks = access_once(&o->_lock_cnt) < 1;

  if (have_no_locks)
    {
      assert_kdb (current_cpu() == o->home_cpu());
      for (;;)
        {
          if (EXPECT_FALSE(access_once(&o->_running_under_lock)))
            continue;
          if (EXPECT_TRUE(mp_cas(&o->_running_under_lock, Mword(false), Mword(true))))
            break;
        }
    }
  else
    assert_kdb (o->_running_under_lock);

  Mem::mp_wmb();

  if (EXPECT_FALSE(!mp_cas(&_lock_owner, Mword(0), Address(o))))
    {
      if (have_no_locks)
        {
          Mem::mp_wmb();
          write_now(&o->_running_under_lock, Mword(false));
        }
      return false;
    }

  return true;
}
// -------------------------------------------------------------------------
IMPLEMENTATION [vmx && !64bit]:

IMPLEMENT inline
void
Vm_vmx_ept::Epte_ptr::set(Unsigned64 v)
{
  // this assumes little endian!
  union T
  {
    Unsigned64 l;
    Unsigned32 u[2];
  };

  T *t = (T*)e;

  write_now(&t->u[0], Unsigned32(0));
  write_now(&t->u[1], Unsigned32(v >> 32));
  write_now(&t->u[0], Unsigned32(v));
}
    bool add_attribs(Page::Attr attr)
    {
      typedef L4_fpage::Rights R;

      if (attr.rights & R::WX())
        {
          Unsigned64 a = 0;
          if (attr.rights & R::W())
            a = 2;

          if (attr.rights & R::X())
            a |= 4;

          auto p = access_once(e);
          auto o = p;
          p |= a;
          if (o != p)
            {
              write_now(e, p);
              return true;
            }
        }
      return false;
    }
// -------------------------------------------------------------------------
IMPLEMENTATION [vmx && 64bit]:

IMPLEMENT inline
void
Vm_vmx_ept::Epte_ptr::set(Unsigned64 v) { write_now(e, v); }