mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
Make improvements
- Get threads working on NetBSD - Get threads working on OpenBSD - Fix Emacs config for Emacs v28 - Improve --strace logging of sigset_t - Improve --strace logging of struct stat - Improve memory safety of DescribeThing functions - Refactor auto stack allocation into LIBC_RUNTIME - Introduce shell.com example which works on Windows - Refactor __strace_thing into DescribeThing functions - Document the CHECK macros and improve them in NDEBUG mode - Rewrite MAP_STACK so it uses FreeBSD behavior across platforms - Deprecate and discourage the use of MAP_GROWSDOWN (it's weird)
This commit is contained in:
parent
dd9ab01d25
commit
e7611a8476
101 changed files with 967 additions and 464 deletions
|
@ -28,6 +28,8 @@
|
|||
#include "libc/runtime/stack.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/clone.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
@ -71,13 +73,10 @@ TEST(rand64, testLcg_doesntProduceIdenticalValues) {
|
|||
}
|
||||
|
||||
TEST(rand64, testThreadSafety_doesntProduceIdenticalValues) {
|
||||
char *stack;
|
||||
sigset_t ss, oldss;
|
||||
void *stacks[THREADS];
|
||||
int i, j, rc, ws, tid[THREADS];
|
||||
if (IsXnu()) return;
|
||||
if (IsNetbsd()) return; // still flaky :'(
|
||||
if (IsOpenbsd()) return; // still flaky :'(
|
||||
if (IsTiny() && IsWindows()) return; // todo(jart): wut
|
||||
struct sigaction oldsa;
|
||||
struct sigaction sa = {.sa_handler = OnChld, .sa_flags = SA_RESTART};
|
||||
EXPECT_NE(-1, sigaction(SIGCHLD, &sa, &oldsa));
|
||||
|
@ -90,8 +89,9 @@ TEST(rand64, testThreadSafety_doesntProduceIdenticalValues) {
|
|||
}
|
||||
ready = false;
|
||||
for (i = 0; i < THREADS; ++i) {
|
||||
stack = gc(malloc(GetStackSize()));
|
||||
tid[i] = clone(Thrasher, stack, GetStackSize(),
|
||||
stacks[i] = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
|
||||
tid[i] = clone(Thrasher, stacks[i], FRAMESIZE,
|
||||
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND,
|
||||
(void *)(intptr_t)i, 0, 0, 0, 0);
|
||||
ASSERT_NE(-1, tid[i]);
|
||||
|
@ -109,4 +109,7 @@ TEST(rand64, testThreadSafety_doesntProduceIdenticalValues) {
|
|||
EXPECT_NE(A[i], A[j], "i=%d j=%d", i, j);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < THREADS; ++i) {
|
||||
EXPECT_SYS(0, 0, munmap(stacks[i], FRAMESIZE));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,9 +99,8 @@ TEST(mmap, testMapFixed_destroysEverythingInItsPath) {
|
|||
TEST(mmap, customStackMemory_isAuthorized) {
|
||||
char *stack;
|
||||
uintptr_t w, r;
|
||||
ASSERT_NE(MAP_FAILED,
|
||||
(stack = mmap(NULL, STACKSIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, -1, 0)));
|
||||
ASSERT_NE(MAP_FAILED, (stack = mmap(NULL, STACKSIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_STACK, -1, 0)));
|
||||
asm("mov\t%%rsp,%0\n\t"
|
||||
"mov\t%2,%%rsp\n\t"
|
||||
"push\t%3\n\t"
|
||||
|
@ -110,6 +109,7 @@ TEST(mmap, customStackMemory_isAuthorized) {
|
|||
: "=&r"(w), "=&r"(r)
|
||||
: "rm"(stack + STACKSIZE - 8), "i"(123));
|
||||
ASSERT_EQ(123, r);
|
||||
EXPECT_SYS(0, 0, munmap(stack, STACKSIZE));
|
||||
}
|
||||
|
||||
TEST(mmap, fileOffset) {
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/intrin/spinlock.h"
|
||||
#include "libc/sysv/consts/clone.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
int x, thechilde;
|
||||
|
@ -41,17 +43,18 @@ int thread(void *arg) {
|
|||
|
||||
TEST(clone, test) {
|
||||
if (IsXnu()) return;
|
||||
if (IsOpenbsd()) return; // still flaky :'(
|
||||
int me, tid;
|
||||
char *stack;
|
||||
me = gettid();
|
||||
_spinlock(&lock);
|
||||
stack = _gc(valloc(STACKSIZE));
|
||||
ASSERT_NE(-1, (tid = clone(thread, stack, STACKSIZE,
|
||||
stack = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
|
||||
ASSERT_NE(-1, (tid = clone(thread, stack, FRAMESIZE,
|
||||
CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND,
|
||||
(void *)23, 0, 0, 0, 0)));
|
||||
_spinlock(&lock);
|
||||
ASSERT_EQ(42, x);
|
||||
ASSERT_NE(me, tid);
|
||||
ASSERT_EQ(tid, thechilde);
|
||||
EXPECT_SYS(0, 0, munmap(stack, FRAMESIZE));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue