From 006c44ff5d40ce279c8293a5a490617f3d5b65cd Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Wed, 18 Jan 2023 00:56:09 -0800 Subject: [PATCH] Update tests and CPU detection for Blink --- libc/calls/pledge.c | 2 +- libc/calls/unveil.c | 2 +- libc/intrin/getcpuidbrand.c | 34 ++++++++++++++++++++++++++ libc/intrin/getcpuidemulator.c | 29 ++++++++++++++++++++++ libc/intrin/getcpuidos.c | 29 ++++++++++++++++++++++ libc/intrin/iscygwin.c | 24 ++++++++++++++++++ libc/intrin/isdebuggerpresent.c | 2 -- libc/intrin/isgenuineblink.c | 25 +++++++++++++++++++ libc/log/attachdebugger.c | 3 +-- libc/nexgen32e/vendor.internal.h | 10 -------- libc/runtime/runtime.h | 14 ++++++++--- libc/testlib/testmain.c | 5 ---- test/libc/calls/ftruncate_test.c | 23 ++++++++++------- test/libc/calls/pipe_test.c | 2 ++ test/libc/calls/sigaction_test.c | 6 +++-- test/libc/calls/writev_test.c | 21 ++++++++-------- test/libc/sock/unix_test.c | 8 +++++- test/libc/stdio/dtoa_test.c | 2 +- test/tool/net/sqlite_test.c | 6 ++--- tool/build/lib/syscall.c | 2 +- tool/build/lib/throw.c | 3 +-- tool/emacs/cosmo-c-keywords.el | 2 ++ tool/emacs/cosmo-platform-constants.el | 4 ++- tool/net/redbean.c | 4 +-- 24 files changed, 206 insertions(+), 56 deletions(-) create mode 100644 libc/intrin/getcpuidbrand.c create mode 100644 libc/intrin/getcpuidemulator.c create mode 100644 libc/intrin/getcpuidos.c create mode 100644 libc/intrin/iscygwin.c create mode 100644 libc/intrin/isgenuineblink.c diff --git a/libc/calls/pledge.c b/libc/calls/pledge.c index ace419995..21b7ce4f7 100644 --- a/libc/calls/pledge.c +++ b/libc/calls/pledge.c @@ -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)) { diff --git a/libc/calls/unveil.c b/libc/calls/unveil.c index 346e5ea78..1f2f150b1 100644 --- a/libc/calls/unveil.c +++ b/libc/calls/unveil.c @@ -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); diff --git a/libc/intrin/getcpuidbrand.c b/libc/intrin/getcpuidbrand.c new file mode 100644 index 000000000..095589d06 --- /dev/null +++ b/libc/intrin/getcpuidbrand.c @@ -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; +} diff --git a/libc/intrin/getcpuidemulator.c b/libc/intrin/getcpuidemulator.c new file mode 100644 index 000000000..6394c6ecc --- /dev/null +++ b/libc/intrin/getcpuidemulator.c @@ -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; +} diff --git a/libc/intrin/getcpuidos.c b/libc/intrin/getcpuidos.c new file mode 100644 index 000000000..ec520a6d2 --- /dev/null +++ b/libc/intrin/getcpuidos.c @@ -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; +} diff --git a/libc/intrin/iscygwin.c b/libc/intrin/iscygwin.c new file mode 100644 index 000000000..3c84b96fe --- /dev/null +++ b/libc/intrin/iscygwin.c @@ -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"); +} diff --git a/libc/intrin/isdebuggerpresent.c b/libc/intrin/isdebuggerpresent.c index 22285cbfc..58885bd60 100644 --- a/libc/intrin/isdebuggerpresent.c +++ b/libc/intrin/isdebuggerpresent.c @@ -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(); diff --git a/libc/intrin/isgenuineblink.c b/libc/intrin/isgenuineblink.c new file mode 100644 index 000000000..ef519f5b3 --- /dev/null +++ b/libc/intrin/isgenuineblink.c @@ -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"); +} diff --git a/libc/log/attachdebugger.c b/libc/log/attachdebugger.c index dd7fecc66..53507c355 100644 --- a/libc/log/attachdebugger.c +++ b/libc/log/attachdebugger.c @@ -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; } diff --git a/libc/nexgen32e/vendor.internal.h b/libc/nexgen32e/vendor.internal.h index 8e3a7b9ba..949e0e865 100644 --- a/libc/nexgen32e/vendor.internal.h +++ b/libc/nexgen32e/vendor.internal.h @@ -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_ */ diff --git a/libc/runtime/runtime.h b/libc/runtime/runtime.h index 0605b1ced..d8aa565e6 100644 --- a/libc/runtime/runtime.h +++ b/libc/runtime/runtime.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) */ diff --git a/libc/testlib/testmain.c b/libc/testlib/testmain.c index 3a0534329..e6dbc0582 100644 --- a/libc/testlib/testmain.c +++ b/libc/testlib/testmain.c @@ -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; diff --git a/test/libc/calls/ftruncate_test.c b/test/libc/calls/ftruncate_test.c index 3b8302a97..a859065c6 100644 --- a/test/libc/calls/ftruncate_test.c +++ b/test/libc/calls/ftruncate_test.c @@ -24,6 +24,7 @@ #include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" #include "libc/mem/gc.internal.h" +#include "libc/nexgen32e/vendor.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -86,16 +87,20 @@ TEST(ftruncate, test) { ASSERT_SYS(0, 5, lseek(3, 0, SEEK_CUR)); // doesn't change position ASSERT_SYS(0, 5, write(3, "world", 5)); ASSERT_SYS(0, 0, fstat(3, &st)); - ASSERT_EQ(8192, st.st_size); // 8192 is logical size - if (IsWindows() || IsNetbsd() || IsOpenbsd()) { // - ASSERT_EQ(8192 / 512, st.st_blocks); // 8192 is physical size - } else if (IsFreebsd()) { // - ASSERT_EQ(512 / 512, st.st_blocks); // 512 is physical size - } else if (IsLinux() || IsXnu()) { // - ASSERT_EQ(4096 / 512, st.st_blocks); // 4096 is physical size - } else { - notpossible; + ASSERT_EQ(8192, st.st_size); +#if 0 + if (!IsGenuineBlink()) { + if (IsWindows() || IsNetbsd() || IsOpenbsd()) { // + ASSERT_EQ(8192 / 512, st.st_blocks); // 8192 is physical size + } else if (IsFreebsd()) { // + ASSERT_EQ(512 / 512, st.st_blocks); // 512 is physical size + } else if (IsLinux() || IsXnu()) { // + ASSERT_EQ(4096 / 512, st.st_blocks); // 4096 is physical size + } else { + notpossible; + } } +#endif ASSERT_SYS(0, 512, pread(3, got, 512, 0)); ASSERT_EQ(0, memcmp(want, got, 512)); ASSERT_SYS(0, 0, ftruncate(3, 0)); // shrink file to be empty diff --git a/test/libc/calls/pipe_test.c b/test/libc/calls/pipe_test.c index 379735055..0a4e4d9ac 100644 --- a/test/libc/calls/pipe_test.c +++ b/test/libc/calls/pipe_test.c @@ -20,6 +20,7 @@ #include "libc/calls/struct/rlimit.h" #include "libc/dce.h" #include "libc/errno.h" +#include "libc/nexgen32e/vendor.internal.h" #include "libc/runtime/runtime.h" #include "libc/sysv/consts/rlimit.h" #include "libc/testlib/testlib.h" @@ -48,6 +49,7 @@ TEST(pipe, ebadf) { TEST(pipe, emfile) { if (IsWindows()) return; // TODO + if (IsCygwin()) return; ASSERT_NE(-1, (pid = fork())); if (!pid) { ASSERT_EQ(0, setrlimit(RLIMIT_NOFILE, &rlim)); diff --git a/test/libc/calls/sigaction_test.c b/test/libc/calls/sigaction_test.c index a1c73a424..549e3a8b0 100644 --- a/test/libc/calls/sigaction_test.c +++ b/test/libc/calls/sigaction_test.c @@ -27,6 +27,7 @@ #include "libc/dce.h" #include "libc/errno.h" #include "libc/nexgen32e/nexgen32e.h" +#include "libc/nexgen32e/vendor.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" @@ -184,6 +185,7 @@ TEST(sigaction, ignoringSignalDiscardsSignal) { TEST(sigaction, autoZombieSlayer) { if (IsWindows()) return; + if (IsCygwin()) return; int pid; struct sigaction sa; // make sure we're starting in expected state @@ -194,8 +196,8 @@ TEST(sigaction, autoZombieSlayer) { if (!pid) _Exit(0); ASSERT_SYS(0, pid, wait(0)); // enable automatic zombie slayer - sa.sa_handler = SIG_DFL; // POSIX.1 says no SIG_IGN - sa.sa_flags = SA_NOCLDWAIT; // seems to be optional + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; sigemptyset(&sa.sa_mask); ASSERT_SYS(0, 0, sigaction(SIGCHLD, &sa, &sa)); // verify it works diff --git a/test/libc/calls/writev_test.c b/test/libc/calls/writev_test.c index 8b716dad1..4da0033e7 100644 --- a/test/libc/calls/writev_test.c +++ b/test/libc/calls/writev_test.c @@ -82,18 +82,18 @@ TEST(writev, test) { TEST(writev, big_fullCompletion) { int fd; - char *ba = gc(malloc(2 * 1024 * 1024)); - char *bb = gc(malloc(2 * 1024 * 1024)); - char *bc = gc(malloc(2 * 1024 * 1024)); + char *ba = gc(malloc(1024 * 1024)); + char *bb = gc(malloc(1024 * 1024)); + char *bc = gc(malloc(1024 * 1024)); struct iovec iov[] = { - {"", 0}, // - {ba, 2 * 1024 * 1024}, // - {NULL, 0}, // - {bb, 2 * 1024 * 1024}, // - {bc, 2 * 1024 * 1024}, // + {"", 0}, // + {ba, 1024 * 1024}, // + {NULL, 0}, // + {bb, 1024 * 1024}, // + {bc, 1024 * 1024}, // }; ASSERT_NE(-1, (fd = open("file", O_RDWR | O_CREAT | O_TRUNC, 0644))); - EXPECT_EQ(6 * 1024 * 1024, writev(fd, iov, ARRAYLEN(iov))); + EXPECT_EQ(3 * 1024 * 1024, writev(fd, iov, ARRAYLEN(iov))); EXPECT_NE(-1, close(fd)); } @@ -125,7 +125,8 @@ TEST(writev, empty_stillPerformsIoOperation) { struct iovec iov[] = {{"", 0}, {NULL, 0}}; ASSERT_NE(-1, touch("file", 0644)); ASSERT_NE(-1, (fd = open("file", O_RDONLY))); - EXPECT_EQ(-1, writev(fd, iov, ARRAYLEN(iov))); + errno = 0; + EXPECT_SYS(EBADF, -1, writev(fd, iov, ARRAYLEN(iov))); EXPECT_EQ(-1, writev(fd, NULL, 0)); EXPECT_NE(-1, close(fd)); } diff --git a/test/libc/sock/unix_test.c b/test/libc/sock/unix_test.c index bfe9321e8..96ad7348c 100644 --- a/test/libc/sock/unix_test.c +++ b/test/libc/sock/unix_test.c @@ -21,6 +21,7 @@ #include "libc/calls/struct/timeval.h" #include "libc/dce.h" #include "libc/errno.h" +#include "libc/nexgen32e/vendor.internal.h" #include "libc/nt/version.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" @@ -124,6 +125,7 @@ TEST(unix, stream) { TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine if (IsWindows()) return; + if (IsCygwin()) return; int ws, rc; char buf[8] = {0}; uint32_t len = sizeof(struct sockaddr_un); @@ -135,7 +137,10 @@ TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine ASSERT_SYS(0, 5, write(4, "hello", 5)); ASSERT_SYS(0, 5, read(3, buf, 8)); ASSERT_SYS(0, 0, close(3)); - ASSERT_SYS(IsBsd() ? ECONNRESET : ECONNREFUSED, -1, write(4, "hello", 5)); + ASSERT_EQ(-1, write(4, "hello", 5)); + ASSERT_TRUE(errno == ECONNREFUSED || // Linux + errno == ECONNRESET); // BSDs + errno = 0; ASSERT_SYS(0, 0, unlink(addr.sun_path)); ASSERT_SYS(0, 3, socket(AF_UNIX, SOCK_DGRAM, 0)); ASSERT_SYS(0, 0, bind(3, (void *)&addr, len)); @@ -156,6 +161,7 @@ TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine TEST(unix, serverGoesDown_usingSendTo_unlink) { // much easier if (IsWindows()) return; + if (IsCygwin()) return; int ws, rc; char buf[8] = {0}; uint32_t len = sizeof(struct sockaddr_un); diff --git a/test/libc/stdio/dtoa_test.c b/test/libc/stdio/dtoa_test.c index 677cbcec1..3f7eca933 100644 --- a/test/libc/stdio/dtoa_test.c +++ b/test/libc/stdio/dtoa_test.c @@ -137,7 +137,7 @@ static const struct { }; TEST(printf, longdouble) { - if (IsGenuineCosmo() || IsGenuineBlink()) { + if (IsGenuineBlink()) { return; // TODO(jart): long double precision in blink } int i; diff --git a/test/tool/net/sqlite_test.c b/test/tool/net/sqlite_test.c index 3a827532c..b579f30eb 100644 --- a/test/tool/net/sqlite_test.c +++ b/test/tool/net/sqlite_test.c @@ -42,7 +42,7 @@ int DbOpen(const char *path, sqlite3 **db) { int i, rc; rc = sqlite3_open(path, db); if (rc != SQLITE_OK) return rc; - for (i = 0; i < 12; ++i) { + for (i = 0; i < 16; ++i) { rc = sqlite3_exec(*db, "PRAGMA journal_mode=WAL", 0, 0, 0); if (rc == SQLITE_OK) break; if (rc != SQLITE_BUSY) return rc; @@ -53,7 +53,7 @@ int DbOpen(const char *path, sqlite3 **db) { int DbStep(sqlite3_stmt *stmt) { int i, rc; - for (i = 0; i < 12; ++i) { + for (i = 0; i < 16; ++i) { rc = sqlite3_step(stmt); if (rc == SQLITE_ROW) break; if (rc == SQLITE_DONE) break; @@ -65,7 +65,7 @@ int DbStep(sqlite3_stmt *stmt) { int DbExec(sqlite3 *db, const char *sql) { int i, rc; - for (i = 0; i < 12; ++i) { + for (i = 0; i < 16; ++i) { rc = sqlite3_exec(db, sql, 0, 0, 0); if (rc == SQLITE_OK) break; if (rc != SQLITE_BUSY) return rc; diff --git a/tool/build/lib/syscall.c b/tool/build/lib/syscall.c index 2fd75102a..60c58cc71 100644 --- a/tool/build/lib/syscall.c +++ b/tool/build/lib/syscall.c @@ -150,7 +150,7 @@ static int GetAfd(struct Machine *m, int fd) { } static const char *GetSimulated(void) { - if (IsGenuineCosmo() || IsGenuineBlink()) { + if (IsGenuineBlink()) { return " SIMULATED"; } else { return ""; diff --git a/tool/build/lib/throw.c b/tool/build/lib/throw.c index 9922e2e6a..4259f8956 100644 --- a/tool/build/lib/throw.c +++ b/tool/build/lib/throw.c @@ -47,8 +47,7 @@ void ThrowSegmentationFault(struct Machine *m, int64_t va) { WARNF("%s%s ADDR %012lx IP %012lx AX %lx CX %lx DX %lx BX %lx SP %lx " "BP %lx SI %lx DI %lx R8 %lx R9 %lx R10 %lx R11 %lx R12 %lx R13 %lx " "R14 %lx R15 %lx", - "SEGMENTATION FAULT", - IsGenuineCosmo() || IsGenuineBlink() ? " SIMULATED" : "", va, m->ip, + "SEGMENTATION FAULT", IsGenuineBlink() ? " SIMULATED" : "", va, m->ip, Read64(m->ax), Read64(m->cx), Read64(m->dx), Read64(m->bx), Read64(m->sp), Read64(m->bp), Read64(m->si), Read64(m->di), Read64(m->r8), Read64(m->r9), Read64(m->r10), Read64(m->r11), diff --git a/tool/emacs/cosmo-c-keywords.el b/tool/emacs/cosmo-c-keywords.el index b771ef4b0..90c1c608b 100644 --- a/tool/emacs/cosmo-c-keywords.el +++ b/tool/emacs/cosmo-c-keywords.el @@ -205,6 +205,8 @@ "__weak__" "__vector_size__" "__ms_abi__" + "__sysv_abi__" + "systemfive" "__mode__" "__seg_fs" "__seg_gs")) diff --git a/tool/emacs/cosmo-platform-constants.el b/tool/emacs/cosmo-platform-constants.el index 04b3fef01..6ba7d8014 100644 --- a/tool/emacs/cosmo-platform-constants.el +++ b/tool/emacs/cosmo-platform-constants.el @@ -41,7 +41,9 @@ "__code_model_medium__")) (cpp92 - '("__BYTE_ORDER__" + '("__SEG_FS" + "__SEG_GS" + "__BYTE_ORDER__" "__ORDER_LITTLE_ENDIAN__" "__ORDER_BIG_ENDIAN__" "__ORDER_PDP_ENDIAN__" diff --git a/tool/net/redbean.c b/tool/net/redbean.c index 8d68a72ab..d176759f0 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -637,7 +637,7 @@ static void DropOutput(void) { } static bool ShouldAvoidGzip(void) { - return IsGenuineCosmo() || (IsGenuineBlink() && !X86_HAVE(JIT)); + return (IsGenuineBlink() && !X86_HAVE(JIT)); } static char *MergePaths(const char *p, size_t n, const char *q, size_t m, @@ -7266,7 +7266,7 @@ static void GetOpts(int argc, char *argv[]) { int opt; bool storeasset = false; // only generate ecp cert under blinkenlights (rsa is slow) - norsagen = IsGenuineCosmo() || IsGenuineBlink(); + norsagen = IsGenuineBlink(); while ((opt = getopt(argc, argv, GETOPTS)) != -1) { switch (opt) { CASE('S', ++sandboxed);