mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
Rewrite special file handling on Windows
This change gets GNU grep working. What caused it to not work, is it wouldn't write to an output file descriptor when its dev/ino equaled /dev/null's. So now we invent special dev/ino values for these files
This commit is contained in:
parent
aca2261cda
commit
2db2f40a98
53 changed files with 485 additions and 299 deletions
|
@ -96,11 +96,19 @@ static wontreturn void UnsupportedSyntax(unsigned char c) {
|
|||
}
|
||||
|
||||
static void Open(const char *path, int fd, int flags) {
|
||||
close(fd);
|
||||
if (open(path, flags, 0644) == -1) {
|
||||
int tmpfd;
|
||||
// use open+dup2 to support things like >/dev/stdout
|
||||
if ((tmpfd = open(path, flags, 0644)) == -1) {
|
||||
perror(path);
|
||||
_Exit(1);
|
||||
}
|
||||
if (tmpfd != fd) {
|
||||
if (dup2(tmpfd, fd) == -1) {
|
||||
perror("dup2");
|
||||
_Exit(1);
|
||||
}
|
||||
close(tmpfd);
|
||||
}
|
||||
}
|
||||
|
||||
static int SystemExec(void) {
|
||||
|
|
|
@ -67,10 +67,8 @@
|
|||
#include "libc/thread/itimer.internal.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/tls.h"
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
extern int64_t __wincrashearly;
|
||||
void __keystroke_wipe(void);
|
||||
|
||||
static textwindows wontreturn void AbortFork(const char *func) {
|
||||
|
@ -399,7 +397,7 @@ textwindows int sys_fork_nt(uint32_t dwCreationFlags) {
|
|||
__tls_enabled_set(true);
|
||||
// clear pending signals
|
||||
tib->tib_sigpending = 0;
|
||||
__sig.pending = 0;
|
||||
atomic_store_explicit(&__sig.pending, 0, memory_order_relaxed);
|
||||
// re-enable threads
|
||||
__enable_threads();
|
||||
// re-apply code morphing for function tracing
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/calls/struct/rusage.internal.h"
|
||||
#include "libc/calls/syscall_support-nt.internal.h"
|
||||
#include "libc/fmt/wintime.internal.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/nt/accounting.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
|
@ -75,7 +76,7 @@ textwindows int sys_getrusage_nt(int who, struct rusage *usage) {
|
|||
.ru_majflt = memcount.PageFaultCount,
|
||||
.ru_inblock = iocount.ReadOperationCount,
|
||||
.ru_oublock = iocount.WriteOperationCount,
|
||||
.ru_nsignals = __sig.count,
|
||||
.ru_nsignals = atomic_load_explicit(&__sig.count, memory_order_acquire),
|
||||
};
|
||||
|
||||
if (who == RUSAGE_BOTH) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue