summaryrefslogblamecommitdiffstats
path: root/libsyscalls_get_syscall.c
blob: aea4d2f04753e7b0bc94dcbc1f331a9f04666824 (plain) (tree)




































                                                                                                    
/* 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;
}