Bump rust-sysroot to v0.13 (#14001)
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
//! @brief Example Rust-based BPF program tests loop iteration
|
//! @brief Example Rust-based BPF program tests loop iteration
|
||||||
|
|
||||||
extern crate solana_program;
|
extern crate solana_program;
|
||||||
use solana_program::entrypoint::SUCCESS;
|
use solana_program::{custom_panic_default, entrypoint::SUCCESS};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||||
@ -50,6 +50,8 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
|||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_panic_default!();
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use solana_program::{entrypoint::SUCCESS, msg};
|
use solana_program::{custom_panic_default, entrypoint::SUCCESS, msg};
|
||||||
use std::{alloc::Layout, mem};
|
use std::{alloc::Layout, mem};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@ -81,6 +81,8 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
|||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_panic_default!();
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! @brief Example Rust-based BPF program that tests call depth and stack usage
|
//! @brief Example Rust-based BPF program that tests call depth and stack usage
|
||||||
|
|
||||||
use solana_program::{entrypoint::SUCCESS, msg};
|
use solana_program::{custom_panic_default, entrypoint::SUCCESS, msg};
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
pub fn recurse(data: &mut [u8]) {
|
pub fn recurse(data: &mut [u8]) {
|
||||||
@ -25,3 +25,5 @@ pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
|
|||||||
recurse(&mut data);
|
recurse(&mut data);
|
||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_panic_default!();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! @brief Example Rust-based BPF program tests loop iteration
|
//! @brief Example Rust-based BPF program tests loop iteration
|
||||||
|
|
||||||
extern crate solana_program;
|
extern crate solana_program;
|
||||||
use solana_program::{entrypoint::SUCCESS, msg};
|
use solana_program::{custom_panic_default, entrypoint::SUCCESS, msg};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||||
@ -18,6 +18,8 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
|||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_panic_default!();
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
mod helper;
|
mod helper;
|
||||||
extern crate solana_program;
|
extern crate solana_program;
|
||||||
use solana_program::{entrypoint::SUCCESS, msg};
|
use solana_program::{custom_panic_default, entrypoint::SUCCESS, msg};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||||
@ -26,6 +26,8 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
|||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_panic_default!();
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#![feature(compiler_builtins_lib)]
|
#![feature(compiler_builtins_lib)]
|
||||||
|
|
||||||
extern crate compiler_builtins;
|
extern crate compiler_builtins;
|
||||||
use solana_program::entrypoint::SUCCESS;
|
use solana_program::{custom_panic_default, entrypoint::SUCCESS, info};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||||
@ -183,3 +183,5 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
|||||||
|
|
||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_panic_default!();
|
||||||
|
@ -11,6 +11,10 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
solana-program = { path = "../../../../sdk/program", version = "1.4.15" }
|
solana-program = { path = "../../../../sdk/program", version = "1.4.15" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["custom-panic"]
|
||||||
|
custom-panic = []
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "solana_bpf_rust_panic"
|
name = "solana_bpf_rust_panic"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
@ -1,8 +1,24 @@
|
|||||||
//! @brief Example Rust-based BPF program that panics
|
//! @brief Example Rust-based BPF program that panics
|
||||||
|
|
||||||
extern crate solana_program;
|
#[cfg(all(feature = "custom-panic", target_arch = "bpf"))]
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
fn custom_panic(info: &core::panic::PanicInfo<'_>) {
|
||||||
panic!();
|
// Note: Full panic reporting is included here for testing purposes
|
||||||
|
solana_program::msg!("program custom panic enabled");
|
||||||
|
solana_program::msg!(&format!("{}", info));
|
||||||
|
}
|
||||||
|
|
||||||
|
extern crate solana_program;
|
||||||
|
use solana_program::{
|
||||||
|
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey,
|
||||||
|
};
|
||||||
|
|
||||||
|
entrypoint!(process_instruction);
|
||||||
|
fn process_instruction(
|
||||||
|
_program_id: &Pubkey,
|
||||||
|
_accounts: &[AccountInfo],
|
||||||
|
_instruction_data: &[u8],
|
||||||
|
) -> ProgramResult {
|
||||||
|
assert_eq!(1, 2);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
extern crate solana_program;
|
extern crate solana_program;
|
||||||
use solana_bpf_rust_param_passing_dep::{Data, TestDep};
|
use solana_bpf_rust_param_passing_dep::{Data, TestDep};
|
||||||
use solana_program::{entrypoint::SUCCESS, msg};
|
use solana_program::{custom_panic_default, entrypoint::SUCCESS, msg};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||||
@ -23,6 +23,8 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
|||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_panic_default!();
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -203,12 +203,12 @@ fn process_instruction(
|
|||||||
macro_rules! check {
|
macro_rules! check {
|
||||||
($left:expr, $right:expr) => {
|
($left:expr, $right:expr) => {
|
||||||
if $left != $right {
|
if $left != $right {
|
||||||
msg!(&format!(
|
msg!(
|
||||||
"Condition failure: {:?} != {:?} at line {:?}",
|
"Condition failure: {:?} != {:?} at line {:?}",
|
||||||
$left,
|
$left,
|
||||||
$right,
|
$right,
|
||||||
line!()
|
line!()
|
||||||
));
|
);
|
||||||
return Err(ProgramError::Custom(0));
|
return Err(ProgramError::Custom(0));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
extern crate solana_program;
|
extern crate solana_program;
|
||||||
use solana_program::{
|
use solana_program::{
|
||||||
|
custom_panic_default,
|
||||||
hash::{hashv, Hasher},
|
hash::{hashv, Hasher},
|
||||||
msg,
|
msg,
|
||||||
};
|
};
|
||||||
@ -22,6 +23,8 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
|||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
custom_panic_default!();
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -835,7 +835,6 @@ fn test_program_bpf_ro_modify() {
|
|||||||
let instruction = Instruction::new(program_pubkey, &[1_u8], account_metas.clone());
|
let instruction = Instruction::new(program_pubkey, &[1_u8], account_metas.clone());
|
||||||
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
||||||
let result = bank_client.send_and_confirm_message(&[&mint_keypair, &test_keypair], message);
|
let result = bank_client.send_and_confirm_message(&[&mint_keypair, &test_keypair], message);
|
||||||
println!("result {:?}", result);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.unwrap_err().unwrap(),
|
result.unwrap_err().unwrap(),
|
||||||
TransactionError::InstructionError(0, InstructionError::Custom(0xb9f0002))
|
TransactionError::InstructionError(0, InstructionError::Custom(0xb9f0002))
|
||||||
@ -844,7 +843,6 @@ fn test_program_bpf_ro_modify() {
|
|||||||
let instruction = Instruction::new(program_pubkey, &[3_u8], account_metas.clone());
|
let instruction = Instruction::new(program_pubkey, &[3_u8], account_metas.clone());
|
||||||
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey()));
|
||||||
let result = bank_client.send_and_confirm_message(&[&mint_keypair, &test_keypair], message);
|
let result = bank_client.send_and_confirm_message(&[&mint_keypair, &test_keypair], message);
|
||||||
println!("result {:?}", result);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.unwrap_err().unwrap(),
|
result.unwrap_err().unwrap(),
|
||||||
TransactionError::InstructionError(0, InstructionError::Custom(0xb9f0002))
|
TransactionError::InstructionError(0, InstructionError::Custom(0xb9f0002))
|
||||||
@ -911,8 +909,8 @@ fn assert_instruction_count() {
|
|||||||
("multiple_static", 8),
|
("multiple_static", 8),
|
||||||
("noop", 57),
|
("noop", 57),
|
||||||
("relative_call", 10),
|
("relative_call", 10),
|
||||||
("sanity", 1140),
|
("sanity", 176),
|
||||||
("sanity++", 1140),
|
("sanity++", 176),
|
||||||
("struct_pass", 8),
|
("struct_pass", 8),
|
||||||
("struct_ret", 22),
|
("struct_ret", 22),
|
||||||
]);
|
]);
|
||||||
@ -920,16 +918,16 @@ fn assert_instruction_count() {
|
|||||||
#[cfg(feature = "bpf_rust")]
|
#[cfg(feature = "bpf_rust")]
|
||||||
{
|
{
|
||||||
programs.extend_from_slice(&[
|
programs.extend_from_slice(&[
|
||||||
("solana_bpf_rust_128bit", 543),
|
("solana_bpf_rust_128bit", 572),
|
||||||
("solana_bpf_rust_alloc", 19082),
|
("solana_bpf_rust_alloc", 12919),
|
||||||
("solana_bpf_rust_dep_crate", 2),
|
("solana_bpf_rust_dep_crate", 2),
|
||||||
("solana_bpf_rust_external_spend", 538),
|
("solana_bpf_rust_external_spend", 514),
|
||||||
("solana_bpf_rust_iter", 723),
|
("solana_bpf_rust_iter", 724),
|
||||||
("solana_bpf_rust_many_args", 231),
|
("solana_bpf_rust_many_args", 237),
|
||||||
("solana_bpf_rust_noop", 488),
|
("solana_bpf_rust_noop", 488),
|
||||||
("solana_bpf_rust_param_passing", 46),
|
("solana_bpf_rust_param_passing", 48),
|
||||||
("solana_bpf_rust_ristretto", 19399),
|
("solana_bpf_rust_ristretto", 19399),
|
||||||
("solana_bpf_rust_sanity", 1965),
|
("solana_bpf_rust_sanity", 894),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -982,7 +980,6 @@ fn test_program_bpf_instruction_introspection() {
|
|||||||
Some(&mint_keypair.pubkey()),
|
Some(&mint_keypair.pubkey()),
|
||||||
);
|
);
|
||||||
let result = bank_client.send_and_confirm_message(&[&mint_keypair], message);
|
let result = bank_client.send_and_confirm_message(&[&mint_keypair], message);
|
||||||
println!("result: {:?}", result);
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
// writable special instructions11111 key, should not be allowed
|
// writable special instructions11111 key, should not be allowed
|
||||||
|
@ -174,7 +174,7 @@ if [[ ! -e rust-bpf-$machine-$version.md || ! -e rust-bpf-$machine ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Install Rust-BPF Sysroot sources
|
# Install Rust-BPF Sysroot sources
|
||||||
version=v0.12
|
version=v0.13
|
||||||
if [[ ! -e rust-bpf-sysroot-$version.md || ! -e rust-bpf-sysroot ]]; then
|
if [[ ! -e rust-bpf-sysroot-$version.md || ! -e rust-bpf-sysroot ]]; then
|
||||||
(
|
(
|
||||||
set -e
|
set -e
|
||||||
|
@ -38,23 +38,9 @@ pub const HEAP_LENGTH: usize = 32 * 1024;
|
|||||||
/// Deserialize the program input arguments and call the user defined
|
/// Deserialize the program input arguments and call the user defined
|
||||||
/// `process_instruction` function. Users must call this macro otherwise an
|
/// `process_instruction` function. Users must call this macro otherwise an
|
||||||
/// entry point for their program will not be created.
|
/// entry point for their program will not be created.
|
||||||
///
|
|
||||||
/// If the program defines the feature `custom-heap` then the default heap
|
|
||||||
/// implementation will not be included and the program is free to implement
|
|
||||||
/// their own `#[global_allocator]`
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! entrypoint {
|
macro_rules! entrypoint {
|
||||||
($process_instruction:ident) => {
|
($process_instruction:ident) => {
|
||||||
/// A program can provide their own custom heap implementation by adding
|
|
||||||
/// a `custom-heap` feature to `Cargo.toml` and implementing their own
|
|
||||||
/// `global_allocator`.
|
|
||||||
#[cfg(all(not(feature = "custom-heap"), target_arch = "bpf"))]
|
|
||||||
#[global_allocator]
|
|
||||||
static A: $crate::entrypoint::BumpAllocator = $crate::entrypoint::BumpAllocator {
|
|
||||||
start: $crate::entrypoint::HEAP_START_ADDRESS,
|
|
||||||
len: $crate::entrypoint::HEAP_LENGTH,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
|
pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
|
||||||
@ -65,6 +51,50 @@ macro_rules! entrypoint {
|
|||||||
Err(error) => error.into(),
|
Err(error) => error.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$crate::custom_heap_default!();
|
||||||
|
$crate::custom_panic_default!();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fallback to default for unused custom heap feature.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! custom_heap_default {
|
||||||
|
() => {
|
||||||
|
/// A program can provide their own custom heap implementation by adding
|
||||||
|
/// a `custom-heap` feature to `Cargo.toml` and implementing their own
|
||||||
|
/// `global_allocator`.
|
||||||
|
///
|
||||||
|
/// If the program defines the feature `custom-heap` then the default heap
|
||||||
|
/// implementation will not be included and the program is free to implement
|
||||||
|
/// their own `#[global_allocator]`
|
||||||
|
#[cfg(all(not(feature = "custom-heap"), target_arch = "bpf"))]
|
||||||
|
#[global_allocator]
|
||||||
|
static A: $crate::entrypoint::BumpAllocator = $crate::entrypoint::BumpAllocator {
|
||||||
|
start: $crate::entrypoint::HEAP_START_ADDRESS,
|
||||||
|
len: $crate::entrypoint::HEAP_LENGTH,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fallback to default for unused custom panic feature.
|
||||||
|
/// This must be used if the entrypoint! macro is not used.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! custom_panic_default {
|
||||||
|
() => {
|
||||||
|
/// A program can provide their own custom panic implementation by
|
||||||
|
/// adding a `custom-panic` feature to `Cargo.toml` and implementing
|
||||||
|
/// their own `custom_panic`.
|
||||||
|
///
|
||||||
|
/// A good way to reduce the final size of the program is to provide a
|
||||||
|
/// `custom_panic` implementation that does nothing. Doing so will cut
|
||||||
|
/// ~25kb from a noop program. That number goes down the more the
|
||||||
|
/// programs pulls in Rust's libstd for other purposes.
|
||||||
|
#[cfg(all(not(feature = "custom-panic"), target_arch = "bpf"))]
|
||||||
|
#[no_mangle]
|
||||||
|
fn custom_panic(info: &core::panic::PanicInfo<'_>) {
|
||||||
|
// Full panic reporting
|
||||||
|
$crate::msg!("{}", info);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user