mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Update tests and CPU detection for Blink
This commit is contained in:
parent
be3e109309
commit
006c44ff5d
24 changed files with 206 additions and 56 deletions
|
@ -239,7 +239,7 @@
|
|||
int pledge(const char *promises, const char *execpromises) {
|
||||
int e, rc;
|
||||
unsigned long ipromises, iexecpromises;
|
||||
if (IsGenuineCosmo() || IsGenuineBlink()) {
|
||||
if (IsGenuineBlink()) {
|
||||
rc = 0; // blink doesn't support seccomp
|
||||
} else if (!ParsePromises(promises, &ipromises) &&
|
||||
!ParsePromises(execpromises, &iexecpromises)) {
|
||||
|
|
|
@ -354,7 +354,7 @@ int sys_unveil_linux(const char *path, const char *permissions) {
|
|||
int unveil(const char *path, const char *permissions) {
|
||||
int e, rc;
|
||||
e = errno;
|
||||
if (IsGenuineCosmo() || IsGenuineBlink()) {
|
||||
if (IsGenuineBlink()) {
|
||||
rc = 0; // blink doesn't support landlock
|
||||
} else if (IsLinux()) {
|
||||
rc = sys_unveil_linux(path, permissions);
|
||||
|
|
34
libc/intrin/getcpuidbrand.c
Normal file
34
libc/intrin/getcpuidbrand.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
void GetCpuidBrand(char s[13], uint32_t leaf) {
|
||||
int ax, cx;
|
||||
asm("push\t%%rbx\r\n"
|
||||
"cpuid\r\n"
|
||||
"mov\t%%ebx,0+%2\r\n"
|
||||
"mov\t%%ecx,4+%2\r\n"
|
||||
"mov\t%%edx,8+%2\r\n"
|
||||
"movb\t$0,12+%2\r\n"
|
||||
"pop\t%%rbx"
|
||||
: "=a"(ax), "=c"(cx), "=o"(*(char(*)[13])s)
|
||||
: "0"(leaf), "1"(0)
|
||||
: "rdx");
|
||||
s[12] = 0;
|
||||
}
|
29
libc/intrin/getcpuidemulator.c
Normal file
29
libc/intrin/getcpuidemulator.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
const char *GetCpuidEmulator(void) {
|
||||
static bool once;
|
||||
static char s[13];
|
||||
if (!once) {
|
||||
GetCpuidBrand(s, 0x40000000);
|
||||
once = true;
|
||||
}
|
||||
return s;
|
||||
}
|
29
libc/intrin/getcpuidos.c
Normal file
29
libc/intrin/getcpuidos.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
const char *GetCpuidOs(void) {
|
||||
static bool once;
|
||||
static char s[13];
|
||||
if (!once) {
|
||||
GetCpuidBrand(s, 0x40031337);
|
||||
once = true;
|
||||
}
|
||||
return s;
|
||||
}
|
24
libc/intrin/iscygwin.c
Normal file
24
libc/intrin/iscygwin.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
bool IsCygwin(void) {
|
||||
return IsGenuineBlink() && !strcmp(GetCpuidOs(), "Cygwin");
|
||||
}
|
|
@ -21,7 +21,6 @@
|
|||
#include "libc/intrin/promises.internal.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/nexgen32e/vendor.internal.h"
|
||||
#include "libc/nt/struct/teb.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
|
@ -42,7 +41,6 @@ int IsDebuggerPresent(bool force) {
|
|||
ssize_t got;
|
||||
int e, fd, res;
|
||||
char *p, buf[1024];
|
||||
if (!force && IsGenuineCosmo()) return 0;
|
||||
if (!force && IsGenuineBlink()) return 0;
|
||||
if (!force && __getenv(environ, "HEISENDEBUG")) return 0;
|
||||
if (IsWindows()) return IsBeingDebugged();
|
||||
|
|
25
libc/intrin/isgenuineblink.c
Normal file
25
libc/intrin/isgenuineblink.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
bool IsGenuineBlink(void) {
|
||||
return X86_HAVE(HYPERVISOR) && !strcmp(GetCpuidEmulator(), "GenuineBlink");
|
||||
}
|
|
@ -57,8 +57,7 @@ relegated int(AttachDebugger)(intptr_t continuetoaddr) {
|
|||
char pidstr[11], breakcmd[40];
|
||||
const char *se, *elf, *gdb, *rewind, *layout;
|
||||
__restore_tty();
|
||||
if (IsGenuineCosmo() || IsGenuineBlink() || !(gdb = GetGdbPath()) ||
|
||||
!isatty(0) || !isatty(1) ||
|
||||
if (IsGenuineBlink() || !(gdb = GetGdbPath()) || !isatty(0) || !isatty(1) ||
|
||||
(ttyfd = open(_PATH_TTY, O_RDWR | O_CLOEXEC)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -13,15 +13,5 @@
|
|||
kCpuids[KCPUIDS_0H][KCPUIDS_EDX] == 0x49656e69 /* ineI */ && \
|
||||
kCpuids[KCPUIDS_0H][KCPUIDS_ECX] == 0x6c65746e /* ntel */)
|
||||
|
||||
#define IsGenuineCosmo() \
|
||||
(kCpuids[KCPUIDS_0H][KCPUIDS_EBX] == 0x756e6547 /* Genu */ && \
|
||||
kCpuids[KCPUIDS_0H][KCPUIDS_EDX] == 0x43656e69 /* ineC */ && \
|
||||
kCpuids[KCPUIDS_0H][KCPUIDS_ECX] == 0x6f6d736f /* osmo */)
|
||||
|
||||
#define IsGenuineBlink() \
|
||||
(kCpuids[KCPUIDS_0H][KCPUIDS_EBX] == 0x756e6547 /* Genu */ && \
|
||||
kCpuids[KCPUIDS_0H][KCPUIDS_EDX] == 0x42656e69 /* ineB */ && \
|
||||
kCpuids[KCPUIDS_0H][KCPUIDS_ECX] == 0x6b6e696c /* link */)
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_VENDOR_H_ */
|
||||
|
|
|
@ -37,11 +37,14 @@ unsigned long getauxval(unsigned long);
|
|||
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
|
||||
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
|
||||
void *_mapstack(void) returnsaligned((FRAMESIZE)) mallocesque;
|
||||
int setjmp(jmp_buf) libcesque returnstwice paramsnonnull();
|
||||
int setjmp(jmp_buf)
|
||||
libcesque returnstwice paramsnonnull();
|
||||
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||
axdx_t setlongerjmp(jmp_buf) libcesque returnstwice paramsnonnull();
|
||||
axdx_t setlongerjmp(jmp_buf)
|
||||
libcesque returnstwice paramsnonnull();
|
||||
void longerjmp(jmp_buf, intptr_t) libcesque wontreturn paramsnonnull();
|
||||
int _setjmp(jmp_buf) libcesque returnstwice paramsnonnull();
|
||||
int _setjmp(jmp_buf)
|
||||
libcesque returnstwice paramsnonnull();
|
||||
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
|
||||
void siglongjmp(sigjmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||
void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
|
||||
|
@ -107,6 +110,11 @@ void __warn_if_powersave(void);
|
|||
const char *__describe_os(void);
|
||||
bool IsDynamicExecutable(const char *);
|
||||
void _restorewintty(void);
|
||||
const char *GetCpuidOs(void);
|
||||
const char *GetCpuidEmulator(void);
|
||||
void GetCpuidBrand(char[13], uint32_t);
|
||||
bool IsGenuineBlink(void);
|
||||
bool IsCygwin(void);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -133,11 +133,6 @@ static void FixIrregularFds(void) {
|
|||
pfds[i].fd = i + 3;
|
||||
pfds[i].events = POLLIN;
|
||||
}
|
||||
if (IsGenuineCosmo()) {
|
||||
// TODO(jart): Fix Blinkenlights poll() / close()
|
||||
free(pfds);
|
||||
return;
|
||||
}
|
||||
if (poll(pfds, maxfds, 0) != -1) {
|
||||
for (i = 0; i < maxfds; ++i) {
|
||||
if (pfds[i].revents & POLLNVAL) continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue