@@ -444,20 +444,19 @@ tstate_set_stack(PyThreadState *tstate,
444
444
void * stack_start_addr , size_t stack_size )
445
445
{
446
446
assert (stack_size > 0 );
447
+ assert (stack_size >= (_PyOS_STACK_MARGIN_BYTES * 3 ));
447
448
448
449
_PyThreadStateImpl * ts = (_PyThreadStateImpl * )tstate ;
449
450
ts -> c_stack_hard_limit = (uintptr_t )stack_start_addr ;
450
451
ts -> c_stack_top = (uintptr_t )stack_start_addr + stack_size ;
451
452
452
453
uintptr_t soft_limit = ts -> c_stack_hard_limit ;
453
- if (stack_size >= _PyOS_STACK_MARGIN_BYTES ) {
454
454
#ifdef _Py_THREAD_SANITIZER
455
- // Thread sanitizer crashes if we use a bit more than half the stack.
456
- soft_limit += (stack_size / 2 );
455
+ // Thread sanitizer crashes if we use a bit more than half the stack.
456
+ soft_limit += (stack_size / 2 );
457
457
#else
458
- soft_limit += _PyOS_STACK_MARGIN_BYTES ;
458
+ soft_limit += _PyOS_STACK_MARGIN_BYTES ;
459
459
#endif
460
- }
461
460
ts -> c_stack_soft_limit = soft_limit ;
462
461
463
462
// Sanity checks
477
476
PyUnstable_ThreadState_SetStack (PyThreadState * tstate ,
478
477
void * stack_start_addr , size_t stack_size )
479
478
{
480
- if (stack_size == 0 ) {
481
- PyErr_SetString (PyExc_ValueError , "stack_size must be greater than 0" );
479
+ if (stack_size < (_PyOS_STACK_MARGIN_BYTES * 3 )) {
480
+ PyErr_Format (PyExc_ValueError ,
481
+ "stack_size must be at least %zu bytes" ,
482
+ _PyOS_STACK_MARGIN_BYTES * 3 );
482
483
return -1 ;
483
484
}
484
485
0 commit comments