summaryrefslogtreecommitdiffstats
path: root/libsyscalls_get_syscall.c
blob: aea4d2f04753e7b0bc94dcbc1f331a9f04666824 (plain) (blame)
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
/* 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;
}