From 38e3088325305395cd5c240e1b98c1d1b9b09b9c Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 7 Dec 2017 15:31:23 +0100 Subject: [PATCH] common: don't expose shutdown() via common.h --- embed/extmod/modtrezorconfig/storage.c | 2 +- embed/extmod/modtrezorui/display-unix.h | 3 +-- embed/prodtest/main.c | 2 +- embed/trezorhal/common.c | 2 ++ embed/trezorhal/common.h | 1 - embed/unix/common.c | 25 +++++++++++++++++++------ embed/unix/common.h | 2 -- embed/unix/touch.c | 6 ++++-- 8 files changed, 28 insertions(+), 15 deletions(-) diff --git a/embed/extmod/modtrezorconfig/storage.c b/embed/extmod/modtrezorconfig/storage.c index 39b954899..e9c7efdfc 100644 --- a/embed/extmod/modtrezorconfig/storage.c +++ b/embed/extmod/modtrezorconfig/storage.c @@ -89,7 +89,7 @@ static void pin_fails_check_max(uint32_t ctr) break; } } - shutdown(); + ensure(secfalse, "pin_fails_check_max"); } } diff --git a/embed/extmod/modtrezorui/display-unix.h b/embed/extmod/modtrezorui/display-unix.h index 144f4ef36..ce5d742f6 100644 --- a/embed/extmod/modtrezorui/display-unix.h +++ b/embed/extmod/modtrezorui/display-unix.h @@ -45,17 +45,16 @@ void display_init(void) printf("%s\n", SDL_GetError()); ensure(secfalse, "SDL_Init error"); } + atexit(SDL_Quit); SDL_Window *win = SDL_CreateWindow("TREZOR", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, DISPLAY_RESX + 2 * DISPLAY_BORDER, DISPLAY_RESY + 2 * DISPLAY_BORDER, SDL_WINDOW_SHOWN); if (!win) { printf("%s\n", SDL_GetError()); - SDL_Quit(); ensure(secfalse, "SDL_CreateWindow error"); } RENDERER = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); if (!RENDERER) { printf("%s\n", SDL_GetError()); SDL_DestroyWindow(win); - SDL_Quit(); ensure(secfalse, "SDL_CreateRenderer error"); } SDL_SetRenderDrawColor(RENDERER, DISPLAY_BACKLIGHT, DISPLAY_BACKLIGHT, DISPLAY_BACKLIGHT, 255); diff --git a/embed/prodtest/main.c b/embed/prodtest/main.c index 97f17ce58..1464ac0d5 100644 --- a/embed/prodtest/main.c +++ b/embed/prodtest/main.c @@ -27,7 +27,7 @@ enum { VCP_IFACE = 0x00 }; static void vcp_intr(void) { display_clear(); - shutdown(); + ensure(secfalse, "vcp_intr"); } static void vcp_puts(const char *s, size_t len) diff --git a/embed/trezorhal/common.c b/embed/trezorhal/common.c index ae9e716dc..fbaa09655 100644 --- a/embed/trezorhal/common.c +++ b/embed/trezorhal/common.c @@ -4,6 +4,8 @@ #include "display.h" #include "rng.h" +void shutdown(void); + void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func) { display_orientation(0); display_backlight(255); diff --git a/embed/trezorhal/common.h b/embed/trezorhal/common.h index 7973eb7b1..be21d6db1 100644 --- a/embed/trezorhal/common.h +++ b/embed/trezorhal/common.h @@ -18,6 +18,5 @@ extern uint32_t __stack_chk_guard; void memset_reg(volatile void *start, volatile void *stop, uint32_t val); void jump_to(uint32_t address); -void shutdown(void); #endif diff --git a/embed/unix/common.c b/embed/unix/common.c index 1d848b2da..6d6993f84 100644 --- a/embed/unix/common.c +++ b/embed/unix/common.c @@ -3,36 +3,49 @@ #include #include "common.h" +#include "display.h" + +void __shutdown(void) +{ + printf("SHUTDOWN\n"); + exit(3); +} void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, const char *file, int line, const char *func) { + display_orientation(0); + display_backlight(255); + display_print_color(COLOR_WHITE, COLOR_RED128); + display_printf("\nFATAL ERROR:\n"); printf("\nFATAL ERROR:\n"); if (expr) { + display_printf("expr: %s\n", expr); printf("expr: %s\n", expr); } if (msg) { + display_printf("msg : %s\n", msg); printf("msg : %s\n", msg); } if (file) { + display_printf("file: %s:%d\n", file, line); printf("file: %s:%d\n", file, line); } if (func) { + display_printf("func: %s\n", func); printf("func: %s\n", func); } #ifdef GITREV #define XSTR(s) STR(s) #define STR(s) #s + display_printf("rev : %s\n", XSTR(GITREV)); printf("rev : %s\n", XSTR(GITREV)); #endif - exit(1); + hal_delay(3000); + __shutdown(); + for (;;); } void hal_delay(uint32_t ms) { usleep(1000 * ms); } - -void shutdown(void) -{ - exit(1); -} diff --git a/embed/unix/common.h b/embed/unix/common.h index d1daf8a1d..fde45ec82 100644 --- a/embed/unix/common.h +++ b/embed/unix/common.h @@ -9,6 +9,4 @@ void __attribute__((noreturn)) __fatal_error(const char *expr, const char *msg, void hal_delay(uint32_t ms); -void shutdown(void); - #endif diff --git a/embed/unix/touch.c b/embed/unix/touch.c index e5150f3be..9fb8f22da 100644 --- a/embed/unix/touch.c +++ b/embed/unix/touch.c @@ -13,6 +13,8 @@ #include "options.h" #include "embed/trezorhal/touch.h" +void __shutdown(void); + uint32_t touch_read(void) { #ifndef TREZOR_NOUI @@ -43,11 +45,11 @@ uint32_t touch_read(void) break; case SDL_KEYUP: if (event.key.keysym.sym == SDLK_ESCAPE) { - exit(3); + __shutdown(); } break; case SDL_QUIT: - exit(3); + __shutdown(); break; } }