From 20d62e22b7f2bf08892e174ae1d23b8c5be78642 Mon Sep 17 00:00:00 2001 From: clabby Date: Fri, 10 Nov 2023 08:32:56 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20a=20project=20example=20from?= =?UTF-8?q?=20@willemolding's=20`Cannon-rs`=20project?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/mipsevm/src/mips/instrumented.rs | 32 ++++++++ example/Makefile | 7 ++ example/bin/hello-willem-rs.elf | Bin 0 -> 29392 bytes example/hello-rs-willem/.gitignore | 2 + example/hello-rs-willem/Cargo.lock | 73 ++++++++++++++++++ example/hello-rs-willem/Cargo.toml | 12 +++ example/hello-rs-willem/README.md | 20 +++++ .../mips-unknown-linux-gnu.json | 29 +++++++ example/hello-rs-willem/src/main.rs | 36 +++++++++ 9 files changed, 211 insertions(+) create mode 100644 example/bin/hello-willem-rs.elf create mode 100644 example/hello-rs-willem/.gitignore create mode 100644 example/hello-rs-willem/Cargo.lock create mode 100644 example/hello-rs-willem/Cargo.toml create mode 100644 example/hello-rs-willem/README.md create mode 100644 example/hello-rs-willem/mips-unknown-linux-gnu.json create mode 100644 example/hello-rs-willem/src/main.rs diff --git a/crates/mipsevm/src/mips/instrumented.rs b/crates/mipsevm/src/mips/instrumented.rs index 4ebb99b..0762013 100644 --- a/crates/mipsevm/src/mips/instrumented.rs +++ b/crates/mipsevm/src/mips/instrumented.rs @@ -227,6 +227,38 @@ mod test { } } + #[test] + fn test_hello_rs_willem() { + let elf_bytes = include_bytes!("../../../../example/bin/hello-willem-rs.elf"); + let mut state = load_elf(elf_bytes).unwrap(); + patch::patch_go(elf_bytes, &mut state).unwrap(); + patch::patch_stack(&mut state).unwrap(); + + let out = BufWriter::new(Vec::default()); + let err = BufWriter::new(Vec::default()); + let mut ins = + InstrumentedState::new(state, StaticOracle::new(b"hello world".to_vec()), out, err); + + for _ in 0..400_000 { + if ins.state.exited { + break; + } + ins.step(false).unwrap(); + } + + assert!(ins.state.exited, "must exit"); + assert_eq!(ins.state.exit_code, 0, "must exit with 0"); + + assert_eq!( + String::from_utf8(ins.std_out.buffer().to_vec()).unwrap(), + "hello world!\n" + ); + assert_eq!( + String::from_utf8(ins.std_err.buffer().to_vec()).unwrap(), + "" + ); + } + #[test] fn test_hello() { let elf_bytes = include_bytes!("../../../../example/bin/hello.elf"); diff --git a/example/Makefile b/example/Makefile index 6712cd0..8dd54e3 100644 --- a/example/Makefile +++ b/example/Makefile @@ -6,6 +6,13 @@ elf: $(patsubst %/go.mod,bin/%.elf,$(wildcard */go.mod)) .PHONY: dump dump: $(patsubst %/go.mod,bin/%.dump,$(wildcard */go.mod)) +# .PHONY: ex-rs +# ex-rs: +# cd hello-rs && \ +# RUSTFLAGS='-C link-arg=-no-pie -C target-cpu=mips32 -C target-feature=-mips32r2,-fpxx,-nooddspreg,+mips32,+crt-static,+soft-float' \ +# cross build --release --target ../mips-unknown-linux-gnu.json -Z build-std -Z build-std-features=panic-unwind && \ +# cp ../../target/mips-unknown-linux-gnu/release/hello-rs ../bin/hello-rs.elf + bin: mkdir bin diff --git a/example/bin/hello-willem-rs.elf b/example/bin/hello-willem-rs.elf new file mode 100644 index 0000000000000000000000000000000000000000..686f5a7da7d199ae7385f8e3c311f9e5d3d11512 GIT binary patch literal 29392 zcmeHv4|H5tdFS^=BYP~#$;go%ktoR<>y0GG^7#Fq_Yx%@$#!CjNu0zXCZ!#{nR#QW zktH#b5*z3;HU?5wkzLAmLpMw1KMAHawi5!RT_8#dG~Lpkl$HX!IXz03KcSli(*vgg zvYGvT_q~xuvSd57-9P8-JAQuezI*R?zx&Y4{Q++rPhTC$Udc&JY zMcaO~UJ=#?f)px9z`9uVR#a^ z2`|u$BK+RdMv>0PzVyDjkIyDLzgU?)`vr=heU{pe94agEjOa^8K3-PpBpKtKZ;D6vGF)7%QGNkqn`fUS_3Sz7 zrYBkxjcg#N!tAU6ex7| zICUuzlJHbwar(Wp$4EXqO-koUig$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fd5DCC@~<#YLhrkh0^Uw2?&1x<&dlSD6uLO!g~(_gUj~b7kM*=3J2c7 zmY(Yu@=kh@3AXeL@{PfoEU#uja!lTFwW8)>TMU}n%;l@L8F|O0CKWgtbL3pg=}m_| zudcz1sQSOyUJUmbF(g7V{KL6?C#~u@gfH}uUCT&IZn<5a>x=yW1oHU5kTYG+tW{93 zQ|8iX*}{Qg!JjoG6N#NLRg2xof{R5r@#6zEulrReZz&oT;hHTpjn;)LGoJ;Og?R)DcJ^_;w*@%>gT~oqiNtH%~8A$m9+2Gj9K%qo) zB}$2dDU=dtUMRJ9WSmmWZ7J+j@RT{}v| zzXglnoLwu9{ouy$Vdt+{Smri-Fpt~e{1V@!;I3YL28gd)a97*yMmyXjuBJfyW-&+p92r!S+hiZi{D`4A+9RCUqgx8 zVIKTD0KQkg5HwlP&Yy3`zYh?<5x}{rxvL5fKT@s2x)o>h2!EV-uL@Q+dc!s2%S3%?1I AH2?qr literal 0 HcmV?d00001 diff --git a/example/hello-rs-willem/.gitignore b/example/hello-rs-willem/.gitignore new file mode 100644 index 0000000..d8d0e32 --- /dev/null +++ b/example/hello-rs-willem/.gitignore @@ -0,0 +1,2 @@ +# Rust target dir +target diff --git a/example/hello-rs-willem/Cargo.lock b/example/hello-rs-willem/Cargo.lock new file mode 100644 index 0000000..2cf98e3 --- /dev/null +++ b/example/hello-rs-willem/Cargo.lock @@ -0,0 +1,73 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "cannon-heap" +version = "0.1.0" +source = "git+https://github.com/badboilabs/Cannon-rs#21b8e555477e740da6f304cd6e3b349c7f0e7f20" +dependencies = [ + "linked_list_allocator", +] + +[[package]] +name = "cannon-io" +version = "0.1.0" +source = "git+https://github.com/badboilabs/Cannon-rs#21b8e555477e740da6f304cd6e3b349c7f0e7f20" +dependencies = [ + "log", +] + +[[package]] +name = "hello-rs-willem" +version = "0.0.1" +dependencies = [ + "cannon-heap", + "cannon-io", +] + +[[package]] +name = "linked_list_allocator" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +dependencies = [ + "spinning_top", +] + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "spinning_top" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" +dependencies = [ + "lock_api", +] diff --git a/example/hello-rs-willem/Cargo.toml b/example/hello-rs-willem/Cargo.toml new file mode 100644 index 0000000..4ea5607 --- /dev/null +++ b/example/hello-rs-willem/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "hello-rs-willem" +edition = "2021" +version = "0.0.1" +authors = ["Willem Olding"] + +[dependencies] +cannon-io = { git = "https://github.com/badboilabs/Cannon-rs" } +cannon-heap = { git = "https://github.com/badboilabs/Cannon-rs" } + +[profile.release] +panic = "abort" diff --git a/example/hello-rs-willem/README.md b/example/hello-rs-willem/README.md new file mode 100644 index 0000000..3b04429 --- /dev/null +++ b/example/hello-rs-willem/README.md @@ -0,0 +1,20 @@ +# [`Cannon-rs`][cannon-rs-willem] example program + +This is an example Rust program for Cannon that uses Willem Olding's [program template][program-template-willem]. + +## Building + +The program can be built using Badboilabs' provided container: + +```sh +docker run \ + --rm \ + --platform linux/amd64 \ + -v `pwd`/:/code \ + -w="/code" \ + ghcr.io/badboilabs/cannon-rs/builder:main cargo build --release -Zbuild-std && \ + cp target/mips-unknown-none/release/hello-rs-willem ../bin/hello-willem-rs.elf +``` + +[cannon-rs-willem]: https://github.com/BadBoiLabs/Cannon-rs +[program-template-willem]: https://github.com/BadBoiLabs/Cannon-rs/tree/main/project-template diff --git a/example/hello-rs-willem/mips-unknown-linux-gnu.json b/example/hello-rs-willem/mips-unknown-linux-gnu.json new file mode 100644 index 0000000..650ef42 --- /dev/null +++ b/example/hello-rs-willem/mips-unknown-linux-gnu.json @@ -0,0 +1,29 @@ +{ + "arch": "mips", + "cpu": "mips32", + "crt-objects-fallback": "false", + "crt-static-respected": true, + "data-layout": "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64", + "dynamic-linking": true, + "env": "gnu", + "features": "-mips32r2,-fpxx,-nooddspreg,+mips32,+crt-static,+soft-float", + "has-rpath": true, + "has-thread-local": true, + "linker-flavor": "gnu-cc", + "llvm-target": "mips-unknown-linux-gnu", + "max-atomic-width": 32, + "os": "linux", + "position-independent-executables": true, + "relro-level": "full", + "supported-split-debuginfo": [ + "packed", + "unpacked", + "off" + ], + "target-endian": "big", + "target-family": [ + "unix" + ], + "target-mcount": "_mcount", + "target-pointer-width": "32" +} diff --git a/example/hello-rs-willem/src/main.rs b/example/hello-rs-willem/src/main.rs new file mode 100644 index 0000000..3cff4c8 --- /dev/null +++ b/example/hello-rs-willem/src/main.rs @@ -0,0 +1,36 @@ +//! `cannon-rs` program template, provided by Willem Olding in the other [`Cannon-rs`](https://github.com/BadBoiLabs/Cannon-rs/tree/main). + +#![no_std] +#![no_main] +#![feature(core_intrinsics)] +#![feature(alloc_error_handler)] +#![feature(asm_experimental_arch)] + +extern crate alloc; + +const HEAP_SIZE: usize = 0x400000; + +use cannon_heap::init_heap; +use cannon_io::prelude::*; + +#[no_mangle] +pub extern "C" fn _start() { + init_heap!(HEAP_SIZE); + + print("hello world!\n").unwrap(); + + exit(0); +} + +#[panic_handler] +fn panic(info: &core::panic::PanicInfo) -> ! { + let msg = alloc::format!("panic: {}", info); + let _ = print(&msg); + exit(2); +} + +#[alloc_error_handler] +fn alloc_error_handler(_layout: alloc::alloc::Layout) -> ! { + let _ = print("alloc error!"); + exit(3); +}