From 3851025b77fcb8aa94df8bf8e42df3d71afa16ce Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Fri, 13 Oct 2023 10:48:04 -0700 Subject: [PATCH] Fix SQLite regressions caused by 3b086af91 --- libc/calls/fcntl-nt.c | 2 +- libc/calls/fstatat-nt.c | 4 +++- libc/calls/pipe-nt.c | 8 ++++++-- libc/calls/truncate-nt.c | 6 ++++-- libc/intrin/kprintf.greg.c | 1 - libc/sock/socketpair-nt.c | 4 +++- libc/stdio/dirstream.c | 12 ++++++++---- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/libc/calls/fcntl-nt.c b/libc/calls/fcntl-nt.c index 5fb0692ffe2..eb5fe2036b7 100644 --- a/libc/calls/fcntl-nt.c +++ b/libc/calls/fcntl-nt.c @@ -96,7 +96,7 @@ static textwindows bool OverlapsFileLock(struct FileLock *fl, int64_t off, EndA = off + (len - 1); BegB = fl->off; EndB = fl->off + (fl->len - 1); - return MAX(BegA, BegB) < MIN(EndA, EndB); + return MAX(BegA, BegB) <= MIN(EndA, EndB); } static textwindows bool EncompassesFileLock(struct FileLock *fl, int64_t off, diff --git a/libc/calls/fstatat-nt.c b/libc/calls/fstatat-nt.c index 3c63a720afc..8a3b7f93d7f 100644 --- a/libc/calls/fstatat-nt.c +++ b/libc/calls/fstatat-nt.c @@ -43,7 +43,9 @@ textwindows int sys_fstatat_nt(int dirfd, const char *path, struct stat *st, dwDesiredAccess = kNtFileGenericRead; TryAgain: if ((fh = CreateFile( - path16, dwDesiredAccess, 0, 0, kNtOpenExisting, + path16, dwDesiredAccess, + kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, 0, + kNtOpenExisting, kNtFileAttributeNormal | kNtFileFlagBackupSemantics | ((flags & AT_SYMLINK_NOFOLLOW) ? kNtFileFlagOpenReparsePoint : 0), diff --git a/libc/calls/pipe-nt.c b/libc/calls/pipe-nt.c index 95c9279e828..08350193642 100644 --- a/libc/calls/pipe-nt.c +++ b/libc/calls/pipe-nt.c @@ -25,6 +25,7 @@ #include "libc/nt/enum/accessmask.h" #include "libc/nt/enum/creationdisposition.h" #include "libc/nt/enum/fileflagandattributes.h" +#include "libc/nt/enum/filesharemode.h" #include "libc/nt/ipc.h" #include "libc/nt/runtime.h" #include "libc/sysv/consts/limits.h" @@ -57,8 +58,11 @@ static textwindows int sys_pipe_nt_impl(int pipefd[2], unsigned flags) { mode, 1, PIPE_BUF, PIPE_BUF, 0, &kNtIsInheritable); __fds_lock(); if (hin != -1) { - if ((hout = CreateFile(pipename, kNtGenericWrite, 0, &kNtIsInheritable, - kNtOpenExisting, kNtFileFlagOverlapped, 0)) != -1) { + if ((hout = CreateFile( + pipename, kNtGenericWrite, + kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, + &kNtIsInheritable, kNtOpenExisting, kNtFileFlagOverlapped, 0)) != + -1) { g_fds.p[reader].kind = kFdFile; g_fds.p[reader].flags = O_RDONLY | flags; g_fds.p[reader].mode = 0010444; diff --git a/libc/calls/truncate-nt.c b/libc/calls/truncate-nt.c index 57daed75fff..8e1dbe43f9d 100644 --- a/libc/calls/truncate-nt.c +++ b/libc/calls/truncate-nt.c @@ -32,8 +32,10 @@ textwindows int sys_truncate_nt(const char *path, uint64_t length) { uint16_t path16[PATH_MAX]; if (__mkntpath(path, path16) == -1) return -1; BLOCK_SIGNALS; - if ((fh = CreateFile(path16, kNtGenericWrite, kNtFileShareRead, NULL, - kNtOpenExisting, kNtFileAttributeNormal, 0)) != -1) { + if ((fh = CreateFile( + path16, kNtGenericWrite, + kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, NULL, + kNtOpenExisting, kNtFileAttributeNormal, 0)) != -1) { rc = sys_ftruncate_nt(fh, length); CloseHandle(fh); } else { diff --git a/libc/intrin/kprintf.greg.c b/libc/intrin/kprintf.greg.c index 32db36881c6..9248333f448 100644 --- a/libc/intrin/kprintf.greg.c +++ b/libc/intrin/kprintf.greg.c @@ -1061,7 +1061,6 @@ privileged void kvprintf(const char *fmt, va_list v) { #pragma GCC diagnostic ignored "-Walloca-larger-than=" long size = __get_safe_size(8000, 3000); if (size < 80) { - asm("int3"); klog(STACK_ERROR, sizeof(STACK_ERROR) - 1); return; } diff --git a/libc/sock/socketpair-nt.c b/libc/sock/socketpair-nt.c index 31dd4096d53..7d3b9e18451 100644 --- a/libc/sock/socketpair-nt.c +++ b/libc/sock/socketpair-nt.c @@ -23,6 +23,7 @@ #include "libc/nt/enum/accessmask.h" #include "libc/nt/enum/creationdisposition.h" #include "libc/nt/enum/fileflagandattributes.h" +#include "libc/nt/enum/filesharemode.h" #include "libc/nt/ipc.h" #include "libc/nt/runtime.h" #include "libc/sock/internal.h" @@ -73,7 +74,8 @@ textwindows int sys_socketpair_nt(int family, int type, int proto, int sv[2]) { return -1; } - h1 = CreateFile(pipename, kNtGenericWrite | kNtGenericRead, 0, + h1 = CreateFile(pipename, kNtGenericWrite | kNtGenericRead, + kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, &kNtIsInheritable, kNtOpenExisting, kNtFileFlagOverlapped, 0); __fds_lock(); diff --git a/libc/stdio/dirstream.c b/libc/stdio/dirstream.c index d2edf324e1a..689b9520c75 100644 --- a/libc/stdio/dirstream.c +++ b/libc/stdio/dirstream.c @@ -36,6 +36,7 @@ #include "libc/nt/enum/accessmask.h" #include "libc/nt/enum/creationdisposition.h" #include "libc/nt/enum/fileflagandattributes.h" +#include "libc/nt/enum/filesharemode.h" #include "libc/nt/enum/filetype.h" #include "libc/nt/files.h" #include "libc/nt/runtime.h" @@ -229,10 +230,13 @@ static textwindows dontinline struct dirent *readdir_nt(DIR *dir) { // get inode such that it's consistent with stat() // it's important that we not follow symlinks here - int64_t fh = CreateFile(jp, kNtFileReadAttributes, 0, 0, kNtOpenExisting, - kNtFileAttributeNormal | kNtFileFlagBackupSemantics | - kNtFileFlagOpenReparsePoint, - 0); + int64_t fh = + CreateFile(jp, kNtFileReadAttributes, + kNtFileShareRead | kNtFileShareWrite | kNtFileShareDelete, 0, + kNtOpenExisting, + kNtFileAttributeNormal | kNtFileFlagBackupSemantics | + kNtFileFlagOpenReparsePoint, + 0); if (fh != kNtInvalidHandleValue) { struct NtByHandleFileInformation wst; if (GetFileInformationByHandle(fh, &wst)) {