mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Improve mkdeps
Our makefile generator now accepts badly formatted include lines. It's now more hermetic with better error checking in the cosmo repo, and it can be configured to not be hermetic at all.
This commit is contained in:
parent
241f949540
commit
d2f49ca175
69 changed files with 466 additions and 533 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/runtime/syslib.internal.h"
|
||||
#include "libc/sysv/consts/rlimit.h"
|
||||
|
|
|
@ -31,10 +31,6 @@ int64_t GetConsoleOutputHandle(void);
|
|||
int IsWindowsExecutable(int64_t, const char16_t *);
|
||||
void InterceptTerminalCommands(const char *, size_t);
|
||||
|
||||
forceinline int64_t __getfdhandleactual(int fd) {
|
||||
return g_fds.p[fd].handle;
|
||||
}
|
||||
|
||||
forceinline bool __isfdopen(int fd) {
|
||||
return 0 <= fd && fd < g_fds.n && g_fds.p[fd].kind != kFdEmpty;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ static int ioctl_default(int fd, unsigned long request, void *arg) {
|
|||
return sys_ioctl(fd, request, arg);
|
||||
} else if (__isfdopen(fd)) {
|
||||
if (g_fds.p[fd].kind == kFdSocket) {
|
||||
handle = __getfdhandleactual(fd);
|
||||
handle = g_fds.p[fd].handle;
|
||||
if ((rc = _weaken(__sys_ioctlsocket_nt)(handle, request, arg)) != -1) {
|
||||
return rc;
|
||||
} else {
|
||||
|
|
|
@ -56,6 +56,6 @@ bool32 ischardev(int fd) {
|
|||
} else {
|
||||
return __isfdkind(fd, kFdConsole) || __isfdkind(fd, kFdDevNull) ||
|
||||
(__isfdkind(fd, kFdFile) &&
|
||||
GetFileType(__getfdhandleactual(fd)) == kNtFileTypeChar);
|
||||
GetFileType(g_fds.p[fd].handle) == kNtFileTypeChar);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nexgen32e/yield.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/syslib.internal.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
@ -32,7 +31,7 @@ int pthread_yield(void) {
|
|||
if (IsXnuSilicon()) {
|
||||
__syslib->__pthread_yield_np();
|
||||
} else if (IsOpenbsd()) {
|
||||
spin_yield(); // sched_yield() is punishingly slow on OpenBSD
|
||||
pthread_pause_np(); // sched_yield() is punishingly slow on OpenBSD
|
||||
} else {
|
||||
sched_yield();
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ struct Keystrokes {
|
|||
|
||||
static struct Keystrokes __keystroke;
|
||||
|
||||
textwindows void __keystroke_wipe(void) {
|
||||
textwindows void WipeKeystrokes(void) {
|
||||
bzero(&__keystroke, sizeof(__keystroke));
|
||||
}
|
||||
|
||||
|
@ -754,8 +754,8 @@ static textwindows ssize_t ReadFromConsole(struct Fd *f, void *data,
|
|||
return rc;
|
||||
}
|
||||
|
||||
textwindows ssize_t sys_read_nt_impl(int fd, void *data, size_t size,
|
||||
int64_t offset, sigset_t waitmask) {
|
||||
textwindows ssize_t ReadBuffer(int fd, void *data, size_t size, int64_t offset,
|
||||
sigset_t waitmask) {
|
||||
|
||||
// switch to terminal polyfill if reading from win32 console
|
||||
struct Fd *f = g_fds.p + fd;
|
||||
|
@ -786,9 +786,9 @@ textwindows ssize_t sys_read_nt_impl(int fd, void *data, size_t size,
|
|||
}
|
||||
}
|
||||
|
||||
static textwindows ssize_t sys_read_nt2(int fd, const struct iovec *iov,
|
||||
size_t iovlen, int64_t opt_offset,
|
||||
sigset_t waitmask) {
|
||||
static textwindows ssize_t ReadIovecs(int fd, const struct iovec *iov,
|
||||
size_t iovlen, int64_t opt_offset,
|
||||
sigset_t waitmask) {
|
||||
ssize_t rc;
|
||||
size_t i, total;
|
||||
if (opt_offset < -1) return einval();
|
||||
|
@ -796,8 +796,8 @@ static textwindows ssize_t sys_read_nt2(int fd, const struct iovec *iov,
|
|||
if (iovlen) {
|
||||
for (total = i = 0; i < iovlen; ++i) {
|
||||
if (!iov[i].iov_len) continue;
|
||||
rc = sys_read_nt_impl(fd, iov[i].iov_base, iov[i].iov_len, opt_offset,
|
||||
waitmask);
|
||||
rc =
|
||||
ReadBuffer(fd, iov[i].iov_base, iov[i].iov_len, opt_offset, waitmask);
|
||||
if (rc == -1) {
|
||||
if (total && errno != ECANCELED) {
|
||||
return total;
|
||||
|
@ -811,7 +811,7 @@ static textwindows ssize_t sys_read_nt2(int fd, const struct iovec *iov,
|
|||
}
|
||||
return total;
|
||||
} else {
|
||||
return sys_read_nt_impl(fd, NULL, 0, opt_offset, waitmask);
|
||||
return ReadBuffer(fd, NULL, 0, opt_offset, waitmask);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -819,7 +819,7 @@ textwindows ssize_t sys_read_nt(int fd, const struct iovec *iov, size_t iovlen,
|
|||
int64_t opt_offset) {
|
||||
ssize_t rc;
|
||||
sigset_t m = __sig_block();
|
||||
rc = sys_read_nt2(fd, iov, iovlen, opt_offset, m);
|
||||
rc = ReadIovecs(fd, iov, iovlen, opt_offset, m);
|
||||
__sig_unblock(m);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/syslib.internal.h"
|
||||
#include "libc/sysv/consts/rlimit.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
|
|
@ -201,7 +201,6 @@ textwindows int __sig_raise(volatile int sig, int sic) {
|
|||
STRACE("__sig_raise(%G, %t) mask %s", sig, __sig_handler(rva),
|
||||
(DescribeSigset)(ssbuf, 0, (sigset_t *)&pt->tib->tib_sigmask));
|
||||
__sig_handler(rva)(sig, &si, &ctx);
|
||||
(void)ssbuf;
|
||||
|
||||
// record this handler
|
||||
if (flags & SA_RESTART) {
|
||||
|
@ -271,7 +270,6 @@ static textwindows wontreturn void __sig_tramp(struct SignalFrame *sf) {
|
|||
(DescribeSigset)(ssbuf[0], 0, &sf->ctx.uc_sigmask),
|
||||
(DescribeSigset)(ssbuf[1], 0, (sigset_t *)&tib->tib_sigmask));
|
||||
__sig_handler(sf->rva)(sig, &sf->si, &sf->ctx);
|
||||
(void)ssbuf;
|
||||
|
||||
// restore the signal mask that was used by the interrupted code
|
||||
// this may have been modified by the signal handler in the callback
|
||||
|
|
|
@ -51,7 +51,6 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info,
|
|||
struct timespec ts;
|
||||
union siginfo_meta si = {0};
|
||||
BEGIN_CANCELATION_POINT;
|
||||
(void)strsig;
|
||||
|
||||
if (IsAsan() && (!__asan_is_valid(set, sizeof(*set)) ||
|
||||
(info && !__asan_is_valid(info, sizeof(*info))) ||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
/**
|
||||
* Flushes file system changes to disk by any means necessary.
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
#define IsPeek(request) (IsLinux() && (request)-1u < 3)
|
||||
|
||||
|
|
|
@ -28,9 +28,10 @@
|
|||
#include "libc/str/tab.internal.h"
|
||||
#include "third_party/linenoise/linenoise.h"
|
||||
|
||||
#define EXT(s) READ32LE(s "\0\0")
|
||||
#define Read32(s) (s[3] << 24 | s[2] << 16 | s[1] << 8 | s[0])
|
||||
#define EXT(s) Read32(s "\0\0")
|
||||
|
||||
static bool IsGraph(wint_t c) {
|
||||
static inline bool IsGraph(wint_t c) {
|
||||
return 0x21 <= c && c <= 0x7E;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/getenv.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
|
||||
privileged struct Env __getenv(char **p, const char *k) {
|
||||
char *t;
|
||||
|
|
|
@ -49,13 +49,9 @@ CreateFile(const char16_t *lpFileName, //
|
|||
int64_t hHandle;
|
||||
uint32_t micros = 1;
|
||||
char buf_accessflags[512];
|
||||
(void)buf_accessflags;
|
||||
char buf_shareflags[64];
|
||||
(void)buf_shareflags;
|
||||
char buf_secattr[32];
|
||||
(void)buf_secattr;
|
||||
char buf_flagattr[256];
|
||||
(void)buf_flagattr;
|
||||
TryAgain:
|
||||
hHandle = __imp_CreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
|
||||
opt_lpSecurity, dwCreationDisposition,
|
||||
|
|
|
@ -33,7 +33,10 @@ void __cxa_unlock(void) {
|
|||
pthread_mutex_unlock(&__cxa_lock_obj);
|
||||
}
|
||||
|
||||
__attribute__((__constructor__)) static void __cxa_init(void) {
|
||||
__cxa_wipe();
|
||||
static textstartup void __cxa_init() {
|
||||
pthread_atfork(__cxa_lock, __cxa_unlock, __cxa_wipe);
|
||||
}
|
||||
|
||||
const void *const __cxa_ctor[] initarray = {
|
||||
__cxa_init,
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @param delta is added to enabled state
|
||||
* @return enabled state before `delta` was applied
|
||||
*/
|
||||
dontinstrument int ftrace_enabled(int delta) {
|
||||
dontinstrument int(ftrace_enabled)(int delta) {
|
||||
int res;
|
||||
struct CosmoTib *tib;
|
||||
if (__tls_enabled) {
|
||||
|
|
|
@ -50,7 +50,7 @@ int IsDebuggerPresent(bool force) {
|
|||
int e, fd, res;
|
||||
char *p, buf[1024];
|
||||
if (!force && IsGenuineBlink()) return 0;
|
||||
if (!force && __getenv(environ, "HEISENDEBUG").s) return 0;
|
||||
if (!force && environ && __getenv(environ, "HEISENDEBUG").s) return 0;
|
||||
if (IsWindows()) return IsBeingDebugged();
|
||||
if (__isworker) return false;
|
||||
if (!PLEDGED(RPATH)) return false;
|
||||
|
|
|
@ -345,7 +345,7 @@ privileged long kloghandle(void) {
|
|||
// it's too early in the initialization process for kprintf
|
||||
return -1;
|
||||
}
|
||||
path = __getenv(__envp, "KPRINTF_LOG").s;
|
||||
path = environ ? __getenv(environ, "KPRINTF_LOG").s : 0;
|
||||
closefd = false;
|
||||
if (!path) {
|
||||
fd = STDERR_FILENO;
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/nexgen32e/yield.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
@ -83,7 +82,7 @@ errno_t pthread_mutex_lock(pthread_mutex_t *mutex) {
|
|||
|
||||
if (mutex->_type == PTHREAD_MUTEX_NORMAL) {
|
||||
while (atomic_exchange_explicit(&mutex->_lock, 1, memory_order_acquire)) {
|
||||
spin_yield();
|
||||
pthread_pause_np();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,7 +102,7 @@ errno_t pthread_mutex_lock(pthread_mutex_t *mutex) {
|
|||
}
|
||||
|
||||
while (atomic_exchange_explicit(&mutex->_lock, 1, memory_order_acquire)) {
|
||||
spin_yield();
|
||||
pthread_pause_np();
|
||||
}
|
||||
|
||||
mutex->_depth = 0;
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/nexgen32e/yield.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
intptr_t _pthread_syshand(struct PosixThread *pt) {
|
||||
intptr_t syshand;
|
||||
|
@ -28,6 +28,6 @@ intptr_t _pthread_syshand(struct PosixThread *pt) {
|
|||
for (;;) {
|
||||
syshand = atomic_load_explicit(&pt->tib->tib_syshand, memory_order_acquire);
|
||||
if (syshand) return syshand;
|
||||
spin_yield();
|
||||
pthread_pause_np();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/nexgen32e/yield.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
int _pthread_tid(struct PosixThread *pt) {
|
||||
int tid = 0;
|
||||
while (pt && !(tid = atomic_load_explicit(&pt->ptid, memory_order_acquire))) {
|
||||
spin_yield();
|
||||
pthread_pause_np();
|
||||
}
|
||||
return tid;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
#ifndef SYSDEBUG
|
||||
#define SYSDEBUG 1
|
||||
#endif
|
||||
|
||||
#define _NTTRACE 0 /* not configurable w/ flag yet */
|
||||
#define _POLLTRACE 0 /* not configurable w/ flag yet */
|
||||
|
@ -16,60 +18,40 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#ifdef SYSDEBUG
|
||||
#define STRACE(FMT, ...) \
|
||||
do { \
|
||||
if (UNLIKELY(strace_enter())) { \
|
||||
__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__); \
|
||||
ftrace_enabled(+1); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define STRACE(FMT, ...) (void)0
|
||||
#endif
|
||||
#define STRACE(FMT, ...) \
|
||||
((void)(SYSDEBUG && strace_enabled(0) > 0 && \
|
||||
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
||||
|
||||
#if defined(SYSDEBUG) && _DATATRACE
|
||||
#define DATATRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__)
|
||||
#else
|
||||
#define DATATRACE(FMT, ...) (void)0
|
||||
#endif
|
||||
#define DATATRACE(FMT, ...) \
|
||||
((void)(SYSDEBUG && _DATATRACE && strace_enabled(0) > 0 && \
|
||||
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
||||
|
||||
#if defined(SYSDEBUG) && _POLLTRACE
|
||||
#define POLLTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__)
|
||||
#else
|
||||
#define POLLTRACE(FMT, ...) (void)0
|
||||
#endif
|
||||
#define POLLTRACE(FMT, ...) \
|
||||
((void)(SYSDEBUG && _POLLTRACE && strace_enabled(0) > 0 && \
|
||||
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
||||
|
||||
#if defined(SYSDEBUG) && _KERNTRACE
|
||||
#define KERNTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__)
|
||||
#else
|
||||
#define KERNTRACE(FMT, ...) (void)0
|
||||
#endif
|
||||
#define KERNTRACE(FMT, ...) \
|
||||
((void)(SYSDEBUG && _KERNTRACE && strace_enabled(0) > 0 && \
|
||||
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
||||
|
||||
#if defined(SYSDEBUG) && _STDIOTRACE
|
||||
#define STDIOTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__)
|
||||
#else
|
||||
#define STDIOTRACE(FMT, ...) (void)0
|
||||
#endif
|
||||
#define STDIOTRACE(FMT, ...) \
|
||||
((void)(SYSDEBUG && _STDIOTRACE && strace_enabled(0) > 0 && \
|
||||
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
||||
|
||||
#if defined(SYSDEBUG) && _NTTRACE
|
||||
#define NTTRACE(FMT, ...) STRACE("\e[2m" FMT "\e[0m", ##__VA_ARGS__)
|
||||
#else
|
||||
#define NTTRACE(FMT, ...) (void)0
|
||||
#endif
|
||||
#define NTTRACE(FMT, ...) \
|
||||
((void)(SYSDEBUG && _NTTRACE && strace_enabled(0) > 0 && \
|
||||
(__stracef(STRACE_PROLOGUE "\e[2m" FMT "\e[0m\n", ##__VA_ARGS__), \
|
||||
0)))
|
||||
|
||||
#if defined(SYSDEBUG) && _LOCKTRACE
|
||||
#define LOCKTRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOCKTRACE(FMT, ...) (void)0
|
||||
#endif
|
||||
#define LOCKTRACE(FMT, ...) \
|
||||
((void)(SYSDEBUG && _LOCKTRACE && strace_enabled(0) > 0 && \
|
||||
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
||||
|
||||
#if defined(SYSDEBUG) && _TIMETRACE
|
||||
#define TIMETRACE(FMT, ...) STRACE(FMT, ##__VA_ARGS__)
|
||||
#else
|
||||
#define TIMETRACE(FMT, ...) (void)0
|
||||
#endif
|
||||
#define TIMETRACE(FMT, ...) \
|
||||
((void)(SYSDEBUG && _TIMETRACE && strace_enabled(0) > 0 && \
|
||||
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
||||
|
||||
int strace_enabled(int);
|
||||
void __stracef(const char *, ...);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
* @param delta is added to enabled state
|
||||
* @return enabled state before `delta` was applied
|
||||
*/
|
||||
dontinstrument int strace_enabled(int delta) {
|
||||
dontinstrument int(strace_enabled)(int delta) {
|
||||
int res;
|
||||
struct CosmoTib *tib;
|
||||
if (__tls_enabled) {
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*-*- 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"
|
||||
#ifdef SYSDEBUG
|
||||
|
||||
dontinstrument bool strace_enter(void) {
|
||||
if (strace_enabled(0) > 0) {
|
||||
ftrace_enabled(-1);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SYSDEBUG */
|
|
@ -19,15 +19,10 @@
|
|||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "libc/thread/tls2.internal.h"
|
||||
|
||||
privileged void __stracef(const char *fmt, ...) {
|
||||
dontinstrument void __stracef(const char *fmt, ...) {
|
||||
va_list v;
|
||||
if (__strace <= 0 ||
|
||||
(__tls_enabled && __get_tls_privileged()->tib_strace <= 0)) {
|
||||
return;
|
||||
}
|
||||
if (strace_enabled(0) <= 0) return;
|
||||
va_start(v, fmt);
|
||||
kvprintf(fmt, v);
|
||||
va_end(v);
|
||||
|
|
16
libc/nexgen32e/yield.h
Normal file → Executable file
16
libc/nexgen32e/yield.h
Normal file → Executable file
|
@ -1,16 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_YIELD_H_
|
||||
#define COSMOPOLITAN_LIBC_YIELD_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
static inline void spin_yield(void) {
|
||||
#if defined(__GNUC__) && defined(__aarch64__)
|
||||
__asm__ volatile("yield");
|
||||
#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
|
||||
__asm__ volatile("pause");
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_YIELD_H_ */
|
|
@ -29,6 +29,7 @@
|
|||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/zipos.internal.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
#include "libc/thread/tls.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
void __keystroke_wipe(void);
|
||||
void WipeKeystrokes(void);
|
||||
|
||||
static textwindows wontreturn void AbortFork(const char *func) {
|
||||
#ifdef SYSDEBUG
|
||||
|
@ -310,9 +310,9 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
|
|||
bzero(&startinfo, sizeof(startinfo));
|
||||
startinfo.cb = sizeof(struct NtStartupInfo);
|
||||
startinfo.dwFlags = kNtStartfUsestdhandles;
|
||||
startinfo.hStdInput = __getfdhandleactual(0);
|
||||
startinfo.hStdOutput = __getfdhandleactual(1);
|
||||
startinfo.hStdError = __getfdhandleactual(2);
|
||||
startinfo.hStdInput = g_fds.p[0].handle;
|
||||
startinfo.hStdOutput = g_fds.p[1].handle;
|
||||
startinfo.hStdError = g_fds.p[2].handle;
|
||||
args = __argv;
|
||||
#ifdef SYSDEBUG
|
||||
// If --strace was passed to this program, then propagate it the
|
||||
|
@ -395,7 +395,7 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
|
|||
}
|
||||
// reset core runtime services
|
||||
__proc_wipe();
|
||||
__keystroke_wipe();
|
||||
WipeKeystrokes();
|
||||
if (_weaken(__itimer_wipe)) {
|
||||
_weaken(__itimer_wipe)();
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ int _fork(uint32_t dwCreationFlags) {
|
|||
struct Dll *e;
|
||||
int ax, dx, tid, parent;
|
||||
parent = __pid;
|
||||
(void)parent;
|
||||
BLOCK_SIGNALS;
|
||||
if (IsWindows()) __proc_lock();
|
||||
if (__threaded && _weaken(_pthread_onfork_prepare)) {
|
||||
|
|
|
@ -269,10 +269,9 @@ textwindows void __proc_wipe(void) {
|
|||
textwindows struct Proc *__proc_new(void) {
|
||||
struct Dll *e;
|
||||
struct Proc *proc = 0;
|
||||
int i, n = ARRAYLEN(__proc.pool);
|
||||
if (atomic_load_explicit(&__proc.allocated, memory_order_acquire) < n &&
|
||||
(i = atomic_fetch_add(&__proc.allocated, 1)) < n) {
|
||||
proc = __proc.pool + i;
|
||||
// fork() + wait() don't depend on malloc() so neither shall we
|
||||
if (__proc.allocated < ARRAYLEN(__proc.pool)) {
|
||||
proc = __proc.pool + __proc.allocated++;
|
||||
} else {
|
||||
if ((e = dll_first(__proc.free))) {
|
||||
proc = PROC_CONTAINER(e);
|
||||
|
|
|
@ -91,7 +91,6 @@ void ShowCrashReports(void);
|
|||
int ftrace_install(void);
|
||||
int ftrace_enabled(int);
|
||||
int strace_enabled(int);
|
||||
bool strace_enter(void);
|
||||
void __print_maps(void);
|
||||
void __printargs(const char *);
|
||||
/* builtin sh-like system/popen dsl */
|
||||
|
@ -139,10 +138,10 @@ __funline int __trace_disabled(int x) {
|
|||
return 0;
|
||||
}
|
||||
#ifndef FTRACE
|
||||
#define ftrace_enabled __trace_disabled
|
||||
#define ftrace_enabled(...) __trace_disabled(__VA_ARGS__)
|
||||
#endif
|
||||
#ifndef SYSDEBUG
|
||||
#define strace_enabled __trace_disabled
|
||||
#define strace_enabled(...) __trace_disabled(__VA_ARGS__)
|
||||
#endif
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
||||
|
|
|
@ -152,7 +152,6 @@ static void __zipos_init(void) {
|
|||
progpath = 0;
|
||||
msg = -777;
|
||||
}
|
||||
(void)msg;
|
||||
STRACE("__zipos_get(%#s) → %d% m", progpath, msg);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ struct NtWsaData kNtWsaData;
|
|||
|
||||
static textwindows void WinSockCleanup(void) {
|
||||
int rc;
|
||||
(void)rc;
|
||||
rc = WSACleanup();
|
||||
NTTRACE("WSACleanup() → %d% lm", rc);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sock/struct/msghdr.h"
|
||||
|
@ -87,7 +88,8 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) {
|
|||
END_CANCELATION_POINT;
|
||||
|
||||
#if defined(SYSDEBUG) && _DATATRACE
|
||||
if (__strace > 0 && strace_enabled(0) > 0) {
|
||||
// TODO(jart): Write a DescribeMsg() function.
|
||||
if (strace_enabled(0) > 0) {
|
||||
kprintf(STRACE_PROLOGUE "sendmsg(");
|
||||
if ((!IsAsan() && kisdangerous(msg)) ||
|
||||
(IsAsan() && !__asan_is_valid(msg, sizeof(*msg)))) {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
|
||||
/**
|
||||
* Reads data from stream.
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
|
||||
/**
|
||||
* Repositions open file stream.
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
|
||||
/**
|
||||
* Writes data to stream.
|
||||
|
|
|
@ -8,6 +8,7 @@ LIBC_STDIO = $(LIBC_STDIO_A_DEPS) $(LIBC_STDIO_A)
|
|||
LIBC_STDIO_A = o/$(MODE)/libc/stdio/stdio.a
|
||||
LIBC_STDIO_A_FILES := $(wildcard libc/stdio/*)
|
||||
LIBC_STDIO_A_HDRS = $(filter %.h,$(LIBC_STDIO_A_FILES))
|
||||
LIBC_STDIO_A_INCS = $(filter %.inc,$(LIBC_STDIO_A_FILES))
|
||||
LIBC_STDIO_A_SRCS_S = $(filter %.S,$(LIBC_STDIO_A_FILES))
|
||||
LIBC_STDIO_A_SRCS_C = $(filter %.c,$(LIBC_STDIO_A_FILES))
|
||||
|
||||
|
@ -68,6 +69,7 @@ o/$(MODE)/libc/stdio/mt19937.o: private \
|
|||
LIBC_STDIO_LIBS = $(foreach x,$(LIBC_STDIO_ARTIFACTS),$($(x)))
|
||||
LIBC_STDIO_SRCS = $(foreach x,$(LIBC_STDIO_ARTIFACTS),$($(x)_SRCS))
|
||||
LIBC_STDIO_HDRS = $(foreach x,$(LIBC_STDIO_ARTIFACTS),$($(x)_HDRS))
|
||||
LIBC_STDIO_INCS = $(foreach x,$(LIBC_STDIO_ARTIFACTS),$($(x)_INCS))
|
||||
LIBC_STDIO_CHECKS = $(foreach x,$(LIBC_STDIO_ARTIFACTS),$($(x)_CHECKS))
|
||||
LIBC_STDIO_OBJS = $(foreach x,$(LIBC_STDIO_ARTIFACTS),$($(x)_OBJS))
|
||||
$(LIBC_STDIO_OBJS): $(BUILD_FILES) libc/stdio/stdio.mk
|
||||
|
|
|
@ -399,7 +399,9 @@ _init_systemfive_magnums:
|
|||
jz 5f
|
||||
ezlea .Llog,di
|
||||
mov %r8d,%esi
|
||||
push %rax
|
||||
call *%rax
|
||||
pop %rax
|
||||
5: pop %rsi
|
||||
pop %rdi
|
||||
#endif /* DEBUGSYS */
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -122,6 +123,7 @@ dontasan int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
// run tests
|
||||
CheckStackIsAligned();
|
||||
testlib_runalltests();
|
||||
|
||||
// run benchmarks
|
||||
|
|
|
@ -91,8 +91,10 @@ void testlib_runtestcases(const testfn_t *start, const testfn_t *end,
|
|||
// the linker sorts into an array.
|
||||
char host[64];
|
||||
struct Dll *e;
|
||||
const char *user;
|
||||
const testfn_t *fn;
|
||||
struct TestAspect *a;
|
||||
user = getenv("USER");
|
||||
strcpy(host, "unknown");
|
||||
gethostname(host, sizeof(host)), errno = 0;
|
||||
for (fn = start; fn != end; ++fn) {
|
||||
|
@ -111,7 +113,7 @@ void testlib_runtestcases(const testfn_t *start, const testfn_t *end,
|
|||
if (warmup) warmup();
|
||||
testlib_clearxmmregisters();
|
||||
STRACE("");
|
||||
STRACE("# running test %t on %s@%s", fn, __getenv(environ, "USER").s, host);
|
||||
STRACE("# running test %t on %s@%s", fn, user, host);
|
||||
(*fn)();
|
||||
STRACE("");
|
||||
STRACE("# tearing down %t", fn);
|
||||
|
|
|
@ -213,6 +213,14 @@ void pthread_testcancel(void);
|
|||
pthread_cleanup_pop(&_buffer, (execute)); \
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && defined(__aarch64__)
|
||||
#define pthread_pause_np() __asm__ volatile("yield")
|
||||
#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
|
||||
#define pthread_pause_np() __asm__ volatile("pause")
|
||||
#else
|
||||
#define pthread_pause_np() (void)0
|
||||
#endif
|
||||
|
||||
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 && \
|
||||
!defined(__STRICT_ANSI__) && !defined(MODE_DBG)
|
||||
extern const errno_t EBUSY;
|
||||
|
@ -220,6 +228,7 @@ extern const errno_t EBUSY;
|
|||
({ \
|
||||
pthread_spinlock_t *_s = pSpin; \
|
||||
while (__atomic_test_and_set(&_s->_lock, __ATOMIC_ACQUIRE)) { \
|
||||
pthread_pause_np(); \
|
||||
} \
|
||||
0; \
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue