blob: 73d90179b51bd30833b336180a6edad4ce396458 [file] [log] [blame]
Steven Rostedt (VMware)bcea3f92018-08-16 11:23:53 -04001// SPDX-License-Identifier: GPL-2.0
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +05302/*
3 * Common code for probe-based Dynamic events.
4 *
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +05305 * This code was copied from kernel/trace/trace_kprobe.c written by
6 * Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
7 *
8 * Updates to make this generic:
9 * Copyright (C) IBM Corporation, 2010-2011
10 * Author: Srikar Dronamraju
11 */
Masami Hiramatsu72576342017-02-07 20:21:28 +090012#define pr_fmt(fmt) "trace_probe: " fmt
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053013
14#include "trace_probe.h"
15
Masami Hiramatsuab105a42019-03-31 18:48:19 -050016#undef C
17#define C(a, b) b
18
19static const char *trace_probe_err_text[] = { ERRORS };
20
Valdis Klētnieks08416252019-03-12 04:52:58 -040021static const char *reserved_field_names[] = {
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053022 "common_type",
23 "common_flags",
24 "common_preempt_count",
25 "common_pid",
26 "common_tgid",
27 FIELD_STRING_IP,
28 FIELD_STRING_RETIP,
29 FIELD_STRING_FUNC,
30};
31
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053032/* Printing in basic type function template */
Masami Hiramatsu17ce3dc2016-08-18 17:57:50 +090033#define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt) \
Masami Hiramatsu56de7632018-04-25 21:16:36 +090034int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053035{ \
Masami Hiramatsu56de7632018-04-25 21:16:36 +090036 trace_seq_printf(s, fmt, *(type *)data); \
Steven Rostedt (Red Hat)d2b01912014-11-12 17:19:51 -050037 return !trace_seq_has_overflowed(s); \
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053038} \
Masami Hiramatsu7bfbc632018-04-25 21:17:34 +090039const char PRINT_TYPE_FMT_NAME(tname)[] = fmt;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053040
Masami Hiramatsubdca79c22016-08-18 17:59:21 +090041DEFINE_BASIC_PRINT_TYPE_FUNC(u8, u8, "%u")
42DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "%u")
43DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "%u")
44DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "%Lu")
Masami Hiramatsu17ce3dc2016-08-18 17:57:50 +090045DEFINE_BASIC_PRINT_TYPE_FUNC(s8, s8, "%d")
46DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d")
47DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d")
48DEFINE_BASIC_PRINT_TYPE_FUNC(s64, s64, "%Ld")
49DEFINE_BASIC_PRINT_TYPE_FUNC(x8, u8, "0x%x")
50DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x")
51DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x")
52DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx")
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053053
Masami Hiramatsu60c2e0c2018-04-25 21:20:28 +090054int PRINT_TYPE_FUNC_NAME(symbol)(struct trace_seq *s, void *data, void *ent)
55{
56 trace_seq_printf(s, "%pS", (void *)*(unsigned long *)data);
57 return !trace_seq_has_overflowed(s);
58}
59const char PRINT_TYPE_FMT_NAME(symbol)[] = "%pS";
60
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053061/* Print type function for string type */
Masami Hiramatsu56de7632018-04-25 21:16:36 +090062int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent)
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053063{
64 int len = *(u32 *)data >> 16;
65
66 if (!len)
Masami Hiramatsu56de7632018-04-25 21:16:36 +090067 trace_seq_puts(s, "(fault)");
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053068 else
Masami Hiramatsu56de7632018-04-25 21:16:36 +090069 trace_seq_printf(s, "\"%s\"",
Steven Rostedt (Red Hat)d2b01912014-11-12 17:19:51 -050070 (const char *)get_loc_data(data, ent));
71 return !trace_seq_has_overflowed(s);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053072}
73
Namhyung Kimb26c74e2013-11-26 14:19:59 +090074const char PRINT_TYPE_FMT_NAME(string)[] = "\\\"%s\\\"";
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +053075
Masami Hiramatsuf451bc82018-04-25 21:18:32 +090076/* Fetch type information table */
77static const struct fetch_type probe_fetch_types[] = {
78 /* Special types */
79 __ASSIGN_FETCH_TYPE("string", string, string, sizeof(u32), 1,
80 "__data_loc char[]"),
Masami Hiramatsu88903c42019-05-15 14:38:30 +090081 __ASSIGN_FETCH_TYPE("ustring", string, string, sizeof(u32), 1,
82 "__data_loc char[]"),
Masami Hiramatsuf451bc82018-04-25 21:18:32 +090083 /* Basic types */
84 ASSIGN_FETCH_TYPE(u8, u8, 0),
85 ASSIGN_FETCH_TYPE(u16, u16, 0),
86 ASSIGN_FETCH_TYPE(u32, u32, 0),
87 ASSIGN_FETCH_TYPE(u64, u64, 0),
88 ASSIGN_FETCH_TYPE(s8, u8, 1),
89 ASSIGN_FETCH_TYPE(s16, u16, 1),
90 ASSIGN_FETCH_TYPE(s32, u32, 1),
91 ASSIGN_FETCH_TYPE(s64, u64, 1),
92 ASSIGN_FETCH_TYPE_ALIAS(x8, u8, u8, 0),
93 ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
94 ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
95 ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
Masami Hiramatsu60c2e0c2018-04-25 21:20:28 +090096 ASSIGN_FETCH_TYPE_ALIAS(symbol, ADDR_FETCH_TYPE, ADDR_FETCH_TYPE, 0),
Masami Hiramatsuf451bc82018-04-25 21:18:32 +090097
98 ASSIGN_FETCH_TYPE_END
99};
100
101static const struct fetch_type *find_fetch_type(const char *type)
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530102{
103 int i;
104
105 if (!type)
106 type = DEFAULT_FETCH_TYPE_STR;
107
108 /* Special case: bitfield */
109 if (*type == 'b') {
110 unsigned long bs;
111
112 type = strchr(type, '/');
113 if (!type)
114 goto fail;
115
116 type++;
Daniel Walterbcd83ea2012-09-26 22:08:38 +0200117 if (kstrtoul(type, 0, &bs))
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530118 goto fail;
119
120 switch (bs) {
121 case 8:
Masami Hiramatsuf451bc82018-04-25 21:18:32 +0900122 return find_fetch_type("u8");
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530123 case 16:
Masami Hiramatsuf451bc82018-04-25 21:18:32 +0900124 return find_fetch_type("u16");
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530125 case 32:
Masami Hiramatsuf451bc82018-04-25 21:18:32 +0900126 return find_fetch_type("u32");
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530127 case 64:
Masami Hiramatsuf451bc82018-04-25 21:18:32 +0900128 return find_fetch_type("u64");
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530129 default:
130 goto fail;
131 }
132 }
133
Masami Hiramatsuf451bc82018-04-25 21:18:32 +0900134 for (i = 0; probe_fetch_types[i].name; i++) {
135 if (strcmp(type, probe_fetch_types[i].name) == 0)
136 return &probe_fetch_types[i];
Namhyung Kim34fee3a2013-11-26 14:56:28 +0900137 }
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530138
139fail:
140 return NULL;
141}
142
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500143static struct trace_probe_log trace_probe_log;
144
145void trace_probe_log_init(const char *subsystem, int argc, const char **argv)
146{
147 trace_probe_log.subsystem = subsystem;
148 trace_probe_log.argc = argc;
149 trace_probe_log.argv = argv;
150 trace_probe_log.index = 0;
151}
152
153void trace_probe_log_clear(void)
154{
155 memset(&trace_probe_log, 0, sizeof(trace_probe_log));
156}
157
158void trace_probe_log_set_index(int index)
159{
160 trace_probe_log.index = index;
161}
162
163void __trace_probe_log_err(int offset, int err_type)
164{
165 char *command, *p;
166 int i, len = 0, pos = 0;
167
168 if (!trace_probe_log.argv)
169 return;
170
Ingo Molnarf2cc0202021-03-23 18:49:35 +0100171 /* Recalculate the length and allocate buffer */
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500172 for (i = 0; i < trace_probe_log.argc; i++) {
173 if (i == trace_probe_log.index)
174 pos = len;
175 len += strlen(trace_probe_log.argv[i]) + 1;
176 }
177 command = kzalloc(len, GFP_KERNEL);
178 if (!command)
179 return;
180
Masami Hiramatsud2aea952019-09-28 05:53:29 -0400181 if (trace_probe_log.index >= trace_probe_log.argc) {
182 /**
183 * Set the error position is next to the last arg + space.
184 * Note that len includes the terminal null and the cursor
Ingo Molnarf2cc0202021-03-23 18:49:35 +0100185 * appears at pos + 1.
Masami Hiramatsud2aea952019-09-28 05:53:29 -0400186 */
187 pos = len;
188 offset = 0;
189 }
190
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500191 /* And make a command string from argv array */
192 p = command;
193 for (i = 0; i < trace_probe_log.argc; i++) {
194 len = strlen(trace_probe_log.argv[i]);
195 strcpy(p, trace_probe_log.argv[i]);
196 p[len] = ' ';
197 p += len + 1;
198 }
199 *(p - 1) = '\0';
200
Steven Rostedt (VMware)2f754e72019-04-01 22:52:21 -0400201 tracing_log_err(NULL, trace_probe_log.subsystem, command,
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500202 trace_probe_err_text, err_type, pos + offset);
203
204 kfree(command);
205}
206
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530207/* Split symbol and offset. */
Masami Hiramatsuc5d343b2018-03-17 21:38:10 +0900208int traceprobe_split_symbol_offset(char *symbol, long *offset)
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530209{
210 char *tmp;
211 int ret;
212
213 if (!offset)
214 return -EINVAL;
215
Masami Hiramatsuc5d343b2018-03-17 21:38:10 +0900216 tmp = strpbrk(symbol, "+-");
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530217 if (tmp) {
Masami Hiramatsuc5d343b2018-03-17 21:38:10 +0900218 ret = kstrtol(tmp, 0, offset);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530219 if (ret)
220 return ret;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530221 *tmp = '\0';
222 } else
223 *offset = 0;
224
225 return 0;
226}
227
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900228/* @buf must has MAX_EVENT_NAME_LEN size */
229int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500230 char *buf, int offset)
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900231{
232 const char *slash, *event = *pevent;
Masami Hiramatsudec65d792019-03-14 13:30:20 +0900233 int len;
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900234
235 slash = strchr(event, '/');
Steven Rostedt (VMware)bc1b9732021-08-16 23:42:59 -0400236 if (!slash)
237 slash = strchr(event, '.');
238
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900239 if (slash) {
240 if (slash == event) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500241 trace_probe_log_err(offset, NO_GROUP_NAME);
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900242 return -EINVAL;
243 }
244 if (slash - event + 1 > MAX_EVENT_NAME_LEN) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500245 trace_probe_log_err(offset, GROUP_TOO_LONG);
246 return -EINVAL;
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900247 }
248 strlcpy(buf, event, slash - event + 1);
Masami Hiramatsu5b7a9622019-03-14 13:30:40 +0900249 if (!is_good_name(buf)) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500250 trace_probe_log_err(offset, BAD_GROUP_NAME);
Masami Hiramatsu5b7a9622019-03-14 13:30:40 +0900251 return -EINVAL;
252 }
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900253 *pgroup = buf;
254 *pevent = slash + 1;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500255 offset += slash - event + 1;
Masami Hiramatsudec65d792019-03-14 13:30:20 +0900256 event = *pevent;
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900257 }
Masami Hiramatsudec65d792019-03-14 13:30:20 +0900258 len = strlen(event);
259 if (len == 0) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500260 trace_probe_log_err(offset, NO_EVENT_NAME);
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900261 return -EINVAL;
Masami Hiramatsudec65d792019-03-14 13:30:20 +0900262 } else if (len > MAX_EVENT_NAME_LEN) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500263 trace_probe_log_err(offset, EVENT_TOO_LONG);
264 return -EINVAL;
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900265 }
Masami Hiramatsu5b7a9622019-03-14 13:30:40 +0900266 if (!is_good_name(event)) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500267 trace_probe_log_err(offset, BAD_EVENT_NAME);
Masami Hiramatsu5b7a9622019-03-14 13:30:40 +0900268 return -EINVAL;
269 }
Masami Hiramatsu6212dd22018-11-05 18:02:36 +0900270 return 0;
271}
272
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530273#define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long))
274
275static int parse_probe_vars(char *arg, const struct fetch_type *t,
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500276 struct fetch_insn *code, unsigned int flags, int offs)
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530277{
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530278 unsigned long param;
Steven Rostedt (VMware)3d739c12018-12-21 23:10:26 -0500279 int ret = 0;
280 int len;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530281
282 if (strcmp(arg, "retval") == 0) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500283 if (flags & TPARG_FL_RETURN) {
Masami Hiramatsu53305922018-04-25 21:18:03 +0900284 code->op = FETCH_OP_RETVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500285 } else {
286 trace_probe_log_err(offs, RETVAL_ON_PROBE);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530287 ret = -EINVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500288 }
Steven Rostedt (VMware)3d739c12018-12-21 23:10:26 -0500289 } else if ((len = str_has_prefix(arg, "stack"))) {
290 if (arg[len] == '\0') {
Masami Hiramatsu53305922018-04-25 21:18:03 +0900291 code->op = FETCH_OP_STACKP;
Steven Rostedt (VMware)3d739c12018-12-21 23:10:26 -0500292 } else if (isdigit(arg[len])) {
293 ret = kstrtoul(arg + len, 10, &param);
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500294 if (ret) {
295 goto inval_var;
296 } else if ((flags & TPARG_FL_KERNEL) &&
297 param > PARAM_MAX_STACK) {
298 trace_probe_log_err(offs, BAD_STACK_NUM);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530299 ret = -EINVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500300 } else {
Masami Hiramatsu53305922018-04-25 21:18:03 +0900301 code->op = FETCH_OP_STACK;
302 code->param = (unsigned int)param;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530303 }
304 } else
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500305 goto inval_var;
Omar Sandoval35abb672016-06-08 18:38:02 -0700306 } else if (strcmp(arg, "comm") == 0) {
Masami Hiramatsu53305922018-04-25 21:18:03 +0900307 code->op = FETCH_OP_COMM;
Masami Hiramatsua1303af2018-04-25 21:21:26 +0900308#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
309 } else if (((flags & TPARG_FL_MASK) ==
310 (TPARG_FL_KERNEL | TPARG_FL_FENTRY)) &&
Steven Rostedt (VMware)3d739c12018-12-21 23:10:26 -0500311 (len = str_has_prefix(arg, "arg"))) {
Steven Rostedt (VMware)3d739c12018-12-21 23:10:26 -0500312 ret = kstrtoul(arg + len, 10, &param);
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500313 if (ret) {
314 goto inval_var;
315 } else if (!param || param > PARAM_MAX_STACK) {
316 trace_probe_log_err(offs, BAD_ARG_NUM);
Masami Hiramatsua1303af2018-04-25 21:21:26 +0900317 return -EINVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500318 }
Masami Hiramatsua1303af2018-04-25 21:21:26 +0900319 code->op = FETCH_OP_ARG;
320 code->param = (unsigned int)param - 1;
321#endif
Tzvetomir Stoyanov (VMware)7491e2c2021-08-19 11:26:06 -0400322 } else if (flags & TPARG_FL_TPOINT) {
323 if (code->data)
324 return -EFAULT;
325 code->data = kstrdup(arg, GFP_KERNEL);
326 if (!code->data)
327 return -ENOMEM;
328 code->op = FETCH_OP_TP_ARG;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530329 } else
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500330 goto inval_var;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530331
332 return ret;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500333
334inval_var:
335 trace_probe_log_err(offs, BAD_VAR);
336 return -EINVAL;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530337}
338
Masami Hiramatsu6218bf92019-06-20 00:08:27 +0900339static int str_to_immediate(char *str, unsigned long *imm)
340{
341 if (isdigit(str[0]))
342 return kstrtoul(str, 0, imm);
343 else if (str[0] == '-')
344 return kstrtol(str, 0, (long *)imm);
345 else if (str[0] == '+')
346 return kstrtol(str + 1, 0, (long *)imm);
347 return -EINVAL;
348}
349
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900350static int __parse_imm_string(char *str, char **pbuf, int offs)
351{
352 size_t len = strlen(str);
353
354 if (str[len - 1] != '"') {
355 trace_probe_log_err(offs + len, IMMSTR_NO_CLOSE);
356 return -EINVAL;
357 }
358 *pbuf = kstrndup(str, len - 1, GFP_KERNEL);
Xiaoke Wang1c1857d2021-12-14 10:26:46 +0800359 if (!*pbuf)
360 return -ENOMEM;
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900361 return 0;
362}
363
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530364/* Recursive argument parser */
Masami Hiramatsu53305922018-04-25 21:18:03 +0900365static int
366parse_probe_arg(char *arg, const struct fetch_type *type,
367 struct fetch_insn **pcode, struct fetch_insn *end,
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500368 unsigned int flags, int offs)
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530369{
Masami Hiramatsu53305922018-04-25 21:18:03 +0900370 struct fetch_insn *code = *pcode;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530371 unsigned long param;
Masami Hiramatsue65f7ae2019-05-15 14:38:42 +0900372 int deref = FETCH_OP_DEREF;
Steven Rostedt (VMware)bf173ca2018-10-12 12:50:22 -0400373 long offset = 0;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530374 char *tmp;
Namhyung Kim34fee3a2013-11-26 14:56:28 +0900375 int ret = 0;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530376
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530377 switch (arg[0]) {
378 case '$':
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500379 ret = parse_probe_vars(arg + 1, type, code, flags, offs);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530380 break;
381
382 case '%': /* named register */
383 ret = regs_query_register_offset(arg + 1);
384 if (ret >= 0) {
Masami Hiramatsu53305922018-04-25 21:18:03 +0900385 code->op = FETCH_OP_REG;
386 code->param = (unsigned int)ret;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530387 ret = 0;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500388 } else
389 trace_probe_log_err(offs, BAD_REG_NAME);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530390 break;
391
Namhyung Kimb7e0bf32013-11-25 13:42:47 +0900392 case '@': /* memory, file-offset or symbol */
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530393 if (isdigit(arg[1])) {
Daniel Walterbcd83ea2012-09-26 22:08:38 +0200394 ret = kstrtoul(arg + 1, 0, &param);
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500395 if (ret) {
396 trace_probe_log_err(offs, BAD_MEM_ADDR);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530397 break;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500398 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900399 /* load address */
400 code->op = FETCH_OP_IMM;
401 code->immediate = param;
Namhyung Kimb7e0bf32013-11-25 13:42:47 +0900402 } else if (arg[1] == '+') {
403 /* kprobes don't support file offsets */
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500404 if (flags & TPARG_FL_KERNEL) {
405 trace_probe_log_err(offs, FILE_ON_KPROBE);
Namhyung Kimb7e0bf32013-11-25 13:42:47 +0900406 return -EINVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500407 }
Namhyung Kimb7e0bf32013-11-25 13:42:47 +0900408 ret = kstrtol(arg + 2, 0, &offset);
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500409 if (ret) {
410 trace_probe_log_err(offs, BAD_FILE_OFFS);
Namhyung Kimb7e0bf32013-11-25 13:42:47 +0900411 break;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500412 }
Namhyung Kimb7e0bf32013-11-25 13:42:47 +0900413
Masami Hiramatsu53305922018-04-25 21:18:03 +0900414 code->op = FETCH_OP_FOFFS;
415 code->immediate = (unsigned long)offset; // imm64?
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530416 } else {
Namhyung Kimb079d372013-07-03 18:34:23 +0900417 /* uprobes don't support symbols */
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500418 if (!(flags & TPARG_FL_KERNEL)) {
419 trace_probe_log_err(offs, SYM_ON_UPROBE);
Namhyung Kimb079d372013-07-03 18:34:23 +0900420 return -EINVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500421 }
Masami Hiramatsua6682812018-08-29 01:18:43 +0900422 /* Preserve symbol for updating */
423 code->op = FETCH_NOP_SYMBOL;
424 code->data = kstrdup(arg + 1, GFP_KERNEL);
425 if (!code->data)
426 return -ENOMEM;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500427 if (++code == end) {
428 trace_probe_log_err(offs, TOO_MANY_OPS);
429 return -EINVAL;
430 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900431 code->op = FETCH_OP_IMM;
Masami Hiramatsua6682812018-08-29 01:18:43 +0900432 code->immediate = 0;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530433 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900434 /* These are fetching from memory */
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500435 if (++code == end) {
436 trace_probe_log_err(offs, TOO_MANY_OPS);
437 return -EINVAL;
438 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900439 *pcode = code;
440 code->op = FETCH_OP_DEREF;
441 code->offset = offset;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530442 break;
443
444 case '+': /* deref memory */
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530445 case '-':
Masami Hiramatsue65f7ae2019-05-15 14:38:42 +0900446 if (arg[1] == 'u') {
447 deref = FETCH_OP_UDEREF;
448 arg[1] = arg[0];
449 arg++;
450 }
451 if (arg[0] == '+')
452 arg++; /* Skip '+', because kstrtol() rejects it. */
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530453 tmp = strchr(arg, '(');
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500454 if (!tmp) {
455 trace_probe_log_err(offs, DEREF_NEED_BRACE);
Masami Hiramatsu53305922018-04-25 21:18:03 +0900456 return -EINVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500457 }
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530458 *tmp = '\0';
Daniel Walterbcd83ea2012-09-26 22:08:38 +0200459 ret = kstrtol(arg, 0, &offset);
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500460 if (ret) {
461 trace_probe_log_err(offs, BAD_DEREF_OFFS);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530462 break;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500463 }
464 offs += (tmp + 1 - arg) + (arg[0] != '-' ? 1 : 0);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530465 arg = tmp + 1;
466 tmp = strrchr(arg, ')');
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500467 if (!tmp) {
468 trace_probe_log_err(offs + strlen(arg),
469 DEREF_OPEN_BRACE);
470 return -EINVAL;
471 } else {
Masami Hiramatsuf451bc82018-04-25 21:18:32 +0900472 const struct fetch_type *t2 = find_fetch_type(NULL);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530473
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530474 *tmp = '\0';
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500475 ret = parse_probe_arg(arg, t2, &code, end, flags, offs);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530476 if (ret)
Masami Hiramatsu53305922018-04-25 21:18:03 +0900477 break;
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900478 if (code->op == FETCH_OP_COMM ||
479 code->op == FETCH_OP_DATA) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500480 trace_probe_log_err(offs, COMM_CANT_DEREF);
Masami Hiramatsu53305922018-04-25 21:18:03 +0900481 return -EINVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500482 }
483 if (++code == end) {
484 trace_probe_log_err(offs, TOO_MANY_OPS);
485 return -EINVAL;
486 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900487 *pcode = code;
488
Masami Hiramatsue65f7ae2019-05-15 14:38:42 +0900489 code->op = deref;
Masami Hiramatsu53305922018-04-25 21:18:03 +0900490 code->offset = offset;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530491 }
492 break;
Masami Hiramatsu6218bf92019-06-20 00:08:27 +0900493 case '\\': /* Immediate value */
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900494 if (arg[1] == '"') { /* Immediate string */
495 ret = __parse_imm_string(arg + 2, &tmp, offs + 2);
496 if (ret)
497 break;
498 code->op = FETCH_OP_DATA;
499 code->data = tmp;
500 } else {
501 ret = str_to_immediate(arg + 1, &code->immediate);
502 if (ret)
503 trace_probe_log_err(offs + 1, BAD_IMM);
504 else
505 code->op = FETCH_OP_IMM;
506 }
Masami Hiramatsu6218bf92019-06-20 00:08:27 +0900507 break;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530508 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900509 if (!ret && code->op == FETCH_OP_NOP) {
510 /* Parsed, but do not find fetch method */
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500511 trace_probe_log_err(offs, BAD_FETCH_ARG);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530512 ret = -EINVAL;
513 }
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530514 return ret;
515}
516
517#define BYTES_TO_BITS(nb) ((BITS_PER_LONG * (nb)) / sizeof(long))
518
519/* Bitfield type needs to be parsed into a fetch function */
520static int __parse_bitfield_probe_arg(const char *bf,
521 const struct fetch_type *t,
Masami Hiramatsu53305922018-04-25 21:18:03 +0900522 struct fetch_insn **pcode)
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530523{
Masami Hiramatsu53305922018-04-25 21:18:03 +0900524 struct fetch_insn *code = *pcode;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530525 unsigned long bw, bo;
526 char *tail;
527
528 if (*bf != 'b')
529 return 0;
530
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530531 bw = simple_strtoul(bf + 1, &tail, 0); /* Use simple one */
532
533 if (bw == 0 || *tail != '@')
534 return -EINVAL;
535
536 bf = tail + 1;
537 bo = simple_strtoul(bf, &tail, 0);
538
539 if (tail == bf || *tail != '/')
540 return -EINVAL;
Masami Hiramatsu53305922018-04-25 21:18:03 +0900541 code++;
542 if (code->op != FETCH_OP_NOP)
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500543 return -EINVAL;
Masami Hiramatsu53305922018-04-25 21:18:03 +0900544 *pcode = code;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530545
Masami Hiramatsu53305922018-04-25 21:18:03 +0900546 code->op = FETCH_OP_MOD_BF;
547 code->lshift = BYTES_TO_BITS(t->size) - (bw + bo);
548 code->rshift = BYTES_TO_BITS(t->size) - bw;
549 code->basesize = t->size;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530550
551 return (BYTES_TO_BITS(t->size) < (bw + bo)) ? -EINVAL : 0;
552}
553
554/* String length checking wrapper */
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400555static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500556 struct probe_arg *parg, unsigned int flags, int offset)
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530557{
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900558 struct fetch_insn *code, *scode, *tmp = NULL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500559 char *t, *t2, *t3;
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400560 char *arg;
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900561 int ret, len;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530562
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400563 arg = kstrdup(argv, GFP_KERNEL);
564 if (!arg)
565 return -ENOMEM;
566
567 ret = -EINVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500568 len = strlen(arg);
569 if (len > MAX_ARGSTR_LEN) {
570 trace_probe_log_err(offset, ARG_TOO_LONG);
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400571 goto out;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500572 } else if (len == 0) {
573 trace_probe_log_err(offset, NO_ARG_BODY);
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400574 goto out;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530575 }
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500576
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400577 ret = -ENOMEM;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530578 parg->comm = kstrdup(arg, GFP_KERNEL);
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500579 if (!parg->comm)
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400580 goto out;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500581
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400582 ret = -EINVAL;
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900583 t = strchr(arg, ':');
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530584 if (t) {
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900585 *t = '\0';
586 t2 = strchr(++t, '[');
587 if (t2) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500588 *t2++ = '\0';
589 t3 = strchr(t2, ']');
590 if (!t3) {
591 offset += t2 + strlen(t2) - arg;
592 trace_probe_log_err(offset,
593 ARRAY_NO_CLOSE);
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400594 goto out;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500595 } else if (t3[1] != '\0') {
596 trace_probe_log_err(offset + t3 + 1 - arg,
597 BAD_ARRAY_SUFFIX);
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400598 goto out;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500599 }
600 *t3 = '\0';
601 if (kstrtouint(t2, 0, &parg->count) || !parg->count) {
602 trace_probe_log_err(offset + t2 - arg,
603 BAD_ARRAY_NUM);
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400604 goto out;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500605 }
606 if (parg->count > MAX_ARRAY_LEN) {
607 trace_probe_log_err(offset + t2 - arg,
608 ARRAY_TOO_BIG);
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400609 goto out;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500610 }
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900611 }
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530612 }
Masami Hiramatsu3dd1f7f2019-05-07 22:56:02 +0900613
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900614 /*
Ingo Molnarf2cc0202021-03-23 18:49:35 +0100615 * Since $comm and immediate string can not be dereferenced,
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900616 * we can find those by strcmp.
617 */
618 if (strcmp(arg, "$comm") == 0 || strncmp(arg, "\\\"", 2) == 0) {
Masami Hiramatsu3dd1f7f2019-05-07 22:56:02 +0900619 /* The type of $comm must be "string", and not an array. */
620 if (parg->count || (t && strcmp(t, "string")))
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400621 goto out;
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900622 parg->type = find_fetch_type("string");
Masami Hiramatsu3dd1f7f2019-05-07 22:56:02 +0900623 } else
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900624 parg->type = find_fetch_type(t);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530625 if (!parg->type) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500626 trace_probe_log_err(offset + (t ? (t - arg) : 0), BAD_TYPE);
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400627 goto out;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530628 }
629 parg->offset = *size;
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900630 *size += parg->type->size * (parg->count ?: 1);
631
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400632 ret = -ENOMEM;
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900633 if (parg->count) {
634 len = strlen(parg->type->fmttype) + 6;
635 parg->fmt = kmalloc(len, GFP_KERNEL);
636 if (!parg->fmt)
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400637 goto out;
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900638 snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype,
639 parg->count);
640 }
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530641
Gustavo A. R. Silva8623b002019-01-14 22:34:08 -0600642 code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL);
Masami Hiramatsu53305922018-04-25 21:18:03 +0900643 if (!code)
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400644 goto out;
Masami Hiramatsu53305922018-04-25 21:18:03 +0900645 code[FETCH_INSN_MAX - 1].op = FETCH_OP_END;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530646
Masami Hiramatsu53305922018-04-25 21:18:03 +0900647 ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1],
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500648 flags, offset);
Masami Hiramatsu53305922018-04-25 21:18:03 +0900649 if (ret)
650 goto fail;
651
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400652 ret = -EINVAL;
Masami Hiramatsu53305922018-04-25 21:18:03 +0900653 /* Store operation */
Masami Hiramatsu88903c42019-05-15 14:38:30 +0900654 if (!strcmp(parg->type->name, "string") ||
655 !strcmp(parg->type->name, "ustring")) {
Masami Hiramatsue65f7ae2019-05-15 14:38:42 +0900656 if (code->op != FETCH_OP_DEREF && code->op != FETCH_OP_UDEREF &&
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900657 code->op != FETCH_OP_IMM && code->op != FETCH_OP_COMM &&
Tzvetomir Stoyanov (VMware)7491e2c2021-08-19 11:26:06 -0400658 code->op != FETCH_OP_DATA && code->op != FETCH_OP_TP_ARG) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500659 trace_probe_log_err(offset + (t ? (t - arg) : 0),
660 BAD_STRING);
Masami Hiramatsu53305922018-04-25 21:18:03 +0900661 goto fail;
662 }
Vamshi K Sthambamkadi3aa8fdc2020-06-15 20:00:38 +0530663 if ((code->op == FETCH_OP_IMM || code->op == FETCH_OP_COMM ||
Tzvetomir Stoyanov (VMware)7491e2c2021-08-19 11:26:06 -0400664 code->op == FETCH_OP_DATA) || code->op == FETCH_OP_TP_ARG ||
665 parg->count) {
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900666 /*
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900667 * IMM, DATA and COMM is pointing actual address, those
668 * must be kept, and if parg->count != 0, this is an
669 * array of string pointers instead of string address
670 * itself.
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900671 */
Masami Hiramatsu53305922018-04-25 21:18:03 +0900672 code++;
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900673 if (code->op != FETCH_OP_NOP) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500674 trace_probe_log_err(offset, TOO_MANY_OPS);
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900675 goto fail;
676 }
677 }
Masami Hiramatsu88903c42019-05-15 14:38:30 +0900678 /* If op == DEREF, replace it with STRING */
Masami Hiramatsue65f7ae2019-05-15 14:38:42 +0900679 if (!strcmp(parg->type->name, "ustring") ||
680 code->op == FETCH_OP_UDEREF)
Masami Hiramatsu88903c42019-05-15 14:38:30 +0900681 code->op = FETCH_OP_ST_USTRING;
682 else
683 code->op = FETCH_OP_ST_STRING;
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900684 code->size = parg->type->size;
Masami Hiramatsu53305922018-04-25 21:18:03 +0900685 parg->dynamic = true;
686 } else if (code->op == FETCH_OP_DEREF) {
687 code->op = FETCH_OP_ST_MEM;
688 code->size = parg->type->size;
Masami Hiramatsue65f7ae2019-05-15 14:38:42 +0900689 } else if (code->op == FETCH_OP_UDEREF) {
690 code->op = FETCH_OP_ST_UMEM;
691 code->size = parg->type->size;
Masami Hiramatsu53305922018-04-25 21:18:03 +0900692 } else {
693 code++;
694 if (code->op != FETCH_OP_NOP) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500695 trace_probe_log_err(offset, TOO_MANY_OPS);
Masami Hiramatsu53305922018-04-25 21:18:03 +0900696 goto fail;
697 }
698 code->op = FETCH_OP_ST_RAW;
699 code->size = parg->type->size;
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530700 }
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900701 scode = code;
Masami Hiramatsu53305922018-04-25 21:18:03 +0900702 /* Modify operation */
703 if (t != NULL) {
704 ret = __parse_bitfield_probe_arg(t, parg->type, &code);
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500705 if (ret) {
706 trace_probe_log_err(offset + t - arg, BAD_BITFIELD);
Masami Hiramatsu53305922018-04-25 21:18:03 +0900707 goto fail;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500708 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900709 }
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400710 ret = -EINVAL;
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900711 /* Loop(Array) operation */
712 if (parg->count) {
713 if (scode->op != FETCH_OP_ST_MEM &&
Masami Hiramatsu88903c42019-05-15 14:38:30 +0900714 scode->op != FETCH_OP_ST_STRING &&
715 scode->op != FETCH_OP_ST_USTRING) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500716 trace_probe_log_err(offset + (t ? (t - arg) : 0),
717 BAD_STRING);
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900718 goto fail;
719 }
720 code++;
721 if (code->op != FETCH_OP_NOP) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500722 trace_probe_log_err(offset, TOO_MANY_OPS);
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900723 goto fail;
724 }
725 code->op = FETCH_OP_LP_ARRAY;
726 code->param = parg->count;
727 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900728 code++;
729 code->op = FETCH_OP_END;
730
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400731 ret = 0;
Masami Hiramatsu53305922018-04-25 21:18:03 +0900732 /* Shrink down the code buffer */
Gustavo A. R. Silva8623b002019-01-14 22:34:08 -0600733 parg->code = kcalloc(code - tmp + 1, sizeof(*code), GFP_KERNEL);
Masami Hiramatsu53305922018-04-25 21:18:03 +0900734 if (!parg->code)
735 ret = -ENOMEM;
736 else
737 memcpy(parg->code, tmp, sizeof(*code) * (code - tmp + 1));
738
739fail:
Masami Hiramatsua6682812018-08-29 01:18:43 +0900740 if (ret) {
741 for (code = tmp; code < tmp + FETCH_INSN_MAX; code++)
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900742 if (code->op == FETCH_NOP_SYMBOL ||
743 code->op == FETCH_OP_DATA)
Masami Hiramatsua6682812018-08-29 01:18:43 +0900744 kfree(code->data);
745 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900746 kfree(tmp);
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400747out:
748 kfree(arg);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530749
750 return ret;
751}
752
753/* Return 1 if name is reserved or already used by another argument */
Masami Hiramatsud00bbea92018-11-05 18:01:40 +0900754static int traceprobe_conflict_field_name(const char *name,
755 struct probe_arg *args, int narg)
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530756{
757 int i;
758
759 for (i = 0; i < ARRAY_SIZE(reserved_field_names); i++)
760 if (strcmp(reserved_field_names[i], name) == 0)
761 return 1;
762
763 for (i = 0; i < narg; i++)
764 if (strcmp(args[i].name, name) == 0)
765 return 1;
766
767 return 0;
768}
769
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400770int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char *arg,
Masami Hiramatsud00bbea92018-11-05 18:01:40 +0900771 unsigned int flags)
772{
773 struct probe_arg *parg = &tp->args[i];
Steven Rostedt (VMware)fcd9db52021-08-16 23:42:58 -0400774 const char *body;
Masami Hiramatsud00bbea92018-11-05 18:01:40 +0900775
776 /* Increment count for freeing args in error case */
777 tp->nr_args++;
778
779 body = strchr(arg, '=');
780 if (body) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500781 if (body - arg > MAX_ARG_NAME_LEN) {
782 trace_probe_log_err(0, ARG_NAME_TOO_LONG);
Masami Hiramatsub4443c12019-03-14 13:30:30 +0900783 return -EINVAL;
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500784 } else if (body == arg) {
785 trace_probe_log_err(0, NO_ARG_NAME);
786 return -EINVAL;
787 }
Masami Hiramatsud00bbea92018-11-05 18:01:40 +0900788 parg->name = kmemdup_nul(arg, body - arg, GFP_KERNEL);
789 body++;
790 } else {
791 /* If argument name is omitted, set "argN" */
792 parg->name = kasprintf(GFP_KERNEL, "arg%d", i + 1);
793 body = arg;
794 }
795 if (!parg->name)
796 return -ENOMEM;
797
798 if (!is_good_name(parg->name)) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500799 trace_probe_log_err(0, BAD_ARG_NAME);
Masami Hiramatsud00bbea92018-11-05 18:01:40 +0900800 return -EINVAL;
801 }
Masami Hiramatsud00bbea92018-11-05 18:01:40 +0900802 if (traceprobe_conflict_field_name(parg->name, tp->args, i)) {
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500803 trace_probe_log_err(0, USED_ARG_NAME);
Masami Hiramatsud00bbea92018-11-05 18:01:40 +0900804 return -EINVAL;
805 }
Masami Hiramatsud00bbea92018-11-05 18:01:40 +0900806 /* Parse fetch argument */
Masami Hiramatsuab105a42019-03-31 18:48:19 -0500807 return traceprobe_parse_probe_arg_body(body, &tp->size, parg, flags,
808 body - arg);
Masami Hiramatsud00bbea92018-11-05 18:01:40 +0900809}
810
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530811void traceprobe_free_probe_arg(struct probe_arg *arg)
812{
Masami Hiramatsua6682812018-08-29 01:18:43 +0900813 struct fetch_insn *code = arg->code;
814
815 while (code && code->op != FETCH_OP_END) {
Masami Hiramatsua42e3c42019-06-20 00:08:37 +0900816 if (code->op == FETCH_NOP_SYMBOL ||
817 code->op == FETCH_OP_DATA)
Masami Hiramatsua6682812018-08-29 01:18:43 +0900818 kfree(code->data);
819 code++;
820 }
Masami Hiramatsu53305922018-04-25 21:18:03 +0900821 kfree(arg->code);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530822 kfree(arg->name);
823 kfree(arg->comm);
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900824 kfree(arg->fmt);
Srikar Dronamraju8ab83f52012-04-09 14:41:44 +0530825}
826
Masami Hiramatsua6682812018-08-29 01:18:43 +0900827int traceprobe_update_arg(struct probe_arg *arg)
828{
829 struct fetch_insn *code = arg->code;
830 long offset;
831 char *tmp;
832 char c;
833 int ret = 0;
834
835 while (code && code->op != FETCH_OP_END) {
836 if (code->op == FETCH_NOP_SYMBOL) {
837 if (code[1].op != FETCH_OP_IMM)
838 return -EINVAL;
839
Masami Hiramatsuee474b82018-11-01 23:29:28 +0900840 tmp = strpbrk(code->data, "+-");
Masami Hiramatsua6682812018-08-29 01:18:43 +0900841 if (tmp)
842 c = *tmp;
843 ret = traceprobe_split_symbol_offset(code->data,
844 &offset);
845 if (ret)
846 return ret;
847
848 code[1].immediate =
849 (unsigned long)kallsyms_lookup_name(code->data);
850 if (tmp)
851 *tmp = c;
852 if (!code[1].immediate)
853 return -ENOENT;
854 code[1].immediate += offset;
855 }
856 code++;
857 }
858 return 0;
859}
860
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900861/* When len=0, we just calculate the needed length */
862#define LEN_OR_ZERO (len ? len - pos : 0)
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900863static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,
Steven Rostedt (VMware)007517a2021-08-19 00:13:27 -0400864 enum probe_print_type ptype)
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900865{
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900866 struct probe_arg *parg;
867 int i, j;
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900868 int pos = 0;
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900869 const char *fmt, *arg;
870
Steven Rostedt (VMware)007517a2021-08-19 00:13:27 -0400871 switch (ptype) {
872 case PROBE_PRINT_NORMAL:
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900873 fmt = "(%lx)";
874 arg = "REC->" FIELD_STRING_IP;
Steven Rostedt (VMware)007517a2021-08-19 00:13:27 -0400875 break;
876 case PROBE_PRINT_RETURN:
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900877 fmt = "(%lx <- %lx)";
878 arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
Steven Rostedt (VMware)007517a2021-08-19 00:13:27 -0400879 break;
Tzvetomir Stoyanov (VMware)7491e2c2021-08-19 11:26:06 -0400880 case PROBE_PRINT_EVENT:
881 fmt = "(%u)";
882 arg = "REC->" FIELD_STRING_TYPE;
883 break;
Steven Rostedt (VMware)007517a2021-08-19 00:13:27 -0400884 default:
885 WARN_ON_ONCE(1);
886 return 0;
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900887 }
888
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900889 pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
890
891 for (i = 0; i < tp->nr_args; i++) {
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900892 parg = tp->args + i;
893 pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=", parg->name);
894 if (parg->count) {
895 pos += snprintf(buf + pos, LEN_OR_ZERO, "{%s",
896 parg->type->fmt);
897 for (j = 1; j < parg->count; j++)
898 pos += snprintf(buf + pos, LEN_OR_ZERO, ",%s",
899 parg->type->fmt);
900 pos += snprintf(buf + pos, LEN_OR_ZERO, "}");
901 } else
902 pos += snprintf(buf + pos, LEN_OR_ZERO, "%s",
903 parg->type->fmt);
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900904 }
905
906 pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
907
908 for (i = 0; i < tp->nr_args; i++) {
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900909 parg = tp->args + i;
910 if (parg->count) {
Steven Rostedt (VMware)20279422020-01-24 10:07:42 -0500911 if ((strcmp(parg->type->name, "string") == 0) ||
912 (strcmp(parg->type->name, "ustring") == 0))
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900913 fmt = ", __get_str(%s[%d])";
914 else
915 fmt = ", REC->%s[%d]";
916 for (j = 0; j < parg->count; j++)
917 pos += snprintf(buf + pos, LEN_OR_ZERO,
918 fmt, parg->name, j);
919 } else {
Steven Rostedt (VMware)20279422020-01-24 10:07:42 -0500920 if ((strcmp(parg->type->name, "string") == 0) ||
921 (strcmp(parg->type->name, "ustring") == 0))
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900922 fmt = ", __get_str(%s)";
923 else
924 fmt = ", REC->%s";
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900925 pos += snprintf(buf + pos, LEN_OR_ZERO,
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900926 fmt, parg->name);
927 }
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900928 }
929
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900930 /* return the length of print_fmt */
931 return pos;
932}
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900933#undef LEN_OR_ZERO
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900934
Steven Rostedt (VMware)007517a2021-08-19 00:13:27 -0400935int traceprobe_set_print_fmt(struct trace_probe *tp, enum probe_print_type ptype)
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900936{
Masami Hiramatsue3dc9f82019-06-01 00:17:57 +0900937 struct trace_event_call *call = trace_probe_event_call(tp);
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900938 int len;
939 char *print_fmt;
940
941 /* First: called with 0 length to calculate the needed length */
Steven Rostedt (VMware)007517a2021-08-19 00:13:27 -0400942 len = __set_print_fmt(tp, NULL, 0, ptype);
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900943 print_fmt = kmalloc(len + 1, GFP_KERNEL);
944 if (!print_fmt)
945 return -ENOMEM;
946
947 /* Second: actually write the @print_fmt */
Steven Rostedt (VMware)007517a2021-08-19 00:13:27 -0400948 __set_print_fmt(tp, print_fmt, len + 1, ptype);
Masami Hiramatsue3dc9f82019-06-01 00:17:57 +0900949 call->print_fmt = print_fmt;
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900950
951 return 0;
952}
Masami Hiramatsueeb07b02018-04-25 21:17:05 +0900953
954int traceprobe_define_arg_fields(struct trace_event_call *event_call,
955 size_t offset, struct trace_probe *tp)
956{
957 int ret, i;
958
959 /* Set argument names as fields */
960 for (i = 0; i < tp->nr_args; i++) {
961 struct probe_arg *parg = &tp->args[i];
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900962 const char *fmt = parg->type->fmttype;
963 int size = parg->type->size;
Masami Hiramatsueeb07b02018-04-25 21:17:05 +0900964
Masami Hiramatsu40b53b72018-04-25 21:21:55 +0900965 if (parg->fmt)
966 fmt = parg->fmt;
967 if (parg->count)
968 size *= parg->count;
969 ret = trace_define_field(event_call, fmt, parg->name,
970 offset + parg->offset, size,
Masami Hiramatsueeb07b02018-04-25 21:17:05 +0900971 parg->type->is_signed,
972 FILTER_OTHER);
973 if (ret)
974 return ret;
975 }
976 return 0;
977}
Masami Hiramatsu455b2892019-06-01 00:17:06 +0900978
Masami Hiramatsuca89bc02019-06-20 00:07:49 +0900979static void trace_probe_event_free(struct trace_probe_event *tpe)
980{
981 kfree(tpe->class.system);
982 kfree(tpe->call.name);
983 kfree(tpe->call.print_fmt);
984 kfree(tpe);
985}
986
987int trace_probe_append(struct trace_probe *tp, struct trace_probe *to)
988{
989 if (trace_probe_has_sibling(tp))
990 return -EBUSY;
991
992 list_del_init(&tp->list);
993 trace_probe_event_free(tp->event);
994
995 tp->event = to->event;
996 list_add_tail(&tp->list, trace_probe_probe_list(to));
997
998 return 0;
999}
1000
1001void trace_probe_unlink(struct trace_probe *tp)
1002{
1003 list_del_init(&tp->list);
1004 if (list_empty(trace_probe_probe_list(tp)))
1005 trace_probe_event_free(tp->event);
1006 tp->event = NULL;
1007}
Masami Hiramatsu455b2892019-06-01 00:17:06 +09001008
1009void trace_probe_cleanup(struct trace_probe *tp)
1010{
1011 int i;
1012
1013 for (i = 0; i < tp->nr_args; i++)
1014 traceprobe_free_probe_arg(&tp->args[i]);
1015
Masami Hiramatsuca89bc02019-06-20 00:07:49 +09001016 if (tp->event)
1017 trace_probe_unlink(tp);
Masami Hiramatsu455b2892019-06-01 00:17:06 +09001018}
1019
1020int trace_probe_init(struct trace_probe *tp, const char *event,
Masami Hiramatsub61387c2020-01-22 12:23:25 +09001021 const char *group, bool alloc_filter)
Masami Hiramatsu455b2892019-06-01 00:17:06 +09001022{
Masami Hiramatsu60d53e22019-06-20 00:07:20 +09001023 struct trace_event_call *call;
Masami Hiramatsub61387c2020-01-22 12:23:25 +09001024 size_t size = sizeof(struct trace_probe_event);
Masami Hiramatsu60d53e22019-06-20 00:07:20 +09001025 int ret = 0;
Masami Hiramatsue3dc9f82019-06-01 00:17:57 +09001026
Masami Hiramatsu455b2892019-06-01 00:17:06 +09001027 if (!event || !group)
1028 return -EINVAL;
1029
Masami Hiramatsub61387c2020-01-22 12:23:25 +09001030 if (alloc_filter)
1031 size += sizeof(struct trace_uprobe_filter);
1032
1033 tp->event = kzalloc(size, GFP_KERNEL);
Masami Hiramatsu60d53e22019-06-20 00:07:20 +09001034 if (!tp->event)
Masami Hiramatsu455b2892019-06-01 00:17:06 +09001035 return -ENOMEM;
1036
Masami Hiramatsud59fae62019-09-17 14:11:37 +09001037 INIT_LIST_HEAD(&tp->event->files);
1038 INIT_LIST_HEAD(&tp->event->class.fields);
1039 INIT_LIST_HEAD(&tp->event->probes);
1040 INIT_LIST_HEAD(&tp->list);
Julia Lawallfc9d2762020-05-07 21:30:08 +02001041 list_add(&tp->list, &tp->event->probes);
Masami Hiramatsud59fae62019-09-17 14:11:37 +09001042
Masami Hiramatsu60d53e22019-06-20 00:07:20 +09001043 call = trace_probe_event_call(tp);
1044 call->class = &tp->event->class;
1045 call->name = kstrdup(event, GFP_KERNEL);
1046 if (!call->name) {
1047 ret = -ENOMEM;
1048 goto error;
Masami Hiramatsu455b2892019-06-01 00:17:06 +09001049 }
Masami Hiramatsu60d53e22019-06-20 00:07:20 +09001050
1051 tp->event->class.system = kstrdup(group, GFP_KERNEL);
1052 if (!tp->event->class.system) {
1053 ret = -ENOMEM;
1054 goto error;
1055 }
Masami Hiramatsu455b2892019-06-01 00:17:06 +09001056
1057 return 0;
Masami Hiramatsu60d53e22019-06-20 00:07:20 +09001058
1059error:
1060 trace_probe_cleanup(tp);
1061 return ret;
Masami Hiramatsu455b2892019-06-01 00:17:06 +09001062}
Masami Hiramatsu46e53762019-06-01 00:17:16 +09001063
Masami Hiramatsu8e242062021-08-19 19:26:02 +09001064static struct trace_event_call *
1065find_trace_event_call(const char *system, const char *event_name)
1066{
1067 struct trace_event_call *tp_event;
1068 const char *name;
1069
1070 list_for_each_entry(tp_event, &ftrace_events, list) {
1071 if (!tp_event->class->system ||
1072 strcmp(system, tp_event->class->system))
1073 continue;
1074 name = trace_event_name(tp_event);
1075 if (!name || strcmp(event_name, name))
1076 continue;
1077 return tp_event;
1078 }
1079
1080 return NULL;
1081}
1082
Masami Hiramatsu46e53762019-06-01 00:17:16 +09001083int trace_probe_register_event_call(struct trace_probe *tp)
1084{
Masami Hiramatsue3dc9f82019-06-01 00:17:57 +09001085 struct trace_event_call *call = trace_probe_event_call(tp);
Masami Hiramatsu46e53762019-06-01 00:17:16 +09001086 int ret;
1087
Masami Hiramatsu8e242062021-08-19 19:26:02 +09001088 lockdep_assert_held(&event_mutex);
1089
1090 if (find_trace_event_call(trace_probe_group_name(tp),
1091 trace_probe_name(tp)))
1092 return -EEXIST;
1093
Masami Hiramatsu46e53762019-06-01 00:17:16 +09001094 ret = register_trace_event(&call->event);
1095 if (!ret)
1096 return -ENODEV;
1097
1098 ret = trace_add_event_call(call);
1099 if (ret)
1100 unregister_trace_event(&call->event);
1101
1102 return ret;
1103}
Masami Hiramatsub5f935e2019-06-01 00:17:26 +09001104
1105int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file)
1106{
1107 struct event_file_link *link;
1108
1109 link = kmalloc(sizeof(*link), GFP_KERNEL);
1110 if (!link)
1111 return -ENOMEM;
1112
1113 link->file = file;
1114 INIT_LIST_HEAD(&link->list);
Masami Hiramatsu60d53e22019-06-20 00:07:20 +09001115 list_add_tail_rcu(&link->list, &tp->event->files);
Masami Hiramatsu747774d2019-06-01 00:17:37 +09001116 trace_probe_set_flag(tp, TP_FLAG_TRACE);
Masami Hiramatsub5f935e2019-06-01 00:17:26 +09001117 return 0;
1118}
1119
1120struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
1121 struct trace_event_file *file)
1122{
1123 struct event_file_link *link;
1124
1125 trace_probe_for_each_link(link, tp) {
1126 if (link->file == file)
1127 return link;
1128 }
1129
1130 return NULL;
1131}
1132
1133int trace_probe_remove_file(struct trace_probe *tp,
1134 struct trace_event_file *file)
1135{
1136 struct event_file_link *link;
1137
1138 link = trace_probe_get_file_link(tp, file);
1139 if (!link)
1140 return -ENOENT;
1141
1142 list_del_rcu(&link->list);
Uladzislau Rezki (Sony)a6ed2ae2021-11-24 12:03:08 +01001143 kvfree_rcu(link);
Masami Hiramatsub5f935e2019-06-01 00:17:26 +09001144
Masami Hiramatsu60d53e22019-06-20 00:07:20 +09001145 if (list_empty(&tp->event->files))
Masami Hiramatsu747774d2019-06-01 00:17:37 +09001146 trace_probe_clear_flag(tp, TP_FLAG_TRACE);
Masami Hiramatsub5f935e2019-06-01 00:17:26 +09001147
1148 return 0;
1149}
Masami Hiramatsuca89bc02019-06-20 00:07:49 +09001150
1151/*
1152 * Return the smallest index of different type argument (start from 1).
1153 * If all argument types and name are same, return 0.
1154 */
1155int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b)
1156{
1157 int i;
1158
Masami Hiramatsud2aea952019-09-28 05:53:29 -04001159 /* In case of more arguments */
1160 if (a->nr_args < b->nr_args)
1161 return a->nr_args + 1;
1162 if (a->nr_args > b->nr_args)
1163 return b->nr_args + 1;
1164
Masami Hiramatsuca89bc02019-06-20 00:07:49 +09001165 for (i = 0; i < a->nr_args; i++) {
1166 if ((b->nr_args <= i) ||
1167 ((a->args[i].type != b->args[i].type) ||
1168 (a->args[i].count != b->args[i].count) ||
1169 strcmp(a->args[i].name, b->args[i].name)))
1170 return i + 1;
1171 }
1172
1173 return 0;
1174}
Masami Hiramatsueb5bf812019-06-20 00:08:08 +09001175
1176bool trace_probe_match_command_args(struct trace_probe *tp,
1177 int argc, const char **argv)
1178{
1179 char buf[MAX_ARGSTR_LEN + 1];
1180 int i;
1181
1182 if (tp->nr_args < argc)
1183 return false;
1184
1185 for (i = 0; i < argc; i++) {
1186 snprintf(buf, sizeof(buf), "%s=%s",
1187 tp->args[i].name, tp->args[i].comm);
1188 if (strcmp(buf, argv[i]))
1189 return false;
1190 }
1191 return true;
1192}
Masami Hiramatsud2622712021-02-01 13:48:11 -06001193
1194int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **))
1195{
1196 int argc = 0, ret = 0;
1197 char **argv;
1198
1199 argv = argv_split(GFP_KERNEL, raw_command, &argc);
1200 if (!argv)
1201 return -ENOMEM;
1202
1203 if (argc)
1204 ret = createfn(argc, (const char **)argv);
1205
1206 argv_free(argv);
1207
1208 return ret;
1209}