Skip to content

Conversation

morinmorin
Copy link
Contributor

@morinmorin morinmorin commented Jul 25, 2025

Darwin's read/write syscalls emit EINVAL only when nbyte > INT_MAX. The case nbyte == INT_MAX is valid, so the subtraction (- 1) in

const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
    libc::c_int::MAX as usize - 1 // <- HERE
} else {
    libc::ssize_t::MAX as usize
};

can be removed.

I tested that the case nbyte == INT_MAX is valid on various versions of macOS, including old one like Mac OS X 10.5.

The man page says:

Here are links to Darwin's code:

Related PR: #38622.

Darwin's `read`/`write` syscalls emit `EINVAL` only when `nbyte > INT_MAX`.
The case `nbyte == INT_MAX` is valid, so the subtraction can be removed.
@rustbot
Copy link
Collaborator

rustbot commented Jul 25, 2025

r? @ChrisDenton

rustbot has assigned @ChrisDenton.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 25, 2025
@morinmorin morinmorin changed the title std/sys/fd: remove - 1 from READ_LIMIT on Darwin std/sys/fd: Relax READ_LIMIT on Darwin Aug 1, 2025
@ChrisDenton
Copy link
Member

Thanks for testing this!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Aug 23, 2025

📌 Commit a6f2666 has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2025
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Aug 23, 2025
…, r=ChrisDenton

std/sys/fd: Relax `READ_LIMIT` on Darwin

Darwin's `read`/`write` syscalls emit `EINVAL` only when `nbyte > INT_MAX`. The case `nbyte == INT_MAX` is valid, so the subtraction (`- 1`) in
```rust
const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
    libc::c_int::MAX as usize - 1 // <- HERE
} else {
    libc::ssize_t::MAX as usize
};
```
can be removed.

I tested that the case `nbyte == INT_MAX` is valid on various versions of macOS, including old one like Mac OS X 10.5.

The man page says:
- read() and pread() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/read.2.html)
- write() and pwrite() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/write.2.html)

Here are links to Darwin's code:
- [macOS 15.5] https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/bsd/kern/sys_generic.c#L307
- [Mac OS X 10.2] https://github.com/apple/darwin-xnu/blob/d738f900846ed2d5f685e18bf85ce63b0176f61a/bsd/kern/sys_generic.c#L220

Related PR: rust-lang#38622.
bors added a commit that referenced this pull request Aug 23, 2025
Rollup of 7 pull requests

Successful merges:

 - #144452 (std/sys/fd: Relax `READ_LIMIT` on Darwin)
 - #145307 (Fix `LazyLock` poison panic message)
 - #145515 (Optimize `char::encode_utf8`)
 - #145540 (interpret/allocation: get_range on ProvenanceMap)
 - #145774 (Remove default opts from config)
 - #145780 (Do not warn about missing change ID in tarball builds)
 - #145781 (Remove profile section from Clippy)

r? `@ghost`
`@rustbot` modify labels: rollup
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Aug 23, 2025
…, r=ChrisDenton

std/sys/fd: Relax `READ_LIMIT` on Darwin

Darwin's `read`/`write` syscalls emit `EINVAL` only when `nbyte > INT_MAX`. The case `nbyte == INT_MAX` is valid, so the subtraction (`- 1`) in
```rust
const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
    libc::c_int::MAX as usize - 1 // <- HERE
} else {
    libc::ssize_t::MAX as usize
};
```
can be removed.

I tested that the case `nbyte == INT_MAX` is valid on various versions of macOS, including old one like Mac OS X 10.5.

The man page says:
- read() and pread() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/read.2.html)
- write() and pwrite() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/write.2.html)

Here are links to Darwin's code:
- [macOS 15.5] https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/bsd/kern/sys_generic.c#L307
- [Mac OS X 10.2] https://github.com/apple/darwin-xnu/blob/d738f900846ed2d5f685e18bf85ce63b0176f61a/bsd/kern/sys_generic.c#L220

Related PR: rust-lang#38622.
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Aug 23, 2025
…, r=ChrisDenton

std/sys/fd: Relax `READ_LIMIT` on Darwin

Darwin's `read`/`write` syscalls emit `EINVAL` only when `nbyte > INT_MAX`. The case `nbyte == INT_MAX` is valid, so the subtraction (`- 1`) in
```rust
const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
    libc::c_int::MAX as usize - 1 // <- HERE
} else {
    libc::ssize_t::MAX as usize
};
```
can be removed.

I tested that the case `nbyte == INT_MAX` is valid on various versions of macOS, including old one like Mac OS X 10.5.

The man page says:
- read() and pread() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/read.2.html)
- write() and pwrite() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/write.2.html)

Here are links to Darwin's code:
- [macOS 15.5] https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/bsd/kern/sys_generic.c#L307
- [Mac OS X 10.2] https://github.com/apple/darwin-xnu/blob/d738f900846ed2d5f685e18bf85ce63b0176f61a/bsd/kern/sys_generic.c#L220

