Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* Copyright (C) 1992-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Brendan Kehoe (brendan@zen.org).
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 <http://www.gnu.org/licenses/>. */
18
19#include <sysdeps/unix/sysdep.h>
20#include <dl-sysdep.h> /* Defines RTLD_PRIVATE_ERRNO. */
21
22#ifdef __ASSEMBLER__
23
24#ifdef __linux__
25# include <alpha/regdef.h>
26#else
27# include <regdef.h>
28#endif
29
30#define __LABEL(x) x##:
31
32#define LEAF(name, framesize) \
33 .globl name; \
34 .align 4; \
35 .ent name, 0; \
36 __LABEL(name) \
37 .frame sp, framesize, ra
38
39#define ENTRY(name) \
40 .globl name; \
41 .align 4; \
42 .ent name, 0; \
43 __LABEL(name) \
44 .frame sp, 0, ra
45
46/* Mark the end of function SYM. */
47#undef END
48#define END(sym) .end sym
49
50#ifdef PROF
51# define PSEUDO_PROF \
52 .set noat; \
53 lda AT, _mcount; \
54 jsr AT, (AT), _mcount; \
55 .set at
56#else
57# define PSEUDO_PROF
58#endif
59
60#ifdef PROF
61# define PSEUDO_PROLOGUE \
62 .frame sp, 0, ra; \
63 ldgp gp,0(pv); \
64 PSEUDO_PROF; \
65 .prologue 1
66#elif defined PIC
67# define PSEUDO_PROLOGUE \
68 .frame sp, 0, ra; \
69 .prologue 0
70#else
71# define PSEUDO_PROLOGUE \
72 .frame sp, 0, ra; \
73 ldgp gp,0(pv); \
74 .prologue 1
75#endif /* PROF */
76
77#ifdef PROF
78# define USEPV_PROF std
79#else
80# define USEPV_PROF no
81#endif
82
83#if RTLD_PRIVATE_ERRNO
84# define SYSCALL_ERROR_LABEL $syscall_error
85# define SYSCALL_ERROR_HANDLER \
86$syscall_error: \
87 stl v0, rtld_errno(gp) !gprel; \
88 lda v0, -1; \
89 ret
90# define SYSCALL_ERROR_FALLTHRU
91#elif defined(PIC)
92# define SYSCALL_ERROR_LABEL __syscall_error !samegp
93# define SYSCALL_ERROR_HANDLER
94# define SYSCALL_ERROR_FALLTHRU br SYSCALL_ERROR_LABEL
95#else
96# define SYSCALL_ERROR_LABEL $syscall_error
97# define SYSCALL_ERROR_HANDLER \
98$syscall_error: \
99 jmp $31, __syscall_error
100# define SYSCALL_ERROR_FALLTHRU
101#endif /* RTLD_PRIVATE_ERRNO */
102
103/* Overridden by specific syscalls. */
104#undef PSEUDO_PREPARE_ARGS
105#define PSEUDO_PREPARE_ARGS /* Nothing. */
106
107#define PSEUDO(name, syscall_name, args) \
108 .globl name; \
109 .align 4; \
110 .ent name,0; \
111__LABEL(name) \
112 PSEUDO_PROLOGUE; \
113 PSEUDO_PREPARE_ARGS \
114 lda v0, SYS_ify(syscall_name); \
115 call_pal PAL_callsys; \
116 bne a3, SYSCALL_ERROR_LABEL
117
118#undef PSEUDO_END
119#define PSEUDO_END(sym) \
120 SYSCALL_ERROR_HANDLER; \
121 END(sym)
122
123#define PSEUDO_NOERRNO(name, syscall_name, args) \
124 .globl name; \
125 .align 4; \
126 .ent name,0; \
127__LABEL(name) \
128 PSEUDO_PROLOGUE; \
129 PSEUDO_PREPARE_ARGS \
130 lda v0, SYS_ify(syscall_name); \
131 call_pal PAL_callsys;
132
133#undef PSEUDO_END_NOERRNO
134#define PSEUDO_END_NOERRNO(sym) END(sym)
135
136#define ret_NOERRNO ret
137
138#define PSEUDO_ERRVAL(name, syscall_name, args) \
139 .globl name; \
140 .align 4; \
141 .ent name,0; \
142__LABEL(name) \
143 PSEUDO_PROLOGUE; \
144 PSEUDO_PREPARE_ARGS \
145 lda v0, SYS_ify(syscall_name); \
146 call_pal PAL_callsys;
147
148#undef PSEUDO_END_ERRVAL
149#define PSEUDO_END_ERRVAL(sym) END(sym)
150
151#define ret_ERRVAL ret
152
153#define r0 v0
154#define r1 a4
155
156#define MOVE(x,y) mov x,y
157
158#else /* !ASSEMBLER */
159
160/* In order to get __set_errno() definition in INLINE_SYSCALL. */
161#include <errno.h>
162
163/* ??? Linux needs to be able to override INLINE_SYSCALL for one
164 particular special case. Make this easy. */
165
166#undef INLINE_SYSCALL
167#define INLINE_SYSCALL(name, nr, args...) \
168 INLINE_SYSCALL1(name, nr, args)
169
170#define INLINE_SYSCALL1(name, nr, args...) \
171({ \
172 long _sc_ret, _sc_err; \
173 inline_syscall##nr(__NR_##name, args); \
174 if (__builtin_expect (_sc_err, 0)) \
175 { \
176 __set_errno (_sc_ret); \
177 _sc_ret = -1L; \
178 } \
179 _sc_ret; \
180})
181
182#define INTERNAL_SYSCALL(name, err_out, nr, args...) \
183 INTERNAL_SYSCALL1(name, err_out, nr, args)
184
185#define INTERNAL_SYSCALL1(name, err_out, nr, args...) \
186 INTERNAL_SYSCALL_NCS(__NR_##name, err_out, nr, args)
187
188#define INTERNAL_SYSCALL_NCS(name, err_out, nr, args...) \
189({ \
190 long _sc_ret, _sc_err; \
191 inline_syscall##nr(name, args); \
192 err_out = _sc_err; \
193 _sc_ret; \
194})
195
196#define INTERNAL_SYSCALL_DECL(err) \
197 long int err __attribute__((unused))
198
199/* The normal Alpha calling convention sign-extends 32-bit quantties
200 no matter what the "real" sign of the 32-bit type. We want to
201 preserve that when filling in values for the kernel. */
202#define syscall_promote(arg) \
203 (sizeof (arg) == 4 ? (long)(int)(long)(arg) : (long)(arg))
204
205/* Make sure and "use" the variable that we're not returning,
206 in order to suppress unused variable warnings. */
207#define INTERNAL_SYSCALL_ERROR_P(val, err) ((void)val, err)
208#define INTERNAL_SYSCALL_ERRNO(val, err) ((void)err, val)
209
210#define inline_syscall_clobbers \
211 "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
212 "$22", "$23", "$24", "$25", "$27", "$28", "memory"
213
214/* It is moderately important optimization-wise to limit the lifetime
215 of the hard-register variables as much as possible. Thus we copy
216 in/out as close to the asm as possible. */
217
218#define inline_syscall0(name, args...) \
219{ \
220 register long _sc_19 __asm__("$19"); \
221 register long _sc_0 = name; \
222 __asm__ __volatile__ \
223 ("callsys # %0 %1 <= %2" \
224 : "+v"(_sc_0), "=r"(_sc_19) \
225 : : inline_syscall_clobbers, \
226 "$16", "$17", "$18", "$20", "$21"); \
227 _sc_ret = _sc_0, _sc_err = _sc_19; \
228}
229
230#define inline_syscall1(name,arg1) \
231{ \
232 register long _tmp_16 = syscall_promote (arg1); \
233 register long _sc_0 = name; \
234 register long _sc_16 __asm__("$16") = _tmp_16; \
235 register long _sc_19 __asm__("$19"); \
236 __asm__ __volatile__ \
237 ("callsys # %0 %1 <= %2 %3" \
238 : "+v"(_sc_0), "=r"(_sc_19), "+r"(_sc_16) \
239 : : inline_syscall_clobbers, \
240 "$17", "$18", "$20", "$21"); \
241 _sc_ret = _sc_0, _sc_err = _sc_19; \
242}
243
244#define inline_syscall2(name,arg1,arg2) \
245{ \
246 register long _tmp_16 = syscall_promote (arg1); \
247 register long _tmp_17 = syscall_promote (arg2); \
248 register long _sc_0 = name; \
249 register long _sc_16 __asm__("$16") = _tmp_16; \
250 register long _sc_17 __asm__("$17") = _tmp_17; \
251 register long _sc_19 __asm__("$19"); \
252 __asm__ __volatile__ \
253 ("callsys # %0 %1 <= %2 %3 %4" \
254 : "+v"(_sc_0), "=r"(_sc_19), \
255 "+r"(_sc_16), "+r"(_sc_17) \
256 : : inline_syscall_clobbers, \
257 "$18", "$20", "$21"); \
258 _sc_ret = _sc_0, _sc_err = _sc_19; \
259}
260
261#define inline_syscall3(name,arg1,arg2,arg3) \
262{ \
263 register long _tmp_16 = syscall_promote (arg1); \
264 register long _tmp_17 = syscall_promote (arg2); \
265 register long _tmp_18 = syscall_promote (arg3); \
266 register long _sc_0 = name; \
267 register long _sc_16 __asm__("$16") = _tmp_16; \
268 register long _sc_17 __asm__("$17") = _tmp_17; \
269 register long _sc_18 __asm__("$18") = _tmp_18; \
270 register long _sc_19 __asm__("$19"); \
271 __asm__ __volatile__ \
272 ("callsys # %0 %1 <= %2 %3 %4 %5" \
273 : "+v"(_sc_0), "=r"(_sc_19), "+r"(_sc_16), \
274 "+r"(_sc_17), "+r"(_sc_18) \
275 : : inline_syscall_clobbers, "$20", "$21"); \
276 _sc_ret = _sc_0, _sc_err = _sc_19; \
277}
278
279#define inline_syscall4(name,arg1,arg2,arg3,arg4) \
280{ \
281 register long _tmp_16 = syscall_promote (arg1); \
282 register long _tmp_17 = syscall_promote (arg2); \
283 register long _tmp_18 = syscall_promote (arg3); \
284 register long _tmp_19 = syscall_promote (arg4); \
285 register long _sc_0 = name; \
286 register long _sc_16 __asm__("$16") = _tmp_16; \
287 register long _sc_17 __asm__("$17") = _tmp_17; \
288 register long _sc_18 __asm__("$18") = _tmp_18; \
289 register long _sc_19 __asm__("$19") = _tmp_19; \
290 __asm__ __volatile__ \
291 ("callsys # %0 %1 <= %2 %3 %4 %5 %6" \
292 : "+v"(_sc_0), "+r"(_sc_19), "+r"(_sc_16), \
293 "+r"(_sc_17), "+r"(_sc_18) \
294 : : inline_syscall_clobbers, "$20", "$21"); \
295 _sc_ret = _sc_0, _sc_err = _sc_19; \
296}
297
298#define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \
299{ \
300 register long _tmp_16 = syscall_promote (arg1); \
301 register long _tmp_17 = syscall_promote (arg2); \
302 register long _tmp_18 = syscall_promote (arg3); \
303 register long _tmp_19 = syscall_promote (arg4); \
304 register long _tmp_20 = syscall_promote (arg5); \
305 register long _sc_0 = name; \
306 register long _sc_16 __asm__("$16") = _tmp_16; \
307 register long _sc_17 __asm__("$17") = _tmp_17; \
308 register long _sc_18 __asm__("$18") = _tmp_18; \
309 register long _sc_19 __asm__("$19") = _tmp_19; \
310 register long _sc_20 __asm__("$20") = _tmp_20; \
311 __asm__ __volatile__ \
312 ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7" \
313 : "+v"(_sc_0), "+r"(_sc_19), "+r"(_sc_16), \
314 "+r"(_sc_17), "+r"(_sc_18), "+r"(_sc_20) \
315 : : inline_syscall_clobbers, "$21"); \
316 _sc_ret = _sc_0, _sc_err = _sc_19; \
317}
318
319#define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \
320{ \
321 register long _tmp_16 = syscall_promote (arg1); \
322 register long _tmp_17 = syscall_promote (arg2); \
323 register long _tmp_18 = syscall_promote (arg3); \
324 register long _tmp_19 = syscall_promote (arg4); \
325 register long _tmp_20 = syscall_promote (arg5); \
326 register long _tmp_21 = syscall_promote (arg6); \
327 register long _sc_0 = name; \
328 register long _sc_16 __asm__("$16") = _tmp_16; \
329 register long _sc_17 __asm__("$17") = _tmp_17; \
330 register long _sc_18 __asm__("$18") = _tmp_18; \
331 register long _sc_19 __asm__("$19") = _tmp_19; \
332 register long _sc_20 __asm__("$20") = _tmp_20; \
333 register long _sc_21 __asm__("$21") = _tmp_21; \
334 __asm__ __volatile__ \
335 ("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7 %8" \
336 : "+v"(_sc_0), "+r"(_sc_19), "+r"(_sc_16), \
337 "+r"(_sc_17), "+r"(_sc_18), "+r"(_sc_20), \
338 "+r"(_sc_21) \
339 : : inline_syscall_clobbers); \
340 _sc_ret = _sc_0, _sc_err = _sc_19; \
341}
342#endif /* ASSEMBLER */
343
344/* Pointer mangling support. Note that tls access is slow enough that
345 we don't deoptimize things by placing the pointer check value there. */
346
347#ifdef __ASSEMBLER__
348# if IS_IN (rtld)
349# define PTR_MANGLE(dst, src, tmp) \
350 ldah tmp, __pointer_chk_guard_local($29) !gprelhigh; \
351 ldq tmp, __pointer_chk_guard_local(tmp) !gprellow; \
352 xor src, tmp, dst
353# define PTR_MANGLE2(dst, src, tmp) \
354 xor src, tmp, dst
355# elif defined SHARED
356# define PTR_MANGLE(dst, src, tmp) \
357 ldq tmp, __pointer_chk_guard; \
358 xor src, tmp, dst
359# else
360# define PTR_MANGLE(dst, src, tmp) \
361 ldq tmp, __pointer_chk_guard_local; \
362 xor src, tmp, dst
363# endif
364# define PTR_MANGLE2(dst, src, tmp) \
365 xor src, tmp, dst
366# define PTR_DEMANGLE(dst, tmp) PTR_MANGLE(dst, dst, tmp)
367# define PTR_DEMANGLE2(dst, tmp) PTR_MANGLE2(dst, dst, tmp)
368#else
369# include <stdint.h>
370# if (IS_IN (rtld) \
371 || (!defined SHARED && (IS_IN (libc) \
372 || IS_IN (libpthread))))
373extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden;
374# define PTR_MANGLE(var) \
375 (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local)
376# else
377extern uintptr_t __pointer_chk_guard attribute_relro;
378# define PTR_MANGLE(var) \
379 (var) = (__typeof(var)) ((uintptr_t) (var) ^ __pointer_chk_guard)
380# endif
381# define PTR_DEMANGLE(var) PTR_MANGLE(var)
382#endif /* ASSEMBLER */
383

Warning: That file was not part of the compilation database. It may have many parsing errors.