hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/tools/perf/builtin-trace.c
....@@ -87,6 +87,8 @@
8787 # define F_LINUX_SPECIFIC_BASE 1024
8888 #endif
8989
90
+#define RAW_SYSCALL_ARGS_NUM 6
91
+
9092 /*
9193 * strtoul: Go from a string to a value, i.e. for msr: MSR_FS_BASE to 0xc0000100
9294 */
....@@ -107,7 +109,7 @@
107109 const char *sys_enter,
108110 *sys_exit;
109111 } bpf_prog_name;
110
- struct syscall_arg_fmt arg[6];
112
+ struct syscall_arg_fmt arg[RAW_SYSCALL_ARGS_NUM];
111113 u8 nr_args;
112114 bool errpid;
113115 bool timeout;
....@@ -1216,7 +1218,7 @@
12161218 */
12171219 struct bpf_map_syscall_entry {
12181220 bool enabled;
1219
- u16 string_args_len[6];
1221
+ u16 string_args_len[RAW_SYSCALL_ARGS_NUM];
12201222 };
12211223
12221224 /*
....@@ -1641,7 +1643,7 @@
16411643 {
16421644 int idx;
16431645
1644
- if (nr_args == 6 && sc->fmt && sc->fmt->nr_args != 0)
1646
+ if (nr_args == RAW_SYSCALL_ARGS_NUM && sc->fmt && sc->fmt->nr_args != 0)
16451647 nr_args = sc->fmt->nr_args;
16461648
16471649 sc->arg_fmt = calloc(nr_args, sizeof(*sc->arg_fmt));
....@@ -1774,11 +1776,11 @@
17741776 #endif
17751777 sc = trace->syscalls.table + id;
17761778 if (sc->nonexistent)
1777
- return 0;
1779
+ return -EEXIST;
17781780
17791781 if (name == NULL) {
17801782 sc->nonexistent = true;
1781
- return 0;
1783
+ return -EEXIST;
17821784 }
17831785
17841786 sc->name = name;
....@@ -1792,11 +1794,18 @@
17921794 sc->tp_format = trace_event__tp_format("syscalls", tp_name);
17931795 }
17941796
1795
- if (syscall__alloc_arg_fmts(sc, IS_ERR(sc->tp_format) ? 6 : sc->tp_format->format.nr_fields))
1796
- return -ENOMEM;
1797
-
1798
- if (IS_ERR(sc->tp_format))
1797
+ /*
1798
+ * Fails to read trace point format via sysfs node, so the trace point
1799
+ * doesn't exist. Set the 'nonexistent' flag as true.
1800
+ */
1801
+ if (IS_ERR(sc->tp_format)) {
1802
+ sc->nonexistent = true;
17991803 return PTR_ERR(sc->tp_format);
1804
+ }
1805
+
1806
+ if (syscall__alloc_arg_fmts(sc, IS_ERR(sc->tp_format) ?
1807
+ RAW_SYSCALL_ARGS_NUM : sc->tp_format->format.nr_fields))
1808
+ return -ENOMEM;
18001809
18011810 sc->args = sc->tp_format->format.fields;
18021811 /*
....@@ -2114,11 +2123,8 @@
21142123 (err = trace__read_syscall_info(trace, id)) != 0)
21152124 goto out_cant_read;
21162125
2117
- if (trace->syscalls.table[id].name == NULL) {
2118
- if (trace->syscalls.table[id].nonexistent)
2119
- return NULL;
2126
+ if (trace->syscalls.table && trace->syscalls.table[id].nonexistent)
21202127 goto out_cant_read;
2121
- }
21222128
21232129 return &trace->syscalls.table[id];
21242130