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
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)
25 # i: scalar (any signedness & size: int, long, long long, enum, whatever)
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 ##############################################################################
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.
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.
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;
68 echo $file $srcfile $caller $rest;
72 test -n "$calls" ||
exit 0
74 # This uses variables $weak, $strong, and $any_versioned.
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.
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>'; \\"
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
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'; \\"
110 base
=`echo $name | sed 's/@.*//'`
111 ver
=`echo $name | sed 's/.*@//;s/\./_/g'`
116 compat_cond
=" && SHLIB_COMPAT (libc, $ver, $compat_ver)"
122 echo " echo '#if defined SHARED && IS_IN (libc)$compat_cond'; \\"
123 if test -z "$vcount" ; then
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)'; \\"
148 # Emit rules to compile the syscalls remaining in $calls.
150 while read file srcfile caller syscall args strong weak
; do
155 vdso_syscall
="${syscall#*:}"
156 syscall
="${syscall%:*}"
163 # Figure out if $syscall is defined with a number in syscall.h.
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"`
176 E
*) noerrno
=1; args
=`echo $args | sed 's/E:\?//'`;;
177 V
*) errval
=1; args
=`echo $args | sed 's/V:\?//'`;;
180 # Derive the number of arguments from the argument signature
191 ?
:????????
) nargs
=8;;
192 ?
:?????????
) nargs
=9;;
195 # Make sure only the first syscall rule is used, if multiple dirs
196 # define the same syscall.
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.
205 *@@
*) any_versioned
=t
;;
206 *@
*) any_versioned
=t shared_only
=t
;;
209 case x
$srcfile"$callnum" in
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)"
217 echo "unix-stub-syscalls += $strong $weak"
220 x
*-) ;; ### Do nothing for undefined callnum
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: \\"
238 object_suffixes
='$(object-suffixes)'
239 test -z "$vdso_syscall" || object_suffixes
='$(object-suffixes-noshared)'
241 \$(foreach p,\$(sysd-rules-targets),\
242 \$(foreach o,${object_suffixes},\$(objpfx)\$(patsubst %,\$p,$file)\$o)): \\"
245 echo " \$(..)sysdeps/unix/make-syscalls.sh"
249 \$(make-target-directory)
250 (echo '/* Dummy module requested by syscalls.list */'; \\"
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>'; \\"
264 # Append any weak aliases or versions defined for this syscall function.
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'`
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.
296 echo 'asm (".globl __GI_${strong}");'; \\
297 echo 'asm ("__GI_${strong} = ${strong}");'; \\
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.