mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-09 19:30:29 +00:00
wip pass program path in register
This commit is contained in:
parent
4673a6f186
commit
abc5809db0
1 changed files with 10 additions and 13 deletions
23
ape/loader.c
23
ape/loader.c
|
@ -224,7 +224,8 @@ struct ApeLoader {
|
||||||
};
|
};
|
||||||
|
|
||||||
EXTERN_C long SystemCall(long, long, long, long, long, long, long, int);
|
EXTERN_C long SystemCall(long, long, long, long, long, long, long, int);
|
||||||
EXTERN_C void Launch(void *, long, void *, int) __attribute__((__noreturn__));
|
EXTERN_C void
|
||||||
|
Launch(void *, long, void *, void *, int) __attribute__((__noreturn__));
|
||||||
|
|
||||||
extern char __executable_start[];
|
extern char __executable_start[];
|
||||||
extern char _end[];
|
extern char _end[];
|
||||||
|
@ -643,7 +644,8 @@ static char *Commandv(struct PathSearcher *ps, int os, const char *name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((__noreturn__)) static void Spawn(int os, const char *exe, int fd,
|
__attribute__((__noreturn__)) static void Spawn(int os, const char *exe,
|
||||||
|
const char *path, int fd,
|
||||||
long *sp, unsigned long pagesz,
|
long *sp, unsigned long pagesz,
|
||||||
struct ElfEhdr *e,
|
struct ElfEhdr *e,
|
||||||
struct ElfPhdr *p) {
|
struct ElfPhdr *p) {
|
||||||
|
@ -801,12 +803,12 @@ __attribute__((__noreturn__)) static void Spawn(int os, const char *exe, int fd,
|
||||||
Msyscall(dynbase + code, codesize, os);
|
Msyscall(dynbase + code, codesize, os);
|
||||||
|
|
||||||
/* call program entrypoint */
|
/* call program entrypoint */
|
||||||
Launch(IsFreebsd() ? sp : 0, dynbase + e->e_entry, sp, os);
|
Launch(IsFreebsd() ? sp : 0, dynbase + e->e_entry, path, sp, os);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf,
|
static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf,
|
||||||
const char *exe, int fd, long *sp, long *auxv,
|
const char *exe, const char *path, int fd, long *sp,
|
||||||
unsigned long pagesz, int os) {
|
long *auxv, unsigned long pagesz, int os) {
|
||||||
long i, rc;
|
long i, rc;
|
||||||
unsigned size;
|
unsigned size;
|
||||||
struct ElfEhdr *e;
|
struct ElfEhdr *e;
|
||||||
|
@ -921,7 +923,7 @@ static const char *TryElf(struct ApeLoader *M, union ElfEhdrBuf *ebuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we're now ready to load */
|
/* we're now ready to load */
|
||||||
Spawn(os, exe, fd, sp, pagesz, e, p);
|
Spawn(os, exe, path, fd, sp, pagesz, e, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((__noreturn__)) static void ShowUsage(int os, int fd, int rc) {
|
__attribute__((__noreturn__)) static void ShowUsage(int os, int fd, int rc) {
|
||||||
|
@ -1088,11 +1090,6 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp,
|
||||||
}
|
}
|
||||||
pe = ebuf->buf + rc;
|
pe = ebuf->buf + rc;
|
||||||
|
|
||||||
/* change argv[0] to resolved path (TODO remove) */
|
|
||||||
if (argc > 0 && prog) {
|
|
||||||
argv[0] = prog;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ape intended behavior
|
/* ape intended behavior
|
||||||
1. if ape, will scan shell script for elf printf statements
|
1. if ape, will scan shell script for elf printf statements
|
||||||
2. shell script may have multiple lines producing elf headers
|
2. shell script may have multiple lines producing elf headers
|
||||||
|
@ -1125,9 +1122,9 @@ EXTERN_C __attribute__((__noreturn__)) void ApeLoader(long di, long *sp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i >= sizeof(ebuf->ehdr)) {
|
if (i >= sizeof(ebuf->ehdr)) {
|
||||||
TryElf(M, ebuf, exe, fd, sp, auxv, pagesz, os);
|
TryElf(M, ebuf, exe, prog, fd, sp, auxv, pagesz, os);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Pexit(os, exe, 0, TryElf(M, ebuf, exe, fd, sp, auxv, pagesz, os));
|
Pexit(os, exe, 0, TryElf(M, ebuf, exe, prog, fd, sp, auxv, pagesz, os));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue