mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-19 02:52:11 +00:00
refactor(core): separate clear_unused_stack()
from sys/linker
module
Following https://github.com/trezor/trezor-firmware/pull/4595#pullrequestreview-2609833271. [no changelog]
This commit is contained in:
parent
d38b52c0c4
commit
ae9e0281df
@ -31,15 +31,6 @@ extern uint8_t _stack_section_end;
|
||||
// to reinitialize these sections if necessary.
|
||||
void init_linker_sections(void);
|
||||
|
||||
// Clears the unused portion of the stack.
|
||||
//
|
||||
// This includes memory between the start of the stack
|
||||
// and the current stack pointer (SP).
|
||||
//
|
||||
// It's safe to call this function at any time, but it's
|
||||
// recommended to call it only during the startup sequence.
|
||||
void clear_unused_stack(void);
|
||||
|
||||
// Maximum number of memory blocks in a memory region
|
||||
#define MEMREGION_MAX_BLOCKS 8
|
||||
|
||||
|
@ -54,21 +54,6 @@ void init_linker_sections(void) {
|
||||
}
|
||||
}
|
||||
|
||||
__attribute((naked, no_stack_protector)) void clear_unused_stack(void) {
|
||||
__asm__ volatile(
|
||||
" MOV R0, #0 \n"
|
||||
" LDR R1, =%[sstack] \n"
|
||||
"1: \n"
|
||||
" STR R0, [R1], #4 \n"
|
||||
" CMP R1, SP \n"
|
||||
" BNE 1b \n"
|
||||
" BX LR \n"
|
||||
: // no output
|
||||
: [sstack] "i"((uint32_t)&_stack_section_start)
|
||||
: // no clobber
|
||||
);
|
||||
}
|
||||
|
||||
static void memregion_remove_block(memregion_t* region, int idx) {
|
||||
if (idx < 0 || idx >= MEMREGION_MAX_BLOCKS) {
|
||||
return;
|
||||
|
29
core/embed/sys/stack/inc/sys/stack_utils.h
Normal file
29
core/embed/sys/stack/inc/sys/stack_utils.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Clears the unused portion of the stack.
|
||||
//
|
||||
// This includes memory between the start of the stack
|
||||
// and the current stack pointer (SP).
|
||||
//
|
||||
// It's safe to call this function at any time, but it's
|
||||
// recommended to call it only during the startup sequence.
|
||||
void clear_unused_stack(void);
|
37
core/embed/sys/stack/stm32/stack_utils.c
Normal file
37
core/embed/sys/stack/stm32/stack_utils.c
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of the Trezor project, https://trezor.io/
|
||||
*
|
||||
* Copyright (c) SatoshiLabs
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <trezor_types.h>
|
||||
|
||||
#include <sys/linker_utils.h>
|
||||
|
||||
__attribute((naked, no_stack_protector)) void clear_unused_stack(void) {
|
||||
__asm__ volatile(
|
||||
" MOV R0, #0 \n"
|
||||
" LDR R1, =%[sstack] \n"
|
||||
"1: \n"
|
||||
" STR R0, [R1], #4 \n"
|
||||
" CMP R1, SP \n"
|
||||
" BNE 1b \n"
|
||||
" BX LR \n"
|
||||
: // no output
|
||||
: [sstack] "i"((uint32_t)&_stack_section_start)
|
||||
: // no clobber
|
||||
);
|
||||
}
|
@ -27,6 +27,7 @@
|
||||
#include <sys/irq.h>
|
||||
#include <sys/linker_utils.h>
|
||||
#include <sys/mpu.h>
|
||||
#include <sys/stack_utils.h>
|
||||
#include <sys/systick.h>
|
||||
#include <sys/sysutils.h>
|
||||
#include <util/image.h>
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <sys/bootargs.h>
|
||||
#include <sys/bootutils.h>
|
||||
#include <sys/linker_utils.h>
|
||||
#include <sys/stack_utils.h>
|
||||
#include <sys/system.h>
|
||||
#include <sys/systick.h>
|
||||
#include <sys/sysutils.h>
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <sec/rng.h>
|
||||
#include <sys/bootargs.h>
|
||||
#include <sys/linker_utils.h>
|
||||
#include <sys/stack_utils.h>
|
||||
#include <sys/system.h>
|
||||
|
||||
#ifdef KERNEL_MODE
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <sys/bootutils.h>
|
||||
#include <sys/linker_utils.h>
|
||||
#include <sys/mpu.h>
|
||||
#include <sys/stack_utils.h>
|
||||
#include <sys/systask.h>
|
||||
#include <sys/system.h>
|
||||
#include <sys/systick.h>
|
||||
|
@ -22,6 +22,7 @@ def stm32f4_common_files(env, defines, sources, paths):
|
||||
"embed/sys/mpu/inc",
|
||||
"embed/sys/pvd/inc",
|
||||
"embed/sec/secret/inc",
|
||||
"embed/sys/stack/inc",
|
||||
"embed/sys/startup/inc",
|
||||
"embed/sys/syscall/inc",
|
||||
"embed/sys/task/inc",
|
||||
@ -70,6 +71,7 @@ def stm32f4_common_files(env, defines, sources, paths):
|
||||
"embed/sys/linker/linker_utils.c",
|
||||
"embed/sys/mpu/stm32f4/mpu.c",
|
||||
"embed/sys/pvd/stm32/pvd.c",
|
||||
"embed/sys/stack/stm32/stack_utils.c",
|
||||
"embed/sys/startup/stm32/bootutils.c",
|
||||
"embed/sys/startup/stm32/sysutils.c",
|
||||
"embed/sys/startup/stm32f4/reset_flags.c",
|
||||
|
@ -23,6 +23,7 @@ def stm32u5_common_files(env, defines, sources, paths):
|
||||
"embed/sys/linker/inc",
|
||||
"embed/sys/mpu/inc",
|
||||
"embed/sys/pvd/inc",
|
||||
"embed/sys/stack/inc",
|
||||
"embed/sys/startup/inc",
|
||||
"embed/sys/syscall/inc",
|
||||
"embed/sys/tamper/inc",
|
||||
@ -88,6 +89,7 @@ def stm32u5_common_files(env, defines, sources, paths):
|
||||
"embed/sys/linker/linker_utils.c",
|
||||
"embed/sys/mpu/stm32u5/mpu.c",
|
||||
"embed/sys/pvd/stm32/pvd.c",
|
||||
"embed/sys/stack/stm32/stack_utils.c",
|
||||
"embed/sys/startup/stm32/bootutils.c",
|
||||
"embed/sys/startup/stm32/sysutils.c",
|
||||
"embed/sys/startup/stm32u5/reset_flags.c",
|
||||
|
Loading…
Reference in New Issue
Block a user