@ -67,7 +67,7 @@ fn main() {
|
||||
.expect("Unable to create BPF install directory")
|
||||
.success());
|
||||
|
||||
let rust_programs = ["alloc", "iter", "noop"];
|
||||
let rust_programs = ["alloc", "iter", "noop", "panic"];
|
||||
for program in rust_programs.iter() {
|
||||
println!(
|
||||
"cargo:warning=(not a warning) Building Rust-based BPF programs: solana_bpf_rust_{}",
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[dependencies.compiler_builtins]
|
||||
path = "../../../../sdk/bpf/rust-bpf-sysroot/src/compiler-builtins"
|
||||
features = ["c", "mem"]
|
||||
|
@ -1,5 +1,4 @@
|
||||
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
|
||||
|
||||
//! @brief Example Rust-based BPF program that test dynamic memory allocation
|
||||
#![no_std]
|
||||
|
||||
#[macro_use]
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[dependencies.compiler_builtins]
|
||||
path = "../../../../sdk/bpf/rust-bpf-sysroot/src/compiler-builtins"
|
||||
features = ["c", "mem"]
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
|
||||
//! @brief Example Rust-based BPF program tests loop iteration
|
||||
|
||||
#![no_std]
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
[dependencies.compiler_builtins]
|
||||
path = "../../../../sdk/bpf/rust-bpf-sysroot/src/compiler-builtins"
|
||||
features = ["c", "mem"]
|
||||
|
3
programs/bpf/rust/panic/.gitignore
vendored
Normal file
3
programs/bpf/rust/panic/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/target/
|
||||
|
||||
Cargo.lock
|
22
programs/bpf/rust/panic/Cargo.toml
Normal file
22
programs/bpf/rust/panic/Cargo.toml
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
# Note: This crate must be built using build.sh
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-panic"
|
||||
version = "0.15.0"
|
||||
description = "Solana BPF iter program written in Rust"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk-bpf-utils = { path = "../../../../sdk/bpf/rust-utils", version = "0.16.0" }
|
||||
|
||||
[workspace]
|
||||
members = []
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_panic"
|
||||
crate-type = ["cdylib"]
|
6
programs/bpf/rust/panic/Xargo.toml
Normal file
6
programs/bpf/rust/panic/Xargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[dependencies.compiler_builtins]
|
||||
path = "../../../../sdk/bpf/rust-bpf-sysroot/src/compiler-builtins"
|
||||
features = ["c", "mem"]
|
||||
|
||||
[target.bpfel-unknown-unknown.dependencies]
|
||||
alloc = { path = "../../../../sdk/bpf/rust-bpf-sysroot/src/liballoc" }
|
10
programs/bpf/rust/panic/src/lib.rs
Normal file
10
programs/bpf/rust/panic/src/lib.rs
Normal file
@ -0,0 +1,10 @@
|
||||
//! @brief Example Rust-based BPF program that panics
|
||||
|
||||
#![no_std]
|
||||
|
||||
extern crate solana_sdk_bpf_utils;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> bool {
|
||||
panic!();
|
||||
}
|
@ -41,15 +41,15 @@ mod bpf {
|
||||
let mut elf = Vec::new();
|
||||
file.read_to_end(&mut elf).unwrap();
|
||||
|
||||
let (genesis_block, alice_keypair) = create_genesis_block(50);
|
||||
let (genesis_block, mint_keypair) = create_genesis_block(50);
|
||||
let bank = Bank::new(&genesis_block);
|
||||
let bank_client = BankClient::new(bank);
|
||||
|
||||
// Call user program
|
||||
let program_id = load_program(&bank_client, &alice_keypair, &bpf_loader::id(), elf);
|
||||
let instruction = create_invoke_instruction(alice_keypair.pubkey(), program_id, &1u8);
|
||||
let program_id = load_program(&bank_client, &mint_keypair, &bpf_loader::id(), elf);
|
||||
let instruction = create_invoke_instruction(mint_keypair.pubkey(), program_id, &1u8);
|
||||
bank_client
|
||||
.send_instruction(&alice_keypair, instruction)
|
||||
.send_instruction(&mint_keypair, instruction)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@ -72,23 +72,23 @@ mod bpf {
|
||||
let mut elf = Vec::new();
|
||||
file.read_to_end(&mut elf).unwrap();
|
||||
|
||||
let (genesis_block, alice_keypair) = create_genesis_block(50);
|
||||
let (genesis_block, mint_keypair) = create_genesis_block(50);
|
||||
let bank = Bank::new(&genesis_block);
|
||||
let bank_client = BankClient::new(bank);
|
||||
|
||||
let loader_pubkey = load_program(
|
||||
&bank_client,
|
||||
&alice_keypair,
|
||||
&mint_keypair,
|
||||
&native_loader::id(),
|
||||
"solana_bpf_loader".as_bytes().to_vec(),
|
||||
);
|
||||
|
||||
// Call user program
|
||||
let program_id = load_program(&bank_client, &alice_keypair, &loader_pubkey, elf);
|
||||
let program_id = load_program(&bank_client, &mint_keypair, &loader_pubkey, elf);
|
||||
let instruction =
|
||||
create_invoke_instruction(alice_keypair.pubkey(), program_id, &1u8);
|
||||
create_invoke_instruction(mint_keypair.pubkey(), program_id, &1u8);
|
||||
bank_client
|
||||
.send_instruction(&alice_keypair, instruction)
|
||||
.send_instruction(&mint_keypair, instruction)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
@ -107,38 +107,42 @@ mod bpf {
|
||||
solana_logger::setup();
|
||||
|
||||
let programs = [
|
||||
"solana_bpf_rust_alloc",
|
||||
"solana_bpf_rust_iter",
|
||||
"solana_bpf_rust_noop",
|
||||
("solana_bpf_rust_alloc", true),
|
||||
("solana_bpf_rust_iter", true),
|
||||
("solana_bpf_rust_noop", true),
|
||||
("solana_bpf_rust_panic", false),
|
||||
];
|
||||
for program in programs.iter() {
|
||||
let filename = create_bpf_path(program);
|
||||
println!("Test program: {:?} from {:?}", program, filename);
|
||||
let filename = create_bpf_path(program.0);
|
||||
println!("Test program: {:?} from {:?}", program.0, filename);
|
||||
let mut file = File::open(filename).unwrap();
|
||||
let mut elf = Vec::new();
|
||||
file.read_to_end(&mut elf).unwrap();
|
||||
|
||||
let (genesis_block, alice_keypair) = create_genesis_block(50);
|
||||
let (genesis_block, mint_keypair) = create_genesis_block(50);
|
||||
let bank = Bank::new(&genesis_block);
|
||||
let bank_client = BankClient::new(bank);
|
||||
|
||||
let loader_pubkey = load_program(
|
||||
&bank_client,
|
||||
&alice_keypair,
|
||||
&mint_keypair,
|
||||
&native_loader::id(),
|
||||
"solana_bpf_loader".as_bytes().to_vec(),
|
||||
);
|
||||
|
||||
// Call user program
|
||||
let program_id = load_program(&bank_client, &alice_keypair, &loader_pubkey, elf);
|
||||
let program_id = load_program(&bank_client, &mint_keypair, &loader_pubkey, elf);
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(alice_keypair.pubkey(), true),
|
||||
AccountMeta::new(mint_keypair.pubkey(), true),
|
||||
AccountMeta::new(Keypair::new().pubkey(), false),
|
||||
];
|
||||
let instruction = Instruction::new(program_id, &1u8, account_metas);
|
||||
bank_client
|
||||
.send_instruction(&alice_keypair, instruction)
|
||||
.unwrap();
|
||||
let result = bank_client.send_instruction(&mint_keypair, instruction);
|
||||
if program.1 {
|
||||
assert!(result.is_ok());
|
||||
} else {
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user