Skip to content

Commit f96cdbe

Browse files
committed
Pass __program_executable_name to cosmo libc
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
1 parent 46d82a0 commit f96cdbe

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

blink/argv.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void LoadArgv(struct Machine *m, char *execfn, char *prog, char **args,
7070
char **vars, u8 rng[16]) {
7171
u8 *bytes;
7272
struct Elf *elf;
73-
i64 sp, *p, *bloc;
73+
i64 sp, dx, *p, *bloc;
7474
size_t i, narg, nenv, naux, nall;
7575
elf = &m->system->elf;
7676
naux = 10;
@@ -85,6 +85,7 @@ void LoadArgv(struct Machine *m, char *execfn, char *prog, char **args,
8585
nall = 1 + narg + 1 + nenv + 1 + naux * 2;
8686
bloc = (i64 *)malloc(sizeof(i64) * nall);
8787
p = bloc + nall;
88+
dx = PushString(m, prog);
8889
PUSH_AUXV(0, 0);
8990
PUSH_AUXV(AT_UID_LINUX, getuid());
9091
PUSH_AUXV(AT_EUID_LINUX, geteuid());
@@ -112,6 +113,7 @@ void LoadArgv(struct Machine *m, char *execfn, char *prog, char **args,
112113
while ((sp - nall * sizeof(i64)) & (STACKALIGN - 1)) --sp;
113114
sp -= nall * sizeof(i64);
114115
Write64(m->sp, sp);
116+
Write64(m->dx, dx);
115117
Write64(m->di, 0); /* or ape detects freebsd */
116118
bytes = (u8 *)malloc(nall * 8);
117119
for (i = 0; i < nall; ++i) {

0 commit comments

Comments
 (0)