Thomas Gleixner | 4317cf9 | 2019-05-31 01:09:38 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 2 | /* |
| 3 | * sortextable.c: Sort the kernel's exception table |
| 4 | * |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 5 | * Copyright 2011 - 2012 Cavium, Inc. |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 6 | * |
| 7 | * Based on code taken from recortmcount.c which is: |
| 8 | * |
| 9 | * Copyright 2009 John F. Reiser <jreiser@BitWagon.com>. All rights reserved. |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 10 | * |
| 11 | * Restructured to fit Linux format, as well as other updates: |
| 12 | * Copyright 2010 Steven Rostedt <srostedt@redhat.com>, Red Hat Inc. |
| 13 | */ |
| 14 | |
| 15 | /* |
| 16 | * Strategy: alter the vmlinux file in-place. |
| 17 | */ |
| 18 | |
| 19 | #include <sys/types.h> |
| 20 | #include <sys/mman.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <getopt.h> |
| 23 | #include <elf.h> |
| 24 | #include <fcntl.h> |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <unistd.h> |
| 29 | |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 30 | #include <tools/be_byteshift.h> |
| 31 | #include <tools/le_byteshift.h> |
| 32 | |
Vineet Gupta | f06d19e | 2013-11-15 12:08:05 +0530 | [diff] [blame] | 33 | #ifndef EM_ARCOMPACT |
| 34 | #define EM_ARCOMPACT 93 |
| 35 | #endif |
| 36 | |
Max Filippov | 25df819 | 2014-02-18 15:29:11 +0400 | [diff] [blame] | 37 | #ifndef EM_XTENSA |
| 38 | #define EM_XTENSA 94 |
| 39 | #endif |
| 40 | |
Will Deacon | adace89 | 2013-05-08 17:29:24 +0100 | [diff] [blame] | 41 | #ifndef EM_AARCH64 |
| 42 | #define EM_AARCH64 183 |
| 43 | #endif |
| 44 | |
Michal Simek | 372c720 | 2014-01-23 15:52:46 -0800 | [diff] [blame] | 45 | #ifndef EM_MICROBLAZE |
| 46 | #define EM_MICROBLAZE 189 |
| 47 | #endif |
| 48 | |
Vineet Gupta | b3210d14 | 2013-11-22 13:05:58 +0530 | [diff] [blame] | 49 | #ifndef EM_ARCV2 |
| 50 | #define EM_ARCV2 195 |
| 51 | #endif |
| 52 | |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 53 | /* |
| 54 | * Get the whole file as a programming convenience in order to avoid |
| 55 | * malloc+lseek+read+free of many pieces. If successful, then mmap |
| 56 | * avoids copying unused pieces; else just read the whole file. |
| 57 | * Open for both read and write. |
| 58 | */ |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 59 | static void *mmap_file(char const *fname, size_t *size) |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 60 | { |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 61 | int fd; |
| 62 | struct stat sb; |
| 63 | void *addr = NULL; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 64 | |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 65 | fd = open(fname, O_RDWR); |
| 66 | if (fd < 0) { |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 67 | perror(fname); |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 68 | return NULL; |
| 69 | } |
| 70 | if (fstat(fd, &sb) < 0) { |
| 71 | perror(fname); |
| 72 | goto out; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 73 | } |
| 74 | if (!S_ISREG(sb.st_mode)) { |
| 75 | fprintf(stderr, "not a regular file: %s\n", fname); |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 76 | goto out; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 77 | } |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 78 | addr = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 79 | if (addr == MAP_FAILED) { |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 80 | fprintf(stderr, "Could not mmap file: %s\n", fname); |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 81 | goto out; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 82 | } |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 83 | |
| 84 | *size = sb.st_size; |
| 85 | |
| 86 | out: |
| 87 | close(fd); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 88 | return addr; |
| 89 | } |
| 90 | |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 91 | static uint64_t r8be(const uint64_t *x) |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 92 | { |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 93 | return get_unaligned_be64(x); |
| 94 | } |
| 95 | static uint32_t rbe(const uint32_t *x) |
| 96 | { |
| 97 | return get_unaligned_be32(x); |
| 98 | } |
| 99 | static uint16_t r2be(const uint16_t *x) |
| 100 | { |
| 101 | return get_unaligned_be16(x); |
| 102 | } |
| 103 | static uint64_t r8le(const uint64_t *x) |
| 104 | { |
| 105 | return get_unaligned_le64(x); |
| 106 | } |
| 107 | static uint32_t rle(const uint32_t *x) |
| 108 | { |
| 109 | return get_unaligned_le32(x); |
| 110 | } |
| 111 | static uint16_t r2le(const uint16_t *x) |
| 112 | { |
| 113 | return get_unaligned_le16(x); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 114 | } |
| 115 | |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 116 | static void w8be(uint64_t val, uint64_t *x) |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 117 | { |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 118 | put_unaligned_be64(val, x); |
| 119 | } |
| 120 | static void wbe(uint32_t val, uint32_t *x) |
| 121 | { |
| 122 | put_unaligned_be32(val, x); |
| 123 | } |
| 124 | static void w2be(uint16_t val, uint16_t *x) |
| 125 | { |
| 126 | put_unaligned_be16(val, x); |
| 127 | } |
| 128 | static void w8le(uint64_t val, uint64_t *x) |
| 129 | { |
| 130 | put_unaligned_le64(val, x); |
| 131 | } |
| 132 | static void wle(uint32_t val, uint32_t *x) |
| 133 | { |
| 134 | put_unaligned_le32(val, x); |
| 135 | } |
| 136 | static void w2le(uint16_t val, uint16_t *x) |
| 137 | { |
| 138 | put_unaligned_le16(val, x); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 139 | } |
| 140 | |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 141 | static uint64_t (*r8)(const uint64_t *); |
| 142 | static uint32_t (*r)(const uint32_t *); |
| 143 | static uint16_t (*r2)(const uint16_t *); |
| 144 | static void (*w8)(uint64_t, uint64_t *); |
| 145 | static void (*w)(uint32_t, uint32_t *); |
| 146 | static void (*w2)(uint16_t, uint16_t *); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 147 | |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 148 | typedef void (*table_sort_t)(char *, int); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 149 | |
Jamie Iles | 59c3645 | 2013-11-12 15:06:51 -0800 | [diff] [blame] | 150 | /* |
| 151 | * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of |
| 152 | * the way to -256..-1, to avoid conflicting with real section |
| 153 | * indices. |
| 154 | */ |
| 155 | #define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1)) |
| 156 | |
| 157 | static inline int is_shndx_special(unsigned int i) |
| 158 | { |
| 159 | return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE; |
| 160 | } |
| 161 | |
| 162 | /* Accessor for sym->st_shndx, hides ugliness of "64k sections" */ |
| 163 | static inline unsigned int get_secindex(unsigned int shndx, |
| 164 | unsigned int sym_offs, |
| 165 | const Elf32_Word *symtab_shndx_start) |
| 166 | { |
| 167 | if (is_shndx_special(shndx)) |
| 168 | return SPECIAL(shndx); |
| 169 | if (shndx != SHN_XINDEX) |
| 170 | return shndx; |
| 171 | return r(&symtab_shndx_start[sym_offs]); |
| 172 | } |
| 173 | |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 174 | /* 32 bit and 64 bit are very similar */ |
| 175 | #include "sortextable.h" |
| 176 | #define SORTEXTABLE_64 |
| 177 | #include "sortextable.h" |
| 178 | |
Heiko Carstens | eb608fb | 2012-09-05 13:26:11 +0200 | [diff] [blame] | 179 | static int compare_relative_table(const void *a, const void *b) |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 180 | { |
| 181 | int32_t av = (int32_t)r(a); |
| 182 | int32_t bv = (int32_t)r(b); |
| 183 | |
| 184 | if (av < bv) |
| 185 | return -1; |
| 186 | if (av > bv) |
| 187 | return 1; |
| 188 | return 0; |
| 189 | } |
| 190 | |
Tony Luck | 548acf1 | 2016-02-17 10:20:12 -0800 | [diff] [blame] | 191 | static void x86_sort_relative_table(char *extab_image, int image_size) |
| 192 | { |
| 193 | int i; |
| 194 | |
| 195 | i = 0; |
| 196 | while (i < image_size) { |
| 197 | uint32_t *loc = (uint32_t *)(extab_image + i); |
| 198 | |
| 199 | w(r(loc) + i, loc); |
| 200 | w(r(loc + 1) + i + 4, loc + 1); |
| 201 | w(r(loc + 2) + i + 8, loc + 2); |
| 202 | |
| 203 | i += sizeof(uint32_t) * 3; |
| 204 | } |
| 205 | |
| 206 | qsort(extab_image, image_size / 12, 12, compare_relative_table); |
| 207 | |
| 208 | i = 0; |
| 209 | while (i < image_size) { |
| 210 | uint32_t *loc = (uint32_t *)(extab_image + i); |
| 211 | |
| 212 | w(r(loc) - i, loc); |
| 213 | w(r(loc + 1) - (i + 4), loc + 1); |
| 214 | w(r(loc + 2) - (i + 8), loc + 2); |
| 215 | |
| 216 | i += sizeof(uint32_t) * 3; |
| 217 | } |
| 218 | } |
| 219 | |
Heiko Carstens | eb608fb | 2012-09-05 13:26:11 +0200 | [diff] [blame] | 220 | static void sort_relative_table(char *extab_image, int image_size) |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 221 | { |
| 222 | int i; |
| 223 | |
| 224 | /* |
| 225 | * Do the same thing the runtime sort does, first normalize to |
| 226 | * being relative to the start of the section. |
| 227 | */ |
| 228 | i = 0; |
| 229 | while (i < image_size) { |
| 230 | uint32_t *loc = (uint32_t *)(extab_image + i); |
| 231 | w(r(loc) + i, loc); |
| 232 | i += 4; |
| 233 | } |
| 234 | |
Heiko Carstens | eb608fb | 2012-09-05 13:26:11 +0200 | [diff] [blame] | 235 | qsort(extab_image, image_size / 8, 8, compare_relative_table); |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 236 | |
| 237 | /* Now denormalize. */ |
| 238 | i = 0; |
| 239 | while (i < image_size) { |
| 240 | uint32_t *loc = (uint32_t *)(extab_image + i); |
| 241 | w(r(loc) - i, loc); |
| 242 | i += 4; |
| 243 | } |
| 244 | } |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 245 | |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 246 | static int |
| 247 | do_file(char const *const fname, void *addr) |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 248 | { |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 249 | table_sort_t custom_sort = NULL; |
| 250 | Elf32_Ehdr *ehdr = addr; |
| 251 | int rc = -1; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 252 | |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 253 | switch (ehdr->e_ident[EI_DATA]) { |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 254 | default: |
| 255 | fprintf(stderr, "unrecognized ELF data encoding %d: %s\n", |
| 256 | ehdr->e_ident[EI_DATA], fname); |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 257 | return -1; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 258 | case ELFDATA2LSB: |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 259 | r = rle; |
| 260 | r2 = r2le; |
| 261 | r8 = r8le; |
| 262 | w = wle; |
| 263 | w2 = w2le; |
| 264 | w8 = w8le; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 265 | break; |
| 266 | case ELFDATA2MSB: |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 267 | r = rbe; |
| 268 | r2 = r2be; |
| 269 | r8 = r8be; |
| 270 | w = wbe; |
| 271 | w2 = w2be; |
| 272 | w8 = w8be; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 273 | break; |
| 274 | } /* end switch */ |
| 275 | if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0 |
Ard Biesheuvel | 7b957b6 | 2016-01-10 11:42:28 +0100 | [diff] [blame] | 276 | || (r2(&ehdr->e_type) != ET_EXEC && r2(&ehdr->e_type) != ET_DYN) |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 277 | || ehdr->e_ident[EI_VERSION] != EV_CURRENT) { |
Ard Biesheuvel | 7b957b6 | 2016-01-10 11:42:28 +0100 | [diff] [blame] | 278 | fprintf(stderr, "unrecognized ET_EXEC/ET_DYN file %s\n", fname); |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 279 | return -1; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 280 | } |
| 281 | |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 282 | custom_sort = NULL; |
| 283 | switch (r2(&ehdr->e_machine)) { |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 284 | default: |
| 285 | fprintf(stderr, "unrecognized e_machine %d %s\n", |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 286 | r2(&ehdr->e_machine), fname); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 287 | break; |
| 288 | case EM_386: |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 289 | case EM_X86_64: |
Tony Luck | 548acf1 | 2016-02-17 10:20:12 -0800 | [diff] [blame] | 290 | custom_sort = x86_sort_relative_table; |
| 291 | break; |
| 292 | |
Heiko Carstens | 3193a98 | 2012-07-24 14:51:34 +0200 | [diff] [blame] | 293 | case EM_S390: |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 294 | case EM_AARCH64: |
Helge Deller | 0de7985 | 2016-03-23 16:00:46 +0100 | [diff] [blame] | 295 | case EM_PARISC: |
Nicholas Piggin | 5b9ff02 | 2016-10-13 16:42:55 +1100 | [diff] [blame] | 296 | case EM_PPC: |
| 297 | case EM_PPC64: |
Heiko Carstens | eb608fb | 2012-09-05 13:26:11 +0200 | [diff] [blame] | 298 | custom_sort = sort_relative_table; |
| 299 | break; |
Vineet Gupta | f06d19e | 2013-11-15 12:08:05 +0530 | [diff] [blame] | 300 | case EM_ARCOMPACT: |
Vineet Gupta | b3210d14 | 2013-11-22 13:05:58 +0530 | [diff] [blame] | 301 | case EM_ARCV2: |
Stephen Boyd | ee951c6 | 2012-10-29 19:19:34 +0100 | [diff] [blame] | 302 | case EM_ARM: |
Michal Simek | 372c720 | 2014-01-23 15:52:46 -0800 | [diff] [blame] | 303 | case EM_MICROBLAZE: |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 304 | case EM_MIPS: |
Max Filippov | 25df819 | 2014-02-18 15:29:11 +0400 | [diff] [blame] | 305 | case EM_XTENSA: |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 306 | break; |
| 307 | } /* end switch */ |
| 308 | |
| 309 | switch (ehdr->e_ident[EI_CLASS]) { |
| 310 | default: |
| 311 | fprintf(stderr, "unrecognized ELF class %d %s\n", |
| 312 | ehdr->e_ident[EI_CLASS], fname); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 313 | break; |
| 314 | case ELFCLASS32: |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 315 | if (r2(&ehdr->e_ehsize) != sizeof(Elf32_Ehdr) |
| 316 | || r2(&ehdr->e_shentsize) != sizeof(Elf32_Shdr)) { |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 317 | fprintf(stderr, |
Ard Biesheuvel | 7b957b6 | 2016-01-10 11:42:28 +0100 | [diff] [blame] | 318 | "unrecognized ET_EXEC/ET_DYN file: %s\n", fname); |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 319 | break; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 320 | } |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 321 | rc = do32(ehdr, fname, custom_sort); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 322 | break; |
| 323 | case ELFCLASS64: { |
| 324 | Elf64_Ehdr *const ghdr = (Elf64_Ehdr *)ehdr; |
David Daney | d59a168 | 2012-04-24 11:23:14 -0700 | [diff] [blame] | 325 | if (r2(&ghdr->e_ehsize) != sizeof(Elf64_Ehdr) |
| 326 | || r2(&ghdr->e_shentsize) != sizeof(Elf64_Shdr)) { |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 327 | fprintf(stderr, |
Ard Biesheuvel | 7b957b6 | 2016-01-10 11:42:28 +0100 | [diff] [blame] | 328 | "unrecognized ET_EXEC/ET_DYN file: %s\n", fname); |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 329 | break; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 330 | } |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 331 | rc = do64(ghdr, fname, custom_sort); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 332 | break; |
| 333 | } |
| 334 | } /* end switch */ |
| 335 | |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 336 | return rc; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | int |
| 340 | main(int argc, char *argv[]) |
| 341 | { |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 342 | int i, n_error = 0; /* gcc-4.3.0 false positive complaint */ |
| 343 | size_t size = 0; |
| 344 | void *addr = NULL; |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 345 | |
| 346 | if (argc < 2) { |
| 347 | fprintf(stderr, "usage: sortextable vmlinux...\n"); |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | /* Process each file in turn, allowing deep failure. */ |
| 352 | for (i = 1; i < argc; i++) { |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 353 | addr = mmap_file(argv[i], &size); |
| 354 | if (!addr) { |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 355 | ++n_error; |
Shile Zhang | 3c47b78 | 2019-12-04 08:46:27 +0800 | [diff] [blame^] | 356 | continue; |
| 357 | } |
| 358 | |
| 359 | if (do_file(argv[i], addr)) |
| 360 | ++n_error; |
| 361 | |
| 362 | munmap(addr, size); |
David Daney | a79f248 | 2012-04-19 14:59:55 -0700 | [diff] [blame] | 363 | } |
| 364 | return !!n_error; |
| 365 | } |