Skip to content

Commit

Permalink
chore: update Rust nightly version to 2024-11-20 (1.84) (#148)
Browse files Browse the repository at this point in the history
* chore: update flake deps and bump rust nightly version

* refactor: add explicit lifetime names

* refactor: replace removed `CARGO_RUSTC_CURRENT_DIR`

ref: rust-lang/cargo#3946

* refactor: switch naked fns to `naked_asm!`

Switch to the newly required `naked_asm!` macro in all naked functions.
ref: rust-lang/rust#90957

* fix: update custom target manifest files to avoid ICE

apparently Rust doesn't like it when the custom target manifest file is missing the `llvm-abiname` field

* silence warning about mutable static

* refactor: elide lifetimes

* fmt

* refactor: apply `clippy::manual_div_ceil` suggestion

* fix: use explicit `ptr.wrapping_byte_add` for conversions from physmem to virtmem references

We previously relied on UB actually doing the wrapping behaviour, but well, that's not ideal is it
  • Loading branch information
JonasKruckenberg authored Nov 20, 2024
1 parent 27a200c commit a3e1859
Show file tree
Hide file tree
Showing 39 changed files with 289 additions and 276 deletions.
18 changes: 9 additions & 9 deletions flake.lock

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

80 changes: 40 additions & 40 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# forked from https://github.com/tosc-rs/mnemos/blob/main/flake.nix
{
description = "Flake providing a development shell for k23";
description = "Flake providing a development shell for k23";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};

outputs = { nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
# use the Rust toolchain specified in the project's rust-toolchain.toml
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in
{
devShell = with pkgs; mkShell rec {
name = "k23-dev";
nativeBuildInputs = [
# compilers
rustToolchain
clang
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustToolchain = with pkgs; rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
in
{
devShells.default = with pkgs; mkShell rec {
name = "k23-dev";
buildInputs = [
# compilers
rustToolchain
clang

# devtools
just
mdbook
socat
wabt
# devtools
just
mdbook
socat
wabt
dtc

# for testing the kernel
qemu
];
buildInputs = [];
# for testing the kernel
qemu
];

LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}";
};
}
);
}
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}";
};
}
);
}
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Variables can be set using `just VARIABLE=VALUE ...` or

# env var to set the cargo runner for the riscv64 target
export CARGO_TARGET_RISCV64GC_K23_NONE_KERNEL_RUNNER := "just _run_riscv64"
# as of recent Rust nightly versions the old `CARGO_RUSTC_CURRENT_DIR` we used to locate the kernel artifact from the
# loader build script got removed :/ This is a stopgap until they come up with a replacement.
# https://github.com/rust-lang/cargo/issues/3946
export __K23_CARGO_RUSTC_CURRENT_DIR := `dirname "$(cargo locate-project --workspace --message-format plain)"`

# default recipe to display help information
_default:
Expand Down
1 change: 1 addition & 0 deletions kernel/riscv64gc-k23-none-kernel.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"position-independent-executables": true,
"relro-level": "full",
"supported-sanitizers": [
"shadow-call-stack",
"kernel-address"
],
"target-pointer-width": "64"
Expand Down
14 changes: 5 additions & 9 deletions kernel/src/arch/riscv64/setjmp_longjmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! result. In a nested calls scenario (e.g. host->wasm->host->wasm) it is therefore up to each host function
//! to propagate the trap and each host function therefore gets to clean up all its resources.
use core::arch::asm;
use core::arch::naked_asm;
use core::ptr;

/// A store for the register state used by `setjmp` and `longjmp`.
Expand Down Expand Up @@ -146,7 +146,7 @@ cfg_if::cfg_if! {
pub unsafe extern "C" fn setjmp(buf: *mut JumpBuf) -> isize {
cfg_if::cfg_if! {
if #[cfg(target_feature = "d")] {
asm! {
naked_asm! {
save_gp!(ra => a0[0]),
save_gp!(s0 => a0[1]),
save_gp!(s1 => a0[2]),
Expand Down Expand Up @@ -177,10 +177,9 @@ pub unsafe extern "C" fn setjmp(buf: *mut JumpBuf) -> isize {

"mv a0, zero",
"ret",
options(noreturn)
}
} else {
asm! {
naked_asm! {
save_gp!(ra => a0[0]),
save_gp!(s0 => a0[1]),
save_gp!(s1 => a0[2]),
Expand All @@ -197,7 +196,6 @@ pub unsafe extern "C" fn setjmp(buf: *mut JumpBuf) -> isize {
save_gp!(sp => a0[13]),
"mv a0, zero",
"ret",
options(noreturn)
}
}
}
Expand All @@ -217,7 +215,7 @@ pub unsafe extern "C" fn setjmp(buf: *mut JumpBuf) -> isize {
pub unsafe extern "C" fn longjmp(buf: *mut JumpBuf, val: isize) -> ! {
cfg_if::cfg_if! {
if #[cfg(target_feature = "d")] {
asm! {
naked_asm! {
load_gp!(a0[0] => ra),
load_gp!(a0[1] => s0),
load_gp!(a0[2] => s1),
Expand Down Expand Up @@ -248,10 +246,9 @@ pub unsafe extern "C" fn longjmp(buf: *mut JumpBuf, val: isize) -> ! {

"add a0, a1, zero",
"ret",
options(noreturn)
}
} else {
asm! {
naked_asm! {
load_gp!(a0[0] => ra),
load_gp!(a0[1] => s0),
load_gp!(a0[2] => s1),
Expand All @@ -269,7 +266,6 @@ pub unsafe extern "C" fn longjmp(buf: *mut JumpBuf, val: isize) -> ! {

"add a0, a1, zero",
"ret",
options(noreturn)
}
}
}
Expand Down
Loading

0 comments on commit a3e1859

Please sign in to comment.