30 "common_preempt_count",
39 #define PRINT_TYPE_FUNC_NAME(type) print_type_##type
40 #define PRINT_TYPE_FMT_NAME(type) print_type_format_##type
43 #define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt, cast) \
44 static __kprobes int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, \
46 void *data, void *ent)\
48 return trace_seq_printf(s, " %s=" fmt, name, (cast)*(type *)data);\
50 static const char PRINT_TYPE_FMT_NAME(type)[] = fmt;
67 static inline void *get_loc_data(
u32 *
dl,
void *
ent)
79 void *
data,
void *ent)
81 int len = *(
u32 *)data >> 16;
87 (
const char *)get_loc_data(data, ent));
92 #define FETCH_FUNC_NAME(method, type) fetch_##method##_##type
97 #define DEFINE_BASIC_FETCH_FUNCS(method) \
98 DEFINE_FETCH_##method(u8) \
99 DEFINE_FETCH_##method(u16) \
100 DEFINE_FETCH_##method(u32) \
101 DEFINE_FETCH_##method(u64)
103 #define CHECK_FETCH_FUNCS(method, fn) \
104 (((FETCH_FUNC_NAME(method, u8) == fn) || \
105 (FETCH_FUNC_NAME(method, u16) == fn) || \
106 (FETCH_FUNC_NAME(method, u32) == fn) || \
107 (FETCH_FUNC_NAME(method, u64) == fn) || \
108 (FETCH_FUNC_NAME(method, string) == fn) || \
109 (FETCH_FUNC_NAME(method, string_size) == fn)) \
113 #define DEFINE_FETCH_reg(type) \
114 static __kprobes void FETCH_FUNC_NAME(reg, type)(struct pt_regs *regs, \
115 void *offset, void *dest) \
117 *(type *)dest = (type)regs_get_register(regs, \
118 (unsigned int)((unsigned long)offset)); \
122 #define fetch_reg_string NULL
123 #define fetch_reg_string_size NULL
125 #define DEFINE_FETCH_stack(type) \
126 static __kprobes void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs,\
127 void *offset, void *dest) \
129 *(type *)dest = (type)regs_get_kernel_stack_nth(regs, \
130 (unsigned int)((unsigned long)offset)); \
134 #define fetch_stack_string NULL
135 #define fetch_stack_string_size NULL
137 #define DEFINE_FETCH_retval(type) \
138 static __kprobes void FETCH_FUNC_NAME(retval, type)(struct pt_regs *regs,\
139 void *dummy, void *dest) \
141 *(type *)dest = (type)regs_return_value(regs); \
145 #define fetch_retval_string NULL
146 #define fetch_retval_string_size NULL
148 #define DEFINE_FETCH_memory(type) \
149 static __kprobes void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs,\
150 void *addr, void *dest) \
153 if (probe_kernel_address(addr, retval)) \
156 *(type *)dest = retval; \
168 u8 *
dst = get_rloc_data(dest);
184 while (dst[-1] && ret == 0 && src - (
u8 *)addr < maxlen);
191 ((
u8 *)get_rloc_data(dest))[0] =
'\0';
252 if (!sym ||
strlen(sym) == 0)
265 update_symbol_cache(sc);
270 #define DEFINE_FETCH_symbol(type) \
271 static __kprobes void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs,\
272 void *data, void *dest) \
274 struct symbol_cache *sc = data; \
276 fetch_memory_##type(regs, (void *)sc->addr, dest); \
285 struct deref_fetch_param {
290 #define DEFINE_FETCH_deref(type) \
291 static __kprobes void FETCH_FUNC_NAME(deref, type)(struct pt_regs *regs,\
292 void *data, void *dest) \
294 struct deref_fetch_param *dprm = data; \
295 unsigned long addr; \
296 call_fetch(&dprm->orig, regs, &addr); \
298 addr += dprm->offset; \
299 fetch_memory_##type(regs, (void *)addr, dest); \
307 static
__kprobes void update_deref_fetch_param(
struct deref_fetch_param *data)
310 update_deref_fetch_param(data->orig.data);
312 update_symbol_cache(data->orig.data);
315 static __kprobes void free_deref_fetch_param(
struct deref_fetch_param *data)
318 free_deref_fetch_param(data->orig.data);
320 free_symbol_cache(data->orig.data);
331 #define DEFINE_FETCH_bitfield(type) \
332 static __kprobes void FETCH_FUNC_NAME(bitfield, type)(struct pt_regs *regs,\
333 void *data, void *dest) \
335 struct bitfield_fetch_param *bprm = data; \
337 call_fetch(&bprm->orig, regs, &buf); \
339 buf <<= bprm->hi_shift; \
340 buf >>= bprm->low_shift; \
342 *(type *)dest = buf; \
346 #define fetch_bitfield_string NULL
347 #define fetch_bitfield_string_size NULL
357 update_deref_fetch_param(data->
orig.data);
359 update_symbol_cache(data->
orig.data);
370 free_deref_fetch_param(data->
orig.data);
372 free_symbol_cache(data->
orig.data);
378 #define __DEFAULT_FETCH_TYPE(t) u##t
379 #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t)
380 #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG)
381 #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE)
383 #define ASSIGN_FETCH_FUNC(method, type) \
384 [FETCH_MTD_##method] = FETCH_FUNC_NAME(method, type)
386 #define __ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, _fmttype) \
390 .print = PRINT_TYPE_FUNC_NAME(ptype), \
391 .fmt = PRINT_TYPE_FMT_NAME(ptype), \
392 .fmttype = _fmttype, \
394 ASSIGN_FETCH_FUNC(reg, ftype), \
395 ASSIGN_FETCH_FUNC(stack, ftype), \
396 ASSIGN_FETCH_FUNC(retval, ftype), \
397 ASSIGN_FETCH_FUNC(memory, ftype), \
398 ASSIGN_FETCH_FUNC(symbol, ftype), \
399 ASSIGN_FETCH_FUNC(deref, ftype), \
400 ASSIGN_FETCH_FUNC(bitfield, ftype), \
404 #define ASSIGN_FETCH_TYPE(ptype, ftype, sign) \
405 __ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #ptype)
407 #define FETCH_TYPE_STRING 0
408 #define FETCH_TYPE_STRSIZE 1
411 static const struct fetch_type fetch_type_table[] = {
414 sizeof(
u32), 1,
"__data_loc char[]"),
416 string_size,
sizeof(
u32), 0,
"u32"),
449 return find_fetch_type(
"u8");
451 return find_fetch_type(
"u16");
453 return find_fetch_type(
"u32");
455 return find_fetch_type(
"u64");
461 for (i = 0; i <
ARRAY_SIZE(fetch_type_table); i++)
462 if (
strcmp(type, fetch_type_table[i].name) == 0)
463 return &fetch_type_table[i];
485 if (type->
fetch[i] == orig_fn)
502 tmp =
strchr(symbol,
'+');
516 #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long))
518 static int parse_probe_vars(
char *
arg,
const struct fetch_type *
t,
524 if (
strcmp(arg,
"retval") == 0) {
529 }
else if (
strncmp(arg,
"stack", 5) == 0) {
530 if (arg[5] ==
'\0') {
532 f->
fn = fetch_stack_address;
541 f->
data = (
void *)param;
563 if (!is_kprobe && arg[0] !=
'%')
568 ret = parse_probe_vars(arg + 1, t, f, is_return);
575 f->
data = (
void *)(
unsigned long)
ret;
587 f->
data = (
void *)param;
593 f->
data = alloc_symbol_cache(arg + 1, offset);
616 struct deref_fetch_param *dprm;
619 t2 = find_fetch_type(
NULL);
621 dprm = kzalloc(
sizeof(
struct deref_fetch_param),
GFP_KERNEL);
627 ret = parse_probe_arg(arg, t2, &dprm->orig, is_return,
633 f->
data = (
void *)dprm;
638 if (!ret && !f->
fn) {
639 pr_info(
"%s type has no corresponding fetch method.\n", t->
name);
646 #define BYTES_TO_BITS(nb) ((BITS_PER_LONG * (nb)) / sizeof(long))
649 static int __parse_bitfield_probe_arg(
const char *
bf,
654 unsigned long bw, bo;
666 f->
data = (
void *)bprm;
669 if (bw == 0 || *tail !=
'@')
675 if (tail == bf || *tail !=
'/')
686 struct probe_arg *parg,
bool is_return,
bool is_kprobe)
692 pr_info(
"Argument is too long.: %s\n", arg);
697 pr_info(
"Failed to allocate memory for command '%s'.\n", arg);
702 arg[t - parg->
comm] =
'\0';
705 parg->
type = find_fetch_type(t);
707 pr_info(
"Unsupported type: %s\n", t);
711 *size += parg->
type->size;
712 ret = parse_probe_arg(arg, parg->
type, &parg->
fetch, is_return, is_kprobe);
714 if (ret >= 0 && t !=
NULL)
715 ret = __parse_bitfield_probe_arg(t, parg->
type, &parg->
fetch);
736 for (i = 0; i < narg; i++)
737 if (
strcmp(args[i].name, name) == 0)
746 update_bitfield_fetch_param(arg->
fetch.data);
748 update_deref_fetch_param(arg->
fetch.data);
750 update_symbol_cache(arg->
fetch.data);
756 free_bitfield_fetch_param(arg->
fetch.data);
758 free_deref_fetch_param(arg->
fetch.data);
760 free_symbol_cache(arg->
fetch.data);
778 ret = createfn(argc, argv);
785 #define WRITE_BUFSIZE 4096
788 size_t count, loff_t *ppos,
789 int (*createfn)(
int,
char **))
800 while (done < count) {
815 size = tmp - kbuf + 1;
816 }
else if (done + size < count) {