2 * probes/lttng-uprobes.c
4 * LTTng uprobes integration module.
6 * Copyright (C) 2013 Yannick Brosseau <yannick.brosseau@gmail.com>
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; only
12 * version 2.1 of the License.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <linux/fdtable.h>
25 #include <linux/module.h>
26 #include <linux/namei.h>
27 #include <linux/slab.h>
28 #include <lttng-events.h>
29 #include <lttng-tracer.h>
30 #include <wrapper/irqflags.h>
31 #include <wrapper/ringbuffer/frontend_types.h>
32 #include <wrapper/uprobes.h>
33 #include <wrapper/vmalloc.h>
36 int lttng_uprobes_handler_pre(struct uprobe_consumer
*uc
, struct pt_regs
*regs
)
38 struct lttng_event
*event
=
39 container_of(uc
, struct lttng_event
, u
.uprobe
.up_consumer
);
40 struct lttng_probe_ctx lttng_probe_ctx
= {
42 .interruptible
= !lttng_regs_irqs_disabled(regs
),
44 struct lttng_channel
*chan
= event
->chan
;
45 struct lib_ring_buffer_ctx ctx
;
52 if (unlikely(!ACCESS_ONCE(chan
->session
->active
)))
54 if (unlikely(!ACCESS_ONCE(chan
->enabled
)))
56 if (unlikely(!ACCESS_ONCE(event
->enabled
)))
59 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, <tng_probe_ctx
,
60 sizeof(payload
), lttng_alignof(payload
), -1);
62 ret
= chan
->ops
->event_reserve(&ctx
, event
->id
);
67 payload
.ip
= regs
->ip
;
68 lib_ring_buffer_align_ctx(&ctx
, lttng_alignof(payload
));
69 chan
->ops
->event_write(&ctx
, &payload
, sizeof(payload
));
70 chan
->ops
->event_commit(&ctx
);
75 * Create event description.
78 int lttng_create_uprobe_event(const char *name
, struct lttng_event
*event
)
80 struct lttng_event_desc
*desc
;
81 struct lttng_event_field
*fields
;
84 desc
= kzalloc(sizeof(*event
->desc
), GFP_KERNEL
);
87 desc
->name
= kstrdup(name
, GFP_KERNEL
);
94 desc
->fields
= fields
=
95 kzalloc(1 * sizeof(struct lttng_event_field
), GFP_KERNEL
);
101 fields
[0].name
= "ip";
102 fields
[0].type
.atype
= atype_integer
;
103 fields
[0].type
.u
.basic
.integer
.size
= sizeof(unsigned long) * CHAR_BIT
;
104 fields
[0].type
.u
.basic
.integer
.alignment
= lttng_alignof(unsigned long) * CHAR_BIT
;
105 fields
[0].type
.u
.basic
.integer
.signedness
= lttng_is_signed_type(unsigned long);
106 fields
[0].type
.u
.basic
.integer
.reverse_byte_order
= 0;
107 fields
[0].type
.u
.basic
.integer
.base
= 16;
108 fields
[0].type
.u
.basic
.integer
.encoding
= lttng_encode_none
;
110 desc
->owner
= THIS_MODULE
;
122 int lttng_uprobes_register(const char *name
,
123 const char *path_name
,
125 struct lttng_event
*event
)
129 /* Shoudl we fail if the path is empty, it should be checked before */
130 if (path_name
[0] == '\0')
133 ret
= lttng_create_uprobe_event(name
, event
);
137 memset(&event
->u
.uprobe
.up_consumer
, 0,
138 sizeof(event
->u
.uprobe
.up_consumer
));
140 event
->u
.uprobe
.up_consumer
.handler
= lttng_uprobes_handler_pre
;
143 ret
= kern_path(path_name
, LOOKUP_FOLLOW
, &path
);
147 event
->u
.uprobe
.inode
= igrab(path
.dentry
->d_inode
);
149 event
->u
.uprobe
.offset
= offset
;
151 /* Ensure the memory we just allocated don't trigger page faults. */
152 wrapper_vmalloc_sync_all();
153 printk(KERN_WARNING
"Registering probe on inode %lu and offset %llu\n", event
->u
.uprobe
.inode
->i_ino
, event
->u
.uprobe
.offset
);
154 ret
= wrapper_uprobe_register(event
->u
.uprobe
.inode
,
155 event
->u
.uprobe
.offset
,
156 &event
->u
.uprobe
.up_consumer
);
158 printk(KERN_WARNING
"Error registering probe on inode %lu "
159 "and offset %llu\n", event
->u
.uprobe
.inode
->i_ino
,
160 event
->u
.uprobe
.offset
);
166 iput(event
->u
.uprobe
.inode
);
168 kfree(event
->desc
->name
);
173 EXPORT_SYMBOL_GPL(lttng_uprobes_register
);
175 void lttng_uprobes_unregister(struct lttng_event
*event
)
177 wrapper_uprobe_unregister(event
->u
.uprobe
.inode
,
178 event
->u
.uprobe
.offset
,
179 &event
->u
.uprobe
.up_consumer
);
181 EXPORT_SYMBOL_GPL(lttng_uprobes_unregister
);
183 void lttng_uprobes_destroy_private(struct lttng_event
*event
)
185 iput(event
->u
.uprobe
.inode
);
186 kfree(event
->desc
->name
);
189 EXPORT_SYMBOL_GPL(lttng_uprobes_destroy_private
);
191 MODULE_LICENSE("GPL and additional rights");
192 MODULE_AUTHOR("Yannick Brosseau");
193 MODULE_DESCRIPTION("Linux Trace Toolkit Uprobes Support");