summaryrefslogblamecommitdiffstats
path: root/libsyscalls_get_syscall.c
blob: e025e182b6e7425181d4c70355d7ed0ba1f84419 (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() */
	syscalldesc = libsyscalls_syscalls_tables_[os][arch][syscallnr - min];

	if (!syscalldesc)
		return LIBSYSCALLS_E_NOSUCHSYSCALL;
	if (syscall_out)
		*syscall_out = syscalldesc;
	return LIBSYSCALLS_E_OK;
}