Skip to content

aipc, an async ipc library for aero #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 65 additions & 32 deletions userland/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion userland/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["apps/*", "servers/*"]
members = ["apps/*", "servers/*", "libs/*"]

[profile.release]
debug = true
1 change: 0 additions & 1 deletion userland/apps/aero_shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ edition = "2021"
[dependencies]
std = { path = "../../libs/aero_std" }
aero_syscall = { path = "../../../src/aero_syscall" }
aero_ipc = { path = "../../libs/aero_ipc" }
32 changes: 7 additions & 25 deletions userland/apps/aero_shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extern crate alloc;

use core::sync::atomic::{AtomicU32, Ordering};

use aero_ipc::SystemService;
use aero_syscall::signal::*;
use aero_syscall::*;

Expand Down Expand Up @@ -126,17 +125,15 @@ fn repl(history: &mut Vec<String>) -> Result<(), AeroSyscallError> {
// if the test kernel is built instead of randomly bloating the shell
// with tests :).

// let fb = sys_open("/dev/fb", OpenFlags::O_RDWR)?;
let fb = sys_open("/dev/fb", OpenFlags::O_RDWR)?;

// let buffer = &[u32::MAX; (1024 * 768)];
// let casted = buffer.as_ptr() as *mut u8;
// let casted = unsafe { core::slice::from_raw_parts(casted, (1024 * 768) as usize) };
let buffer = &[u32::MAX; (1024 * 768)];
let casted = buffer.as_ptr() as *mut u8;
let casted = unsafe { core::slice::from_raw_parts(casted, (1024 * 768) as usize) };

// println!("writing to fb");
// sys_write(fb, casted)?;
// sys_close(fb)?;

uwutest()?;
println!("writing to fb");
sys_write(fb, casted)?;
sys_close(fb)?;
}

"pid" => {
Expand Down Expand Up @@ -295,21 +292,6 @@ fn print_kernel_log() -> Result<(), AeroSyscallError> {
cat_file(Some("/dev/kmsg"))
}

fn uwutest() -> Result<(), AeroSyscallError> {
let my_pid = sys_getpid()?;
let ipc = SystemService::open(sys_ipc_discover_root()?);

ipc.announce(my_pid, "TestServer")
.expect("Failed to announce");

println!(
"TestServer is at {}",
ipc.discover("TestServer").expect("Failed to discover")
);

Ok(())
}

fn get_uptime() -> Result<String, AeroSyscallError> {
let mut info = unsafe { core::mem::zeroed() };

Expand Down
12 changes: 12 additions & 0 deletions userland/apps/aipc_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "aipc_test"
version = "0.1.0"
edition = "2021"
authors = ["pitust <[email protected]>"]

[dependencies]
std = { path = "../../libs/aero_std" }
aero_syscall = { path = "../../../src/aero_syscall" }
aipc = { path = "../../libs/aipc" }
postcard = { version = "0.7.3", features = ["alloc"] }
spin = "0.9"
98 changes: 98 additions & 0 deletions userland/apps/aipc_test/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2021-2022 The Aero Project Developers.
*
* This file is part of The Aero Project.
*
* Aero is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Aero is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Aero. If not, see <https://www.gnu.org/licenses/>.
*/
use core::sync::atomic::{AtomicUsize, Ordering, AtomicBool};

use aero_syscall::{sys_fork, sys_exit};
use aipc::async_runtime::Listener;

#[aipc::def("TestObj")]
trait TestObj {
async fn create() -> TestObj;
async fn foo(&self);
async fn kill(&self);
}
#[aipc::def("ServerControlObj")]
trait ServerControlObj {
async fn create() -> ServerControlObj;
async fn can_control(&self) -> bool;
async fn quit(&self);
}

static COUNTER: AtomicUsize = AtomicUsize::new(1);

struct NoData {
data: usize,
}

#[aipc::object(TestObjSrv as TestObj)]
impl NoData {
fn create() -> NoData {
return NoData {
data: COUNTER.fetch_add(1, Ordering::SeqCst),
};
}
fn foo(&self) {
println!("Hello from obj {}!", self.data);
}
}

static SCS_PERMIT_ONCE: AtomicBool = AtomicBool::new(true);
pub struct ServerControlState {
permitted: bool
}
#[aipc::object(ServerControlSrv as ServerControlObj)]
impl ServerControlState {
pub fn create() -> ServerControlState {
return ServerControlState {
permitted: SCS_PERMIT_ONCE.swap(false, Ordering::SeqCst)
};
}
pub fn can_control(&self) -> bool {
self.permitted
}
pub fn quit(&self) {
if self.permitted {
println!("[ServerControlSrv] exiting!");
aipc::async_runtime::spawn(async {
sys_exit(0);
});
}
}
}


fn main() {
let mut rt = aipc::async_runtime::AsyncRuntime::new();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of constructing a runtime manually at the start of the main function, it would be a much cleaner idea to initialize it lazily in the spawn function instead. So it will look like apic::spawn(async {}). In future we; after we get the rust userland port sorted out we can switch to using tokio as our async runtime.

rt.spawn(async {
let pid = sys_fork().unwrap();
if pid == 0 {
// server
ServerControlSrv::listen();
TestObjSrv::listen();
} else {
// client
let ctl = ServerControlObj::create(pid).await;
let o = TestObj::create(pid).await;
o.foo().await;
ctl.quit().await;
sys_exit(0);
}
});
rt.run();
}
2 changes: 1 addition & 1 deletion userland/apps/utest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ authors = ["Anhad Singh <[email protected]>"]
[dependencies]
std = { path = "../../libs/aero_std" }
aero_syscall = { path = "../../../src/aero_syscall" }
aero_ipc = { path = "../../libs/aero_ipc" }
aipc = { path = "../../libs/aipc" }
utest-proc = { path = "../utest-proc" }
Loading