1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

fix(core/rust): disable stack checking in tests (fixes spurious "recursion exceeded" errors)

This commit is contained in:
matejcik 2023-06-20 11:09:18 +02:00 committed by matejcik
parent c3f6e8f19f
commit ccddc8f5f3

View File

@ -1,6 +1,6 @@
extern "C" {
fn gc_init(start: *mut cty::c_void, end: *mut cty::c_void);
fn mp_stack_ctrl_init();
fn mp_stack_set_top(top: *mut cty::c_void);
fn mp_stack_set_limit(limit: usize);
fn mp_init();
}
@ -11,8 +11,8 @@ static mut MPY_INITIALIZED: bool = false;
/// Initialize the MicroPython environment.
///
/// This is very hacky, in no way safe, and should not be used in production.
/// The stack is configured on a best-effort basis and depending on from where
/// this is called, you might get errorneous "recursion exceeded" problems.
/// The stack is configured to span all of memory, effectively disabling the
/// stack guard. I have no idea what can happen.
///
/// This should only be called at start of your test function.
#[cfg(test)]
@ -21,8 +21,8 @@ pub unsafe fn mpy_init() {
if MPY_INITIALIZED {
return;
}
mp_stack_ctrl_init();
mp_stack_set_limit(6000000);
mp_stack_set_top(usize::MAX as *mut cty::c_void);
mp_stack_set_limit(usize::MAX);
gc_init(
HEAP.as_mut_ptr().cast(),
HEAP.as_mut_ptr().add(HEAP.len()).cast(),