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 "../wrapper/vmalloc.h"
16 #include "../ltt-tracer.h"
19 int lttng_kprobes_handler_pre(struct kprobe
*p
, struct pt_regs
*regs
)
21 struct ltt_event
*event
=
22 container_of(p
, struct ltt_event
, u
.kprobe
.kp
);
23 struct ltt_channel
*chan
= event
->chan
;
24 struct lib_ring_buffer_ctx ctx
;
26 unsigned long data
= (unsigned long) p
->addr
;
28 if (!ACCESS_ONCE(chan
->session
->active
))
30 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, sizeof(data
),
31 ltt_alignof(data
), -1);
32 ret
= chan
->ops
->event_reserve(&ctx
, event
->id
);
35 lib_ring_buffer_align_ctx(&ctx
, ltt_alignof(data
));
36 chan
->ops
->event_write(&ctx
, &data
, sizeof(data
));
37 chan
->ops
->event_commit(&ctx
);
42 * Create event description
45 int lttng_create_kprobe_event(const char *name
, struct ltt_event
*event
)
47 struct lttng_event_field
*field
;
48 struct lttng_event_desc
*desc
;
51 desc
= kzalloc(sizeof(*event
->desc
), GFP_KERNEL
);
54 desc
->name
= kstrdup(name
, GFP_KERNEL
);
60 desc
->fields
= field
=
61 kzalloc(1 * sizeof(struct lttng_event_field
), GFP_KERNEL
);
67 field
->type
.atype
= atype_integer
;
68 field
->type
.u
.basic
.integer
.size
= sizeof(unsigned long) * CHAR_BIT
;
69 field
->type
.u
.basic
.integer
.alignment
= ltt_alignof(unsigned long) * CHAR_BIT
;
70 field
->type
.u
.basic
.integer
.signedness
= 0;
71 field
->type
.u
.basic
.integer
.reverse_byte_order
= 0;
72 field
->type
.u
.basic
.integer
.base
= 16;
73 field
->type
.u
.basic
.integer
.encoding
= lttng_encode_none
;
74 desc
->owner
= THIS_MODULE
;
86 int lttng_kprobes_register(const char *name
,
87 const char *symbol_name
,
90 struct ltt_event
*event
)
94 ret
= lttng_create_kprobe_event(name
, event
);
97 memset(&event
->u
.kprobe
.kp
, 0, sizeof(event
->u
.kprobe
.kp
));
98 event
->u
.kprobe
.kp
.pre_handler
= lttng_kprobes_handler_pre
;
99 event
->u
.kprobe
.symbol_name
=
100 kzalloc(LTTNG_SYM_NAME_LEN
* sizeof(char),
102 if (!event
->u
.kprobe
.symbol_name
) {
106 memcpy(event
->u
.kprobe
.symbol_name
, symbol_name
,
107 LTTNG_SYM_NAME_LEN
* sizeof(char));
108 event
->u
.kprobe
.kp
.symbol_name
=
109 event
->u
.kprobe
.symbol_name
;
110 event
->u
.kprobe
.kp
.offset
= offset
;
111 event
->u
.kprobe
.kp
.addr
= (void *) addr
;
114 * Ensure the memory we just allocated don't trigger page faults.
115 * Well.. kprobes itself puts the page fault handler on the blacklist,
116 * but we can never be too careful.
118 wrapper_vmalloc_sync_all();
120 ret
= register_kprobe(&event
->u
.kprobe
.kp
);
126 kfree(event
->u
.kprobe
.symbol_name
);
128 kfree(event
->desc
->fields
);
129 kfree(event
->desc
->name
);
134 EXPORT_SYMBOL_GPL(lttng_kprobes_register
);
136 void lttng_kprobes_unregister(struct ltt_event
*event
)
138 unregister_kprobe(&event
->u
.kprobe
.kp
);
139 kfree(event
->u
.kprobe
.symbol_name
);
140 kfree(event
->desc
->fields
);
141 kfree(event
->desc
->name
);
144 EXPORT_SYMBOL_GPL(lttng_kprobes_unregister
);
146 MODULE_LICENSE("GPL and additional rights");
147 MODULE_AUTHOR("Mathieu Desnoyers");
148 MODULE_DESCRIPTION("Linux Trace Toolkit Kprobes Support");