From 1163f1377212c45c1d0bf43ae6028885f3b61f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Sun, 24 Dec 2023 17:29:33 -0500 Subject: [PATCH] cosmo2 receives os from loader FreeBSD aarch64 now traps early rather than pretending to be Linux. o/aarch64/examples/env.com still works on Linux and Xnu. --- libc/runtime/cosmo2.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/libc/runtime/cosmo2.c b/libc/runtime/cosmo2.c index 57067b5ab..7b7569851 100644 --- a/libc/runtime/cosmo2.c +++ b/libc/runtime/cosmo2.c @@ -78,7 +78,8 @@ static const char *DecodeMagnum(const char *p, long *r) { return *r = x, p; } -wontreturn textstartup void cosmo(long *sp, struct Syslib *m1, char *exename) { +wontreturn textstartup void cosmo(long *sp, struct Syslib *m1, char *exename, + int os) { // get startup timestamp as early as possible // its used by --strace and also kprintf() %T @@ -111,14 +112,26 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1, char *exename) { __program_executable_name = exename; program_invocation_name = argv[0]; __oldstack = (intptr_t)sp; + if (os) { + hostos = os; + } else { + /* old loader */ + if (SupportsXnu() && m1) { + hostos = _HOSTXNU; + } else if (SupportsLinux()) { + hostos = _HOSTLINUX; + } else { + notpossible; + } + } - // detect apple m1 environment const char *magnums; - if (SupportsXnu() && (__syslib = m1)) { - hostos = _HOSTXNU; + if (IsXnu()) { + if (!(__syslib = m1)) { + notpossible; + } magnums = syscon_xnu; - } else if (SupportsLinux()) { - hostos = _HOSTLINUX; + } else if (IsLinux()) { magnums = syscon_linux; } else { notpossible; @@ -130,7 +143,7 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1, char *exename) { } // check system call abi compatibility - if (SupportsXnu() && __syslib && __syslib->__version < SYSLIB_VERSION) { + if (IsXnu() && __syslib->__version < SYSLIB_VERSION) { sys_write(2, "need newer ape loader\n", 22); _Exit(127); }