2 * (C) Copyright 2009-2011 -
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * LTTng kprobes integration module.
7 * Dual LGPL v2.1/GPL v2 license.
10 #include <linux/module.h>
11 #include <linux/kprobes.h>
12 #include <linux/slab.h>
13 #include "../ltt-events.h"
14 #include "../wrapper/ringbuffer/frontend_types.h"
15 #include "../ltt-tracer.h"
18 int lttng_kprobes_handler_pre(struct kprobe
*p
, struct pt_regs
*regs
)
20 struct ltt_event
*event
=
21 container_of(p
, struct ltt_event
, u
.kprobe
.kp
);
22 struct ltt_channel
*chan
= event
->chan
;
23 struct lib_ring_buffer_ctx ctx
;
25 unsigned long data
= (unsigned long) p
->addr
;
27 if (!ACCESS_ONCE(chan
->session
->active
))
29 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, sizeof(data
),
30 ltt_alignof(data
), -1);
31 ret
= chan
->ops
->event_reserve(&ctx
);
34 lib_ring_buffer_align_ctx(&ctx
, ltt_alignof(data
));
35 chan
->ops
->event_write(&ctx
, &data
, sizeof(data
));
36 chan
->ops
->event_commit(&ctx
);
41 * Create event description
44 int lttng_create_kprobe_event(const char *name
, struct ltt_event
*event
)
46 struct lttng_event_field
*field
;
47 struct lttng_event_desc
*desc
;
50 desc
= kzalloc(sizeof(*event
->desc
), GFP_KERNEL
);
53 desc
->name
= kstrdup(name
, GFP_KERNEL
);
59 desc
->fields
= field
=
60 kzalloc(1 * sizeof(struct lttng_event_field
), GFP_KERNEL
);
62 field
->type
.atype
= atype_integer
;
63 field
->type
.u
.basic
.integer
.size
= sizeof(unsigned long);
64 field
->type
.u
.basic
.integer
.alignment
= ltt_alignof(unsigned long);
65 field
->type
.u
.basic
.integer
.signedness
= 0;
66 field
->type
.u
.basic
.integer
.reverse_byte_order
= 0;
67 field
->type
.u
.basic
.integer
.base
= 16;
68 field
->type
.u
.basic
.integer
.encoding
= lttng_encode_none
;
78 int lttng_kprobes_register(const char *name
,
79 const char *symbol_name
,
82 struct ltt_event
*event
)
86 ret
= lttng_create_kprobe_event(name
, event
);
89 memset(&event
->u
.kprobe
.kp
, 0, sizeof(event
->u
.kprobe
.kp
));
90 event
->u
.kprobe
.kp
.pre_handler
= lttng_kprobes_handler_pre
;
91 event
->u
.kprobe
.symbol_name
=
92 kzalloc(LTTNG_SYM_NAME_LEN
* sizeof(char),
94 if (!event
->u
.kprobe
.symbol_name
) {
98 memcpy(event
->u
.kprobe
.symbol_name
, symbol_name
,
99 LTTNG_SYM_NAME_LEN
* sizeof(char));
100 event
->u
.kprobe
.kp
.symbol_name
=
101 event
->u
.kprobe
.symbol_name
;
102 event
->u
.kprobe
.kp
.offset
= offset
;
103 event
->u
.kprobe
.kp
.addr
= (void *) addr
;
104 ret
= register_kprobe(&event
->u
.kprobe
.kp
);
110 kfree(event
->u
.kprobe
.symbol_name
);
112 kfree(event
->desc
->name
);
117 EXPORT_SYMBOL_GPL(lttng_kprobes_register
);
119 void lttng_kprobes_unregister(struct ltt_event
*event
)
121 unregister_kprobe(&event
->u
.kprobe
.kp
);
122 kfree(event
->u
.kprobe
.symbol_name
);
123 kfree(event
->desc
->name
);
126 EXPORT_SYMBOL_GPL(lttng_kprobes_unregister
);
128 MODULE_LICENSE("GPL and additional rights");
129 MODULE_AUTHOR("Mathieu Desnoyers");
130 MODULE_DESCRIPTION("Linux Trace Toolkit Kprobes Support");