Linux Perf
prctl.c
Go to the documentation of this file.
1 /*
2  * trace/beauty/prctl.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 <uapi/linux/prctl.h>
12 
13 #include "trace/beauty/generated/prctl_option_array.c"
14 
15 static size_t prctl__scnprintf_option(int option, char *bf, size_t size)
16 {
17  static DEFINE_STRARRAY(prctl_options);
18  return strarray__scnprintf(&strarray__prctl_options, bf, size, "%d", option);
19 }
20 
21 static size_t prctl__scnprintf_set_mm(int option, char *bf, size_t size)
22 {
23  static DEFINE_STRARRAY(prctl_set_mm_options);
24  return strarray__scnprintf(&strarray__prctl_set_mm_options, bf, size, "%d", option);
25 }
26 
27 size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg)
28 {
29  int option = syscall_arg__val(arg, 0);
30 
31  if (option == PR_SET_MM)
32  return prctl__scnprintf_set_mm(arg->val, bf, size);
33  /*
34  * We still don't grab the contents of pointers on entry or exit,
35  * so just print them as hex numbers
36  */
37  if (option == PR_SET_NAME)
38  return syscall_arg__scnprintf_hex(bf, size, arg);
39 
40  return syscall_arg__scnprintf_long(bf, size, arg);
41 }
42 
43 size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg)
44 {
45  int option = syscall_arg__val(arg, 0);
46 
47  if (option == PR_SET_MM)
48  return syscall_arg__scnprintf_hex(bf, size, arg);
49 
50  return syscall_arg__scnprintf_long(bf, size, arg);
51 }
52 
53 size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg)
54 {
55  unsigned long option = arg->val;
56  enum {
57  SPO_ARG2 = (1 << 1),
58  SPO_ARG3 = (1 << 2),
59  SPO_ARG4 = (1 << 3),
60  SPO_ARG5 = (1 << 4),
61  SPO_ARG6 = (1 << 5),
62  };
63  const u8 all_but2 = SPO_ARG3 | SPO_ARG4 | SPO_ARG5 | SPO_ARG6;
64  const u8 all = SPO_ARG2 | all_but2;
65  const u8 masks[] = {
66  [PR_GET_DUMPABLE] = all,
67  [PR_SET_DUMPABLE] = all_but2,
68  [PR_SET_NAME] = all_but2,
69  [PR_GET_CHILD_SUBREAPER] = all_but2,
70  [PR_SET_CHILD_SUBREAPER] = all_but2,
71  [PR_GET_SECUREBITS] = all,
72  [PR_SET_SECUREBITS] = all_but2,
73  [PR_SET_MM] = SPO_ARG4 | SPO_ARG5 | SPO_ARG6,
74  [PR_GET_PDEATHSIG] = all,
75  [PR_SET_PDEATHSIG] = all_but2,
76  };
77 
78  if (option < ARRAY_SIZE(masks))
79  arg->mask |= masks[option];
80 
81  return prctl__scnprintf_option(option, bf, size);
82 }
#define DEFINE_STRARRAY(array)
Definition: beauty.h:15
size_t size
Definition: evsel.c:60
size_t syscall_arg__scnprintf_hex(char *bf, size_t size, struct syscall_arg *arg)
size_t syscall_arg__scnprintf_long(char *bf, size_t size, struct syscall_arg *arg)
size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg)
Definition: prctl.c:43
#define PR_SET_NAME
Definition: builtin-sched.c:41
size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg)
Definition: prctl.c:53
static size_t prctl__scnprintf_set_mm(int option, char *bf, size_t size)
Definition: prctl.c:21
static size_t prctl__scnprintf_option(int option, char *bf, size_t size)
Definition: prctl.c:15
u8 mask
Definition: beauty.h:50
size_t strarray__scnprintf(struct strarray *sa, char *bf, size_t size, const char *intfmt, int val)
unsigned long val
Definition: beauty.h:44
unsigned long syscall_arg__val(struct syscall_arg *arg, u8 idx)
size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg)
Definition: prctl.c:27