summaryrefslogtreecommitdiff
path: root/src/arch-syscall-check
blob: 9c7fd4193a762ab0847b0f7c4a6d515051a0623d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash

#
# libseccomp syscall build-time checking script
#
# Copyright (c) 2021 Microsoft Corporation. <paulmoore@microsoft.com>
#
# Author: Paul Moore <paul@paul-moore.com>
#

#
# This library is free software; you can redistribute it and/or modify it
# under the terms of version 2.1 of the GNU Lesser General Public License as
# published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, see <http://www.gnu.org/licenses>.
#

# Based on an idea from GNU coreutils
abs_topsrcdir="$(unset CDPATH; cd $(dirname $0)/.. && pwd)"

SYSCALL_CSV="$abs_topsrcdir/src/syscalls.csv"
SYSCALL_HDR="$abs_topsrcdir/include/seccomp-syscalls.h"

function check_snr() {
	(export LC_ALL=C; diff \
		--label "CSV ($SYSCALL_CSV)" --label "HDR ($SYSCALL_HDR)" -u \
		<(tail -n+2 $SYSCALL_CSV | cut -d',' -f1 | sort -u) \
		<(grep __SNR_ $SYSCALL_HDR | awk '{ print $2 }' | \
		  sed -e 's/^__SNR_//' | sort -u))
	return $?
}

function check_pnr() {
	# NOTE: we don't care if we have __PNR_ define that isn't needed, we
	#       likely want to preserve those values so they aren't mistakenly
	#       reused by a new __PNR_ in the future
	(export LC_ALL=C; diff \
		<(tail -n+2 $SYSCALL_CSV | grep "PNR" | cut -d',' -f1 | \
		  sort -u) \
		<(grep "#define __PNR_" $SYSCALL_HDR | awk '{ print $2 }' | \
		  sed -e 's/^__PNR_//' | sort -u) | \
		grep "^<")
	[[ $? -eq 1 ]] && return 0 || return 1
}

rc=0

echo ">>> CHECKING FOR MISSING __SNR_syscall VALUES"
check_snr
rc=$(( $rc + $? ))

echo ">>> CHECKING FOR MISSING __PNR_syscall VALUES"
check_pnr
rc=$(( $rc + $? ))

exit $rc