rust-c: rename alloc module to c_alloc
What changed, and why it matters
This commit simply renames an internal Rust module from `alloc` to `c_alloc` to avoid a naming conflict with Rust's standard `alloc` crate in a future change. The actual allocator code is identical; only file paths and a module reference are updated. There is no security-relevant change.
No security action required; treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch is a pure refactor: src/rust/bitbox02-rust-c/src/alloc.rs is moved/renamed to c_alloc.rs with identical contents, lib.rs updates mod alloc; to mod c_alloc;, and bitbox02-cbindgen.toml updates a comment path. No functional, cryptographic, memory-safety, or API changes are introduced.
Changed components
src/rust/bitbox02-rust-c/src/alloc.rs (renamed to c_alloc.rs)src/rust/bitbox02-rust-c/src/lib.rssrc/rust/bitbox02-cbindgen.tomlInspect captured patch +38 / −38
diff --git a/src/rust/bitbox02-cbindgen.toml b/src/rust/bitbox02-cbindgen.toml
index 13e91ef..ab5e33a 100644
--- a/src/rust/bitbox02-cbindgen.toml
+++ b/src/rust/bitbox02-cbindgen.toml
@@ -28,7 +28,7 @@ include = ["bitbox02-rust", "util", "bitbox-aes", "bitbox-framed-serial-link"]
extra_bindings = ["bitbox02-rust", "util", "bitbox-aes", "bitbox-framed-serial-link"]
[export]
-# malloc, free declared in bitbox02-rust-c/src/alloc.rs, but does not need to be exported, as it
+# malloc, free declared in bitbox02-rust-c/src/c_alloc.rs, but does not need to be exported, as it
# already exists in stdlib.h.
exclude = [
"malloc",
diff --git a/src/rust/bitbox02-rust-c/src/alloc.rs b/src/rust/bitbox02-rust-c/src/alloc.rs
deleted file mode 100644
index 30c9834..0000000
--- a/src/rust/bitbox02-rust-c/src/alloc.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-// SPDX-License-Identifier: Apache-2.0
-
-struct BB02Allocator;
-
-unsafe extern "C" {
- pub fn malloc(size: usize) -> *mut core::ffi::c_void;
- pub fn free(p: *mut core::ffi::c_void);
-}
-
-unsafe impl core::alloc::GlobalAlloc for BB02Allocator {
- unsafe fn alloc(&self, layout: core::alloc::Layout) -> *mut u8 {
- unsafe { malloc(layout.size()) as _ }
- }
- unsafe fn dealloc(&self, ptr: *mut u8, _layout: core::alloc::Layout) {
- unsafe { free(ptr as _) }
- }
-}
-
-#[global_allocator]
-static BB02_ALLOCATOR: BB02Allocator = BB02Allocator;
-
-#[cfg(test)]
-mod tests {
- extern crate std;
- use std::prelude::v1::*;
-
- #[test]
- fn test_alloc_dealloc() {
- unsafe {
- let layout = core::alloc::Layout::new::<u32>();
- let ptr = std::alloc::alloc(layout);
- assert!(!ptr.is_null());
- std::alloc::dealloc(ptr, layout);
- }
- }
-}
diff --git a/src/rust/bitbox02-rust-c/src/c_alloc.rs b/src/rust/bitbox02-rust-c/src/c_alloc.rs
new file mode 100644
index 0000000..30c9834
--- /dev/null
+++ b/src/rust/bitbox02-rust-c/src/c_alloc.rs
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: Apache-2.0
+
+struct BB02Allocator;
+
+unsafe extern "C" {
+ pub fn malloc(size: usize) -> *mut core::ffi::c_void;
+ pub fn free(p: *mut core::ffi::c_void);
+}
+
+unsafe impl core::alloc::GlobalAlloc for BB02Allocator {
+ unsafe fn alloc(&self, layout: core::alloc::Layout) -> *mut u8 {
+ unsafe { malloc(layout.size()) as _ }
+ }
+ unsafe fn dealloc(&self, ptr: *mut u8, _layout: core::alloc::Layout) {
+ unsafe { free(ptr as _) }
+ }
+}
+
+#[global_allocator]
+static BB02_ALLOCATOR: BB02Allocator = BB02Allocator;
+
+#[cfg(test)]
+mod tests {
+ extern crate std;
+ use std::prelude::v1::*;
+
+ #[test]
+ fn test_alloc_dealloc() {
+ unsafe {
+ let layout = core::alloc::Layout::new::<u32>();
+ let ptr = std::alloc::alloc(layout);
+ assert!(!ptr.is_null());
+ std::alloc::dealloc(ptr, layout);
+ }
+ }
+}
diff --git a/src/rust/bitbox02-rust-c/src/lib.rs b/src/rust/bitbox02-rust-c/src/lib.rs
index 0824dde..7968dd8 100644
--- a/src/rust/bitbox02-rust-c/src/lib.rs
+++ b/src/rust/bitbox02-rust-c/src/lib.rs
@@ -7,7 +7,7 @@
extern crate std;
#[macro_use]
-mod alloc;
+mod c_alloc;
#[cfg(feature = "firmware")]
pub mod async_usb;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.