]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h
1 /* Copyright (C) 2000-2019 Free Software Foundation, Inc.
2 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #ifndef _LINUX_S390_SYSDEP_H
20 #define _LINUX_S390_SYSDEP_H
22 #include <sysdeps/s390/s390-32/sysdep.h>
23 #include <sysdeps/unix/sysdep.h>
24 #include <sysdeps/unix/sysv/linux/s390/sysdep.h>
25 #include <sysdeps/unix/sysv/linux/sysdep.h>
26 #include <dl-sysdep.h> /* For RTLD_PRIVATE_ERRNO. */
29 /* Define __set_errno() for INLINE_SYSCALL macro below. */
34 /* For Linux we can use the system call table in the header file
35 /usr/include/asm/unistd.h
36 of the kernel. But these symbols do not follow the SYS_* syntax
37 so we have to redefine the `SYS_ify' macro here. */
38 /* in newer 2.1 kernels __NR_syscall is missing so we define it here */
39 #define __NR_syscall 0
42 #define SYS_ify(syscall_name) __NR_##syscall_name
46 /* Linux uses a negative return value to indicate syscall errors, unlike
47 most Unices, which use the condition codes' carry flag.
49 Since version 2.1 the return value of a system call might be negative
50 even if the call succeeded. E.g., the `lseek' system call might return
51 a large offset. Therefore we must not anymore test for < 0, but test
52 for a real error by making sure the value in gpr2 is a real error
53 number. Linus said he will make sure that no syscall returns a value
54 in -1 .. -4095 as a valid result so we can savely test with -4095. */
57 #define PSEUDO(name, syscall_name, args) \
60 DO_CALL (syscall_name, args); \
63 jnl SYSCALL_ERROR_LABEL
66 #define PSEUDO_END(name) \
67 SYSCALL_ERROR_HANDLER; \
71 #define PSEUDO_NOERRNO(name, syscall_name, args) \
74 DO_CALL (syscall_name, args)
76 #undef PSEUDO_END_NOERRNO
77 #define PSEUDO_END_NOERRNO(name) \
81 #define PSEUDO_ERRVAL(name, syscall_name, args) \
84 DO_CALL (syscall_name, args); \
87 #undef PSEUDO_END_ERRVAL
88 #define PSEUDO_END_ERRVAL(name) \
92 # define SYSCALL_ERROR_LABEL 0f
93 # define SYSCALL_ERROR_HANDLER \
95 1: l %r1,2f-1b(%r1); \
97 2: .long syscall_error
99 # if RTLD_PRIVATE_ERRNO
100 # define SYSCALL_ERROR_LABEL 0f
101 # define SYSCALL_ERROR_HANDLER \
103 1: al %r1,2f-1b(%r1); \
108 2: .long rtld_errno-1b
109 # elif defined _LIBC_REENTRANT
111 # define SYSCALL_ERROR_ERRNO __libc_errno
113 # define SYSCALL_ERROR_ERRNO errno
115 # define SYSCALL_ERROR_LABEL 0f
116 # define SYSCALL_ERROR_HANDLER \
119 1: al %r1,2f-1b(%r1); \
120 l %r1,SYSCALL_ERROR_ERRNO@gotntpoff(%r1); \
125 2: .long _GLOBAL_OFFSET_TABLE_-1b
127 # define SYSCALL_ERROR_LABEL 0f
128 # define SYSCALL_ERROR_HANDLER \
130 1: al %r1,2f-1b(%r1); \
131 l %r1,errno@GOT(%r1); \
136 2: .long _GLOBAL_OFFSET_TABLE_-1b
137 # endif /* _LIBC_REENTRANT */
140 /* Linux takes system call arguments in registers:
142 syscall number 1 call-clobbered
143 arg 1 2 call-clobbered
144 arg 2 3 call-clobbered
145 arg 3 4 call-clobbered
146 arg 4 5 call-clobbered
150 (Of course a function with say 3 arguments does not have entries for
152 For system calls with 6 parameters a stack operation is required
153 to load the 6th parameter to register 7. Call saved register 7 is
154 moved to register 0 and back to avoid an additional stack frame.
157 #define DO_CALL(syscall, args) \
162 .if SYS_ify (syscall) < 256; \
163 svc SYS_ify (syscall); \
165 lhi %r1,SYS_ify (syscall); \
175 #define ret_NOERRNO \
181 #endif /* __ASSEMBLER__ */
183 #undef INLINE_SYSCALL
184 #define INLINE_SYSCALL(name, nr, args...) \
186 unsigned int _ret = INTERNAL_SYSCALL (name, , nr, args); \
187 if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (_ret, ))) \
189 __set_errno (INTERNAL_SYSCALL_ERRNO (_ret, )); \
194 #undef INTERNAL_SYSCALL_DECL
195 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
197 #undef INTERNAL_SYSCALL_DIRECT
198 #define INTERNAL_SYSCALL_DIRECT(name, err, nr, args...) \
200 DECLARGS_##nr(args) \
201 register int _ret __asm__("2"); \
202 __asm__ __volatile__ ( \
205 : "i" (__NR_##name) ASMFMT_##nr \
209 #undef INTERNAL_SYSCALL_SVC0
210 #define INTERNAL_SYSCALL_SVC0(name, err, nr, args...) \
212 DECLARGS_##nr(args) \
213 register unsigned long _nr __asm__("1") = (unsigned long)(__NR_##name); \
214 register int _ret __asm__("2"); \
215 __asm__ __volatile__ ( \
218 : "d" (_nr) ASMFMT_##nr \
222 #undef INTERNAL_SYSCALL_NCS
223 #define INTERNAL_SYSCALL_NCS(no, err, nr, args...) \
225 DECLARGS_##nr(args) \
226 register unsigned long _nr __asm__("1") = (unsigned long)(no); \
227 register int _ret __asm__("2"); \
228 __asm__ __volatile__ ( \
231 : "d" (_nr) ASMFMT_##nr \
235 #undef INTERNAL_SYSCALL
236 #define INTERNAL_SYSCALL(name, err, nr, args...) \
237 (((__NR_##name) < 256) \
238 ? INTERNAL_SYSCALL_DIRECT(name, err, nr, args) \
239 : INTERNAL_SYSCALL_SVC0(name, err,nr, args))
241 #undef INTERNAL_SYSCALL_ERROR_P
242 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
243 ((unsigned int) (val) >= 0xfffff001u)
245 #undef INTERNAL_SYSCALL_ERRNO
246 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
249 #define DECLARGS_1(arg1) \
250 register unsigned long gpr2 __asm__ ("2") = (unsigned long)(arg1);
251 #define DECLARGS_2(arg1, arg2) \
253 register unsigned long gpr3 __asm__ ("3") = (unsigned long)(arg2);
254 #define DECLARGS_3(arg1, arg2, arg3) \
255 DECLARGS_2(arg1, arg2) \
256 register unsigned long gpr4 __asm__ ("4") = (unsigned long)(arg3);
257 #define DECLARGS_4(arg1, arg2, arg3, arg4) \
258 DECLARGS_3(arg1, arg2, arg3) \
259 register unsigned long gpr5 __asm__ ("5") = (unsigned long)(arg4);
260 #define DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
261 DECLARGS_4(arg1, arg2, arg3, arg4) \
262 register unsigned long gpr6 __asm__ ("6") = (unsigned long)(arg5);
263 #define DECLARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
264 DECLARGS_5(arg1, arg2, arg3, arg4, arg5) \
265 register unsigned long gpr7 __asm__ ("7") = (unsigned long)(arg6);
268 #define ASMFMT_1 , "0" (gpr2)
269 #define ASMFMT_2 , "0" (gpr2), "d" (gpr3)
270 #define ASMFMT_3 , "0" (gpr2), "d" (gpr3), "d" (gpr4)
271 #define ASMFMT_4 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5)
272 #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
273 #define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7)
275 /* Pointer mangling support. */
277 /* We cannot use the thread descriptor because in ld.so we use setjmp
278 earlier than the descriptor is initialized. */
280 /* For the time being just use stack_guard rather than a separate
282 # ifdef __ASSEMBLER__
283 # define PTR_MANGLE(reg, tmpreg) \
285 x reg,STACK_GUARD(tmpreg)
286 # define PTR_MANGLE2(reg, tmpreg) \
287 x reg,STACK_GUARD(tmpreg)
288 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
290 # define PTR_MANGLE(var) \
291 (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
292 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
296 #endif /* _LINUX_S390_SYSDEP_H */