Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: third_party/android_crazy_linker/src/tests/test_util.h

Issue 328153002: Roll to android/platform/ndk/681f1b744aec1b0888f4c7a68165720db9670300 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fork
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // A set of common helper functions used by crazy_linker tests. 5 // A set of common helper functions used by crazy_linker tests.
6 // IMPORTANT: ALL FUNCTIONS HERE ARE INLINED. This avoids adding a 6 // IMPORTANT: ALL FUNCTIONS HERE ARE INLINED. This avoids adding a
7 // dependency on another source file for all tests that include this 7 // dependency on another source file for all tests that include this
8 // header. 8 // header.
9 9
10 #ifndef TEST_UTIL_H 10 #ifndef TEST_UTIL_H
11 #define TEST_UTIL_H 11 #define TEST_UTIL_H
12 12
13 #include <crazy_linker.h> 13 #include <crazy_linker.h>
14 14
15 #include <dirent.h> 15 #include <dirent.h>
16 #include <errno.h> 16 #include <errno.h>
17 #include <limits.h> 17 #include <limits.h>
18 #include <stdarg.h> 18 #include <stdarg.h>
19 #include <stdio.h> 19 #include <stdio.h>
20 #include <stdlib.h> 20 #include <stdlib.h>
21 #include <sys/mman.h> 21 #include <sys/mman.h>
22 #include <sys/socket.h> 22 #include <sys/socket.h>
23 #include <sys/stat.h> 23 #include <sys/stat.h>
24 #include <sys/uio.h> 24 #include <sys/uio.h>
25 #include <unistd.h> 25 #include <unistd.h>
26 #ifndef __STDC_FORMAT_MACROS
27 #define __STDC_FORMAT_MACROS // to get PRI and SCN in 32-bit inttypes.h
28 #endif
29 #include <inttypes.h>
26 30
27 namespace { 31 namespace {
28 32
29 // Print an error message and exit the process. 33 // Print an error message and exit the process.
30 // Message must be terminated by a newline. 34 // Message must be terminated by a newline.
31 inline void Panic(const char* fmt, ...) { 35 inline void Panic(const char* fmt, ...) {
32 va_list args; 36 va_list args;
33 fprintf(stderr, "PANIC: "); 37 fprintf(stderr, "PANIC: ");
34 va_start(args, fmt); 38 va_start(args, fmt);
35 vfprintf(stderr, fmt, args); 39 vfprintf(stderr, fmt, args);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 while (fgets(line, sizeof line, file)) { 338 while (fgets(line, sizeof line, file)) {
335 if (strstr(line, "with_relro")) { 339 if (strstr(line, "with_relro")) {
336 // The supported library names are "lib<name>_with_relro.so". 340 // The supported library names are "lib<name>_with_relro.so".
337 printf("%s", line); 341 printf("%s", line);
338 if (strstr(line, "/dev/ashmem/RELRO:")) { 342 if (strstr(line, "/dev/ashmem/RELRO:")) {
339 count_relros++; 343 count_relros++;
340 // Check that they are read-only mappings. 344 // Check that they are read-only mappings.
341 if (!strstr(line, " r--")) 345 if (!strstr(line, " r--"))
342 Panic("Shared RELRO mapping is not readonly!\n"); 346 Panic("Shared RELRO mapping is not readonly!\n");
343 // Check that they can't be remapped read-write. 347 // Check that they can't be remapped read-write.
344 unsigned vma_start, vma_end; 348 uint64_t vma_start, vma_end;
345 if (sscanf(line, "%x-%x", &vma_start, &vma_end) != 2) 349 if (sscanf(line, "%" SCNx64 "-%" SCNx64, &vma_start, &vma_end) != 2)
346 Panic("Could not parse VM address range!\n"); 350 Panic("Could not parse VM address range!\n");
347 int ret = ::mprotect( 351 int ret = ::mprotect(
348 (void*)vma_start, vma_end - vma_start, PROT_READ | PROT_WRITE); 352 (void*)vma_start, vma_end - vma_start, PROT_READ | PROT_WRITE);
349 if (ret == 0) 353 if (ret == 0)
350 Panic("Could remap shared RELRO as writable, should not happen!\n"); 354 Panic("Could remap shared RELRO as writable, should not happen!\n");
351 355
352 if (errno != EACCES) 356 if (errno != EACCES)
353 Panic("remapping shared RELRO to writable failed with: %s\n", 357 Panic("remapping shared RELRO to writable failed with: %s\n",
354 strerror(errno)); 358 strerror(errno));
355 } 359 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 Panic("Could not use %s shared RELRO: %s\n", 460 Panic("Could not use %s shared RELRO: %s\n",
457 this->name, 461 this->name,
458 crazy_context_get_error(context)); 462 crazy_context_get_error(context));
459 } 463 }
460 } 464 }
461 }; 465 };
462 466
463 } // namespace 467 } // namespace
464 468
465 #endif // TEST_UTIL_H 469 #endif // TEST_UTIL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698