| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 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 <assert.h> | 7 #include <assert.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <limits.h> | 10 #include <limits.h> |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 219 } |
| 220 | 220 |
| 221 /* | 221 /* |
| 222 * Verify that mmap into the NULL pointer guard page will fail. | 222 * Verify that mmap into the NULL pointer guard page will fail. |
| 223 */ | 223 */ |
| 224 | 224 |
| 225 bool test3() { | 225 bool test3() { |
| 226 void *res; | 226 void *res; |
| 227 | 227 |
| 228 printf("test3\n"); | 228 printf("test3\n"); |
| 229 if (NONSFI_MODE) { |
| 230 /* |
| 231 * This test checks a security property of the NaCl TCB. However, when |
| 232 * calling Linux's mmap() syscall directly, we can't necessarily expect |
| 233 * a specific error value for this case. |
| 234 */ |
| 235 printf("test3 skipped\n"); |
| 236 return true; |
| 237 } |
| 238 |
| 229 res = mmap(static_cast<void*>(0), (size_t) (1 << 16), | 239 res = mmap(static_cast<void*>(0), (size_t) (1 << 16), |
| 230 PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0); | 240 PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0); |
| 231 printf("res = %p\n", res); | 241 printf("res = %p\n", res); |
| 232 const int kExpectedErrno = NONSFI_MODE ? EPERM : EINVAL; | 242 if (MAP_FAILED == res) { |
| 233 if (MAP_FAILED == res && kExpectedErrno == errno) { | 243 printf("errno = %d\n", errno); |
| 244 } |
| 245 if (MAP_FAILED == res && EINVAL == errno) { |
| 234 printf("mmap okay\n"); | 246 printf("mmap okay\n"); |
| 235 return true; | 247 return true; |
| 236 } | 248 } |
| 237 printf("mmap should not have succeeded, or failed with wrong error\n"); | 249 printf("mmap should not have succeeded, or failed with wrong error\n"); |
| 238 return false; | 250 return false; |
| 239 } | 251 } |
| 240 | 252 |
| 241 /* | 253 /* |
| 242 * Verify that mmap/MAP_FIXED with a non-page-aligned address will fail. | 254 * Verify that mmap/MAP_FIXED with a non-page-aligned address will fail. |
| 243 */ | 255 */ |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 // run the full test suite | 582 // run the full test suite |
| 571 passed = testSuite(); | 583 passed = testSuite(); |
| 572 | 584 |
| 573 if (passed) { | 585 if (passed) { |
| 574 printf("All tests PASSED\n"); | 586 printf("All tests PASSED\n"); |
| 575 exit(0); | 587 exit(0); |
| 576 } | 588 } |
| 577 printf("One or more tests FAILED\n"); | 589 printf("One or more tests FAILED\n"); |
| 578 exit(-1); | 590 exit(-1); |
| 579 } | 591 } |
| OLD | NEW |