Skip to content

Commit

Permalink
Merge pull request #180 from ryankurte/fix/heap-feature
Browse files Browse the repository at this point in the history
Allow heap feature to be disabled.
  • Loading branch information
yogh333 authored Aug 21, 2024
2 parents c50113d + 9997226 commit e18d34f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

12 changes: 5 additions & 7 deletions ledger_device_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ledger_device_sdk"
version = "1.14.0"
version = "1.14.1"
authors = ["yhql", "yogh333", "agrojean-ledger", "kingofpayne"]
edition = "2021"
license.workspace = true
Expand All @@ -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.4" }

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

default = [ "heap" ]
2 changes: 1 addition & 1 deletion ledger_secure_sdk_sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ledger_secure_sdk_sys"
version = "1.4.3"
version = "1.4.4"
authors = ["yhql", "agrojean-ledger"]
edition = "2021"
license.workspace = true
Expand Down
18 changes: 9 additions & 9 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;
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"));

0 comments on commit e18d34f

Please sign in to comment.