fix: inherit process environment and untrack libc objects
This commit is contained in:
@@ -34,8 +34,10 @@ static inline long _sys2(long nr, long a1, long a2) {
|
||||
#define SYS_EXIT 0
|
||||
#define SYS_GETARGS 25
|
||||
#define SYS_GETEXECPATH 151
|
||||
#define SYS_GETENVIRON 171
|
||||
|
||||
extern int main(int argc, char** argv);
|
||||
extern void __libc_init_environ(const char *blob, unsigned long len);
|
||||
|
||||
/* Global constructor/destructor tables. The linker provides these
|
||||
boundary symbols whenever .preinit_array/.init_array/.fini_array
|
||||
@@ -72,9 +74,13 @@ static void _run_fini_array(void) {
|
||||
void _start(void) {
|
||||
/* Static: 4 KiB args + 256 argv slots would crowd a 32 KiB stack. */
|
||||
static char argbuf[4096];
|
||||
static char envbuf[4096];
|
||||
static char pathbuf[256];
|
||||
static char* argv[256];
|
||||
int len = (int)_sys2(SYS_GETARGS, (long)argbuf, (long)sizeof(argbuf));
|
||||
int envlen = (int)_sys2(SYS_GETENVIRON, (long)envbuf, (long)sizeof(envbuf));
|
||||
if (envlen > 0)
|
||||
__libc_init_environ(envbuf, (unsigned long)envlen);
|
||||
|
||||
int argc = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user