OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <setjmp.h> | 7 #include <setjmp.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 fprintf(stderr, "Skipping assert_addr_is_unreadable() under Valgrind\n"); | 44 fprintf(stderr, "Skipping assert_addr_is_unreadable() under Valgrind\n"); |
45 return; | 45 return; |
46 } | 46 } |
47 | 47 |
48 rc = nacl_exception_set_handler(test_handler); | 48 rc = nacl_exception_set_handler(test_handler); |
49 CHECK(rc == 0); | 49 CHECK(rc == 0); |
50 if (!setjmp(g_jmp_buf)) { | 50 if (!setjmp(g_jmp_buf)) { |
51 char value = *addr; | 51 char value = *addr; |
52 /* If we reach here, the assertion failed. */ | 52 /* If we reach here, the assertion failed. */ |
53 fprintf(stderr, "Address %p was readable, and contained %i\n", | 53 fprintf(stderr, "Address %p was readable, and contained %i\n", |
54 addr, value); | 54 (void *)addr, value); |
55 exit(1); | 55 exit(1); |
56 } | 56 } |
57 /* | 57 /* |
58 * Clean up: Unregister the exception handler so that we do not | 58 * Clean up: Unregister the exception handler so that we do not |
59 * accidentally return through g_jmp_buf if an exception occurs. | 59 * accidentally return through g_jmp_buf if an exception occurs. |
60 */ | 60 */ |
61 rc = nacl_exception_set_handler(NULL); | 61 rc = nacl_exception_set_handler(NULL); |
62 CHECK(rc == 0); | 62 CHECK(rc == 0); |
63 } | 63 } |
64 | 64 |
65 static void check_addr_is_unwritable(volatile char *addr, char value) { | 65 static void check_addr_is_unwritable(volatile char *addr, char value) { |
66 int rc; | 66 int rc; |
67 | 67 |
68 if (getenv("RUNNING_ON_VALGRIND") != NULL) { | 68 if (getenv("RUNNING_ON_VALGRIND") != NULL) { |
69 fprintf(stderr, "Skipping assert_addr_is_unwritable() under Valgrind\n"); | 69 fprintf(stderr, "Skipping assert_addr_is_unwritable() under Valgrind\n"); |
70 return; | 70 return; |
71 } | 71 } |
72 if (getenv("RUNNING_ON_ASAN") != NULL) { | 72 if (getenv("RUNNING_ON_ASAN") != NULL) { |
73 fprintf(stderr, "Skipping assert_addr_is_unwritable() under ASan\n"); | 73 fprintf(stderr, "Skipping assert_addr_is_unwritable() under ASan\n"); |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 rc = nacl_exception_set_handler(test_handler); | 77 rc = nacl_exception_set_handler(test_handler); |
78 CHECK(rc == 0); | 78 CHECK(rc == 0); |
79 if (!setjmp(g_jmp_buf)) { | 79 if (!setjmp(g_jmp_buf)) { |
80 *addr = value; | 80 *addr = value; |
81 /* If we reach here, the assertion failed. */ | 81 /* If we reach here, the assertion failed. */ |
82 fprintf(stderr, "Address %p was writable, %i was written\n", | 82 fprintf(stderr, "Address %p was writable, %i was written\n", |
83 addr, value); | 83 (void *)addr, value); |
84 exit(1); | 84 exit(1); |
85 } | 85 } |
86 /* | 86 /* |
87 * Clean up: Unregister the exception handler so that we do not | 87 * Clean up: Unregister the exception handler so that we do not |
88 * accidentally return through g_jmp_buf if an exception occurs. | 88 * accidentally return through g_jmp_buf if an exception occurs. |
89 */ | 89 */ |
90 rc = nacl_exception_set_handler(NULL); | 90 rc = nacl_exception_set_handler(NULL); |
91 CHECK(rc == 0); | 91 CHECK(rc == 0); |
92 } | 92 } |
93 | 93 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 struct prot_access_specs { | 143 struct prot_access_specs { |
144 int map_prot; | 144 int map_prot; |
145 int map_flags; | 145 int map_flags; |
146 int map_offset; | 146 int map_offset; |
147 }; | 147 }; |
148 | 148 |
149 int test_prot_access(int fd, size_t map_size, void *test_spec) { | 149 int test_prot_access(int fd, size_t map_size, void *test_spec) { |
150 struct prot_access_specs *spec = (struct prot_access_specs *) test_spec; | 150 struct prot_access_specs *spec = (struct prot_access_specs *) test_spec; |
151 char *addr; | 151 char *addr; |
152 | 152 |
153 addr = (char *) mmap(NULL, | 153 addr = (char *) mmap(NULL, |
154 map_size, | 154 map_size, |
155 spec->map_prot, | 155 spec->map_prot, |
156 spec->map_flags, | 156 spec->map_flags, |
157 fd, | 157 fd, |
158 spec->map_offset); | 158 spec->map_offset); |
159 if (MAP_FAILED == addr) { | 159 if (MAP_FAILED == addr) { |
160 fprintf(stderr, "test_prot_access: mmap failed, errno %d\n", errno); | 160 fprintf(stderr, "test_prot_access: mmap failed, errno %d\n", errno); |
161 return 1; | 161 return 1; |
162 } | 162 } |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 tests[ix].map_size, | 691 tests[ix].map_size, |
692 tests[ix].test_specifics); | 692 tests[ix].test_specifics); |
693 printf("%s\n", (0 == test_errors) ? "PASS" : "FAIL"); | 693 printf("%s\n", (0 == test_errors) ? "PASS" : "FAIL"); |
694 err_count += test_errors; | 694 err_count += test_errors; |
695 test_file_close(fd); | 695 test_file_close(fd); |
696 } | 696 } |
697 } | 697 } |
698 | 698 |
699 return (err_count > 0) ? -1 : 0; | 699 return (err_count > 0) ? -1 : 0; |
700 } | 700 } |
OLD | NEW |