1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +00:00

fix(core): remove shutdown()

In a very weird situation, our declaration of `shutdown()` shadows a
function `shutdown(int, int)` from sys/socket, which _just happens_ to
be called by libxcb when closing the sdl window. This calls
`main_clean_exit` which calls into micropython and causes at best an
uncaught NLR and at worst an outright segfault because by that time the
micropython environment doesn't exist anymore.

I didn't think this sort of thing would be possible but here we are??

Fixed by removing `__shutdown()` and replacing `shutdown` with
`trezor_shutdown`
This commit is contained in:
matejcik 2023-03-24 11:24:34 +01:00 committed by matejcik
parent f0486a2d0b
commit 9244522721
6 changed files with 11 additions and 16 deletions

View File

@ -1,7 +1,7 @@
mod ffi {
extern "C" {
// trezorhal/common.c
pub fn shutdown() -> !;
pub fn trezor_shutdown() -> !;
}
}
@ -13,7 +13,7 @@ use heapless::String;
use crate::ui::util::u32_to_str;
fn shutdown() -> ! {
unsafe { ffi::shutdown() }
unsafe { ffi::trezor_shutdown() }
}
#[cfg(feature = "bootloader")]

View File

@ -43,7 +43,7 @@
// from util.s
extern void shutdown_privileged(void);
void __attribute__((noreturn)) shutdown(void) {
void __attribute__((noreturn)) trezor_shutdown(void) {
#ifdef USE_SVC_SHUTDOWN
svc_shutdown();
#else
@ -88,7 +88,7 @@ __fatal_error(const char *expr, const char *msg, const char *file, int line,
#endif
display_printf("\nPlease contact Trezor support.\n");
#endif
shutdown();
trezor_shutdown();
}
void __attribute__((noreturn))
@ -108,7 +108,7 @@ error_shutdown(const char *label, const char *msg) {
display_printf("\nPlease unplug the device.\n");
#endif
display_backlight(255);
shutdown();
trezor_shutdown();
}
#ifndef NDEBUG

View File

@ -51,7 +51,7 @@
#define STAY_IN_BOOTLOADER_FLAG 0x0FC35A96
void __attribute__((noreturn)) shutdown(void);
void __attribute__((noreturn)) trezor_shutdown(void);
void __attribute__((noreturn))
__fatal_error(const char *expr, const char *msg, const char *file, int line,

View File

@ -34,15 +34,13 @@
extern void main_clean_exit();
extern float DISPLAY_GAMMA;
void __attribute__((noreturn)) __shutdown(void) {
void __attribute__((noreturn)) trezor_shutdown(void) {
printf("SHUTDOWN\n");
main_clean_exit(3);
for (;;)
;
}
void __attribute__((noreturn)) shutdown(void) { __shutdown(); }
#ifdef RGB16
#define COLOR_FATAL_ERROR RGB16(0x7F, 0x00, 0x00)
#else
@ -92,7 +90,7 @@ __fatal_error(const char *expr, const char *msg, const char *file, int line,
printf("Hint:\nIsn't the emulator already running?\n");
#endif
hal_delay(3000);
shutdown();
trezor_shutdown();
}
void __attribute__((noreturn))
@ -135,7 +133,7 @@ uint32_t hal_ticks_ms() {
static int SDLCALL emulator_event_filter(void *userdata, SDL_Event *event) {
switch (event->type) {
case SDL_QUIT:
__shutdown();
trezor_shutdown();
return 0;
case SDL_KEYUP:
if (event->key.repeat) {
@ -143,7 +141,7 @@ static int SDLCALL emulator_event_filter(void *userdata, SDL_Event *event) {
}
switch (event->key.keysym.sym) {
case SDLK_ESCAPE:
__shutdown();
trezor_shutdown();
return 0;
case SDLK_p:
display_save("emu");

View File

@ -40,7 +40,7 @@
})
#endif
void __attribute__((noreturn)) shutdown(void);
void __attribute__((noreturn)) trezor_shutdown(void);
void __attribute__((noreturn))
__fatal_error(const char *expr, const char *msg, const char *file, int line,

View File

@ -21,9 +21,6 @@
#include <stdbool.h>
#include <stdint.h>
extern void __shutdown(void);
extern const char *display_save(const char *prefix);
#if defined TREZOR_MODEL_T
#include "touch.h"