Migrate tracepoint instrumentation to TP_FIELDS
[lttng-modules.git] / probes / lttng-probe-user.c
1 /*
2 * lttng-probe-user.c
3 *
4 * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; only
9 * version 2.1 of the License.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <linux/uaccess.h>
22 #include "lttng-probe-user.h"
23
24 /*
25 * Calculate string length. Include final null terminating character if there is
26 * one, or ends at first fault. Disabling page faults ensures that we can safely
27 * call this from pretty much any context, including those where the caller
28 * holds mmap_sem, or any lock which nests in mmap_sem.
29 */
30 long lttng_strlen_user_inatomic(const char *addr)
31 {
32 long count = 0;
33 mm_segment_t old_fs = get_fs();
34
35 set_fs(KERNEL_DS);
36 pagefault_disable();
37 for (;;) {
38 char v;
39 unsigned long ret;
40
41 if (unlikely(!access_ok(VERIFY_READ,
42 (__force const char __user *) addr,
43 sizeof(v))))
44 break;
45 ret = __copy_from_user_inatomic(&v,
46 (__force const char __user *)(addr),
47 sizeof(v));
48 if (unlikely(ret > 0))
49 break;
50 count++;
51 if (unlikely(!v))
52 break;
53 addr++;
54 }
55 pagefault_enable();
56 set_fs(old_fs);
57 return count;
58 }
59 EXPORT_SYMBOL_GPL(lttng_strlen_user_inatomic);
This page took 0.0369080000000001 seconds and 4 git commands to generate.