| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# |
| 4 |
# libseccomp syscall build-time checking script |
| 5 |
# |
| 6 |
# Copyright (c) 2021 Microsoft Corporation. <[email protected]> |
| 7 |
# |
| 8 |
# Author: Paul Moore <[email protected]> |
| 9 |
# |
| 10 |
|
| 11 |
# |
| 12 |
# This library is free software; you can redistribute it and/or modify it |
| 13 |
# under the terms of version 2.1 of the GNU Lesser General Public License as |
| 14 |
# published by the Free Software Foundation. |
| 15 |
# |
| 16 |
# This library is distributed in the hope that it will be useful, but WITHOUT |
| 17 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 18 |
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 19 |
# for more details. |
| 20 |
# |
| 21 |
# You should have received a copy of the GNU Lesser General Public License |
| 22 |
# along with this library; if not, see <http://www.gnu.org/licenses>. |
| 23 |
# |
| 24 |
|
| 25 |
# Based on an idea from GNU coreutils |
| 26 |
abs_topsrcdir="$(unset CDPATH; cd $(dirname $0)/.. && pwd)" |
| 27 |
|
| 28 |
SYSCALL_CSV="$abs_topsrcdir/src/syscalls.csv" |
| 29 |
SYSCALL_HDR="$abs_topsrcdir/include/seccomp-syscalls.h" |
| 30 |
|
| 31 |
function check_snr() { |
| 32 |
(export LC_ALL=C; diff \ |
| 33 |
--label "CSV ($SYSCALL_CSV)" --label "HDR ($SYSCALL_HDR)" -u \ |
| 34 |
<(tail -n+2 $SYSCALL_CSV | cut -d',' -f1 | sort -u) \ |
| 35 |
<(grep __SNR_ $SYSCALL_HDR | awk '{ print $2 }' | \ |
| 36 |
sed -e 's/^__SNR_//' | sort -u)) |
| 37 |
return $? |
| 38 |
} |
| 39 |
|
| 40 |
function check_pnr() { |
| 41 |
# NOTE: we don't care if we have __PNR_ define that isn't needed, we |
| 42 |
# likely want to preserve those values so they aren't mistakenly |
| 43 |
# reused by a new __PNR_ in the future |
| 44 |
(export LC_ALL=C; diff \ |
| 45 |
<(tail -n+2 $SYSCALL_CSV | grep "PNR" | cut -d',' -f1 | \ |
| 46 |
sort -u) \ |
| 47 |
<(grep "#define __PNR_" $SYSCALL_HDR | awk '{ print $2 }' | \ |
| 48 |
sed -e 's/^__PNR_//' | sort -u) | \ |
| 49 |
grep "^<") |
| 50 |
[[ $? -eq 1 ]] && return 0 || return 1 |
| 51 |
} |
| 52 |
|
| 53 |
rc=0 |
| 54 |
|
| 55 |
echo ">>> CHECKING FOR MISSING __SNR_syscall VALUES" |
| 56 |
check_snr |
| 57 |
rc=$(( $rc + $? )) |
| 58 |
|
| 59 |
echo ">>> CHECKING FOR MISSING __PNR_syscall VALUES" |
| 60 |
check_pnr |
| 61 |
rc=$(( $rc + $? )) |
| 62 |
|
| 63 |
exit $rc |