]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/thread-vcpu.cpp
73276fd5236919e24f6b85e52393ea4f5b77429b
[l4.git] / kernel / fiasco / src / kern / thread-vcpu.cpp
1 IMPLEMENTATION:
2
3 #include "logdefs.h"
4 #include "task.h"
5 #include "vcpu.h"
6
7 PUBLIC inline NEEDS["task.h"]
8 void
9 Thread::vcpu_set_user_space(Task *t)
10 {
11   assert_kdb (current() == this);
12   if (t)
13     t->inc_ref();
14
15   Task *old = static_cast<Task*>(_space.vcpu_user());
16   _space.vcpu_user(t);
17
18   if (old)
19     {
20       if (!old->dec_ref())
21         {
22           rcu_wait();
23           delete old;
24         }
25     }
26 }
27
28 PUBLIC inline NEEDS["logdefs.h", "vcpu.h"]
29 bool
30 Thread::vcpu_pagefault(Address pfa, Mword err, Mword ip)
31 {
32   (void)ip;
33   Vcpu_state *vcpu = vcpu_state().access();
34   if (vcpu_pagefaults_enabled(vcpu))
35     {
36       spill_user_state();
37       vcpu_enter_kernel_mode(vcpu);
38       LOG_TRACE("VCPU events", "vcpu", this, Vcpu_log,
39           l->type = 3;
40           l->state = vcpu->_saved_state;
41           l->ip = ip;
42           l->sp = pfa;
43           l->space = vcpu_user_space() ? static_cast<Task*>(vcpu_user_space())->dbg_id() : ~0;
44           );
45       vcpu->_ts.set_pagefault(pfa, err);
46       vcpu_save_state_and_upcall();
47       return true;
48     }
49
50   return false;
51 }
52
53