mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Stack thunk yield() fixes (#9224)
* Update bearssl builder * Keep bssl stack pointer from confusing yield implement stack_thunk_yield() which is called within bssl stack overflow checks for cont would always fail otherwise
This commit is contained in:
parent
be3035c853
commit
1a13ab95fb
@ -27,18 +27,26 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "pgmspace.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "StackThunk.h"
|
#include "StackThunk.h"
|
||||||
|
|
||||||
|
#include <pgmspace.h>
|
||||||
#include <ets_sys.h>
|
#include <ets_sys.h>
|
||||||
|
|
||||||
#include <umm_malloc/umm_malloc.h>
|
#include <umm_malloc/umm_malloc.h>
|
||||||
#include <umm_malloc/umm_heap_select.h>
|
#include <umm_malloc/umm_heap_select.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
extern void optimistic_yield(uint32_t);
|
||||||
|
|
||||||
uint32_t *stack_thunk_ptr = NULL;
|
uint32_t *stack_thunk_ptr = NULL;
|
||||||
uint32_t *stack_thunk_top = NULL;
|
uint32_t *stack_thunk_top = NULL;
|
||||||
|
|
||||||
uint32_t *stack_thunk_save = NULL; /* Saved A1 while in BearSSL */
|
uint32_t *stack_thunk_save = NULL; /* Saved A1 while in BearSSL */
|
||||||
|
uint32_t *stack_thunk_yield_save = NULL; /* Saved A1 when yielding from within BearSSL */
|
||||||
|
|
||||||
uint32_t stack_thunk_refcnt = 0;
|
uint32_t stack_thunk_refcnt = 0;
|
||||||
|
|
||||||
/* Largest stack usage seen in the wild at 6120 */
|
/* Largest stack usage seen in the wild at 6120 */
|
||||||
@ -150,4 +158,37 @@ void stack_thunk_fatal_smashing()
|
|||||||
__stack_chk_fail();
|
__stack_chk_fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Called within bearssl code instead of optimistic_yield(...) */
|
||||||
|
void stack_thunk_yield();
|
||||||
|
asm(
|
||||||
|
".section .text.stack_thunk_yield,\"ax\",@progbits\n\t"
|
||||||
|
".literal_position\n\t"
|
||||||
|
".align 4\n\t"
|
||||||
|
".global stack_thunk_yield\n\t"
|
||||||
|
".type stack_thunk_yield, @function\n\t"
|
||||||
|
"\n"
|
||||||
|
"stack_thunk_yield:\n\t"
|
||||||
|
/* Keep the original caller */
|
||||||
|
"addi a1, a1, -16\n\t"
|
||||||
|
"s32i.n a0, a1, 12\n\t"
|
||||||
|
/* Swap bearssl <-> cont stacks */
|
||||||
|
"movi a2, stack_thunk_yield_save\n\t"
|
||||||
|
"s32i.n a1, a2, 0\n\t"
|
||||||
|
"movi a2, stack_thunk_save\n\t"
|
||||||
|
"l32i.n a1, a2, 0\n\t"
|
||||||
|
/* optimistic_yield(10000) without extra l32r */
|
||||||
|
"movi a2, 0x10\n\t"
|
||||||
|
"addmi a2, a2, 0x2700\n\t"
|
||||||
|
"call0 optimistic_yield\n\t"
|
||||||
|
/* Swap bearssl <-> cont stacks, again */
|
||||||
|
"movi a2, stack_thunk_yield_save\n\t"
|
||||||
|
"l32i.n a1, a2, 0\n\t"
|
||||||
|
"\n"
|
||||||
|
/* Restore caller */
|
||||||
|
"l32i.n a0, a1, 12\n\t"
|
||||||
|
"addi a1, a1, 16\n\t"
|
||||||
|
"ret.n\n\t"
|
||||||
|
".size stack_thunk_yield, .-stack_thunk_yield\n\t"
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern void stack_thunk_yield(void);
|
||||||
|
|
||||||
extern void stack_thunk_add_ref();
|
extern void stack_thunk_add_ref();
|
||||||
extern void stack_thunk_del_ref();
|
extern void stack_thunk_del_ref();
|
||||||
extern void stack_thunk_repaint();
|
extern void stack_thunk_repaint();
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
// Do not edit -- Automatically generated by tools/sdk/ssl/bearssl/Makefile
|
// Do not edit -- Automatically generated by tools/sdk/ssl/bearssl/Makefile
|
||||||
#define BEARSSL_GIT b024386
|
#define BEARSSL_GIT 5166f2b
|
||||||
|
Binary file not shown.
@ -1 +1 @@
|
|||||||
Subproject commit b024386d461abd1b7b9be3117e2516b7541f1201
|
Subproject commit 5166f2bb03fb03597b0f2c8c7fbcf01616df67c9
|
Loading…
x
Reference in New Issue
Block a user