Skip to content

Commit 7a19844

Browse files
committed
init
1 parent 2daccd2 commit 7a19844

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+2866
-477
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
uftrace*
22
*.profile
3-
*dat.cpu*
3+
*dat.cpu*
4+
.out
5+
Tests
6+
lib.zip
7+
*.out

.vscode/settings.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,43 @@
1717
"ranges": "cpp",
1818
"iostream": "cpp",
1919
"deque": "cpp",
20-
"string": "cpp"
20+
"string": "cpp",
21+
"array": "cpp",
22+
"bit": "cpp",
23+
"cctype": "cpp",
24+
"clocale": "cpp",
25+
"cmath": "cpp",
26+
"compare": "cpp",
27+
"concepts": "cpp",
28+
"cstdarg": "cpp",
29+
"cstddef": "cpp",
30+
"cstdio": "cpp",
31+
"cstdlib": "cpp",
32+
"ctime": "cpp",
33+
"cwchar": "cpp",
34+
"cwctype": "cpp",
35+
"list": "cpp",
36+
"map": "cpp",
37+
"exception": "cpp",
38+
"algorithm": "cpp",
39+
"functional": "cpp",
40+
"iterator": "cpp",
41+
"memory_resource": "cpp",
42+
"ratio": "cpp",
43+
"string_view": "cpp",
44+
"system_error": "cpp",
45+
"tuple": "cpp",
46+
"type_traits": "cpp",
47+
"utility": "cpp",
48+
"initializer_list": "cpp",
49+
"iosfwd": "cpp",
50+
"limits": "cpp",
51+
"new": "cpp",
52+
"stdexcept": "cpp",
53+
"streambuf": "cpp",
54+
"typeinfo": "cpp",
55+
"stop_token": "cpp",
56+
"thread": "cpp",
57+
"cinttypes": "cpp"
2158
}
2259
}

a.out

4.65 KB
Binary file not shown.

conf.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/mumu/create_shared_memory

