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

@ -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