Skip to content
Merged
Show file tree
Hide file tree
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 sdk/src/entrypoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
Address, BPF_ALIGN_OF_U128, MAX_TX_ACCOUNTS,
};

#[cfg(all(target_os = "solana", feature = "alloc"))]
#[cfg(all(any(target_os = "solana", target_arch = "bpf"), feature = "alloc"))]
pub use alloc::BumpAllocator;

/// Start address of the memory region used for program heap.
Expand Down Expand Up @@ -440,7 +440,7 @@ pub unsafe fn deserialize<const MAX_ACCOUNTS: usize>(
macro_rules! default_panic_handler {
() => {
/// Default panic handler.
#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
#[no_mangle]
fn custom_panic(info: &core::panic::PanicInfo<'_>) {
if let Some(location) = info.location() {
Expand All @@ -464,7 +464,7 @@ macro_rules! default_panic_handler {
macro_rules! nostd_panic_handler {
() => {
/// A panic handler for `no_std`.
#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
#[panic_handler]
fn handler(info: &core::panic::PanicInfo<'_>) -> ! {
if let Some(location) = info.location() {
Expand All @@ -490,7 +490,7 @@ macro_rules! nostd_panic_handler {
/// `"solana"`.
///
/// This links the `std` library, which will set up a default panic handler.
#[cfg(not(target_os = "solana"))]
#[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
mod __private_panic_handler {
extern crate std as __std;
}
Expand All @@ -504,7 +504,7 @@ macro_rules! nostd_panic_handler {
#[macro_export]
macro_rules! default_allocator {
() => {
#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
#[global_allocator]
static A: $crate::entrypoint::BumpAllocator = $crate::entrypoint::BumpAllocator {
start: $crate::entrypoint::HEAP_START_ADDRESS as usize,
Expand All @@ -515,7 +515,7 @@ macro_rules! default_allocator {
/// `"solana"`.
///
/// This links the `std` library, which will set up a default global allocator.
#[cfg(not(target_os = "solana"))]
#[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
mod __private_alloc {
extern crate std as __std;
}
Expand All @@ -534,7 +534,7 @@ macro_rules! default_allocator {
#[macro_export]
macro_rules! no_allocator {
() => {
#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
#[global_allocator]
static A: $crate::entrypoint::NoAllocator = $crate::entrypoint::NoAllocator;

Expand Down Expand Up @@ -582,7 +582,7 @@ macro_rules! no_allocator {
/// `"solana"`.
///
/// This links the `std` library, which will set up a default global allocator.
#[cfg(not(target_os = "solana"))]
#[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
mod __private_alloc {
extern crate std as __std;
}
Expand All @@ -606,7 +606,7 @@ unsafe impl GlobalAlloc for NoAllocator {
}
}

#[cfg(all(target_os = "solana", feature = "alloc"))]
#[cfg(all(any(target_os = "solana", target_arch = "bpf"), feature = "alloc"))]
mod alloc {
use core::{
alloc::{GlobalAlloc, Layout},
Expand Down
16 changes: 8 additions & 8 deletions sdk/src/sysvars/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Provides access to cluster system accounts.

#[cfg(not(target_os = "solana"))]
#[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
use core::hint::black_box;

#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
use crate::syscalls::sol_get_sysvar;
use crate::{error::ProgramError, Address};

Expand All @@ -17,13 +17,13 @@ pub mod slot_hashes;
/// the sysvar data.
//
// Defined in the bpf loader as [`OFFSET_LENGTH_EXCEEDS_SYSVAR`](https://github.com/anza-xyz/agave/blob/master/programs/bpf_loader/src/syscalls/sysvar.rs#L172).
#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
const OFFSET_LENGTH_EXCEEDS_SYSVAR: u64 = 1;

/// Return value indicating that the sysvar was not found.
//
// Defined in the bpf loader as [`SYSVAR_NOT_FOUND`](https://github.com/anza-xyz/agave/blob/master/programs/bpf_loader/src/syscalls/sysvar.rs#L171).
#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
const SYSVAR_NOT_FOUND: u64 = 2;

/// A type that holds sysvar data.
Expand All @@ -49,10 +49,10 @@ macro_rules! impl_sysvar_get {
let mut var = core::mem::MaybeUninit::<Self>::uninit();
let var_addr = var.as_mut_ptr() as *mut _ as *mut u8;

#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
let result = unsafe { $crate::syscalls::$syscall_name(var_addr) };

#[cfg(not(target_os = "solana"))]
#[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
let result = core::hint::black_box(var_addr as *const _ as u64);

match result {
Expand Down Expand Up @@ -81,7 +81,7 @@ pub unsafe fn get_sysvar_unchecked(
offset: usize,
len: usize,
) -> Result<(), ProgramError> {
#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
{
let result = unsafe {
sol_get_sysvar(
Expand All @@ -101,7 +101,7 @@ pub unsafe fn get_sysvar_unchecked(
}
}

#[cfg(not(target_os = "solana"))]
#[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
{
black_box((dst, sysvar_id, offset, len));
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/sysvars/slot_hashes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ pub struct SlotHashes<T: Deref<Target = [u8]>> {

/// Log a `Hash` from a program.
pub fn log(hash: &Hash) {
#[cfg(target_os = "solana")]
#[cfg(any(target_os = "solana", target_arch = "bpf"))]
// SAFETY: `sol_log_pubkey` expects a valid pointer to a 32-byte array.
unsafe {
solana_address::syscalls::sol_log_pubkey(hash.as_ptr());
}

#[cfg(not(target_os = "solana"))]
#[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
core::hint::black_box(hash);
}

Expand Down Expand Up @@ -311,7 +311,7 @@ impl SlotHashes<Box<[u8]>> {
crate::sysvars::get_sysvar_unchecked(buffer_ptr, &SLOTHASHES_ID, 0, MAX_SIZE)?;

// For tests on builds that don't actually fill the buffer.
#[cfg(not(target_os = "solana"))]
#[cfg(not(any(target_os = "solana", target_arch = "bpf")))]
core::ptr::write_bytes(buffer_ptr, 0, NUM_ENTRIES_SIZE);

Ok(())
Expand Down