Message ID | 1464360721-14359-2-git-send-email-peter.maydell@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Le 27/05/2016 à 16:51, Peter Maydell a écrit : > Factor out the code to handle a single signal from the > process_pending_signals() function. The use of goto for flow control > is OK currently, but would get significantly uglier if extended to > allow running the handle_signal code multiple times. > > Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> > --- > linux-user/signal.c | 29 ++++++++++++++++++----------- > 1 file changed, 18 insertions(+), 11 deletions(-) > > diff --git a/linux-user/signal.c b/linux-user/signal.c > index 8090b4d..a9ac491 100644 > --- a/linux-user/signal.c > +++ b/linux-user/signal.c > @@ -5765,33 +5765,40 @@ long do_rt_sigreturn(CPUArchState *env) > > #endif > > +static void handle_pending_signal(CPUArchState *cpu_env, int sig); > + > void process_pending_signals(CPUArchState *cpu_env) > { > CPUState *cpu = ENV_GET_CPU(cpu_env); > int sig; > - abi_ulong handler; > - sigset_t set, old_set; > - target_sigset_t target_old_set; > - struct emulated_sigtable *k; > - struct target_sigaction *sa; > - struct sigqueue *q; > TaskState *ts = cpu->opaque; > > if (!ts->signal_pending) > return; > > /* FIXME: This is not threadsafe. */ > - k = ts->sigtab; > for(sig = 1; sig <= TARGET_NSIG; sig++) { > - if (k->pending) > - goto handle_signal; > - k++; > + if (ts->sigtab[sig - 1].pending) { > + handle_pending_signal(cpu_env, sig); > + return; > + } > } > /* if no signal is pending, just return */ > ts->signal_pending = 0; > return; > +} > + > +static void handle_pending_signal(CPUArchState *cpu_env, int sig) > +{ > + CPUState *cpu = ENV_GET_CPU(cpu_env); > + abi_ulong handler; > + sigset_t set, old_set; > + target_sigset_t target_old_set; > + struct target_sigaction *sa; > + struct sigqueue *q; > + TaskState *ts = cpu->opaque; > + struct emulated_sigtable *k = &ts->sigtab[sig - 1]; > > - handle_signal: > trace_user_handle_signal(cpu_env, sig); > /* dequeue signal */ > q = k->first; >
diff --git a/linux-user/signal.c b/linux-user/signal.c index 8090b4d..a9ac491 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -5765,33 +5765,40 @@ long do_rt_sigreturn(CPUArchState *env) #endif +static void handle_pending_signal(CPUArchState *cpu_env, int sig); + void process_pending_signals(CPUArchState *cpu_env) { CPUState *cpu = ENV_GET_CPU(cpu_env); int sig; - abi_ulong handler; - sigset_t set, old_set; - target_sigset_t target_old_set; - struct emulated_sigtable *k; - struct target_sigaction *sa; - struct sigqueue *q; TaskState *ts = cpu->opaque; if (!ts->signal_pending) return; /* FIXME: This is not threadsafe. */ - k = ts->sigtab; for(sig = 1; sig <= TARGET_NSIG; sig++) { - if (k->pending) - goto handle_signal; - k++; + if (ts->sigtab[sig - 1].pending) { + handle_pending_signal(cpu_env, sig); + return; + } } /* if no signal is pending, just return */ ts->signal_pending = 0; return; +} + +static void handle_pending_signal(CPUArchState *cpu_env, int sig) +{ + CPUState *cpu = ENV_GET_CPU(cpu_env); + abi_ulong handler; + sigset_t set, old_set; + target_sigset_t target_old_set; + struct target_sigaction *sa; + struct sigqueue *q; + TaskState *ts = cpu->opaque; + struct emulated_sigtable *k = &ts->sigtab[sig - 1]; - handle_signal: trace_user_handle_signal(cpu_env, sig); /* dequeue signal */ q = k->first;
Factor out the code to handle a single signal from the process_pending_signals() function. The use of goto for flow control is OK currently, but would get significantly uglier if extended to allow running the handle_signal code multiple times. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> --- linux-user/signal.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)