NEWS: Add advisories.
[glibc.git] / sysdeps / unix / syscall-template.S
blob49b9a7943fa82391c37bdcee9c6fd6093d63b450
1 /* Assembly code template for system call stubs.
2    Copyright (C) 2009-2024 Free Software Foundation, Inc.
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 /* The real guts of this work are in the macros defined in the
20    machine- and kernel-specific sysdep.h header file.  Cancellable syscalls
21    should be implemented using C implementation with SYSCALL_CANCEL macro.
23    Each system call's object is built by a rule in sysd-syscalls
24    generated by make-syscalls.sh that #include's this file after
25    defining a few macros:
26         SYSCALL_NAME            syscall name
27         SYSCALL_NARGS           number of arguments this call takes
28         SYSCALL_ULONG_ARG_1     the first unsigned long int argument this
29                                 call takes.  0 means that there are no
30                                 unsigned long int arguments.
31         SYSCALL_ULONG_ARG_2     the second unsigned long int argument this
32                                 call takes.  0 means that there is at most
33                                 one unsigned long int argument.
34         SYSCALL_SYMBOL          primary symbol name
35         SYSCALL_NOERRNO         1 to define a no-errno version (see below)
36         SYSCALL_ERRVAL          1 to define an error-value version (see below)
38    We used to simply pipe the correct three lines below through cpp into
39    the assembler.  The main reason to have this file instead is so that
40    stub objects can be assembled with -g and get source line information
41    that leads a user back to a source file and these fine comments.  The
42    average user otherwise has a hard time knowing which "syscall-like"
43    functions in libc are plain stubs and which have nontrivial C wrappers.
44    Some versions of the "plain" stub generation macros are more than a few
45    instructions long and the untrained eye might not distinguish them from
46    some compiled code that inexplicably lacks source line information.  */
48 #include <sysdep.h>
50 /* This indirection is needed so that SYMBOL gets macro-expanded.  */
51 #define syscall_hidden_def(SYMBOL)              hidden_def (SYMBOL)
53 /* If PSEUDOS_HAVE_ULONG_INDICES is defined, PSEUDO and T_PSEUDO macros
54    have 2 extra arguments for unsigned long int arguments:
55      Extra argument 1: Position of the first unsigned long int argument.
56      Extra argument 2: Position of the second unsigned long int argument.
57  */
58 #ifndef PSEUDOS_HAVE_ULONG_INDICES
59 # undef SYSCALL_ULONG_ARG_1
60 # define SYSCALL_ULONG_ARG_1 0
61 #endif
63 #if SYSCALL_ULONG_ARG_1
64 # define T_PSEUDO(SYMBOL, NAME, N, U1, U2) \
65   PSEUDO (SYMBOL, NAME, N, U1, U2)
66 # define T_PSEUDO_NOERRNO(SYMBOL, NAME, N, U1, U2) \
67   PSEUDO_NOERRNO (SYMBOL, NAME, N, U1, U2)
68 # define T_PSEUDO_ERRVAL(SYMBOL, NAME, N, U1, U2) \
69   PSEUDO_ERRVAL (SYMBOL, NAME, N, U1, U2)
70 #else
71 # define T_PSEUDO(SYMBOL, NAME, N) \
72   PSEUDO (SYMBOL, NAME, N)
73 # define T_PSEUDO_NOERRNO(SYMBOL, NAME, N) \
74   PSEUDO_NOERRNO (SYMBOL, NAME, N)
75 # define T_PSEUDO_ERRVAL(SYMBOL, NAME, N) \
76   PSEUDO_ERRVAL (SYMBOL, NAME, N)
77 #endif
78 #define T_PSEUDO_END(SYMBOL)                    PSEUDO_END (SYMBOL)
79 #define T_PSEUDO_END_NOERRNO(SYMBOL)            PSEUDO_END_NOERRNO (SYMBOL)
80 #define T_PSEUDO_END_ERRVAL(SYMBOL)             PSEUDO_END_ERRVAL (SYMBOL)
82 #if SYSCALL_NOERRNO
84 /* This kind of system call stub never returns an error.
85    We return the return value register to the caller unexamined.  */
87 # if SYSCALL_ULONG_ARG_1
88 T_PSEUDO_NOERRNO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS,
89                   SYSCALL_ULONG_ARG_1, SYSCALL_ULONG_ARG_2)
90 # else
91 T_PSEUDO_NOERRNO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
92 # endif
93         ret_NOERRNO
94 T_PSEUDO_END_NOERRNO (SYSCALL_SYMBOL)
96 #elif SYSCALL_ERRVAL
98 /* This kind of system call stub returns the errno code as its return
99    value, or zero for success.  We may massage the kernel's return value
100    to meet that ABI, but we never set errno here.  */
102 # if SYSCALL_ULONG_ARG_1
103 T_PSEUDO_ERRVAL (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS,
104                  SYSCALL_ULONG_ARG_1, SYSCALL_ULONG_ARG_2)
105 # else
106 T_PSEUDO_ERRVAL (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
107 # endif
108         ret_ERRVAL
109 T_PSEUDO_END_ERRVAL (SYSCALL_SYMBOL)
111 #else
113 /* This is a "normal" system call stub: if there is an error,
114    it returns -1 and sets errno.  */
116 # if SYSCALL_ULONG_ARG_1
117 T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS,
118           SYSCALL_ULONG_ARG_1, SYSCALL_ULONG_ARG_2)
119 # else
120 T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
121 # endif
122         ret
123 T_PSEUDO_END (SYSCALL_SYMBOL)
125 #endif
127 syscall_hidden_def (SYSCALL_SYMBOL)