Skip to content

Commit d6e7525

Browse files
refactor: break up kstd crate into multiple smaller crates (#90)
This change breaks up the monolithic `kstd` crate into multiple smaller crates (`panic`, `unwind`, `sync`, `backtrace`, `tls`, and `riscv`) that are easier to compose, work on and extend
1 parent 7d655d0 commit d6e7525

File tree

145 files changed

+3146
-2322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+3146
-2322
lines changed

Cargo.lock

+157-206
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+32-39
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
[workspace]
2-
members = [
3-
"libs/*",
4-
"kernel",
5-
"loader",
6-
"loader/api",
7-
"loader/api/macros",
8-
"libs/ktest/macros", "build/lz4-block-compress",
9-
]
2+
members = ["kernel", "libs/*", "build/*", "loader", "loader/api", "loader/api/macros", "libs/ktest/macros", "libs/kconfig-declare/macros"]
103
resolver = "2"
114

125
[workspace.package]
@@ -22,41 +15,47 @@ large_stack_arrays = "deny"
2215
recursive_format_impl = "deny"
2316

2417
[workspace.dependencies]
25-
dtb-parser = { path = "libs/dtb-parser" }
26-
uart-16550 = { path = "libs/uart-16550" }
27-
vmm = { path = "libs/vmm" }
2818
loader-api = { path = "loader/api" }
29-
kstd = { path = "libs/kstd" }
19+
backtrace = { path = "libs/backtrace" }
20+
dtb-parser = { path = "libs/dtb-parser" }
21+
kconfig-declare = { path = "libs/kconfig-declare" }
22+
kmm = { path = "libs/kmm" }
3023
ktest = { path = "libs/ktest" }
31-
wast = { path = "libs/wast" }
32-
wat = { path = "libs/wat" }
3324
leb128 = { path = "libs/leb128" }
25+
panic = { path = "libs/panic" }
26+
riscv = { path = "libs/riscv" }
27+
semihosting-logger = { path = "libs/semihosting-logger" }
28+
sync = { path = "libs/sync" }
29+
tls = { path = "libs/tls" }
30+
unwind = { path = "libs/unwind" }
3431
wasm-encoder = { path = "libs/wasm-encoder" }
32+
wast = { path = "libs/wast" }
33+
wat = { path = "libs/wat" }
3534

36-
onlyerror = { version = "0.1.4", default-features = false }
35+
cfg-if = "1.0.0"
36+
lock_api = "0.4.12"
3737
log = "0.4.21"
3838
bitflags = "2.6.0"
39-
cfg-if = "1.0.0"
40-
linked_list_allocator = "0.10.5"
39+
onlyerror = { version = "0.1.4", default-features = false }
4140
arrayvec = { version = "0.7.4", default-features = false }
42-
ed25519-dalek = { version = "2.1.1", default-features = false }
43-
object = { version = "0.36.0", default-features = false }
4441
lz4_flex = { version = "0.11", default-features = false }
45-
lock_api = "0.4.12"
42+
object = { version = "0.36.0", default-features = false }
43+
gimli = { version = "0.31.0", default-features = false, features = ["read"] }
44+
linked_list_allocator = "0.10.5"
45+
talc = "4.4.1"
46+
#ed25519-dalek = { version = "2.1.1", default-features = false, features = ["fast"] }
47+
48+
# wast dependencies
49+
bumpalo = "3.14.0"
4650
unicode-width = { version = "0.1.9" }
4751
memchr = { version = "2.4.1", default-features = false }
48-
bumpalo = "3.14.0"
49-
rustc-demangle = "0.1.24"
50-
postcard = { version = "1.0.8", default-features = false, features = ["alloc"] }
51-
talc = "4.4.1"
52-
gimli = { version = "0.31.0", default-features = false, features = ["read"] }
5352

5453
# cranelift dependencies
5554
hashbrown = { version = "0.14.5", default-features = false, features = [
5655
"inline-more",
5756
"nightly",
5857
] }
59-
wasmparser = { version = "0.214.0", default-features = false }
58+
wasmparser = { version = "0.215.0", default-features = false }
6059
target-lexicon = { version = "0.12.14", default-features = false }
6160
cranelift-wasm = { git = "https://github.com/JonasKruckenberg/wasmtime", branch = "no_std2", default-features = false, features = [
6261
"core",
@@ -71,16 +70,10 @@ cranelift-frontend = { git = "https://github.com/JonasKruckenberg/wasmtime", bra
7170
cranelift-entity = { git = "https://github.com/JonasKruckenberg/wasmtime", branch = "no_std2", default-features = false }
7271

7372
# build dependencies
74-
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
75-
rand_core = { version = "0.6.4", features = ["getrandom"] }
76-
clap = { version = "4.5.7", features = ["derive"] }
77-
env_logger = "0.11.3"
78-
anstyle = "1.0.7"
79-
cargo_metadata = "0.18.1"
8073
proc-macro2 = "1"
8174
quote = "1"
8275
syn = { version = "2", features = ["full"] }
83-
toml = "0.8.14"
76+
toml = "0.8.19"
8477

8578
[profile.release]
8679
opt-level = 3
@@ -90,14 +83,14 @@ strip = true
9083
overflow-checks = true
9184
split-debuginfo = "packed"
9285

93-
[profile.dev.package.ed25519-dalek]
94-
opt-level = 3
95-
96-
[profile.test.package.ed25519-dalek]
97-
opt-level = 3
86+
#[profile.dev.package.ed25519-dalek]
87+
#opt-level = 3
88+
#
89+
#[profile.test.package.ed25519-dalek]
90+
#opt-level = 3
9891

9992
[profile.dev.package.lz4_flex]
10093
opt-level = 3
10194

10295
[profile.test.package.lz4_flex]
103-
opt-level = 3
96+
opt-level = 3
File renamed without changes.

configs/riscv64-qemu.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
runner = "qemu-system-riscv64"
2+
memory-mode = "Riscv64Sv39"
3+
wasm-features = ["a", "b"]
24

35
[kernel]
46
target = "./configs/riscv64gc-k23-none-kernel.json"
57
target-triple = "riscv64gc-k23-none-kernel"
8+
stack-size-pages = 256
9+
trap-stack-size-pages = 16
10+
heap-size-pages = 8192
11+
log-level = "trace"
612

713
[loader]
814
target = "./configs/riscv64imac-k23-none-loader.json"
9-
target-triple = "riscv64imac-k23-none-loader"
15+
target-triple = "riscv64imac-k23-none-loader"
16+
linker-script = "./configs/loader-riscv64-qemu.ld"
17+
stack-size-pages = 32
18+
log-level = "trace"

configs/riscv64gc-k23-none-kernel.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"llvm-target": "riscv64",
1414
"max-atomic-width": 64,
1515
"panic-strategy": "unwind",
16-
"relocation-model": "pie",
16+
"relocation-model": "pic",
17+
"tls-model": "local-exec",
1718
"supported-sanitizers": [
1819
"kernel-address"
1920
],

deny.toml

-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ allow = [
1313
"Apache-2.0", # requires license notice
1414
"Unicode-DFS-2016", # requires license notice
1515
"Apache-2.0 WITH LLVM-exception",
16-
"BSD-3-Clause", # requires license notice and link to source code TODO allow?
1716
]
1817

1918
[sources]
2019
allow-git = [
2120
"https://github.com/JonasKruckenberg/wasmtime?branch=no_std", # Cranelift no_std fork
22-
"https://github.com/JonasKruckenberg/HdrHistogram_rust" # hdrhistogram no_std fork
2321
]

flake.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
just
3434
nushell
3535
cargo-binutils
36+
mdbook
3637
lz4
3738
openssl
3839
coreutils

justfile

+21-24
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ lint config *FLAGS: (clippy config FLAGS) (check-fmt FLAGS)
4242
clippy config $RUSTFLAGS='-Dwarnings' *CARGO_ARGS='':
4343
#!/usr/bin/env nu
4444
let config = open {{config}}
45+
$env.K23_CONFIG = {{config}}
4546

4647
# check kernel and dependencies
4748
({{_cargo}} clippy
4849
-p kernel
4950
--target $config.kernel.target
50-
--tests
51-
--benches
5251
--profile {{profile}}
5352
{{_buildstd}}
5453
{{CARGO_ARGS}})
@@ -57,8 +56,6 @@ clippy config $RUSTFLAGS='-Dwarnings' *CARGO_ARGS='':
5756
({{_cargo}} clippy
5857
-p loader
5958
--target $config.loader.target
60-
--tests
61-
--benches
6259
--profile {{profile}}
6360
{{_buildstd}}
6461
{{CARGO_ARGS}})
@@ -67,13 +64,12 @@ clippy config $RUSTFLAGS='-Dwarnings' *CARGO_ARGS='':
6764
check config $RUSTFLAGS='' *CARGO_ARGS='':
6865
#!/usr/bin/env nu
6966
let config = open {{config}}
67+
$env.K23_CONFIG = {{config}}
7068

7169
# check kernel and dependencies
7270
({{_cargo}} check
7371
-p kernel
7472
--target $config.kernel.target
75-
--tests
76-
--benches
7773
--profile {{profile}}
7874
{{_buildstd}}
7975
{{CARGO_ARGS}})
@@ -82,8 +78,6 @@ check config $RUSTFLAGS='' *CARGO_ARGS='':
8278
({{_cargo}} check
8379
-p loader
8480
--target $config.loader.target
85-
--tests
86-
--benches
8781
--profile {{profile}}
8882
{{_buildstd}}
8983
{{CARGO_ARGS}})
@@ -99,14 +93,14 @@ run config CARGO_ARGS="" *ARGS="": (build config CARGO_ARGS) (_run config "targe
9993
build config *CARGO_ARGS="": && (_make_bootimg config "target/k23/payload" CARGO_ARGS)
10094
#!/usr/bin/env nu
10195
let config = open {{config}}
102-
let target = try { $config | get kernel.target } catch { $config | get target }
96+
$env.K23_CONFIG = {{config}}
10397

10498
let out_dir = "{{_target_dir}}" | path join "k23"
10599
mkdir $out_dir
106100

107101
let cargo_out = ({{_cargo}} build
108102
-p kernel
109-
--target $target
103+
--target $config.kernel.target
110104
--profile {{profile}}
111105
--message-format=json
112106
{{_buildstd}}
@@ -117,13 +111,15 @@ build config *CARGO_ARGS="": && (_make_bootimg config "target/k23/payload" CARGO
117111
test config *CARGO_ARGS="" :
118112
#!/usr/bin/env nu
119113
let config = open {{config}}
120-
let target = try { $config.kernel.target } catch { $config.target }
114+
$env.K23_CONFIG = {{config}}
115+
116+
#let target = try { } catch { $config.target }
121117
let triple = try { $config.kernel.target-triple } catch { $config.target-triple }
122118

123119
# CARGO_TARGET_<triple>_RUNNER
124120
$env.CARGO_TARGET_RISCV64GC_K23_NONE_KERNEL_RUNNER = "just profile={{profile}} _runner {{config}}"
125121

126-
{{ _cargo }} test -p kernel --target $target {{ _buildstd }} {{ CARGO_ARGS }}
122+
{{ _cargo }} test -p kernel --target $config.kernel.target {{ _buildstd }} {{ CARGO_ARGS }}
127123

128124
# This is a helper recipe designed to be used as a cargo *target runner*
129125
# When running tests, the `cargo test` command will produce potentially many executables.
@@ -137,6 +133,8 @@ _runner config binary *ARGS: (_make_bootimg config binary) (_run config "target/
137133
_run config binary *ARGS:
138134
#!/usr/bin/env nu
139135
let config = open {{ config }}
136+
$env.K23_CONFIG = {{config}}
137+
140138
let runner = $config.runner
141139

142140
let cpu = match $runner {
@@ -173,15 +171,15 @@ _run config binary *ARGS:
173171
_make_bootimg config payload *CARGO_ARGS="":
174172
#!/usr/bin/env nu
175173
let config = open {{config}}
176-
let target = try { $config.loader.target } catch { $config.target }
174+
$env.K23_CONFIG = {{config}}
177175

178176
let out_dir = "{{_target_dir}}" | path join "k23"
179177
mkdir $out_dir
180178

181179
let loader_path = ($out_dir | path join loader)
182-
let secret_key_path = ($out_dir | path join secret.der)
183-
let public_key_path = ($out_dir | path join pubkey.bin)
184-
let signature_path = ($out_dir | path join signature.bin)
180+
#let secret_key_path = ($out_dir | path join secret.der)
181+
#let public_key_path = ($out_dir | path join pubkey.bin)
182+
#let signature_path = ($out_dir | path join signature.bin)
185183
let bootimg_path = ($out_dir | path join bootimg.bin)
186184

187185
# Step 1: Compress the payload
@@ -190,25 +188,24 @@ _make_bootimg config payload *CARGO_ARGS="":
190188
{{_cargo}} run -p lz4-block-compress {{payload}} $payload_lz4_path
191189

192190
# Step 2: Sign the compressed payload
193-
print "Signing the compressed payload..."
191+
#print "Signing the compressed payload..."
194192
# Write ed25519 key pair
195-
echo "{{_signing_key}}" | openssl pkey -outform DER -out $secret_key_path
193+
#echo "_signing_key" | openssl pkey -outform DER -out $secret_key_path
196194
# Do the actual signing
197-
openssl pkeyutl -sign -inkey $secret_key_path -out $signature_path -rawin -in $payload_lz4_path
195+
#openssl pkeyutl -sign -inkey $secret_key_path -out $signature_path -rawin -in $payload_lz4_path
198196
# Extract the 32-byte public key
199-
openssl pkey -in $secret_key_path -pubout -outform DER | tail -c 32 | save -f $public_key_path
197+
#openssl pkey -in $secret_key_path -pubout -outform DER | tail -c 32 | save -f $public_key_path
200198

201199
# Assign environment variables so we can pick it up in the loader build script
202-
$env.K23_VERIFYING_KEY_PATH = $public_key_path
203-
$env.K23_SIGNATURE_PATH = $signature_path
200+
#$env.K23_VERIFYING_KEY_PATH = $public_key_path
201+
#$env.K23_SIGNATURE_PATH = $signature_path
204202
$env.K23_PAYLOAD_PATH = $payload_lz4_path
205-
$env.K23_PAYLOAD_SIZE = (stat -c %s {{payload}})
206203

207204
# Step 3: Build the bootloader
208205
print "Building the bootloader..."
209206
let cargo_out = ({{_cargo}} build
210207
-p loader
211-
--target $target
208+
--target $config.loader.target
212209
--profile {{profile}}
213210
--message-format=json
214211
{{_buildstd}}

0 commit comments

Comments
 (0)