-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy paththread.c
More file actions
47 lines (41 loc) · 938 Bytes
/
Copy paththread.c
File metadata and controls
47 lines (41 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <thread>
#include <assert.h>
#include "thread.h"
#include "process.h"
#include "vm.h"
#include "mm.h"
#include "loop.h"
void
thread_create(thread_t *thread, process_t *process)
{
thread->process = process;
vm_create_vcpu(&process->vm, &thread->vcpu);
}
void
thread_init(thread_t *thread, vcpu_sysregs_t *sysregs, mm_gvirt_t rip, mm_gvirt_t rsp)
{
vcpu_init_sysregs(&thread->vcpu, sysregs);
vcpu_regs_t regs[] = {
VCPU_REGS_ENTRY_SET(RIP, rip),
VCPU_REGS_ENTRY_SET(RSP, rsp),
VCPU_REGS_ENTRY_SET(RDX, 0),
};
vcpu_set_regs(&thread->vcpu, regs, countof(regs));
}
static void
start_thread(thread_t *thread)
{
do {
vcpu_run(&thread->vcpu);
handle_vmexit(thread);
} while (thread->vcpu.in_operation);
}
void
thread_run(thread_t *thread)
{
std::thread t(start_thread, thread);
for (int i = 0; i < 1000000000; i++)
(void)0;
vcpu_stop(&thread->vcpu);
t.join();
}