On Wed, Apr 29, 2020 at 03:44:17PM -0400, Daniele Buono wrote: > diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h > index bd6b0468e1..2ffd75ddbe 100644 > --- a/include/qemu/coroutine_int.h > +++ b/include/qemu/coroutine_int.h > @@ -28,6 +28,12 @@ > #include "qemu/queue.h" > #include "qemu/coroutine.h" > > +#if defined(__has_feature) && __has_feature(safe_stack) > +#define CONFIG_SAFESTACK 1 Please perform this feature check in ./configure. That way CONFIG_SAFESTACK will be defined alongside all the other CONFIG_* values and be available to C and Makefiles via config-host.h and config-host.mak. > @@ -160,6 +169,19 @@ Coroutine *qemu_coroutine_new(void) > /* swapcontext() in, siglongjmp() back out */ > if (!sigsetjmp(old_env, 0)) { > start_switch_fiber(&fake_stack_save, co->stack, co->stack_size); > +#ifdef CONFIG_SAFESTACK > + /* > + * Before we swap the context, set the new unsafe stack > + * The unsafe stack grows just like the normal stack, so start from > + * the last usable location of the memory area. > + * NOTE: we don't have to re-set it afterwards because sigsetjmp was > + * called with the original usp. Since we are not coming back with a > + * swapcontext, but with a siglongjmp, when we are back here we > + * already have usp restored to the valid one for this function I don't understand this comment. __safestack_unsafe_stack_ptr is a thread-local variable, not a CPU register. How will siglongjmp() automatically restore it? > + */ > + void *usp = co->unsafe_stack + co->unsafe_stack_size; > + __safestack_unsafe_stack_ptr = usp; > +#endif > swapcontext(&old_uc, &uc); > } >