Add libstd support to Rust BPF (#5788)
This commit is contained in:
@@ -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