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:
Justine Tunney 2023-11-10 04:14:27 -08:00
parent 241f949540
commit d2f49ca175
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
69 changed files with 466 additions and 533 deletions

View file

@ -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;

View file

@ -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,

View file

@ -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,
};

View file

@ -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) {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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;
}

View file

@ -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_

View file

@ -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) {

View file

@ -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 */

View file

@ -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);