From 64c91aff8ee14cb1871beb1213853353f9895c73 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Tue, 24 Jun 2014 12:43:56 +0400 Subject: [PATCH] [IMPROVE] add support kernel 3.12 Change-Id: I803ffa89d24d8cbcb42bc4d97f63916ed6ea1f08 Signed-off-by: Vyacheslav Cherkashin --- kprobe/arch/asm-x86/swap_kprobes.c | 4 ++++ kprobe/swap_kprobes_deps.c | 41 ++++++++++++++++++++++++++++---------- kprobe/swap_kprobes_deps.h | 11 ++++++++++ us_manager/us_manager_common.h | 6 ++++++ 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/kprobe/arch/asm-x86/swap_kprobes.c b/kprobe/arch/asm-x86/swap_kprobes.c index 9bc1f6c..3f1226a 100644 --- a/kprobe/arch/asm-x86/swap_kprobes.c +++ b/kprobe/arch/asm-x86/swap_kprobes.c @@ -844,7 +844,11 @@ int arch_init_module_deps() if (swap_text_poke == NULL) goto not_found; +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) sym = "show_registers"; +#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) */ + sym = "show_regs"; +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) */ swap_show_registers = (void *)swap_ksyms(sym); if (swap_show_registers == NULL) goto not_found; diff --git a/kprobe/swap_kprobes_deps.c b/kprobe/swap_kprobes_deps.c index 008910c..275a3b0 100644 --- a/kprobe/swap_kprobes_deps.c +++ b/kprobe/swap_kprobes_deps.c @@ -80,7 +80,7 @@ DECLARE_MOD_DEP_WRAPPER(swap_do_mmap_pgoff, unsigned long flags, unsigned long pgoff, unsigned long *populate) IMP_MOD_DEP_WRAPPER(do_mmap_pgoff, file, addr, len, prot, flags, pgoff, populate) -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) */ +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) DECLARE_MOD_FUNC_DEP(do_mmap_pgoff, unsigned long, struct file *file, unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long pgoff); DECLARE_MOD_DEP_WRAPPER(swap_do_mmap_pgoff, unsigned long, @@ -88,7 +88,7 @@ DECLARE_MOD_DEP_WRAPPER(swap_do_mmap_pgoff, unsigned long len, unsigned long prot, unsigned long flags, unsigned long pgoff) IMP_MOD_DEP_WRAPPER(do_mmap_pgoff, file, addr, len, prot, flags, pgoff) -#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) */ +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0) EXPORT_SYMBOL_GPL(swap_do_mmap_pgoff); @@ -124,13 +124,6 @@ static DECLARE_MOD_FUNC_DEP(get_gate_vma, struct vm_area_struct *, struct mm_str static DECLARE_MOD_FUNC_DEP(get_gate_vma, struct vm_area_struct *, struct task_struct *tsk); #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ -#ifdef CONFIG_HUGETLB_PAGE -DECLARE_MOD_FUNC_DEP(follow_hugetlb_page, int, struct mm_struct *mm, \ - struct vm_area_struct *vma, struct page **pages, \ - struct vm_area_struct **vmas, unsigned long *position, int *length, \ - int i, int write); -#endif - #ifdef __HAVE_ARCH_GATE_AREA #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) DECLARE_MOD_FUNC_DEP(in_gate_area, int, struct mm_struct *mm, unsigned long addr); @@ -216,13 +209,39 @@ IMP_MOD_DEP_WRAPPER (get_gate_vma, tsk) #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ #ifdef CONFIG_HUGETLB_PAGE + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) +DECLARE_MOD_FUNC_DEP(follow_hugetlb_page, \ + int, \ + struct mm_struct *mm, struct vm_area_struct *vma, \ + struct page **pages, struct vm_area_struct **vmas, \ + unsigned long *position, int *length, int i, \ + unsigned int flags); DECLARE_MOD_DEP_WRAPPER(swap_follow_hugetlb_page, int, struct mm_struct *mm, struct vm_area_struct *vma, struct page **pages, struct vm_area_struct **vmas, unsigned long *position, int *length, int i, - unsigned int write) - IMP_MOD_DEP_WRAPPER (follow_hugetlb_page, mm, vma, pages, vmas, position, length, i, write) + unsigned int flags) +IMP_MOD_DEP_WRAPPER(follow_hugetlb_page, \ + mm, vma, pages, vmas, position, length, i, flags) +#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) */ +DECLARE_MOD_FUNC_DEP(follow_hugetlb_page, \ + long, \ + struct mm_struct *mm, struct vm_area_struct *vma, \ + struct page **pages, struct vm_area_struct **vmas, \ + unsigned long *position, unsigned long *nr_pages, \ + long i, unsigned int flags); +DECLARE_MOD_DEP_WRAPPER(swap_follow_hugetlb_page, + long, + struct mm_struct *mm, struct vm_area_struct *vma, + struct page **pages, struct vm_area_struct **vmas, + unsigned long *position, unsigned long *nr_pages, + long i, unsigned int flags) +IMP_MOD_DEP_WRAPPER(follow_hugetlb_page, \ + mm, vma, pages, vmas, position, nr_pages, i, flags) +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) */ + #else /* CONFIG_HUGETLB_PAGE */ #define swap_follow_hugetlb_page follow_hugetlb_page #endif /* CONFIG_HUGETLB_PAGE */ diff --git a/kprobe/swap_kprobes_deps.h b/kprobe/swap_kprobes_deps.h index da58074..06a57e6 100644 --- a/kprobe/swap_kprobes_deps.h +++ b/kprobe/swap_kprobes_deps.h @@ -96,5 +96,16 @@ int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr, void * #define write_proc_vm_atomic(tsk, addr, buf, len) access_process_vm_atomic (tsk, addr, buf, len, 1) int page_present (struct mm_struct *mm, unsigned long addr); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) +unsigned long swap_do_mmap_pgoff(struct file *file, unsigned long addr, + unsigned long len, unsigned long prot, + unsigned long flags, unsigned long pgoff, + unsigned long *populate); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) +unsigned long swap_do_mmap_pgoff(struct file *file, unsigned long addr, + unsigned long len, unsigned long prot, + unsigned long flags, unsigned long pgoff); +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) */ + #endif /* _SWAP_KPROBES_DEPS_H */ diff --git a/us_manager/us_manager_common.h b/us_manager/us_manager_common.h index 13ad9dc..f190be2 100644 --- a/us_manager/us_manager_common.h +++ b/us_manager/us_manager_common.h @@ -26,6 +26,12 @@ #include #include +/* + * TODO: move declaration and definition swap_do_mmap_pgoff() + * from swap_kprobe.ko to swap_us_manager.ko + */ +#include + static inline unsigned long swap_do_mmap(struct file *filp, unsigned long addr, unsigned long len, unsigned long prot, -- 2.7.4