From d8b69e89d8a4996eac2e53f16e6ef6e1cbb284b4 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sun, 19 Mar 2023 18:10:02 +0300 Subject: hurd: Move a couple of signal-related files to x86 These do not need any changes to be used on x86_64. Signed-off-by: Sergey Bugaev Message-Id: <20230319151017.531737-20-bugaevc@gmail.com> --- sysdeps/mach/hurd/i386/exc2signal.c | 196 ------------------------------ sysdeps/mach/hurd/i386/signal-defines.sym | 10 -- sysdeps/mach/hurd/x86/exc2signal.c | 196 ++++++++++++++++++++++++++++++ sysdeps/mach/hurd/x86/signal-defines.sym | 10 ++ 4 files changed, 206 insertions(+), 206 deletions(-) delete mode 100644 sysdeps/mach/hurd/i386/exc2signal.c delete mode 100644 sysdeps/mach/hurd/i386/signal-defines.sym create mode 100644 sysdeps/mach/hurd/x86/exc2signal.c create mode 100644 sysdeps/mach/hurd/x86/signal-defines.sym (limited to 'sysdeps') diff --git a/sysdeps/mach/hurd/i386/exc2signal.c b/sysdeps/mach/hurd/i386/exc2signal.c deleted file mode 100644 index c4e705121e..0000000000 --- a/sysdeps/mach/hurd/i386/exc2signal.c +++ /dev/null @@ -1,196 +0,0 @@ -/* Translate Mach exception codes into signal numbers. i386 version. - Copyright (C) 1991-2023 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - -/* Translate the Mach exception codes, as received in an `exception_raise' RPC, - into a signal number and signal subcode. */ - -static void -exception2signal (struct hurd_signal_detail *detail, int *signo, int posix) -{ - detail->error = 0; - - switch (detail->exc) - { - default: - *signo = SIGIOT; - detail->code = detail->exc; - break; - - case EXC_BAD_ACCESS: - switch (detail->exc_code) - { - case KERN_INVALID_ADDRESS: - case KERN_MEMORY_FAILURE: - *signo = SIGSEGV; - detail->code = posix ? SEGV_MAPERR : detail->exc_subcode; - break; - - case KERN_PROTECTION_FAILURE: - case KERN_WRITE_PROTECTION_FAILURE: - *signo = SIGSEGV; - detail->code = posix ? SEGV_ACCERR : detail->exc_subcode; - break; - - default: - *signo = SIGBUS; - detail->code = posix ? BUS_ADRERR : detail->exc_subcode; - break; - } - detail->error = detail->exc_code; - break; - - case EXC_BAD_INSTRUCTION: - *signo = SIGILL; - switch (detail->exc_code) - { - case EXC_I386_INVOP: - detail->code = posix ? ILL_ILLOPC : ILL_INVOPR_FAULT; - break; - - case EXC_I386_STKFLT: - detail->code = posix ? ILL_BADSTK : ILL_STACK_FAULT; - break; - - default: - detail->code = 0; - break; - } - break; - - case EXC_ARITHMETIC: - *signo = SIGFPE; - switch (detail->exc_code) - { - case EXC_I386_DIV: /* integer divide by zero */ - detail->code = posix ? FPE_INTDIV : FPE_INTDIV_FAULT; - break; - - case EXC_I386_INTO: /* integer overflow */ - detail->code = posix ? FPE_INTOVF : FPE_INTOVF_TRAP; - break; - - /* These aren't anywhere documented or used in Mach 3.0. */ - case EXC_I386_NOEXT: - case EXC_I386_EXTOVR: - default: - detail->code = 0; - break; - - case EXC_I386_EXTERR: - /* Subcode is the fp_status word saved by the hardware. - Give an error code corresponding to the first bit set. */ - if (detail->exc_subcode & FPS_IE) - { - /* NB: We used to send SIGILL here but we can't distinguish - POSIX vs. legacy with respect to what signal we send. */ - detail->code = posix ? FPE_FLTINV : 0 /*ILL_FPEOPR_FAULT*/; - } - else if (detail->exc_subcode & FPS_DE) - { - detail->code = posix ? FPE_FLTUND : FPE_FLTDNR_FAULT; - } - else if (detail->exc_subcode & FPS_ZE) - { - detail->code = posix ? FPE_FLTDIV : FPE_FLTDIV_FAULT; - } - else if (detail->exc_subcode & FPS_OE) - { - detail->code = posix ? FPE_FLTOVF : FPE_FLTOVF_FAULT; - } - else if (detail->exc_subcode & FPS_UE) - { - detail->code = posix ? FPE_FLTUND : FPE_FLTUND_FAULT; - } - else if (detail->exc_subcode & FPS_PE) - { - detail->code = posix ? FPE_FLTRES : FPE_FLTINX_FAULT; - } - else - { - detail->code = 0; - } - break; - - /* These two can only be arithmetic exceptions if we - are in V86 mode. (See Mach 3.0 i386/trap.c.) */ - case EXC_I386_EMERR: - detail->code = posix ? 0 : FPE_EMERR_FAULT; - break; - case EXC_I386_BOUND: - detail->code = posix ? FPE_FLTSUB : FPE_EMBND_FAULT; - break; - } - break; - - case EXC_EMULATION: - /* 3.0 doesn't give this one, why, I don't know. */ - *signo = SIGEMT; - detail->code = 0; - break; - - case EXC_SOFTWARE: - /* The only time we get this in Mach 3.0 - is for an out of bounds trap. */ - if (detail->exc_code == EXC_I386_BOUND) - { - *signo = SIGFPE; - detail->code = posix ? FPE_FLTSUB : FPE_SUBRNG_FAULT; - } - else - { - *signo = SIGEMT; - detail->code = 0; - } - break; - - case EXC_BREAKPOINT: - *signo = SIGTRAP; - switch (detail->exc_code) - { - case EXC_I386_SGL: - detail->code = posix ? TRAP_BRKPT : DBG_SINGLE_TRAP; - break; - - case EXC_I386_BPT: - detail->code = posix ? TRAP_BRKPT : DBG_BRKPNT_FAULT; - break; - - default: - detail->code = 0; - break; - } - break; - } -} -libc_hidden_def (_hurd_exception2signal) - -void -_hurd_exception2signal (struct hurd_signal_detail *detail, int *signo) -{ - exception2signal (detail, signo, 1); -} - -void -_hurd_exception2signal_legacy (struct hurd_signal_detail *detail, int *signo) -{ - exception2signal (detail, signo, 0); -} diff --git a/sysdeps/mach/hurd/i386/signal-defines.sym b/sysdeps/mach/hurd/i386/signal-defines.sym deleted file mode 100644 index e42bbbe061..0000000000 --- a/sysdeps/mach/hurd/i386/signal-defines.sym +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - --- - -HURD_SIGSTATE__SIGALTSTACK__OFFSET offsetof(struct hurd_sigstate, sigaltstack) - -SIGALTSTACK__SS_SP__OFFSET offsetof(stack_t, ss_sp) -SIGALTSTACK__SS_SIZE__OFFSET offsetof(stack_t, ss_size) -SIGALTSTACK__SS_FLAGS__OFFSET offsetof(stack_t, ss_flags) diff --git a/sysdeps/mach/hurd/x86/exc2signal.c b/sysdeps/mach/hurd/x86/exc2signal.c new file mode 100644 index 0000000000..c4e705121e --- /dev/null +++ b/sysdeps/mach/hurd/x86/exc2signal.c @@ -0,0 +1,196 @@ +/* Translate Mach exception codes into signal numbers. i386 version. + Copyright (C) 1991-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +/* Translate the Mach exception codes, as received in an `exception_raise' RPC, + into a signal number and signal subcode. */ + +static void +exception2signal (struct hurd_signal_detail *detail, int *signo, int posix) +{ + detail->error = 0; + + switch (detail->exc) + { + default: + *signo = SIGIOT; + detail->code = detail->exc; + break; + + case EXC_BAD_ACCESS: + switch (detail->exc_code) + { + case KERN_INVALID_ADDRESS: + case KERN_MEMORY_FAILURE: + *signo = SIGSEGV; + detail->code = posix ? SEGV_MAPERR : detail->exc_subcode; + break; + + case KERN_PROTECTION_FAILURE: + case KERN_WRITE_PROTECTION_FAILURE: + *signo = SIGSEGV; + detail->code = posix ? SEGV_ACCERR : detail->exc_subcode; + break; + + default: + *signo = SIGBUS; + detail->code = posix ? BUS_ADRERR : detail->exc_subcode; + break; + } + detail->error = detail->exc_code; + break; + + case EXC_BAD_INSTRUCTION: + *signo = SIGILL; + switch (detail->exc_code) + { + case EXC_I386_INVOP: + detail->code = posix ? ILL_ILLOPC : ILL_INVOPR_FAULT; + break; + + case EXC_I386_STKFLT: + detail->code = posix ? ILL_BADSTK : ILL_STACK_FAULT; + break; + + default: + detail->code = 0; + break; + } + break; + + case EXC_ARITHMETIC: + *signo = SIGFPE; + switch (detail->exc_code) + { + case EXC_I386_DIV: /* integer divide by zero */ + detail->code = posix ? FPE_INTDIV : FPE_INTDIV_FAULT; + break; + + case EXC_I386_INTO: /* integer overflow */ + detail->code = posix ? FPE_INTOVF : FPE_INTOVF_TRAP; + break; + + /* These aren't anywhere documented or used in Mach 3.0. */ + case EXC_I386_NOEXT: + case EXC_I386_EXTOVR: + default: + detail->code = 0; + break; + + case EXC_I386_EXTERR: + /* Subcode is the fp_status word saved by the hardware. + Give an error code corresponding to the first bit set. */ + if (detail->exc_subcode & FPS_IE) + { + /* NB: We used to send SIGILL here but we can't distinguish + POSIX vs. legacy with respect to what signal we send. */ + detail->code = posix ? FPE_FLTINV : 0 /*ILL_FPEOPR_FAULT*/; + } + else if (detail->exc_subcode & FPS_DE) + { + detail->code = posix ? FPE_FLTUND : FPE_FLTDNR_FAULT; + } + else if (detail->exc_subcode & FPS_ZE) + { + detail->code = posix ? FPE_FLTDIV : FPE_FLTDIV_FAULT; + } + else if (detail->exc_subcode & FPS_OE) + { + detail->code = posix ? FPE_FLTOVF : FPE_FLTOVF_FAULT; + } + else if (detail->exc_subcode & FPS_UE) + { + detail->code = posix ? FPE_FLTUND : FPE_FLTUND_FAULT; + } + else if (detail->exc_subcode & FPS_PE) + { + detail->code = posix ? FPE_FLTRES : FPE_FLTINX_FAULT; + } + else + { + detail->code = 0; + } + break; + + /* These two can only be arithmetic exceptions if we + are in V86 mode. (See Mach 3.0 i386/trap.c.) */ + case EXC_I386_EMERR: + detail->code = posix ? 0 : FPE_EMERR_FAULT; + break; + case EXC_I386_BOUND: + detail->code = posix ? FPE_FLTSUB : FPE_EMBND_FAULT; + break; + } + break; + + case EXC_EMULATION: + /* 3.0 doesn't give this one, why, I don't know. */ + *signo = SIGEMT; + detail->code = 0; + break; + + case EXC_SOFTWARE: + /* The only time we get this in Mach 3.0 + is for an out of bounds trap. */ + if (detail->exc_code == EXC_I386_BOUND) + { + *signo = SIGFPE; + detail->code = posix ? FPE_FLTSUB : FPE_SUBRNG_FAULT; + } + else + { + *signo = SIGEMT; + detail->code = 0; + } + break; + + case EXC_BREAKPOINT: + *signo = SIGTRAP; + switch (detail->exc_code) + { + case EXC_I386_SGL: + detail->code = posix ? TRAP_BRKPT : DBG_SINGLE_TRAP; + break; + + case EXC_I386_BPT: + detail->code = posix ? TRAP_BRKPT : DBG_BRKPNT_FAULT; + break; + + default: + detail->code = 0; + break; + } + break; + } +} +libc_hidden_def (_hurd_exception2signal) + +void +_hurd_exception2signal (struct hurd_signal_detail *detail, int *signo) +{ + exception2signal (detail, signo, 1); +} + +void +_hurd_exception2signal_legacy (struct hurd_signal_detail *detail, int *signo) +{ + exception2signal (detail, signo, 0); +} diff --git a/sysdeps/mach/hurd/x86/signal-defines.sym b/sysdeps/mach/hurd/x86/signal-defines.sym new file mode 100644 index 0000000000..e42bbbe061 --- /dev/null +++ b/sysdeps/mach/hurd/x86/signal-defines.sym @@ -0,0 +1,10 @@ +#include +#include + +-- + +HURD_SIGSTATE__SIGALTSTACK__OFFSET offsetof(struct hurd_sigstate, sigaltstack) + +SIGALTSTACK__SS_SP__OFFSET offsetof(stack_t, ss_sp) +SIGALTSTACK__SS_SIZE__OFFSET offsetof(stack_t, ss_size) +SIGALTSTACK__SS_FLAGS__OFFSET offsetof(stack_t, ss_flags) -- cgit 1.4.1