| 1 | /* |
| 2 | * wrapper/page_alloc.c |
| 3 | * |
| 4 | * wrapper around get_pfnblock_flags_mask. Using KALLSYMS to get its address |
| 5 | * when available, else we need to have a kernel that exports this function to |
| 6 | * GPL modules. |
| 7 | * |
| 8 | * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Lesser General Public |
| 12 | * License as published by the Free Software Foundation; only |
| 13 | * version 2.1 of the License. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with this library; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | */ |
| 24 | |
| 25 | #include "../lttng-kernel-version.h" |
| 26 | |
| 27 | #if (defined(CONFIG_KALLSYMS) \ |
| 28 | && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,2) \ |
| 29 | || LTTNG_DEBIAN_KERNEL_RANGE(3,16,7,9,0,0, 3,17,0,0,0,0))) |
| 30 | |
| 31 | #include <linux/kallsyms.h> |
| 32 | #include <linux/mm_types.h> |
| 33 | #include <linux/module.h> |
| 34 | #include "kallsyms.h" |
| 35 | #include "page_alloc.h" |
| 36 | |
| 37 | static |
| 38 | unsigned long (*get_pfnblock_flags_mask_sym)(struct page *page, |
| 39 | unsigned long pfn, |
| 40 | unsigned long end_bitidx, |
| 41 | unsigned long mask); |
| 42 | |
| 43 | unsigned long wrapper_get_pfnblock_flags_mask(struct page *page, |
| 44 | unsigned long pfn, |
| 45 | unsigned long end_bitidx, |
| 46 | unsigned long mask) |
| 47 | { |
| 48 | WARN_ON_ONCE(!get_pfnblock_flags_mask_sym); |
| 49 | if (get_pfnblock_flags_mask_sym) { |
| 50 | return get_pfnblock_flags_mask_sym(page, pfn, end_bitidx, mask); |
| 51 | } else { |
| 52 | return -ENOSYS; |
| 53 | } |
| 54 | } |
| 55 | EXPORT_SYMBOL_GPL(wrapper_get_pfnblock_flags_mask); |
| 56 | |
| 57 | int wrapper_get_pfnblock_flags_mask_init(void) |
| 58 | { |
| 59 | get_pfnblock_flags_mask_sym = |
| 60 | (void *) kallsyms_lookup_funcptr("get_pfnblock_flags_mask"); |
| 61 | if (!get_pfnblock_flags_mask_sym) |
| 62 | return -1; |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | #else /* #if defined(CONFIG_KALLSYMS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,2)) */ |
| 67 | |
| 68 | #include <linux/pageblock-flags.h> |
| 69 | |
| 70 | #endif /* #else #if defined(CONFIG_KALLSYMS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,2)) */ |