1/* setjmp for s390, ELF version.
2   Copyright (C) 2000-2022 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#include <sysdep.h>
20#define _ASM
21#define _SETJMP_H
22#include <bits/setjmp.h>
23#include <shlib-compat.h>
24#include <stap-probe.h>
25
26#if !IS_IN (rtld) && defined SHARED \
27  && SHLIB_COMPAT (libc, GLIBC_2_19, GLIBC_2_20)
28# define NEED_COMPAT_SYMBOLS 1
29/* We need a unique name in case of symbol versioning.  */
30# define setjmp __v1setjmp
31# define _setjmp __v1_setjmp
32# define __sigsetjmp __v1__sigsetjmp
33#else
34# define NEED_COMPAT_SYMBOLS 0
35#endif
36
37	/* We include the BSD entry points here as well.  */
38ENTRY (setjmp)
39	lhi    %r3,1                /* second argument of one */
40	j      .Linternal_sigsetjmp /* branch relativ to __sigsetjmp */
41END (setjmp)
42
43	/* Binary compatibility entry point.  */
44ENTRY(_setjmp)
45	lhi    %r3,0                /* second argument of zero */
46	j      .Linternal_sigsetjmp /* branch relativ to __sigsetjmp */
47END (_setjmp)
48#if NEED_COMPAT_SYMBOLS
49strong_alias (_setjmp, __GI__setjmp)
50#else
51libc_hidden_def (_setjmp)
52#endif
53
54ENTRY(__setjmp)
55	lhi    %r3,0                /* second argument of zero */
56	j      .Linternal_sigsetjmp /* branch relativ to __sigsetjmp */
57END (__setjmp)
58
59ENTRY(__sigsetjmp)
60.Linternal_sigsetjmp:
61	/* setjmp probe expects sig/setjmp first argument (4@%r2), second
62	   argument (-4@%r3) and target address (4@%r14).  */
63	LIBC_PROBE (setjmp, 3, 4@%r2, -4@%r3, 4@%r14)
64#ifdef PTR_MANGLE
65	stm    %r6,%r13,0(%r2)      /* store registers in jmp_buf */
66	lr     %r4,%r14
67	lr     %r5,%r15
68	PTR_MANGLE (%r4, %r1)
69	PTR_MANGLE2 (%r5, %r1)
70	stm    %r4,%r5,32(%r2)
71#else
72	stm    %r6,%r15,0(%r2)      /* store registers in jmp_buf */
73#endif
74	std    %f4,40(%r2)
75	std    %f6,48(%r2)
76#if IS_IN (rtld)
77	/* In ld.so we never save the signal mask.  */
78	lhi    %r2,0
79	br     %r14
80#elif defined PIC
81	/* We cannot use the PLT, because it requires that %r12 be set, but
82	   we can't save and restore our caller's value.  Instead, we do an
83	   indirect jump through the GOT. */
84	basr   %r1,0
85.L0:    al     %r1,.L1 - .L0(0,%r1) /* get address of global offset table */
86				    /* get address of __sigjmp_save from got */
87	l      %r1,__sigjmp_save@GOT(%r1)
88	br     %r1
89.L1:    .long  _GLOBAL_OFFSET_TABLE_ - .L0
90#else
91	basr   %r1,0
92.L0:    l      %r1,.L1-.L0(0,%r1)   /* load address of __sigjmp_save */
93	br     %r1                  /* tail-call __sigjmp_save */
94.L1:    .long  __sigjmp_save
95#endif
96END (__sigsetjmp)
97#if NEED_COMPAT_SYMBOLS
98strong_alias (__sigsetjmp, __GI___sigsetjmp)
99#else
100libc_hidden_def (__sigsetjmp)
101#endif
102
103#if NEED_COMPAT_SYMBOLS
104/* In glibc release 2.19 new versions of setjmp-functions were introduced,
105   but were reverted before 2.20. Thus both versions are the same function.  */
106
107# undef setjmp
108# undef _setjmp
109# undef __sigsetjmp
110
111strong_alias (__v1setjmp, __v2setjmp);
112versioned_symbol (libc, __v1setjmp, setjmp, GLIBC_2_0);
113compat_symbol (libc, __v2setjmp, setjmp, GLIBC_2_19);
114
115strong_alias (__v1_setjmp, __v2_setjmp);
116versioned_symbol (libc, __v1_setjmp, _setjmp, GLIBC_2_0);
117compat_symbol (libc, __v2_setjmp, _setjmp, GLIBC_2_19);
118
119strong_alias (__v1__sigsetjmp, __v2__sigsetjmp);
120versioned_symbol (libc, __v1__sigsetjmp, __sigsetjmp, GLIBC_2_0);
121compat_symbol (libc, __v2__sigsetjmp, __sigsetjmp, GLIBC_2_19);
122#endif /* NEED_COMPAT_SYMBOLS */
123