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.
This commit is contained in:
Jōshin 2023-12-24 17:29:33 -05:00
parent bb2602a524
commit 1163f13772
No known key found for this signature in database

View file

@ -78,7 +78,8 @@ static const char *DecodeMagnum(const char *p, long *r) {
return *r = x, p; 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 // get startup timestamp as early as possible
// its used by --strace and also kprintf() %T // 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_executable_name = exename;
program_invocation_name = argv[0]; program_invocation_name = argv[0];
__oldstack = (intptr_t)sp; __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; const char *magnums;
if (SupportsXnu() && (__syslib = m1)) { if (IsXnu()) {
hostos = _HOSTXNU; if (!(__syslib = m1)) {
notpossible;
}
magnums = syscon_xnu; magnums = syscon_xnu;
} else if (SupportsLinux()) { } else if (IsLinux()) {
hostos = _HOSTLINUX;
magnums = syscon_linux; magnums = syscon_linux;
} else { } else {
notpossible; notpossible;
@ -130,7 +143,7 @@ wontreturn textstartup void cosmo(long *sp, struct Syslib *m1, char *exename) {
} }
// check system call abi compatibility // 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); sys_write(2, "need newer ape loader\n", 22);
_Exit(127); _Exit(127);
} }