Add MAP_SYNC from Linux 4.15.
[glibc.git] / sysdeps / unix / make-syscalls.sh
blob874ad691cd34f7489bef0c8b602b18871a71ee15
1 #!/bin/sh
3 # Usage: make-syscalls.sh ../sysdeps/unix/common
4 # Expects $sysdirs in environment.
6 ##############################################################################
8 # This script is used to process the syscall data encoded in the various
9 # syscalls.list files to produce thin assembly syscall wrappers around the
10 # appropriate OS syscall. See syscall-template.s for more details on the
11 # actual wrapper.
13 # Syscall Signature Prefixes:
15 # E: errno and return value are not set by the call
16 # V: errno is not set, but errno or zero (success) is returned from the call
18 # Syscall Signature Key Letters:
20 # a: unchecked address (e.g., 1st arg to mmap)
21 # b: non-NULL buffer (e.g., 2nd arg to read; return value from mmap)
22 # B: optionally-NULL buffer (e.g., 4th arg to getsockopt)
23 # f: buffer of 2 ints (e.g., 4th arg to socketpair)
24 # F: 3rd arg to fcntl
25 # i: scalar (any signedness & size: int, long, long long, enum, whatever)
26 # I: 3rd arg to ioctl
27 # n: scalar buffer length (e.g., 3rd arg to read)
28 # N: pointer to value/return scalar buffer length (e.g., 6th arg to recvfrom)
29 # p: non-NULL pointer to typed object (e.g., any non-void* arg)
30 # P: optionally-NULL pointer to typed object (e.g., 2nd argument to gettimeofday)
31 # s: non-NULL string (e.g., 1st arg to open)
32 # S: optionally-NULL string (e.g., 1st arg to acct)
33 # v: vararg scalar (e.g., optional 3rd arg to open)
34 # V: byte-per-page vector (3rd arg to mincore)
35 # W: wait status, optionally-NULL pointer to int (e.g., 2nd arg of wait4)
38 ##############################################################################
40 thisdir=$1; shift
42 echo ''
43 echo \#### DIRECTORY = $thisdir
44 # Check each sysdep dir with higher priority than this one,
45 # and remove from $calls all the functions found in other dirs.
46 # Punt when we reach the directory defining these syscalls.
47 sysdirs=`for dir in $sysdirs; do
48 test $dir = $thisdir && break; echo $dir; done`
49 echo \#### SYSDIRS = $sysdirs
51 # Get the list of system calls for this directory.
52 calls=`sed 's/#.*$//
53 /^[ ]*$/d' $thisdir/syscalls.list`
55 calls=`echo "$calls" |
56 while read file caller rest; do
57 # Remove each syscall that is implemented by a file in $dir.
58 # If a syscall specified a "caller", then only compile that syscall
59 # if the caller function is also implemented in this directory.
60 srcfile=-;
61 for dir in $sysdirs; do
62 { test -f $dir/$file.c && srcfile=$dir/$file.c; } ||
63 { test -f $dir/$file.S && srcfile=$dir/$file.S; } ||
64 { test x$caller != x- &&
65 { { test -f $dir/$caller.c && srcfile=$dir/$caller.c; } ||
66 { test -f $dir/$caller.S && srcfile=$dir/$caller.S; }; }; } && break;
67 done;
68 echo $file $srcfile $caller $rest;
69 done`
71 # Any calls left?
72 test -n "$calls" || exit 0
74 # This uses variables $weak, $strong, and $any_versioned.
75 emit_weak_aliases()
77 # A shortcoming in the current gas is that it will only allow one
78 # version-alias per symbol. So we create new strong aliases as needed.
79 vcount=""
81 # We use the <shlib-compat.h> macros to generate the versioned aliases
82 # so that the version sets can be mapped to the configuration's
83 # minimum version set as per shlib-versions DEFAULT lines. If an
84 # entry point is specified in the form NAME@VERSION:OBSOLETED, a
85 # SHLIB_COMPAT conditional is generated.
86 if [ $any_versioned = t ]; then
87 echo " echo '#include <shlib-compat.h>'; \\"
90 for name in $weak; do
91 case $name in
92 *@@*)
93 base=`echo $name | sed 's/@@.*//'`
94 ver=`echo $name | sed 's/.*@@//;s/\./_/g'`
95 echo " echo '#if IS_IN (libc)'; \\"
96 if test -z "$vcount" ; then
97 source=$strong
98 vcount=1
99 else
100 source="${strong}_${vcount}"
101 vcount=`expr $vcount + 1`
102 echo " echo 'strong_alias ($strong, $source)'; \\"
104 echo " echo 'versioned_symbol (libc, $source, $base, $ver)'; \\"
105 echo " echo '#else'; \\"
106 echo " echo 'strong_alias ($strong, $base)'; \\"
107 echo " echo '#endif'; \\"
109 *@*)
110 base=`echo $name | sed 's/@.*//'`
111 ver=`echo $name | sed 's/.*@//;s/\./_/g'`
112 case $ver in
113 *:*)
114 compat_ver=${ver#*:}
115 ver=${ver%%:*}
116 compat_cond=" && SHLIB_COMPAT (libc, $ver, $compat_ver)"
119 compat_cond=
121 esac
122 echo " echo '#if defined SHARED && IS_IN (libc)$compat_cond'; \\"
123 if test -z "$vcount" ; then
124 source=$strong
125 vcount=1
126 else
127 source="${strong}_${vcount}"
128 vcount=`expr $vcount + 1`
129 echo " echo 'strong_alias ($strong, $source)'; \\"
131 echo " echo 'compat_symbol (libc, $source, $base, $ver)'; \\"
132 echo " echo '#endif'; \\"
135 name=`echo $name | sed 's/.//'`
136 echo " echo 'strong_alias ($strong, $name)'; \\"
137 echo " echo 'hidden_def ($name)'; \\"
140 echo " echo 'weak_alias ($strong, $name)'; \\"
141 echo " echo 'hidden_weak ($name)'; \\"
143 esac
144 done
148 # Emit rules to compile the syscalls remaining in $calls.
149 echo "$calls" |
150 while read file srcfile caller syscall args strong weak; do
152 vdso_syscall=
153 case x"$syscall" in
154 *:*@*)
155 vdso_syscall="${syscall#*:}"
156 syscall="${syscall%:*}"
158 esac
160 case x"$syscall" in
161 x-) callnum=_ ;;
163 # Figure out if $syscall is defined with a number in syscall.h.
164 callnum=-
165 eval `{ echo "#include <sysdep.h>";
166 echo "callnum=SYS_ify ($syscall)"; } |
167 $asm_CPP -D__OPTIMIZE__ - |
168 sed -n -e "/^callnum=.*$syscall/d" \
169 -e "/^\(callnum=\)[ ]*\(.*\)/s//\1'\2'/p"`
171 esac
173 noerrno=0
174 errval=0
175 case $args in
176 E*) noerrno=1; args=`echo $args | sed 's/E:\?//'`;;
177 V*) errval=1; args=`echo $args | sed 's/V:\?//'`;;
178 esac
180 # Derive the number of arguments from the argument signature
181 case $args in
182 [0-9]) nargs=$args;;
183 ?:) nargs=0;;
184 ?:?) nargs=1;;
185 ?:??) nargs=2;;
186 ?:???) nargs=3;;
187 ?:????) nargs=4;;
188 ?:?????) nargs=5;;
189 ?:??????) nargs=6;;
190 ?:???????) nargs=7;;
191 ?:????????) nargs=8;;
192 ?:?????????) nargs=9;;
193 esac
195 # Make sure only the first syscall rule is used, if multiple dirs
196 # define the same syscall.
197 echo ''
198 echo "#### CALL=$file NUMBER=$callnum ARGS=$args SOURCE=$srcfile"
200 # If there are versioned aliases the entry is only generated for the
201 # shared library, unless it is a default version.
202 any_versioned=f
203 shared_only=f
204 case $weak in
205 *@@*) any_versioned=t ;;
206 *@*) any_versioned=t shared_only=t ;;
207 esac
209 case x$srcfile"$callnum" in
210 x--)
211 # Undefined callnum for an extra syscall.
212 if [ x$caller != x- ]; then
213 if [ $noerrno != 0 ]; then
214 echo >&2 "$0: no number for $fileno, no-error syscall ($strong $weak)"
215 exit 2
217 echo "unix-stub-syscalls += $strong $weak"
220 x*-) ;; ### Do nothing for undefined callnum
221 x-*)
222 echo "ifeq (,\$(filter $file,\$(unix-syscalls)))"
224 if test $shared_only = t; then
225 # The versioned symbols are only in the shared library.
226 echo "ifneq (,\$(filter .os,\$(object-suffixes)))"
228 # Accumulate the list of syscall files for this directory.
229 echo "unix-syscalls += $file"
230 test x$caller = x- || echo "unix-extra-syscalls += $file"
232 # Emit a compilation rule for this syscall.
233 if test $shared_only = t; then
234 # The versioned symbols are only in the shared library.
235 echo "shared-only-routines += $file"
236 test -n "$vdso_syscall" || echo "\$(objpfx)${file}.os: \\"
237 else
238 object_suffixes='$(object-suffixes)'
239 test -z "$vdso_syscall" || object_suffixes='$(object-suffixes-noshared)'
240 echo "\
241 \$(foreach p,\$(sysd-rules-targets),\
242 \$(foreach o,${object_suffixes},\$(objpfx)\$(patsubst %,\$p,$file)\$o)): \\"
245 echo " \$(..)sysdeps/unix/make-syscalls.sh"
246 case x"$callnum" in
248 echo "\
249 \$(make-target-directory)
250 (echo '/* Dummy module requested by syscalls.list */'; \\"
253 echo "\
254 \$(make-target-directory)
255 (echo '#define SYSCALL_NAME $syscall'; \\
256 echo '#define SYSCALL_NARGS $nargs'; \\
257 echo '#define SYSCALL_SYMBOL $strong'; \\
258 echo '#define SYSCALL_NOERRNO $noerrno'; \\
259 echo '#define SYSCALL_ERRVAL $errval'; \\
260 echo '#include <syscall-template.S>'; \\"
262 esac
264 # Append any weak aliases or versions defined for this syscall function.
265 emit_weak_aliases
267 # And finally, pipe this all into the compiler.
268 echo ' ) | $(compile-syscall) '"\
269 \$(foreach p,\$(patsubst %$file,%,\$(basename \$(@F))),\$(\$(p)CPPFLAGS))"
271 if test -n "$vdso_syscall"; then
272 # In the shared library, we're going to emit an IFUNC using a vDSO function.
273 # $vdso_syscall looks like "name@KERNEL_X.Y" where "name" is the symbol
274 # name in the vDSO and KERNEL_X.Y is its symbol version.
275 vdso_symbol="${vdso_syscall%@*}"
276 vdso_symver="${vdso_syscall#*@}"
277 vdso_symver=`echo "$vdso_symver" | sed 's/\./_/g'`
278 cat <<EOF
280 \$(foreach p,\$(sysd-rules-targets),\$(objpfx)\$(patsubst %,\$p,$file).os): \\
281 \$(..)sysdeps/unix/make-syscalls.sh
282 \$(make-target-directory)
283 (echo '#define ${strong} __redirect_${strong}'; \\
284 echo '#include <dl-vdso.h>'; \\
285 echo '#undef ${strong}'; \\
286 echo '#define vdso_ifunc_init() \\'; \\
287 echo ' PREPARE_VERSION_KNOWN (symver, ${vdso_symver})'; \\
288 echo '__ifunc (__redirect_${strong}, ${strong},'; \\
289 echo ' _dl_vdso_vsym ("${vdso_symbol}", &symver), void,'; \\
290 echo ' vdso_ifunc_init)'; \\
292 # This is doing "hidden_def (${strong})", but the compiler
293 # doesn't know that we've defined ${strong} in the same file, so
294 # we can't do it the normal way.
295 cat <<EOF
296 echo 'asm (".globl __GI_${strong}");'; \\
297 echo 'asm ("__GI_${strong} = ${strong}");'; \\
299 emit_weak_aliases
300 cat <<EOF
301 ) | \$(compile-stdin.c) \
302 \$(foreach p,\$(patsubst %$file,%,\$(basename \$(@F))),\$(\$(p)CPPFLAGS))
306 if test $shared_only = t; then
307 # The versioned symbols are only in the shared library.
308 echo endif
311 echo endif
313 esac
315 done