mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
Improve cancellations, randomness, and time
- Exhaustively document cancellation points - Rename SIGCANCEL to SIGTHR just like BSDs - Further improve POSIX thread cancellations - Ensure asynchronous cancellations work correctly - Elevate the quality of getrandom() and getentropy() - Make futexes cancel correctly on OpenBSD 6.x and 7.x - Add reboot.com and shutdown.com to examples directory - Remove underscore prefix from awesome timespec_*() APIs - Create assertions that help verify our cancellation points - Remove bad timespec APIs (cmp generalizes eq/ne/gt/gte/lt/lte)
This commit is contained in:
parent
0d7c265392
commit
3f0bcdc3ef
173 changed files with 1599 additions and 782 deletions
|
@ -54,6 +54,13 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
char *debugbin, *p1, *p2, *p3, *addr2line;
|
||||
char buf[kBacktraceBufSize], *argv[kBacktraceMaxFrames];
|
||||
|
||||
// DWARF is a weak standard. Platforms that use LLVM or old GNU
|
||||
// usually can't be counted upon to print backtraces correctly.
|
||||
if (!IsLinux() && !IsWindows()) {
|
||||
ShowHint("won't print addr2line backtrace because probably llvm");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!PLEDGED(STDIO) || !PLEDGED(EXEC) || !PLEDGED(EXEC)) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -69,13 +76,6 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// DWARF is a weak standard. Platforms that use LLVM or old GNU
|
||||
// usually can't be counted upon to print backtraces correctly.
|
||||
if (!IsLinux() && !IsWindows()) {
|
||||
ShowHint("won't print addr2line backtrace because probably llvm");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// backtrace_test.com failing on windows for some reason via runitd
|
||||
// don't want to pull in the high-level syscalls here anyway
|
||||
if (IsWindows()) {
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
│ 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/struct/sigaction.h"
|
||||
#include "libc/calls/struct/sigaltstack.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/log/log.h"
|
||||
|
@ -40,17 +42,16 @@ STATIC_YOINK("PrintBacktraceUsingSymbols"); // for backtracing
|
|||
STATIC_YOINK("malloc_inspect_all"); // for asan memory origin
|
||||
STATIC_YOINK("GetSymbolByAddr"); // for asan memory origin
|
||||
|
||||
extern const unsigned char __oncrash_thunks[8][11];
|
||||
static struct sigaltstack g_oldsigaltstack;
|
||||
static struct sigaction g_oldcrashacts[8];
|
||||
extern const unsigned char __oncrash_thunks[8][11];
|
||||
|
||||
static void InstallCrashHandlers(int extraflags) {
|
||||
int e;
|
||||
size_t i;
|
||||
struct sigaction sa;
|
||||
bzero(&sa, sizeof(sa));
|
||||
sa.sa_flags = SA_SIGINFO | SA_NODEFER | extraflags;
|
||||
sigfillset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_SIGINFO | SA_NODEFER | extraflags;
|
||||
for (i = 0; i < ARRAYLEN(kCrashSigs); ++i) {
|
||||
sigdelset(&sa.sa_mask, kCrashSigs[i]);
|
||||
}
|
||||
|
@ -81,11 +82,6 @@ relegated void RestoreDefaultCrashSignalHandlers(void) {
|
|||
strace_enabled(+1);
|
||||
}
|
||||
|
||||
static void FreeSigAltStack(void *p) {
|
||||
sigaltstack(&g_oldsigaltstack, 0);
|
||||
munmap(p, GetStackSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs crash signal handlers.
|
||||
*
|
||||
|
@ -102,7 +98,6 @@ static void FreeSigAltStack(void *p) {
|
|||
* useful, for example, if a program is caught in an infinite loop.
|
||||
*/
|
||||
void ShowCrashReports(void) {
|
||||
char *sp;
|
||||
struct sigaltstack ss;
|
||||
_wantcrashreports = true;
|
||||
/* <SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
|
||||
|
@ -116,19 +111,12 @@ void ShowCrashReports(void) {
|
|||
kCrashSigs[7] = SIGURG; /* placeholder */
|
||||
/* </SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
|
||||
if (!IsWindows()) {
|
||||
bzero(&ss, sizeof(ss));
|
||||
ss.ss_flags = 0;
|
||||
ss.ss_size = GetStackSize();
|
||||
// FreeBSD sigaltstack() will EFAULT if we use MAP_STACK here
|
||||
// OpenBSD sigaltstack() auto-applies MAP_STACK to the memory
|
||||
if ((sp = _mapanon(GetStackSize()))) {
|
||||
ss.ss_sp = sp;
|
||||
if (!sigaltstack(&ss, &g_oldsigaltstack)) {
|
||||
__cxa_atexit(FreeSigAltStack, ss.ss_sp, 0);
|
||||
} else {
|
||||
munmap(ss.ss_sp, GetStackSize());
|
||||
}
|
||||
}
|
||||
_npassert((ss.ss_sp = _mapanon(GetStackSize())));
|
||||
_npassert(!sigaltstack(&ss, 0));
|
||||
InstallCrashHandlers(SA_ONSTACK);
|
||||
} else {
|
||||
InstallCrashHandlers(0);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/blockcancel.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/dprintf.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
|
@ -96,10 +97,11 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f,
|
|||
if (!f) return;
|
||||
flockfile(f);
|
||||
strace_enabled(-1);
|
||||
BLOCK_CANCELLATIONS;
|
||||
|
||||
// We display TIMESTAMP.MICROS normally. However, when we log multiple
|
||||
// times in the same second, we display TIMESTAMP+DELTAMICROS instead.
|
||||
t2 = _timespec_real();
|
||||
t2 = timespec_real();
|
||||
if (t2.tv_sec == vflogf_ts.tv_sec) {
|
||||
sign = "+";
|
||||
dots = t2.tv_nsec - vflogf_ts.tv_nsec;
|
||||
|
@ -138,6 +140,7 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f,
|
|||
unreachable;
|
||||
}
|
||||
|
||||
ALLOW_CANCELLATIONS;
|
||||
strace_enabled(+1);
|
||||
funlockfile(f);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue