Blame src/syscalls.perf.template

Packit Service 10c312
%{
Packit Service 10c312
/**
Packit Service 10c312
 * Copyright (c) 2012 Red Hat <pmoore@redhat.com>
Packit Service 10c312
 * Copyright (c) 2020 Red Hat <gscrivan@redhat.com>
Packit Service 10c312
 * Authors: Paul Moore <paul@paul-moore.com>
Packit Service 10c312
 *          Giuseppe Scrivano <gscrivan@redhat.com>
Packit Service 10c312
 */
Packit Service 10c312
Packit Service 10c312
/*
Packit Service 10c312
 * This library is free software; you can redistribute it and/or modify it
Packit Service 10c312
 * under the terms of version 2.1 of the GNU Lesser General Public License as
Packit Service 10c312
 * published by the Free Software Foundation.
Packit Service 10c312
 *
Packit Service 10c312
 * This library is distributed in the hope that it will be useful, but WITHOUT
Packit Service 10c312
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit Service 10c312
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
Packit Service 10c312
 * for more details.
Packit Service 10c312
 *
Packit Service 10c312
 * You should have received a copy of the GNU Lesser General Public License
Packit Service 10c312
 * along with this library; if not, see <http://www.gnu.org/licenses>.
Packit Service 10c312
 */
Packit Service 10c312
Packit Service 10c312
#include <seccomp.h>
Packit Service 10c312
#include <string.h>
Packit Service 10c312
#include "syscalls.h"
Packit Service 10c312
Packit Service 10c312
%}
Packit Service 10c312
struct arch_syscall_table;
Packit Service 10c312
Packit Service 10c312
%%
Packit Service 10c312
@@SYSCALLS_TABLE@@
Packit Service 10c312
%%
Packit Service 10c312
Packit Service 10c312
static int syscall_get_offset_value(const struct arch_syscall_table *s,
Packit Service 10c312
				    int offset)
Packit Service 10c312
{
Packit Service 10c312
	return *(int *)((char *)s + offset);
Packit Service 10c312
}
Packit Service 10c312
Packit Service 10c312
int syscall_resolve_name(const char *name, int offset)
Packit Service 10c312
{
Packit Service 10c312
	const struct arch_syscall_table *s;
Packit Service 10c312
Packit Service 10c312
	s = in_word_set(name, strlen(name));
Packit Service 10c312
	if (s == NULL)
Packit Service 10c312
		return __NR_SCMP_ERROR;
Packit Service 10c312
Packit Service 10c312
	return syscall_get_offset_value(s, offset);
Packit Service 10c312
}
Packit Service 10c312
Packit Service 10c312
const char *syscall_resolve_num(int num, int offset)
Packit Service 10c312
{
Packit Service 10c312
	unsigned int iter;
Packit Service 10c312
Packit Service 10c312
	for (iter = 0; iter < sizeof(wordlist)/sizeof(wordlist[0]); iter++) {
Packit Service 10c312
		if (syscall_get_offset_value(&wordlist[iter], offset) == num)
Packit Service 10c312
			return (stringpool + wordlist[iter].name);
Packit Service 10c312
	}
Packit Service 10c312
Packit Service 10c312
	return NULL;
Packit Service 10c312
}
Packit Service 10c312
Packit Service 10c312
const struct arch_syscall_def *syscall_iterate(unsigned int spot, int offset)
Packit Service 10c312
{
Packit Service 10c312
	unsigned int iter;
Packit Service 10c312
        /* this is thread-unsafe, only use for testing */
Packit Service 10c312
	static struct arch_syscall_def arch_def;
Packit Service 10c312
Packit Service 10c312
	arch_def.name = NULL;
Packit Service 10c312
	arch_def.num = __NR_SCMP_ERROR;
Packit Service 10c312
Packit Service 10c312
	for (iter = 0; iter < sizeof(wordlist)/sizeof(wordlist[0]); iter++) {
Packit Service 10c312
		if (wordlist[iter].index == spot) {
Packit Service 10c312
			arch_def.name = stringpool + wordlist[iter].name;
Packit Service 10c312
			arch_def.num = syscall_get_offset_value(&wordlist[iter],
Packit Service 10c312
								offset);
Packit Service 10c312
			return &arch_def;
Packit Service 10c312
		}
Packit Service 10c312
	}
Packit Service 10c312
Packit Service 10c312
	return &arch_def;
Packit Service 10c312
}