Skip to content

program-entrypoint: Add no_std attribute #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions program-entrypoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
//! For more information see the [`bpf_loader`] module.
//!
//! [`bpf_loader`]: crate::bpf_loader
#![no_std]

extern crate alloc;
use {
alloc::vec::Vec,
solana_account_info::AccountInfo,
solana_pubkey::Pubkey,
std::{
alloc::{rc::Rc, vec::Vec},
core::{
alloc::Layout,
cell::RefCell,
mem::{size_of, MaybeUninit},
ptr::null_mut,
rc::Rc,
slice::{from_raw_parts, from_raw_parts_mut},
},
solana_account_info::AccountInfo,
solana_pubkey::Pubkey,
};
// need to re-export msg for custom_heap_default macro
pub use {
Expand Down Expand Up @@ -159,7 +159,7 @@ macro_rules! entrypoint_no_alloc {
/// # Safety
#[no_mangle]
pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
use std::mem::MaybeUninit;
use core::mem::MaybeUninit;
// Clippy complains about this because a `const` with interior
// mutability `RefCell` should use `static` instead to make it
// clear that it can change.
Expand Down Expand Up @@ -331,7 +331,7 @@ impl BumpAllocator {
/// operating on the prescribed `HEAP_START_ADDRESS` and `HEAP_LENGTH`. Any
/// other use may overflow and is thus unsupported and at one's own risk.
#[allow(clippy::arithmetic_side_effects)]
unsafe impl std::alloc::GlobalAlloc for BumpAllocator {
unsafe impl core::alloc::GlobalAlloc for BumpAllocator {
#[inline]
#[allow(deprecated)] //we get to use deprecated pub fields
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
Expand All @@ -355,7 +355,7 @@ unsafe impl std::alloc::GlobalAlloc for BumpAllocator {
}
}

/// `assert_eq(std::mem::align_of::<u128>(), 8)` is true for BPF but not for some host machines
/// `assert_eq(core::mem::align_of::<u128>(), 8)` is true for BPF but not for some host machines
pub const BPF_ALIGN_OF_U128: usize = 8;

#[allow(clippy::arithmetic_side_effects)]
Expand Down Expand Up @@ -550,7 +550,7 @@ pub unsafe fn deserialize_into<'a>(

#[cfg(test)]
mod test {
use {super::*, std::alloc::GlobalAlloc};
use {super::*, core::alloc::GlobalAlloc};

#[test]
fn test_bump_allocator() {
Expand Down