Skip to content

Commit

Permalink
Pass __program_executable_name to cosmo libc
Browse files Browse the repository at this point in the history
We recently introduced an improved system to Cosmo Libc and Ape Loader
for detecting the path of the executable. This caused issues for blink
because Cosmo was choosing `/proc/self/exe` rather than `argv[0]`. The
solution is to use Cosmo CRT's new feature that lets us pass the value
in the the RDX register to _start(). This allows programs like redbean
which need to introspect their own zip assets, to start working again.

Fixes #162
  • Loading branch information
jart committed Jan 21, 2024
1 parent 46d82a0 commit f96cdbe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion blink/argv.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void LoadArgv(struct Machine *m, char *execfn, char *prog, char **args,
char **vars, u8 rng[16]) {
u8 *bytes;
struct Elf *elf;
i64 sp, *p, *bloc;
i64 sp, dx, *p, *bloc;
size_t i, narg, nenv, naux, nall;
elf = &m->system->elf;
naux = 10;
Expand All @@ -85,6 +85,7 @@ void LoadArgv(struct Machine *m, char *execfn, char *prog, char **args,
nall = 1 + narg + 1 + nenv + 1 + naux * 2;
bloc = (i64 *)malloc(sizeof(i64) * nall);
p = bloc + nall;
dx = PushString(m, prog);
PUSH_AUXV(0, 0);
PUSH_AUXV(AT_UID_LINUX, getuid());
PUSH_AUXV(AT_EUID_LINUX, geteuid());
Expand Down Expand Up @@ -112,6 +113,7 @@ void LoadArgv(struct Machine *m, char *execfn, char *prog, char **args,
while ((sp - nall * sizeof(i64)) & (STACKALIGN - 1)) --sp;
sp -= nall * sizeof(i64);
Write64(m->sp, sp);
Write64(m->dx, dx);
Write64(m->di, 0); /* or ape detects freebsd */
bytes = (u8 *)malloc(nall * 8);
for (i = 0; i < nall; ++i) {
Expand Down

0 comments on commit f96cdbe

Please sign in to comment.