mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-20 09:30:31 +00:00
Improve synchronization
- Fix bugs in kDos2Errno definition - malloc() should now be thread safe - Fix bug in rollup.com header generator - Fix open(O_APPEND) on the New Technology - Fix select() on the New Technology and test it - Work towards refactoring i/o for thread safety - Socket reads and writes on NT now poll for signals - Work towards i/o completion ports on the New Technology - Make read() and write() intermittently check for signals - Blinkenlights keyboard i/o so much better on NT w/ poll() - You can now poll() files and sockets at the same time on NT - Fix bug in appendr() that manifests with dlmalloc footers off
This commit is contained in:
parent
233144b19d
commit
933411ba99
266 changed files with 8761 additions and 4344 deletions
|
@ -51,13 +51,13 @@
|
|||
#include "libc/sysv/consts/nr.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "third_party/dlmalloc/dlmalloc.internal.h"
|
||||
#include "third_party/dlmalloc/dlmalloc.h"
|
||||
|
||||
STATIC_YOINK("_init_asan");
|
||||
|
||||
#define ASAN_MORGUE_ITEMS 512
|
||||
#define ASAN_MORGUE_THRESHOLD 65536 // morgue memory O(ITEMS*THRESHOLD)
|
||||
#define ASAN_TRACE_ITEMS 16 // backtrace limit on malloc origin
|
||||
#define ASAN_TRACE_ITEMS 16 // backtrace limit on malloc origin
|
||||
|
||||
/**
|
||||
* @fileoverview Cosmopolitan Address Sanitizer Runtime.
|
||||
|
@ -177,8 +177,7 @@ static uint64_t __asan_roundup2pow(uint64_t x) {
|
|||
static char *__asan_utf8cpy(char *p, unsigned c) {
|
||||
uint64_t z;
|
||||
z = tpenc(c);
|
||||
do
|
||||
*p++ = z;
|
||||
do *p++ = z;
|
||||
while ((z >>= 8));
|
||||
return p;
|
||||
}
|
||||
|
@ -922,8 +921,7 @@ static void __asan_trace(struct AsanTrace *bt, const struct StackFrame *bp) {
|
|||
if (!__asan_checka(SHADOW(bp), sizeof(*bp) >> 3).kind) {
|
||||
addr = bp->addr;
|
||||
if (addr == weakaddr("__gc") && weakaddr("__gc")) {
|
||||
do
|
||||
--gi;
|
||||
do --gi;
|
||||
while ((addr = garbage->p[gi].ret) == weakaddr("__gc"));
|
||||
}
|
||||
bt->p[i] = addr;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/cmpxchg.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/lockcmpxchg.h"
|
||||
|
@ -32,6 +33,8 @@ relegated wontreturn void __assert_fail(const char *expr, const char *file,
|
|||
int line) {
|
||||
int rc;
|
||||
static bool noreentry;
|
||||
__strace = 0;
|
||||
g_ftrace = 0;
|
||||
kprintf("%s:%d: assert(%s) failed%n", file, line, expr);
|
||||
if (_lockcmpxchg(&noreentry, false, true)) {
|
||||
if (weaken(__die)) {
|
||||
|
|
|
@ -16,12 +16,14 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(CloseHandle) *const __imp_CloseHandle __msabi;
|
||||
__msabi extern typeof(CloseHandle) *const __imp_CloseHandle;
|
||||
|
||||
/**
|
||||
* Closes an open object handle.
|
||||
|
@ -30,7 +32,10 @@ extern typeof(CloseHandle) *const __imp_CloseHandle __msabi;
|
|||
textwindows bool32 CloseHandle(int64_t hObject) {
|
||||
bool32 ok;
|
||||
ok = __imp_CloseHandle(hObject);
|
||||
if (!ok) __winerr();
|
||||
if (!ok) {
|
||||
__winerr();
|
||||
if (weaken(__die)) weaken(__die)();
|
||||
}
|
||||
STRACE("CloseHandle(%ld) → %hhhd% m", hObject, ok);
|
||||
return ok;
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(CreateDirectory) *const __imp_CreateDirectoryW __msabi;
|
||||
__msabi extern typeof(CreateDirectory) *const __imp_CreateDirectoryW;
|
||||
|
||||
/**
|
||||
* Creates directory on the New Technology.
|
||||
|
@ -35,7 +36,7 @@ CreateDirectory(const char16_t *lpPathName,
|
|||
bool32 ok;
|
||||
ok = __imp_CreateDirectoryW(lpPathName, lpSecurityAttributes);
|
||||
if (!ok) __winerr();
|
||||
STRACE("CreateDirectory(%#hs, %p) → %hhhd% m", lpPathName,
|
||||
lpSecurityAttributes, ok);
|
||||
STRACE("CreateDirectory(%#hs, %s) → %hhhd% m", lpPathName,
|
||||
DescribeNtSecurityAttributes(lpSecurityAttributes), ok);
|
||||
return ok;
|
||||
}
|
||||
|
|
|
@ -20,27 +20,9 @@
|
|||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/createfile.h"
|
||||
#include "libc/nt/enum/creationdisposition.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(CreateFile) *const __imp_CreateFileW __msabi;
|
||||
|
||||
static const char *DescribeDisposition(int x) {
|
||||
switch (x) {
|
||||
case kNtCreateNew:
|
||||
return "kNtCreateNew";
|
||||
case kNtCreateAlways:
|
||||
return "kNtCreateAlways";
|
||||
case kNtOpenExisting:
|
||||
return "kNtOpenExisting";
|
||||
case kNtOpenAlways:
|
||||
return "kNtOpenAlways";
|
||||
case kNtTruncateExisting:
|
||||
return "kNtTruncateExisting";
|
||||
default:
|
||||
return "wut";
|
||||
}
|
||||
}
|
||||
__msabi extern typeof(CreateFile) *const __imp_CreateFileW;
|
||||
|
||||
/**
|
||||
* Opens file on the New Technology.
|
||||
|
@ -58,10 +40,11 @@ textwindows int64_t CreateFile(
|
|||
opt_lpSecurityAttributes, dwCreationDisposition,
|
||||
dwFlagsAndAttributes, opt_hTemplateFile);
|
||||
if (hHandle == -1) __winerr();
|
||||
STRACE("CreateFile(%#hs, %s, %s, %p, %s, %s, %ld) → %ld% m", lpFileName,
|
||||
STRACE("CreateFile(%#hs, %s, %s, %s, %s, %s, %ld) → %ld% m", lpFileName,
|
||||
DescribeNtFileAccessFlags(dwDesiredAccess),
|
||||
DescribeNtFileShareFlags(dwShareMode), opt_lpSecurityAttributes,
|
||||
DescribeDisposition(dwCreationDisposition),
|
||||
DescribeNtFileShareFlags(dwShareMode),
|
||||
DescribeNtSecurityAttributes(opt_lpSecurityAttributes),
|
||||
DescribeNtCreationDisposition(dwCreationDisposition),
|
||||
DescribeNtFileFlagsAndAttributes(dwFlagsAndAttributes),
|
||||
opt_hTemplateFile, hHandle);
|
||||
return hHandle;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "libc/nt/struct/securityattributes.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(CreateFileMapping) *const __imp_CreateFileMappingW __msabi;
|
||||
__msabi extern typeof(CreateFileMapping) *const __imp_CreateFileMappingW;
|
||||
|
||||
/**
|
||||
* Creates file mapping object on the New Technology.
|
||||
|
@ -43,7 +43,8 @@ textwindows int64_t CreateFileMapping(
|
|||
flProtect, dwMaximumSizeHigh,
|
||||
dwMaximumSizeLow, opt_lpName);
|
||||
if (!hHandle) __winerr();
|
||||
STRACE("CreateFileMapping(%ld, %s, max:%'zu, name:%#hs) → %ld% m", opt_hFile,
|
||||
STRACE("CreateFileMapping(%ld, %s, %s, %'zu, %#hs) → %ld% m", opt_hFile,
|
||||
DescribeNtSecurityAttributes(opt_lpFileMappingAttributes),
|
||||
DescribeNtPageFlags(flProtect),
|
||||
(uint64_t)dwMaximumSizeHigh << 32 | dwMaximumSizeLow, opt_lpName,
|
||||
hHandle);
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#include "libc/nt/memory.h"
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
|
||||
extern typeof(CreateFileMappingNuma) *const
|
||||
__imp_CreateFileMappingNumaW __msabi;
|
||||
__msabi extern typeof(CreateFileMappingNuma) *const
|
||||
__imp_CreateFileMappingNumaW;
|
||||
|
||||
/**
|
||||
* Creates file mapping object on the New Technology.
|
||||
|
@ -44,8 +44,9 @@ textwindows int64_t CreateFileMappingNuma(
|
|||
opt_hFile, opt_lpFileMappingAttributes, flProtect, dwMaximumSizeHigh,
|
||||
dwMaximumSizeLow, opt_lpName, nndDesiredNumaNode);
|
||||
if (!hHandle) __winerr();
|
||||
STRACE("CreateFileMappingNuma(%ld, %s, max:%'zu, name:%#hs) → %ld% m",
|
||||
opt_hFile, DescribeNtPageFlags(flProtect),
|
||||
STRACE("CreateFileMappingNuma(%ld, %s, %s, %'zu, %#hs) → %ld% m", opt_hFile,
|
||||
DescribeNtSecurityAttributes(opt_lpFileMappingAttributes),
|
||||
DescribeNtPageFlags(flProtect),
|
||||
(uint64_t)dwMaximumSizeHigh << 32 | dwMaximumSizeLow, opt_lpName,
|
||||
hHandle);
|
||||
return hHandle;
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/ipc.h"
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(CreateNamedPipe) *const __imp_CreateNamedPipeW __msabi;
|
||||
__msabi extern typeof(CreateNamedPipe) *const __imp_CreateNamedPipeW;
|
||||
|
||||
/**
|
||||
* Creates pipe.
|
||||
|
@ -40,16 +41,10 @@ textwindows int64_t CreateNamedPipe(
|
|||
nMaxInstances, nOutBufferSize, nInBufferSize,
|
||||
nDefaultTimeOutMs, opt_lpSecurityAttributes);
|
||||
if (hServer == -1) __winerr();
|
||||
STRACE("CreateNamedPipe(%#hs,"
|
||||
" dwOpenMode=%u,"
|
||||
" dwPipeMode=%u,"
|
||||
" nMaxInstances=%u,"
|
||||
" nOutBufferSize=%'u,"
|
||||
" nInBufferSize=%'u,"
|
||||
" nDefaultTimeOutMs=%'u,"
|
||||
" lpSecurity=%p) → "
|
||||
"%ld% m",
|
||||
lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize,
|
||||
nInBufferSize, nDefaultTimeOutMs, opt_lpSecurityAttributes, hServer);
|
||||
STRACE("CreateNamedPipe(%#hs, %s, %s, %u, %'u, %'u, %'u, %s) → %ld% m",
|
||||
lpName, DescribeNtPipeOpenFlags(dwOpenMode),
|
||||
DescribeNtPipeModeFlags(dwPipeMode), nMaxInstances, nOutBufferSize,
|
||||
nInBufferSize, nDefaultTimeOutMs,
|
||||
DescribeNtSecurityAttributes(opt_lpSecurityAttributes), hServer);
|
||||
return hServer;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/ipc.h"
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(CreatePipe) *const __imp_CreatePipe __msabi;
|
||||
__msabi extern typeof(CreatePipe) *const __imp_CreatePipe;
|
||||
|
||||
/**
|
||||
* Creates anonymous pipe.
|
||||
|
@ -35,7 +36,8 @@ textwindows bool32 CreatePipe(
|
|||
ok = __imp_CreatePipe(out_hReadPipe, out_hWritePipe, opt_lpPipeAttributes,
|
||||
nSize);
|
||||
if (!ok) __winerr();
|
||||
STRACE("CreatePipe([%ld], [%ld], %p, %'zu) → %hhhd% m", *out_hReadPipe,
|
||||
*out_hWritePipe, opt_lpPipeAttributes, nSize, ok);
|
||||
STRACE("CreatePipe([%ld], [%ld], %s, %'zu) → %hhhd% m", *out_hReadPipe,
|
||||
*out_hWritePipe, DescribeNtSecurityAttributes(opt_lpPipeAttributes),
|
||||
nSize, ok);
|
||||
return ok;
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(CreateProcess) *const __imp_CreateProcessW __msabi;
|
||||
__msabi extern typeof(CreateProcess) *const __imp_CreateProcessW;
|
||||
|
||||
/**
|
||||
* Creates process on the New Technology.
|
||||
|
@ -44,10 +45,11 @@ CreateProcess(const char16_t *opt_lpApplicationName, char16_t *lpCommandLine,
|
|||
opt_out_lpProcessInformation);
|
||||
if (!ok) __winerr();
|
||||
STRACE(
|
||||
"CreateFile(%#hs, %#hs, %p, %p, %hhhd, %u, %p, %#hs, %p, %p) → %hhhd% m",
|
||||
opt_lpApplicationName, lpCommandLine, opt_lpProcessAttributes,
|
||||
opt_lpThreadAttributes, bInheritHandles, dwCreationFlags,
|
||||
opt_lpEnvironment, opt_lpCurrentDirectory, lpStartupInfo,
|
||||
"CreateFile(%#hs, %#hs, %s, %s, %hhhd, %u, %p, %#hs, %p, %p) → %hhhd% m",
|
||||
opt_lpApplicationName, lpCommandLine,
|
||||
DescribeNtSecurityAttributes(opt_lpProcessAttributes),
|
||||
DescribeNtSecurityAttributes(opt_lpThreadAttributes), bInheritHandles,
|
||||
dwCreationFlags, opt_lpEnvironment, opt_lpCurrentDirectory, lpStartupInfo,
|
||||
opt_out_lpProcessInformation, ok);
|
||||
return ok;
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
#include "libc/nt/thread.h"
|
||||
|
||||
extern typeof(CreateThread) *const __imp_CreateThread __msabi;
|
||||
__msabi extern typeof(CreateThread) *const __imp_CreateThread;
|
||||
|
||||
/**
|
||||
* Opens file on the New Technology.
|
||||
|
@ -38,9 +39,8 @@ textwindows int64_t CreateThread(
|
|||
hHandle = __imp_CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress,
|
||||
lpParameter, dwCreationFlags, opt_lpThreadId);
|
||||
if (hHandle == -1) __winerr();
|
||||
STRACE("CreateThread(sec=%p, stack=%'zu, start=%p, param=%p, flags=%s, "
|
||||
"id=%p) → %ld% m",
|
||||
lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter,
|
||||
dwCreationFlags, opt_lpThreadId, hHandle);
|
||||
STRACE("CreateThread(%s, %'zu, %p, %p, %s, %p) → %ld% m",
|
||||
DescribeNtSecurityAttributes(lpThreadAttributes), dwStackSize,
|
||||
lpStartAddress, lpParameter, dwCreationFlags, opt_lpThreadId, hHandle);
|
||||
return hHandle;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "libc/nt/memory.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(DeleteFile) *const __imp_DeleteFileW __msabi;
|
||||
__msabi extern typeof(DeleteFile) *const __imp_DeleteFileW;
|
||||
|
||||
/**
|
||||
* Deletes existing file.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define COSMOPOLITAN_LIBC_INTRIN_DESCRIBEFLAGS_INTERNAL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
|
||||
struct thatispacked DescribeFlags {
|
||||
unsigned flag;
|
||||
|
@ -16,14 +17,19 @@ const char *DescribeProtFlags(int);
|
|||
const char *DescribeRemapFlags(int);
|
||||
|
||||
const char *DescribeNtPageFlags(uint32_t);
|
||||
const char *DescribeNtStartFlags(uint32_t);
|
||||
const char *DescribeNtFileMapFlags(uint32_t);
|
||||
const char *DescribeNtFiletypeFlags(uint32_t);
|
||||
const char *DescribeNtFileFlagsAndAttributes(uint32_t);
|
||||
const char *DescribeNtPipeOpenFlags(uint32_t);
|
||||
const char *DescribeNtPipeModeFlags(uint32_t);
|
||||
const char *DescribeNtFileShareFlags(uint32_t);
|
||||
const char *DescribeNtFileAccessFlags(uint32_t);
|
||||
const char *DescribeNtProcessAccessFlags(uint32_t);
|
||||
const char *DescribeNtCreationDisposition(uint32_t);
|
||||
const char *DescribeNtConsoleModeInputFlags(uint32_t);
|
||||
const char *DescribeNtConsoleModeOutputFlags(uint32_t);
|
||||
const char *DescribeNtFileFlagsAndAttributes(uint32_t);
|
||||
const char *DescribeNtSecurityAttributes(struct NtSecurityAttributes *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
37
libc/intrin/describentcreationdisposition.greg.c
Normal file
37
libc/intrin/describentcreationdisposition.greg.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/enum/creationdisposition.h"
|
||||
|
||||
const char *DescribeNtCreationDisposition(uint32_t x) {
|
||||
switch (x) {
|
||||
case kNtCreateNew:
|
||||
return "kNtCreateNew";
|
||||
case kNtCreateAlways:
|
||||
return "kNtCreateAlways";
|
||||
case kNtOpenExisting:
|
||||
return "kNtOpenExisting";
|
||||
case kNtOpenAlways:
|
||||
return "kNtOpenAlways";
|
||||
case kNtTruncateExisting:
|
||||
return "kNtTruncateExisting";
|
||||
default:
|
||||
return "wut";
|
||||
}
|
||||
}
|
|
@ -64,7 +64,7 @@ static const struct DescribeFlags kFileAccessflags[] = {
|
|||
};
|
||||
|
||||
const char *DescribeNtFileAccessFlags(uint32_t x) {
|
||||
static char ntfileaccessflags[256];
|
||||
static char ntfileaccessflags[512];
|
||||
return DescribeFlags(ntfileaccessflags, sizeof(ntfileaccessflags),
|
||||
kFileAccessflags, ARRAYLEN(kFileAccessflags), "kNt", x);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,10 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/enum/fileflagandattributes.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
static const struct DescribeFlags kFileFlags[] = {
|
||||
{kNtFileAttributeReadonly, "AttributeReadonly"}, //
|
||||
|
|
39
libc/intrin/describentpipemodeflags.greg.c
Normal file
39
libc/intrin/describentpipemodeflags.greg.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/enum/filemapflags.h"
|
||||
#include "libc/nt/ipc.h"
|
||||
|
||||
static const struct DescribeFlags kPipeModeFlags[] = {
|
||||
{kNtPipeNowait, "Nowait"}, // 0x0000000001
|
||||
{kNtPipeReadmodeMessage, "ReadmodeMessage"}, // 0x0000000002
|
||||
{kNtPipeTypeMessage, "TypeMessage"}, // 0x0000000004
|
||||
{kNtPipeRejectRemoteClients, "RejectRemoteClients"}, // 0x0000000008
|
||||
//{kNtPipeAcceptRemoteClients, "AcceptRemoteClients"}, // 0x00000000
|
||||
//{kNtPipeReadmodeByte, "ReadmodeByte"}, // 0x00000000
|
||||
//{kNtPipeWait, "Wait"}, // 0x00000000
|
||||
//{kNtPipeTypeByte, "TypeByte"}, // 0x00000000
|
||||
};
|
||||
|
||||
const char *DescribeNtPipeModeFlags(uint32_t x) {
|
||||
static char pipemodeflags[64];
|
||||
return DescribeFlags(pipemodeflags, sizeof(pipemodeflags), kPipeModeFlags,
|
||||
ARRAYLEN(kPipeModeFlags), "kNtPipe", x);
|
||||
}
|
34
libc/intrin/describentpipeopenflags.greg.c
Normal file
34
libc/intrin/describentpipeopenflags.greg.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/enum/filemapflags.h"
|
||||
#include "libc/nt/ipc.h"
|
||||
|
||||
static const struct DescribeFlags kPipeOpenFlags[] = {
|
||||
{kNtPipeAccessDuplex, "Duplex"}, // 0x00000003
|
||||
{kNtPipeAccessOutbound, "Outbound"}, // 0x00000002
|
||||
{kNtPipeAccessInbound, "Inbound"}, // 0x00000001
|
||||
};
|
||||
|
||||
const char *DescribeNtPipeOpenFlags(uint32_t x) {
|
||||
static char pipeopenflags[64];
|
||||
return DescribeFlags(pipeopenflags, sizeof(pipeopenflags), kPipeOpenFlags,
|
||||
ARRAYLEN(kPipeOpenFlags), "kNtPipeAccess", x);
|
||||
}
|
26
libc/intrin/describentsecurityattributes.greg.c
Normal file
26
libc/intrin/describentsecurityattributes.greg.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
|
||||
const char *DescribeNtSecurityAttributes(struct NtSecurityAttributes *p) {
|
||||
if (p == &kNtIsInheritable) return "&kNtIsInheritable";
|
||||
return "0";
|
||||
}
|
45
libc/intrin/describentstartflags.greg.c
Normal file
45
libc/intrin/describentstartflags.greg.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/enum/startf.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
||||
static const struct DescribeFlags kNtStartFlags[] = {
|
||||
{kNtStartfUseshowwindow, "Useshowwindow"}, //
|
||||
{kNtStartfUsesize, "Usesize"}, //
|
||||
{kNtStartfUseposition, "Useposition"}, //
|
||||
{kNtStartfUsecountchars, "Usecountchars"}, //
|
||||
{kNtStartfUsefillattribute, "Usefillattribute"}, //
|
||||
{kNtStartfRunfullscreen, "Runfullscreen"}, //
|
||||
{kNtStartfForceonfeedback, "Forceonfeedback"}, //
|
||||
{kNtStartfForceofffeedback, "Forceofffeedback"}, //
|
||||
{kNtStartfUsestdhandles, "Usestdhandles"}, //
|
||||
{kNtStartfUsehotkey, "Usehotkey"}, //
|
||||
{kNtStartfTitleislinkname, "Titleislinkname"}, //
|
||||
{kNtStartfTitleisappid, "Titleisappid"}, //
|
||||
{kNtStartfPreventpinning, "Preventpinning"}, //
|
||||
{kNtStartfUntrustedsource, "Untrustedsource"}, //
|
||||
};
|
||||
|
||||
const char *DescribeNtStartFlags(uint32_t x) {
|
||||
static char startflags[128];
|
||||
return DescribeFlags(startflags, sizeof(startflags), kNtStartFlags,
|
||||
ARRAYLEN(kNtStartFlags), "kNtStartf", x);
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
#include "libc/nt/struct/overlapped.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(DeviceIoControl) *const __imp_DeviceIoControl __msabi;
|
||||
__msabi extern typeof(DeviceIoControl) *const __imp_DeviceIoControl;
|
||||
|
||||
/**
|
||||
* Does device file stuff on the New Technology.
|
||||
|
|
|
@ -17,16 +17,10 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/dos2errno.internal.h"
|
||||
#include "libc/nt/errors.h"
|
||||
#include "libc/sock/sock.h"
|
||||
|
||||
struct thatispacked Dos2Errno {
|
||||
uint16_t doscode;
|
||||
int32_t systemv;
|
||||
};
|
||||
|
||||
extern const struct Dos2Errno kDos2Errno[];
|
||||
|
||||
/**
|
||||
* Translates Windows error using superset of consts.sh.
|
||||
*
|
||||
|
|
15
libc/intrin/dos2errno.internal.h
Normal file
15
libc/intrin/dos2errno.internal.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_INTRIN_DOS2ERRNO_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_DOS2ERRNO_INTERNAL_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct thatispacked Dos2Errno {
|
||||
uint16_t doscode;
|
||||
int32_t systemv;
|
||||
};
|
||||
|
||||
extern const struct Dos2Errno kDos2Errno[];
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_DOS2ERRNO_INTERNAL_H_ */
|
|
@ -16,35 +16,21 @@
|
|||
│ 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/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/lockcmpxchg.h"
|
||||
#include "libc/intrin/spinlock.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
__msabi extern typeof(FindClose) *const __imp_FindClose;
|
||||
|
||||
/**
|
||||
* Acquires spinlock.
|
||||
* Finds more files in directory.
|
||||
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
||||
*/
|
||||
void cthread_spinlock(cthread_spinlock_t *lock) {
|
||||
#if 0
|
||||
// TODO(jart): possibly reenable for !NDEBUG when we have TLS
|
||||
int me = gettid();
|
||||
if (lock->x && lock->owner == me) {
|
||||
assert(!"cosmo spinlock not intended to be reentrant");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
do
|
||||
while (lock->x) asm("pause");
|
||||
while (!_lockcmpxchg(&lock->x, false, true));
|
||||
#if 0
|
||||
lock->owner = me;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases spinlock.
|
||||
*/
|
||||
void cthread_spunlock(cthread_spinlock_t *lock) {
|
||||
lock->x = false;
|
||||
textwindows bool32 FindClose(int64_t hFindFile) {
|
||||
bool32 ok;
|
||||
ok = __imp_FindClose(hFindFile);
|
||||
if (!ok) __winerr();
|
||||
STRACE("FindClose(%ld) → %hhhd% m", hFindFile, ok);
|
||||
return ok;
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
#include "libc/nt/struct/win32finddata.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(FindFirstFile) *const __imp_FindFirstFileW __msabi;
|
||||
__msabi extern typeof(FindFirstFile) *const __imp_FindFirstFileW;
|
||||
|
||||
/**
|
||||
* Finds first file in directory.
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/errors.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/memory.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/struct/win32finddata.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(FindNextFile) *const __imp_FindNextFileW __msabi;
|
||||
__msabi extern typeof(FindNextFile) *const __imp_FindNextFileW;
|
||||
|
||||
/**
|
||||
* Finds more files in directory.
|
||||
|
@ -45,8 +47,8 @@ textwindows bool32 FindNextFile(int64_t hFindFile,
|
|||
DescribeNtFileFlagsAndAttributes(out_lpFindFileData->dwFileAttributes),
|
||||
DescribeNtFiletypeFlags(out_lpFindFileData->dwFileType), ok);
|
||||
} else {
|
||||
__winerr();
|
||||
STRACE("FindNextFile(%ld, [n/a]) → %hhhd% m", hFindFile, ok);
|
||||
if (GetLastError() != kNtErrorNoMoreFiles) __winerr();
|
||||
STRACE("FindNextFile(%ld) → %hhhd% m", hFindFile, ok);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/nt/files.h"
|
||||
|
||||
extern typeof(FlushFileBuffers) *const __imp_FlushFileBuffers __msabi;
|
||||
__msabi extern typeof(FlushFileBuffers) *const __imp_FlushFileBuffers;
|
||||
|
||||
/**
|
||||
* Flushes buffers of specified file to disk.
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/nt/memory.h"
|
||||
|
||||
extern typeof(FlushViewOfFile) *const __imp_FlushViewOfFile __msabi;
|
||||
__msabi extern typeof(FlushViewOfFile) *const __imp_FlushViewOfFile;
|
||||
|
||||
/**
|
||||
* Syncs memory created by MapViewOfFileEx().
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include "libc/nt/console.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(GenerateConsoleCtrlEvent) *const
|
||||
__imp_GenerateConsoleCtrlEvent __msabi;
|
||||
__msabi extern typeof(GenerateConsoleCtrlEvent) *const
|
||||
__imp_GenerateConsoleCtrlEvent;
|
||||
|
||||
/**
|
||||
* Sends signal to process group that shares console w/ calling process.
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW __msabi;
|
||||
__msabi extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW;
|
||||
|
||||
/**
|
||||
* Gets file info on the New Technology.
|
||||
|
|
|
@ -65,6 +65,7 @@ o/$(MODE)/libc/intrin/kprintf.greg.o: \
|
|||
$(NO_MAGIC)
|
||||
|
||||
o/$(MODE)/libc/intrin/createfile.greg.o \
|
||||
o/$(MODE)/libc/intrin/reopenfile.greg.o \
|
||||
o/$(MODE)/libc/intrin/deletefile.greg.o \
|
||||
o/$(MODE)/libc/intrin/createpipe.greg.o \
|
||||
o/$(MODE)/libc/intrin/closehandle.greg.o \
|
||||
|
|
|
@ -29,6 +29,71 @@
|
|||
.section .rodata
|
||||
.underrun
|
||||
kDos2Errno:
|
||||
// .e kNtErrorInvalidFunction,ENOSYS # in consts.sh
|
||||
// .e kNtErrorFileNotFound,ENOENT # in consts.sh
|
||||
// .e kNtErrorPathNotFound,ENOTDIR # in consts.sh
|
||||
// .e kNtErrorTooManyOpenFiles,EMFILE # in consts.sh
|
||||
// .e kNtErrorAccessDenied,EACCES # in consts.sh
|
||||
// .e kNtErrorInvalidHandle,EBADF # in consts.sh
|
||||
// .e kNtErrorInvalidAccess,EPERM # in consts.sh
|
||||
// .e kNtErrorSeek,ESPIPE # in consts.sh
|
||||
// .e kNtErrorNotDosDisk,ENOTBLK # in consts.sh
|
||||
// .e kNtErrorFileExists,EEXIST # in consts.sh
|
||||
// .e kNtErrorInvalidParameter,EINVAL # in consts.sh
|
||||
// .e kNtErrorOutofmemory,ENOMEM # in consts.sh
|
||||
// .e kNtErrorBrokenPipe,EPIPE # in consts.sh
|
||||
// .e kNtErrorWaitNoChildren,ECHILD # in consts.sh
|
||||
// .e kNtErrorPathBusy,ETXTBSY # in consts.sh
|
||||
// .e kNtErrorBusy,EBUSY # in consts.sh
|
||||
// .e kNtErrorAlreadyExists,EEXIST # in consts.sh
|
||||
// .e kNtErrorBadExeFormat,ENOEXEC # in consts.sh
|
||||
// .e kNtErrorFileTooLarge,EFBIG # in consts.sh
|
||||
// .e kNtErrorTooManyDescriptors,ENFILE # in consts.sh
|
||||
// .e kNtErrorDirectoryNotSupported,EISDIR # in consts.sh
|
||||
// .e kNtErrorInvalidAddress,EFAULT # in consts.sh
|
||||
// .e kNtErrorThreadNotInProcess,ESRCH # in consts.sh
|
||||
// .e kNtErrorNoMediaInDrive,ENXIO # in consts.sh
|
||||
// .e kNtErrorIoDevice,EIO # in consts.sh
|
||||
// .e kNtErrorSerialNoDevice,ENOTTY # in consts.sh
|
||||
// .e kNtErrorPossibleDeadlock,EDEADLK # in consts.sh
|
||||
// .e kNtErrorBadDevice,ENODEV # in consts.sh
|
||||
// .e kNtErrorInvalidCommandLine,E2BIG # in consts.sh
|
||||
// .e kNtErrorFileReadOnly,EROFS # in consts.sh
|
||||
// .e kNtErrorNoData,ENODATA # in consts.sh
|
||||
// .e WSAEPROCLIM,EPROCLIM # in consts.sh
|
||||
// .e WSAESHUTDOWN,ESHUTDOWN # in consts.sh
|
||||
// .e WSAEINPROGRESS,EINPROGRESS # in consts.sh
|
||||
// .e WSAENETDOWN,ENETDOWN # in consts.sh
|
||||
// .e WSAENETUNREACH,ENETUNREACH # in consts.sh
|
||||
// .e WSAENETRESET,ENETRESET # in consts.sh
|
||||
// .e WSAEUSERS,EUSERS # in consts.sh
|
||||
// .e WSAENOTSOCK,ENOTSOCK # in consts.sh
|
||||
// .e WSAEDESTADDRREQ,EDESTADDRREQ # in consts.sh
|
||||
// .e WSAEMSGSIZE,EMSGSIZE # in consts.sh
|
||||
// .e WSAEPROTOTYPE,EPROTOTYPE # in consts.sh
|
||||
// .e WSAENOPROTOOPT,ENOPROTOOPT # in consts.sh
|
||||
// .e WSAEPROTONOSUPPORT,EPROTONOSUPPORT # in consts.sh
|
||||
// .e WSAESOCKTNOSUPPORT,ESOCKTNOSUPPORT # in consts.sh
|
||||
// .e WSAEOPNOTSUPP,ENOTSUP # in consts.sh
|
||||
// .e WSAEOPNOTSUPP,EOPNOTSUPP # in consts.sh
|
||||
// .e WSAEPFNOSUPPORT,EPFNOSUPPORT # in consts.sh
|
||||
// .e WSAEAFNOSUPPORT,EAFNOSUPPORT # in consts.sh
|
||||
// .e WSAEADDRINUSE,EADDRINUSE # in consts.sh
|
||||
// .e WSAEADDRNOTAVAIL,EADDRNOTAVAIL # in consts.sh
|
||||
// .e WSAECONNABORTED,ECONNABORTED # in consts.sh
|
||||
// .e WSAECONNRESET,ECONNRESET # in consts.sh
|
||||
// .e WSAENOBUFS,ENOBUFS # in consts.sh
|
||||
// .e WSAEISCONN,EISCONN # in consts.sh
|
||||
// .e WSAENOTCONN,ENOTCONN # in consts.sh
|
||||
// .e WSAESHUTDOWN,ESHUTDOWN # in consts.sh
|
||||
// .e WSAETOOMANYREFS,ETOOMANYREFS # in consts.sh
|
||||
// .e WSAETIMEDOUT,ETIMEDOUT # in consts.sh
|
||||
// .e WSAECONNREFUSED,ECONNREFUSED # in consts.sh
|
||||
// .e WSAEHOSTDOWN,EHOSTDOWN # in consts.sh
|
||||
// .e WSAEHOSTUNREACH,EHOSTUNREACH # in consts.sh
|
||||
// .e WSAEALREADY,EALREADY # in consts.sh
|
||||
// .e WSAESTALE,ESTALE # in consts.sh
|
||||
// .e WSAEREMOTE,EREMOTE # in consts.sh
|
||||
.e kNtErrorModNotFound,ENOSYS
|
||||
.e kNtErrorBadCommand,EACCES
|
||||
.e kNtErrorBadLength,EACCES
|
||||
|
@ -94,10 +159,8 @@ kDos2Errno:
|
|||
.e WSAEACCES,EACCES
|
||||
.e WSAEDISCON,EPIPE
|
||||
.e WSAEFAULT,EFAULT
|
||||
.e WSAEINPROGRESS,EBUSY
|
||||
.e WSAEINVAL,EINVAL
|
||||
.e WSAEPROCLIM,ENOMEM
|
||||
.e WSAESHUTDOWN,EPIPE
|
||||
.e WSANOTINITIALISED,ENETDOWN
|
||||
.e WSASYSNOTREADY,ENETDOWN
|
||||
.e WSAVERNOTSUPPORTED,ENOSYS
|
||||
|
|
25
libc/intrin/kntisinheritable.greg.c
Normal file
25
libc/intrin/kntisinheritable.greg.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nt/struct/securityattributes.h"
|
||||
|
||||
hidden const struct NtSecurityAttributes kNtIsInheritable = {
|
||||
sizeof(struct NtSecurityAttributes),
|
||||
NULL,
|
||||
true,
|
||||
};
|
|
@ -37,6 +37,7 @@
|
|||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -438,8 +439,7 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, va_list va,
|
|||
i = 0;
|
||||
m = (1 << base) - 1;
|
||||
if (hash && x) sign = hash;
|
||||
do
|
||||
z[i++ & 127] = abet[x & m];
|
||||
do z[i++ & 127] = abet[x & m];
|
||||
while ((x >>= base) || (pdot && i < prec));
|
||||
goto EmitNumber;
|
||||
|
||||
|
@ -487,17 +487,31 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, va_list va,
|
|||
}
|
||||
goto EmitChar;
|
||||
|
||||
case 'm':
|
||||
if (!(x = errno) && sign == ' ' /* && */
|
||||
/* (!IsWindows() || !__imp_GetLastError()) */) {
|
||||
case 'm': {
|
||||
int unixerr;
|
||||
uint32_t winerr;
|
||||
unixerr = errno;
|
||||
winerr = 0;
|
||||
if (IsWindows()) {
|
||||
if (type == 1 && weaken(WSAGetLastError)) {
|
||||
winerr = weaken(WSAGetLastError)();
|
||||
} else if (weaken(GetLastError)) {
|
||||
winerr = weaken(GetLastError)();
|
||||
}
|
||||
}
|
||||
if (!unixerr && sign == ' ') {
|
||||
break;
|
||||
} else if (weaken(strerror_r) &&
|
||||
!weaken(strerror_r)(x, z, sizeof(z))) {
|
||||
} else if (weaken(strerror_wr) &&
|
||||
!weaken(strerror_wr)(unixerr, winerr, z, sizeof(z))) {
|
||||
s = z;
|
||||
type = 0;
|
||||
goto FormatString;
|
||||
} else {
|
||||
type = 0;
|
||||
x = unixerr;
|
||||
goto FormatDecimal;
|
||||
}
|
||||
}
|
||||
|
||||
case 'G':
|
||||
x = va_arg(va, int);
|
||||
|
@ -864,6 +878,13 @@ privileged void kvprintf(const char *fmt, va_list v) {
|
|||
* - ` ` space leftpad if positive (aligns w/ negatives)
|
||||
* - `#` represent value with literal syntax, e.g. 0x, 0b, quotes
|
||||
*
|
||||
* Error numbers:
|
||||
*
|
||||
* - `%m` formats error (if strerror_wr if is linked)
|
||||
* - `%m` formats errno number (if strerror_wr isn't linked)
|
||||
* - `% m` formats error with leading space if errno isn't zero
|
||||
* - `%lm` means favor WSAGetLastError() over GetLastError() if linked
|
||||
*
|
||||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "libc/nt/enum/filemapflags.h"
|
||||
#include "libc/nt/memory.h"
|
||||
|
||||
extern typeof(MapViewOfFileEx) *const __imp_MapViewOfFileEx __msabi;
|
||||
__msabi extern typeof(MapViewOfFileEx) *const __imp_MapViewOfFileEx;
|
||||
|
||||
/**
|
||||
* Maps view of file mapping into memory on the New Technology.
|
||||
|
@ -45,8 +45,8 @@ textwindows void *MapViewOfFileEx(int64_t hFileMappingObject,
|
|||
hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow,
|
||||
dwNumberOfBytesToMap, opt_lpDesiredBaseAddress);
|
||||
if (!pStartingAddress) __winerr();
|
||||
STRACE("MapViewOfFileEx(%ld, %s, off:%'ld, size:%'zu, addr:%p) → %p% m",
|
||||
hFileMappingObject, DescribeNtFileMapFlags(dwDesiredAccess),
|
||||
STRACE("MapViewOfFileEx(%ld, %s, %'ld, %'zu, %p) → %p% m", hFileMappingObject,
|
||||
DescribeNtFileMapFlags(dwDesiredAccess),
|
||||
(uint64_t)dwFileOffsetHigh << 32 | dwFileOffsetLow,
|
||||
dwNumberOfBytesToMap, opt_lpDesiredBaseAddress, pStartingAddress);
|
||||
return pStartingAddress;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "libc/nt/enum/filemapflags.h"
|
||||
#include "libc/nt/memory.h"
|
||||
|
||||
extern typeof(MapViewOfFileExNuma) *const __imp_MapViewOfFileExNuma __msabi;
|
||||
__msabi extern typeof(MapViewOfFileExNuma) *const __imp_MapViewOfFileExNuma;
|
||||
|
||||
/**
|
||||
* Maps view of file mapping into memory on the New Technology.
|
||||
|
@ -47,7 +47,7 @@ textwindows void *MapViewOfFileExNuma(int64_t hFileMappingObject,
|
|||
hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow,
|
||||
dwNumberOfBytesToMap, opt_lpDesiredBaseAddress, nndDesiredNumaNode);
|
||||
if (!pStartingAddress) __winerr();
|
||||
STRACE("MapViewOfFileExNuma(%ld, %s, off:%'ld, size:%'zu, %p) → %p% m",
|
||||
STRACE("MapViewOfFileExNuma(%ld, %s, %'ld, %'zu, %p) → %p% m",
|
||||
hFileMappingObject, DescribeNtFileMapFlags(dwDesiredAccess),
|
||||
(uint64_t)dwFileOffsetHigh << 32 | dwFileOffsetLow,
|
||||
dwNumberOfBytesToMap, opt_lpDesiredBaseAddress, pStartingAddress);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "libc/nt/struct/securityattributes.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(OpenProcess) *const __imp_OpenProcess __msabi;
|
||||
__msabi extern typeof(OpenProcess) *const __imp_OpenProcess;
|
||||
|
||||
/**
|
||||
* Creates file mapping object on the New Technology.
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "libc/nt/memory.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(RemoveDirectory) *const __imp_RemoveDirectoryW __msabi;
|
||||
__msabi extern typeof(RemoveDirectory) *const __imp_RemoveDirectoryW;
|
||||
|
||||
/**
|
||||
* Deletes existing empty directory.
|
||||
|
|
44
libc/intrin/reopenfile.greg.c
Normal file
44
libc/intrin/reopenfile.greg.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
__msabi extern typeof(ReOpenFile) *const __imp_ReOpenFile;
|
||||
|
||||
/**
|
||||
* Reopens file on the New Technology.
|
||||
*
|
||||
* @return handle, or -1 on failure
|
||||
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
|
||||
*/
|
||||
int64_t ReOpenFile(int64_t hOriginalFile, uint32_t dwDesiredAccess,
|
||||
uint32_t dwShareMode, uint32_t dwFlagsAndAttributes) {
|
||||
int64_t hHandle;
|
||||
hHandle = __imp_ReOpenFile(hOriginalFile, dwDesiredAccess, dwShareMode,
|
||||
dwFlagsAndAttributes);
|
||||
if (hHandle == -1) __winerr();
|
||||
STRACE("ReOpenFile(%ld, %s, %s, %s) → %ld% m", hOriginalFile,
|
||||
DescribeNtFileAccessFlags(dwDesiredAccess),
|
||||
DescribeNtFileShareFlags(dwShareMode),
|
||||
DescribeNtFileFlagsAndAttributes(dwFlagsAndAttributes), hHandle);
|
||||
return hHandle;
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nt/console.h"
|
||||
#include "libc/nt/process.h"
|
||||
|
@ -35,7 +36,9 @@ const char kConsoleHandles[3] = {
|
|||
*/
|
||||
noasan void __restorewintty(void) {
|
||||
int i;
|
||||
if (IsWindows() && GetCurrentProcessId() == __winmainpid) {
|
||||
if (!IsWindows()) return;
|
||||
STRACE("__restorewintty()");
|
||||
if (GetCurrentProcessId() == __winmainpid) {
|
||||
for (i = 0; i < 3; ++i) {
|
||||
SetConsoleMode(GetStdHandle(kConsoleHandles[i]), __ntconsolemode[i]);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "libc/nt/memory.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(SetCurrentDirectory) *const __imp_SetCurrentDirectoryW __msabi;
|
||||
__msabi extern typeof(SetCurrentDirectory) *const __imp_SetCurrentDirectoryW;
|
||||
|
||||
/**
|
||||
* Sets current directory.
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_INTRIN_SPINLOCK_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_SPINLOCK_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401 && \
|
||||
!defined(__STRICT_ANSI__)
|
||||
|
||||
/* "Place each synchronization variable alone,
|
||||
separated by 128 bytes or in a separate cache line."
|
||||
──Intel Optimization Manual §8.3.1 */
|
||||
struct cthread_spinlock_t {
|
||||
bool x;
|
||||
int owner;
|
||||
char __ignore[128 - 1 - 4];
|
||||
} forcealign(128);
|
||||
#define _spinlock(lock) \
|
||||
do { \
|
||||
for (;;) { \
|
||||
typeof(*(lock)) x; \
|
||||
__atomic_load(lock, &x, __ATOMIC_RELAXED); \
|
||||
if (!x && !__sync_lock_test_and_set(lock, __ATOMIC_CONSUME)) { \
|
||||
break; \
|
||||
} else { \
|
||||
__builtin_ia32_pause(); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef struct cthread_spinlock_t cthread_spinlock_t;
|
||||
#define _spunlock(lock) __sync_lock_release(lock)
|
||||
|
||||
void cthread_spinlock(cthread_spinlock_t *) dontthrow;
|
||||
void cthread_spunlock(cthread_spinlock_t *) dontthrow;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* GNU 4.1+ */
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_SPINLOCK_H_ */
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "libc/nt/runtime.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
|
||||
extern typeof(TerminateProcess) *const __imp_TerminateProcess __msabi;
|
||||
__msabi extern typeof(TerminateProcess) *const __imp_TerminateProcess;
|
||||
|
||||
/**
|
||||
* Terminates the specified process and all of its threads.
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/nt/memory.h"
|
||||
|
||||
extern typeof(UnmapViewOfFile) *const __imp_UnmapViewOfFile __msabi;
|
||||
__msabi extern typeof(UnmapViewOfFile) *const __imp_UnmapViewOfFile;
|
||||
|
||||
/**
|
||||
* Unmaps memory created by MapViewOfFileEx().
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/nt/memory.h"
|
||||
|
||||
extern typeof(VirtualProtect) *const __imp_VirtualProtect __msabi;
|
||||
__msabi extern typeof(VirtualProtect) *const __imp_VirtualProtect;
|
||||
|
||||
/**
|
||||
* Protects memory on the New Technology.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue