Chromium Code Reviews| Index: src/untrusted/minidump_generator/build_id.c |
| diff --git a/src/untrusted/minidump_generator/build_id.c b/src/untrusted/minidump_generator/build_id.c |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..270950fb3b45a7f2550d0f8f82baa36da5b58c0e |
| --- /dev/null |
| +++ b/src/untrusted/minidump_generator/build_id.c |
| @@ -0,0 +1,47 @@ |
| +/* |
| + * Copyright (c) 2013 The Native Client Authors. All rights reserved. |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include <assert.h> |
| + |
| +#include "native_client/src/include/elf32.h" |
| + |
| + |
| +extern const Elf32_Ehdr __ehdr_start __attribute__((weak)); |
| + |
| +static uintptr_t note_align(uintptr_t value) { |
| + return (value + 3) & ~3; |
| +} |
| + |
| +int nacl_get_build_id(const char **data, size_t *size) { |
| + if (&__ehdr_start != NULL && |
| + __ehdr_start.e_ident[EI_CLASS] == ELFCLASS32 && |
| + __ehdr_start.e_phentsize == sizeof(Elf32_Phdr)) { |
| + int phnum = __ehdr_start.e_phnum; |
| + uintptr_t start_addr = (uintptr_t) &__ehdr_start; |
| + Elf32_Phdr *phdrs = (Elf32_Phdr *) (start_addr + __ehdr_start.e_phoff); |
| + for (int i = 0; i < phnum; ++i) { |
| + Elf32_Phdr *phdr = &phdrs[i]; |
| + if (phdr->p_type == PT_NOTE) { |
| + Elf32_Nhdr *note = (Elf32_Nhdr *) (start_addr + phdr->p_offset); |
| + uintptr_t note_end = (uintptr_t) note + phdr->p_memsz; |
| + while ((uintptr_t) note < note_end) { |
| + uintptr_t name_ptr = (uintptr_t) ¬e[1]; |
| + assert(name_ptr <= note_end); |
| + uintptr_t desc_ptr = note_align(name_ptr + note->n_namesz); |
| + uintptr_t next_ptr = note_align(desc_ptr + note->n_descsz); |
| + assert(next_ptr <= note_end); |
| + if (note->n_type == NT_GNU_BUILD_ID) { |
|
Roland McGrath
2013/05/10 16:58:13
This needs to check that the name is "GNU" (four b
Mark Seaborn
2013/05/10 18:25:28
Ah, good point. I hadn't quite realised it was na
|
| + *data = (const char *) desc_ptr; |
| + *size = note->n_descsz; |
| + return 1; |
| + } |
| + note = (Elf32_Nhdr *) next_ptr; |
| + } |
| + } |
| + } |
| + } |
| + return 0; |
| +} |