1#!/bin/bash 2# Consistency checks for the system call list 3# Copyright (C) 2017-2022 Free Software Foundation, Inc. 4# This file is part of the GNU C Library. 5# 6# The GNU C Library is free software; you can redistribute it and/or 7# modify it under the terms of the GNU Lesser General Public 8# License as published by the Free Software Foundation; either 9# version 2.1 of the License, or (at your option) any later version. 10# 11# The GNU C Library is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14# Lesser General Public License for more details. 15# 16# You should have received a copy of the GNU Lesser General Public 17# License along with the GNU C Library; if not, see 18# <https://www.gnu.org/licenses/>. 19 20export LC_ALL=C 21set -e 22set -o pipefail 23 24if test $# != 4; then 25 echo "error: wrong number of arguments: $#" 26 exit 1 27fi 28 29macros="$1" 30list_nr="$2" 31list_sys="$3" 32GAWK="$4" 33 34linux_version="$("$GAWK" \ 35 '/#define LINUX_VERSION_CODE / {print $3}' < "$macros")" 36glibc_linux_version="$("$GAWK" \ 37 '/#define __GLIBC_LINUX_VERSION_CODE / {print $3}' < "$macros")" 38 39echo "info: LINUX_VERSION_CODE: $linux_version" 40echo "info: __GLIBC_LINUX_VERSION_CODE: $glibc_linux_version" 41# Ignore the subrelease in the comparison. 42if test $(expr "$glibc_linux_version" / 256) \ 43 -lt $(expr "$linux_version" / 256); then 44 echo "info: The kernel major/minor version is newer than the glibc version" 45 kernel_newer=true 46else 47 kernel_newer=false 48fi 49echo 50 51errors=0 52 53# Use getpid as a system call which is expected to be always defined. 54# alpha uses getxpid instead, so it is permitted as an alternative. 55if ! grep -E -q '^getx?pid$' -- "$list_nr"; then 56 echo "error: __NR_getpid not defined" 57 errors=1 58fi 59if ! grep -E -q '^getx?pid$' -- "$list_sys"; then 60 echo "error: SYS_getpid not defined" 61 errors=1 62fi 63 64comm_1="$(mktemp)" 65comm_2="$(mktemp)" 66comm_result="$(mktemp)" 67cleanup () { 68 rm -f -- "$comm_1" "$comm_2" "$comm_result" 69} 70trap cleanup 0 71 72sort -o "$comm_1" -- "$list_nr" 73sort -o "$comm_2" -- "$list_sys" 74 75# Check for missing SYS_* macros. 76comm --check-order -2 -3 -- "$comm_1" "$comm_2" > "$comm_result" 77if test -s "$comm_result"; then 78 echo "error: These system calls need to be added to syscall-names.list:" 79 cat -- "$comm_result" 80 # This is only an error if our version is older than the kernel 81 # version because we cannot predict future kernel development. 82 if $kernel_newer; then 83 echo 84 echo "warning: This error has been ignored because the glibc" 85 echo "warning: system call list is older than the kernel version." 86 else 87 errors=1 88 fi 89fi 90 91# Check for additional SYS_* macros. 92comm --check-order -1 -3 -- "$comm_1" "$comm_2" > "$comm_result" 93if test -s "$comm_result"; then 94 echo "error: The following system calls have unexpected SYS_* macros:" 95 cat -- "$comm_result" 96 errors=1 97fi 98 99exit "$errors" 100