mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 16:28:30 +00:00
Fix some issues and do some code cleanup
This commit is contained in:
parent
1f229e4efc
commit
312ed5c67c
72 changed files with 880 additions and 982 deletions
|
@ -46,6 +46,27 @@ TEST(asan, test) {
|
|||
EXPECT_FALSE(__asan_is_valid(p, 64 + 4));
|
||||
EXPECT_TRUE(__asan_is_valid(p + 1, 64 + 2));
|
||||
EXPECT_FALSE(__asan_is_valid(p + 1, 64 + 3));
|
||||
EXPECT_FALSE(__asan_is_valid(p - 1, 64));
|
||||
}
|
||||
|
||||
TEST(asan, test2) {
|
||||
char *p;
|
||||
if (!IsAsan()) return;
|
||||
p = gc(memalign(16, 64));
|
||||
// asan design precludes this kind of poisoning
|
||||
__asan_poison(p + 1, 1, kAsanProtected);
|
||||
EXPECT_TRUE(__asan_is_valid(p, 2));
|
||||
EXPECT_TRUE(__asan_is_valid(p + 1, 2));
|
||||
// but we can do this
|
||||
__asan_poison(p + 7, 1, kAsanProtected);
|
||||
EXPECT_TRUE(__asan_is_valid(p + 6, 1));
|
||||
EXPECT_FALSE(__asan_is_valid(p + 7, 1));
|
||||
EXPECT_TRUE(__asan_is_valid(p + 8, 1));
|
||||
EXPECT_FALSE(__asan_is_valid(p + 6, 2));
|
||||
EXPECT_FALSE(__asan_is_valid(p + 7, 2));
|
||||
EXPECT_FALSE(__asan_is_valid(p + 6, 3));
|
||||
__asan_unpoison(p + 7, 1);
|
||||
EXPECT_TRUE(__asan_is_valid(p + 6, 3));
|
||||
}
|
||||
|
||||
TEST(asan, testEmptySize_isAlwaysValid) {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*-*- 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 2022 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/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nexgen32e/threaded.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
char tib[64];
|
||||
|
||||
TEST(gettid, test) {
|
||||
if (IsLinux()) EXPECT_EQ(getpid(), gettid());
|
||||
if (IsNetbsd()) EXPECT_EQ(1, gettid());
|
||||
}
|
||||
|
||||
BENCH(gettid, bench) {
|
||||
int gettid_(void) asm("gettid");
|
||||
EZBENCH2("gettid (single threaded)", donothing, gettid());
|
||||
__install_tls(__initialize_tls(tib));
|
||||
EZBENCH2("gettid (tls enabled)", donothing, gettid());
|
||||
}
|
|
@ -28,6 +28,8 @@ TEST(tls, test) {
|
|||
EXPECT_EQ(31337, errno);
|
||||
EXPECT_EQ(&__errno, __errno_location());
|
||||
__initialize_tls(tib);
|
||||
*(int *)((char *)tib + 0x38) = gettid();
|
||||
*(int *)((char *)tib + 0x3c) = __errno;
|
||||
__install_tls(tib);
|
||||
EXPECT_EQ(31337, errno);
|
||||
EXPECT_EQ(tib, __get_tls());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue