mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Make improvements to cosmocc toolchain
This commit is contained in:
parent
8ff48201ca
commit
2676ec55de
8 changed files with 205 additions and 117 deletions
|
@ -23,11 +23,18 @@ void __assert_fail(const char *, const char *, int) _Hide relegated;
|
|||
({ \
|
||||
if (__builtin_expect(!(x), 0)) { \
|
||||
__assert_fail(s, __FILE__, __LINE__); \
|
||||
notpossible; \
|
||||
__builtin_trap(); \
|
||||
} \
|
||||
(void)0; \
|
||||
})
|
||||
#else
|
||||
#define _npassert(x) \
|
||||
({ \
|
||||
if (__builtin_expect(!(x), 0)) { \
|
||||
__builtin_trap(); \
|
||||
} \
|
||||
(void)0; \
|
||||
})
|
||||
#define _unassert(x) \
|
||||
({ \
|
||||
if (__builtin_expect(!(x), 0)) { \
|
||||
|
@ -35,13 +42,6 @@ void __assert_fail(const char *, const char *, int) _Hide relegated;
|
|||
} \
|
||||
(void)0; \
|
||||
})
|
||||
#define _npassert(x) \
|
||||
({ \
|
||||
if (__builtin_expect(!(x), 0)) { \
|
||||
notpossible; \
|
||||
} \
|
||||
(void)0; \
|
||||
})
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/sig.internal.h"
|
||||
|
@ -47,7 +46,7 @@ static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size,
|
|||
|
||||
if (offset != -1) {
|
||||
// windows changes the file pointer even if overlapped is passed
|
||||
_npassert(SetFilePointerEx(h, 0, &p, SEEK_CUR));
|
||||
SetFilePointerEx(h, 0, &p, SEEK_CUR);
|
||||
}
|
||||
|
||||
ok = WriteFile(h, data, _clampio(size), &sent,
|
||||
|
@ -55,7 +54,7 @@ static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size,
|
|||
|
||||
if (offset != -1) {
|
||||
// windows clobbers file pointer even on error
|
||||
_npassert(SetFilePointerEx(h, p, 0, SEEK_SET));
|
||||
SetFilePointerEx(h, p, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
|
|
|
@ -18,49 +18,15 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/atomic.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
relegated void __assert_fail(const char *expr, const char *file, int line) {
|
||||
int me, owner;
|
||||
static atomic_int once;
|
||||
privileged void __assert_fail(const char *expr, const char *file, int line) {
|
||||
static atomic_bool once;
|
||||
if (!__assert_disable) {
|
||||
strace_enabled(-1);
|
||||
ftrace_enabled(-1);
|
||||
owner = 0;
|
||||
me = __tls_enabled ? __get_tls()->tib_tid : __pid;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
|
||||
kprintf("%s:%d: assert(%s) failed (tid %d) %m\n", file, line, expr, me);
|
||||
if (__vforked ||
|
||||
atomic_compare_exchange_strong_explicit(
|
||||
&once, &owner, me, memory_order_relaxed, memory_order_relaxed)) {
|
||||
__restore_tty();
|
||||
if (_weaken(ShowBacktrace)) {
|
||||
_weaken(ShowBacktrace)(2, __builtin_frame_address(0));
|
||||
} else if (_weaken(PrintBacktraceUsingSymbols) &&
|
||||
_weaken(GetSymbolTable)) {
|
||||
_weaken(PrintBacktraceUsingSymbols)(2, __builtin_frame_address(0),
|
||||
_weaken(GetSymbolTable)());
|
||||
} else {
|
||||
kprintf("can't backtrace b/c `ShowCrashReports` not linked\n");
|
||||
}
|
||||
_Exitr(23);
|
||||
} else if (owner == me) {
|
||||
kprintf("assert failed while failing\n");
|
||||
_Exitr(24);
|
||||
} else {
|
||||
_Exit1(25);
|
||||
if (!atomic_exchange(&once, true)) {
|
||||
kprintf("%s:%d: assert(%s) failed (tid %P) %m\n", file, line, expr);
|
||||
}
|
||||
__builtin_trap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ long _missingno();
|
|||
void _weakfree(void *);
|
||||
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
|
||||
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
|
||||
void *_mapstack(void) returnsaligned((FRAMESIZE)) mallocesque;
|
||||
void *_mapstack(void) returnsaligned((APE_PAGESIZE)) mallocesque;
|
||||
int _freestack(void *);
|
||||
void __oom_hook(size_t);
|
||||
void _peekall(void);
|
||||
|
|
|
@ -55,7 +55,7 @@ void *xrealloc(void *, size_t)
|
|||
attributeallocsize((2)) dontthrow nocallback dontdiscard;
|
||||
void *xcalloc(size_t, size_t) attributeallocsize((1, 2))
|
||||
returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull;
|
||||
void *xvalloc(size_t) attributeallocsize((1)) returnsaligned((FRAMESIZE))
|
||||
void *xvalloc(size_t) attributeallocsize((1)) returnsaligned((APE_PAGESIZE))
|
||||
returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull;
|
||||
void *xmemalign(size_t, size_t) attributeallocalign((1)) attributeallocsize((2))
|
||||
returnspointerwithnoaliases dontthrow nocallback dontdiscard returnsnonnull;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue