Skip to content

Commit e6a2d1f

Browse files
cfd-36Linus Torvalds
authored andcommitted
uml: clean up sig_handler_common_skas
sig_handler_common_skas needs significant modernization, starting with its name and storage class. There is no need to hide the true type of the sigcontext pointer, so the void * dummy parameter can be replaced with a sigcontext *sc. The array of uml_pt_regs structs used in the page fault case are gone, replaced by a local variable. This is also used in the non-segfault case instead of the copy in the task_struct. Since it's local, the special handling of the is_user flag can go away. There hasn't been any special treatment of SIGUSR1 in ages, so the line that enables it can be deleted. The special treatment of SIGSEGV similarly goes away, but to compensate, SA_NODEFER is added to sa_mask when registering a signal handler. Signed-off-by: Jeff Dike <jdike@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 75ada8f commit e6a2d1f

1 file changed

Lines changed: 18 additions & 45 deletions

File tree

‎arch/um/os-Linux/signal.c‎

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
#include <signal.h>
1111
#include <strings.h>
1212
#include "as-layout.h"
13-
#include "kern_constants.h"
1413
#include "kern_util.h"
1514
#include "os.h"
1615
#include "sysdep/barrier.h"
1716
#include "sysdep/sigcontext.h"
18-
#include "task.h"
1917
#include "user.h"
2018

19+
/* Copied from linux/compiler-gcc.h since we can't include it directly */
20+
#define barrier() __asm__ __volatile__("": : :"memory")
21+
2122
void (*sig_info[NSIG])(int, struct uml_pt_regs *) = {
2223
[SIGTRAP] = relay_signal,
2324
[SIGFPE] = relay_signal,
@@ -28,58 +29,27 @@ void (*sig_info[NSIG])(int, struct uml_pt_regs *) = {
2829
[SIGIO] = sigio_handler,
2930
[SIGVTALRM] = timer_handler };
3031

31-
static struct uml_pt_regs ksig_regs[UM_NR_CPUS];
32-
33-
void sig_handler_common_skas(int sig, void *sc_ptr)
32+
static void sig_handler_common(int sig, struct sigcontext *sc)
3433
{
35-
struct sigcontext *sc = sc_ptr;
36-
struct uml_pt_regs *r;
37-
void (*handler)(int, struct uml_pt_regs *);
38-
int save_user, save_errno = errno;
34+
struct uml_pt_regs r;
35+
int save_errno = errno;
3936

40-
/*
41-
* This is done because to allow SIGSEGV to be delivered inside a SEGV
42-
* handler. This can happen in copy_user, and if SEGV is disabled,
43-
* the process will die.
44-
* XXX Figure out why this is better than SA_NODEFER
45-
*/
37+
r.is_user = 0;
4638
if (sig == SIGSEGV) {
47-
change_sig(SIGSEGV, 1);
48-
/*
49-
* For segfaults, we want the data from the
50-
* sigcontext. In this case, we don't want to mangle
51-
* the process registers, so use a static set of
52-
* registers. For other signals, the process
53-
* registers are OK.
54-
*/
55-
r = &ksig_regs[cpu()];
56-
copy_sc(r, sc_ptr);
57-
} else
58-
r = TASK_REGS(get_current());
59-
60-
save_user = r->is_user;
61-
r->is_user = 0;
62-
if ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) ||
63-
(sig == SIGILL) || (sig == SIGTRAP))
64-
GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
65-
66-
change_sig(SIGUSR1, 1);
67-
68-
handler = sig_info[sig];
39+
/* For segfaults, we want the data from the sigcontext. */
40+
copy_sc(&r, sc);
41+
GET_FAULTINFO_FROM_SC(r.faultinfo, sc);
42+
}
6943

70-
/* unblock SIGVTALRM, SIGIO if sig isn't IRQ signal */
44+
/* enable signals if sig isn't IRQ signal */
7145
if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGVTALRM))
7246
unblock_signals();
7347

74-
handler(sig, r);
48+
(*sig_info[sig])(sig, &r);
7549

7650
errno = save_errno;
77-
r->is_user = save_user;
7851
}
7952

80-
/* Copied from linux/compiler-gcc.h since we can't include it directly */
81-
#define barrier() __asm__ __volatile__("": : :"memory")
82-
8353
/*
8454
* These are the asynchronous signals. SIGPROF is excluded because we want to
8555
* be able to profile all of UML, not just the non-critical sections. If
@@ -107,7 +77,7 @@ void sig_handler(int sig, struct sigcontext *sc)
10777

10878
block_signals();
10979

110-
sig_handler_common_skas(sig, sc);
80+
sig_handler_common(sig, sc);
11181

11282
set_signals(enabled);
11383
}
@@ -227,6 +197,9 @@ void set_handler(int sig, void (*handler)(int), int flags, ...)
227197
sigaddset(&action.sa_mask, mask);
228198
va_end(ap);
229199

200+
if (sig == SIGSEGV)
201+
flags |= SA_NODEFER;
202+
230203
action.sa_flags = flags;
231204
action.sa_restorer = NULL;
232205
if (sigaction(sig, &action, NULL) < 0)
@@ -306,7 +279,7 @@ void unblock_signals(void)
306279
* back here.
307280
*/
308281
if (save_pending & SIGIO_MASK)
309-
sig_handler_common_skas(SIGIO, NULL);
282+
sig_handler_common(SIGIO, NULL);
310283

311284
if (save_pending & SIGVTALRM_MASK)
312285
real_alarm_handler(NULL);

0 commit comments

Comments
 (0)