Move headers under include/
[lttng-modules.git] / probes / lttng-probe-user.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
7b8ea3a5
MD
3 * lttng-probe-user.c
4 *
5 * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7b8ea3a5
MD
6 */
7
8#include <linux/uaccess.h>
8d90c035 9#include <linux/module.h>
b5304713 10#include <lttng/lttng-probe-user.h>
7b8ea3a5
MD
11
12/*
13 * Calculate string length. Include final null terminating character if there is
14 * one, or ends at first fault. Disabling page faults ensures that we can safely
15 * call this from pretty much any context, including those where the caller
16 * holds mmap_sem, or any lock which nests in mmap_sem.
17 */
18long lttng_strlen_user_inatomic(const char *addr)
19{
20 long count = 0;
a824008c 21 mm_segment_t old_fs;
7b8ea3a5 22
a824008c
MD
23 if (!addr)
24 return 0;
25
26 old_fs = get_fs();
7b8ea3a5
MD
27 set_fs(KERNEL_DS);
28 pagefault_disable();
29 for (;;) {
30 char v;
2a8b83a1 31 unsigned long ret;
7b8ea3a5 32
a865837a 33 if (unlikely(!access_ok((__force const char __user *) addr,
f127e61e
MD
34 sizeof(v))))
35 break;
7b8ea3a5
MD
36 ret = __copy_from_user_inatomic(&v,
37 (__force const char __user *)(addr),
38 sizeof(v));
2a8b83a1 39 if (unlikely(ret > 0))
7b8ea3a5
MD
40 break;
41 count++;
42 if (unlikely(!v))
43 break;
44 addr++;
45 }
46 pagefault_enable();
47 set_fs(old_fs);
48 return count;
49}
f127e61e 50EXPORT_SYMBOL_GPL(lttng_strlen_user_inatomic);
This page took 0.037833 seconds and 4 git commands to generate.