Skip to content
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

Allow heap feature to be disabled. #180

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions ledger_device_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ rand_core = { version = "0.6.3", default_features = false }
zeroize = { version = "1.6.0", default_features = false }
numtoa = "0.2.4"
const-zero = "0.1.1"

[target.'cfg(target_os="nanos")'.dependencies]
ledger_secure_sdk_sys = {path = "../ledger_secure_sdk_sys", version = "1.4.3"}

[target.'cfg(not(target_os="nanos"))'.dependencies]
ledger_secure_sdk_sys = {path = "../ledger_secure_sdk_sys", version = "1.4.3", features = ["heap"]}
ledger_secure_sdk_sys = {path = "../ledger_secure_sdk_sys", version = "1.4.3", default_features = false}
ryankurte marked this conversation as resolved.
Show resolved Hide resolved

[features]
speculos = []
ccid = []
heap = [ "ledger_secure_sdk_sys/heap" ]

default = [ "heap" ]
20 changes: 10 additions & 10 deletions ledger_secure_sdk_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(non_snake_case)]

use core::ffi::c_void;
#[cfg(feature = "heap")]
#[cfg(all(feature = "heap", not(target_os = "nanos")))]
use core::mem::MaybeUninit;

pub mod buttons;
Expand Down Expand Up @@ -35,22 +35,22 @@ pub fn pic_rs_mut<T>(x: &mut T) -> &mut T {
unsafe { &mut *ptr }
}

#[cfg(feature = "heap")]
#[cfg(all(feature = "heap", not(target_os = "nanos")))]
use critical_section::RawRestoreState;
#[cfg(feature = "heap")]
#[cfg(all(feature = "heap", not(target_os = "nanos")))]
use embedded_alloc::Heap;

#[cfg(feature = "heap")]
#[cfg(all(feature = "heap", not(target_os = "nanos")))]
#[global_allocator]
static HEAP: Heap = Heap::empty();

#[cfg(feature = "heap")]
#[cfg(all(feature = "heap", not(target_os = "nanos")))]
struct CriticalSection;
#[cfg(feature = "heap")]
#[cfg(all(feature = "heap", not(target_os = "nanos")))]
critical_section::set_impl!(CriticalSection);

/// Default empty implementation as we don't have concurrency.
#[cfg(feature = "heap")]
#[cfg(all(feature = "heap", not(target_os = "nanos")))]
unsafe impl critical_section::Impl for CriticalSection {
unsafe fn acquire() -> RawRestoreState {}
unsafe fn release(_restore_state: RawRestoreState) {}
Expand All @@ -61,15 +61,15 @@ unsafe impl critical_section::Impl for CriticalSection {
/// The heap is stored in the stack, and has a fixed size.
/// This method is called just before [sample_main].
#[no_mangle]
#[cfg(feature = "heap")]
#[cfg(all(feature = "heap", not(target_os = "nanos")))]
extern "C" fn heap_init() {
const HEAP_SIZE: usize = 8192;
const HEAP_SIZE: usize = 1024;
ryankurte marked this conversation as resolved.
Show resolved Hide resolved
static mut HEAP_MEM: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
}

#[no_mangle]
#[cfg(not(feature = "heap"))]
#[cfg(any(not(feature = "heap"), target_os = "nanos"))]
extern "C" fn heap_init() {}

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));