mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-10 11:50:29 +00:00
Work around Rosetta clobbering startup registers on M1 Macs (issue #429)
Rosetta doesn't correctly respect the startup registers as defined in LC_UNIXTHREAD which makes platform detection go awry. But at least Rosetta appears to consistently set rbx to 0x00000000ffffffff and rdx to 0x0000000000000001 at startup for every x64 executable I could get my hands on. So we use that to detect Rosetta's presence and set up the correct registers for XNU. Thanks to @pkulchenko and @jart for pointers on getting this done :)
This commit is contained in:
parent
a6f65eea7c
commit
a7bab48b78
4 changed files with 38 additions and 4 deletions
|
@ -213,7 +213,18 @@ macho: .long 0xFEEDFACE+1
|
||||||
//
|
//
|
||||||
// @see APE_LOADER_ENTRY
|
// @see APE_LOADER_ENTRY
|
||||||
// @see ape/loader.h
|
// @see ape/loader.h
|
||||||
_start: mov %rsp,%rsi
|
_start:
|
||||||
|
|
||||||
|
// Hack for detecting M1 Rosetta environment.
|
||||||
|
// https://github.com/jart/cosmopolitan/issues/429#issuecomment-1166704377
|
||||||
|
cmp $-1,%ebx
|
||||||
|
jne 0f
|
||||||
|
cmp $+1,%edx
|
||||||
|
jne 0f
|
||||||
|
mov $XNU,%dl
|
||||||
|
mov $0,%rcx
|
||||||
|
|
||||||
|
0: mov %rsp,%rsi
|
||||||
jmp ApeLoader
|
jmp ApeLoader
|
||||||
.endfn _start,globl
|
.endfn _start,globl
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,18 @@ macho: .long 0xFEEDFACE+1
|
||||||
.endobj macho,globl
|
.endobj macho,globl
|
||||||
|
|
||||||
.align 64
|
.align 64
|
||||||
_start: mov %rsp,%rsi
|
_start:
|
||||||
|
|
||||||
|
// Hack for detecting M1 Rosetta environment.
|
||||||
|
// https://github.com/jart/cosmopolitan/issues/429#issuecomment-1166704377
|
||||||
|
cmp $-1,%ebx
|
||||||
|
jne 0f
|
||||||
|
cmp $+1,%edx
|
||||||
|
jne 0f
|
||||||
|
mov $XNU,%dl
|
||||||
|
mov $0,%rcx
|
||||||
|
|
||||||
|
0: mov %rsp,%rsi
|
||||||
jmp ApeLoader
|
jmp ApeLoader
|
||||||
.endfn _start,globl
|
.endfn _start,globl
|
||||||
|
|
||||||
|
|
|
@ -595,11 +595,11 @@ __attribute__((__noreturn__)) void ApeLoader(long di, long *sp, char dl,
|
||||||
// detect freebsd
|
// detect freebsd
|
||||||
if (handoff) {
|
if (handoff) {
|
||||||
os = handoff->os;
|
os = handoff->os;
|
||||||
|
} else if (SupportsXnu() && dl == XNU) {
|
||||||
|
os = XNU;
|
||||||
} else if (SupportsFreebsd() && di) {
|
} else if (SupportsFreebsd() && di) {
|
||||||
os = FREEBSD;
|
os = FREEBSD;
|
||||||
sp = (long *)di;
|
sp = (long *)di;
|
||||||
} else if (SupportsXnu() && dl == XNU) {
|
|
||||||
os = XNU;
|
|
||||||
} else {
|
} else {
|
||||||
os = 0;
|
os = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,18 @@
|
||||||
// @noreturn
|
// @noreturn
|
||||||
_start:
|
_start:
|
||||||
|
|
||||||
|
#if SupportsXnu()
|
||||||
|
// Hack for detecting M1 Rosetta environment.
|
||||||
|
// https://github.com/jart/cosmopolitan/issues/429#issuecomment-1166704377
|
||||||
|
cmp $-1,%ebx
|
||||||
|
jne 0f
|
||||||
|
cmp $+1,%edx
|
||||||
|
jne 0f
|
||||||
|
mov $XNU,%cl
|
||||||
|
mov $0,%rdi
|
||||||
|
0:
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SupportsFreebsd()
|
#if SupportsFreebsd()
|
||||||
// detect free besiyata dishmaya
|
// detect free besiyata dishmaya
|
||||||
test %rdi,%rdi
|
test %rdi,%rdi
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue