0001
0002
0003
0004
0005
0006
0007
0008 #include "trace/beauty/beauty.h"
0009 #include <linux/kernel.h>
0010 #include <uapi/linux/prctl.h>
0011
0012 #include "trace/beauty/generated/prctl_option_array.c"
0013
0014 DEFINE_STRARRAY(prctl_options, "PR_");
0015
0016 static size_t prctl__scnprintf_option(int option, char *bf, size_t size, bool show_prefix)
0017 {
0018 return strarray__scnprintf(&strarray__prctl_options, bf, size, "%d", show_prefix, option);
0019 }
0020
0021 static size_t prctl__scnprintf_set_mm(int option, char *bf, size_t size, bool show_prefix)
0022 {
0023 static DEFINE_STRARRAY(prctl_set_mm_options, "PR_SET_MM_");
0024 return strarray__scnprintf(&strarray__prctl_set_mm_options, bf, size, "%d", show_prefix, option);
0025 }
0026
0027 size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_arg *arg)
0028 {
0029 int option = syscall_arg__val(arg, 0);
0030
0031 if (option == PR_SET_MM)
0032 return prctl__scnprintf_set_mm(arg->val, bf, size, arg->show_string_prefix);
0033
0034
0035
0036
0037 if (option == PR_SET_NAME)
0038 return syscall_arg__scnprintf_hex(bf, size, arg);
0039
0040 return syscall_arg__scnprintf_long(bf, size, arg);
0041 }
0042
0043 size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg)
0044 {
0045 int option = syscall_arg__val(arg, 0);
0046
0047 if (option == PR_SET_MM)
0048 return syscall_arg__scnprintf_hex(bf, size, arg);
0049
0050 return syscall_arg__scnprintf_long(bf, size, arg);
0051 }
0052
0053 size_t syscall_arg__scnprintf_prctl_option(char *bf, size_t size, struct syscall_arg *arg)
0054 {
0055 unsigned long option = arg->val;
0056 enum {
0057 SPO_ARG2 = (1 << 1),
0058 SPO_ARG3 = (1 << 2),
0059 SPO_ARG4 = (1 << 3),
0060 SPO_ARG5 = (1 << 4),
0061 SPO_ARG6 = (1 << 5),
0062 };
0063 const u8 all_but2 = SPO_ARG3 | SPO_ARG4 | SPO_ARG5 | SPO_ARG6;
0064 const u8 all = SPO_ARG2 | all_but2;
0065 const u8 masks[] = {
0066 [PR_GET_DUMPABLE] = all,
0067 [PR_SET_DUMPABLE] = all_but2,
0068 [PR_SET_NAME] = all_but2,
0069 [PR_GET_CHILD_SUBREAPER] = all_but2,
0070 [PR_SET_CHILD_SUBREAPER] = all_but2,
0071 [PR_GET_SECUREBITS] = all,
0072 [PR_SET_SECUREBITS] = all_but2,
0073 [PR_SET_MM] = SPO_ARG4 | SPO_ARG5 | SPO_ARG6,
0074 [PR_GET_PDEATHSIG] = all,
0075 [PR_SET_PDEATHSIG] = all_but2,
0076 };
0077
0078 if (option < ARRAY_SIZE(masks))
0079 arg->mask |= masks[option];
0080
0081 return prctl__scnprintf_option(option, bf, size, arg->show_string_prefix);
0082 }