Add libstd support to Rust BPF (#5788)
This commit is contained in:
4
sdk/bpf/rust/rust-no-std/.gitignore
vendored
4
sdk/bpf/rust/rust-no-std/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
/target/
|
||||
|
||||
Cargo.lock
|
||||
/farf/
|
@ -1,16 +0,0 @@
|
||||
|
||||
[package]
|
||||
name = "solana-sdk-bpf-no-std"
|
||||
version = "0.19.0-pre0"
|
||||
description = "Solana BPF SDK Rust no_std support"
|
||||
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 = "../rust-utils" }
|
||||
|
||||
[workspace]
|
||||
members = []
|
@ -1,23 +0,0 @@
|
||||
//! @brief Solana Rust-based BPF program memory allocator shim
|
||||
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use solana_sdk_bpf_utils::log::*;
|
||||
|
||||
pub struct Allocator;
|
||||
unsafe impl GlobalAlloc for Allocator {
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
sol_alloc_free_(layout.size() as u64, 0)
|
||||
}
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||
sol_alloc_free_(layout.size() as u64, ptr as u64);
|
||||
}
|
||||
}
|
||||
extern "C" {
|
||||
fn sol_alloc_free_(size: u64, ptr: u64) -> *mut u8;
|
||||
}
|
||||
|
||||
#[alloc_error_handler]
|
||||
fn my_alloc_error_handler(_: core::alloc::Layout) -> ! {
|
||||
sol_log("alloc_error_handler");
|
||||
panic!();
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//! @brief Solana Rust-based BPF program utility functions and types
|
||||
|
||||
#![no_std]
|
||||
#![feature(allocator_api)]
|
||||
#![feature(alloc_error_handler)]
|
||||
#![feature(panic_info_message)]
|
||||
#![feature(compiler_builtins_lib)]
|
||||
#![feature(lang_items)]
|
||||
#![cfg(not(test))]
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
extern "C" fn eh_personality() {}
|
||||
|
||||
extern crate compiler_builtins;
|
||||
|
||||
pub mod allocator;
|
||||
pub mod panic;
|
||||
|
||||
#[global_allocator]
|
||||
static A: allocator::Allocator = allocator::Allocator;
|
@ -1,32 +0,0 @@
|
||||
//! @brief Solana Rust-based BPF program panic handling
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
use core::ptr;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
// Message is ignored for now to avoid incurring formatting overhead
|
||||
match info.location() {
|
||||
Some(location) => {
|
||||
let mut file: [u8; 128] = [0; 128];
|
||||
for (i, c) in location.file().as_bytes().iter().enumerate() {
|
||||
if i > 127 {
|
||||
break;
|
||||
}
|
||||
file[i] = *c;
|
||||
}
|
||||
unsafe {
|
||||
sol_panic_(
|
||||
file.as_ptr(),
|
||||
file.len() as u64,
|
||||
u64::from(location.line()),
|
||||
u64::from(location.column()),
|
||||
);
|
||||
}
|
||||
}
|
||||
None => unsafe { sol_panic_(ptr::null(), 0, 0, 0) },
|
||||
}
|
||||
}
|
||||
extern "C" {
|
||||
pub fn sol_panic_(file: *const u8, len: u64, line: u64, column: u64) -> !;
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
//! @brief Solana Rust-based BPF program utility functions and types
|
||||
|
||||
#![no_std]
|
||||
|
||||
pub mod entrypoint;
|
||||
pub mod log;
|
||||
|
Reference in New Issue
Block a user