casaroli opened a new pull request, #21529:
URL: https://github.com/apache/nuttx/pull/21529

   ## Summary
   
   `<limits.h>` defines `IOV_MAX` as `INT_MAX`, because `readv()` and 
`writev()` have no upper limit on the number of vectors. But programs use 
`IOV_MAX` as the size of an array of `struct iovec`, also on the stack. On a 
64-bit target such an array has 32 GiB, more than any stack. On a 32-bit target 
the array does not compile. Also, `sysconf(_SC_IOV_MAX)` returns -1 with 
`ENOSYS`.
   
   This PR sets `IOV_MAX` to 1024, the value of Linux and the BSDs, and makes 
`sysconf(_SC_IOV_MAX)` return it. POSIX requires at least 16 (`_XOPEN_IOV_MAX`).
   
   ## Impact
   
   **This changes a value of the flat-build API: `IOV_MAX` in `<limits.h>`.** 
`readv()` and `writev()` do not change: they still accept more than `IOV_MAX` 
vectors. A program that sizes an array with `IOV_MAX` now gets 1024 entries (16 
KiB on a 64-bit target, 8 KiB on a 32-bit target). Users in the tree: only the 
comments of `<sys/uio.h>`, which stay correct, and 
`arch/risc-v/src/gd32vw55x/gdwifi/config/lwipopts.h`, which replaces `IOV_MAX` 
with its own value for lwIP and does not change. No user in apps. No 
architecture code. No Documentation change: `Documentation/` does not name 
`IOV_MAX` or `_SC_IOV_MAX`.
   
   ## Testing
   
   Test program: `IOV_MAX` is 1024, `sysconf(_SC_IOV_MAX)` returns it, a thread 
clears an array of `IOV_MAX` vectors on its stack, and `writev()` of 1024 
one-byte vectors to a tmpfs file writes all of them. On master the stack case 
is not tried, because the array is larger than 1 MiB. It is not in apps; a 
regression guard would need an apps PR.
   
   | Config | master 43f7f34b995 | this branch |
   |---|---|---|
   | `qemu-armv8a:nsh` (flat), HVF | value 2147483647 FAIL, sysconf -1 FAIL, 
stack FAIL, writev PASS; ostest status 0 | 4 PASS (stack 16384 bytes); ostest 
status 0 |
   | `qemu-armv8a:knsh` (kernel), HVF | value 2147483647 FAIL, sysconf -1 FAIL, 
stack FAIL, writev PASS; ostest status 0 | 4 PASS (stack 16384 bytes); ostest 
status 0 |
   | `mps2-an500:knsh` (protected), TCG | the test does not compile: `size of 
array 'iov' exceeds maximum object size '2147483647'` | 4 PASS (stack 8192 
bytes); ostest status 0 |
   
   Options: `FS_TMPFS`. `mps2-an500:knsh` also has `TLS_LOG2_MAXSTACK=15`, for 
the stack of the test. Compilers: aarch64 GCC 14.2, arm-none-eabi GCC 15.3. The 
value has no architecture dependency.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to