2 * test_rodata.c: functional test for mark_rodata_ro function
4 * (C) Copyright 2008 Intel Corporation
5 * Author: Arjan van de Ven <arjan@linux.intel.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; version 2
12 #include <asm/cacheflush.h>
13 #include <asm/sections.h>
19 unsigned long start
, end
;
21 /* test 1: read the value */
22 /* If this test fails, some previous testrun has clobbered the state */
23 if (!rodata_test_data
) {
24 printk(KERN_ERR
"rodata_test: test 1 fails (start data)\n");
28 /* test 2: write to the variable; this should fault */
30 * If this test fails, we managed to overwrite the data
32 * This is written in assembly to be able to catch the
33 * exception that is supposed to happen in the correct
39 "0: mov %[zero],(%[rodata_test])\n"
40 " mov %[zero], %[rslt]\n"
42 ".section .fixup,\"ax\"\n"
46 : [rslt
] "=r" (result
)
47 : [rodata_test
] "r" (&rodata_test_data
), [zero
] "r" (0UL)
52 printk(KERN_ERR
"rodata_test: test data was not read only\n");
56 /* test 3: check the value hasn't changed */
57 /* If this test fails, we managed to overwrite the data */
58 if (!rodata_test_data
) {
59 printk(KERN_ERR
"rodata_test: Test 3 fails (end data)\n");
62 /* test 4: check if the rodata section is 4Kb aligned */
63 start
= (unsigned long)__start_rodata
;
64 end
= (unsigned long)__end_rodata
;
65 if (start
& (PAGE_SIZE
- 1)) {
66 printk(KERN_ERR
"rodata_test: .rodata is not 4k aligned\n");
69 if (end
& (PAGE_SIZE
- 1)) {
70 printk(KERN_ERR
"rodata_test: .rodata end is not 4k aligned\n");