Rename LINUX to _HOSTLINUX etc. to reduce clashes (#655)

Co-authored-by: tkchia <tkchia-cosmo@gmx.com>
This commit is contained in:
tkchia 2022-10-11 11:31:25 +08:00 committed by GitHub
parent 9209ea63a7
commit 7a06760e6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 85 additions and 85 deletions

View file

@ -874,7 +874,7 @@ ape_macho:
.long (520f-510f)/4 # count
510: .quad 0 # rax
.quad IMAGE_BASE_VIRTUAL # rbx
.quad XNU # rcx
.quad _HOSTXNU # rcx
.quad 0 # rdx
.quad 0 # rdi
.quad 0 # rsi
@ -1555,7 +1555,7 @@ kernel: movabs $ape_stack_vaddr,%rsp
.byte 0x0f,0x1f,0207 # nop rdi binbase
.long (IMAGE_BASE_VIRTUAL-IMAGE_BASE_REAL)/512
#endif
push $METAL # sets __hostos in crt.S
push $_HOSTMETAL # sets __hostos in crt.S
pop %rcx
push $0
mov %rsp,%rbp

View file

@ -175,7 +175,7 @@ macho: .long 0xFEEDFACE+1
510: .quad 0 # rax
.quad 0 # rbx
.quad 0 # rcx
.quad XNU # rdx
.quad _HOSTXNU # rdx
.quad 0 # rdi
.quad 0 # rsi
.quad 0 # rbp
@ -221,7 +221,7 @@ _start:
jne 0f
cmp $+1,%edx
jne 0f
mov $XNU,%dl
mov $_HOSTXNU,%dl
xor %ecx,%ecx
0: mov %rsp,%rsi

View file

@ -90,7 +90,7 @@ macho: .long 0xFEEDFACE+1
510: .quad 0 # rax
.quad 0 # rbx
.quad 0 # rcx
.quad XNU # rdx
.quad _HOSTXNU # rdx
.quad 0 # rdi
.quad 0 # rsi
.quad 0 # rbp
@ -121,7 +121,7 @@ _start:
jne 0f
cmp $+1,%edx
jne 0f
mov $XNU,%dl
mov $_HOSTXNU,%dl
xor %ecx,%ecx
0: mov %rsp,%rsi

View file

@ -90,23 +90,23 @@ void __sigenter_openbsd(int, void *, void *) hidden;
static void sigaction_cosmo2native(union metasigaction *sa) {
if (!sa) return;
switch (__hostos) {
case LINUX:
case _HOSTLINUX:
SWITCHEROO(sa->cosmo, sa->linux, sa_handler, sa_flags, sa_restorer,
sa_mask);
break;
case XNU:
case _HOSTXNU:
SWITCHEROO(sa->cosmo, sa->xnu_in, sa_handler, sa_flags, sa_restorer,
sa_mask);
break;
case FREEBSD:
case _HOSTFREEBSD:
SWITCHEROO(sa->cosmo, sa->freebsd, sa_handler, sa_flags, sa_flags,
sa_mask);
break;
case OPENBSD:
case _HOSTOPENBSD:
SWITCHEROO(sa->cosmo, sa->openbsd, sa_handler, sa_flags, sa_flags,
sa_mask);
break;
case NETBSD:
case _HOSTNETBSD:
SWITCHEROO(sa->cosmo, sa->netbsd, sa_handler, sa_flags, sa_flags,
sa_mask);
break;
@ -118,23 +118,23 @@ static void sigaction_cosmo2native(union metasigaction *sa) {
static void sigaction_native2cosmo(union metasigaction *sa) {
if (!sa) return;
switch (__hostos) {
case LINUX:
case _HOSTLINUX:
SWITCHEROO(sa->linux, sa->cosmo, sa_handler, sa_flags, sa_restorer,
sa_mask);
break;
case XNU:
case _HOSTXNU:
SWITCHEROO(sa->xnu_out, sa->cosmo, sa_handler, sa_flags, sa_flags,
sa_mask);
break;
case FREEBSD:
case _HOSTFREEBSD:
SWITCHEROO(sa->freebsd, sa->cosmo, sa_handler, sa_flags, sa_flags,
sa_mask);
break;
case OPENBSD:
case _HOSTOPENBSD:
SWITCHEROO(sa->openbsd, sa->cosmo, sa_handler, sa_flags, sa_flags,
sa_mask);
break;
case NETBSD:
case _HOSTNETBSD:
SWITCHEROO(sa->netbsd, sa->cosmo, sa_handler, sa_flags, sa_flags,
sa_mask);
break;

View file

@ -38,7 +38,7 @@ _start:
jne 0f
cmp $+1,%edx
jne 0f
mov $XNU,%cl
mov $_HOSTXNU,%cl
xor %edi,%edi
0:
#endif
@ -48,7 +48,7 @@ _start:
test %rdi,%rdi
cmovnz %rdi,%rsp
jz 0f
movb $FREEBSD,%cl
movb $_HOSTFREEBSD,%cl
0:
#endif

View file

@ -12,13 +12,13 @@
#define SUPPORT_VECTOR 255
#endif
#define LINUX 1
#define METAL 2
#define WINDOWS 4
#define XNU 8
#define OPENBSD 16
#define FREEBSD 32
#define NETBSD 64
#define _HOSTLINUX 1
#define _HOSTMETAL 2
#define _HOSTWINDOWS 4
#define _HOSTXNU 8
#define _HOSTOPENBSD 16
#define _HOSTFREEBSD 32
#define _HOSTNETBSD 64
#ifdef NDEBUG
#define NoDebug() 1
@ -68,36 +68,36 @@
#define IsPositionIndependent() 0
#endif
#define SupportsLinux() ((SUPPORT_VECTOR & LINUX) == LINUX)
#define SupportsMetal() ((SUPPORT_VECTOR & METAL) == METAL)
#define SupportsWindows() ((SUPPORT_VECTOR & WINDOWS) == WINDOWS)
#define SupportsXnu() ((SUPPORT_VECTOR & XNU) == XNU)
#define SupportsFreebsd() ((SUPPORT_VECTOR & FREEBSD) == FREEBSD)
#define SupportsOpenbsd() ((SUPPORT_VECTOR & OPENBSD) == OPENBSD)
#define SupportsNetbsd() ((SUPPORT_VECTOR & NETBSD) == NETBSD)
#define SupportsBsd() (!!(SUPPORT_VECTOR & (XNU | FREEBSD | OPENBSD | NETBSD)))
#define SupportsLinux() ((SUPPORT_VECTOR & _HOSTLINUX) == _HOSTLINUX)
#define SupportsMetal() ((SUPPORT_VECTOR & _HOSTMETAL) == _HOSTMETAL)
#define SupportsWindows() ((SUPPORT_VECTOR & _HOSTWINDOWS) == _HOSTWINDOWS)
#define SupportsXnu() ((SUPPORT_VECTOR & _HOSTXNU) == _HOSTXNU)
#define SupportsFreebsd() ((SUPPORT_VECTOR & _HOSTFREEBSD) == _HOSTFREEBSD)
#define SupportsOpenbsd() ((SUPPORT_VECTOR & _HOSTOPENBSD) == _HOSTOPENBSD)
#define SupportsNetbsd() ((SUPPORT_VECTOR & _HOSTNETBSD) == _HOSTNETBSD)
#define SupportsBsd() (!!(SUPPORT_VECTOR & (_HOSTXNU | _HOSTFREEBSD | _HOSTOPENBSD | _HOSTNETBSD)))
#define SupportsSystemv() \
(!!(SUPPORT_VECTOR & (LINUX | XNU | OPENBSD | FREEBSD | NETBSD)))
(!!(SUPPORT_VECTOR & (_HOSTLINUX | _HOSTXNU | _HOSTOPENBSD | _HOSTFREEBSD | _HOSTNETBSD)))
#ifndef __ASSEMBLER__
#define IsLinux() (SupportsLinux() && (__hostos & LINUX))
#define IsMetal() (SupportsMetal() && (__hostos & METAL))
#define IsWindows() (SupportsWindows() && (__hostos & WINDOWS))
#define IsXnu() (SupportsXnu() && (__hostos & XNU))
#define IsFreebsd() (SupportsFreebsd() && (__hostos & FREEBSD))
#define IsOpenbsd() (SupportsOpenbsd() && (__hostos & OPENBSD))
#define IsNetbsd() (SupportsNetbsd() && (__hostos & NETBSD))
#define IsLinux() (SupportsLinux() && (__hostos & _HOSTLINUX))
#define IsMetal() (SupportsMetal() && (__hostos & _HOSTMETAL))
#define IsWindows() (SupportsWindows() && (__hostos & _HOSTWINDOWS))
#define IsXnu() (SupportsXnu() && (__hostos & _HOSTXNU))
#define IsFreebsd() (SupportsFreebsd() && (__hostos & _HOSTFREEBSD))
#define IsOpenbsd() (SupportsOpenbsd() && (__hostos & _HOSTOPENBSD))
#define IsNetbsd() (SupportsNetbsd() && (__hostos & _HOSTNETBSD))
#define IsBsd() (IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd())
#else
/* clang-format off */
#define IsLinux() $LINUX,__hostos(%rip)
#define IsMetal() $METAL,__hostos(%rip)
#define IsWindows() $WINDOWS,__hostos(%rip)
#define IsBsd() $XNU|FREEBSD|OPENBSD|NETBSD,__hostos(%rip)
#define IsXnu() $XNU,__hostos(%rip)
#define IsFreebsd() $FREEBSD,__hostos(%rip)
#define IsOpenbsd() $OPENBSD,__hostos(%rip)
#define IsNetbsd() $NETBSD,__hostos(%rip)
#define IsLinux() $_HOSTLINUX,__hostos(%rip)
#define IsMetal() $_HOSTMETAL,__hostos(%rip)
#define IsWindows() $_HOSTWINDOWS,__hostos(%rip)
#define IsBsd() $_HOSTXNU|_HOSTFREEBSD|_HOSTOPENBSD|_HOSTNETBSD,__hostos(%rip)
#define IsXnu() $_HOSTXNU,__hostos(%rip)
#define IsFreebsd() $_HOSTFREEBSD,__hostos(%rip)
#define IsOpenbsd() $_HOSTOPENBSD,__hostos(%rip)
#define IsNetbsd() $_HOSTNETBSD,__hostos(%rip)
/* clang-format on */
#endif

View file

@ -32,7 +32,7 @@ sched_yield:
mov __hostos(%rip),%dl
#if SupportsMetal()
testb $METAL,%dl
testb $_HOSTMETAL,%dl
jnz 9f
#endif
@ -46,7 +46,7 @@ sched_yield:
// threads ready to run and no user APCs are queued, the function
// returns immediately, and the thread continues execution.
// Quoth MSDN
testb $WINDOWS,%dl
testb $_HOSTWINDOWS,%dl
jz 1f
xor %ecx,%ecx
xor %edx,%edx

View file

@ -205,22 +205,22 @@ int arch_prctl(int code, int64_t addr) {
rc = efault();
} else {
switch (__hostos) {
case METAL:
case _HOSTMETAL:
rc = arch_prctl_msr(code, addr);
break;
case FREEBSD:
case _HOSTFREEBSD:
rc = arch_prctl_freebsd(code, addr);
break;
case NETBSD:
case _HOSTNETBSD:
rc = arch_prctl_netbsd(code, addr);
break;
case OPENBSD:
case _HOSTOPENBSD:
rc = arch_prctl_openbsd(code, addr);
break;
case LINUX:
case _HOSTLINUX:
rc = sys_arch_prctl(code, addr);
break;
case XNU:
case _HOSTXNU:
rc = arch_prctl_xnu(code, addr);
break;
default:

View file

@ -74,7 +74,7 @@ __msabi noasan EFI_STATUS EfiMain(EFI_HANDLE ImageHandle,
uint64_t p, pe, cr4, *m, *pd, *sp, *pml4t, *pdt1, *pdt2, *pdpt1, *pdpt2;
extern char __os asm("__hostos");
__os = METAL;
__os = _HOSTMETAL;
/*
* Allocates and clears PC-compatible memory and copies image.

View file

@ -266,7 +266,7 @@ __msabi textwindows int64_t WinMain(int64_t hInstance, int64_t hPrevInstance,
const char *lpCmdLine, int64_t nCmdShow) {
const char16_t *cmdline;
extern char os asm("__hostos");
os = WINDOWS; /* madness https://news.ycombinator.com/item?id=21019722 */
os = _HOSTWINDOWS; /* madness https://news.ycombinator.com/item?id=21019722 */
kStartTsc = rdtsc();
__pid = GetCurrentProcessId();
#if !IsTiny()

View file

@ -52,21 +52,21 @@ syscall:
// convert from consts.sh to syscalls.sh encoding
push %rcx
mov __hostos(%rip),%cl
test $LINUX,%cl
test $_HOSTLINUX,%cl
jnz 2f
1: test $FREEBSD,%cl
1: test $_HOSTFREEBSD,%cl
jz 1f
shl $4*7,%rax
jmp 2f
1: test $OPENBSD,%cl
1: test $_HOSTOPENBSD,%cl
jz 1f
shl $4*10,%rax
jmp 2f
1: test $NETBSD,%cl
1: test $_HOSTNETBSD,%cl
jz 1f
shl $4*13,%rax
jmp 2f
1: test $XNU,%cl
1: test $_HOSTXNU,%cl
jz 2f
mov %eax,%ecx
and $0x0f000000,%ecx

View file

@ -219,7 +219,7 @@ systemfive_xnu:
#if SupportsOpenbsd()
cmpq $0,(%r15) # OpenBSD has no auxv
jnz 0f
mov $OPENBSD,%al
mov $_HOSTOPENBSD,%al
jmp _init_systemfive_detected
0:
#endif
@ -227,14 +227,14 @@ systemfive_xnu:
xor %ecx,%ecx
0: cmpq $2014,(%r15,%rcx,8) # NetBSD's AT_EXECFN
jne 1f
mov $NETBSD,%al
mov $_HOSTNETBSD,%al
jmp _init_systemfive_detected
1: cmpq $0,(%r15,%rcx,8)
lea 2(%ecx),%ecx
jnz 0b
2:
#endif
mov $LINUX,%al
mov $_HOSTLINUX,%al
_init_systemfive_detected:
stosq # __hostos
bsr %eax,%eax
@ -356,7 +356,7 @@ _init_systemfive_pid:
ezlea __hostos,cx
mov (%rcx),%al
mov (%rdi),%eax
testb $WINDOWS|METAL,(%rcx)
testb $_HOSTWINDOWS|_HOSTMETAL,(%rcx)
jnz 1f
mov __NR_getpid,%eax
syscall

View file

@ -25,15 +25,15 @@
int GetSynFingerOs(uint32_t x) {
switch (x) {
case 0x7e7a6599:
return XNU;
return _HOSTXNU;
case 0xbb724187:
return LINUX;
return _HOSTLINUX;
case 0xb228b212:
return WINDOWS;
return _HOSTWINDOWS;
case 0x77c30887:
return FREEBSD;
return _HOSTFREEBSD;
case 0xc45d694b:
return OPENBSD;
return _HOSTOPENBSD;
default:
return 0;
}

View file

@ -27,7 +27,7 @@ TEST(FingerSyn, testWindows7_isWindows) {
\x7f\x0a\x0a\x7c\xc3\x9e\x1b\x58\x12\x38\xfe\xd3\x00\x00\x00\x00\
\x80\x02\x20\x00\x35\xee\x00\x00\x02\x04\x05\xb4\x01\x03\x03\x02\
\x01\x01\x04\x02";
EXPECT_EQ(WINDOWS, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTWINDOWS, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testWindows10_isWindows) {
@ -36,7 +36,7 @@ TEST(FingerSyn, testWindows10_isWindows) {
\x7f\x0a\x0a\x7c\xed\xf2\x1b\x58\xeb\xa6\xa7\xb0\x00\x00\x00\x00\
\x80\x02\xfa\xf0\xae\xe0\x00\x00\x02\x04\x05\xb4\x01\x03\x03\x08\
\x01\x01\x04\x02";
EXPECT_EQ(WINDOWS, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTWINDOWS, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testLinuxAlpine_isLinux) {
@ -45,7 +45,7 @@ TEST(FingerSyn, testLinuxAlpine_isLinux) {
\x7f\x0a\x0a\x7c\xee\x32\x1b\x58\xfe\xa9\xa4\xae\x00\x00\x00\x00\
\xa0\x02\xff\xd7\x29\x3a\x00\x00\x02\x04\xff\xd7\x04\x02\x08\x0a\
\x43\x3d\xab\x7c\x00\x00\x00\x00\x01\x03\x03\x07";
EXPECT_EQ(LINUX, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTLINUX, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testLinuxDebian_isLinux) {
@ -54,7 +54,7 @@ TEST(FingerSyn, testLinuxDebian_isLinux) {
\x7f\x0a\x0a\x7c\xe2\x24\x1b\x58\xf6\xe9\xf2\x85\x00\x00\x00\x00\
\xa0\x02\xfa\xf0\x5f\xac\x00\x00\x02\x04\x05\xb4\x04\x02\x08\x0a\
\x4a\x43\x93\x29\x00\x00\x00\x00\x01\x03\x03\x07";
EXPECT_EQ(LINUX, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTLINUX, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testLinuxFastOpen_isLinux) {
@ -64,7 +64,7 @@ TEST(FingerSyn, testLinuxFastOpen_isLinux) {
\xd0\x02\xff\xd7\x29\x97\x00\x00\x02\x04\xff\xd7\x04\x02\x08\x0a\
\x43\x3f\x21\xf8\x00\x00\x00\x00\x01\x03\x03\x07\x22\x0a\xd4\x75\
\x4f\x06\xc0\x97\x25\x6c\x01\x01";
EXPECT_EQ(LINUX, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTLINUX, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testLinuxGceVm_isLinux) {
@ -73,7 +73,7 @@ TEST(FingerSyn, testLinuxGceVm_isLinux) {
\x7f\x00\x00\x7c\xd2\xfe\x1b\x58\xf5\xb2\xf6\xca\x00\x00\x00\x00\
\xa0\x02\xff\x28\x16\xe7\x00\x00\x02\x04\x05\x8c\x04\x02\x08\x0a\
\xb6\x4d\x6b\xd8\x00\x00\x00\x00\x01\x03\x03\x07";
EXPECT_EQ(LINUX, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTLINUX, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testOpenbsd) {
@ -82,7 +82,7 @@ TEST(FingerSyn, testOpenbsd) {
\x7f\x00\x00\x7c\xa2\x91\x1b\x58\x53\x54\xbc\xc5\x00\x00\x00\x00\
\xb0\x02\x40\x00\x70\xf7\x00\x00\x02\x04\x05\xb4\x01\x01\x04\x02\
\x01\x03\x03\x06\x01\x01\x08\x0a\xa2\x70\xeb\x7a\x00\x00\x00\x00";
EXPECT_EQ(OPENBSD, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTOPENBSD, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testXnu) {
@ -91,7 +91,7 @@ TEST(FingerSyn, testXnu) {
\x7f\x00\x00\x7c\xd3\x63\x1b\x58\xe6\xd5\xf8\x7e\x00\x00\x00\x00\
\xb0\x02\xff\xff\x70\x36\x00\x00\x02\x04\x05\xb4\x01\x03\x03\x06\
\x01\x01\x08\x0a\x25\x85\xaa\x28\x00\x00\x00\x00\x04\x02\x00\x00";
EXPECT_EQ(XNU, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTXNU, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testFreebsd12) {
@ -100,7 +100,7 @@ TEST(FingerSyn, testFreebsd12) {
\x7f\x00\x00\x7c\xde\x81\x1b\x58\x23\x39\xfc\x6b\x00\x00\x00\x00\
\xa0\x02\xff\xff\x8c\x8c\x00\x00\x02\x04\x05\xb4\x01\x03\x03\x06\
\x04\x02\x08\x0a\x1f\xa1\x59\x46\x00\x00\x00\x00";
EXPECT_EQ(FREEBSD, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTFREEBSD, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testRedbeanGceVm_isFreebsd) {
@ -109,7 +109,7 @@ TEST(FingerSyn, testRedbeanGceVm_isFreebsd) {
\x7f\x00\x00\x7c\x5a\x6e\x1b\x58\x0a\x15\xba\x1a\x00\x00\x00\x00\
\xa0\x02\xff\xff\xe4\x60\x00\x00\x02\x04\x05\x8c\x01\x03\x03\x06\
\x04\x02\x08\x0a\xc9\x06\xb4\x13\x00\x00\x00\x00";
EXPECT_EQ(FREEBSD, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTFREEBSD, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}
TEST(FingerSyn, testNetbsd_isFreebsdSadly) {
@ -118,5 +118,5 @@ TEST(FingerSyn, testNetbsd_isFreebsdSadly) {
\x7f\x00\x00\x7c\xfc\x18\x1b\x58\x8e\xb8\x1b\xfe\x00\x00\x00\x00\
\xa0\x02\x80\x00\xdc\xb6\x00\x00\x02\x04\x05\xb4\x01\x03\x03\x03\
\x04\x02\x08\x0a\x00\x00\x00\x01\x00\x00\x00\x00";
EXPECT_EQ(FREEBSD, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
EXPECT_EQ(_HOSTFREEBSD, GetSynFingerOs(FingerSyn(s, sizeof(s) - 1)));
}

View file

@ -6624,7 +6624,7 @@ static void MakeExecutableModifiable(void) {
int ft;
size_t n;
extern char ape_rom_vaddr[] __attribute__((__weak__));
if (!(SUPPORT_VECTOR & (METAL | WINDOWS | XNU))) return;
if (!(SUPPORT_VECTOR & (_HOSTMETAL | _HOSTWINDOWS | _HOSTXNU))) return;
if (IsWindows()) return; // TODO
if (IsOpenbsd()) return; // TODO
if (IsNetbsd()) return; // TODO