Skip to content

Commit

Permalink
Merge ab9e774 into 78497a5
Browse files Browse the repository at this point in the history
  • Loading branch information
varqox committed May 5, 2019
2 parents 78497a5 + ab9e774 commit 9c7518a
Show file tree
Hide file tree
Showing 18 changed files with 340 additions and 430 deletions.
2 changes: 2 additions & 0 deletions src/.gitignore
@@ -1,3 +1,5 @@
libseccomp.a
arch-syscall-check
arch-syscall-dump
arch-*-syscall-hashmap-printer
arch-*-syscall-hashmap.c
25 changes: 25 additions & 0 deletions src/Makefile.am
Expand Up @@ -31,6 +31,7 @@ SOURCES_ALL = \
hash.h hash.c \
db.h db.c \
arch.c arch.h \
syscall-hashmap.h syscall-hashmap.c \
arch-x86.h arch-x86.c arch-x86-syscalls.c \
arch-x86_64.h arch-x86_64.c arch-x86_64-syscalls.c \
arch-x32.h arch-x32.c arch-x32-syscalls.c \
Expand Down Expand Up @@ -69,3 +70,27 @@ libseccomp_la_LDFLAGS = ${AM_LDFLAGS} ${CODE_COVERAGE_LDFLAGS} ${LDFLAGS} \

check-build:
${MAKE} ${AM_MAKEFLAGS} ${check_PROGRAMS}

FORCE: ;

arch-x86-syscalls.c: arch-x86-syscall-hashmap.c
arch-x86_64-syscalls.c: arch-x86_64-syscall-hashmap.c
arch-x32-syscalls.c: arch-x32-syscall-hashmap.c
arch-arm-syscalls.c: arch-arm-syscall-hashmap.c
arch-aarch64-syscalls.c: arch-aarch64-syscall-hashmap.c
arch-mips-syscalls.c: arch-mips-syscall-hashmap.c
arch-mips64-syscalls.c: arch-mips64-syscall-hashmap.c
arch-mips64n32-syscalls.c: arch-mips64n32-syscall-hashmap.c
arch-parisc-syscalls.c: arch-parisc-syscall-hashmap.c
arch-ppc-syscalls.c: arch-ppc-syscall-hashmap.c
arch-ppc64-syscalls.c: arch-ppc64-syscall-hashmap.c
arch-s390-syscalls.c: arch-s390-syscall-hashmap.c
arch-s390x-syscalls.c: arch-s390x-syscall-hashmap.c

arch-%-syscall-hashmap.c: syscall-hashmap-template.c FORCE
if [ "$@" -nt "arch-$*-syscalls.c" ]; then exit 0; fi; \
(echo '#include "arch-$*-syscalls.c"' && cat syscall-hashmap-template.c) | $(COMPILE) -x c - -o 'arch-$*-syscall-hashmap-printer' -DGENERATING_HASHMAP -DARCH='$*' && \
'./arch-$*-syscall-hashmap-printer' > $@

clean-local:
${RM} -rf arch-*-syscall-hashmap.c arch-*-syscall-hashmap-printer
19 changes: 9 additions & 10 deletions src/arch-aarch64-syscalls.c
Expand Up @@ -25,6 +25,7 @@

#include "arch.h"
#include "arch-aarch64.h"
#include "syscall-hashmap.h"

