Skip to content

Commit

Permalink
Keep bssl stack pointer from confusing yield
Browse files Browse the repository at this point in the history
only rememember a1, yield handles the rest of the registers
see esp8266#9170, should no longer crash when using client keys
  • Loading branch information
mcspr committed Sep 2, 2024
1 parent 092cefc commit ffda6c3
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions cores/esp8266/StackThunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ extern void optimistic_yield(uint32_t);

uint32_t *stack_thunk_ptr = NULL;
uint32_t *stack_thunk_top = NULL;

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;

/* Largest stack usage seen in the wild at 6120 */
Expand Down Expand Up @@ -155,9 +158,32 @@ void stack_thunk_fatal_smashing()
__stack_chk_fail();
}

void stack_thunk_yield()
{
optimistic_yield(10000);
}
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"
"addi a1, a1, -16\n\t"
"s32i.n a0, a1, 12\n\t"
"call0 can_yield\n\t"
"beqz.n a2, .Lstack_thunk_yield_pass\n\t"
"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"
"call0 yield\n\t"
"movi a2, stack_thunk_yield_save\n\t"
"l32i.n a1, a2, 0\n\t"
"\n"
".Lstack_thunk_yield_pass:\n\t"
"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"
);

}

0 comments on commit ffda6c3

Please sign in to comment.