Add libstd support to Rust BPF (#5788)
This commit is contained in:
@ -13,7 +13,6 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk-bpf-utils = { path = "../../../../sdk/bpf/rust/rust-utils", version = "0.19.0-pre0" }
|
||||
solana-sdk-bpf-no-std = { path = "../../../../sdk/bpf/rust/rust-no-std", version = "0.19.0-pre0" }
|
||||
|
||||
[workspace]
|
||||
members = []
|
||||
|
@ -1,6 +1,2 @@
|
||||
[dependencies.compiler_builtins]
|
||||
path = "../../../../sdk/bpf/dependencies/rust-bpf-sysroot/src/compiler-builtins"
|
||||
features = ["c", "mem"]
|
||||
|
||||
[target.bpfel-unknown-unknown.dependencies]
|
||||
alloc = { path = "../../../../sdk/bpf/dependencies/rust-bpf-sysroot/src/liballoc" }
|
||||
[target.bpfel-unknown-unknown.dependencies.std]
|
||||
features = []
|
@ -1,24 +1,18 @@
|
||||
//! @brief Example Rust-based BPF program that test dynamic memory allocation
|
||||
#![no_std]
|
||||
#![allow(unused_attributes)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
#[cfg(not(test))]
|
||||
extern crate solana_sdk_bpf_no_std;
|
||||
extern crate solana_sdk_bpf_utils;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use core::alloc::Layout;
|
||||
use core::mem;
|
||||
use solana_sdk_bpf_utils::info;
|
||||
use std::alloc::Layout;
|
||||
use std::mem;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> bool {
|
||||
unsafe {
|
||||
// Confirm large allocation fails
|
||||
|
||||
let layout = Layout::from_size_align(core::usize::MAX, mem::align_of::<u8>()).unwrap();
|
||||
let layout = Layout::from_size_align(std::usize::MAX, mem::align_of::<u8>()).unwrap();
|
||||
let ptr = alloc::alloc::alloc(layout);
|
||||
if !ptr.is_null() {
|
||||
info!("Error: Alloc of very larger buffer should fail");
|
||||
@ -59,7 +53,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> bool {
|
||||
alloc::alloc::dealloc(ptr, layout);
|
||||
}
|
||||
|
||||
// // TODO not supported for system or bump allocator
|
||||
// TODO not supported bump allocator
|
||||
// unsafe {
|
||||
// // Test alloc all bytes and one more (assumes heap size of 2048)
|
||||
|
||||
@ -93,7 +87,7 @@ pub extern "C" fn entrypoint(_input: *mut u8) -> bool {
|
||||
}
|
||||
|
||||
{
|
||||
// TODO test Vec::new()
|
||||
// test Vec::new()
|
||||
|
||||
const ITERS: usize = 100;
|
||||
let mut v = Vec::new();
|
||||
|
Reference in New Issue
Block a user