Steven Rostedt (VMware) | bcea3f9 | 2018-08-16 11:23:53 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Common code for probe-based Dynamic events. |
| 4 | * |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 5 | * 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 Hiramatsu | 7257634 | 2017-02-07 20:21:28 +0900 | [diff] [blame] | 12 | #define pr_fmt(fmt) "trace_probe: " fmt |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 13 | |
| 14 | #include "trace_probe.h" |
| 15 | |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 16 | #undef C |
| 17 | #define C(a, b) b |
| 18 | |
| 19 | static const char *trace_probe_err_text[] = { ERRORS }; |
| 20 | |
Valdis Klētnieks | 0841625 | 2019-03-12 04:52:58 -0400 | [diff] [blame] | 21 | static const char *reserved_field_names[] = { |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 22 | "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 Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 32 | /* Printing in basic type function template */ |
Masami Hiramatsu | 17ce3dc | 2016-08-18 17:57:50 +0900 | [diff] [blame] | 33 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt) \ |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 34 | int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 35 | { \ |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 36 | trace_seq_printf(s, fmt, *(type *)data); \ |
Steven Rostedt (Red Hat) | d2b0191 | 2014-11-12 17:19:51 -0500 | [diff] [blame] | 37 | return !trace_seq_has_overflowed(s); \ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 38 | } \ |
Masami Hiramatsu | 7bfbc63 | 2018-04-25 21:17:34 +0900 | [diff] [blame] | 39 | const char PRINT_TYPE_FMT_NAME(tname)[] = fmt; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 40 | |
Masami Hiramatsu | bdca79c2 | 2016-08-18 17:59:21 +0900 | [diff] [blame] | 41 | DEFINE_BASIC_PRINT_TYPE_FUNC(u8, u8, "%u") |
| 42 | DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "%u") |
| 43 | DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "%u") |
| 44 | DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "%Lu") |
Masami Hiramatsu | 17ce3dc | 2016-08-18 17:57:50 +0900 | [diff] [blame] | 45 | DEFINE_BASIC_PRINT_TYPE_FUNC(s8, s8, "%d") |
| 46 | DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d") |
| 47 | DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d") |
| 48 | DEFINE_BASIC_PRINT_TYPE_FUNC(s64, s64, "%Ld") |
| 49 | DEFINE_BASIC_PRINT_TYPE_FUNC(x8, u8, "0x%x") |
| 50 | DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x") |
| 51 | DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x") |
| 52 | DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx") |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 53 | |
Masami Hiramatsu | 60c2e0c | 2018-04-25 21:20:28 +0900 | [diff] [blame] | 54 | int 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 | } |
| 59 | const char PRINT_TYPE_FMT_NAME(symbol)[] = "%pS"; |
| 60 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 61 | /* Print type function for string type */ |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 62 | int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 63 | { |
| 64 | int len = *(u32 *)data >> 16; |
| 65 | |
| 66 | if (!len) |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 67 | trace_seq_puts(s, "(fault)"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 68 | else |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 69 | trace_seq_printf(s, "\"%s\"", |
Steven Rostedt (Red Hat) | d2b0191 | 2014-11-12 17:19:51 -0500 | [diff] [blame] | 70 | (const char *)get_loc_data(data, ent)); |
| 71 | return !trace_seq_has_overflowed(s); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 72 | } |
| 73 | |
Namhyung Kim | b26c74e | 2013-11-26 14:19:59 +0900 | [diff] [blame] | 74 | const char PRINT_TYPE_FMT_NAME(string)[] = "\\\"%s\\\""; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 75 | |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 76 | /* Fetch type information table */ |
| 77 | static const struct fetch_type probe_fetch_types[] = { |
| 78 | /* Special types */ |
| 79 | __ASSIGN_FETCH_TYPE("string", string, string, sizeof(u32), 1, |
| 80 | "__data_loc char[]"), |
| 81 | /* Basic types */ |
| 82 | ASSIGN_FETCH_TYPE(u8, u8, 0), |
| 83 | ASSIGN_FETCH_TYPE(u16, u16, 0), |
| 84 | ASSIGN_FETCH_TYPE(u32, u32, 0), |
| 85 | ASSIGN_FETCH_TYPE(u64, u64, 0), |
| 86 | ASSIGN_FETCH_TYPE(s8, u8, 1), |
| 87 | ASSIGN_FETCH_TYPE(s16, u16, 1), |
| 88 | ASSIGN_FETCH_TYPE(s32, u32, 1), |
| 89 | ASSIGN_FETCH_TYPE(s64, u64, 1), |
| 90 | ASSIGN_FETCH_TYPE_ALIAS(x8, u8, u8, 0), |
| 91 | ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0), |
| 92 | ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0), |
| 93 | ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0), |
Masami Hiramatsu | 60c2e0c | 2018-04-25 21:20:28 +0900 | [diff] [blame] | 94 | ASSIGN_FETCH_TYPE_ALIAS(symbol, ADDR_FETCH_TYPE, ADDR_FETCH_TYPE, 0), |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 95 | |
| 96 | ASSIGN_FETCH_TYPE_END |
| 97 | }; |
| 98 | |
| 99 | static const struct fetch_type *find_fetch_type(const char *type) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 100 | { |
| 101 | int i; |
| 102 | |
| 103 | if (!type) |
| 104 | type = DEFAULT_FETCH_TYPE_STR; |
| 105 | |
| 106 | /* Special case: bitfield */ |
| 107 | if (*type == 'b') { |
| 108 | unsigned long bs; |
| 109 | |
| 110 | type = strchr(type, '/'); |
| 111 | if (!type) |
| 112 | goto fail; |
| 113 | |
| 114 | type++; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 115 | if (kstrtoul(type, 0, &bs)) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 116 | goto fail; |
| 117 | |
| 118 | switch (bs) { |
| 119 | case 8: |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 120 | return find_fetch_type("u8"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 121 | case 16: |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 122 | return find_fetch_type("u16"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 123 | case 32: |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 124 | return find_fetch_type("u32"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 125 | case 64: |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 126 | return find_fetch_type("u64"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 127 | default: |
| 128 | goto fail; |
| 129 | } |
| 130 | } |
| 131 | |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 132 | for (i = 0; probe_fetch_types[i].name; i++) { |
| 133 | if (strcmp(type, probe_fetch_types[i].name) == 0) |
| 134 | return &probe_fetch_types[i]; |
Namhyung Kim | 34fee3a | 2013-11-26 14:56:28 +0900 | [diff] [blame] | 135 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 136 | |
| 137 | fail: |
| 138 | return NULL; |
| 139 | } |
| 140 | |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 141 | static struct trace_probe_log trace_probe_log; |
| 142 | |
| 143 | void trace_probe_log_init(const char *subsystem, int argc, const char **argv) |
| 144 | { |
| 145 | trace_probe_log.subsystem = subsystem; |
| 146 | trace_probe_log.argc = argc; |
| 147 | trace_probe_log.argv = argv; |
| 148 | trace_probe_log.index = 0; |
| 149 | } |
| 150 | |
| 151 | void trace_probe_log_clear(void) |
| 152 | { |
| 153 | memset(&trace_probe_log, 0, sizeof(trace_probe_log)); |
| 154 | } |
| 155 | |
| 156 | void trace_probe_log_set_index(int index) |
| 157 | { |
| 158 | trace_probe_log.index = index; |
| 159 | } |
| 160 | |
| 161 | void __trace_probe_log_err(int offset, int err_type) |
| 162 | { |
| 163 | char *command, *p; |
| 164 | int i, len = 0, pos = 0; |
| 165 | |
| 166 | if (!trace_probe_log.argv) |
| 167 | return; |
| 168 | |
| 169 | /* Recalcurate the length and allocate buffer */ |
| 170 | for (i = 0; i < trace_probe_log.argc; i++) { |
| 171 | if (i == trace_probe_log.index) |
| 172 | pos = len; |
| 173 | len += strlen(trace_probe_log.argv[i]) + 1; |
| 174 | } |
| 175 | command = kzalloc(len, GFP_KERNEL); |
| 176 | if (!command) |
| 177 | return; |
| 178 | |
| 179 | /* And make a command string from argv array */ |
| 180 | p = command; |
| 181 | for (i = 0; i < trace_probe_log.argc; i++) { |
| 182 | len = strlen(trace_probe_log.argv[i]); |
| 183 | strcpy(p, trace_probe_log.argv[i]); |
| 184 | p[len] = ' '; |
| 185 | p += len + 1; |
| 186 | } |
| 187 | *(p - 1) = '\0'; |
| 188 | |
Steven Rostedt (VMware) | 2f754e7 | 2019-04-01 22:52:21 -0400 | [diff] [blame] | 189 | tracing_log_err(NULL, trace_probe_log.subsystem, command, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 190 | trace_probe_err_text, err_type, pos + offset); |
| 191 | |
| 192 | kfree(command); |
| 193 | } |
| 194 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 195 | /* Split symbol and offset. */ |
Masami Hiramatsu | c5d343b | 2018-03-17 21:38:10 +0900 | [diff] [blame] | 196 | int traceprobe_split_symbol_offset(char *symbol, long *offset) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 197 | { |
| 198 | char *tmp; |
| 199 | int ret; |
| 200 | |
| 201 | if (!offset) |
| 202 | return -EINVAL; |
| 203 | |
Masami Hiramatsu | c5d343b | 2018-03-17 21:38:10 +0900 | [diff] [blame] | 204 | tmp = strpbrk(symbol, "+-"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 205 | if (tmp) { |
Masami Hiramatsu | c5d343b | 2018-03-17 21:38:10 +0900 | [diff] [blame] | 206 | ret = kstrtol(tmp, 0, offset); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 207 | if (ret) |
| 208 | return ret; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 209 | *tmp = '\0'; |
| 210 | } else |
| 211 | *offset = 0; |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 216 | /* @buf must has MAX_EVENT_NAME_LEN size */ |
| 217 | int traceprobe_parse_event_name(const char **pevent, const char **pgroup, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 218 | char *buf, int offset) |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 219 | { |
| 220 | const char *slash, *event = *pevent; |
Masami Hiramatsu | dec65d79 | 2019-03-14 13:30:20 +0900 | [diff] [blame] | 221 | int len; |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 222 | |
| 223 | slash = strchr(event, '/'); |
| 224 | if (slash) { |
| 225 | if (slash == event) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 226 | trace_probe_log_err(offset, NO_GROUP_NAME); |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 227 | return -EINVAL; |
| 228 | } |
| 229 | if (slash - event + 1 > MAX_EVENT_NAME_LEN) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 230 | trace_probe_log_err(offset, GROUP_TOO_LONG); |
| 231 | return -EINVAL; |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 232 | } |
| 233 | strlcpy(buf, event, slash - event + 1); |
Masami Hiramatsu | 5b7a962 | 2019-03-14 13:30:40 +0900 | [diff] [blame] | 234 | if (!is_good_name(buf)) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 235 | trace_probe_log_err(offset, BAD_GROUP_NAME); |
Masami Hiramatsu | 5b7a962 | 2019-03-14 13:30:40 +0900 | [diff] [blame] | 236 | return -EINVAL; |
| 237 | } |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 238 | *pgroup = buf; |
| 239 | *pevent = slash + 1; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 240 | offset += slash - event + 1; |
Masami Hiramatsu | dec65d79 | 2019-03-14 13:30:20 +0900 | [diff] [blame] | 241 | event = *pevent; |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 242 | } |
Masami Hiramatsu | dec65d79 | 2019-03-14 13:30:20 +0900 | [diff] [blame] | 243 | len = strlen(event); |
| 244 | if (len == 0) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 245 | trace_probe_log_err(offset, NO_EVENT_NAME); |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 246 | return -EINVAL; |
Masami Hiramatsu | dec65d79 | 2019-03-14 13:30:20 +0900 | [diff] [blame] | 247 | } else if (len > MAX_EVENT_NAME_LEN) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 248 | trace_probe_log_err(offset, EVENT_TOO_LONG); |
| 249 | return -EINVAL; |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 250 | } |
Masami Hiramatsu | 5b7a962 | 2019-03-14 13:30:40 +0900 | [diff] [blame] | 251 | if (!is_good_name(event)) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 252 | trace_probe_log_err(offset, BAD_EVENT_NAME); |
Masami Hiramatsu | 5b7a962 | 2019-03-14 13:30:40 +0900 | [diff] [blame] | 253 | return -EINVAL; |
| 254 | } |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 258 | #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long)) |
| 259 | |
| 260 | static int parse_probe_vars(char *arg, const struct fetch_type *t, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 261 | struct fetch_insn *code, unsigned int flags, int offs) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 262 | { |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 263 | unsigned long param; |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 264 | int ret = 0; |
| 265 | int len; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 266 | |
| 267 | if (strcmp(arg, "retval") == 0) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 268 | if (flags & TPARG_FL_RETURN) { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 269 | code->op = FETCH_OP_RETVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 270 | } else { |
| 271 | trace_probe_log_err(offs, RETVAL_ON_PROBE); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 272 | ret = -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 273 | } |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 274 | } else if ((len = str_has_prefix(arg, "stack"))) { |
| 275 | if (arg[len] == '\0') { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 276 | code->op = FETCH_OP_STACKP; |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 277 | } else if (isdigit(arg[len])) { |
| 278 | ret = kstrtoul(arg + len, 10, ¶m); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 279 | if (ret) { |
| 280 | goto inval_var; |
| 281 | } else if ((flags & TPARG_FL_KERNEL) && |
| 282 | param > PARAM_MAX_STACK) { |
| 283 | trace_probe_log_err(offs, BAD_STACK_NUM); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 284 | ret = -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 285 | } else { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 286 | code->op = FETCH_OP_STACK; |
| 287 | code->param = (unsigned int)param; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 288 | } |
| 289 | } else |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 290 | goto inval_var; |
Omar Sandoval | 35abb67 | 2016-06-08 18:38:02 -0700 | [diff] [blame] | 291 | } else if (strcmp(arg, "comm") == 0) { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 292 | code->op = FETCH_OP_COMM; |
Masami Hiramatsu | a1303af | 2018-04-25 21:21:26 +0900 | [diff] [blame] | 293 | #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API |
| 294 | } else if (((flags & TPARG_FL_MASK) == |
| 295 | (TPARG_FL_KERNEL | TPARG_FL_FENTRY)) && |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 296 | (len = str_has_prefix(arg, "arg"))) { |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 297 | ret = kstrtoul(arg + len, 10, ¶m); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 298 | if (ret) { |
| 299 | goto inval_var; |
| 300 | } else if (!param || param > PARAM_MAX_STACK) { |
| 301 | trace_probe_log_err(offs, BAD_ARG_NUM); |
Masami Hiramatsu | a1303af | 2018-04-25 21:21:26 +0900 | [diff] [blame] | 302 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 303 | } |
Masami Hiramatsu | a1303af | 2018-04-25 21:21:26 +0900 | [diff] [blame] | 304 | code->op = FETCH_OP_ARG; |
| 305 | code->param = (unsigned int)param - 1; |
| 306 | #endif |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 307 | } else |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 308 | goto inval_var; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 309 | |
| 310 | return ret; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 311 | |
| 312 | inval_var: |
| 313 | trace_probe_log_err(offs, BAD_VAR); |
| 314 | return -EINVAL; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /* Recursive argument parser */ |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 318 | static int |
| 319 | parse_probe_arg(char *arg, const struct fetch_type *type, |
| 320 | struct fetch_insn **pcode, struct fetch_insn *end, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 321 | unsigned int flags, int offs) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 322 | { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 323 | struct fetch_insn *code = *pcode; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 324 | unsigned long param; |
Steven Rostedt (VMware) | bf173ca | 2018-10-12 12:50:22 -0400 | [diff] [blame] | 325 | long offset = 0; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 326 | char *tmp; |
Namhyung Kim | 34fee3a | 2013-11-26 14:56:28 +0900 | [diff] [blame] | 327 | int ret = 0; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 328 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 329 | switch (arg[0]) { |
| 330 | case '$': |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 331 | ret = parse_probe_vars(arg + 1, type, code, flags, offs); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 332 | break; |
| 333 | |
| 334 | case '%': /* named register */ |
| 335 | ret = regs_query_register_offset(arg + 1); |
| 336 | if (ret >= 0) { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 337 | code->op = FETCH_OP_REG; |
| 338 | code->param = (unsigned int)ret; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 339 | ret = 0; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 340 | } else |
| 341 | trace_probe_log_err(offs, BAD_REG_NAME); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 342 | break; |
| 343 | |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 344 | case '@': /* memory, file-offset or symbol */ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 345 | if (isdigit(arg[1])) { |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 346 | ret = kstrtoul(arg + 1, 0, ¶m); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 347 | if (ret) { |
| 348 | trace_probe_log_err(offs, BAD_MEM_ADDR); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 349 | break; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 350 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 351 | /* load address */ |
| 352 | code->op = FETCH_OP_IMM; |
| 353 | code->immediate = param; |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 354 | } else if (arg[1] == '+') { |
| 355 | /* kprobes don't support file offsets */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 356 | if (flags & TPARG_FL_KERNEL) { |
| 357 | trace_probe_log_err(offs, FILE_ON_KPROBE); |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 358 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 359 | } |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 360 | ret = kstrtol(arg + 2, 0, &offset); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 361 | if (ret) { |
| 362 | trace_probe_log_err(offs, BAD_FILE_OFFS); |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 363 | break; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 364 | } |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 365 | |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 366 | code->op = FETCH_OP_FOFFS; |
| 367 | code->immediate = (unsigned long)offset; // imm64? |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 368 | } else { |
Namhyung Kim | b079d37 | 2013-07-03 18:34:23 +0900 | [diff] [blame] | 369 | /* uprobes don't support symbols */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 370 | if (!(flags & TPARG_FL_KERNEL)) { |
| 371 | trace_probe_log_err(offs, SYM_ON_UPROBE); |
Namhyung Kim | b079d37 | 2013-07-03 18:34:23 +0900 | [diff] [blame] | 372 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 373 | } |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 374 | /* Preserve symbol for updating */ |
| 375 | code->op = FETCH_NOP_SYMBOL; |
| 376 | code->data = kstrdup(arg + 1, GFP_KERNEL); |
| 377 | if (!code->data) |
| 378 | return -ENOMEM; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 379 | if (++code == end) { |
| 380 | trace_probe_log_err(offs, TOO_MANY_OPS); |
| 381 | return -EINVAL; |
| 382 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 383 | code->op = FETCH_OP_IMM; |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 384 | code->immediate = 0; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 385 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 386 | /* These are fetching from memory */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 387 | if (++code == end) { |
| 388 | trace_probe_log_err(offs, TOO_MANY_OPS); |
| 389 | return -EINVAL; |
| 390 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 391 | *pcode = code; |
| 392 | code->op = FETCH_OP_DEREF; |
| 393 | code->offset = offset; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 394 | break; |
| 395 | |
| 396 | case '+': /* deref memory */ |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 397 | arg++; /* Skip '+', because kstrtol() rejects it. */ |
Mathieu Malaterre | 91457c0 | 2019-01-14 21:30:37 +0100 | [diff] [blame] | 398 | /* fall through */ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 399 | case '-': |
| 400 | tmp = strchr(arg, '('); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 401 | if (!tmp) { |
| 402 | trace_probe_log_err(offs, DEREF_NEED_BRACE); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 403 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 404 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 405 | *tmp = '\0'; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 406 | ret = kstrtol(arg, 0, &offset); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 407 | if (ret) { |
| 408 | trace_probe_log_err(offs, BAD_DEREF_OFFS); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 409 | break; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 410 | } |
| 411 | offs += (tmp + 1 - arg) + (arg[0] != '-' ? 1 : 0); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 412 | arg = tmp + 1; |
| 413 | tmp = strrchr(arg, ')'); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 414 | if (!tmp) { |
| 415 | trace_probe_log_err(offs + strlen(arg), |
| 416 | DEREF_OPEN_BRACE); |
| 417 | return -EINVAL; |
| 418 | } else { |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 419 | const struct fetch_type *t2 = find_fetch_type(NULL); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 420 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 421 | *tmp = '\0'; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 422 | ret = parse_probe_arg(arg, t2, &code, end, flags, offs); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 423 | if (ret) |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 424 | break; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 425 | if (code->op == FETCH_OP_COMM) { |
| 426 | trace_probe_log_err(offs, COMM_CANT_DEREF); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 427 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 428 | } |
| 429 | if (++code == end) { |
| 430 | trace_probe_log_err(offs, TOO_MANY_OPS); |
| 431 | return -EINVAL; |
| 432 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 433 | *pcode = code; |
| 434 | |
| 435 | code->op = FETCH_OP_DEREF; |
| 436 | code->offset = offset; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 437 | } |
| 438 | break; |
| 439 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 440 | if (!ret && code->op == FETCH_OP_NOP) { |
| 441 | /* Parsed, but do not find fetch method */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 442 | trace_probe_log_err(offs, BAD_FETCH_ARG); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 443 | ret = -EINVAL; |
| 444 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 445 | return ret; |
| 446 | } |
| 447 | |
| 448 | #define BYTES_TO_BITS(nb) ((BITS_PER_LONG * (nb)) / sizeof(long)) |
| 449 | |
| 450 | /* Bitfield type needs to be parsed into a fetch function */ |
| 451 | static int __parse_bitfield_probe_arg(const char *bf, |
| 452 | const struct fetch_type *t, |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 453 | struct fetch_insn **pcode) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 454 | { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 455 | struct fetch_insn *code = *pcode; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 456 | unsigned long bw, bo; |
| 457 | char *tail; |
| 458 | |
| 459 | if (*bf != 'b') |
| 460 | return 0; |
| 461 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 462 | bw = simple_strtoul(bf + 1, &tail, 0); /* Use simple one */ |
| 463 | |
| 464 | if (bw == 0 || *tail != '@') |
| 465 | return -EINVAL; |
| 466 | |
| 467 | bf = tail + 1; |
| 468 | bo = simple_strtoul(bf, &tail, 0); |
| 469 | |
| 470 | if (tail == bf || *tail != '/') |
| 471 | return -EINVAL; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 472 | code++; |
| 473 | if (code->op != FETCH_OP_NOP) |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 474 | return -EINVAL; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 475 | *pcode = code; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 476 | |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 477 | code->op = FETCH_OP_MOD_BF; |
| 478 | code->lshift = BYTES_TO_BITS(t->size) - (bw + bo); |
| 479 | code->rshift = BYTES_TO_BITS(t->size) - bw; |
| 480 | code->basesize = t->size; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 481 | |
| 482 | return (BYTES_TO_BITS(t->size) < (bw + bo)) ? -EINVAL : 0; |
| 483 | } |
| 484 | |
| 485 | /* String length checking wrapper */ |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 486 | static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 487 | struct probe_arg *parg, unsigned int flags, int offset) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 488 | { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 489 | struct fetch_insn *code, *scode, *tmp = NULL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 490 | char *t, *t2, *t3; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 491 | int ret, len; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 492 | |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 493 | len = strlen(arg); |
| 494 | if (len > MAX_ARGSTR_LEN) { |
| 495 | trace_probe_log_err(offset, ARG_TOO_LONG); |
| 496 | return -EINVAL; |
| 497 | } else if (len == 0) { |
| 498 | trace_probe_log_err(offset, NO_ARG_BODY); |
| 499 | return -EINVAL; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 500 | } |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 501 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 502 | parg->comm = kstrdup(arg, GFP_KERNEL); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 503 | if (!parg->comm) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 504 | return -ENOMEM; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 505 | |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 506 | t = strchr(arg, ':'); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 507 | if (t) { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 508 | *t = '\0'; |
| 509 | t2 = strchr(++t, '['); |
| 510 | if (t2) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 511 | *t2++ = '\0'; |
| 512 | t3 = strchr(t2, ']'); |
| 513 | if (!t3) { |
| 514 | offset += t2 + strlen(t2) - arg; |
| 515 | trace_probe_log_err(offset, |
| 516 | ARRAY_NO_CLOSE); |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 517 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 518 | } else if (t3[1] != '\0') { |
| 519 | trace_probe_log_err(offset + t3 + 1 - arg, |
| 520 | BAD_ARRAY_SUFFIX); |
| 521 | return -EINVAL; |
| 522 | } |
| 523 | *t3 = '\0'; |
| 524 | if (kstrtouint(t2, 0, &parg->count) || !parg->count) { |
| 525 | trace_probe_log_err(offset + t2 - arg, |
| 526 | BAD_ARRAY_NUM); |
| 527 | return -EINVAL; |
| 528 | } |
| 529 | if (parg->count > MAX_ARRAY_LEN) { |
| 530 | trace_probe_log_err(offset + t2 - arg, |
| 531 | ARRAY_TOO_BIG); |
| 532 | return -EINVAL; |
| 533 | } |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 534 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 535 | } |
Masami Hiramatsu | 3dd1f7f | 2019-05-07 22:56:02 +0900 | [diff] [blame] | 536 | |
| 537 | /* Since $comm can not be dereferred, we can find $comm by strcmp */ |
| 538 | if (strcmp(arg, "$comm") == 0) { |
| 539 | /* The type of $comm must be "string", and not an array. */ |
| 540 | if (parg->count || (t && strcmp(t, "string"))) |
| 541 | return -EINVAL; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 542 | parg->type = find_fetch_type("string"); |
Masami Hiramatsu | 3dd1f7f | 2019-05-07 22:56:02 +0900 | [diff] [blame] | 543 | } else |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 544 | parg->type = find_fetch_type(t); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 545 | if (!parg->type) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 546 | trace_probe_log_err(offset + (t ? (t - arg) : 0), BAD_TYPE); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 547 | return -EINVAL; |
| 548 | } |
| 549 | parg->offset = *size; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 550 | *size += parg->type->size * (parg->count ?: 1); |
| 551 | |
| 552 | if (parg->count) { |
| 553 | len = strlen(parg->type->fmttype) + 6; |
| 554 | parg->fmt = kmalloc(len, GFP_KERNEL); |
| 555 | if (!parg->fmt) |
| 556 | return -ENOMEM; |
| 557 | snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype, |
| 558 | parg->count); |
| 559 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 560 | |
Gustavo A. R. Silva | 8623b00 | 2019-01-14 22:34:08 -0600 | [diff] [blame] | 561 | code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 562 | if (!code) |
| 563 | return -ENOMEM; |
| 564 | code[FETCH_INSN_MAX - 1].op = FETCH_OP_END; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 565 | |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 566 | ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1], |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 567 | flags, offset); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 568 | if (ret) |
| 569 | goto fail; |
| 570 | |
| 571 | /* Store operation */ |
| 572 | if (!strcmp(parg->type->name, "string")) { |
| 573 | if (code->op != FETCH_OP_DEREF && code->op != FETCH_OP_IMM && |
| 574 | code->op != FETCH_OP_COMM) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 575 | trace_probe_log_err(offset + (t ? (t - arg) : 0), |
| 576 | BAD_STRING); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 577 | ret = -EINVAL; |
| 578 | goto fail; |
| 579 | } |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 580 | if (code->op != FETCH_OP_DEREF || parg->count) { |
| 581 | /* |
| 582 | * IMM and COMM is pointing actual address, those must |
| 583 | * be kept, and if parg->count != 0, this is an array |
| 584 | * of string pointers instead of string address itself. |
| 585 | */ |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 586 | code++; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 587 | if (code->op != FETCH_OP_NOP) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 588 | trace_probe_log_err(offset, TOO_MANY_OPS); |
| 589 | ret = -EINVAL; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 590 | goto fail; |
| 591 | } |
| 592 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 593 | code->op = FETCH_OP_ST_STRING; /* In DEREF case, replace it */ |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 594 | code->size = parg->type->size; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 595 | parg->dynamic = true; |
| 596 | } else if (code->op == FETCH_OP_DEREF) { |
| 597 | code->op = FETCH_OP_ST_MEM; |
| 598 | code->size = parg->type->size; |
| 599 | } else { |
| 600 | code++; |
| 601 | if (code->op != FETCH_OP_NOP) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 602 | trace_probe_log_err(offset, TOO_MANY_OPS); |
| 603 | ret = -EINVAL; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 604 | goto fail; |
| 605 | } |
| 606 | code->op = FETCH_OP_ST_RAW; |
| 607 | code->size = parg->type->size; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 608 | } |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 609 | scode = code; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 610 | /* Modify operation */ |
| 611 | if (t != NULL) { |
| 612 | ret = __parse_bitfield_probe_arg(t, parg->type, &code); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 613 | if (ret) { |
| 614 | trace_probe_log_err(offset + t - arg, BAD_BITFIELD); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 615 | goto fail; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 616 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 617 | } |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 618 | /* Loop(Array) operation */ |
| 619 | if (parg->count) { |
| 620 | if (scode->op != FETCH_OP_ST_MEM && |
| 621 | scode->op != FETCH_OP_ST_STRING) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 622 | trace_probe_log_err(offset + (t ? (t - arg) : 0), |
| 623 | BAD_STRING); |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 624 | ret = -EINVAL; |
| 625 | goto fail; |
| 626 | } |
| 627 | code++; |
| 628 | if (code->op != FETCH_OP_NOP) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 629 | trace_probe_log_err(offset, TOO_MANY_OPS); |
| 630 | ret = -EINVAL; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 631 | goto fail; |
| 632 | } |
| 633 | code->op = FETCH_OP_LP_ARRAY; |
| 634 | code->param = parg->count; |
| 635 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 636 | code++; |
| 637 | code->op = FETCH_OP_END; |
| 638 | |
| 639 | /* Shrink down the code buffer */ |
Gustavo A. R. Silva | 8623b00 | 2019-01-14 22:34:08 -0600 | [diff] [blame] | 640 | parg->code = kcalloc(code - tmp + 1, sizeof(*code), GFP_KERNEL); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 641 | if (!parg->code) |
| 642 | ret = -ENOMEM; |
| 643 | else |
| 644 | memcpy(parg->code, tmp, sizeof(*code) * (code - tmp + 1)); |
| 645 | |
| 646 | fail: |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 647 | if (ret) { |
| 648 | for (code = tmp; code < tmp + FETCH_INSN_MAX; code++) |
| 649 | if (code->op == FETCH_NOP_SYMBOL) |
| 650 | kfree(code->data); |
| 651 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 652 | kfree(tmp); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 653 | |
| 654 | return ret; |
| 655 | } |
| 656 | |
| 657 | /* Return 1 if name is reserved or already used by another argument */ |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 658 | static int traceprobe_conflict_field_name(const char *name, |
| 659 | struct probe_arg *args, int narg) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 660 | { |
| 661 | int i; |
| 662 | |
| 663 | for (i = 0; i < ARRAY_SIZE(reserved_field_names); i++) |
| 664 | if (strcmp(reserved_field_names[i], name) == 0) |
| 665 | return 1; |
| 666 | |
| 667 | for (i = 0; i < narg; i++) |
| 668 | if (strcmp(args[i].name, name) == 0) |
| 669 | return 1; |
| 670 | |
| 671 | return 0; |
| 672 | } |
| 673 | |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 674 | int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, char *arg, |
| 675 | unsigned int flags) |
| 676 | { |
| 677 | struct probe_arg *parg = &tp->args[i]; |
| 678 | char *body; |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 679 | |
| 680 | /* Increment count for freeing args in error case */ |
| 681 | tp->nr_args++; |
| 682 | |
| 683 | body = strchr(arg, '='); |
| 684 | if (body) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 685 | if (body - arg > MAX_ARG_NAME_LEN) { |
| 686 | trace_probe_log_err(0, ARG_NAME_TOO_LONG); |
Masami Hiramatsu | b4443c1 | 2019-03-14 13:30:30 +0900 | [diff] [blame] | 687 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 688 | } else if (body == arg) { |
| 689 | trace_probe_log_err(0, NO_ARG_NAME); |
| 690 | return -EINVAL; |
| 691 | } |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 692 | parg->name = kmemdup_nul(arg, body - arg, GFP_KERNEL); |
| 693 | body++; |
| 694 | } else { |
| 695 | /* If argument name is omitted, set "argN" */ |
| 696 | parg->name = kasprintf(GFP_KERNEL, "arg%d", i + 1); |
| 697 | body = arg; |
| 698 | } |
| 699 | if (!parg->name) |
| 700 | return -ENOMEM; |
| 701 | |
| 702 | if (!is_good_name(parg->name)) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 703 | trace_probe_log_err(0, BAD_ARG_NAME); |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 704 | return -EINVAL; |
| 705 | } |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 706 | if (traceprobe_conflict_field_name(parg->name, tp->args, i)) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 707 | trace_probe_log_err(0, USED_ARG_NAME); |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 708 | return -EINVAL; |
| 709 | } |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 710 | /* Parse fetch argument */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 711 | return traceprobe_parse_probe_arg_body(body, &tp->size, parg, flags, |
| 712 | body - arg); |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 713 | } |
| 714 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 715 | void traceprobe_free_probe_arg(struct probe_arg *arg) |
| 716 | { |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 717 | struct fetch_insn *code = arg->code; |
| 718 | |
| 719 | while (code && code->op != FETCH_OP_END) { |
| 720 | if (code->op == FETCH_NOP_SYMBOL) |
| 721 | kfree(code->data); |
| 722 | code++; |
| 723 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 724 | kfree(arg->code); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 725 | kfree(arg->name); |
| 726 | kfree(arg->comm); |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 727 | kfree(arg->fmt); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 728 | } |
| 729 | |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 730 | int traceprobe_update_arg(struct probe_arg *arg) |
| 731 | { |
| 732 | struct fetch_insn *code = arg->code; |
| 733 | long offset; |
| 734 | char *tmp; |
| 735 | char c; |
| 736 | int ret = 0; |
| 737 | |
| 738 | while (code && code->op != FETCH_OP_END) { |
| 739 | if (code->op == FETCH_NOP_SYMBOL) { |
| 740 | if (code[1].op != FETCH_OP_IMM) |
| 741 | return -EINVAL; |
| 742 | |
Masami Hiramatsu | ee474b8 | 2018-11-01 23:29:28 +0900 | [diff] [blame] | 743 | tmp = strpbrk(code->data, "+-"); |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 744 | if (tmp) |
| 745 | c = *tmp; |
| 746 | ret = traceprobe_split_symbol_offset(code->data, |
| 747 | &offset); |
| 748 | if (ret) |
| 749 | return ret; |
| 750 | |
| 751 | code[1].immediate = |
| 752 | (unsigned long)kallsyms_lookup_name(code->data); |
| 753 | if (tmp) |
| 754 | *tmp = c; |
| 755 | if (!code[1].immediate) |
| 756 | return -ENOENT; |
| 757 | code[1].immediate += offset; |
| 758 | } |
| 759 | code++; |
| 760 | } |
| 761 | return 0; |
| 762 | } |
| 763 | |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 764 | /* When len=0, we just calculate the needed length */ |
| 765 | #define LEN_OR_ZERO (len ? len - pos : 0) |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 766 | static int __set_print_fmt(struct trace_probe *tp, char *buf, int len, |
| 767 | bool is_return) |
| 768 | { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 769 | struct probe_arg *parg; |
| 770 | int i, j; |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 771 | int pos = 0; |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 772 | const char *fmt, *arg; |
| 773 | |
| 774 | if (!is_return) { |
| 775 | fmt = "(%lx)"; |
| 776 | arg = "REC->" FIELD_STRING_IP; |
| 777 | } else { |
| 778 | fmt = "(%lx <- %lx)"; |
| 779 | arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP; |
| 780 | } |
| 781 | |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 782 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); |
| 783 | |
| 784 | for (i = 0; i < tp->nr_args; i++) { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 785 | parg = tp->args + i; |
| 786 | pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=", parg->name); |
| 787 | if (parg->count) { |
| 788 | pos += snprintf(buf + pos, LEN_OR_ZERO, "{%s", |
| 789 | parg->type->fmt); |
| 790 | for (j = 1; j < parg->count; j++) |
| 791 | pos += snprintf(buf + pos, LEN_OR_ZERO, ",%s", |
| 792 | parg->type->fmt); |
| 793 | pos += snprintf(buf + pos, LEN_OR_ZERO, "}"); |
| 794 | } else |
| 795 | pos += snprintf(buf + pos, LEN_OR_ZERO, "%s", |
| 796 | parg->type->fmt); |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); |
| 800 | |
| 801 | for (i = 0; i < tp->nr_args; i++) { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 802 | parg = tp->args + i; |
| 803 | if (parg->count) { |
| 804 | if (strcmp(parg->type->name, "string") == 0) |
| 805 | fmt = ", __get_str(%s[%d])"; |
| 806 | else |
| 807 | fmt = ", REC->%s[%d]"; |
| 808 | for (j = 0; j < parg->count; j++) |
| 809 | pos += snprintf(buf + pos, LEN_OR_ZERO, |
| 810 | fmt, parg->name, j); |
| 811 | } else { |
| 812 | if (strcmp(parg->type->name, "string") == 0) |
| 813 | fmt = ", __get_str(%s)"; |
| 814 | else |
| 815 | fmt = ", REC->%s"; |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 816 | pos += snprintf(buf + pos, LEN_OR_ZERO, |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 817 | fmt, parg->name); |
| 818 | } |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 819 | } |
| 820 | |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 821 | /* return the length of print_fmt */ |
| 822 | return pos; |
| 823 | } |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 824 | #undef LEN_OR_ZERO |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 825 | |
Masami Hiramatsu | 0a46c85 | 2018-04-25 21:19:30 +0900 | [diff] [blame] | 826 | int traceprobe_set_print_fmt(struct trace_probe *tp, bool is_return) |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 827 | { |
| 828 | int len; |
| 829 | char *print_fmt; |
| 830 | |
| 831 | /* First: called with 0 length to calculate the needed length */ |
| 832 | len = __set_print_fmt(tp, NULL, 0, is_return); |
| 833 | print_fmt = kmalloc(len + 1, GFP_KERNEL); |
| 834 | if (!print_fmt) |
| 835 | return -ENOMEM; |
| 836 | |
| 837 | /* Second: actually write the @print_fmt */ |
| 838 | __set_print_fmt(tp, print_fmt, len + 1, is_return); |
| 839 | tp->call.print_fmt = print_fmt; |
| 840 | |
| 841 | return 0; |
| 842 | } |
Masami Hiramatsu | eeb07b0 | 2018-04-25 21:17:05 +0900 | [diff] [blame] | 843 | |
| 844 | int traceprobe_define_arg_fields(struct trace_event_call *event_call, |
| 845 | size_t offset, struct trace_probe *tp) |
| 846 | { |
| 847 | int ret, i; |
| 848 | |
| 849 | /* Set argument names as fields */ |
| 850 | for (i = 0; i < tp->nr_args; i++) { |
| 851 | struct probe_arg *parg = &tp->args[i]; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 852 | const char *fmt = parg->type->fmttype; |
| 853 | int size = parg->type->size; |
Masami Hiramatsu | eeb07b0 | 2018-04-25 21:17:05 +0900 | [diff] [blame] | 854 | |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 855 | if (parg->fmt) |
| 856 | fmt = parg->fmt; |
| 857 | if (parg->count) |
| 858 | size *= parg->count; |
| 859 | ret = trace_define_field(event_call, fmt, parg->name, |
| 860 | offset + parg->offset, size, |
Masami Hiramatsu | eeb07b0 | 2018-04-25 21:17:05 +0900 | [diff] [blame] | 861 | parg->type->is_signed, |
| 862 | FILTER_OTHER); |
| 863 | if (ret) |
| 864 | return ret; |
| 865 | } |
| 866 | return 0; |
| 867 | } |