Skip to content

Commit

Permalink
Fix memory ownership issue in the init function
Browse files Browse the repository at this point in the history
  • Loading branch information
diondokter committed Jun 17, 2024
1 parent b639e81 commit aa1d153
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nrfxlib"
version = "0.6.0"
version = "0.6.1"
authors = ["Jonathan Pallant (42 Technology) <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand All @@ -18,3 +18,4 @@ linked_list_allocator = { version = "0.10", default-features = false, features =
] }
log = "0.4"
nrfxlib-sys = "=1.5.1"
grounded = "0.2.0"
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@ See [nrf9160-demo](https://github.com/42-technology-ltd/nrf9160-demo) for a demo

## Changelog

### Unreleased Changes ([Source](https://github.com/42-technology-ltd/nrfxlib/tree/develop) | [Changes](https://github.com/42-technology-ltd/nrfxlib/compare/v0.6.0...develop))
### Unreleased Changes ([Source](https://github.com/42-technology-ltd/nrfxlib/tree/develop) | [Changes](https://github.com/42-technology-ltd/nrfxlib/compare/v0.6.1...develop))

* None

### v0.6.1 ([Source](https://github.com/42-technology-ltd/nrfxlib/tree/v0.6.1) | [Changes](https://github.com/42-technology-ltd/nrfxlib/compare/v0.6.0...v0.6.1))

* Fixed a memory ownership issue in `nrf_modem_init`. The `nrf_modem_init_params` pointer given to the init must
have a static lifetime. This has been a stack variable since forever.
Originally this seems to have not been required, but this changed +-4 years ago
without documentation update from Nordic.

### v0.6.0 ([Source](https://github.com/42-technology-ltd/nrfxlib/tree/v0.6.0) | [Changes](https://github.com/42-technology-ltd/nrfxlib/compare/v0.5.0...v0.6.0))

* Updated to nrfxlib-sys v1.5.1.
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ pub fn init() -> Result<(), Error> {
}

// Tell nrf_modem what memory it can use.
static PARAMS: grounded::uninit::GroundedCell<nrfxlib_sys::nrf_modem_init_params> =

Check failure on line 172 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (thumbv8m.main-none-eabihf)

cannot find type `nrf_modem_init_params` in crate `nrfxlib_sys`
grounded::uninit::GroundedCell::uninit();

let params = sys::nrf_modem_init_params_t {
shmem: sys::nrf_modem_shmem_cfg {
ctrl: sys::nrf_modem_shmem_cfg__bindgen_ty_1 {
Expand All @@ -195,6 +198,8 @@ pub fn init() -> Result<(), Error> {
ipc_irq_prio: 0,
};

cortex_m::interrupt::free(|_| unsafe { PARAMS.get().write(params) });

unsafe {
// Use the same TX memory region as above
cortex_m::interrupt::free(|cs| {
Expand All @@ -206,7 +211,7 @@ pub fn init() -> Result<(), Error> {
}

// OK, let's start the library
let result = unsafe { sys::nrf_modem_init(&params, sys::nrf_modem_mode_t_NORMAL_MODE) };
let result = unsafe { sys::nrf_modem_init(PARAMS.get(), sys::nrf_modem_mode_t_NORMAL_MODE) };

// Was it happy?
if result < 0 {
Expand Down

0 comments on commit aa1d153

Please sign in to comment.