Fix: Remove 'type' argument from access_ok() function (v5.0)
[lttng-modules.git] / probes / lttng-probe-user.c
CommitLineData
7b8ea3a5
MD
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>
8d90c035 22#include <linux/module.h>
0039dbe9 23#include <wrapper/uaccess.h>
156a3977 24#include <probes/lttng-probe-user.h>
7b8ea3a5
MD
25
26/*
27 * Calculate string length. Include final null terminating character if there is
28 * one, or ends at first fault. Disabling page faults ensures that we can safely
29 * call this from pretty much any context, including those where the caller
30 * holds mmap_sem, or any lock which nests in mmap_sem.
31 */
32long lttng_strlen_user_inatomic(const char *addr)
33{
34 long count = 0;
a824008c 35 mm_segment_t old_fs;
7b8ea3a5 36
a824008c
MD
37 if (!addr)
38 return 0;
39
40 old_fs = get_fs();
7b8ea3a5
MD
41 set_fs(KERNEL_DS);
42 pagefault_disable();
43 for (;;) {
44 char v;
2a8b83a1 45 unsigned long ret;
7b8ea3a5 46
0039dbe9 47 if (unlikely(!lttng_access_ok(VERIFY_READ,
f127e61e
MD
48 (__force const char __user *) addr,
49 sizeof(v))))
50 break;
7b8ea3a5
MD
51 ret = __copy_from_user_inatomic(&v,
52 (__force const char __user *)(addr),
53 sizeof(v));
2a8b83a1 54 if (unlikely(ret > 0))
7b8ea3a5
MD
55 break;
56 count++;
57 if (unlikely(!v))
58 break;
59 addr++;
60 }
61 pagefault_enable();
62 set_fs(old_fs);
63 return count;
64}
f127e61e 65EXPORT_SYMBOL_GPL(lttng_strlen_user_inatomic);
This page took 0.045243 seconds and 4 git commands to generate.