mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 03:38:31 +00:00
Add torture test for zipos file descriptors
This change hardens the code for opening /zip/ files using the system call interface. Thread safety and signal safety has been improved for file descriptors in general. We now document fixed addresses that are needed for low level allocations.
This commit is contained in:
parent
579080cd4c
commit
e466dd0553
44 changed files with 2981 additions and 307 deletions
|
@ -21,7 +21,9 @@
|
|||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
|
@ -82,6 +84,7 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
}
|
||||
|
||||
// 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()) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -118,17 +121,17 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
j += uint64toarray_radix16(addr - 1, buf + j) + 1;
|
||||
}
|
||||
argv[i++] = NULL;
|
||||
pipe(pipefds);
|
||||
if (sys_pipe(pipefds) == -1) return -1;
|
||||
if (!(pid = vfork())) {
|
||||
dup2(pipefds[1], 1);
|
||||
if (pipefds[0] != 1) close(pipefds[0]);
|
||||
if (pipefds[1] != 1) close(pipefds[1]);
|
||||
execve(addr2line, argv, environ);
|
||||
_exit(127);
|
||||
sys_dup2(pipefds[1], 1);
|
||||
if (pipefds[0] != 1) sys_close(pipefds[0]);
|
||||
if (pipefds[1] != 1) sys_close(pipefds[1]);
|
||||
sys_execve(addr2line, argv, environ);
|
||||
_Exit(127);
|
||||
}
|
||||
close(pipefds[1]);
|
||||
sys_close(pipefds[1]);
|
||||
for (;;) {
|
||||
got = read(pipefds[0], buf, kBacktraceBufSize);
|
||||
got = sys_read(pipefds[0], buf, kBacktraceBufSize);
|
||||
if (!got) break;
|
||||
if (got == -1 && errno == EINTR) {
|
||||
errno = 0;
|
||||
|
@ -161,8 +164,8 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
|
|||
}
|
||||
}
|
||||
}
|
||||
close(pipefds[0]);
|
||||
while (waitpid(pid, &ws, 0) == -1) {
|
||||
sys_close(pipefds[0]);
|
||||
while (sys_wait4(pid, &ws, 0, 0) == -1) {
|
||||
if (errno == EINTR) continue;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "libc/bits/atomic.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/spinlock.h"
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
@ -71,14 +70,14 @@ static struct Memlog {
|
|||
long usage;
|
||||
} __memlog;
|
||||
|
||||
_Alignas(64) static int __memlog_lock_obj;
|
||||
static pthread_mutex_t __memlog_lock_obj;
|
||||
|
||||
static void __memlog_lock(void) {
|
||||
_spinlock(&__memlog_lock_obj);
|
||||
pthread_mutex_lock(&__memlog_lock_obj);
|
||||
}
|
||||
|
||||
static void __memlog_unlock(void) {
|
||||
_spunlock(&__memlog_lock_obj);
|
||||
pthread_mutex_unlock(&__memlog_lock_obj);
|
||||
}
|
||||
|
||||
static long __memlog_size(void *p) {
|
||||
|
|
|
@ -263,8 +263,7 @@ static wontreturn relegated noinstrument void __minicrash(int sig,
|
|||
*
|
||||
* This function never returns, except for traps w/ human supervision.
|
||||
*/
|
||||
relegated noinstrument void __oncrash(int sig, struct siginfo *si,
|
||||
ucontext_t *ctx) {
|
||||
relegated void __oncrash(int sig, struct siginfo *si, ucontext_t *ctx) {
|
||||
intptr_t rip;
|
||||
int gdbpid, err;
|
||||
static bool noreentry, notpossible;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue