@@ -43,7 +43,10 @@ extern void optimistic_yield(uint32_t);
43
43
44
44
uint32_t *stack_thunk_ptr = NULL ;
45
45
uint32_t *stack_thunk_top = NULL ;
46
+
46
47
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
+
47
50
uint32_t stack_thunk_refcnt = 0 ;
48
51
49
52
/* Largest stack usage seen in the wild at 6120 */
@@ -155,9 +158,32 @@ void stack_thunk_fatal_smashing()
155
158
__stack_chk_fail ();
156
159
}
157
160
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
+ );
162
188
163
189
}
0 commit comments