Add epoll and do more release readiness changes

This change also pays off some of the remaining technical debt with
stdio, file descriptors, and memory managemnt polyfills.
This commit is contained in:
Justine Tunney 2020-11-28 12:01:51 -08:00
parent a9ea949df8
commit 3e4fd4b0ad
271 changed files with 5706 additions and 1365 deletions

13
libc/nt/enum/afd.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef COSMOPOLITAN_LIBC_NT_ENUM_AFD_H_
#define COSMOPOLITAN_LIBC_NT_ENUM_AFD_H_
#define kNtAfdPollReceive 0x0001
#define kNtAfdPollReceiveExpedited 0x0002
#define kNtAfdPollSend 0x0004
#define kNtAfdPollDisconnect 0x0008
#define kNtAfdPollAbort 0x0010
#define kNtAfdPollLocalClose 0x0020
#define kNtAfdPollAccept 0x0080
#define kNtAfdPollConnectFail 0x0100
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_AFD_H_ */

View file

@ -1,13 +1,12 @@
#ifndef COSMOPOLITAN_LIBC_NT_ENUM_FILEMAPFLAGS_H_
#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMAPFLAGS_H_
/* Choose subset of NtPageFlags passed earlier. */
#define kNtFileMapCopy 0x00000001u
#define kNtFileMapWrite 0x00000002u
#define kNtFileMapRead 0x00000004u
#define kNtFileMapExecute 0x00000020u
#define kNtFileMapReserve 0x80000000u
#define kNtFileMapCopy 0x00000001u
#define kNtFileMapWrite 0x00000002u
#define kNtFileMapRead 0x00000004u
#define kNtFileMapExecute 0x00000020u
#define kNtFileMapReserve 0x80000000u
#define kNtFileMapTargetsInvalid 0x40000000u
#define kNtFileMapLargePages 0x20000000u
#define kNtFileMapLargePages 0x20000000u
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_FILEMAPFLAGS_H_ */

View file

@ -2,5 +2,6 @@
#define COSMOPOLITAN_LIBC_NT_ENUM_IOCTL_H_
#define kNtIoctlDiskGetDriveGeometry 0x00070000u
#define kNtIoctlAfdPoll 0x00012024u
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_IOCTL_H_ */

10
libc/nt/enum/keyedevent.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef COSMOPOLITAN_LIBC_NT_ENUM_KEYEDEVENT_H_
#define COSMOPOLITAN_LIBC_NT_ENUM_KEYEDEVENT_H_
#include "libc/nt/enum/accessmask.h"
#define kNtKeyedeventWait 0x00000001u
#define kNtKeyedeventWake 0x00000002u
#define kNtKeyedeventAllAccess \
(kNtStandardRightsRequired | kNtKeyedeventWait | kNtKeyedeventWake)
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_KEYEDEVENT_H_ */

7
libc/nt/enum/sio.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_NT_ENUM_SIO_H_
#define COSMOPOLITAN_LIBC_NT_ENUM_SIO_H_
#define kNtSioBspHandlePoll 0x4800001D
#define kNtSioBaseHandle 0x48000022
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_SIO_H_ */

View file

