Replace COSMO define with _COSMO_SOURCE

This change might cause ABI breakages for /opt/cosmos. It's needed to
help us better conform to header declaration practices.
This commit is contained in:
Justine Tunney 2023-08-13 20:31:27 -07:00
parent a033b65a33
commit c776a32f75
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
238 changed files with 858 additions and 1069 deletions

View file

@ -104,7 +104,7 @@ TEST(diagnose_syscall, getpid) {
// netbsd puts parent pid in edx
// xnu seems to just clobber it!
ASSERT_STREQ("rax rdx rcx r11", _gc(DiffContexts(&x, &y)));
} else if (IsWsl1()) {
} else if (__iswsl1()) {
// XXX: WSL1 must be emulating SYSCALL instructions.
ASSERT_STREQ("rax rcx", _gc(DiffContexts(&x, &y)));
} else {
@ -117,7 +117,7 @@ TEST(diagnose_syscall, testWriteSuccess) {
diagnose_syscall(__NR_write, 2, Z, 0, Z, Z, Z, Z, &x, &y);
if (IsFreebsd()) {
ASSERT_STREQ("rax rcx r8 r9 r10 r11", _gc(DiffContexts(&x, &y)));
} else if (IsWsl1()) {
} else if (__iswsl1()) {
// XXX: WSL1 must be emulating SYSCALL instructions.
ASSERT_STREQ("rax rcx", _gc(DiffContexts(&x, &y)));
} else {
@ -132,7 +132,7 @@ TEST(diagnose_syscall, testWriteFailed) {
ASSERT_STREQ("rax rcx r8 r9 r10 r11 cf", _gc(DiffContexts(&x, &y)));
} else if (IsBsd()) {
ASSERT_STREQ("rax rcx r11 cf", _gc(DiffContexts(&x, &y)));
} else if (IsWsl1()) {
} else if (__iswsl1()) {
// XXX: WSL1 must be emulating SYSCALL instructions.
ASSERT_STREQ("rax rcx", _gc(DiffContexts(&x, &y)));
} else {

View file

@ -37,6 +37,7 @@
#include "libc/sock/sock.h"
#include "libc/sock/struct/sockaddr.h"
#include "libc/sock/struct/sockaddr6.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/af.h"
@ -605,7 +606,7 @@ TEST(pledge_openbsd, bigSyscalls) {
int LockWorker(void *arg, int tid) {
flockfile(stdout);
ASSERT_EQ(gettid(), ((pthread_mutex_t *)stdout->lock)->_owner);
ASSERT_EQ(gettid(), stdout->lock._owner);
funlockfile(stdout);
return 0;
}

View file

@ -112,7 +112,7 @@ TEST(readlinkat, realpathReturnsLongPath) {
struct stat st;
char buf[PATH_MAX];
if (!IsWindows()) return;
if (!_startswith(getcwd(buf, PATH_MAX), "/c/")) return;
if (!startswith(getcwd(buf, PATH_MAX), "/c/")) return;
ASSERT_SYS(0, 0, touch("froot", 0644));
ASSERT_STARTSWITH("/c/", realpath("froot", buf));
}

View file

@ -210,7 +210,7 @@ TEST(sigaction, autoZombieSlayer) {
ASSERT_NE(-1, (pid = fork()));
if (!pid) _Exit(0);
// XXX: WSL does the wrong thing here.
if (IsWsl1()) usleep(10);
if (__iswsl1()) usleep(10);
ASSERT_SYS(ECHILD, -1, wait(0));
// clean up
ASSERT_SYS(0, 0, sigaction(SIGCHLD, &sa, 0));

View file

@ -326,7 +326,7 @@ TEST(ShowCrashReports, testDivideByZero) {
__die();
}
// XXX: WSL doesn't save and restore x87 registers to ucontext_t
if (!IsWsl1()) {
if (!__iswsl1()) {
if (!strstr(output, "3.141")) {
fprintf(stderr, "ERROR: crash report didn't have fpu register\n%s\n",
_gc(IndentLines(output, -1, 0, 4)));

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/strace.internal.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/mem/mem.h"
@ -34,6 +35,39 @@ void SetUpOnce(void) {
ASSERT_SYS(0, 0, pledge("stdio rpath", 0));
}
bool AreMemoryIntervalsOk(const struct MemoryIntervals *mm) {
/* asan runtime depends on this function */
int i;
size_t wantsize;
for (i = 0; i < mm->i; ++i) {
if (mm->p[i].y < mm->p[i].x) {
STRACE("AreMemoryIntervalsOk() y should be >= x!");
return false;
}
wantsize = (size_t)(mm->p[i].y - mm->p[i].x) * FRAMESIZE;
if (!(wantsize < mm->p[i].size && mm->p[i].size <= wantsize + FRAMESIZE)) {
STRACE("AreMemoryIntervalsOk(%p) size is wrong!"
" %'zu not within %'zu .. %'zu",
(uintptr_t)mm->p[i].x << 16, mm->p[i].size, wantsize,
wantsize + FRAMESIZE);
return false;
}
if (i) {
if (mm->p[i].h != -1 || mm->p[i - 1].h != -1) {
if (mm->p[i].x <= mm->p[i - 1].y) {
return false;
}
} else {
if (!(mm->p[i - 1].y + 1 <= mm->p[i].x)) {
STRACE("AreMemoryIntervalsOk() out of order or overlap!");
return false;
}
}
}
}
return true;
}
static bool AreMemoryIntervalsEqual(const struct MemoryIntervals *mm1,
const struct MemoryIntervals *mm2) {
if (mm1->i != mm2->i) return false;
@ -75,8 +109,8 @@ static void RunTrackMemoryIntervalTest(const struct MemoryIntervals t[2], int x,
struct MemoryIntervals *mm;
mm = memcpy(memalign(64, sizeof(*t)), t, sizeof(*t));
CheckMemoryIntervalsAreOk(mm);
CHECK_NE(-1, TrackMemoryInterval(mm, x, y, h, 0, 0, 0, 0, 0,
(y - x) * FRAMESIZE + FRAMESIZE));
CHECK_NE(-1, __track_memory(mm, x, y, h, 0, 0, 0, 0, 0,
(y - x) * FRAMESIZE + FRAMESIZE));
CheckMemoryIntervalsAreOk(mm);
CheckMemoryIntervalsEqual(mm, t + 1);
free(mm);
@ -88,7 +122,7 @@ static int RunReleaseMemoryIntervalsTest(const struct MemoryIntervals t[2],
struct MemoryIntervals *mm;
mm = memcpy(memalign(64, sizeof(*t)), t, sizeof(*t));
CheckMemoryIntervalsAreOk(mm);
if ((rc = ReleaseMemoryIntervals(mm, x, y, NULL)) != -1) {
if ((rc = __untrack_memory(mm, x, y, NULL)) != -1) {
CheckMemoryIntervalsAreOk(mm);
CheckMemoryIntervalsEqual(t + 1, mm);
}
@ -96,7 +130,7 @@ static int RunReleaseMemoryIntervalsTest(const struct MemoryIntervals t[2],
return rc;
}
TEST(TrackMemoryInterval, TestEmpty) {
TEST(__track_memory, TestEmpty) {
static struct MemoryIntervals mm[2] = {
{0, OPEN_MAX, 0, {}},
{1, OPEN_MAX, 0, {{2, 2, 0, FRAMESIZE}}},
@ -106,24 +140,24 @@ TEST(TrackMemoryInterval, TestEmpty) {
RunTrackMemoryIntervalTest(mm, 2, 2, 0);
}
TEST(TrackMemoryInterval, TestFull) {
TEST(__track_memory, TestFull) {
#if 0 // TODO(jart): Find way to re-enable
int i;
struct MemoryIntervals *mm;
mm = calloc(1, sizeof(struct MemoryIntervals));
for (i = 0; i < mm->n; ++i) {
CheckMemoryIntervalsAreOk(mm);
CHECK_NE(-1, TrackMemoryInterval(mm, i, i, i, 0, 0, 0, 0, 0, 0));
CHECK_NE(-1, __track_memory(mm, i, i, i, 0, 0, 0, 0, 0, 0));
CheckMemoryIntervalsAreOk(mm);
}
CHECK_EQ(-1, TrackMemoryInterval(mm, i, i, i, 0, 0, 0, 0, 0, 0));
CHECK_EQ(-1, __track_memory(mm, i, i, i, 0, 0, 0, 0, 0, 0));
CHECK_EQ(ENOMEM, errno);
CheckMemoryIntervalsAreOk(mm);
free(mm);
#endif
}
TEST(TrackMemoryInterval, TestAppend) {
TEST(__track_memory, TestAppend) {
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(2, 2)}},
{1, OPEN_MAX, 0, {I(2, 3)}},
@ -133,7 +167,7 @@ TEST(TrackMemoryInterval, TestAppend) {
RunTrackMemoryIntervalTest(mm, 3, 3, 0);
}
TEST(TrackMemoryInterval, TestPrepend) {
TEST(__track_memory, TestPrepend) {
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(2, 2)}},
{1, OPEN_MAX, 0, {I(1, 2)}},
@ -143,7 +177,7 @@ TEST(TrackMemoryInterval, TestPrepend) {
RunTrackMemoryIntervalTest(mm, 1, 1, 0);
}
TEST(TrackMemoryInterval, TestFillHole) {
TEST(__track_memory, TestFillHole) {
static struct MemoryIntervals mm[2] = {
{4, OPEN_MAX, 0, {I(1, 1), I(3, 4), {5, 5, 1, FRAMESIZE}, I(6, 8)}},
{3, OPEN_MAX, 0, {I(1, 4), {5, 5, 1, FRAMESIZE}, I(6, 8)}},
@ -153,7 +187,7 @@ TEST(TrackMemoryInterval, TestFillHole) {
RunTrackMemoryIntervalTest(mm, 2, 2, 0);
}
TEST(TrackMemoryInterval, TestAppend2) {
TEST(__track_memory, TestAppend2) {
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(2, 2)}},
{2, OPEN_MAX, 0, {I(2, 2), {3, 3, 1, FRAMESIZE}}},
@ -163,7 +197,7 @@ TEST(TrackMemoryInterval, TestAppend2) {
RunTrackMemoryIntervalTest(mm, 3, 3, 1);
}
TEST(TrackMemoryInterval, TestPrepend2) {
TEST(__track_memory, TestPrepend2) {
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(2, 2)}},
{2, OPEN_MAX, 0, {{1, 1, 1, FRAMESIZE}, I(2, 2)}},
@ -173,7 +207,7 @@ TEST(TrackMemoryInterval, TestPrepend2) {
RunTrackMemoryIntervalTest(mm, 1, 1, 1);
}
TEST(TrackMemoryInterval, TestFillHole2) {
TEST(__track_memory, TestFillHole2) {
static struct MemoryIntervals mm[2] = {
{4,
OPEN_MAX,
@ -200,7 +234,7 @@ TEST(TrackMemoryInterval, TestFillHole2) {
RunTrackMemoryIntervalTest(mm, 2, 2, 1);
}
TEST(FindMemoryInterval, Test) {
TEST(__find_memory, Test) {
static struct MemoryIntervals mm[1] = {
{
4,
@ -215,19 +249,19 @@ TEST(FindMemoryInterval, Test) {
},
};
mm[0].p = mm[0].s;
EXPECT_EQ(0, FindMemoryInterval(mm, 0));
EXPECT_EQ(0, FindMemoryInterval(mm, 1));
EXPECT_EQ(1, FindMemoryInterval(mm, 2));
EXPECT_EQ(1, FindMemoryInterval(mm, 3));
EXPECT_EQ(1, FindMemoryInterval(mm, 4));
EXPECT_EQ(2, FindMemoryInterval(mm, 5));
EXPECT_EQ(3, FindMemoryInterval(mm, 6));
EXPECT_EQ(3, FindMemoryInterval(mm, 7));
EXPECT_EQ(3, FindMemoryInterval(mm, 8));
EXPECT_EQ(4, FindMemoryInterval(mm, 9));
EXPECT_EQ(0, __find_memory(mm, 0));
EXPECT_EQ(0, __find_memory(mm, 1));
EXPECT_EQ(1, __find_memory(mm, 2));
EXPECT_EQ(1, __find_memory(mm, 3));
EXPECT_EQ(1, __find_memory(mm, 4));
EXPECT_EQ(2, __find_memory(mm, 5));
EXPECT_EQ(3, __find_memory(mm, 6));
EXPECT_EQ(3, __find_memory(mm, 7));
EXPECT_EQ(3, __find_memory(mm, 8));
EXPECT_EQ(4, __find_memory(mm, 9));
}
TEST(ReleaseMemoryIntervals, TestEmpty) {
TEST(__untrack_memory, TestEmpty) {
static struct MemoryIntervals mm[2] = {
{0, OPEN_MAX, 0, {}},
{0, OPEN_MAX, 0, {}},
@ -237,7 +271,7 @@ TEST(ReleaseMemoryIntervals, TestEmpty) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, 2, 2));
}
TEST(ReleaseMemoryIntervals, TestRemoveElement_UsesInclusiveRange) {
TEST(__untrack_memory, TestRemoveElement_UsesInclusiveRange) {
static struct MemoryIntervals mm[2] = {
{3, OPEN_MAX, 0, {I(0, 0), I(2, 2), I(4, 4)}},
{2, OPEN_MAX, 0, {I(0, 0), I(4, 4)}},
@ -247,7 +281,7 @@ TEST(ReleaseMemoryIntervals, TestRemoveElement_UsesInclusiveRange) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, 2, 2));
}
TEST(ReleaseMemoryIntervals, TestPunchHole) {
TEST(__untrack_memory, TestPunchHole) {
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(0, 9)}},
{2, OPEN_MAX, 0, {I(0, 3), I(6, 9)}},
@ -257,7 +291,7 @@ TEST(ReleaseMemoryIntervals, TestPunchHole) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, 4, 5));
}
TEST(ReleaseMemoryIntervals, TestShortenLeft) {
TEST(__untrack_memory, TestShortenLeft) {
if (IsWindows()) return;
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(0, 9)}},
@ -268,7 +302,7 @@ TEST(ReleaseMemoryIntervals, TestShortenLeft) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, 8, 9));
}
TEST(ReleaseMemoryIntervals, TestShortenRight) {
TEST(__untrack_memory, TestShortenRight) {
if (IsWindows()) return;
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(0, 9)}},
@ -279,7 +313,7 @@ TEST(ReleaseMemoryIntervals, TestShortenRight) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, 0, 2));
}
TEST(ReleaseMemoryIntervals, TestShortenLeft2) {
TEST(__untrack_memory, TestShortenLeft2) {
if (IsWindows()) return;
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(0, 9)}},
@ -290,7 +324,7 @@ TEST(ReleaseMemoryIntervals, TestShortenLeft2) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, 8, 11));
}
TEST(ReleaseMemoryIntervals, TestShortenRight2) {
TEST(__untrack_memory, TestShortenRight2) {
if (IsWindows()) return;
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(0, 9)}},
@ -301,7 +335,7 @@ TEST(ReleaseMemoryIntervals, TestShortenRight2) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, -3, 2));
}
TEST(ReleaseMemoryIntervals, TestZeroZero) {
TEST(__untrack_memory, TestZeroZero) {
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(3, 9)}},
{1, OPEN_MAX, 0, {I(3, 9)}},
@ -311,7 +345,7 @@ TEST(ReleaseMemoryIntervals, TestZeroZero) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, 0, 0));
}
TEST(ReleaseMemoryIntervals, TestNoopLeft) {
TEST(__untrack_memory, TestNoopLeft) {
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(3, 9)}},
{1, OPEN_MAX, 0, {I(3, 9)}},
@ -321,7 +355,7 @@ TEST(ReleaseMemoryIntervals, TestNoopLeft) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, 1, 2));
}
TEST(ReleaseMemoryIntervals, TestNoopRight) {
TEST(__untrack_memory, TestNoopRight) {
static struct MemoryIntervals mm[2] = {
{1, OPEN_MAX, 0, {I(3, 9)}},
{1, OPEN_MAX, 0, {I(3, 9)}},
@ -331,7 +365,7 @@ TEST(ReleaseMemoryIntervals, TestNoopRight) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, 10, 10));
}
TEST(ReleaseMemoryIntervals, TestBigFree) {
TEST(__untrack_memory, TestBigFree) {
static struct MemoryIntervals mm[2] = {
{2, OPEN_MAX, 0, {I(0, 3), I(6, 9)}},
{0, OPEN_MAX, 0, {}},
@ -341,7 +375,7 @@ TEST(ReleaseMemoryIntervals, TestBigFree) {
EXPECT_NE(-1, RunReleaseMemoryIntervalsTest(mm, INT_MIN, INT_MAX));
}
TEST(ReleaseMemoryIntervals, TestWeirdGap) {
TEST(__untrack_memory, TestWeirdGap) {
static struct MemoryIntervals mm[2] = {
{3, OPEN_MAX, 0, {I(10, 10), I(20, 20), I(30, 30)}},
{2, OPEN_MAX, 0, {I(10, 10), I(30, 30)}},

View file

@ -129,7 +129,7 @@ TEST(sendfile, testPositioning) {
ASSERT_TRUE(errno == EINVAL || errno == EPIPE);
errno = 0;
// XXX: WSL1 clobbers file offset on failure!
if (!IsWsl1()) {
if (!__iswsl1()) {
ASSERT_EQ(12, GetFileOffset(5));
}
_Exit(0);

View file

@ -166,7 +166,7 @@ TEST(unix, serverGoesDown_usingSendTo_unlink) { // much easier
ASSERT_SYS(0, 5, sendto(4, "hello", 5, 0, (void *)&addr, len));
ASSERT_SYS(0, 5, read(3, buf, 8));
ASSERT_SYS(0, 0, close(3));
ASSERT_SYS(IsWsl1() ? ENOTCONN : ECONNREFUSED, -1,
ASSERT_SYS(__iswsl1() ? ENOTCONN : ECONNREFUSED, -1,
sendto(4, "hello", 5, 0, (void *)&addr, len));
ASSERT_SYS(0, 0, unlink(addr.sun_path));
ASSERT_SYS(ENOENT, -1, sendto(4, "hello", 5, 0, (void *)&addr, len));

View file

@ -27,34 +27,34 @@ __static_yoink("strwidth");
volatile uint64_t v;
TEST(_tpenc, test) {
EXPECT_EQ(0, _tpenc(0));
EXPECT_EQ(1, _tpenc(1));
EXPECT_EQ(' ', _tpenc(' '));
EXPECT_EQ(0x7f, _tpenc(0x7f));
EXPECT_EQ(0x008496E2, _tpenc(L''));
EXPECT_EQ(0x8080808080FEul, _tpenc(INT_MIN));
TEST(tpenc, test) {
EXPECT_EQ(0, tpenc(0));
EXPECT_EQ(1, tpenc(1));
EXPECT_EQ(' ', tpenc(' '));
EXPECT_EQ(0x7f, tpenc(0x7f));
EXPECT_EQ(0x008496E2, tpenc(L''));
EXPECT_EQ(0x8080808080FEul, tpenc(INT_MIN));
}
TEST(_tpenc, theimp) {
ASSERT_EQ(0x88989FF0, _tpenc(L'😈'));
TEST(tpenc, theimp) {
ASSERT_EQ(0x88989FF0, tpenc(L'😈'));
}
TEST(_tpenc, testBeyondTheStandard) {
ASSERT_EQ(0xBFBFBFBFBFFF, _tpenc(-1));
TEST(tpenc, testBeyondTheStandard) {
ASSERT_EQ(0xBFBFBFBFBFFF, tpenc(-1));
}
uint64_t _Tpenc(int x) {
return (v = __expropriate(_tpenc(__veil("r", x))));
uint64_t tpenc_(int x) {
return (v = __expropriate(tpenc(__veil("r", x))));
}
BENCH(_tpenc, bench) {
EZBENCH(donothing, _Tpenc(0));
EZBENCH(donothing, _Tpenc(1));
EZBENCH(donothing, _Tpenc(' '));
EZBENCH(donothing, _Tpenc(0x7f));
EZBENCH(donothing, _Tpenc(L''));
EZBENCH(donothing, _Tpenc(-1));
EZBENCH(donothing, _Tpenc(INT_MIN));
BENCH(tpenc, bench) {
EZBENCH(donothing, tpenc_(0));
EZBENCH(donothing, tpenc_(1));
EZBENCH(donothing, tpenc_(' '));
EZBENCH(donothing, tpenc_(0x7f));
EZBENCH(donothing, tpenc_(L''));
EZBENCH(donothing, tpenc_(-1));
EZBENCH(donothing, tpenc_(INT_MIN));
fprintf(stderr, "\n");
}