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

Side by Side Diff: src/untrusted/minidump_generator/build_id.c

Issue 14757008: Minidumper: Get the nexe's build ID from PT_NOTE when available (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
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
4 * found in the LICENSE file.
5 */
6
7 #include <assert.h>
8
9 #include "native_client/src/include/elf32.h"
10
11
12 extern const Elf32_Ehdr __ehdr_start __attribute__((weak));
13
14 static uintptr_t note_align(uintptr_t value) {
15 return (value + 3) & ~3;
16 }
17
18 int nacl_get_build_id(const char **data, size_t *size) {
19 if (&__ehdr_start != NULL &&
20 __ehdr_start.e_ident[EI_CLASS] == ELFCLASS32 &&
21 __ehdr_start.e_phentsize == sizeof(Elf32_Phdr)) {
22 int phnum = __ehdr_start.e_phnum;
23 uintptr_t start_addr = (uintptr_t) &__ehdr_start;
24 Elf32_Phdr *phdrs = (Elf32_Phdr *) (start_addr + __ehdr_start.e_phoff);
25 for (int i = 0; i < phnum; ++i) {
26 Elf32_Phdr *phdr = &phdrs[i];
27 if (phdr->p_type == PT_NOTE) {
28 Elf32_Nhdr *note = (Elf32_Nhdr *) (start_addr + phdr->p_offset);
29 uintptr_t note_end = (uintptr_t) note + phdr->p_memsz;
30 while ((uintptr_t) note < note_end) {
31 uintptr_t name_ptr = (uintptr_t) &note[1];
32 assert(name_ptr <= note_end);
33 uintptr_t desc_ptr = note_align(name_ptr + note->n_namesz);
34 uintptr_t next_ptr = note_align(desc_ptr + note->n_descsz);
35 assert(next_ptr <= note_end);
36 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
37 *data = (const char *) desc_ptr;
38 *size = note->n_descsz;
39 return 1;
40 }
41 note = (Elf32_Nhdr *) next_ptr;
42 }
43 }
44 }
45 }
46 return 0;
47 }
OLDNEW
« no previous file with comments | « src/untrusted/minidump_generator/build_id.h ('k') | src/untrusted/minidump_generator/minidump_generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698