mailing list of musl libc
 help / color / mirror / code / Atom feed
From: rcombs <rcombs@rcombs.me>
To: musl@lists.openwall.com
Subject: [musl] [PATCH 1/2] ldso: when run via CLI, set auxv as if the app was loaded by the kernel
Date: Sun, 29 Mar 2020 15:15:00 -0500	[thread overview]
Message-ID: <1585512901-18979-1-git-send-email-rcombs@rcombs.me> (raw)

---
 ldso/dynlink.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 6468f20..a9144e2 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1808,6 +1808,22 @@ void __dls3(size_t *sp, size_t *auxv)
 			}
 			dprintf(1, "\t%s (%p)\n", ldso.name, ldso.base);
 		}
+
+		// Make it look to the app as if it was loaded by the kernel
+		for (i=0; auxv[i]; i+=2) {
+			if (auxv[i] == AT_BASE)
+				auxv[i + 1] = (size_t)ldso.base;
+			if (auxv[i] == AT_PHDR)
+				auxv[i + 1] = (size_t)app.phdr;
+			if (auxv[i] == AT_ENTRY)
+				auxv[i + 1] = aux[AT_ENTRY];
+			if (auxv[i] == AT_PHNUM)
+				auxv[i + 1] = app.phnum;
+			if (auxv[i] == AT_PHENT)
+				auxv[i + 1] = app.phentsize;
+			if (auxv[i] == AT_EXECFN)
+				auxv[i + 1] = (size_t)app.name;
+		}
 	}
 	if (app.tls.size) {
 		libc.tls_head = tls_tail = &app.tls;
-- 
2.7.4

             reply	other threads:[~2020-03-29 20:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-29 20:15 rcombs [this message]
2020-03-29 20:15 ` [musl] [PATCH 2/2] crt: add dcrt1, with support for locating the dynamic loader at runtime rcombs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1585512901-18979-1-git-send-email-rcombs@rcombs.me \
    --to=rcombs@rcombs.me \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).