#ifdef _FORTIFY_SOURCE
#undef _FORTIFY_SOURCE
#endif
-#include <stdlib.h>
-#include <setjmp.h>
-#include <stdint.h>
+#include "qemu/osdep.h"
#include <pthread.h>
-#include <signal.h>
#include "qemu-common.h"
#include "qemu/coroutine_int.h"
typedef struct {
Coroutine base;
void *stack;
+ size_t stack_size;
sigjmp_buf env;
-} CoroutineUContext;
+} CoroutineSigAltStack;
/**
* Per-thread coroutine bookkeeping
Coroutine *current;
/** The default coroutine */
- CoroutineUContext leader;
+ CoroutineSigAltStack leader;
/** Information for the signal handler (trampoline) */
sigjmp_buf tr_reenter;
* (from the signal handler when it is not signal handling, read ahead
* for more information).
*/
-static void coroutine_bootstrap(CoroutineUContext *self, Coroutine *co)
+static void coroutine_bootstrap(CoroutineSigAltStack *self, Coroutine *co)
{
/* Initialize longjmp environment and switch back the caller */
if (!sigsetjmp(self->env, 0)) {
*/
static void coroutine_trampoline(int signal)
{
- CoroutineUContext *self;
+ CoroutineSigAltStack *self;
Coroutine *co;
CoroutineThreadState *coTS;
Coroutine *qemu_coroutine_new(void)
{
- const size_t stack_size = 1 << 20;
- CoroutineUContext *co;
+ CoroutineSigAltStack *co;
CoroutineThreadState *coTS;
struct sigaction sa;
struct sigaction osa;
*/
co = g_malloc0(sizeof(*co));
- co->stack = g_malloc(stack_size);
+ co->stack_size = COROUTINE_STACK_SIZE;
+ co->stack = qemu_alloc_stack(&co->stack_size);
co->base.entry_arg = &old_env; /* stash away our jmp_buf */
coTS = coroutine_get_thread_state();
* Set the new stack.
*/
ss.ss_sp = co->stack;
- ss.ss_size = stack_size;
+ ss.ss_size = co->stack_size;
ss.ss_flags = 0;
if (sigaltstack(&ss, &oss) < 0) {
abort();
void qemu_coroutine_delete(Coroutine *co_)
{
- CoroutineUContext *co = DO_UPCAST(CoroutineUContext, base, co_);
+ CoroutineSigAltStack *co = DO_UPCAST(CoroutineSigAltStack, base, co_);
- g_free(co->stack);
+ qemu_free_stack(co->stack, co->stack_size);
g_free(co);
}
CoroutineAction qemu_coroutine_switch(Coroutine *from_, Coroutine *to_,
CoroutineAction action)
{
- CoroutineUContext *from = DO_UPCAST(CoroutineUContext, base, from_);
- CoroutineUContext *to = DO_UPCAST(CoroutineUContext, base, to_);
+ CoroutineSigAltStack *from = DO_UPCAST(CoroutineSigAltStack, base, from_);
+ CoroutineSigAltStack *to = DO_UPCAST(CoroutineSigAltStack, base, to_);
CoroutineThreadState *s = coroutine_get_thread_state();
int ret;