blob: 2ba784a3734adb2fd7088016970c627a508511f8 [file] [log] [blame]
Arnaldo Carvalho de Melo83bc9c372017-08-28 11:47:11 -03001/*
2 * trace/beauty/pkey_alloc.c
3 *
4 * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
5 *
6 * Released under the GPL v2. (and only v2, not any later version)
7 */
8
9#include "trace/beauty/beauty.h"
10#include <linux/kernel.h>
11#include <linux/log2.h>
12
13static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size)
14{
15 int i, printed = 0;
16
17#include "trace/beauty/generated/pkey_alloc_access_rights_array.c"
18 static DEFINE_STRARRAY(pkey_alloc_access_rights);
19
20 if (access_rights == 0) {
21 const char *s = strarray__pkey_alloc_access_rights.entries[0];
22 if (s)
23 return scnprintf(bf, size, "%s", s);
24 return scnprintf(bf, size, "%d", 0);
25 }
26
27 for (i = 1; i < strarray__pkey_alloc_access_rights.nr_entries; ++i) {
28 int bit = 1 << (i - 1);
29
30 if (!(access_rights & bit))
31 continue;
32
33 if (printed != 0)
34 printed += scnprintf(bf + printed, size - printed, "|");
35
36 if (strarray__pkey_alloc_access_rights.entries[i] != NULL)
37 printed += scnprintf(bf + printed, size - printed, "%s", strarray__pkey_alloc_access_rights.entries[i]);
38 else
39 printed += scnprintf(bf + printed, size - printed, "0x%#", bit);
40 }
41
42 return printed;
43}
44
45size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg)
46{
47 unsigned long cmd = arg->val;
48
49 return pkey_alloc__scnprintf_access_rights(cmd, bf, size);
50}