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:
Justine Tunney 2023-10-14 01:06:00 -07:00
parent aca2261cda
commit 2db2f40a98
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
53 changed files with 485 additions and 299 deletions

View file

@ -2,6 +2,7 @@
#define COSMOPOLITAN_LIBC_THREAD_POSIXTHREAD_INTERNAL_H_
#include "libc/calls/struct/sched_param.h"
#include "libc/calls/struct/sigaltstack.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/dll.h"
#include "libc/runtime/runtime.h"
#include "libc/thread/thread.h"
@ -16,9 +17,9 @@
#define PT_RESTARTABLE 64
#define PT_OPENBSD_KLUDGE 128
#define PT_BLOCKER_CPU ((_Atomic(int) *)-0)
#define PT_BLOCKER_SEM ((_Atomic(int) *)-1)
#define PT_BLOCKER_IO ((_Atomic(int) *)-2)
#define PT_BLOCKER_CPU ((atomic_int *)-0)
#define PT_BLOCKER_SEM ((atomic_int *)-1)
#define PT_BLOCKER_IO ((atomic_int *)-2)
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -79,10 +80,11 @@ enum PosixThreadStatus {
#define POSIXTHREAD_CONTAINER(e) DLL_CONTAINER(struct PosixThread, list, e)
struct PosixThread {
int pt_flags; // 0x00: see PT_* constants
_Atomic(int) pt_canceled; // 0x04: thread has bad beliefs
int pt_flags; // 0x00: see PT_* constants
atomic_int pt_canceled; // 0x04: thread has bad beliefs
_Atomic(enum PosixThreadStatus) pt_status;
_Atomic(int) ptid; // transitions 0 → tid
atomic_int ptid; // transitions 0 → tid
atomic_int pt_refs; // negative means free
void *(*pt_start)(void *); // creation callback
void *pt_arg; // start's parameter
void *pt_rc; // start's return value
@ -90,7 +92,7 @@ struct PosixThread {
struct CosmoTib *tib; // middle of tls allocation
struct Dll list; // list of threads
struct _pthread_cleanup_buffer *pt_cleanup;
_Atomic(_Atomic(int) *) pt_blocker;
_Atomic(atomic_int *) pt_blocker;
int64_t pt_semaphore;
intptr_t pt_iohandle;
void *pt_ioverlap;
@ -119,6 +121,7 @@ void _pthread_onfork_prepare(void);
void _pthread_ungarbage(void);
void _pthread_unkey(struct CosmoTib *);
void _pthread_unlock(void);
void _pthread_unref(struct PosixThread *);
void _pthread_unwind(struct PosixThread *);
void _pthread_zombify(struct PosixThread *);
@ -126,6 +129,10 @@ __funline pureconst struct PosixThread *_pthread_self(void) {
return (struct PosixThread *)__get_tls()->tib_pthread;
}
__funline void _pthread_ref(struct PosixThread *pt) {
atomic_fetch_add_explicit(&pt->pt_refs, 1, memory_order_relaxed);
}
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_THREAD_POSIXTHREAD_INTERNAL_H_ */