Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e6f2eb

Browse files
committed
syscalls: use gperf for lookup
use gperf to generate a perfect hash to lookup syscall names. It improves significantly the complexity for seccomp_syscall_resolve_name.* since it replaces the expensive strcmp for each syscall in the database, with a lookup table. The complexity for syscall_resolve_num is not changed and it uses the linear search, that is anyway less expensive than seccomp_syscall_resolve_name.* as it uses an index for comparison instead of doing a string comparison. On my machine, calling 1000 seccomp_syscall_resolve_name_arch and seccomp_syscall_resolve_num_arch over the entire syscalls DB passed from ~0.45 sec to ~0.06s. Closes: #207 Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 38f04da commit 5e6f2eb

27 files changed

+890
-8140
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ addons:
3232
- valgrind
3333
- clang
3434
- lcov
35+
- gperf
3536

3637
env:
3738
global:

configure.ac

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ AC_DEFINE_UNQUOTED([ENABLE_PYTHON],
119119
[$(test "$enable_python" = yes && echo 1 || echo 0)],
120120
[Python bindings build flag.])
121121

122+
AC_CHECK_TOOL(GPERF, gperf)
123+
if test -z "$GPERF"; then
124+
AC_MSG_ERROR([please install gperf])
125+
fi
126+
122127
dnl ####
123128
dnl coverity checks
124129
dnl ####

src/Makefile.am

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,21 @@ SOURCES_ALL = \
3131
hash.h hash.c \
3232
db.h db.c \
3333
arch.c arch.h \
34-
arch-x86.h arch-x86.c arch-x86-syscalls.c \
35-
arch-x86_64.h arch-x86_64.c arch-x86_64-syscalls.c \
36-
arch-x32.h arch-x32.c arch-x32-syscalls.c \
37-
arch-arm.h arch-arm.c arch-arm-syscalls.c \
38-
arch-aarch64.h arch-aarch64.c arch-aarch64-syscalls.c \
39-
arch-mips.h arch-mips.c arch-mips-syscalls.c \
40-
arch-mips64.h arch-mips64.c arch-mips64-syscalls.c \
41-
arch-mips64n32.h arch-mips64n32.c arch-mips64n32-syscalls.c \
42-
arch-parisc.h arch-parisc.c arch-parisc64.c arch-parisc-syscalls.c \
43-
arch-ppc.h arch-ppc.c arch-ppc-syscalls.c \
44-
arch-ppc64.h arch-ppc64.c arch-ppc64-syscalls.c \
45-
arch-riscv64.h arch-riscv64.c arch-riscv64-syscalls.c \
46-
arch-s390.h arch-s390.c arch-s390-syscalls.c \
47-
arch-s390x.h arch-s390x.c arch-s390x-syscalls.c
34+
arch-x86.h arch-x86.c \
35+
arch-x86_64.h arch-x86_64.c \
36+
arch-x32.h arch-x32.c \
37+
arch-arm.h arch-arm.c \
38+
arch-aarch64.h arch-aarch64.c \
39+
arch-mips.h arch-mips.c \
40+
arch-mips64.h arch-mips64.c \
41+
arch-mips64n32.h arch-mips64n32.c \
42+
arch-parisc.h arch-parisc.c arch-parisc64.c \
43+
arch-ppc.h arch-ppc.c \
44+
arch-ppc64.h arch-ppc64.c \
45+
arch-riscv64.h arch-riscv64.c \
46+
arch-s390.h arch-s390.c \
47+
arch-s390x.h arch-s390x.c\
48+
syscalls.c syscalls.perf.c
4849

4950
EXTRA_DIST = arch-syscall-validate
5051

@@ -68,5 +69,14 @@ libseccomp_la_CFLAGS = ${AM_CFLAGS} ${CODE_COVERAGE_CFLAGS} ${CFLAGS} \
6869
libseccomp_la_LDFLAGS = ${AM_LDFLAGS} ${CODE_COVERAGE_LDFLAGS} ${LDFLAGS} \
6970
-version-number ${VERSION_MAJOR}:${VERSION_MINOR}:${VERSION_MICRO}
7071

72+
EXTRA_DIST += syscalls.perf.c syscalls.perf
73+
CLEANFILES = syscalls.perf.c syscalls.perf
74+
75+
syscalls.perf: syscalls.csv syscalls.perf.template
76+
${AM_V_GEN} ${srcdir}/generate_syscalls_perf.sh ${srcdir}/syscalls.csv ${srcdir}/syscalls.perf.template
77+
78+
syscalls.perf.c: syscalls.perf
79+
${GPERF} -m 100 --null-strings --pic -tCEG -T -S1 $< > $@
80+
7181
check-build:
7282
${MAKE} ${AM_MAKEFLAGS} ${check_PROGRAMS}

0 commit comments

Comments
 (0)