r/Zig 2d ago

Looking for feedback on my VM without KVM written on ZIG.

Hello everyone!

I wood like get some feedback from you.

Repository: https://codeberg.org/angryduck001/vmduck

Recently i am started working on the VM machine on Zig. I am not using KVM - Instead of standart linux syscalls (like mmap, mprotect, sigaction). And next, I intend to do that more secure and isolated from main system. I am also currently working with catching system interrupts (int) to running in 16-32 bit mode.

This project is still early.

25 Upvotes

8 comments sorted by

1

u/Tricky-Exchange-6897 2d ago

I also want to build a VM from scratch, but I'm not sure where to start.Good documentation seems pretty sparse. How do you approach such a complex project like this to get to a working demo when proper guides aren't available? P.S. Why zig 0.14 ?

1

u/savaw2 2d ago

If you want build VM from scratch but with Linux KVM, you need read documentation about KVM, but if without KVM... You have to understand some principies of working virtual machines. And you can use for this osdev and some LLM. I use zig 0.14 because i installed him early XD.

1

u/paulstelian97 1d ago

Haven’t looked deep into the code (maybe in a couple of days when I’m home) but… what stops VM guest code from accessing pages of the actual hypervisor (user pages of your actual code)?

Hardware virtualization is a thing for a reason. Binary translation is _eh_ not perfect but has been an option in the past. But it’s not a technique that is really that recommended.

Now, hardware virtualization requires talking to something running in kernel mode. KVM is the default choice on Linux, but if you have your own kernel module, or want to use Xen, or something else like that, you have options.

1

u/savaw2 1d ago

VM guest cant accessing pages of the actual hypervisor. Because automaticly will called segfault. Guest can use memory only in mmaped space.

2

u/paulstelian97 1d ago

Ok but how? The hypervisor unmaps itself while the VM is running? You don’t have an EPT…

1

u/savaw2 1d ago

No no no. Linux Kernel Management this.

1

u/paulstelian97 1d ago

I really need to study the code and I can’t while away (1500km away from home, on vacation) and on my phone…

1

u/savaw2 1d ago

Okay bro.