/* NOTE: based on Linux 4.15-rc7 */
const struct arch_syscall_def aarch64_syscall_table[] = { \
Expand Down Expand Up @@ -465,6 +466,12 @@ const struct arch_syscall_def aarch64_syscall_table[] = { \
{ NULL, __NR_SCMP_ERROR },
};

const struct syscall_hashmap_entry aarch64_syscall_hashmap[] = {
#ifndef GENERATING_HASHMAP
#include "arch-aarch64-syscall-hashmap.c"
#endif
};

/**
* Resolve a syscall name to a number
* @param name the syscall name
Expand All @@ -476,16 +483,8 @@ const struct arch_syscall_def aarch64_syscall_table[] = { \
*/
int aarch64_syscall_resolve_name(const char *name)
{
unsigned int iter;
const struct arch_syscall_def *table = aarch64_syscall_table;

/* XXX - plenty of room for future improvement here */
for (iter = 0; table[iter].name != NULL; iter++) {
if (strcmp(name, table[iter].name) == 0)
return table[iter].num;
}

return __NR_SCMP_ERROR;
return syscall_hashmap_resolve(aarch64_syscall_hashmap,
sizeof(aarch64_syscall_hashmap) / sizeof(*aarch64_syscall_hashmap), name);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions src/arch-arm-syscalls.c
Expand Up @@ -25,6 +25,7 @@

#include "arch.h"
#include "arch-arm.h"
#include "syscall-hashmap.h"

#define __SCMP_NR_OABI_SYSCALL_BASE 0x900000
#define __SCMP_ARM_NR_BASE 0x0f0000
Expand Down Expand Up @@ -477,6 +478,12 @@ const struct arch_syscall_def arm_syscall_table[] = { \
{ NULL, __NR_SCMP_ERROR },
};

const struct syscall_hashmap_entry arm_syscall_hashmap[] = {
#ifndef GENERATING_HASHMAP
#include "arch-arm-syscall-hashmap.c"
#endif
};

/**
* Resolve a syscall name to a number
* @param name the syscall name
Expand All @@ -488,16 +495,8 @@ const struct arch_syscall_def arm_syscall_table[] = { \
*/
int arm_syscall_resolve_name(const char *name)
{
unsigned int iter;
const struct arch_syscall_def *table = arm_syscall_table;

/* XXX - plenty of room for future improvement here */
for (iter = 0; table[iter].name != NULL; iter++) {
if (strcmp(name, table[iter].name) == 0)
return table[iter].num;
}

return __NR_SCMP_ERROR;
return syscall_hashmap_resolve(arm_syscall_hashmap,
sizeof(arm_syscall_hashmap) / sizeof(*arm_syscall_hashmap), name);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions src/arch-mips-syscalls.c
Expand Up @@ -26,6 +26,7 @@

#include "arch.h"
#include "arch-mips.h"
#include "syscall-hashmap.h"

/* O32 ABI */
#define __SCMP_NR_BASE 4000
Expand Down Expand Up @@ -469,6 +470,12 @@ const struct arch_syscall_def mips_syscall_table[] = { \
{ NULL, __NR_SCMP_ERROR },
};

const struct syscall_hashmap_entry mips_syscall_hashmap[] = {
#ifndef GENERATING_HASHMAP
#include "arch-mips-syscall-hashmap.c"
#endif
};

/**
* Resolve a syscall name to a number
* @param name the syscall name
Expand All @@ -480,16 +487,8 @@ const struct arch_syscall_def mips_syscall_table[] = { \
*/
int mips_syscall_resolve_name(const char *name)
{
unsigned int iter;
const struct arch_syscall_def *table = mips_syscall_table;

/* XXX - plenty of room for future improvement here */
for (iter = 0; table[iter].name != NULL; iter++) {
if (strcmp(name, table[iter].name) == 0)
return table[iter].num;
}

return __NR_SCMP_ERROR;
return syscall_hashmap_resolve(mips_syscall_hashmap,
sizeof(mips_syscall_hashmap) / sizeof(*mips_syscall_hashmap), name);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions src/arch-mips64-syscalls.c
Expand Up @@ -26,6 +26,7 @@

#include "arch.h"
#include "arch-mips64.h"
#include "syscall-hashmap.h"

/* 64 ABI */
#define __SCMP_NR_BASE 5000
Expand Down Expand Up @@ -469,6 +470,12 @@ const struct arch_syscall_def mips64_syscall_table[] = { \
{ NULL, __NR_SCMP_ERROR },
};

const struct syscall_hashmap_entry mips64_syscall_hashmap[] = {
#ifndef GENERATING_HASHMAP
#include "arch-mips64-syscall-hashmap.c"
#endif
};

/**
* Resolve a syscall name to a number
* @param name the syscall name
Expand All @@ -480,16 +487,8 @@ const struct arch_syscall_def mips64_syscall_table[] = { \
*/
int mips64_syscall_resolve_name(const char *name)
{
unsigned int iter;
const struct arch_syscall_def *table = mips64_syscall_table;

/* XXX - plenty of room for future improvement here */
for (iter = 0; table[iter].name != NULL; iter++) {
if (strcmp(name, table[iter].name) == 0)
return table[iter].num;
}

return __NR_SCMP_ERROR;
return syscall_hashmap_resolve(mips64_syscall_hashmap,
sizeof(mips64_syscall_hashmap) / sizeof(*mips64_syscall_hashmap), name);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions src/arch-mips64n32-syscalls.c
Expand Up @@ -26,6 +26,7 @@

#include "arch.h"
#include "arch-mips64n32.h"
#include "syscall-hashmap.h"

/* N32 ABI */
#define __SCMP_NR_BASE 6000
Expand Down Expand Up @@ -469,6 +470,12 @@ const struct arch_syscall_def mips64n32_syscall_table[] = { \
{ NULL, __NR_SCMP_ERROR },
};

const struct syscall_hashmap_entry mips64n32_syscall_hashmap[] = {
#ifndef GENERATING_HASHMAP
#include "arch-mips64n32-syscall-hashmap.c"
#endif
};

/**
* Resolve a syscall name to a number
* @param name the syscall name
Expand All @@ -480,16 +487,8 @@ const struct arch_syscall_def mips64n32_syscall_table[] = { \
*/
int mips64n32_syscall_resolve_name(const char *name)
{
unsigned int iter;
const struct arch_syscall_def *table = mips64n32_syscall_table;

/* XXX - plenty of room for future improvement here */
for (iter = 0; table[iter].name != NULL; iter++) {
if (strcmp(name, table[iter].name) == 0)
return table[iter].num;
}

return __NR_SCMP_ERROR;
return syscall_hashmap_resolve(mips64n32_syscall_hashmap,
sizeof(mips64n32_syscall_hashmap) / sizeof(*mips64n32_syscall_hashmap), name);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions src/arch-parisc-syscalls.c
Expand Up @@ -9,6 +9,7 @@

#include "arch.h"
#include "arch-parisc.h"
#include "syscall-hashmap.h"

/* NOTE: based on Linux 4.15-rc7 */
const struct arch_syscall_def parisc_syscall_table[] = { \
Expand Down Expand Up @@ -449,6 +450,12 @@ const struct arch_syscall_def parisc_syscall_table[] = { \
{ NULL, __NR_SCMP_ERROR },
};

const struct syscall_hashmap_entry parisc_syscall_hashmap[] = {
#ifndef GENERATING_HASHMAP
#include "arch-parisc-syscall-hashmap.c"
#endif
};

/**
* Resolve a syscall name to a number
* @param name the syscall name
Expand All @@ -460,16 +467,8 @@ const struct arch_syscall_def parisc_syscall_table[] = { \
*/
int parisc_syscall_resolve_name(const char *name)
{
unsigned int iter;
const struct arch_syscall_def *table = parisc_syscall_table;

/* XXX - plenty of room for future improvement here */
for (iter = 0; table[iter].name != NULL; iter++) {
if (strcmp(name, table[iter].name) == 0)
return table[iter].num;
}

return __NR_SCMP_ERROR;
return syscall_hashmap_resolve(parisc_syscall_hashmap,
sizeof(parisc_syscall_hashmap) / sizeof(*parisc_syscall_hashmap), name);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions src/arch-ppc-syscalls.c
Expand Up @@ -26,6 +26,7 @@

#include "arch.h"
#include "arch-ppc.h"
#include "syscall-hashmap.h"

/* NOTE: based on Linux 4.15-rc7 */
const struct arch_syscall_def ppc_syscall_table[] = { \
Expand Down Expand Up @@ -466,6 +467,12 @@ const struct arch_syscall_def ppc_syscall_table[] = { \
{ NULL, __NR_SCMP_ERROR },
};

const struct syscall_hashmap_entry ppc_syscall_hashmap[] = {
#ifndef GENERATING_HASHMAP
#include "arch-ppc-syscall-hashmap.c"
#endif
};

/**
* Resolve a syscall name to a number
* @param name the syscall name
Expand All @@ -477,16 +484,8 @@ const struct arch_syscall_def ppc_syscall_table[] = { \
*/
int ppc_syscall_resolve_name(const char *name)
{
unsigned int iter;
const struct arch_syscall_def *table = ppc_syscall_table;

/* XXX - plenty of room for future improvement here */
for (iter = 0; table[iter].name != NULL; iter++) {
if (strcmp(name, table[iter].name) == 0)
return table[iter].num;
}

return __NR_SCMP_ERROR;
return syscall_hashmap_resolve(ppc_syscall_hashmap,
sizeof(ppc_syscall_hashmap) / sizeof(*ppc_syscall_hashmap), name);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions src/arch-ppc64-syscalls.c
Expand Up @@ -26,6 +26,7 @@

#include "arch.h"
#include "arch-ppc64.h"
#include "syscall-hashmap.h"

/* NOTE: based on Linux 4.15-rc7 */
const struct arch_syscall_def ppc64_syscall_table[] = { \
Expand Down Expand Up @@ -466,6 +467,12 @@ const struct arch_syscall_def ppc64_syscall_table[] = { \
{ NULL, __NR_SCMP_ERROR },
};

const struct syscall_hashmap_entry ppc64_syscall_hashmap[] = {
#ifndef GENERATING_HASHMAP
#include "arch-ppc64-syscall-hashmap.c"
#endif
};

/**
* Resolve a syscall name to a number
* @param name the syscall name
Expand All @@ -477,16 +484,8 @@ const struct arch_syscall_def ppc64_syscall_table[] = { \
*/
int ppc64_syscall_resolve_name(const char *name)
{
unsigned int iter;
const struct arch_syscall_def *table = ppc64_syscall_table;

/* XXX - plenty of room for future improvement here */
for (iter = 0; table[iter].name != NULL; iter++) {
if (strcmp(name, table[iter].name) == 0)
return table[iter].num;
}

return __NR_SCMP_ERROR;
return syscall_hashmap_resolve(ppc64_syscall_hashmap,
sizeof(ppc64_syscall_hashmap) / sizeof(*ppc64_syscall_hashmap), name);
}

/**
Expand Down

0 comments on commit 9c7518a

Please sign in to comment.