Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) |
2 | * | |
886d51a3 | 3 | * wrapper/splice.c |
5dd620fa | 4 | * |
711e3212 | 5 | * wrapper around splice_to_pipe. Using KALLSYMS to get its address when |
5dd620fa | 6 | * available, else we need to have a kernel that exports this function to GPL |
39d1ce90 | 7 | * modules. The export was introduced in kernel 4.2. |
5dd620fa | 8 | * |
886d51a3 | 9 | * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
5dd620fa MD |
10 | */ |
11 | ||
39d1ce90 MD |
12 | #include <lttng-kernel-version.h> |
13 | ||
14 | #if (defined(CONFIG_KALLSYMS) \ | |
15 | && (LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0))) | |
5dd620fa MD |
16 | |
17 | #include <linux/kallsyms.h> | |
18 | #include <linux/fs.h> | |
19 | #include <linux/splice.h> | |
5a2f5e92 | 20 | #include <wrapper/kallsyms.h> |
5dd620fa MD |
21 | |
22 | static | |
23 | ssize_t (*splice_to_pipe_sym)(struct pipe_inode_info *pipe, | |
24 | struct splice_pipe_desc *spd); | |
25 | ||
26 | ssize_t wrapper_splice_to_pipe(struct pipe_inode_info *pipe, | |
27 | struct splice_pipe_desc *spd) | |
28 | { | |
29 | if (!splice_to_pipe_sym) | |
c539a324 | 30 | splice_to_pipe_sym = (void *) kallsyms_lookup_funcptr("splice_to_pipe"); |
5dd620fa MD |
31 | if (splice_to_pipe_sym) { |
32 | return splice_to_pipe_sym(pipe, spd); | |
33 | } else { | |
e36de50d | 34 | printk_once(KERN_WARNING "LTTng: splice_to_pipe symbol lookup failed.\n"); |
5dd620fa MD |
35 | return -ENOSYS; |
36 | } | |
37 | } | |
38 | ||
60c64030 MJ |
39 | /* |
40 | * Canary function to check for 'splice_to_pipe()' at compile time. | |
41 | * | |
42 | * From 'include/linux/splice.h': | |
43 | * | |
44 | * extern ssize_t splice_to_pipe(struct pipe_inode_info *, | |
45 | * struct splice_pipe_desc *spd); | |
46 | */ | |
47 | __attribute__((unused)) static | |
48 | ssize_t __canary__splice_to_pipe(struct pipe_inode_info *pipe, | |
49 | struct splice_pipe_desc *spd) | |
50 | { | |
51 | return splice_to_pipe(pipe, spd); | |
52 | } | |
53 | ||
5dd620fa MD |
54 | #else |
55 | ||
56 | #include <linux/fs.h> | |
57 | #include <linux/splice.h> | |
58 | ||
59 | ssize_t wrapper_splice_to_pipe(struct pipe_inode_info *pipe, | |
60 | struct splice_pipe_desc *spd) | |
61 | { | |
62 | return splice_to_pipe(pipe, spd); | |
63 | } | |
64 | ||
65 | #endif |