Related PR: rust-lang#38622.
bors added a commit that referenced this pull request Aug 23, 2025
Rollup of 14 pull requests

Successful merges:

 - #143898 (opt-dist: rebuild rustc when doing static LLVM builds)
 - #144452 (std/sys/fd: Relax `READ_LIMIT` on Darwin)
 - #145234 (match exhaustiveness diagnostics: show a trailing comma on singleton tuple consructors in witness patterns (and clean up a little))
 - #145515 (Optimize `char::encode_utf8`)
 - #145540 (interpret/allocation: get_range on ProvenanceMap)
 - #145670 (port `sanitize` attribute to the new parsing infrastructure)
 - #145713 (next-solver: fix `feature(const_trait_impl)` bootstrap)
 - #145729 (Remove two duplicated crates)
 - #145744 (miri: also detect aliasing of in-place argument and return place)
 - #145774 (Remove default opts from config)
 - #145781 (Remove profile section from Clippy)
 - #145782 (rustdoc: make attributes render consistently)
 - #145787 (citool: cleanup `mismatched_lifetime_syntaxes` warnings)
 - #145791 (Fix ICE when validating transmuting ZST to inhabited enum)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 982b022 into rust-lang:master Aug 24, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 24, 2025
rust-timer added a commit that referenced this pull request Aug 24, 2025
Rollup merge of #144452 - morinmorin:apple/update_read_limit, r=ChrisDenton

std/sys/fd: Relax `READ_LIMIT` on Darwin

Darwin's `read`/`write` syscalls emit `EINVAL` only when `nbyte > INT_MAX`. The case `nbyte == INT_MAX` is valid, so the subtraction (`- 1`) in
```rust
const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
    libc::c_int::MAX as usize - 1 // <- HERE
} else {
    libc::ssize_t::MAX as usize
};
```
can be removed.

I tested that the case `nbyte == INT_MAX` is valid on various versions of macOS, including old one like Mac OS X 10.5.

The man page says:
- read() and pread() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/read.2.html)
- write() and pwrite() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/write.2.html)

Here are links to Darwin's code:
- [macOS 15.5] https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/bsd/kern/sys_generic.c#L307
- [Mac OS X 10.2] https://github.com/apple/darwin-xnu/blob/d738f900846ed2d5f685e18bf85ce63b0176f61a/bsd/kern/sys_generic.c#L220

Related PR: #38622.
@jhpratt
Copy link
Member

jhpratt commented Aug 24, 2025

still in queue

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 24, 2025
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 24, 2025
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#143898 (opt-dist: rebuild rustc when doing static LLVM builds)
 - rust-lang/rust#144452 (std/sys/fd: Relax `READ_LIMIT` on Darwin)
 - rust-lang/rust#145234 (match exhaustiveness diagnostics: show a trailing comma on singleton tuple consructors in witness patterns (and clean up a little))
 - rust-lang/rust#145515 (Optimize `char::encode_utf8`)
 - rust-lang/rust#145540 (interpret/allocation: get_range on ProvenanceMap)
 - rust-lang/rust#145670 (port `sanitize` attribute to the new parsing infrastructure)
 - rust-lang/rust#145713 (next-solver: fix `feature(const_trait_impl)` bootstrap)
 - rust-lang/rust#145729 (Remove two duplicated crates)
 - rust-lang/rust#145744 (miri: also detect aliasing of in-place argument and return place)
 - rust-lang/rust#145774 (Remove default opts from config)
 - rust-lang/rust#145781 (Remove profile section from Clippy)
 - rust-lang/rust#145782 (rustdoc: make attributes render consistently)
 - rust-lang/rust#145787 (citool: cleanup `mismatched_lifetime_syntaxes` warnings)
 - rust-lang/rust#145791 (Fix ICE when validating transmuting ZST to inhabited enum)

r? `@ghost`
`@rustbot` modify labels: rollup
@morinmorin morinmorin deleted the apple/update_read_limit branch August 24, 2025 12:54
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Aug 26, 2025
…, r=ChrisDenton

std/sys/fd: Relax `READ_LIMIT` on Darwin

Darwin's `read`/`write` syscalls emit `EINVAL` only when `nbyte > INT_MAX`. The case `nbyte == INT_MAX` is valid, so the subtraction (`- 1`) in
```rust
const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
    libc::c_int::MAX as usize - 1 // <- HERE
} else {
    libc::ssize_t::MAX as usize
};
```
can be removed.

I tested that the case `nbyte == INT_MAX` is valid on various versions of macOS, including old one like Mac OS X 10.5.

The man page says:
- read() and pread() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/read.2.html)
- write() and pwrite() will fail if the parameter nbyte exceeds INT_MAX (link: https://keith.github.io/xcode-man-pages/write.2.html)

Here are links to Darwin's code:
- [macOS 15.5] https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/bsd/kern/sys_generic.c#L307
- [Mac OS X 10.2] https://github.com/apple/darwin-xnu/blob/d738f900846ed2d5f685e18bf85ce63b0176f61a/bsd/kern/sys_generic.c#L220

Related PR: rust-lang#38622.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants