mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-09 00:00:03 +01:00
Set the memsz in the kernel header correctly
The protocol structs should be packed. uHyve works now in single core mode.
This commit is contained in:
parent
f1a58a1059
commit
ee1682fa1a
7 changed files with 45 additions and 101 deletions
|
@ -8,6 +8,10 @@ find_package(rustdoc)
|
|||
find_package(cargo)
|
||||
include(Rust)
|
||||
|
||||
#cargo_dependency(cargo
|
||||
# PACKAGE_NAMES memmap libc nix elf errno inotify byteorder log env_logger
|
||||
# PACKAGE_VERSIONS =0.5.2 =0.2.22 =0.8 =0.0.10 =0.2.3 =0.4 =1 =0.3 =0.3)
|
||||
|
||||
ExternalProject_Add(
|
||||
hermit_proxy
|
||||
DOWNLOAD_COMMAND ""
|
||||
|
@ -17,4 +21,4 @@ ExternalProject_Add(
|
|||
INSTALL_COMMAND ""
|
||||
LOG_BUILD ON)
|
||||
|
||||
install(FILES target/debug/hermit_proxy DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
install(PROGRAMS target/debug/hermit_proxy DESTINATION bin)
|
||||
|
|
65
tools/hermit_proxy/Cargo.lock
generated
65
tools/hermit_proxy/Cargo.lock
generated
|
@ -1,5 +1,5 @@
|
|||
[root]
|
||||
name = "hermit_proxy"
|
||||
name = "hermitcore_proxy"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -13,14 +13,6 @@ dependencies = [
|
|||
"nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "0.7.0"
|
||||
|
@ -60,7 +52,6 @@ version = "0.3.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -120,14 +111,6 @@ name = "log"
|
|||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memmap"
|
||||
version = "0.5.2"
|
||||
|
@ -150,45 +133,6 @@ dependencies = [
|
|||
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "0.1.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "thread-id"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8-ranges"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "void"
|
||||
version = "1.0.2"
|
||||
|
@ -205,7 +149,6 @@ version = "0.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
|
||||
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
|
||||
"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
|
||||
|
@ -220,14 +163,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502"
|
||||
"checksum log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5141eca02775a762cc6cd564d8d2c50f67c0ea3a372cbf1c51592b3e029e10ad"
|
||||
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
|
||||
"checksum memmap 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "46f3c7359028b31999287dae4e5047ddfe90a23b7dca2282ce759b491080c99b"
|
||||
"checksum nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "47e49f6982987135c5e9620ab317623e723bd06738fd85377e8d55f57c8b6487"
|
||||
"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
|
||||
"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
|
||||
"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
|
||||
"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5"
|
||||
"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "hermit_proxy"
|
||||
name = "hermitcore_proxy"
|
||||
version = "0.0.1"
|
||||
authors = ["bytesnake <bytesnake@mailbox.org>"]
|
||||
|
||||
|
@ -12,4 +12,7 @@ errno = "0.2.3"
|
|||
inotify = "0.4"
|
||||
byteorder = "1"
|
||||
log = "0.3"
|
||||
env_logger = "0.3"
|
||||
|
||||
[dependencies.env_logger]
|
||||
version = "0.3"
|
||||
default-features = false
|
||||
|
|
|
@ -82,9 +82,8 @@ impl QEmu {
|
|||
|
||||
let app_port = hermit_env::app_port();
|
||||
if app_port != "" {
|
||||
port_str = format!("tcp:{}::{}", app_port, app_port);
|
||||
args.push("-redir");
|
||||
args.push(&port_str);
|
||||
port_str = format!("{},hostfwd=tcp::{}-:{}", hostfwd,app_port, app_port);
|
||||
args[12] = &port_str;
|
||||
}
|
||||
|
||||
if hermit_env::use_kvm() != "0" {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use libc::{write, read, lseek, exit, open, close, c_int, c_void};
|
||||
use uhyve::kvm_header::{kvm_run, KVM_EXIT_IO, KVM_EXIT_HLT, KVM_EXIT_MMIO,KVM_EXIT_FAIL_ENTRY, KVM_EXIT_INTERNAL_ERROR, KVM_EXIT_SHUTDOWN };
|
||||
use std::ffi::CStr;
|
||||
|
||||
|
||||
const PORT_WRITE: u16 = 0x499;
|
||||
const PORT_OPEN: u16 = 0x500;
|
||||
|
@ -8,37 +10,43 @@ const PORT_READ: u16 = 0x502;
|
|||
const PORT_EXIT: u16 = 0x503;
|
||||
const PORT_LSEEK: u16 = 0x504;
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct Write {
|
||||
fd: c_int,
|
||||
buf: *const u8,
|
||||
length: usize
|
||||
fd: i32,
|
||||
buf: isize,
|
||||
length: isize
|
||||
}
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct Open {
|
||||
name: *const u8,
|
||||
flags: c_int,
|
||||
mode: c_int,
|
||||
ret: c_int
|
||||
name: isize,
|
||||
flags: i32,
|
||||
mode: i32,
|
||||
ret: i32
|
||||
}
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct Close {
|
||||
fd: c_int,
|
||||
ret: c_int
|
||||
fd: i32,
|
||||
ret: i32
|
||||
}
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct Read {
|
||||
fd: c_int,
|
||||
buf: *mut u8,
|
||||
fd: i32,
|
||||
buf: isize,
|
||||
len: usize,
|
||||
ret: isize
|
||||
}
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct LSeek {
|
||||
fd: c_int,
|
||||
offset: usize,
|
||||
whence: c_int
|
||||
fd: i32,
|
||||
whence: i32,
|
||||
offset: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Syscall {
|
||||
Write(*mut Write),
|
||||
Open(*mut Open),
|
||||
|
@ -54,16 +62,15 @@ impl Syscall {
|
|||
unsafe {
|
||||
let ref run = *(mem.as_ptr() as *const kvm_run);
|
||||
|
||||
debug!("{:?}", &mem[0..100]);
|
||||
|
||||
debug!("Exit reason {}", run.exit_reason);
|
||||
|
||||
if run.exit_reason != KVM_EXIT_IO {
|
||||
return Syscall::Other(mem.as_ptr() as *const kvm_run);
|
||||
}
|
||||
|
||||
let offset = mem.as_ptr().offset(run.__bindgen_anon_1.io.data_offset as isize) as isize;
|
||||
|
||||
|
||||
let offset = *((mem.as_ptr().offset(run.__bindgen_anon_1.io.data_offset as isize) as *const isize));
|
||||
|
||||
match run.__bindgen_anon_1.io.port {
|
||||
PORT_WRITE => { Syscall::Write(guest_mem.as_ptr().offset(offset) as *mut Write) },
|
||||
PORT_READ => { Syscall::Read (guest_mem.as_ptr().offset(offset) as *mut Read) },
|
||||
|
@ -78,19 +85,20 @@ impl Syscall {
|
|||
}
|
||||
|
||||
pub unsafe fn run(&self, guest_mem: *mut u8) {
|
||||
debug!("{:?}", *self);
|
||||
|
||||
match *self {
|
||||
Syscall::Write(obj) => {
|
||||
//let Write { fd, buf, length } = *write;
|
||||
(*obj).length = write((*obj).fd, guest_mem.offset((*obj).buf as isize) as *const c_void, (*obj).length) as usize;
|
||||
(*obj).length = write((*obj).fd, guest_mem.offset((*obj).buf) as *const c_void, (*obj).length as usize);
|
||||
},
|
||||
Syscall::Read(obj) => {
|
||||
(*obj).ret = read((*obj).fd, guest_mem.offset((*obj).buf as isize) as *mut c_void, (*obj).len) as isize;
|
||||
(*obj).ret = read((*obj).fd, guest_mem.offset((*obj).buf) as *mut c_void, (*obj).len);
|
||||
},
|
||||
Syscall::Exit(obj) => {
|
||||
exit(*((guest_mem as *mut i32).offset((*obj) as isize)));
|
||||
},
|
||||
Syscall::Open(obj) => {
|
||||
(*obj).ret = open((guest_mem as *const i8).offset((*obj).name as isize), (*obj).flags, (*obj).mode);
|
||||
(*obj).ret = open(guest_mem.offset((*obj).name) as *const i8, (*obj).flags, (*obj).mode);
|
||||
},
|
||||
Syscall::Close(obj) => {
|
||||
if (*obj).ret == 2 {
|
||||
|
@ -98,7 +106,7 @@ impl Syscall {
|
|||
}
|
||||
},
|
||||
Syscall::LSeek(obj) => {
|
||||
(*obj).offset = lseek((*obj).fd, (*obj).offset as i64, (*obj).whence) as usize;
|
||||
(*obj).offset = lseek((*obj).fd, (*obj).offset as i64, (*obj).whence);
|
||||
},
|
||||
Syscall::Other(id) => { match (*id).exit_reason {
|
||||
KVM_EXIT_HLT => panic!("Guest has halted the CPU, this is considered as a normal exit."),
|
||||
|
|
|
@ -205,8 +205,6 @@ impl VirtualCPU {
|
|||
debug!("Set the system to 64bit");
|
||||
self.setup_system_64bit(&mut sregs)?;
|
||||
|
||||
debug!("SREGS {:#?}", sregs);
|
||||
|
||||
self.set_sregs(sregs)?;
|
||||
|
||||
Ok(())
|
||||
|
@ -228,8 +226,6 @@ impl VirtualCPU {
|
|||
*(ptr.offset(gdt::BOOT_DATA)) = gdt_data.as_u64();
|
||||
}
|
||||
|
||||
debug!("{} {} {}", gdt_null.as_u64(), gdt_code.as_u64(), gdt_data.as_u64());
|
||||
|
||||
gdt_code.apply_to_kvm(gdt::BOOT_CODE, &mut code_seg);
|
||||
gdt_data.apply_to_kvm(gdt::BOOT_DATA, &mut data_seg);
|
||||
|
||||
|
|
|
@ -90,12 +90,10 @@ impl VirtualMachine {
|
|||
*(ptr.offset(0x18) as *mut u32) = utils::cpufreq()? / 1000; // CPU frequency
|
||||
*(ptr.offset(0x24) as *mut u32) = 1; // number of used CPUs
|
||||
*(ptr.offset(0x30) as *mut u32) = 0; // apicid (?)
|
||||
*(ptr.offset(0x38) as *mut u64) = header.filesz; //
|
||||
*(ptr.offset(0x38) as *mut u64) = header.memsz; //
|
||||
*(ptr.offset(0x60) as *mut u32) = 1; // NUMA nodes
|
||||
*(ptr.offset(0x94) as *mut u32) = 1; // announce uhyve
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
debug!("Kernel loaded");
|
||||
|
@ -110,7 +108,6 @@ impl VirtualMachine {
|
|||
slot: 0, guest_phys_addr: 0, flags: 0, memory_size: self.mem.len() as u64, userspace_addr: start_ptr
|
||||
};
|
||||
|
||||
debug!("Bla {}", self.mem.len());
|
||||
self.set_user_memory_region(kvm_region)?;
|
||||
self.create_irqchip()?;
|
||||
let vcpu = self.create_vcpu(0)?;
|
||||
|
|
Loading…
Add table
Reference in a new issue