@ -2,79 +2,82 @@
#define COSMOPOLITAN_LIBC_NT_STATUS_H_
/* high two bits = {success,informational,warning,error} */
#define kNtStatusWait0 0x00000000 /* success statuses */
#define kNtStatusAbandonedWait0 0x00000080
#define kNtStatusUserApc 0x000000C0
#define kNtStatusTimeout 0x00000102
#define kNtStatusPending 0x00000103
#define kNtStatusGuardPageViolation 0x80000001 /* warning statuses */
#define kNtStatusDatatypeMisalignment 0x80000002
#define kNtStatusBreakpoint 0x80000003
#define kNtStatusSingleStep 0x80000004
#define kNtStatusLongjump 0x80000026
#define kNtStatusUnwindConsolidate 0x80000029
#define kNtStatusAccessViolation 0xC0000005 /* error statuses */
#define kNtStatusInPageError 0xC0000006
#define kNtStatusInvalidHandle 0xC0000008
#define kNtStatusInvalidParameter 0xC000000D
#define kNtStatusNoMemory 0xC0000017
#define kNtStatusIllegalInstruction 0xC000001D
#define kNtStatusNoncontinuableException 0xC0000025
#define kNtStatusInvalidDisposition 0xC0000026
#define kNtStatusArrayBoundsExceeded 0xC000008C
#define kNtStatusFloatDenormalOperand 0xC000008D
#define kNtStatusFloatDivideByZero 0xC000008E
#define kNtStatusFloatInexactResult 0xC000008F
#define kNtStatusFloatInvalidOperation 0xC0000090
#define kNtStatusFloatOverflow 0xC0000091
#define kNtStatusFloatStackCheck 0xC0000092
#define kNtStatusFloatUnderflow 0xC0000093
#define kNtStatusIntegerDivideBYZero 0xC0000094
#define kNtStatusIntegerOverflow 0xC0000095
#define kNtStatusPrivilegedInstruction 0xC0000096
#define kNtStatusStackOverflow 0xC00000FD
#define kNtStatusDllNotFound 0xC0000135
#define kNtStatusOrdinalNotFound 0xC0000138
#define kNtStatusEntrypointNotFound 0xC0000139
#define kNtStatusControlCExit 0xC000013A
#define kNtStatusDllInitFailed 0xC0000142
#define kNtStatusFloatMultipleFaults 0xC00002B4
#define kNtStatusFloatMultipleTraps 0xC00002B5
#define kNtStatusRegNatConsumption 0xC00002C9
#define kNtStatusHeapCorruption 0xC0000374
#define kNtStatusStackBufferOverrun 0xC0000409
#define kNtStatusInvalidCruntimeParameter 0xC0000417
#define kNtStatusAssertionFailure 0xC0000420
#define kNtStatusEnclaveViolation 0xC00004A2
#define kNtStatusSegmentNotification 0x40000005
#define kNtStatusFatalAppExit 0x40000015
/* statuses for the debugger facility */
#define kNtDbgExceptionHandled 0x00010001
#define kNtDbgContinue 0x00010002
#define kNtDbgReplyLater 0x40010001
#define kNtDbgTerminateThread 0x40010003
#define kNtDbgTerminateProcess 0x40010004
#define kNtDbgControlC 0x40010005
#define kNtDbgPrintexceptionC 0x40010006
#define kNtDbgRipexception 0x40010007
#define kNtDbgControlBreak 0x40010008
#define kNtDbgCommandException 0x40010009
#define kNtDbgPrintexceptionWideC 0x4001000A
#define kNtDbgExceptionNotHandled 0x80010001
#define kNtStillActive kNtStatusPending
#define kNtStatusSuccess 0x00000000u /* success statuses */
#define kNtStatusWait0 0x00000000u
#define kNtStatusAbandonedWait0 0x00000080u
#define kNtStatusUserApc 0x000000C0u
#define kNtStatusTimeout 0x00000102u
#define kNtStatusPending 0x00000103u
#define kNtStatusGuardPageViolation 0x80000001u /* warning statuses */
#define kNtStatusDatatypeMisalignment 0x80000002u
#define kNtStatusBreakpoint 0x80000003u
#define kNtStatusSingleStep 0x80000004u
#define kNtStatusLongjump 0x80000026u
#define kNtStatusUnwindConsolidate 0x80000029u
#define kNtStatusAccessViolation 0xC0000005u /* error statuses */
#define kNtStatusInPageError 0xC0000006u
#define kNtStatusInvalidHandle 0xC0000008u
#define kNtStatusInvalidParameter 0xC000000Du
#define kNtStatusNoMemory 0xC0000017u
#define kNtStatusIllegalInstruction 0xC000001Du
#define kNtStatusNoncontinuableException 0xC0000025u
#define kNtStatusInvalidDisposition 0xC0000026u
#define kNtStatusArrayBoundsExceeded 0xC000008Cu
#define kNtStatusFloatDenormalOperand 0xC000008Du
#define kNtStatusFloatDivideByZero 0xC000008Eu
#define kNtStatusFloatInexactResult 0xC000008Fu
#define kNtStatusFloatInvalidOperation 0xC0000090u
#define kNtStatusFloatOverflow 0xC0000091u
#define kNtStatusFloatStackCheck 0xC0000092u
#define kNtStatusFloatUnderflow 0xC0000093u
#define kNtStatusIntegerDivideBYZero 0xC0000094u
#define kNtStatusIntegerOverflow 0xC0000095u
#define kNtStatusPrivilegedInstruction 0xC0000096u
#define kNtStatusStackOverflow 0xC00000FDu
#define kNtStatusDllNotFound 0xC0000135u
#define kNtStatusOrdinalNotFound 0xC0000138u
#define kNtStatusEntrypointNotFound 0xC0000139u
#define kNtStatusControlCExit 0xC000013Au
#define kNtStatusDllInitFailed 0xC0000142u
#define kNtStatusFloatMultipleFaults 0xC00002B4u
#define kNtStatusFloatMultipleTraps 0xC00002B5u
#define kNtStatusRegNatConsumption 0xC00002C9u
#define kNtStatusHeapCorruption 0xC0000374u
#define kNtStatusStackBufferOverrun 0xC0000409u
#define kNtStatusInvalidCruntimeParameter 0xC0000417u
#define kNtStatusAssertionFailure 0xC0000420u
#define kNtStatusEnclaveViolation 0xC00004A2u
#define kNtStatusSegmentNotification 0x40000005u
#define kNtStatusFatalAppExit 0x40000015u
#define kNtStatusNotFound 0xC0000225u
#define kNtStatusCancelled 0xC0000120u
#define kNtDbgExceptionHandled 0x00010001u
#define kNtDbgContinue 0x00010002u
#define kNtDbgReplyLater 0x40010001u
#define kNtDbgTerminateThread 0x40010003u
#define kNtDbgTerminateProcess 0x40010004u
#define kNtDbgControlC 0x40010005u
#define kNtDbgPrintexceptionC 0x40010006u
#define kNtDbgRipexception 0x40010007u
#define kNtDbgControlBreak 0x40010008u
#define kNtDbgCommandException 0x40010009u
#define kNtDbgPrintexceptionWideC 0x4001000Au
#define kNtDbgExceptionNotHandled 0x80010001u
#define kNtStillActive kNtStatusPending
#if !(__ASSEMBLER__ + __LINKER__ + 0)
typedef uint32_t NtStatus;
forceinline int NtSeverity(NtStatus s) { return (unsigned)s >> 30; }
forceinline bool32 NtSuccess(NtStatus s) { return NtSeverity(s) == 0; }
forceinline bool32 NtInformation(NtStatus s) { return NtSeverity(s) == 1; }
forceinline bool32 NtWarning(NtStatus s) { return NtSeverity(s) == 2; }
forceinline bool32 NtError(NtStatus s) { return NtSeverity(s) == 3; }
forceinline int NtCode(NtStatus s) { return s & 0xffff; }
forceinline int NtFacility(NtStatus s) { return (s >> 16) & 0xfff; }
forceinline int NtFacilityCode(NtStatus s) { return s & 0x0FFFFFFF; }
#define NtSuccess(s) ((NtStatus)(s) >= 0)
#define NtInformation(s) (NtSeverity(s) == 1)
#define NtWarning(s) (NtSeverity(s) == 2)
#define NtError(s) (NtSeverity(s) == 3)
#define NtCode(s) ((NtStatus)(s)&0xffff)
#define NtSeverity(s) ((NtStatus)(s) >> 30)
#define NtFacility(s) (((NtStatus)(s) >> 16) & 0xfff)
#define NtFacilityCode(s) ((NtStatus)(s)&0x0FFFFFFF)
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_STATUS_H_ */