aboutsummaryrefslogtreecommitdiff
path: root/util/coroutine-sigaltstack.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/coroutine-sigaltstack.c')
-rw-r--r--util/coroutine-sigaltstack.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/util/coroutine-sigaltstack.c b/util/coroutine-sigaltstack.c
index a7c3366553..f6fc49a0e5 100644
--- a/util/coroutine-sigaltstack.c
+++ b/util/coroutine-sigaltstack.c
@@ -33,8 +33,9 @@
typedef struct {
Coroutine base;
void *stack;
+ size_t stack_size;
sigjmp_buf env;
-} CoroutineUContext;
+} CoroutineSigAltStack;
/**
* Per-thread coroutine bookkeeping
@@ -44,7 +45,7 @@ typedef struct {
Coroutine *current;
/** The default coroutine */
- CoroutineUContext leader;
+ CoroutineSigAltStack leader;
/** Information for the signal handler (trampoline) */
sigjmp_buf tr_reenter;
@@ -89,7 +90,7 @@ static void __attribute__((constructor)) coroutine_init(void)
* (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)) {
@@ -109,7 +110,7 @@ static void coroutine_bootstrap(CoroutineUContext *self, Coroutine *co)
*/
static void coroutine_trampoline(int signal)
{
- CoroutineUContext *self;
+ CoroutineSigAltStack *self;
Coroutine *co;
CoroutineThreadState *coTS;
@@ -143,8 +144,7 @@ static void coroutine_trampoline(int signal)
Coroutine *qemu_coroutine_new(void)
{
- const size_t stack_size = 1 << 20;
- CoroutineUContext *co;
+ CoroutineSigAltStack *co;
CoroutineThreadState *coTS;
struct sigaction sa;
struct sigaction osa;
@@ -164,7 +164,8 @@ Coroutine *qemu_coroutine_new(void)
*/
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();
@@ -189,7 +190,7 @@ Coroutine *qemu_coroutine_new(void)
* 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();
@@ -251,17 +252,17 @@ Coroutine *qemu_coroutine_new(void)
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;