107 KB
Binary file not shown.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <iostream>
2+
#include <list>
3+
#include <fstream>
4+
#include <sys/ioctl.h>
5+
6+
#include "../src/hypervisor/kvm/kvm.h"
7+
#include "../src/hypervisor/kvm/vm.h"
8+
#include "../src/hypervisor/kvm/vcpu.h"
9+
#include "../src/hypervisor/kvm/modes.h"
10+
#include "../src/xml/xml_parser.h"
11+
12+
using namespace std;
13+
14+
void *mumu_mem_thread(void *_mem)
15+
{
16+
char *mem = (char *)_mem;
17+
while (1)
18+
{
19+
uint64_t memval = 0;
20+
memcpy(&memval, &mem[1024], 8);
21+
cout << memval << endl;
22+
sleep(1);
23+
}
24+
}
25+
26+
int main()
27+
{
28+
KVM *_kvm = new KVM();
29+
_kvm->init();
30+
31+
VM *vm = new VM(_kvm);
32+
VM *vm1 = new VM(_kvm);
33+
34+
vm->create_vcpu(0, 0, 0);
35+
vm1->create_vcpu(0, 0, 0);
36+
37+
vm->mem_init();
38+
vm1->mem_init();
39+
40+
kvm_userspace_memory_region mem;
41+
42+
char *mem1 = (char *)mmap(NULL, RAM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
43+
if ((void *)mem1 == MAP_FAILED)
44+
{
45+
perror("ERROR MAP_FAILED");
46+
return -1;
47+
}
48+
49+
mem.flags = 0;
50+
mem.slot = 1;
51+
mem.guest_phys_addr = RAM_SIZE;
52+
mem.memory_size = RAM_SIZE;
53+
mem.userspace_addr = (uint64_t)(mem1);
54+
55+
for (int k = 0; k < 100; k++)
56+
{
57+
mem1[k] = '\0';
58+
}
59+
60+
int ret = ioctl(vm->fd, KVM_SET_USER_MEMORY_REGION, &(mem));
61+
int ret2 = ioctl(vm1->fd, KVM_SET_USER_MEMORY_REGION, &(mem));
62+
63+
if (ret < 0)
64+
{
65+
perror("ERROR KVM_SET_USER_MEMORY_REGION");
66+
return ret;
67+
}
68+
69+
if (ret2 < 0)
70+
{
71+
perror("ERROR KVM_SET_USER_MEMORY_REGION");
72+
return ret;
73+
}
74+
75+
vm->load_binary("/home/musa/Desktop/Tübitak/mumu_visor/Hello World/readwrite/write.bin");
76+
vm1->load_binary("/home/musa/Desktop/Tübitak/mumu_visor/Hello World/readwrite/read.bin");
77+
78+
vm->top_address += 0x200000;
79+
vm1->top_address += 0x200000;
80+
run_long_mode(vm, vm->vcpus[0]);
81+
run_long_mode(vm1, vm1->vcpus[0]);
82+
83+
vm->run_vm();
84+
vm1->run_vm();
85+
pthread_t th1;
86+
pthread_create(&th1, NULL, mumu_mem_thread, mem1);
87+
88+
vm->stop_vm();
89+
vm1->stop_vm();
90+
}

examples/mumu/createvm

93.2 KB
Binary file not shown.

examples/mumu/createvm.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
#include <list>
3+
#include <fstream>
4+
5+
#include "../src/hypervisor/kvm/kvm.h"
6+
#include "../src/hypervisor/kvm/vm.h"
7+
#include "../src/hypervisor/kvm/vcpu.h"
8+
#include "../src/hypervisor/kvm/modes.h"
9+
10+
using namespace std;
11+
12+
13+
int main()
14+
{
15+
KVM *_kvm = new KVM();
16+
_kvm->init();
17+
18+
19+
VM *vm = new VM(_kvm);
20+
vm->create_vcpu(0,0,0);
21+
22+
vm->mem_init();
23+
24+
vm->load_binary("/home/musa/Desktop/Tübitak/mumu_visor/Hello World/c_hello_world/main.bin");
25+
setup_protected_mode(vm->vcpus[0]);
26+
cout << "brad" << endl;
27+
vm->run_vm();
28+
vm->stop_vm();
29+
}

examples/mumu/elf_sampling

782 KB
Binary file not shown.

examples/mumu/elf_sampling.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#include <iostream>
2+
#include <list>
3+
#include <fstream>
4+
5+
#include "../src/hypervisor/kvm/kvm.h"
6+
#include "../src/hypervisor/kvm/vm.h"
7+
#include "../src/hypervisor/kvm/vcpu.h"
8+
#include "../src/hypervisor/kvm/modes.h"
9+
10+
#include "../src/hypervisor/loader/mumu_elf.hpp"
11+
#include "../src/xml/xml_parser_port.h"
12+
13+
#include <inttypes.h>
14+
15+
using namespace std;
16+
17+
struct SAMPLING_PORT{
18+
int port1;
19+
int port2;
20+
int name;
21+
int flip;
22+
long long cc;
23+
};
24+
25+
struct CHANNELS{
26+
int names[10];
27+
int addresses[10];
28+
int size;
29+
};
30+
31+
32+
int main()
33+
{
34+
KVM *_kvm = new KVM();
35+
_kvm->init();
36+
37+
auto xml_parser = new Parser("/home/musa/Desktop/Tübitak/mumu_visor/tests/test_sampling.xml");
38+
auto parsed_vms = xml_parser->parse_vm_structures();
39+
auto parsed_channels = xml_parser->parse_channels();
40+
41+
vector<VM*> vm_list;
42+
for(auto l: parsed_vms) {
43+
VM *vm = new VM(_kvm);
44+
for(auto k = 0; k < l->cores.size(); k++){
45+
vm->create_vcpu(k,l->cores[k]->core_id,l->cores[k]->physical_core_map);
46+
}
47+
vm->mem_init();
48+
load_elf(l->binary_path,vm);
49+
vm->entry_address = get_entry_address(l->binary_path);
50+
l->vm = vm;
51+
vm_list.push_back(vm);
52+
}
53+
54+
vector<char*> shared_memories;
55+
56+
57+
int counter = 0;
58+
for(auto channel: parsed_channels) {
59+
kvm_userspace_memory_region mem;
60+
char* mem1 = (char*)mmap(NULL, RAM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
61+
mem.flags = 0;
62+
mem.slot = counter+1;
63+
mem.guest_phys_addr = channel->source->vm->vm->top_address;
64+
mem.memory_size = 0x200000;
65+
mem.userspace_addr = (uint64_t)(mem1);
66+
67+
auto source_p_address = channel->source->vm->vm->top_address;
68+
69+
70+
auto memory_struct = (SAMPLING_PORT*)mem1;
71+
memory_struct->port2 = 0;
72+
memory_struct->flip = 0;
73+
memory_struct->name = 0;
74+
memory_struct->port1 = 0;
75+
76+
77+
auto channel_struct = (CHANNELS*)(channel->source->vm->vm->mem+SHARED_BASE);
78+
// channel_struct->names[counter] = stoi(channel->source->name.c_str(), NULL,0);
79+
channel_struct->addresses[counter] = channel->source->vm->vm->top_address;
80+
channel_struct->names[counter] = stoi(channel->source->name.c_str());
81+
channel_struct->size = counter + 1;
82+
83+
channel->source->vm->vm->top_address += 0x200000;
84+
85+
int ret = ioctl(channel->source->vm->vm->fd, KVM_SET_USER_MEMORY_REGION, &(mem));
86+
87+
if (ret < 0) {
88+
perror("ERROR KVM_SET_USER_MEMORY_REGION");
89+
return ret;
90+
}
91+
92+
for (auto destination: channel->destinations){
93+
mem.flags = KVM_MEM_READONLY;
94+
mem.guest_phys_addr = destination->vm->vm->top_address;
95+
96+
auto channel_struct = (CHANNELS*)(destination->vm->vm->mem+SHARED_BASE);
97+
// channel_struct->names[counter] = stoi(channel->source->name.c_str(), NULL,0);
98+
channel_struct->addresses[counter] = destination->vm->vm->top_address;
99+
channel_struct->names[counter] = stoi(destination->name.c_str());
100+
channel_struct->size = counter + 1;
101+
102+
destination->vm->vm->top_address += 0x200000;
103+
104+
ret = ioctl(destination->vm->vm->fd, KVM_SET_USER_MEMORY_REGION, &(mem));
105+
if (ret < 0) {
106+
perror("ERROR KVM_SET_USER_MEMORY_REGION");
107+
return ret;
108+
}
109+
}
110+
cout << "Channel created " << endl;
111+
counter ++;
112+
shared_memories.push_back(mem1);
113+
}
114+
115+
for (auto vm : vm_list){
116+
run_long_mode(vm,vm->vcpus[0],vm->entry_address);
117+
}
118+
for (auto vm : vm_list){
119+
vm->run_vm();
120+
}
121+
for (auto vm : vm_list){
122+
vm->stop_vm();
123+
}
124+
}

0 commit comments

Comments
 (0)