feat(core): add trampoline functions with proper signatures
What changed, and why it matters
This commit adds small adapter functions (called trampolines) so that two existing functions are called with the correct number and type of arguments when passed to a task scheduler. It is a code-correctness improvement for the Unix emulator build of the Trezor firmware and does not introduce obvious security flaws.
No immediate security action required. Treat as a normal code-quality/correctness commit. Reviewers may want to confirm that `systask_push_call` expects exactly the three-argument trampoline signature on all supported Unix targets.
Security signals we found
Function signature mismatch between callback interface and target functions is corrected by trampolines
Casts between `uintptr_t` and `int`/`char**` are explicit and bounded by the trampoline signature
No input validation, memory allocation, or cryptographic logic is changed
Changes are confined to the Unix emulator build (`core/embed/projects/unix`, `core/embed/sys/task/unix`)
Evidence from the diff
The patch introduces throw_exit_exception_trampoline and coreapp_emu_trampoline in the Unix-specific Trezor core code. Both trampolines match the systask_push_call callback signature (uintptr_t, uintptr_t, uintptr_t) -> uintptr_t and internally cast arguments back to the original types before calling coreapp_throw_exit_exception(int) and coreapp_emu(int, char**). This avoids passing functions with mismatched signatures directly to systask_push_call, which is a defensive/correctness change.
Changed components
core/embed/projects/unix/main_main.ccore/embed/sys/task/unix/coreapp.cInspect captured patch +20 / −4
diff --git a/core/embed/projects/unix/main_main.c b/core/embed/projects/unix/main_main.c
index 57799aa5..304c8c69 100644
--- a/core/embed/projects/unix/main_main.c
+++ b/core/embed/projects/unix/main_main.c
@@ -97,11 +97,21 @@ static void drivers_init(void) {
#endif
}
+static uintptr_t throw_exit_exception_trampoline(uintptr_t code,
+ uintptr_t unused1,
+ uintptr_t unused2) {
+ extern void coreapp_throw_exit_exception(int code);
+ UNUSED(unused1);
+ UNUSED(unused2);
+ coreapp_throw_exit_exception((int)code);
+ return 0;
+}
+
// Throws MicroPython SystemExit exception in the context of the given task
static void throw_exit_exception(systask_t *task, int code) {
- extern void coreapp_throw_exit_exception(int code);
// Push call to the task
- systask_push_call(task, (void *)coreapp_throw_exit_exception, code, 0, 0);
+ systask_push_call(task, (void *)throw_exit_exception_trampoline,
+ (uintptr_t)code, 0, 0);
// Yield to the task and throw the exception
systask_yield_to(task);
// We are back and the task should be terminated by now
diff --git a/core/embed/sys/task/unix/coreapp.c b/core/embed/sys/task/unix/coreapp.c
index 60477abe..9286f7f0 100644
--- a/core/embed/sys/task/unix/coreapp.c
+++ b/core/embed/sys/task/unix/coreapp.c
@@ -27,6 +27,12 @@
extern int coreapp_emu(int argc, char** argv);
+static uintptr_t coreapp_emu_trampoline(uintptr_t argc, uintptr_t argv,
+ uintptr_t unused) {
+ UNUSED(unused);
+ return (uintptr_t)coreapp_emu((int)argc, (char**)argv);
+}
+
// API getter function implemented in the coreapp
extern const void* coreapp_api_get(uint32_t version);
@@ -39,8 +45,8 @@ bool coreapp_init(applet_t* applet, int argc, char** argv) {
return false;
}
- if (!systask_push_call(&applet->task, (void*)coreapp_emu, (uintptr_t)argc,
- (uintptr_t)argv, 0)) {
+ if (!systask_push_call(&applet->task, (void*)coreapp_emu_trampoline,
+ (uintptr_t)argc, (uintptr_t)argv, 0)) {
return false;
}
Why this scored 28/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.