Skip to content

Commit

Permalink
Syscalls refined
Browse files Browse the repository at this point in the history
- user mode: only one assembly function returning SyscallResult
- adopted all runtime functions to handle SyscallResult
- user mode runtime crate 'io' renamed to 'terminal'
- kernel mode: split up syscall/mod.rs to group related syscalls in one file
  • Loading branch information
schoettner committed Aug 31, 2024
1 parent 7704ad4 commit 0cd69e1
Show file tree
Hide file tree
Showing 41 changed files with 602 additions and 716 deletions.
2 changes: 1 addition & 1 deletion os/application/date/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ path = "src/date.rs"
[dependencies]
# Local dependencies
runtime = { path = "../../library/runtime" }
io = { path = "../../library/io" }
terminal = { path = "../../library/terminal" }
time = { path = "../../library/time" }

chrono = { version = "0.4.38", default-features = false, features = ["alloc"] }
2 changes: 1 addition & 1 deletion os/application/date/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ args = [ "build", "-Z", "build-std=core,alloc", "-Z", "build-std-features=compil
condition = { files_modified = { input = [
"${CARGO_MAKE_WORKING_DIRECTORY}/Cargo.toml", "${SOURCE_DIRECTORY}/**/*.rs",
"${LIBRARY_DIRECTORY}/runtime/Cargo.toml", "${LIBRARY_DIRECTORY}/runtime/src/**/*.rs",
"${LIBRARY_DIRECTORY}/io/Cargo.toml", "${LIBRARY_DIRECTORY}/io/src/**/*.rs",
"${LIBRARY_DIRECTORY}/terminal/Cargo.toml", "${LIBRARY_DIRECTORY}/terminal/src/**/*.rs",
"${LIBRARY_DIRECTORY}/time/Cargo.toml", "${LIBRARY_DIRECTORY}/time/src/**/*.rs",
"${LIBRARY_DIRECTORY}/concurrent/Cargo.toml", "${LIBRARY_DIRECTORY}/concurrent/src/**/*.rs",
"${LIBRARY_DIRECTORY}/syscall/Cargo.toml", "${LIBRARY_DIRECTORY}/syscall/src/**/*.rs" ], output = [ "${BUILD_DIRECTORY}/lib${CARGO_MAKE_PROJECT_NAME}*" ] } }
Expand Down
2 changes: 1 addition & 1 deletion os/application/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate alloc;

#[allow(unused_imports)]
use runtime::*;
use io::{print, println};
use terminal::{print, println};
use time::date;

#[unsafe(no_mangle)]
Expand Down
2 changes: 1 addition & 1 deletion os/application/hello/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ path = "src/hello.rs"
[dependencies]
# Local dependencies
runtime = { path = "../../library/runtime" }
io = { path = "../../library/io" }
terminal = { path = "../../library/terminal" }
concurrent = { path = "../../library/concurrent" }
2 changes: 1 addition & 1 deletion os/application/hello/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ args = [ "build", "-Z", "build-std=core,alloc", "-Z", "build-std-features=compil
condition = { files_modified = { input = [
"${CARGO_MAKE_WORKING_DIRECTORY}/Cargo.toml", "${SOURCE_DIRECTORY}/**/*.rs",
"${LIBRARY_DIRECTORY}/runtime/Cargo.toml", "${LIBRARY_DIRECTORY}/runtime/src/**/*.rs",
"${LIBRARY_DIRECTORY}/io/Cargo.toml", "${LIBRARY_DIRECTORY}/io/src/**/*.rs",
"${LIBRARY_DIRECTORY}/terminal/Cargo.toml", "${LIBRARY_DIRECTORY}/terminal/src/**/*.rs",
"${LIBRARY_DIRECTORY}/concurrent/Cargo.toml", "${LIBRARY_DIRECTORY}/concurrent/src/**/*.rs",
"${LIBRARY_DIRECTORY}/syscall/Cargo.toml", "${LIBRARY_DIRECTORY}/syscall/src/**/*.rs" ], output = [ "${BUILD_DIRECTORY}/lib${CARGO_MAKE_PROJECT_NAME}*" ] } }

Expand Down
7 changes: 4 additions & 3 deletions os/application/hello/src/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ extern crate alloc;
use concurrent::{process, thread};
#[allow(unused_imports)]
use runtime::*;
use io::{print, println};
use terminal::{print, println};

#[unsafe(no_mangle)]
pub fn main() {
let process = process::current();
let thread = thread::current();
let process = process::current().unwrap();
let thread = thread::current().unwrap();

println!("Hello from Thread [{}] in Process [{}]!", thread.id(), process.id());

let args = env::args();
Expand Down
2 changes: 1 addition & 1 deletion os/application/mkentry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ path = "src/mkentry.rs"

[dependencies]
# Local dependencies
io = { path = "../../library/io" }
terminal = { path = "../../library/terminal" }
runtime = { path = "../../library/runtime" }
naming = { path = "../../library/naming" }

Expand Down
2 changes: 1 addition & 1 deletion os/application/mkentry/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ args = [ "build", "-Z", "build-std=core,alloc", "-Z", "build-std-features=compil
condition = { files_modified = { input = [
"${CARGO_MAKE_WORKING_DIRECTORY}/Cargo.toml", "${SOURCE_DIRECTORY}/**/*.rs",
"${LIBRARY_DIRECTORY}/runtime/Cargo.toml", "${LIBRARY_DIRECTORY}/runtime/src/**/*.rs",
"${LIBRARY_DIRECTORY}/io/Cargo.toml", "${LIBRARY_DIRECTORY}/io/src/**/*.rs",
"${LIBRARY_DIRECTORY}/terminal/Cargo.toml", "${LIBRARY_DIRECTORY}/terminal/src/**/*.rs",
"${LIBRARY_DIRECTORY}/time/Cargo.toml", "${LIBRARY_DIRECTORY}/time/src/**/*.rs",
"${LIBRARY_DIRECTORY}/concurrent/Cargo.toml", "${LIBRARY_DIRECTORY}/concurrent/src/**/*.rs",
"${LIBRARY_DIRECTORY}/syscall/Cargo.toml", "${LIBRARY_DIRECTORY}/syscall/src/**/*.rs" ], output = [ "${BUILD_DIRECTORY}/lib${CARGO_MAKE_PROJECT_NAME}*" ] } }
Expand Down
6 changes: 5 additions & 1 deletion os/application/mkentry/src/mkentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ extern crate alloc;

#[allow(unused_imports)]
use runtime::*;
use io::{print, println};
use terminal::{print, println};
use naming::mkentry;

#[unsafe(no_mangle)]
pub fn main() {
let args = env::args();
for (i, arg) in args.enumerate() {
println!("Arg[{}]: {}", i, arg);
}

let res = mkentry("/home/schoettner", "test.txt", 1);

Expand Down
2 changes: 1 addition & 1 deletion os/application/shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ path = "src/shell.rs"
[dependencies]
# Local dependencies
runtime = { path = "../../library/runtime" }
io = { path = "../../library/io" }
terminal = { path = "../../library/terminal" }
concurrent = { path = "../../library/concurrent" }
2 changes: 1 addition & 1 deletion os/application/shell/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ args = [ "build", "-Z", "build-std=core,alloc", "-Z", "build-std-features=compil
condition = { files_modified = { input = [
"${CARGO_MAKE_WORKING_DIRECTORY}/Cargo.toml", "${SOURCE_DIRECTORY}/**/*.rs",
"${LIBRARY_DIRECTORY}/runtime/Cargo.toml", "${LIBRARY_DIRECTORY}/runtime/src/**/*.rs",
"${LIBRARY_DIRECTORY}/io/Cargo.toml", "${LIBRARY_DIRECTORY}/io/src/**/*.rs",
"${LIBRARY_DIRECTORY}/terminal/Cargo.toml", "${LIBRARY_DIRECTORY}/terminal/src/**/*.rs",
"${LIBRARY_DIRECTORY}/concurrent/Cargo.toml", "${LIBRARY_DIRECTORY}/concurrent/src/**/*.rs",
"${LIBRARY_DIRECTORY}/syscall/Cargo.toml", "${LIBRARY_DIRECTORY}/syscall/src/**/*.rs" ], output = [ "${BUILD_DIRECTORY}/lib${CARGO_MAKE_PROJECT_NAME}*" ] } }

Expand Down
45 changes: 29 additions & 16 deletions os/application/shell/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,34 @@ extern crate alloc;
use alloc::string::String;
use alloc::vec::Vec;
use concurrent::thread;
use terminal::read::read;
use terminal::{print, println};
#[allow(unused_imports)]
use runtime::*;
use io::{print, println};
use io::read::read;


fn process_next_char(line: &mut String, ch: char) {
match ch {
'\n' => {
let split = line.split_whitespace().collect::<Vec<&str>>();
if !split.is_empty() {
match thread::start_application(split[0], split[1..].iter().map(|&s| s).collect()) {
Some(app) => app.join(),
None => println!("Command not found!"),
}
}

line.clear();
print!("> ");
},
'\x08' => {
line.pop();
},
_ => {
line.push(ch);
},
}
}

#[unsafe(no_mangle)]
pub fn main() {
Expand All @@ -17,19 +41,8 @@ pub fn main() {

loop {
match read() {
'\n' => {
let split = line.split_whitespace().collect::<Vec<&str>>();
if !split.is_empty() {
match thread::start_application(split[0], split[1..].iter().map(|&s| s).collect()) {
Some(app) => app.join(),
None => println!("Command not found!")
}
}

line.clear();
print!("> ")
},
c => line.push(char::from_u32(c as u32).unwrap())
Some(ch) => process_next_char(&mut line, ch),
None => (),
}
}
}
}
2 changes: 1 addition & 1 deletion os/application/uptime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ path = "src/uptime.rs"
[dependencies]
# Local dependencies
runtime = { path = "../../library/runtime" }
io = { path = "../../library/io" }
terminal = { path = "../../library/terminal" }
time = { path = "../../library/time" }
2 changes: 1 addition & 1 deletion os/application/uptime/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ args = [ "build", "-Z", "build-std=core,alloc", "-Z", "build-std-features=compil
condition = { files_modified = { input = [
"${CARGO_MAKE_WORKING_DIRECTORY}/Cargo.toml", "${SOURCE_DIRECTORY}/**/*.rs",
"${LIBRARY_DIRECTORY}/runtime/Cargo.toml", "${LIBRARY_DIRECTORY}/runtime/src/**/*.rs",
"${LIBRARY_DIRECTORY}/io/Cargo.toml", "${LIBRARY_DIRECTORY}/io/src/**/*.rs",
"${LIBRARY_DIRECTORY}/terminal/Cargo.toml", "${LIBRARY_DIRECTORY}/terminal/src/**/*.rs",
"${LIBRARY_DIRECTORY}/time/Cargo.toml", "${LIBRARY_DIRECTORY}/time/src/**/*.rs",
"${LIBRARY_DIRECTORY}/concurrent/Cargo.toml", "${LIBRARY_DIRECTORY}/concurrent/src/**/*.rs",
"${LIBRARY_DIRECTORY}/syscall/Cargo.toml", "${LIBRARY_DIRECTORY}/syscall/src/**/*.rs" ], output = [ "${BUILD_DIRECTORY}/lib${CARGO_MAKE_PROJECT_NAME}*" ] } }
Expand Down
2 changes: 1 addition & 1 deletion os/application/uptime/src/uptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate alloc;

#[allow(unused_imports)]
use runtime::*;
use io::{print, println};
use terminal::{print, println};
use time::systime;

#[unsafe(no_mangle)]
Expand Down
1 change: 1 addition & 0 deletions os/kernel/src/naming/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod stat;
pub mod name_service;
mod name_service_internal;
pub mod name_service_tests;

49 changes: 19 additions & 30 deletions os/kernel/src/naming/name_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,29 @@
╟─────────────────────────────────────────────────────────────────────────╢
║ Descr.: API of name service. ║
╟─────────────────────────────────────────────────────────────────────────╢
║ Author: Michael Schoettner, 1.8.2024, HHU
║ Author: Michael Schoettner, 30.8.2024, HHU ║
╚═════════════════════════════════════════════════════════════════════════╝
*/
use alloc::sync::Arc;
use alloc::vec::Vec;
//use core::result::Result;
use syscall::consts::Errno;
use syscall::consts::Result;

use syscall::return_vals::{SyscallResult,Errno};
use ::log::info;

use crate::naming::name_service_internal;
use crate::naming::name_service_internal::get_root_dir;
use crate::naming::stat::Stat;

pub type Result<T> = ::core::result::Result<T, Errno>;

///
/// Description:
/// Add an entry (with or without data)
///
/// Parameters: \
/// `path` path (must exist) \
/// `name` name for the new entry \
/// `content` data bytes
///
pub fn mkentry_new(path: &str, name: &str, content: Vec<u8>) -> ::core::result::Result<usize,Errno> {
let r = get_root_dir().mkentry(path, name, content);

info!("mkentry: res = {:?}", r);
return Ok(0)
}

// Wrapper function to convert Result<(), Errno> to SyscallResult
fn convert_result(result: core::result::Result<(), Errno>) -> SyscallResult {
match result {
Ok(()) => Ok(0), // Convert the success case to a meaningful u64, e.g., 0
Err(e) => Err(e), // Forward the error directly
}
}

///
/// Description:
Expand All @@ -45,22 +36,20 @@ pub fn mkentry_new(path: &str, name: &str, content: Vec<u8>) -> ::core::result::
/// `name` name for the new entry \
/// `content` data bytes
///
pub fn mkentry(path: &str, name: &str, content: Vec<u8>) -> Result<()> {
let r = get_root_dir().mkentry(path, name, content);

info!("mkentry: res = {:?}", r);
r
pub fn mkentry(path: &str, name: &str, content: Vec<u8>) -> SyscallResult {
convert_result(get_root_dir().mkentry(path, name, content))
}


///
/// Description:
/// Add a directory. Creates all sub directories for the given path (if they do not exist already)
///
/// Parameters: \
/// `path` path to be created
///
pub fn mkdir(path: &str) -> Result<()> {
get_root_dir().mkdir(path)
pub fn mkdir(path: &str) -> SyscallResult {
convert_result(get_root_dir().mkdir(path))
}

///
Expand Down Expand Up @@ -104,8 +93,8 @@ pub fn dir(path: &str) -> Result<Vec<Stat>> {
/// `path` path&entry name \
/// `new_name` new name
///
pub fn rename(path: &str, new_name: &str) -> Result<()> {
get_root_dir().rename(path, new_name)
pub fn rename(path: &str, new_name: &str) -> SyscallResult {
convert_result(get_root_dir().rename(path, new_name))
}

///
Expand All @@ -115,8 +104,8 @@ pub fn rename(path: &str, new_name: &str) -> Result<()> {
/// Parameters: \
/// `path` path&entry name
///
pub fn del(path: &str) -> Result<()> {
get_root_dir().del(path)
pub fn del(path: &str) -> SyscallResult {
convert_result(get_root_dir().del(path))
}

///
Expand Down
4 changes: 2 additions & 2 deletions os/kernel/src/naming/name_service_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
║ Author: Michael Schoettner, 29.8.2024, HHU ║
╚═════════════════════════════════════════════════════════════════════════╝
*/
use syscall::consts::Result;
use syscall::consts::Errno;
use syscall::return_vals::Errno;
use crate::naming::stat;
use crate::naming::stat::Mode;
use crate::naming::stat::Stat;
use crate::naming::name_service::Result;

use alloc::boxed::Box;
use alloc::string::ToString;
Expand Down
Loading

0 comments on commit 0cd69e1

Please sign in to comment.