Skip to content

Update everything #11

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

Merged
merged 1 commit into from
Apr 22, 2024
Merged
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
File renamed without changes.
626 changes: 352 additions & 274 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ members = [

[patch.crates-io.ring]
git = "https://github.com/coliasgroup/ring.git"
rev = "10a2b3cbe68da77f9f20ebb3776ab4c605f2b40e"
rev = "0e644b7837cffcd53a3ff67d7f478801b4e9e0ed"
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BUILD ?= build

build_dir := $(BUILD)

microkit_board := qemu_arm_virt
microkit_board := qemu_virt_aarch64
microkit_config := debug
microkit_sdk_config_dir := $(MICROKIT_SDK)/board/$(microkit_board)/$(microkit_config)

Expand All @@ -22,15 +22,13 @@ clean:
### Protection domains

target_cc := aarch64-none-elf-gcc
target_bindgen_clang_args := --sysroot=/opt/gcc-aarch64-none-elf-sysroot

rust_target_path := support/targets
rust_microkit_target := aarch64-sel4-microkit
target_dir := $(build_dir)/target

common_env := \
CC_$(subst -,_,$(rust_microkit_target))=$(target_cc) \
BINDGEN_EXTRA_CLANG_ARGS_$(subst -,_,$(rust_microkit_target))="$(target_bindgen_clang_args)" \
SEL4_INCLUDE_DIRS=$(abspath $(microkit_sdk_config_dir)/include)

common_options := \
Expand Down Expand Up @@ -93,8 +91,7 @@ $(disk_img): $(compressed_disk_img)

qemu_cmd := \
qemu-system-aarch64 \
-machine virt \
-cpu cortex-a53 -m size=1G \
-machine virt -cpu cortex-a53 -m size=2G \
-device loader,file=$(loader),addr=0x70000000,cpu-num=0 \
-serial mon:stdio \
-nographic \
Expand Down
10 changes: 5 additions & 5 deletions crates/pds/pl031-driver/core/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tock_registers::{register_bitfields, register_structs};

register_structs! {
#[allow(non_snake_case)]
pub RTCRegisterBlock {
pub RtcRegisterBlock {
(0x000 => Data: ReadOnly<u32>),
(0x004 => Match: ReadWrite<u32>),
(0x008 => Load: ReadWrite<u32>),
Expand Down Expand Up @@ -53,17 +53,17 @@ register_bitfields! {
}

pub struct Device {
ptr: *const RTCRegisterBlock,
ptr: *const RtcRegisterBlock,
}

#[allow(dead_code)]
impl Device {
pub unsafe fn new(ptr: *const ()) -> Self {
let ptr = ptr.cast::<RTCRegisterBlock>();
let ptr = ptr.cast::<RtcRegisterBlock>();
Self { ptr }
}

fn ptr(&self) -> *const RTCRegisterBlock {
fn ptr(&self) -> *const RtcRegisterBlock {
self.ptr
}

Expand All @@ -73,7 +73,7 @@ impl Device {
}

impl Deref for Device {
type Target = RTCRegisterBlock;
type Target = RtcRegisterBlock;

fn deref(&self) -> &Self::Target {
unsafe { &*self.ptr() }
Expand Down
9 changes: 2 additions & 7 deletions crates/pds/server/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,19 @@ license = "BSD-2-Clause"
futures = { version = "0.3.28", default-features = false, features = ["async-await", "alloc"] }
httparse = { version = "1.8.0", default-features = false }
log = "0.4.17"
rustls = { version = "0.23.5", default-features = false, features = ["logging", "ring", "tls12"] }
rustls-pemfile = { version = "2.0.0", default-features = false }
sel4-async-block-io = { git = "https://github.com/seL4/rust-sel4" }
sel4-async-block-io-fat = { git = "https://github.com/seL4/rust-sel4" }
sel4-async-io = { git = "https://github.com/seL4/rust-sel4" }
sel4-async-network = { git = "https://github.com/seL4/rust-sel4" }
sel4-async-network-rustls = { git = "https://github.com/seL4/rust-sel4" }
sel4-async-network-rustls-utils = { git = "https://github.com/seL4/rust-sel4" }
sel4-async-network-traits = { git = "https://github.com/seL4/rust-sel4" }
sel4-async-time = { git = "https://github.com/seL4/rust-sel4" }
sel4-async-unsync = { git = "https://github.com/seL4/rust-sel4" }
sel4-panicking-env = { git = "https://github.com/seL4/rust-sel4" }
webpki-roots = "0.26"

[dependencies.rustls]
git = "https://github.com/coliasgroup/rustls.git"
rev = "c315801aa0c1e9c765b27106b3969dd458995cc7"
default-features = false
features = ["logging", "ring", "tls12"]

[dependencies.sel4-async-single-threaded-executor]
git = "https://github.com/seL4/rust-sel4"

Expand Down
38 changes: 17 additions & 21 deletions crates/pds/server/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ use core::time::Duration;
use futures::future::{self, LocalBoxFuture};
use futures::task::LocalSpawnExt;
use rustls::pki_types::{PrivateKeyDer, UnixTime};
use rustls::time_provider::TimeProvider;
use rustls::version::TLS12;
use rustls::ServerConfig;

use sel4_async_block_io::{access::ReadOnly, constant_block_sizes, BlockIO};
use sel4_async_block_io_fat as fat;
use sel4_async_io::ReadExactError;
use sel4_async_network::{ManagedInterface, TcpSocket, TcpSocketError};
use sel4_async_network_rustls::{Error as AsyncRustlsError, ServerConnector};
use sel4_async_network_rustls_utils::GetCurrentTimeImpl;
use sel4_async_network_traits::ClosedError;
use sel4_async_network_rustls_utils::TimeProviderImpl;
use sel4_async_single_threaded_executor::LocalSpawner;
use sel4_async_time::{Instant, TimerManager};

Expand Down Expand Up @@ -117,18 +116,18 @@ type SocketUser<T> = Box<
async fn use_socket_for_http<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static>(
server: Server<D, T>,
mut socket: TcpSocket,
) -> Result<(), ClosedError<TcpSocketError>> {
) -> Result<(), ReadExactError<TcpSocketError>> {
socket.accept(HTTP_PORT).await?;
server.handle_connection(&mut socket).await?;
socket.close().await?;
socket.close();
Ok(())
}

async fn use_socket_for_https<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static>(
server: Server<D, T>,
tls_config: Arc<ServerConfig>,
mut socket: TcpSocket,
) -> Result<(), ClosedError<AsyncRustlsError<TcpSocketError>>> {
) -> Result<(), ReadExactError<AsyncRustlsError<TcpSocketError>>> {
socket
.accept(HTTPS_PORT)
.await
Expand All @@ -138,11 +137,7 @@ async fn use_socket_for_https<D: fat::BlockDevice + 'static, T: fat::TimeSource

server.handle_connection(&mut conn).await?;

// TODO TcpSocket doesn't support stateless .poll_close() yet, so we close the socket directly
conn.into_io()
.close()
.await
.map_err(AsyncRustlsError::TransitError)?;
conn.into_io().close();

Ok(())
}
Expand Down Expand Up @@ -173,14 +168,15 @@ fn mk_tls_config(
_ => panic!(),
};

let mut config = ServerConfig::builder_with_protocol_versions(&[&TLS12])
.with_no_client_auth()
.with_single_cert(vec![cert_der], key_der)
.unwrap();
config.time_provider = TimeProvider::new(GetCurrentTimeImpl::new(
UnixTime::since_unix_epoch(now_unix_time),
now_fn,
));

config
let time_provider = TimeProviderImpl::new(UnixTime::since_unix_epoch(now_unix_time), now_fn);

ServerConfig::builder_with_details(
Arc::new(rustls::crypto::ring::default_provider()),
Arc::new(time_provider),
)
.with_protocol_versions(&[&TLS12])
.unwrap()
.with_no_client_auth()
.with_single_cert(vec![cert_der], key_der)
.unwrap()
}
36 changes: 18 additions & 18 deletions crates/pds/server/core/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use alloc::string::{String, ToString};
use alloc::vec;

use sel4_async_block_io_fat as fat;
use sel4_async_network_traits::{AsyncIO, AsyncIOExt, ClosedError};
use sel4_async_io::{Read, ReadExactError, Write};
use sel4_async_unsync::Mutex;

use crate::mime::content_type_from_name;
Expand All @@ -29,17 +29,17 @@ impl<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static> Server<D, T> {
}
}

pub(crate) async fn handle_connection<U: AsyncIO + Unpin>(
pub(crate) async fn handle_connection<U: Read + Write + Unpin>(
&self,
conn: &mut U,
) -> Result<(), ClosedError<U::Error>> {
) -> Result<(), ReadExactError<U::Error>> {
loop {
let mut buf = vec![0; 1024 * 16];
let mut i = 0;
loop {
let n = conn.read(&mut buf[i..]).await?;
if n == 0 {
return Err(ClosedError::Closed);
return Err(ReadExactError::UnexpectedEof);
}
i += n;
if is_request_complete(&buf[..i]).unwrap_or(false) {
Expand Down Expand Up @@ -68,11 +68,11 @@ impl<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static> Server<D, T> {
Ok(())
}

async fn handle_request<U: AsyncIO + Unpin>(
async fn handle_request<U: Read + Write + Unpin>(
&self,
conn: &mut U,
request_path: &str,
) -> Result<(), ClosedError<U::Error>> {
) -> Result<(), ReadExactError<U::Error>> {
match self.lookup_request_path(request_path).await {
RequestPathStatus::Ok { file_name, file } => {
let content_type = content_type_from_name(&file_name);
Expand All @@ -88,12 +88,12 @@ impl<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static> Server<D, T> {
Ok(())
}

async fn serve_file<U: AsyncIO + Unpin>(
async fn serve_file<U: Write + Unpin>(
&self,
conn: &mut U,
content_type: &str,
file: fat::File,
) -> Result<(), ClosedError<U::Error>> {
) -> Result<(), ReadExactError<U::Error>> {
let file_len: usize = self
.volume_manager
.lock()
Expand Down Expand Up @@ -133,11 +133,11 @@ impl<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static> Server<D, T> {
Ok(())
}

async fn serve_moved_permanently<U: AsyncIO + Unpin>(
async fn serve_moved_permanently<U: Write + Unpin>(
&self,
conn: &mut U,
location: &str,
) -> Result<(), ClosedError<U::Error>> {
) -> Result<(), ReadExactError<U::Error>> {
let phrase = "Moved Permanently";
self.start_response_headers(conn, 301, phrase).await?;
self.send_response_header(conn, "Content-Type", b"text/plain")
Expand All @@ -151,10 +151,10 @@ impl<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static> Server<D, T> {
Ok(())
}

async fn serve_not_found<U: AsyncIO + Unpin>(
async fn serve_not_found<U: Write + Unpin>(
&self,
conn: &mut U,
) -> Result<(), ClosedError<U::Error>> {
) -> Result<(), ReadExactError<U::Error>> {
let phrase = "Not Found";
self.start_response_headers(conn, 404, phrase).await?;
self.send_response_header(conn, "Content-Type", b"text/plain")
Expand All @@ -166,12 +166,12 @@ impl<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static> Server<D, T> {
Ok(())
}

async fn start_response_headers<U: AsyncIO + Unpin>(
async fn start_response_headers<U: Write + Unpin>(
&self,
conn: &mut U,
status_code: usize,
reason_phrase: &str,
) -> Result<(), ClosedError<U::Error>> {
) -> Result<(), ReadExactError<U::Error>> {
conn.write_all(b"HTTP/1.1 ").await?;
conn.write_all(status_code.to_string().as_bytes()).await?;
conn.write_all(b" ").await?;
Expand All @@ -180,23 +180,23 @@ impl<D: fat::BlockDevice + 'static, T: fat::TimeSource + 'static> Server<D, T> {
Ok(())
}

async fn send_response_header<U: AsyncIO + Unpin>(
async fn send_response_header<U: Write + Unpin>(
&self,
conn: &mut U,
name: &str,
value: &[u8],
) -> Result<(), ClosedError<U::Error>> {
) -> Result<(), ReadExactError<U::Error>> {
conn.write_all(name.as_bytes()).await?;
conn.write_all(b": ").await?;
conn.write_all(value).await?;
conn.write_all(b"\r\n").await?;
Ok(())
}

async fn finish_response_headers<U: AsyncIO + Unpin>(
async fn finish_response_headers<U: Write + Unpin>(
&self,
conn: &mut U,
) -> Result<(), ClosedError<U::Error>> {
) -> Result<(), ReadExactError<U::Error>> {
conn.write_all(b"\r\n").await?;
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pds/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use block_client::BlockClient;
use config::channels;
use handler::HandlerImpl;
use net_client::NetClient;
use rtc_client::RTCClient;
use rtc_client::RtcClient;
use timer_client::TimerClient;

const BLOCK_CACHE_SIZE_IN_BLOCKS: usize = 128;
Expand Down Expand Up @@ -72,7 +72,7 @@ static LOGGER: Logger = LoggerBuilder::const_default()
fn init() -> impl Handler {
LOGGER.set().unwrap();

let rtc_client = RTCClient::new(channels::RTC_DRIVER);
let rtc_client = RtcClient::new(channels::RTC_DRIVER);
let timer_client = Arc::new(TimerClient::new(channels::TIMER_DRIVER));
let net_client = NetClient::new(channels::NET_DRIVER);
let block_client = BlockClient::new(channels::BLOCK_DRIVER);
Expand Down
4 changes: 2 additions & 2 deletions crates/pds/server/src/rtc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use sel4_microkit_message::MessageInfoExt as _;

use microkit_http_server_example_pl031_driver_interface_types::*;

pub struct RTCClient {
pub struct RtcClient {
channel: sel4_microkit::Channel,
}

impl RTCClient {
impl RtcClient {
pub fn new(channel: sel4_microkit::Channel) -> Self {
Self { channel }
}
Expand Down
27 changes: 12 additions & 15 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@ RUN apt-get update -q && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN set -eux; \
target=aarch64-none-elf; \
install_dir=/opt/gcc-$target; \
sysroot_dir=$install_dir-sysroot; \
url="https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz"; \
url="https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/binrel/arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-elf.tar.xz"; \
wget -nv "$url"; \
tar -xf gcc-arm-*.tar.xz; \
rm gcc-arm-*.tar.xz; \
mv gcc-arm-* $install_dir; \
mkdir -p $sysroot_dir; \
ln -s $install_dir/$target $sysroot_dir/usr;
tar -xf arm-gnu-toolchain-*.tar.xz; \
rm arm-gnu-toolchain-*.tar.xz; \
mv arm-gnu-toolchain-* /opt/gcc-aarch64-none-elf;

ENV PATH=/opt/gcc-aarch64-none-elf/bin:$PATH

Expand All @@ -65,16 +60,18 @@ ENV PATH=/opt/qemu/bin:$PATH

ENV MICROKIT_SDK_VERSION=1.2.6

# branch: rust-testing (rust branch + QEMU support patches)
RUN git clone \
https://github.com/coliasgroup/microkit.git \
--branch keep/c8ea99b72b845ef61bf114fdac539972 \
--config advice.detachedHead=false
RUN set -eux; \
git clone \
https://github.com/seL4/microkit.git \
--config advice.detachedHead=false; \
cd microkit; \
git checkout 35978315953532d3d2aca3faa82eda54d2a9172f;

# TODO
# branch: rust-microkit
RUN git clone \
https://github.com/coliasgroup/seL4.git \
--branch keep/5f71dc4a5cd90b823876bec10265da92 \
--branch keep/1daabe63fd34ae3d348b8e4a4057bd1a \
--config advice.detachedHead=false \
microkit/seL4

Expand Down
Loading
Loading