From 4adf50149438e1d904231c30545ec3603553d806 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Penna Date: Tue, 24 Sep 2024 15:03:11 -0700 Subject: [PATCH 1/2] [contrib] E: Updating kcall --- Cargo.toml | 4 +++- src/debug.rs | 2 +- src/event.rs | 8 ++++++- src/ipc/message.rs | 8 +++---- src/ipc/mod.rs | 10 ++++++-- src/lib.rs | 17 ++++--------- src/logging.rs | 2 +- src/mm/allocator.rs | 2 +- src/mm/mod.rs | 49 ++++++++++++++++++++++++-------------- src/pm/message/lookup.rs | 20 ++++++++-------- src/pm/message/message.rs | 4 ++-- src/pm/message/shutdown.rs | 2 +- src/pm/message/signup.rs | 18 +++++++------- src/pm/mod.rs | 43 ++++++++++++++++++++++----------- src/pm/syscall/lookup.rs | 12 +++++----- src/pm/syscall/shutdown.rs | 6 ++--- src/pm/syscall/signup.rs | 12 +++++----- 17 files changed, 127 insertions(+), 92 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 244ce1c..167ce34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/debug.rs b/src/debug.rs index 3cd5049..48b2650 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -5,4 +5,4 @@ // Exports //================================================================================================== -pub use ::kcall::debug::*; +pub use ::sys::kcall::debug::debug; diff --git a/src/event.rs b/src/event.rs index e710c73..3e197c7 100644 --- a/src/event.rs +++ b/src/event.rs @@ -5,4 +5,10 @@ // Exports //================================================================================================== -pub use ::kcall::event::*; +pub use ::sys::{ + event::*, + kcall::event::{ + evctrl, + resume, + }, +}; diff --git a/src/ipc/message.rs b/src/ipc/message.rs index fd3bc37..29f38e1 100644 --- a/src/ipc/message.rs +++ b/src/ipc/message.rs @@ -6,12 +6,12 @@ //================================================================================================== use ::core::mem; -use ::kcall::{ - ipc::Message, - sys::error::{ +use ::sys::{ + error::{ Error, ErrorCode, }, + ipc::Message, }; //================================================================================================== @@ -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. diff --git a/src/ipc/mod.rs b/src/ipc/mod.rs index c5dc4f1..64c86d1 100644 --- a/src/ipc/mod.rs +++ b/src/ipc/mod.rs @@ -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, + }, +}; diff --git a/src/lib.rs b/src/lib.rs index 708bb1e..ba70dd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,7 @@ extern crate alloc; //================================================================================================== /// Architecture-specific symbols. -pub use ::kcall::arch; +pub use ::sys::kcall::arch; /// Debug facilities. pub mod debug; @@ -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; @@ -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. @@ -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. diff --git a/src/logging.rs b/src/logging.rs index 7ed8ed6..f3240d3 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -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(()) } } diff --git a/src/mm/allocator.rs b/src/mm/allocator.rs index 89558f3..195a085 100644 --- a/src/mm/allocator.rs +++ b/src/mm/allocator.rs @@ -10,7 +10,7 @@ use ::alloc::alloc::{ Layout, }; use ::core::ptr; -use ::kcall::sys::error::{ +use ::sys::error::{ Error, ErrorCode, }; diff --git a/src/mm/mod.rs b/src/mm/mod.rs index afbe8a7..e17f0fb 100644 --- a/src/mm/mod.rs +++ b/src/mm/mod.rs @@ -12,13 +12,19 @@ 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 @@ -26,7 +32,7 @@ pub use ::kcall::mm::*; /// 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 @@ -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 { @@ -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()?; @@ -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(()) } diff --git a/src/pm/message/lookup.rs b/src/pm/message/lookup.rs index 1525663..fd01e9e 100644 --- a/src/pm/message/lookup.rs +++ b/src/pm/message/lookup.rs @@ -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, - }, }; //================================================================================================== @@ -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 @@ -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 @@ -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 = @@ -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) } /// @@ -298,5 +298,5 @@ pub fn lookup_response( ); // Send IPC message. - ::kcall::ipc::send(&ipc_message) + ::sys::kcall::ipc::send(&ipc_message) } diff --git a/src/pm/message/message.rs b/src/pm/message/message.rs index 174b145..0dd7197 100644 --- a/src/pm/message/message.rs +++ b/src/pm/message/message.rs @@ -7,7 +7,7 @@ use crate::ipc::SystemMessage; use ::core::mem; -use ::kcall::sys::error::{ +use ::sys::error::{ Error, ErrorCode, }; @@ -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. diff --git a/src/pm/message/shutdown.rs b/src/pm/message/shutdown.rs index d2f5f13..4dd2a1e 100644 --- a/src/pm/message/shutdown.rs +++ b/src/pm/message/shutdown.rs @@ -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 diff --git a/src/pm/message/signup.rs b/src/pm/message/signup.rs index 49e5af8..0b1bda3 100644 --- a/src/pm/message/signup.rs +++ b/src/pm/message/signup.rs @@ -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, - }, }; //================================================================================================== @@ -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 @@ -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 @@ -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) } /// @@ -304,5 +304,5 @@ pub fn signup_response( ); // Send IPC message. - ::kcall::ipc::send(&ipc_message) + ::sys::kcall::ipc::send(&ipc_message) } diff --git a/src/pm/mod.rs b/src/pm/mod.rs index a09a838..5496486 100644 --- a/src/pm/mod.rs +++ b/src/pm/mod.rs @@ -12,19 +12,34 @@ mod syscall; // Exports //================================================================================================== -pub use ::kcall::pm::*; -pub use message::{ - lookup_response, - signup_response, - LookupMessage, - ProcessManagementMessage, - ProcessManagementMessageHeader, - ShutdownMessage, - SignupMessage, - SignupResponseMessage, +pub use self::{ + message::{ + lookup_response, + signup_response, + LookupMessage, + ProcessManagementMessage, + ProcessManagementMessageHeader, + ShutdownMessage, + SignupMessage, + SignupResponseMessage, + }, + syscall::{ + lookup, + shutdown, + signup, + }, }; -pub use syscall::{ - lookup, - shutdown, - signup, +pub use ::sys::{ + kcall::pm::{ + capctl, + exit, + getegid, + geteuid, + getgid, + getpid, + gettid, + getuid, + terminate, + }, + pm::*, }; diff --git a/src/pm/syscall/lookup.rs b/src/pm/syscall/lookup.rs index 977d70f..6ea4b75 100644 --- a/src/pm/syscall/lookup.rs +++ b/src/pm/syscall/lookup.rs @@ -16,11 +16,11 @@ use crate::{ ProcessManagementMessageHeader, }, }; -use ::kcall::sys::error::{ - Error, - ErrorCode, -}; -use kcall::{ +use ::sys::{ + error::{ + Error, + ErrorCode, + }, ipc::{ Message, MessageType, @@ -51,7 +51,7 @@ pub fn lookup(name: &str) -> Result { crate::pm::message::lookup(name)?; // Wait response from the process manager daemon. - let message: Message = crate::ipc::recv()?; + let message: Message = ::sys::kcall::ipc::recv()?; // Parse response. match message.message_type { diff --git a/src/pm/syscall/shutdown.rs b/src/pm/syscall/shutdown.rs index 6178592..78bccfd 100644 --- a/src/pm/syscall/shutdown.rs +++ b/src/pm/syscall/shutdown.rs @@ -16,8 +16,8 @@ use crate::{ ShutdownMessage, }, }; -use ::kcall::sys::error::Error; -use kcall::{ +use ::sys::{ + error::Error, ipc::{ Message, MessageType, @@ -66,5 +66,5 @@ pub fn shutdown(destination: ProcessIdentifier, code: u8) -> Result<(), Error> { ); // Send IPC message. - ::kcall::ipc::send(&ipc_message) + ::sys::kcall::ipc::send(&ipc_message) } diff --git a/src/pm/syscall/signup.rs b/src/pm/syscall/signup.rs index cb07dfe..3e7fea3 100644 --- a/src/pm/syscall/signup.rs +++ b/src/pm/syscall/signup.rs @@ -16,11 +16,11 @@ use crate::{ SignupResponseMessage, }, }; -use ::kcall::sys::error::{ - Error, - ErrorCode, -}; -use kcall::{ +use ::sys::{ + error::{ + Error, + ErrorCode, + }, ipc::{ Message, MessageType, @@ -51,7 +51,7 @@ pub fn signup(pid: &ProcessIdentifier, name: &str) -> Result<(), Error> { crate::pm::message::signup(pid.clone(), &name)?; // Wait unblock message from the process manager daemon. - let message: Message = crate::ipc::recv()?; + let message: Message = ::sys::kcall::ipc::recv()?; // Parse message. match message.message_type { From 095a6f9861d8789f3f434828c54fcd440f35d4ad Mon Sep 17 00:00:00 2001 From: Pedro Henrique Penna Date: Tue, 24 Sep 2024 16:10:27 -0700 Subject: [PATCH 2/2] [build] E: Updating Version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 167ce34..b8b3f5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"]