Move lttng wrappers into own module
[lttng-modules.git] / wrapper / page_alloc.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
389d7070
MD
2 * wrapper/page_alloc.c
3 *
0e14d6e7
MD
4 * wrapper around get_pfnblock_flags_mask and Ubuntu
5 * get_pageblock_flags_mask. Using KALLSYMS to get their address when
6 * available, else we need to have a kernel that exports this function
7 * to GPL modules.
389d7070
MD
8 *
9 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
389d7070
MD
10 */
11
5a2f5e92 12#include <lttng-kernel-version.h>
389d7070 13
ffc696db 14#if (defined(CONFIG_KALLSYMS) \
36561775
MD
15 && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,2) \
16 || LTTNG_KERNEL_RANGE(3,14,36, 3,15,0) \
17 || LTTNG_KERNEL_RANGE(3,18,10, 3,19,0) \
397c12b4
MD
18 || LTTNG_DEBIAN_KERNEL_RANGE(3,16,7,9,0,0, 3,17,0,0,0,0) \
19 || LTTNG_UBUNTU_KERNEL_RANGE(3,16,7,34, 3,17,0,0)))
389d7070
MD
20
21#include <linux/kallsyms.h>
22#include <linux/mm_types.h>
23#include <linux/module.h>
5a2f5e92
MD
24#include <wrapper/kallsyms.h>
25#include <wrapper/page_alloc.h>
389d7070
MD
26
27static
28unsigned long (*get_pfnblock_flags_mask_sym)(struct page *page,
29 unsigned long pfn,
30 unsigned long end_bitidx,
31 unsigned long mask);
32
33unsigned long wrapper_get_pfnblock_flags_mask(struct page *page,
34 unsigned long pfn,
35 unsigned long end_bitidx,
36 unsigned long mask)
37{
38 WARN_ON_ONCE(!get_pfnblock_flags_mask_sym);
39 if (get_pfnblock_flags_mask_sym) {
40 return get_pfnblock_flags_mask_sym(page, pfn, end_bitidx, mask);
41 } else {
42 return -ENOSYS;
43 }
44}
45EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask);
46
47int wrapper_get_pfnblock_flags_mask_init(void)
48{
49 get_pfnblock_flags_mask_sym =
50 (void *) kallsyms_lookup_funcptr("get_pfnblock_flags_mask");
51 if (!get_pfnblock_flags_mask_sym)
52 return -1;
53 return 0;
54}
1c999280 55EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init);
389d7070 56
0e14d6e7 57#else
389d7070
MD
58
59#include <linux/pageblock-flags.h>
60
0e14d6e7
MD
61#endif
62
63#if (defined(CONFIG_KALLSYMS) \
64 && LTTNG_UBUNTU_KERNEL_RANGE(3,13,11,50, 3,14,0,0))
65
66#include <linux/kallsyms.h>
67#include <linux/mm_types.h>
68#include <linux/module.h>
5a2f5e92
MD
69#include <wrapper/kallsyms.h>
70#include <wrapper/page_alloc.h>
0e14d6e7
MD
71
72static
73unsigned long (*get_pageblock_flags_mask_sym)(struct page *page,
74 unsigned long end_bitidx,
75 unsigned long mask);
76
77unsigned long wrapper_get_pageblock_flags_mask(struct page *page,
78 unsigned long end_bitidx,
79 unsigned long mask)
80{
81 WARN_ON_ONCE(!get_pageblock_flags_mask_sym);
82 if (get_pageblock_flags_mask_sym) {
83 return get_pageblock_flags_mask_sym(page, end_bitidx, mask);
84 } else {
85 return -ENOSYS;
86 }
87}
88EXPORT_SYMBOL_GPL(wrapper_get_pageblock_flags_mask);
89
90int wrapper_get_pageblock_flags_mask_init(void)
91{
92 get_pageblock_flags_mask_sym =
93 (void *) kallsyms_lookup_funcptr("get_pageblock_flags_mask");
94 if (!get_pageblock_flags_mask_sym)
95 return -1;
96 return 0;
97}
1c999280 98EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask_init);
0e14d6e7
MD
99
100#else
101
102#include <linux/pageblock-flags.h>
103
104#endif
This page took 0.035702 seconds and 4 git commands to generate.