diff options
author | Mattias Andrée <maandree@kth.se> | 2023-12-03 19:23:35 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-12-03 19:23:35 +0100 |
commit | c131f122778c62f920a99bbf854ced4a37ee8b03 (patch) | |
tree | 14c933f98f4d64dffb0a594bc40dd5121c6c5a8e /libsyscalls_get_syscall.c | |
download | libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.gz libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.bz2 libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.xz |
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libsyscalls_get_syscall.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libsyscalls_get_syscall.c b/libsyscalls_get_syscall.c new file mode 100644 index 0000000..aea4d2f --- /dev/null +++ b/libsyscalls_get_syscall.c @@ -0,0 +1,37 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +enum libsyscalls_error +libsyscalls_get_syscall(enum libsyscalls_os os, enum libsyscalls_arch arch, long long int syscallnr, + const struct libsyscalls_syscall **syscall_out) +{ + const struct libsyscalls_syscall *syscalldesc; + static enum libsyscalls_error error; + long long int min, max; + + error = libsyscalls_get_syscall_range(os, arch, &min, &max); + if (error) + return error; + + if (syscallnr < min || syscallnr > max) + return LIBSYSCALLS_E_NOSUCHSYSCALL; + + /* buffer access is validated by libsyscalls_get_syscall_range() */ +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#endif + + syscalldesc = libsyscalls_syscalls_tables_[os][arch][syscallnr - min]; + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + + if (!syscalldesc) + return LIBSYSCALLS_E_NOSUCHSYSCALL; + if (syscall_out) + *syscall_out = syscalldesc; + return LIBSYSCALLS_E_OK; +} |