Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'enhancement-contrib-update' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ppenna committed Sep 24, 2024
2 parents 12b3d56 + 095a6f9 commit 6951298
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 93 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "nvx"
version = "0.4.2"
version = "0.4.3"
license-file = "LICENSE.txt"
edition = "2021"
authors = ["The Maintainers of Nanvix"]
Expand All @@ -14,7 +14,9 @@ homepage = "https://github.com/nanvix"
crate-type = ["lib"]

[dependencies]
kcall = { git = "https://github.com/nanvix/kcall", branch = "releases/v2.3.1" }
kernel = { git = "https://github.com/nanvix/kernel", branch = "releases/v0.7.0", features = [
"kcall",
] }
talc = "4.4.1"
spin = "0.9.8"

Expand Down
2 changes: 1 addition & 1 deletion src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// Exports
//==================================================================================================

pub use ::kcall::debug::*;
pub use ::sys::kcall::debug::debug;
8 changes: 7 additions & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
// Exports
//==================================================================================================

pub use ::kcall::event::*;
pub use ::sys::{
event::*,
kcall::event::{
evctrl,
resume,
},
};
8 changes: 4 additions & 4 deletions src/ipc/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
//==================================================================================================

use ::core::mem;
use ::kcall::{
ipc::Message,
sys::error::{
use ::sys::{
error::{
Error,
ErrorCode,
},
ipc::Message,
};

//==================================================================================================
Expand Down Expand Up @@ -74,7 +74,7 @@ pub struct SystemMessage {
pub payload: [u8; Self::PAYLOAD_SIZE],
}

::kcall::sys::static_assert_size!(SystemMessage, Message::PAYLOAD_SIZE);
::sys::static_assert_size!(SystemMessage, Message::PAYLOAD_SIZE);

impl SystemMessage {
/// Size of payload.
Expand Down
10 changes: 8 additions & 2 deletions src/ipc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ mod message;
// Exports
//==================================================================================================

pub use ::kcall::ipc::*;
pub use message::{
pub use self::message::{
SystemMessage,
SystemMessageHeader,
};
pub use ::sys::{
ipc::*,
kcall::ipc::{
recv,
send,
},
};
17 changes: 5 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern crate alloc;
//==================================================================================================

/// Architecture-specific symbols.
pub use ::kcall::arch;
pub use ::sys::kcall::arch;

/// Debug facilities.
pub mod debug;
Expand All @@ -42,7 +42,7 @@ pub mod event;
pub mod ipc;

/// System configuration.
pub use ::kcall::sys;
pub use ::sys;

/// Memory management kernel calls.
pub mod mm;
Expand All @@ -66,7 +66,7 @@ macro_rules! log{
#[no_mangle]
pub extern "C" fn _start() -> ! {
extern "Rust" {
fn main() -> Result<(), ::kcall::sys::error::Error>;
fn main() -> Result<(), ::sys::error::Error>;
}

// Initializes the system runtime.
Expand All @@ -82,15 +82,8 @@ pub extern "C" fn _start() -> ! {
cleanup();

// Exits the runtime.
if let Err(e) = ::kcall::pm::exit(status) {
panic!("failed to exit process manager daemon: {:?}", e);
}

loop {
unsafe {
::core::hint::unreachable_unchecked();
}
}
let Err(e) = ::sys::kcall::pm::exit(status);
panic!("failed to exit process manager daemon: {:?}", e);
}

/// Initializes system runtime.
Expand Down
2 changes: 1 addition & 1 deletion src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Logger;

impl fmt::Write for Logger {
fn write_str(&mut self, s: &str) -> fmt::Result {
let _ = ::kcall::debug::debug(s.as_ptr(), s.len());
let _ = ::sys::kcall::debug::debug(s.as_ptr(), s.len());
Ok(())
}
}
2 changes: 1 addition & 1 deletion src/mm/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ::alloc::alloc::{
Layout,
};
use ::core::ptr;
use ::kcall::sys::error::{
use ::sys::error::{
Error,
ErrorCode,
};
Expand Down
49 changes: 31 additions & 18 deletions src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ mod allocator;
// Imports
//==================================================================================================

use ::kcall::sys::error::Error;
use ::sys::error::Error;

//==================================================================================================
// Exports
//==================================================================================================

pub use ::kcall::mm::*;
pub use ::sys::{
kcall::mm::{
mmap,
munmap,
},
mm::*,
};

//==================================================================================================
// Constants
//==================================================================================================

/// Heap size (in bytes). This value was chosen arbitrarily.
#[cfg(feature = "allocator")]
const HEAP_SIZE: usize = 4 * ::kcall::sys::constants::MEGABYTE;
const HEAP_SIZE: usize = 4 * ::sys::constants::MEGABYTE;

//==================================================================================================
// Standalone Functions
Expand All @@ -37,27 +43,28 @@ pub fn init() -> Result<(), Error> {
#[cfg(feature = "allocator")]
{
use crate::mm::allocator;
use ::kcall::{
use ::sys::{
arch::mem,
mm,
pm::ProcessIdentifier,
sys::config::memory_layout,
config::memory_layout,
kcall::{
self,
},
pm::{
Capability,
ProcessIdentifier,
},
};

let pid: ProcessIdentifier = kcall::pm::getpid()?;

// Acquire memory management capability.
::kcall::pm::capctl(kcall::pm::Capability::MemoryManagement, true)?;
kcall::pm::capctl(Capability::MemoryManagement, true)?;

// Map underlying pages for the heap.
let start: usize = memory_layout::USER_HEAP_BASE.into_raw_value();
let end: usize = start + HEAP_SIZE;
for vaddr in (start..end).step_by(mem::PAGE_SIZE) {
::kcall::mm::mmap(
pid,
VirtualAddress::from_raw_value(vaddr)?,
mm::AccessPermission::RDWR,
)?;
kcall::mm::mmap(pid, VirtualAddress::from_raw_value(vaddr)?, AccessPermission::RDWR)?;

// Zero page.
unsafe {
Expand All @@ -76,10 +83,16 @@ pub fn init() -> Result<(), Error> {
pub fn cleanup() -> Result<(), Error> {
#[cfg(feature = "allocator")]
{
use ::kcall::{
use ::sys::{
arch::mem,
pm::ProcessIdentifier,
sys::config::memory_layout,
config::memory_layout,
kcall::{
self,
},
pm::{
Capability,
ProcessIdentifier,
},
};

let pid: ProcessIdentifier = kcall::pm::getpid()?;
Expand All @@ -88,11 +101,11 @@ pub fn cleanup() -> Result<(), Error> {
let start: usize = memory_layout::USER_HEAP_BASE.into_raw_value();
let end: usize = start + HEAP_SIZE;
for vaddr in (start..end).step_by(mem::PAGE_SIZE) {
::kcall::mm::munmap(pid, VirtualAddress::from_raw_value(vaddr)?)?;
kcall::mm::munmap(pid, VirtualAddress::from_raw_value(vaddr)?)?;
}

// Release memory management capability.
::kcall::pm::capctl(kcall::pm::Capability::MemoryManagement, false)?;
kcall::pm::capctl(Capability::MemoryManagement, false)?;
}
Ok(())
}
20 changes: 10 additions & 10 deletions src/pm/message/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ use ::core::{
ffi::CStr,
mem,
};
use ::kcall::{
use ::sys::{
error::{
Error,
ErrorCode,
},
ipc::{
Message,
MessageType,
},
pm::ProcessIdentifier,
sys::error::{
Error,
ErrorCode,
},
};

//==================================================================================================
Expand All @@ -48,7 +48,7 @@ pub struct LookupMessage {
}

// NOTE: The size of a lookup message must match the size of a process management message payload.
::kcall::sys::static_assert_size!(LookupMessage, ProcessManagementMessage::PAYLOAD_SIZE);
::sys::static_assert_size!(LookupMessage, ProcessManagementMessage::PAYLOAD_SIZE);

///
/// # Description
Expand All @@ -64,7 +64,7 @@ pub struct LookupResponseMessage {
}

// NOTE: The size of a lookup response message must match the size of a process management message payload.
::kcall::sys::static_assert_size!(LookupResponseMessage, ProcessManagementMessage::PAYLOAD_SIZE);
::sys::static_assert_size!(LookupResponseMessage, ProcessManagementMessage::PAYLOAD_SIZE);

//==================================================================================================
// Implementations
Expand Down Expand Up @@ -239,7 +239,7 @@ pub fn lookup(name: &str) -> Result<(), Error> {
);

// FIXME: this should not be required.
let mypid = ::kcall::pm::getpid()?;
let mypid = ::sys::kcall::pm::getpid()?;

// Construct a system message.
let system_message: SystemMessage =
Expand All @@ -254,7 +254,7 @@ pub fn lookup(name: &str) -> Result<(), Error> {
);

// Send IPC message.
::kcall::ipc::send(&ipc_message)
::sys::kcall::ipc::send(&ipc_message)
}

///
Expand Down Expand Up @@ -298,5 +298,5 @@ pub fn lookup_response(
);

// Send IPC message.
::kcall::ipc::send(&ipc_message)
::sys::kcall::ipc::send(&ipc_message)
}
4 changes: 2 additions & 2 deletions src/pm/message/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use crate::ipc::SystemMessage;
use ::core::mem;
use ::kcall::sys::error::{
use ::sys::error::{
Error,
ErrorCode,
};
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct ProcessManagementMessage {
}

// NOTE: the size of a process management message must match the size of a system message payload.
::kcall::sys::static_assert_size!(ProcessManagementMessage, SystemMessage::PAYLOAD_SIZE);
::sys::static_assert_size!(ProcessManagementMessage, SystemMessage::PAYLOAD_SIZE);

impl ProcessManagementMessage {
/// Size of payload.
Expand Down
2 changes: 1 addition & 1 deletion src/pm/message/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct ShutdownMessage {
}

// NOTE: the size of a shutdown message must match the size of a process management message payload.
::kcall::sys::static_assert_size!(ShutdownMessage, ProcessManagementMessage::PAYLOAD_SIZE);
::sys::static_assert_size!(ShutdownMessage, ProcessManagementMessage::PAYLOAD_SIZE);

//==================================================================================================
// Implementations
Expand Down
18 changes: 9 additions & 9 deletions src/pm/message/signup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ use ::core::{
ffi::CStr,
mem,
};
use ::kcall::{
use ::sys::{
error::{
Error,
ErrorCode,
},
ipc::{
Message,
MessageType,
},
pm::ProcessIdentifier,
sys::error::{
Error,
ErrorCode,
},
};

//==================================================================================================
Expand All @@ -49,7 +49,7 @@ pub struct SignupMessage {
}

// NOTE: The size of a signup message must match the size of a process management message payload.
::kcall::sys::static_assert_size!(SignupMessage, ProcessManagementMessage::PAYLOAD_SIZE);
::sys::static_assert_size!(SignupMessage, ProcessManagementMessage::PAYLOAD_SIZE);

///
/// # Description
Expand All @@ -66,7 +66,7 @@ pub struct SignupResponseMessage {
}

// NOTE: The size of a signup response message must match the size of a process management message payload.
::kcall::sys::static_assert_size!(SignupResponseMessage, ProcessManagementMessage::PAYLOAD_SIZE);
::sys::static_assert_size!(SignupResponseMessage, ProcessManagementMessage::PAYLOAD_SIZE);

//==================================================================================================
// Implementations
Expand Down Expand Up @@ -259,7 +259,7 @@ pub fn signup(pid: ProcessIdentifier, name: &str) -> Result<(), Error> {
Message::new(pid, ProcessIdentifier::PROCD, MessageType::Ipc, system_message.into_bytes());

// Send IPC message.
::kcall::ipc::send(&ipc_message)
::sys::kcall::ipc::send(&ipc_message)
}

///
Expand Down Expand Up @@ -304,5 +304,5 @@ pub fn signup_response(
);

// Send IPC message.
::kcall::ipc::send(&ipc_message)
::sys::kcall::ipc::send(&ipc_message)
}
Loading

0 comments on commit 6951298

Please sign in to comment.