mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Fix bug with sendfile() on XNU
This commit is contained in:
parent
790c661317
commit
827f25f054
3 changed files with 26 additions and 12 deletions
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue