mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Ensure io requests are always capped at 0x7ffff000
This gives us the Linux behavior across platforms. Fixes #1189
This commit is contained in:
parent
6cf9b9e0fc
commit
af3f62a71a
10 changed files with 268 additions and 81 deletions
|
@ -28,6 +28,7 @@
|
|||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdio/sysparam.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
|
@ -37,7 +38,7 @@
|
|||
*
|
||||
* @param fd is something open()'d earlier, noting pipes might not work
|
||||
* @param buf is copied from, cf. copy_file_range(), sendfile(), etc.
|
||||
* @param size in range [1..0x7ffff000] is reasonable
|
||||
* @param size is always saturated to 0x7ffff000 automatically
|
||||
* @param offset is bytes from start of file at which write begins,
|
||||
* which can exceed or overlap the end of file, in which case your
|
||||
* file will be extended
|
||||
|
@ -53,6 +54,10 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) {
|
|||
size_t wrote;
|
||||
BEGIN_CANCELATION_POINT;
|
||||
|
||||
// XNU and BSDs will EINVAL if requested bytes exceeds INT_MAX
|
||||
// this is inconsistent with Linux which ignores huge requests
|
||||
size = MIN(size, 0x7ffff000);
|
||||
|
||||
if (offset < 0) {
|
||||
rc = einval();
|
||||
} else if (fd == -1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue