android_kernel_xiaomi_sm8350/include/asm-sparc/signal.h
David S. Miller 28e6103665 sparc: Fix debugger syscall restart interactions.
So, forever, we've had this ptrace_signal_deliver implementation
which tries to handle all of the nasties that can occur when the
debugger looks at a process about to take a signal.  It's meant
to address all of these issues inside of the kernel so that the
debugger need not be mindful of such things.

Problem is, this doesn't work.

The idea was that we should do the syscall restart business first, so
that the debugger captures that state.  Otherwise, if the debugger for
example saves the child's state, makes the child execute something
else, then restores the saved state, we won't handle the syscall
restart properly because we lose the "we're in a syscall" state.

The code here worked for most cases, but if the debugger actually
passes the signal through to the child unaltered, it's possible that
we would do a syscall restart when we shouldn't have.

In particular this breaks the case of debugging a process under a gdb
which is being debugged by yet another gdb.  gdb uses sigsuspend
to wait for SIGCHLD of the inferior, but if gdb itself is being
debugged by a top-level gdb we get a ptrace_stop().  The top-level gdb
does a PTRACE_CONT with SIGCHLD to let the inferior gdb see the
signal.  But ptrace_signal_deliver() assumed the debugger would cancel
out the signal and therefore did a syscall restart, because the return
error was ERESTARTNOHAND.

Fix this by simply making ptrace_signal_deliver() a nop, and providing
a way for the debugger to control system call restarting properly:

1) Report a "in syscall" software bit in regs->{tstate,psr}.
   It is set early on in trap entry to a system call and is fully
   visible to the debugger via ptrace() and regsets.

2) Test this bit right before doing a syscall restart.  We have
   to do a final recheck right after get_signal_to_deliver() in
   case the debugger cleared the bit during ptrace_stop().

3) Clear the bit in trap return so we don't accidently try to set
   that bit in the real register.

As a result we also get a ptrace_{is,clear}_syscall() for sparc32 just
like sparc64 has.

M68K has this same exact bug, and is now the only other user of the
ptrace_signal_deliver hook.  It needs to be fixed in the same exact
way as sparc.

Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-11 02:07:19 -07:00

209 lines
5.1 KiB
C

/* $Id: signal.h,v 1.35 1999/09/06 08:22:04 jj Exp $ */
#ifndef _ASMSPARC_SIGNAL_H
#define _ASMSPARC_SIGNAL_H
#include <asm/sigcontext.h>
#include <linux/compiler.h>
#ifdef __KERNEL__
#ifndef __ASSEMBLY__
#include <linux/personality.h>
#include <linux/types.h>
#endif
#endif
/* On the Sparc the signal handlers get passed a 'sub-signal' code
* for certain signal types, which we document here.
*/
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SUBSIG_STACK 0
#define SUBSIG_ILLINST 2
#define SUBSIG_PRIVINST 3
#define SUBSIG_BADTRAP(t) (0x80 + (t))
#define SIGTRAP 5
#define SIGABRT 6
#define SIGIOT 6
#define SIGEMT 7
#define SUBSIG_TAG 10
#define SIGFPE 8
#define SUBSIG_FPDISABLED 0x400
#define SUBSIG_FPERROR 0x404
#define SUBSIG_FPINTOVFL 0x001
#define SUBSIG_FPSTSIG 0x002
#define SUBSIG_IDIVZERO 0x014
#define SUBSIG_FPINEXACT 0x0c4
#define SUBSIG_FPDIVZERO 0x0c8
#define SUBSIG_FPUNFLOW 0x0cc
#define SUBSIG_FPOPERROR 0x0d0
#define SUBSIG_FPOVFLOW 0x0d4
#define SIGKILL 9
#define SIGBUS 10
#define SUBSIG_BUSTIMEOUT 1
#define SUBSIG_ALIGNMENT 2
#define SUBSIG_MISCERROR 5
#define SIGSEGV 11
#define SUBSIG_NOMAPPING 3
#define SUBSIG_PROTECTION 4
#define SUBSIG_SEGERROR 5
#define SIGSYS 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGURG 16
/* SunOS values which deviate from the Linux/i386 ones */
#define SIGSTOP 17
#define SIGTSTP 18
#define SIGCONT 19
#define SIGCHLD 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGIO 23
#define SIGPOLL SIGIO /* SysV name for SIGIO */
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGLOST 29
#define SIGPWR SIGLOST
#define SIGUSR1 30
#define SIGUSR2 31
/* Most things should be clean enough to redefine this at will, if care
* is taken to make libc match.
*/
#define __OLD_NSIG 32
#define __NEW_NSIG 64
#define _NSIG_BPW 32
#define _NSIG_WORDS (__NEW_NSIG / _NSIG_BPW)
#define SIGRTMIN 32
#define SIGRTMAX __NEW_NSIG
#if defined(__KERNEL__) || defined(__WANT_POSIX1B_SIGNALS__)
#define _NSIG __NEW_NSIG
#define __new_sigset_t sigset_t
#define __new_sigaction sigaction
#define __old_sigset_t old_sigset_t
#define __old_sigaction old_sigaction
#else
#define _NSIG __OLD_NSIG
#define __old_sigset_t sigset_t
#define __old_sigaction sigaction
#endif
#ifndef __ASSEMBLY__
typedef unsigned long __old_sigset_t;
typedef struct {
unsigned long sig[_NSIG_WORDS];
} __new_sigset_t;
#ifdef __KERNEL__
/* A SunOS sigstack */
struct sigstack {
char *the_stack;
int cur_status;
};
#endif
/* Sigvec flags */
#define _SV_SSTACK 1u /* This signal handler should use sig-stack */
#define _SV_INTR 2u /* Sig return should not restart system call */
#define _SV_RESET 4u /* Set handler to SIG_DFL upon taken signal */
#define _SV_IGNCHILD 8u /* Do not send SIGCHLD */
/*
* sa_flags values: SA_STACK is not currently supported, but will allow the
* usage of signal stacks by using the (now obsolete) sa_restorer field in
* the sigaction structure as a stack pointer. This is now possible due to
* the changes in signal handling. LBT 010493.
* SA_RESTART flag to get restarting signals (which were the default long ago)
*/
#define SA_NOCLDSTOP _SV_IGNCHILD
#define SA_STACK _SV_SSTACK
#define SA_ONSTACK _SV_SSTACK
#define SA_RESTART _SV_INTR
#define SA_ONESHOT _SV_RESET
#define SA_NOMASK 0x20u
#define SA_NOCLDWAIT 0x100u
#define SA_SIGINFO 0x200u
#define SIG_BLOCK 0x01 /* for blocking signals */
#define SIG_UNBLOCK 0x02 /* for unblocking signals */
#define SIG_SETMASK 0x04 /* for setting the signal mask */
/*
* sigaltstack controls
*/
#define SS_ONSTACK 1
#define SS_DISABLE 2
#define MINSIGSTKSZ 4096
#define SIGSTKSZ 16384
#ifdef __KERNEL__
/*
* DJHR
* SA_STATIC_ALLOC is used for the SPARC system to indicate that this
* interrupt handler's irq structure should be statically allocated
* by the request_irq routine.
* The alternative is that arch/sparc/kernel/irq.c has carnal knowledge
* of interrupt usage and that sucks. Also without a flag like this
* it may be possible for the free_irq routine to attempt to free
* statically allocated data.. which is NOT GOOD.
*
*/
#define SA_STATIC_ALLOC 0x8000
#endif
#include <asm-generic/signal.h>
#ifdef __KERNEL__
struct __new_sigaction {
__sighandler_t sa_handler;
unsigned long sa_flags;
void (*sa_restorer)(void); /* Not used by Linux/SPARC */
__new_sigset_t sa_mask;
};
struct k_sigaction {
struct __new_sigaction sa;
void __user *ka_restorer;
};
struct __old_sigaction {
__sighandler_t sa_handler;
__old_sigset_t sa_mask;
unsigned long sa_flags;
void (*sa_restorer) (void); /* not used by Linux/SPARC */
};
typedef struct sigaltstack {
void __user *ss_sp;
int ss_flags;
size_t ss_size;
} stack_t;
#define ptrace_signal_deliver(regs, cookie) do { } while (0)
#endif /* !(__KERNEL__) */
#endif /* !(__ASSEMBLY__) */
#endif /* !(_ASMSPARC_SIGNAL_H) */