diff --git a/libc/calls/readv-metal.c b/libc/calls/readv-metal.c index d7476f9bb..3e283a1f3 100644 --- a/libc/calls/readv-metal.c +++ b/libc/calls/readv-metal.c @@ -37,8 +37,8 @@ ssize_t sys_readv_metal(struct Fd *fd, const struct iovec *iov, int iovlen) { * escape sequences, in response to requests sent to it via write(). * Read & return these if they are available. */ - if (_weaken(sys_readv_vga)) { - ssize_t res = _weaken(sys_readv_vga)(fd, iov, iovlen); + if (weaken(sys_readv_vga)) { + ssize_t res = weaken(sys_readv_vga)(fd, iov, iovlen); if (res > 0) return res; } /* fall through */ diff --git a/libc/sock/sendfile.c b/libc/sock/sendfile.c index 2a1350a33..4908c2f23 100644 --- a/libc/sock/sendfile.c +++ b/libc/sock/sendfile.c @@ -23,6 +23,7 @@ #include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall_support-nt.internal.h" #include "libc/dce.h" +#include "libc/intrin/asan.internal.h" #include "libc/intrin/safemacros.internal.h" #include "libc/nt/enum/wait.h" #include "libc/nt/errors.h" @@ -106,10 +107,13 @@ static ssize_t sendfile_linux2bsd(int outfd, int infd, if (IsFreebsd()) { rc = sys_sendfile_freebsd(infd, outfd, offset, uptobytes, 0, &sbytes, 0); } else { + sbytes = uptobytes; rc = sys_sendfile_xnu(infd, outfd, offset, &sbytes, 0, 0); } if (rc != -1) { - if (inout_opt_inoffset) *inout_opt_inoffset += sbytes; + if (inout_opt_inoffset) { + *inout_opt_inoffset += sbytes; + } return sbytes; } else { return -1; @@ -131,15 +135,25 @@ static ssize_t sendfile_linux2bsd(int outfd, int infd, */ ssize_t sendfile(int outfd, int infd, int64_t *inout_opt_inoffset, size_t uptobytes) { - if (!uptobytes) return einval(); - if (uptobytes > 0x7ffffffe /* Microsoft's off-by-one */) return eoverflow(); - if (IsLinux()) { - return sys_sendfile(outfd, infd, inout_opt_inoffset, uptobytes); + int rc; + if (!uptobytes) { + rc = einval(); + } else if (IsAsan() && inout_opt_inoffset && + !__asan_is_valid(inout_opt_inoffset, + sizeof(*inout_opt_inoffset))) { + rc = efault(); + } else if (uptobytes > 0x7ffffffe /* Microsoft's off-by-one */) { + rc = eoverflow(); + } else if (IsLinux()) { + rc = sys_sendfile(outfd, infd, inout_opt_inoffset, uptobytes); } else if (IsFreebsd() || IsXnu()) { - return sendfile_linux2bsd(outfd, infd, inout_opt_inoffset, uptobytes); + rc = sendfile_linux2bsd(outfd, infd, inout_opt_inoffset, uptobytes); } else if (IsWindows()) { - return sendfile_linux2nt(outfd, infd, inout_opt_inoffset, uptobytes); + rc = sendfile_linux2nt(outfd, infd, inout_opt_inoffset, uptobytes); } else { - return copyfd(infd, inout_opt_inoffset, outfd, NULL, uptobytes, 0); + rc = copyfd(infd, inout_opt_inoffset, outfd, NULL, uptobytes, 0); } + STRACE("sendfile(%d, %d, %p, %'zu) → %ld% m", outfd, infd, inout_opt_inoffset, + uptobytes, rc); + return rc; } diff --git a/tool/emacs/cosmo-stuff.el b/tool/emacs/cosmo-stuff.el index a10d4b269..d7241f477 100644 --- a/tool/emacs/cosmo-stuff.el +++ b/tool/emacs/cosmo-stuff.el @@ -637,7 +637,7 @@ (let ((default-directory root)) (save-buffer) (cond ((memq major-mode '(c-mode c++-mode asm-mode fortran-mode)) - (let* ((mode (cosmo--make-mode arg "")) + (let* ((mode (cosmo--make-mode arg "fastbuild")) (compile-command (cosmo--compile-command this root 'test mode "" "" ".ok"))) (compile compile-command))) ('t @@ -653,7 +653,7 @@ (let ((default-directory root)) (save-buffer) (cond ((memq major-mode '(c-mode c++-mode asm-mode fortran-mode)) - (let* ((mode (cosmo--make-mode arg "")) + (let* ((mode (cosmo--make-mode arg "fastbuild")) (compile-command (cosmo--compile-command this root 'run-win10 mode "" "" ""))) (compile compile-command))) ('t