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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/ldso/dl_iterate_phdr.c
diff --git a/fusl/src/ldso/dl_iterate_phdr.c b/fusl/src/ldso/dl_iterate_phdr.c
new file mode 100644
index 0000000000000000000000000000000000000000..49b321a0203cb53e198506dac9a827878b24f459
--- /dev/null
+++ b/fusl/src/ldso/dl_iterate_phdr.c
@@ -0,0 +1,43 @@
+#ifndef SHARED
+
+#include <elf.h>
+#include <link.h>
+#include "libc.h"
+
+#define AUX_CNT 38
+
+int dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data)
+{
+ unsigned char *p;
+ ElfW(Phdr) *phdr, *tls_phdr=0;
+ size_t base = 0;
+ size_t n;
+ struct dl_phdr_info info;
+ size_t i, aux[AUX_CNT];
+
+ for (i=0; libc.auxv[i]; i+=2)
+ if (libc.auxv[i]<AUX_CNT) aux[libc.auxv[i]] = libc.auxv[i+1];
+
+ for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) {
+ phdr = (void *)p;
+ if (phdr->p_type == PT_PHDR)
+ base = aux[AT_PHDR] - phdr->p_vaddr;
+ if (phdr->p_type == PT_TLS)
+ tls_phdr = phdr;
+ }
+ info.dlpi_addr = base;
+ info.dlpi_name = "/proc/self/exe";
+ info.dlpi_phdr = (void *)aux[AT_PHDR];
+ info.dlpi_phnum = aux[AT_PHNUM];
+ info.dlpi_adds = 0;
+ info.dlpi_subs = 0;
+ if (tls_phdr) {
+ info.dlpi_tls_modid = 1;
+ info.dlpi_tls_data = (void *)(base + tls_phdr->p_vaddr);
+ } else {
+ info.dlpi_tls_modid = 0;
+ info.dlpi_tls_data = 0;
+ }
+ return (callback)(&info, sizeof (info), data);
+}
+#endif
« 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