Add adjustable stack size and call depth (#12728)
This commit is contained in:
26
programs/bpf/rust/call_depth/Cargo.toml
Normal file
26
programs/bpf/rust/call_depth/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
# Note: This crate must be built using do.sh
|
||||
|
||||
[package]
|
||||
name = "solana-bpf-rust-call-depth"
|
||||
version = "1.4.0"
|
||||
description = "Solana BPF test program written in Rust"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../../../sdk/", version = "1.4.0", default-features = false }
|
||||
|
||||
[features]
|
||||
program = ["solana-sdk/program"]
|
||||
default = ["program", "solana-sdk/default"]
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_call_depth"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
2
programs/bpf/rust/call_depth/Xargo.toml
Normal file
2
programs/bpf/rust/call_depth/Xargo.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
27
programs/bpf/rust/call_depth/src/lib.rs
Normal file
27
programs/bpf/rust/call_depth/src/lib.rs
Normal file
@ -0,0 +1,27 @@
|
||||
//! @brief Example Rust-based BPF program that tests call depth and stack usage
|
||||
|
||||
use solana_sdk::{entrypoint::SUCCESS, info};
|
||||
|
||||
#[inline(never)]
|
||||
pub fn recurse(data: &mut [u8]) {
|
||||
if data.len() <= 1 {
|
||||
return;
|
||||
}
|
||||
recurse(&mut data[1..]);
|
||||
info!(line!(), 0, 0, 0, data[0]);
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
#[inline(never)]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
|
||||
info!("Call depth");
|
||||
let depth = *(input.add(16) as *mut u8);
|
||||
info!(line!(), 0, 0, 0, depth);
|
||||
let mut data = Vec::with_capacity(depth as usize);
|
||||
for i in 0_u8..depth {
|
||||
data.push(i);
|
||||
}
|
||||
recurse(&mut data);
|
||||
SUCCESS
|
||||
}
|
Reference in New Issue
Block a user