]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/mips/unwind-arch.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / mips / unwind-arch.h
1 /* Return backtrace of current program state. Arch-specific bits.
2 Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #ifndef _UNWIND_ARCH_H
20 #define _UNWIND_ARCH_H
21
22 #include <stdint.h>
23
24 /* MIPS fallback code handle a frame where its FDE can not be obtained
25 (for instance a signal frame) by reading the kernel allocated signal frame
26 and adding '2' to the value of 'sc_pc' [1]. The added value is used to
27 recognize an end of an EH region on mips16 [2].
28
29 The idea here is to adjust the obtained signal frame ADDR value and remove
30 the libgcc added value by checking if the previous frame is a signal frame
31 one.
32
33 [1] libgcc/config/mips/linux-unwind.h from gcc code.
34 [2] gcc/config/mips/mips.h from gcc code. */
35
36 static inline void *
37 unwind_arch_adjustment (void *prev, void *addr)
38 {
39 uint32_t *pc = (uint32_t *) prev;
40
41 if (pc == NULL)
42 return addr;
43
44 /* For MIPS16 or microMIPS frame libgcc makes no adjustment. */
45 if ((uintptr_t) pc & 0x3)
46 return addr;
47
48 /* The vDSO containes either
49
50 24021061 li v0, 0x1061 (rt_sigreturn)
51 0000000c syscall
52 or
53 24021017 li v0, 0x1017 (sigreturn)
54 0000000c syscall */
55 if (pc[1] != 0x0000000c)
56 return addr;
57 #if _MIPS_SIM == _ABIO32
58 if (pc[0] == (0x24020000 | __NR_sigreturn))
59 return (void *) ((uintptr_t) addr - 2);
60 #endif
61 if (pc[0] == (0x24020000 | __NR_rt_sigreturn))
62 return (void *) ((uintptr_t) addr - 2);
63
64 return addr;
65 }
66
67 #endif