pkey_alloc.c 1.4 KB
Newer Older
1
// SPDX-License-Identifier: LGPL-2.1
2 3 4 5 6 7 8 9 10 11
/*
 * trace/beauty/pkey_alloc.c
 *
 *  Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
 */

#include "trace/beauty/beauty.h"
#include <linux/kernel.h>
#include <linux/log2.h>

12
size_t strarray__scnprintf_flags(struct strarray *sa, char *bf, size_t size, unsigned long flags)
13 14 15
{
	int i, printed = 0;

16 17
	if (flags == 0) {
		const char *s = sa->entries[0];
18 19 20 21 22
		if (s)
			return scnprintf(bf, size, "%s", s);
		return scnprintf(bf, size, "%d", 0);
	}

23 24
	for (i = 1; i < sa->nr_entries; ++i) {
		unsigned long bit = 1UL << (i - 1);
25

26
		if (!(flags & bit))
27 28 29 30 31
			continue;

		if (printed != 0)
			printed += scnprintf(bf + printed, size - printed, "|");

32 33
		if (sa->entries[i] != NULL)
			printed += scnprintf(bf + printed, size - printed, "%s", sa->entries[i]);
34 35 36 37 38 39 40
		else
			printed += scnprintf(bf + printed, size - printed, "0x%#", bit);
	}

	return printed;
}

41 42 43 44 45 46 47 48
static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size)
{
#include "trace/beauty/generated/pkey_alloc_access_rights_array.c"
	static DEFINE_STRARRAY(pkey_alloc_access_rights);

	return strarray__scnprintf_flags(&strarray__pkey_alloc_access_rights, bf, size, access_rights);
}

49 50 51 52 53 54
size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg)
{
	unsigned long cmd = arg->val;

	return pkey_alloc__scnprintf_access_rights(cmd, bf, size);
}