1 /* Copyright (C) 1991-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <https://www.gnu.org/licenses/>. */
17
18 #include <setjmp.h>
19
20 /* Save the current program position in ENV and return 0. */
21 int
22 inhibit_stack_protector
23 #if defined BSD_SETJMP
24 # undef setjmp
25 # define savemask 1
setjmp(jmp_buf env)26 setjmp (jmp_buf env)
27 #elif defined BSD__SETJMP
28 # undef _setjmp
29 # define savemask 0
30 _setjmp (jmp_buf env)
31 #else
32 __sigsetjmp (jmp_buf env, int savemask)
33 #endif
34 {
35 /* Save data registers D1 through D7. */
36 asm volatile ("movem%.l %/d1-%/d7, %0"
37 : : "m" (env[0].__jmpbuf[0].__dregs[0]));
38
39 /* Save return address in place of register A0. */
40 env[0].__jmpbuf[0].__aregs[0] = __builtin_return_address (0);
41
42 /* Save address registers A1 through A5. */
43 asm volatile ("movem%.l %/a1-%/a5, %0"
44 : : "m" (env[0].__jmpbuf[0].__aregs[1]));
45
46 /* Save caller's FP, not our own. */
47 env[0].__jmpbuf[0].__fp = *(int **) __builtin_frame_address (0);
48
49 /* Save caller's SP, not our own. */
50 env[0].__jmpbuf[0].__sp = (int *) __builtin_frame_address (0) + 2;
51
52 #if defined __HAVE_68881__ || defined __HAVE_FPU__
53 /* Save floating-point (68881) registers FP0 through FP7. */
54 asm volatile ("fmovem%.x %/fp0-%/fp7, %0"
55 : : "m" (env[0].__jmpbuf[0].__fpregs[0]));
56 #elif defined (__mcffpu__)
57 asm volatile ("fmovem %/fp0-%/fp7, %0"
58 : : "m" (env[0].__jmpbuf[0].__fpregs[0]));
59 #endif
60
61 #if IS_IN (rtld)
62 /* In ld.so we never save the signal mask. */
63 return 0;
64 #else
65 /* Save the signal mask if requested. */
66 return __sigjmp_save (env, savemask);
67 #endif
68 }
69 #if !defined BSD_SETJMP && !defined BSD__SETJMP
70 libc_hidden_def (__sigsetjmp)
71 #endif
72