mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 17:28:30 +00:00
Improve system calls
- Wrap clock_getres() - Wrap sched_setscheduler() - Make sleep() api conformant - Polyfill sleep() using select() - Improve clock_gettime() polyfill - Make nanosleep() POSIX conformant - Slightly improve some DNS functions - Further strengthen pledge() sandboxing - Improve rounding of timeval / timespec - Allow layering of pledge() calls on Linux - Polyfill sched_yield() using select() on XNU - Delete more system constants we probably don't need
This commit is contained in:
parent
5df3e4e7a8
commit
853b6c3864
330 changed files with 1971 additions and 1223 deletions
|
@ -16,11 +16,11 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/atomic.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/spinlock.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
|
@ -32,16 +32,12 @@ const char *testlib_showerror_func;
|
|||
const char *testlib_showerror_isfatal;
|
||||
const char *testlib_showerror_macro;
|
||||
const char *testlib_showerror_symbol;
|
||||
_Alignas(64) static char testlib_showerror_lock;
|
||||
|
||||
testonly void testlib_showerror(const char *file, int line, const char *func,
|
||||
const char *method, const char *symbol,
|
||||
const char *code, char *v1, char *v2) {
|
||||
char *p;
|
||||
char hostname[128];
|
||||
_spinlock(&testlib_showerror_lock);
|
||||
if (!IsWindows()) __getpid(); /* make strace easier to read */
|
||||
if (!IsWindows()) __getpid();
|
||||
__stpcpy(hostname, "unknown");
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
kprintf("%serror%s%s:%s:%d%s: %s() in %s(%s) on %s pid %d tid %d\n"
|
||||
|
@ -55,7 +51,6 @@ testonly void testlib_showerror(const char *file, int line, const char *func,
|
|||
SUBTLE, strerror(errno), GetProgramExecutableName(), RESET);
|
||||
free_s(&v1);
|
||||
free_s(&v2);
|
||||
_spunlock(&testlib_showerror_lock);
|
||||
}
|
||||
|
||||
/* TODO(jart): Pay off tech debt re duplication */
|
||||
|
@ -65,10 +60,7 @@ testonly void testlib_showerror_(int line, const char *wantcode,
|
|||
int e;
|
||||
va_list va;
|
||||
char hostname[128];
|
||||
_spinlock(&testlib_showerror_lock);
|
||||
e = errno;
|
||||
if (!IsWindows()) __getpid();
|
||||
if (!IsWindows()) __getpid();
|
||||
if (gethostname(hostname, sizeof(hostname))) {
|
||||
__stpcpy(hostname, "unknown");
|
||||
}
|
||||
|
@ -98,6 +90,7 @@ testonly void testlib_showerror_(int line, const char *wantcode,
|
|||
free_s(&FREED_want);
|
||||
free_s(&FREED_got);
|
||||
++g_testlib_failed;
|
||||
if (testlib_showerror_isfatal) testlib_abort();
|
||||
_spunlock(&testlib_showerror_lock);
|
||||
if (testlib_showerror_isfatal) {
|
||||
testlib_abort();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,12 +268,11 @@ void TearDownOnce(void);
|
|||
Got = (intptr_t)(GOT); \
|
||||
Want = (intptr_t)(WANT); \
|
||||
if (Want != Got) { \
|
||||
if (g_testlib_shoulddebugbreak) DebugBreak(); \
|
||||
testlib_showerror_file = FILE; \
|
||||
testlib_showerror_func = FUNC; \
|
||||
testlib_error_enter(FILE, FUNC); \
|
||||
testlib_showerror_##KIND##_eq(LINE, WANTCODE, GOTCODE, \
|
||||
testlib_formatint(Want), \
|
||||
testlib_formatint(Got), "" __VA_ARGS__); \
|
||||
testlib_error_leave(); \
|
||||
} \
|
||||
(void)0; \
|
||||
} while (0)
|
||||
|
@ -285,12 +284,11 @@ void TearDownOnce(void);
|
|||
Got = (intptr_t)(GOT); \
|
||||
Want = (intptr_t)(WANT); \
|
||||
if (Want == Got) { \
|
||||
if (g_testlib_shoulddebugbreak) DebugBreak(); \
|
||||
testlib_showerror_file = FILE; \
|
||||
testlib_showerror_func = FUNC; \
|
||||
testlib_error_enter(FILE, FUNC); \
|
||||
testlib_showerror_##KIND##_ne(LINE, WANTCODE, GOTCODE, \
|
||||
testlib_formatint(Want), \
|
||||
testlib_formatint(Got), "" __VA_ARGS__); \
|
||||
testlib_error_leave(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
@ -344,6 +342,8 @@ void testlib_showerror_expect_ne(int, const char *, const char *, char *,
|
|||
void testlib_showerror_expect_true(int, const char *, const char *, char *,
|
||||
char *, const char *, ...);
|
||||
|
||||
void testlib_error_leave(void);
|
||||
void testlib_error_enter(const char *, const char *);
|
||||
void testlib_showerror(const char *, int, const char *, const char *,
|
||||
const char *, const char *, char *, char *);
|
||||
|
||||
|
@ -391,7 +391,9 @@ forceinline void testlib_ontest() {
|
|||
|
||||
forceinline void testlib_onfail2(bool isfatal) {
|
||||
testlib_incrementfailed();
|
||||
if (isfatal) testlib_abort();
|
||||
if (isfatal) {
|
||||
testlib_abort();
|
||||
}
|
||||
}
|
||||
|
||||
forceinline void assertNotEquals(FILIFU_ARGS intptr_t donotwant, intptr_t got,
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/atomic.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
|
@ -28,6 +29,7 @@
|
|||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/spinlock.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
@ -49,6 +51,7 @@ static int x;
|
|||
char g_testlib_olddir[PATH_MAX];
|
||||
char g_testlib_tmpdir[PATH_MAX];
|
||||
struct sigaction wanthandlers[31];
|
||||
static char testlib_error_lock;
|
||||
|
||||
void testlib_finish(void) {
|
||||
if (g_testlib_failed) {
|
||||
|
@ -57,11 +60,29 @@ void testlib_finish(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void testlib_error_enter(const char *file, const char *func) {
|
||||
atomic_fetch_sub_explicit(&__ftrace, 1, memory_order_relaxed);
|
||||
atomic_fetch_sub_explicit(&__strace, 1, memory_order_relaxed);
|
||||
_spinlock(&testlib_error_lock);
|
||||
if (!IsWindows()) sys_getpid(); /* make strace easier to read */
|
||||
if (!IsWindows()) sys_getpid();
|
||||
if (g_testlib_shoulddebugbreak) {
|
||||
DebugBreak();
|
||||
}
|
||||
testlib_showerror_file = file;
|
||||
testlib_showerror_func = func;
|
||||
}
|
||||
|
||||
void testlib_error_leave(void) {
|
||||
atomic_fetch_add_explicit(&__ftrace, 1, memory_order_relaxed);
|
||||
atomic_fetch_add_explicit(&__strace, 1, memory_order_relaxed);
|
||||
_spunlock(&testlib_error_lock);
|
||||
}
|
||||
|
||||
wontreturn void testlib_abort(void) {
|
||||
testlib_finish();
|
||||
__restorewintty();
|
||||
_Exit(MIN(255, g_testlib_failed));
|
||||
unreachable;
|
||||
}
|
||||
|
||||
static void SetupTmpDir(void) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue