Skip to content

Commit ffda6c3

Browse files
committed
Keep bssl stack pointer from confusing yield
only rememember a1, yield handles the rest of the registers see esp8266#9170, should no longer crash when using client keys
1 parent 092cefc commit ffda6c3

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

Diff for: cores/esp8266/StackThunk.cpp

+30-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ extern void optimistic_yield(uint32_t);
4343

4444
uint32_t *stack_thunk_ptr = NULL;
4545
uint32_t *stack_thunk_top = NULL;
46+
4647
uint32_t *stack_thunk_save = NULL; /* Saved A1 while in BearSSL */
48+
uint32_t *stack_thunk_yield_save = NULL; /* Saved A1 when yielding from within BearSSL */
49+
4750
uint32_t stack_thunk_refcnt = 0;
4851

4952
/* Largest stack usage seen in the wild at 6120 */
@@ -155,9 +158,32 @@ void stack_thunk_fatal_smashing()
155158
__stack_chk_fail();
156159
}
157160

158-
void stack_thunk_yield()
159-
{
160-
optimistic_yield(10000);
161-
}
161+
void stack_thunk_yield();
162+
asm(
163+
".section .text.stack_thunk_yield,\"ax\",@progbits\n\t"
164+
".literal_position\n\t"
165+
".align 4\n\t"
166+
".global stack_thunk_yield\n\t"
167+
".type stack_thunk_yield, @function\n\t"
168+
"\n"
169+
"stack_thunk_yield:\n\t"
170+
"addi a1, a1, -16\n\t"
171+
"s32i.n a0, a1, 12\n\t"
172+
"call0 can_yield\n\t"
173+
"beqz.n a2, .Lstack_thunk_yield_pass\n\t"
174+
"movi a2, stack_thunk_yield_save\n\t"
175+
"s32i.n a1, a2, 0\n\t"
176+
"movi a2, stack_thunk_save\n\t"
177+
"l32i.n a1, a2, 0\n\t"
178+
"call0 yield\n\t"
179+
"movi a2, stack_thunk_yield_save\n\t"
180+
"l32i.n a1, a2, 0\n\t"
181+
"\n"
182+
".Lstack_thunk_yield_pass:\n\t"
183+
"l32i.n a0, a1, 12\n\t"
184+
"addi a1, a1, 16\n\t"
185+
"ret.n\n\t"
186+
".size stack_thunk_yield, .-stack_thunk_yield\n\t"
187+
);
162188

163189
}

0 commit comments

Comments
 (0)