Skip to content

Commit bef62c1

Browse files
committed
bssl: explicit stack thunk yield
see esp8266#9170
1 parent 7e0d20e commit bef62c1

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

cores/esp8266/StackThunk.cpp

+28-3
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,24 @@
2424
Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling)
2525
*/
2626

27-
#include <stdint.h>
28-
#include <stdlib.h>
29-
#include <stdio.h>
27+
#include <cassert>
28+
#include <cstdint>
29+
#include <cstdlib>
30+
#include <cstdio>
31+
3032
#include "pgmspace.h"
3133
#include "debug.h"
3234
#include "StackThunk.h"
35+
3336
#include <ets_sys.h>
3437
#include <umm_malloc/umm_malloc.h>
3538
#include <umm_malloc/umm_heap_select.h>
3639

3740
extern "C" {
3841

42+
extern void yield();
43+
extern bool can_yield();
44+
3945
uint32_t *stack_thunk_ptr = NULL;
4046
uint32_t *stack_thunk_top = NULL;
4147
uint32_t *stack_thunk_save = NULL; /* Saved A1 while in BearSSL */
@@ -45,6 +51,25 @@ uint32_t stack_thunk_refcnt = 0;
4551
#define _stackSize (6200/4)
4652
#define _stackPaint 0xdeadbeef
4753

54+
void stack_thunk_yield()
55+
{
56+
if (can_yield()) {
57+
uint32_t tmp;
58+
register uint32_t* save __asm__("a3") = stack_thunk_save;
59+
60+
__asm__ __volatile__ (
61+
"mov.n %0, a1\n\t"
62+
"mov.n a1, %1\n\t"
63+
: "=r"(tmp) : "r"(save) : "memory");
64+
65+
yield();
66+
67+
__asm__ __volatile__ (
68+
"mov.n a1, %0\n\t"
69+
:: "r"(tmp) : "memory");
70+
}
71+
}
72+
4873
/* Add a reference, and allocate the stack if necessary */
4974
void stack_thunk_add_ref()
5075
{

cores/esp8266/StackThunk.h

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
extern "C" {
3232
#endif
3333

34+
extern void stack_thunk_yield();
35+
3436
extern void stack_thunk_add_ref();
3537
extern void stack_thunk_del_ref();
3638
extern void stack_thunk_repaint();

tools/sdk/lib/libbearssl.a

-39.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)