11
programs/bpf/rust/noop/Cargo.toml
Normal file
11
programs/bpf/rust/noop/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "solana-bpf-noop"
|
||||
version = "0.11.0"
|
||||
description = "Solana BPF noop program"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
rbpf = "0.1.0"
|
||||
solana-sdk = { path = "../../../../sdk", version = "0.11.0" }
|
10
programs/bpf/rust/noop/build.sh
Executable file
10
programs/bpf/rust/noop/build.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash -ex
|
||||
|
||||
# TODO building release flavor with rust produces a bunch of output .bc files
|
||||
INTERDIR=../../../target/release
|
||||
OUTDIR="${1:-../../../target/debug/}"
|
||||
mkdir -p "$OUTDIR"
|
||||
# cargo +nightly rustc --release -- -C panic=abort --emit=llvm-ir
|
||||
cargo +nightly rustc --release -- -C panic=abort --emit=llvm-bc
|
||||
cp "$INTERDIR"/deps/noop_rust-*.bc "$OUTDIR"/noop_rust.bc
|
||||
/usr/local/opt/llvm/bin/llc -march=bpf -filetype=obj -o "$OUTDIR"/noop_rust.o "$OUTDIR"/noop_rust.bc
|
3
programs/bpf/rust/noop/dump.sh
Executable file
3
programs/bpf/rust/noop/dump.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
/usr/local/opt/llvm/bin/llvm-objdump -color -source -disassemble target/release/noop_rust.o
|
15
programs/bpf/rust/noop/src/lib.rs
Normal file
15
programs/bpf/rust/noop/src/lib.rs
Normal file
@ -0,0 +1,15 @@
|
||||
extern crate rbpf;
|
||||
|
||||
use std::mem::transmute;
|
||||
|
||||
#[no_mangle]
|
||||
#[link_section = ".text,entrypoint"] // TODO platform independent needed
|
||||
pub extern "C" fn entrypoint(_raw: *mut u8) {
|
||||
let bpf_func_trace_printk = unsafe {
|
||||
transmute::<u64, extern "C" fn(u64, u64, u64, u64, u64)>(
|
||||
rbpf::helpers::BPF_TRACE_PRINTK_IDX as u64,
|
||||
)
|
||||
};
|
||||
|
||||
bpf_func_trace_printk(0, 0, 1, 2, 3);
|
||||
}
|
Reference in New Issue
Block a user