Compare commits

...

6 Commits

30 changed files with 506 additions and 46 deletions

30
rust/Cargo.lock generated
View File

@ -17,6 +17,16 @@ dependencies = [
"unicode-segmentation",
]
[[package]]
name = "denali"
version = "0.1.0"
dependencies = [
"mammoth",
"yunq",
"yunq-derive",
"yunqc",
]
[[package]]
name = "linked_list_allocator"
version = "0.10.5"
@ -113,7 +123,7 @@ name = "testbed"
version = "0.1.0"
dependencies = [
"mammoth",
"yellowstone",
"yellowstone-yunq",
"yunq",
]
@ -124,7 +134,7 @@ dependencies = [
"mammoth",
"victoriafalls",
"voyageurs",
"yellowstone",
"yellowstone-yunq",
]
[[package]]
@ -144,7 +154,7 @@ name = "victoriafalls"
version = "0.1.0"
dependencies = [
"mammoth",
"yellowstone",
"yellowstone-yunq",
"yunq",
"yunq-derive",
"yunqc",
@ -155,7 +165,7 @@ name = "voyageurs"
version = "0.1.0"
dependencies = [
"mammoth",
"yellowstone",
"yellowstone-yunq",
"yunq",
"yunq-derive",
"yunqc",
@ -164,6 +174,18 @@ dependencies = [
[[package]]
name = "yellowstone"
version = "0.1.0"
dependencies = [
"denali",
"mammoth",
"victoriafalls",
"voyageurs",
"yellowstone-yunq",
"yunq",
]
[[package]]
name = "yellowstone-yunq"
version = "0.1.0"
dependencies = [
"mammoth",
"yunq",

View File

@ -1,7 +1,7 @@
[workspace]
members = [
"lib/mammoth", "lib/victoriafalls", "lib/voyageurs", "lib/yellowstone", "lib/yunq", "lib/yunq-derive", "sys/teton", "usr/testbed",
members = [ "lib/denali",
"lib/mammoth", "lib/victoriafalls", "lib/voyageurs", "lib/yellowstone", "lib/yunq", "lib/yunq-derive", "sys/teton", "sys/yellowstone", "usr/testbed",
]
resolver = "2"

View File

@ -0,0 +1,12 @@
[package]
name = "denali"
version = "0.1.0"
edition = "2021"
[dependencies]
mammoth = { path = "../mammoth" }
yunq = {path = "../yunq"}
yunq-derive = {path = "../yunq-derive"}
[build-dependencies]
yunqc = {path = "../../../yunq/rust"}

14
rust/lib/denali/build.rs Normal file
View File

@ -0,0 +1,14 @@
use std::fs;
fn main() {
let input_file = "../../../sys/denali/lib/denali/denali.yunq";
println!("cargo::rerun-if-changed={input_file}");
let input = fs::read_to_string(input_file).expect("Failed to read input file");
let code = yunqc::codegen(&input).expect("Failed to generate yunq code.");
let out = std::env::var("OUT_DIR").unwrap() + "/yunq.rs";
fs::write(out, code).expect("Failed to write generated code.");
}

View File

@ -0,0 +1,5 @@
#![no_std]
use core::include;
include!(concat!(env!("OUT_DIR"), "/yunq.rs"));

View File

@ -13,9 +13,7 @@ const ELF_IDENT_64BIT: u8 = 0x2;
const ELF_ENDIAN_LITTLE: u8 = 0x1;
const ELF_ENDIAN_BIG: u8 = 0x2;
const ELF_VERSION_CURRENT: u8 = 0x1;
const ELF_ABI_SYSV: u8 = 0x0;
const ELF_ABI_LINUX: u8 = 0x3;
@ -312,7 +310,10 @@ fn load_elf_program(elf_file: &[u8], vmas: &Capability) -> Result<u64, ZError> {
Ok(header.entry)
}
pub fn spawn_process_from_elf(elf_file: &[u8]) -> Result<Capability, ZError> {
pub fn spawn_process_from_elf_and_init(
elf_file: &[u8],
init_cap: Capability,
) -> Result<Capability, ZError> {
let self_cap = Capability::take_copy(unsafe { init::SELF_PROC_CAP })?;
let port_cap = syscall::port_create()?;
@ -328,8 +329,7 @@ pub fn spawn_process_from_elf(elf_file: &[u8]) -> Result<Capability, ZError> {
new_proc_cap.duplicate(Capability::PERMS_ALL)?,
)?;
port.write_u64_and_cap(crate::init::Z_INIT_SELF_VMAS, new_as_cap)?;
let yellowstone = Capability::take_copy(unsafe { crate::init::INIT_ENDPOINT })?;
port.write_u64_and_cap(crate::init::Z_INIT_ENDPOINT, yellowstone)?;
port.write_u64_and_cap(crate::init::Z_INIT_ENDPOINT, init_cap)?;
let thread_cap = syscall::thread_create(&new_proc_cap)?;
@ -337,3 +337,8 @@ pub fn spawn_process_from_elf(elf_file: &[u8]) -> Result<Capability, ZError> {
Ok(new_proc_cap)
}
pub fn spawn_process_from_elf(elf_file: &[u8]) -> Result<Capability, ZError> {
let yellowstone = Capability::take_copy(unsafe { crate::init::INIT_ENDPOINT })?;
spawn_process_from_elf_and_init(elf_file, yellowstone)
}

View File

@ -6,11 +6,21 @@ use crate::zion::z_cap_t;
pub const Z_INIT_SELF_PROC: u64 = 0x4000_0000;
pub const Z_INIT_SELF_VMAS: u64 = 0x4000_0001;
pub const Z_INIT_ENDPOINT: u64 = 0x4100_0000;
const Z_BOOT_DENALI_VMMO: u64 = 0x4200_0000;
const Z_BOOT_VICTORIA_FALLS_VMMO: u64 = 0x4200_0001;
const Z_BOOT_PCI_VMMO: u64 = 0x4200_0002;
const Z_BOOT_FRAMEBUFFER_INFO_VMMO: u64 = 0x4200_0003;
pub static mut SELF_PROC_CAP: z_cap_t = 0;
pub static mut SELF_VMAS_CAP: z_cap_t = 0;
pub static mut INIT_ENDPOINT: z_cap_t = 0;
// Boot capabilities, are generally only passed to yellowstone.
pub static mut BOOT_DENALI_VMMO: z_cap_t = 0;
pub static mut BOOT_VICTORIA_FALLS_VMMO: z_cap_t = 0;
pub static mut BOOT_PCI_VMMO: z_cap_t = 0;
pub static mut BOOT_FRAMEBUFFER_INFO_VMMO: z_cap_t = 0;
pub fn parse_init_port(port_cap: z_cap_t) {
let init_port = Capability::take(port_cap);
loop {
@ -29,6 +39,10 @@ pub fn parse_init_port(port_cap: z_cap_t) {
Z_INIT_SELF_PROC => SELF_PROC_CAP = caps[0],
Z_INIT_SELF_VMAS => SELF_VMAS_CAP = caps[0],
Z_INIT_ENDPOINT => INIT_ENDPOINT = caps[0],
Z_BOOT_DENALI_VMMO => BOOT_DENALI_VMMO = caps[0],
Z_BOOT_VICTORIA_FALLS_VMMO => BOOT_VICTORIA_FALLS_VMMO = caps[0],
Z_BOOT_PCI_VMMO => BOOT_PCI_VMMO = caps[0],
Z_BOOT_FRAMEBUFFER_INFO_VMMO => BOOT_FRAMEBUFFER_INFO_VMMO = caps[0],
_ => syscall::debug("Unknown Cap in Init"),
}
}

View File

@ -14,6 +14,7 @@ pub mod elf;
pub mod init;
pub mod mem;
pub mod port;
pub mod sync;
pub mod syscall;
pub mod thread;
pub mod zion;

View File

@ -78,6 +78,10 @@ impl MemoryRegion {
pub fn cap(&self) -> &Capability {
&self.mem_cap
}
pub fn duplicate(&self, offset: u64, length: u64) -> Result<Capability, ZError> {
syscall::memory_obj_duplicate(&self.mem_cap, offset, length)
}
}
impl Drop for MemoryRegion {

View File

@ -0,0 +1,19 @@
use crate::{cap::Capability, syscall, zion::ZError};
pub struct Semaphore {
cap: Capability,
}
impl Semaphore {
pub fn new() -> Result<Self, ZError> {
syscall::semaphore_create().map(|cap| Self { cap })
}
pub fn wait(&self) -> Result<(), ZError> {
syscall::semaphone_wait(&self.cap)
}
pub fn signal(&self) -> Result<(), ZError> {
syscall::semaphone_signal(&self.cap)
}
}

View File

@ -167,6 +167,24 @@ pub fn memory_object_inspect(mem_cap: &Capability) -> Result<u64, ZError> {
Ok(mem_size)
}
pub fn memory_obj_duplicate(
mem_cap: &Capability,
base_offset: u64,
length: u64,
) -> Result<Capability, ZError> {
let mut new_cap = 0;
syscall(
zion::kZionMemoryObjectDuplicate,
&zion::ZMemoryObjectDuplicateReq {
vmmo_cap: mem_cap.raw(),
base_offset,
length,
new_vmmo_cap: &mut new_cap,
},
)?;
Ok(Capability::take(new_cap))
}
pub fn address_space_map(vmmo_cap: &Capability) -> Result<u64, ZError> {
let mut vaddr: u64 = 0;
// FIXME: Allow caller to pass these options.
@ -363,3 +381,33 @@ pub fn reply_port_recv(
Ok((num_bytes, num_caps))
}
pub fn semaphore_create() -> Result<Capability, ZError> {
let mut sem_cap: z_cap_t = 0;
syscall(
zion::kZionSemaphoreCreate,
&zion::ZSemaphoreCreateReq {
semaphore_cap: &mut sem_cap,
},
)?;
Ok(Capability::take(sem_cap))
}
pub fn semaphone_signal(sem_cap: &Capability) -> Result<(), ZError> {
syscall(
zion::kZionSemaphoreSignal,
&zion::ZSemaphoreSignalReq {
semaphore_cap: sem_cap.raw(),
},
)
}
pub fn semaphone_wait(sem_cap: &Capability) -> Result<(), ZError> {
syscall(
zion::kZionSemaphoreWait,
&zion::ZSemaphoreWaitReq {
semaphore_cap: sem_cap.raw(),
},
)
}

View File

@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
mammoth = { path = "../mammoth" }
yellowstone = { path = "../yellowstone" }
yellowstone-yunq = { path = "../yellowstone" }
yunq = {path = "../yunq"}
yunq-derive = {path = "../yunq-derive"}

View File

@ -12,8 +12,8 @@ static mut VFS_CLIENT: Option<VFSClient> = None;
fn get_client() -> &'static mut VFSClient {
unsafe {
if let None = VFS_CLIENT {
let endpoint_cap = yellowstone::from_init_endpoint()
.get_endpoint(&yellowstone::GetEndpointRequest {
let endpoint_cap = yellowstone_yunq::from_init_endpoint()
.get_endpoint(&yellowstone_yunq::GetEndpointRequest {
endpoint_name: "victoriafalls".to_string(),
})
.expect("Failed to get VFS endpoint");

View File

@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
mammoth = { path = "../mammoth" }
yellowstone = { path = "../yellowstone" }
yellowstone-yunq = { path = "../yellowstone" }
yunq = {path = "../yunq"}
yunq-derive = {path = "../yunq-derive"}

View File

@ -211,8 +211,8 @@ impl KeyboardListener {
handler,
});
let voyageur_endpoint = yellowstone::from_init_endpoint()
.get_endpoint(&yellowstone::GetEndpointRequest {
let voyageur_endpoint = yellowstone_yunq::from_init_endpoint()
.get_endpoint(&yellowstone_yunq::GetEndpointRequest {
endpoint_name: "voyageurs".to_string(),
})?
.endpoint;

View File

@ -1,5 +1,5 @@
[package]
name = "yellowstone"
name = "yellowstone-yunq"
version = "0.1.0"
edition = "2021"

View File

@ -33,10 +33,16 @@ fn serialize_field(name: &Ident, ind: usize, path: &Path) -> proc_macro2::TokenS
}
}
} else {
panic!(
"Serialization not implemented for: {}",
path.to_token_stream()
)
quote! {
{
let msg_offset = next_extension;
let msg_length = self.#name.serialize(buf, offset + next_extension as usize, caps)? as u32;
next_extension += msg_length;
buf.write_at(yunq::message::field_offset(offset, #ind), msg_offset)?;
buf.write_at(yunq::message::field_offset(offset, #ind) + 4, msg_length)?;
}
}
}
}
@ -62,7 +68,13 @@ fn parse_field(name: &Ident, ind: usize, path: &Path) -> proc_macro2::TokenStrea
let #name = buf.at::<u64>(yunq::message::field_offset(offset, #ind))?;
}
} else {
panic!("Parsing not implemented for: {}", path.into_token_stream());
quote! {
let #name = {
let msg_offset = buf.at::<u32>(yunq::message::field_offset(offset, #ind))? as usize;
#path::parse(buf, offset + msg_offset, caps)?
};
}
}
}

View File

@ -6,7 +6,7 @@ use mammoth::zion::z_cap_t;
use mammoth::zion::ZError;
pub trait YunqServer {
fn server_loop(&self) {
fn server_loop(&mut self) {
loop {
let mut byte_buffer = ByteBuffer::<1024>::new();
let mut cap_buffer = vec![0; 10];
@ -38,8 +38,13 @@ pub trait YunqServer {
}
fn endpoint_cap(&self) -> &Capability;
fn create_client_cap(&self) -> Result<Capability, ZError> {
self.endpoint_cap()
.duplicate(!mammoth::zion::kZionPerm_Read)
}
fn handle_request(
&self,
&mut self,
method_number: u64,
byte_buffer: &mut ByteBuffer<1024>,
cap_buffer: &mut Vec<z_cap_t>,

View File

@ -7,4 +7,4 @@ edition = "2021"
mammoth = { path = "../../lib/mammoth" }
victoriafalls = { path = "../../lib/victoriafalls" }
voyageurs = { path = "../../lib/voyageurs" }
yellowstone = { path = "../../lib/yellowstone" }
yellowstone-yunq = { path = "../../lib/yellowstone" }

View File

@ -1,5 +1,5 @@
use mammoth::{mem::MemoryRegion, zion::ZError};
use yellowstone::FramebufferInfo;
use yellowstone_yunq::FramebufferInfo;
pub struct Framebuffer {
fb_info: FramebufferInfo,

View File

@ -20,7 +20,7 @@ define_entry!();
extern "C" fn main() -> z_err_t {
debug!("Teton Starting");
let yellowstone = yellowstone::from_init_endpoint();
let yellowstone = yellowstone_yunq::from_init_endpoint();
let framebuffer_info = yellowstone
.get_framebuffer_info()
.expect("Failed to get framebuffer info.");

View File

@ -0,0 +1,12 @@
[package]
name = "yellowstone"
version = "0.1.0"
edition = "2021"
[dependencies]
mammoth = { path = "../../lib/mammoth" }
denali = { path = "../../lib/denali" }
victoriafalls = { path = "../../lib/victoriafalls" }
voyageurs = { path = "../../lib/voyageurs" }
yellowstone-yunq = { path = "../../lib/yellowstone" }
yunq = { path = "../../lib/yunq" }

View File

@ -0,0 +1,62 @@
#![no_std]
#![no_main]
extern crate alloc;
use mammoth::{
cap::Capability,
define_entry, elf,
init::BOOT_PCI_VMMO,
mem::MemoryRegion,
zion::{z_cap_t, z_err_t, ZError},
};
use yellowstone_yunq::YellowstoneServer;
use yunq::server::YunqServer;
mod pci;
mod server;
define_entry!();
fn spawn_from_vmmo(vmmo_cap: z_cap_t, server_cap: Capability) -> Result<(), ZError> {
let region = mammoth::mem::MemoryRegion::from_cap(Capability::take(vmmo_cap))?;
elf::spawn_process_from_elf_and_init(region.slice(), server_cap)?;
Ok(())
}
#[no_mangle]
extern "C" fn main() -> z_err_t {
let pci_region = MemoryRegion::from_cap(Capability::take(unsafe { BOOT_PCI_VMMO }))
.expect("Failed to create PCI region");
let context = alloc::rc::Rc::new(
server::YellowstoneServerContext::new(pci_region)
.expect("Failed to create yellowstone context"),
);
let handler = server::YellowstoneServerImpl::new(context.clone());
let server = YellowstoneServer::new(handler).expect("Couldn't create yellowstone server");
let server_thread = server.run_server().expect("Failed to run server");
spawn_from_vmmo(
unsafe { mammoth::init::BOOT_DENALI_VMMO },
server
.create_client_cap()
.expect("Failed to create client cap for denali"),
)
.expect("Failed to spawn denali");
context.wait_denali().expect("Failed to wait for denali");
mammoth::debug!("Denali registered.");
spawn_from_vmmo(
unsafe { mammoth::init::BOOT_VICTORIA_FALLS_VMMO },
server.create_client_cap().unwrap(),
)
.expect("Failed to spawn victoriafalls");
context.wait_victoria_falls().unwrap();
mammoth::debug!("VFS Registered");
server_thread.join().expect("Failed to join thread");
0
}

View File

@ -0,0 +1,122 @@
use mammoth::{cap::Capability, mem::MemoryRegion, zion::ZError};
pub struct PciReader {
memory_region: MemoryRegion,
}
type DevPredicate = fn(u8, u8, u8) -> bool;
impl PciReader {
pub fn new(memory_region: MemoryRegion) -> Self {
Self { memory_region }
}
pub fn get_ahci_region(&self) -> Result<Capability, ZError> {
match self.probe_pci(|class, _, _| class == 0x1) {
Some(m) => Ok(m),
None => Err(ZError::NOT_FOUND),
}
}
fn probe_pci(&self, pred: DevPredicate) -> Option<Capability> {
let base_header = self.pci_header(0, 0, 0);
if (base_header.header_type & 0x80) == 0 {
if let Some(dev) = self.probe_bus(pred, 0) {
return Some(dev);
}
} else {
for fun in 0..8 {
let fun_hdr = self.pci_header(0, 0, fun);
if fun_hdr.vendor_id != 0xFFFF {
if let Some(dev) = self.probe_bus(pred, fun) {
return Some(dev);
}
}
}
}
None
}
fn probe_bus(&self, pred: DevPredicate, bus: u8) -> Option<Capability> {
for dev in 0..0x20 {
if let Some(dev) = self.probe_device(pred, bus, dev) {
return Some(dev);
}
}
None
}
fn probe_device(&self, pred: DevPredicate, bus: u8, dev: u8) -> Option<Capability> {
let device_base_header = self.pci_header(bus, dev, 0);
if device_base_header.vendor_id == 0xFFFF {
return None;
}
if let Some(dev) = self.probe_function(pred, bus, dev, 0) {
return Some(dev);
}
if (device_base_header.header_type & 0x80) != 0 {
for fun in 1..8 {
if let Some(dev) = self.probe_function(pred, bus, dev, fun) {
return Some(dev);
}
}
}
None
}
fn probe_function(&self, pred: DevPredicate, bus: u8, dev: u8, fun: u8) -> Option<Capability> {
let function_header = self.pci_header(bus, dev, fun);
mammoth::debug!(
"PCI Function: {:#x} {:#x} {:#x}",
function_header.class_code,
function_header.subclass,
function_header.prog_interface
);
if pred(
function_header.class_code,
function_header.subclass,
function_header.prog_interface,
) {
mammoth::debug!("Found!");
let offset = pci_header_offset(bus, dev, fun);
Some(
self.memory_region
.duplicate(offset as u64, 0x1000)
.expect("Failed to duplicate PCI cap"),
)
} else {
None
}
}
fn pci_header(&self, bus: u8, dev: u8, fun: u8) -> &PciHeader {
let offset = pci_header_offset(bus, dev, fun);
let header_slice: &[u8] =
&self.memory_region.slice()[offset..offset + size_of::<PciHeader>()];
unsafe { header_slice.as_ptr().cast::<PciHeader>().as_ref().unwrap() }
}
}
#[repr(C, packed)]
struct PciHeader {
vendor_id: u16,
device_id: u16,
command_reg: u16,
status_reg: u16,
revision: u8,
prog_interface: u8,
subclass: u8,
class_code: u8,
cache_line_size: u8,
latency_timer: u8,
header_type: u8,
bist: u8,
}
fn pci_header_offset(bus: u8, dev: u8, fun: u8) -> usize {
((bus as usize) << 20) | ((dev as usize) << 15) | ((fun as usize) << 12)
}

View File

@ -0,0 +1,93 @@
use alloc::rc::Rc;
use alloc::{collections::BTreeMap, string::String};
use mammoth::{cap::Capability, mem::MemoryRegion, zion::ZError};
use yellowstone_yunq::{
AhciInfo, DenaliInfo, Endpoint, FramebufferInfo, GetEndpointRequest, RegisterEndpointRequest,
XhciInfo, YellowstoneServerHandler,
};
use crate::pci::PciReader;
pub struct YellowstoneServerContext {
denali_semaphore: mammoth::sync::Semaphore,
victoria_falls_semaphore: mammoth::sync::Semaphore,
pci_reader: PciReader,
}
impl YellowstoneServerContext {
pub fn new(pci_region: MemoryRegion) -> Result<Self, ZError> {
Ok(Self {
denali_semaphore: mammoth::sync::Semaphore::new()?,
victoria_falls_semaphore: mammoth::sync::Semaphore::new()?,
pci_reader: PciReader::new(pci_region),
})
}
pub fn wait_denali(&self) -> Result<(), ZError> {
self.denali_semaphore.wait()
}
pub fn wait_victoria_falls(&self) -> Result<(), ZError> {
self.victoria_falls_semaphore.wait()
}
}
pub struct YellowstoneServerImpl {
context: Rc<YellowstoneServerContext>,
service_map: BTreeMap<String, Capability>,
}
impl YellowstoneServerImpl {
pub fn new(context: Rc<YellowstoneServerContext>) -> Self {
Self {
context,
service_map: BTreeMap::new(),
}
}
}
impl YellowstoneServerHandler for YellowstoneServerImpl {
fn register_endpoint(&mut self, req: RegisterEndpointRequest) -> Result<(), ZError> {
let signal_denali = req.endpoint_name == "denali";
let signal_vfs = req.endpoint_name == "victoriafalls";
self.service_map
.insert(req.endpoint_name, Capability::take(req.endpoint_capability));
if signal_denali {
self.context.denali_semaphore.signal()?
}
if signal_vfs {
self.context.victoria_falls_semaphore.signal()?
}
Ok(())
}
fn get_endpoint(&mut self, req: GetEndpointRequest) -> Result<Endpoint, ZError> {
match self.service_map.get(&req.endpoint_name) {
Some(cap) => Ok(Endpoint {
endpoint: cap.duplicate(Capability::PERMS_ALL)?.release(),
}),
None => Err(ZError::NOT_FOUND),
}
}
fn get_ahci_info(&mut self) -> Result<AhciInfo, ZError> {
Ok(AhciInfo {
ahci_region: self.context.pci_reader.get_ahci_region()?.release(),
region_length: 0x1000,
})
}
fn get_xhci_info(&mut self) -> Result<XhciInfo, ZError> {
todo!()
}
fn get_framebuffer_info(&mut self) -> Result<FramebufferInfo, ZError> {
todo!()
}
fn get_denali(&mut self) -> Result<DenaliInfo, ZError> {
todo!()
}
}

View File

@ -5,5 +5,5 @@ edition = "2021"
[dependencies]
mammoth = { path = "../../lib/mammoth" }
yellowstone = { path = "../../lib/yellowstone" }
yellowstone-yunq = { path = "../../lib/yellowstone" }
yunq = { path = "../../lib/yunq" }

View File

@ -8,7 +8,7 @@ use mammoth::debug;
use mammoth::define_entry;
use mammoth::thread;
use mammoth::zion::z_err_t;
use yellowstone::GetEndpointRequest;
use yellowstone_yunq::GetEndpointRequest;
define_entry!();
@ -16,7 +16,7 @@ define_entry!();
pub extern "C" fn main() -> z_err_t {
debug!("Testing!");
let yellowstone = yellowstone::from_init_endpoint();
let yellowstone = yellowstone_yunq::from_init_endpoint();
debug!("Get endpoint");

View File

@ -39,7 +39,7 @@ cp /usr/share/limine/limine-bios.sys efi/
cp ../zion/boot/limine.cfg efi/
cp zion/zion efi/
mkdir -p efi/sys
cp sys/yellowstone/yellowstone efi/sys/yellowstone
cp ../sysroot/bin/yellowstone efi/sys/yellowstone
cp sys/denali/denali efi/sys/denali
cp sys/victoriafalls/victoriafalls efi/sys/victoriafalls

View File

@ -82,7 +82,7 @@ fn generate_server_case(method: &Method) -> TokenStream {
(Some(req), Some(_)) => quote! {
#id => {
let req = #req::parse_from_request(byte_buffer, cap_buffer)?;
let resp = self.handler.#name(&req)?;
let resp = self.handler.#name(req)?;
cap_buffer.resize(0, 0);
let resp_len = resp.serialize_as_request(0, byte_buffer, cap_buffer)?;
Ok(resp_len)
@ -91,7 +91,7 @@ fn generate_server_case(method: &Method) -> TokenStream {
(Some(req), None) => quote! {
#id => {
let req = #req::parse_from_request(byte_buffer, cap_buffer)?;
self.handler.#name(&req)?;
self.handler.#name(req)?;
cap_buffer.resize(0, 0);
// TODO: Implement serialization for EmptyMessage so this is less hacky.
yunq::message::serialize_error(byte_buffer, ZError::from(0));
@ -116,13 +116,13 @@ fn generate_server_method(method: &Method) -> TokenStream {
let maybe_resp = method.response.clone().map(|r| ident(&r));
match (maybe_req, maybe_resp) {
(Some(req), Some(resp)) => quote! {
fn #name (&self, req: & #req) -> Result<#resp, ZError>;
fn #name (&mut self, req: #req) -> Result<#resp, ZError>;
},
(Some(req), None) => quote! {
fn #name (&self, req: & #req) -> Result<(), ZError>;
fn #name (&mut self, req: #req) -> Result<(), ZError>;
},
(None, Some(resp)) => quote! {
fn #name (&self) -> Result<#resp, ZError>;
fn #name (&mut self) -> Result<#resp, ZError>;
},
_ => unreachable!(),
}
@ -153,7 +153,7 @@ fn generate_server(interface: &Interface) -> TokenStream {
pub fn run_server(&self) -> Result<Box<thread::Thread>, ZError> {
let thread_entry = |server_ptr: *const c_void| {
let server = unsafe { (server_ptr as *const #server_name<T>).as_ref().expect("Failed to convert to server") };
let server = unsafe { (server_ptr as *mut #server_name<T>).as_mut().expect("Failed to convert to server") };
server.server_loop();
};
thread::Thread::spawn(
@ -169,7 +169,7 @@ fn generate_server(interface: &Interface) -> TokenStream {
}
fn handle_request(
&self,
&mut self,
method_number: u64,
byte_buffer: &mut ByteBuffer<1024>,
cap_buffer: &mut Vec<z_cap_t>,

View File

@ -13,7 +13,7 @@
#include "scheduler/process_manager.h"
#include "scheduler/scheduler.h"
#define K_INIT_DEBUG 0
#define K_INIT_DEBUG 1
namespace {
@ -67,6 +67,9 @@ uint64_t LoadElfProgram(Process& dest_proc, uint64_t base, uint64_t offset) {
reinterpret_cast<Elf64ProgramHeader*>(base + header->phoff);
for (uint64_t i = 0; i < header->phnum; i++) {
Elf64ProgramHeader& program = programs[i];
if (program.type != 1) {
continue;
}
#if K_INIT_DEBUG
dbgln(
"prog: type: {}, flags: {}, offset: {}\n vaddr: {x}, paddr: {x}\n "
@ -74,12 +77,19 @@ uint64_t LoadElfProgram(Process& dest_proc, uint64_t base, uint64_t offset) {
program.type, program.flags, program.offset, program.vaddr,
program.paddr, program.filesz, program.memsz, program.align);
#endif
auto mem_obj = glcr::MakeRefCounted<VariableMemoryObject>(program.memsz);
mem_obj->CopyBytesToObject(base + program.offset, program.filesz);
PANIC_ON_ERR(
dest_proc.vmas()->MapInMemoryObject(
program.vaddr, glcr::StaticCastRefPtr<MemoryObject>(mem_obj)),
"Couldn't map in init program.");
uint64_t page_offset = program.vaddr & 0xFFF;
auto mem_obj =
glcr::MakeRefCounted<VariableMemoryObject>(program.memsz + page_offset);
// Super hacky but if we adjust the offsets to handle a non-aligned page.
mem_obj->CopyBytesToObject(base + program.offset - page_offset,
program.filesz + page_offset);
auto map_res = dest_proc.vmas()->MapInMemoryObject(
program.vaddr - page_offset,
glcr::StaticCastRefPtr<MemoryObject>(mem_obj));
if (map_res != glcr::OK) {
panic("Couldn't map in init program {}", map_res);
}
}
return header->entry;
}