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

Side by Side Diff: fusl/src/ldso/dl_iterate_phdr.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « fusl/src/ldso/arm/dlsym.s ('k') | fusl/src/ldso/dladdr.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #ifndef SHARED
2
3 #include <elf.h>
4 #include <link.h>
5 #include "libc.h"
6
7 #define AUX_CNT 38
8
9 int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
10 {
11 unsigned char *p;
12 ElfW(Phdr) *phdr, *tls_phdr=0;
13 size_t base = 0;
14 size_t n;
15 struct dl_phdr_info info;
16 size_t i, aux[AUX_CNT];
17
18 for (i=0; libc.auxv[i]; i+=2)
19 if (libc.auxv[i]<AUX_CNT) aux[libc.auxv[i]] = libc.auxv[i+1];
20
21 for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) {
22 phdr = (void *)p;
23 if (phdr->p_type == PT_PHDR)
24 base = aux[AT_PHDR] - phdr->p_vaddr;
25 if (phdr->p_type == PT_TLS)
26 tls_phdr = phdr;
27 }
28 info.dlpi_addr = base;
29 info.dlpi_name = "/proc/self/exe";
30 info.dlpi_phdr = (void *)aux[AT_PHDR];
31 info.dlpi_phnum = aux[AT_PHNUM];
32 info.dlpi_adds = 0;
33 info.dlpi_subs = 0;
34 if (tls_phdr) {
35 info.dlpi_tls_modid = 1;
36 info.dlpi_tls_data = (void *)(base + tls_phdr->p_vaddr);
37 } else {
38 info.dlpi_tls_modid = 0;
39 info.dlpi_tls_data = 0;
40 }
41 return (callback)(&info, sizeof (info), data);
42 }
43 #endif
OLDNEW
« no previous file with comments | « fusl/src/ldso/arm/dlsym.s ('k') | fusl/src/ldso/dladdr.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698