2 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/sched.h>
18 #include <asm/pgtable.h>
19 #include <asm/tlbflush.h>
21 struct page_change_data
{
26 static int change_page_range(pte_t
*ptep
, pgtable_t token
, unsigned long addr
,
29 struct page_change_data
*cdata
= data
;
32 pte
= clear_pte_bit(pte
, cdata
->clear_mask
);
33 pte
= set_pte_bit(pte
, cdata
->set_mask
);
39 static int change_memory_common(unsigned long addr
, int numpages
,
40 pgprot_t set_mask
, pgprot_t clear_mask
)
42 unsigned long start
= addr
;
43 unsigned long size
= PAGE_SIZE
*numpages
;
44 unsigned long end
= start
+ size
;
46 struct page_change_data data
;
48 if (!PAGE_ALIGNED(addr
)) {
54 if (start
< MODULES_VADDR
|| start
>= MODULES_END
)
57 if (end
< MODULES_VADDR
|| end
>= MODULES_END
)
63 data
.set_mask
= set_mask
;
64 data
.clear_mask
= clear_mask
;
66 ret
= apply_to_page_range(&init_mm
, start
, size
, change_page_range
,
69 flush_tlb_kernel_range(start
, end
);
73 int set_memory_ro(unsigned long addr
, int numpages
)
75 return change_memory_common(addr
, numpages
,
80 int set_memory_rw(unsigned long addr
, int numpages
)
82 return change_memory_common(addr
, numpages
,
84 __pgprot(PTE_RDONLY
));
87 int set_memory_nx(unsigned long addr
, int numpages
)
89 return change_memory_common(addr
, numpages
,
93 EXPORT_SYMBOL_GPL(set_memory_nx
);
95 int set_memory_x(unsigned long addr
, int numpages
)
97 return change_memory_common(addr
, numpages
,
101 EXPORT_SYMBOL_GPL(set_memory_x
);
This page took 0.033281 seconds and 5 git commands to generate.