Commit Graph

1964 Commits

Author SHA1 Message Date
cui
40c800e5fc
unix,stream: verify uv_try_write2 handle (#5035)
Looks like this was simply missed in #3183 because it was a bit outside
the review context window.
2026-03-15 10:13:52 -04:00
Jameson Nash
10902ab616
unix: improve handling of uv_async_send mistakes (#5058)
When the user calls uv_async_send concurrently with uv_loop_close, we
try to prevent that data race from actually accessing undefined behavior
by setting the pending flag atomically with the busy flag. This was
proposed in the original PR, but we didn't have motivation to go with
this implementation until a user pointed out that it improves behavior
of the race window in more cases.
2026-03-15 10:00:48 -04:00
Ben Noordhuis
a43e543dbf
unix: fix pedantic compiler warnings (#5052)
Fixes: https://github.com/libuv/libuv/issues/5051
2026-03-11 19:46:54 +01:00
Juan José
b030b02a3e
linux: fix crash if poll callback closes handle before POLLERR (#5039)
Previously, `uv__udp_io` would proceed to call `uv__udp_recvmsg` for
the `POLLERR` event even if the handle was just closed by the `POLLIN`
callback.

This commit adds a guard to verify the handle is still active before
processing the error queue. It also adds a regression test that
mimics this recursive closure behavior.

Fixes: https://github.com/libuv/libuv/issues/5030

Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2026-03-06 15:00:09 -05:00
Rudi Heitbaum
e62ccbf770 unix: do not cast to char variables that are const char
Fix the casting of const char varaibles with const char returns from
functions, when the data being returned is not being modified.  Includes
the part revert of "unix: fix compilation warnings with GCC 15"

This reverts commit 50ed2fd7bd.
2026-03-06 18:06:19 +01:00
Saúl Ibarra Corretgé
50ed2fd7bd unix: fix compilation warnings with GCC 15
~~~
libuv/src/unix/internal.h: In function ‘uv__basename_r’:
libuv/src/unix/internal.h:480:12: warning: return discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  480 |   return s + 1;

libuv/src/unix/linux.c: In function ‘uv__cgroup1_find_cpu_controller’:
libuv/src/unix/linux.c:2377:22: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
 2377 |   char* cgroup_cpu = strstr(cgroup, ":cpu,");
      |                      ^~~~~~

libuv/src/unix/linux.c: In function ‘uv_cpu_info’:
libuv/src/unix/linux.c:1903:20: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
 1903 |       .model     = p + c->model * sizeof(*model),
      |                    ^
~~~
2026-03-02 15:56:50 +01:00
Quaylyn Rimer
12d0dd48e3
Fix const-correctness warning in linux.c (#4843)
Fix #4814 by adding const annotation when assigning string literal
"unknown" to `char*` pointer.

This eliminates compiler warnings when building with strict
const-correctness flags like `-Wwrite-strings`.
2026-02-20 20:20:14 -05:00
Saúl Ibarra Corretgé
edfc95dbd7 unix,win: support NULL loop for sync uv_getaddrinfo
Brings symmetry with the uv_fs_xxx APIs.
2026-02-19 13:18:14 +01:00
Jameson Nash
1eacb1386f
unix: check RLIMIT_AS and RLIMIT_DATA in uv_get_constrained_memory (#4899)
Add uv__get_rlimit_max_memory() helper that checks RLIMIT_AS and
RLIMIT_DATA resource limits across all Unix platforms. This helper
returns the minimum of these rlimits if set.

Update all Unix platform implementations of uv_get_constrained_memory()
to use this helper, ensuring consistent handling of resource limits:
- Linux: combine cgroup limits with rlimits
- z/OS: combine RLIMIT_MEMLIMIT with rlimits
- Other Unix platforms: use rlimits (previously returned 0)

This provides a more accurate view of available memory when processes
have rlimit constraints in addition to platform-specific limits.

Related: https://github.com/JuliaLang/julia/pull/51656
Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-13 20:54:29 -05:00
Saúl Ibarra Corretgé
26a97ad442 unix,udp: fix -Wgnu-folding-constant warning
~~~
/Users/saghul/src/libuv/src/unix/udp.c:1460:26: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1460 |   struct sockaddr* addrs[N];
      |                          ^
/Users/saghul/src/libuv/src/unix/udp.c:1461:22: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1461 |   unsigned int nbufs[N];
      |                      ^
/Users/saghul/src/libuv/src/unix/udp.c:1462:18: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1462 |   uv_buf_t* bufs[N];
      |                  ^
3 warnings generated.
/Users/saghul/src/libuv/src/unix/udp.c:1460:26: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1460 |   struct sockaddr* addrs[N];
      |                          ^
/Users/saghul/src/libuv/src/unix/udp.c:1461:22: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1461 |   unsigned int nbufs[N];
      |                      ^
/Users/saghul/src/libuv/src/unix/udp.c:1462:18: warning: variable length array folded to constant array as an extension [-Wgnu-folding-constant]
 1462 |   uv_buf_t* bufs[N];
      |                  ^
~~~
2026-02-05 20:11:10 +01:00
mischief
71801576eb unix: make OpenBSD uv_exepath work
some users of libuv rely on uv_exepath to be an actual path to a
program. unfortunately, the OpenBSD KERN_PROC_ARGV sysctl just returns
what is in argv[0], so if the program was executed by being looked up in
$PATH, uv_exepath would only return the basename and not an actual path.

to fix, this use the same approach as IBM i, OS/390 and AIX by searching
with uv__search_path. this is also the same approach the Zig language
has taken for the similar selfExePath function for OpenBSD.

the tests expect that uv_exepath still works after uv_set_process_title,
which on BSD is a call to setproctitle. the place setproctitle stores to
is the same place that KERN_PROC_ARGV reads from, so we need to stash
the original argv[0] in uv_setup_args to recover it later in uv_exepath.
2026-02-05 11:45:49 +01:00
Han Gao
e50d4e672e
unix: implement cpu_relax() for riscv64 (#5019)
Signed-off-by: Han Gao <gaohan@iscas.ac.cn>
2026-02-04 22:46:14 +01:00
Ben Noordhuis
fc90bb9843
unix: remove sunpro references (#5017)
Sun Studio / Oracle Developer Studio hasn't had a release in almost
nine years. If Oracle doesn't feel like supporting it, then neither
do I.
2026-02-02 23:15:38 +01:00
Ben Noordhuis
91dc2389cc
unix,win: check nbufs argument is reasonable (#5014)
Catch sign conversion bugs by introducing a bounds check that doubles
as a sanity check.

Fixes: https://github.com/libuv/libuv/issues/5012
2026-02-01 13:03:07 +01:00
Ben Noordhuis
4cb6a2d33c
unix: factor out common i/o poll code (#5000) 2026-01-18 22:32:36 +01:00
Ben Noordhuis
2e2114ed89
unix: fix partial read handling after POLLHUP (#4997)
It was reported that PTYs on Linux sometimes report POLLHUP, return a
partial read, but still return more data on the next read.

Libuv contains an optimization where it assumes a partial read after
POLLHUP means the next read can be skipped because it's going to fail
with EOF anyway. That assumption was thought to be always true but,
alas, it isn't.

The fact the optimization has been present for 13 years and this is the
first bug report about it, indicates how rare this particular condition
is, but of course we can't skim on correctness.

The reworked optimization only uses POLLHUP as an input signal when
POLLIN is not also set. That means we no longer have to track partial
reads because we're going to try and read anyway as long as POLLIN is
set. It seems to cause no measurable regressions on the test suite or
the (lightly tested) benchmarks.

Fixes: https://github.com/libuv/libuv/issues/4992
2026-01-18 12:21:53 +01:00
Ben Noordhuis
91ae02a63d
unix,win: add f_frsize field to uv_statfs_t (#4984)
Fixes: https://github.com/libuv/libuv/issues/4983
2026-01-01 22:33:44 +01:00
Oblivionsage
3e9ae1bca0
unix: remove handle from queue on uv_spawn() error (#4980)
If uv_spawn() fails after uv__handle_init() has been called, the handle
remains in loop->handle_queue. This causes use-after-free if the handle
is stack-allocated or freed, and a subsequent loop operation like
uv_walk() accesses it.

This follows the same pattern as uv_tcp_init_ex() which explicitly
removes the handle from the queue on error.
2025-12-26 16:53:42 +01:00
Santiago Gimeno
fd89e63f2f linux: fix uv_fs_ftruncate io_uring implementation (#4963 2/2)
The `offset` field should be assigned to ithe `io_uring_sqe.off` field.
2025-12-08 10:31:45 +01:00
Ambuj Vashistha
9640bc6510
unix,win: fix leak in uv_os_environ error path (#4960) 2025-12-06 22:04:49 +01:00
Ayush Kumar
bf44c3fdcc
unix: support nanosecond resolution in uv__fs_to_timespec (#4951)
Remove the microsecond truncation in uv__fs_to_timespec() function to enable
full nanosecond resolution support. The utimensat() system call already
supports nanosecond precision, so the artificial truncation to microseconds
is no longer necessary.

This allows file modification and access times to be set with full nanosecond
precision instead of being limited to microsecond resolution.

Fixes the TODO comment about removing the microsecond resolution limit.
2025-12-02 08:42:44 +01:00
Ben Noordhuis
b33162dd0b
unix: fix use of uninitialized variable (#4924)
The `flags` argument to `uv__udp_recvmsg_errqueue` was not initialized
in all code paths. Shuffle code around to make the control flow more
obvious (at the cost of a less legible diff.)

Also fixes an unused label warning when building on systems that aren't
Linux.

Introduced last month in commit 80a5e3ba0, "linux: add MSG_ERRQUEUE
ipv4/ipv6 udp support".
2025-11-06 22:34:44 +01:00
Christian Guinard
a944c422cc
darwin: better heuristic for available memory (#4908)
Fixes: https://github.com/libuv/libuv/issues/3897
2025-10-15 08:35:42 +02:00
Ben Noordhuis
f3ce527ea9
ibmi: add stub function to satisfy linker (#4905)
Add a stub function for no-ahafs builds. src/unix/core.c won't actually
call uv__ahafs_event but the linker still needs to see a symbol.

Like commit 87943b03 but for IBM i instead of AIX this time.
2025-10-07 23:08:33 +02:00
Juan José
80a5e3ba01
linux: add MSG_ERRQUEUE ipv4/ipv6 udp support (#4902)
Fixes: https://github.com/libuv/libuv/issues/4447
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
Co-authored-by: theanarkh <theratliter@gmail.com>
2025-10-06 16:45:58 +02:00
Ben Noordhuis
87943b03b3
aix: add stub function to satisfy linker (#4903)
Add a stub function for no-ahafs builds. src/unix/core.c won't actually
call uv__ahafs_event but the linker still needs to see a symbol.
2025-10-05 18:40:12 +02:00
Juan José
ee67f3db88
unix,win: implement uv_udp_open_ex (#4896)
Fixes: https://github.com/libuv/libuv/issues/4551

Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-10-04 09:43:07 +02:00
green-br
74079a8e47
unix: add neoverse-v2 cpu identifier (#4897) 2025-10-01 19:18:20 +02:00
Ben Noordhuis
553bb9858f
aix: fix nullptr check in uv__skip_lines (#4892)
Fixes: https://github.com/libuv/libuv/issues/4891
2025-09-25 20:21:54 +02:00
Jameson Nash
cfdce92fa5
unix: fix uv__signal_loop_cleanup call in init (#4876)
While unlikely that this fails (since it is implemented to call
`abort()` instead of actually return an error code, we would
theoretically leak this state. The process state init doesn't actually
have a cleanup, and just awkwardly relies on uv_signal_close being
unnecessary (which is likely true though).
2025-09-25 11:02:44 -04:00
Juan José
64dd229a5b
unix: remove UV__SIGNAL_EVENT dispatch from uv__io_cb (#4871)
uv__signal_event() is invoked directly from uv__io_poll(), so the
UV__SIGNAL_EVENT case in uv__io_cb() is never reached.

Refs: https://github.com/libuv/libuv/pull/4854#discussion_r2246110177
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-08-25 22:39:46 +02:00
Santiago Gimeno
9ba8078272
netbsd: fix thread affinity compilation error (#4787)
Fixes: https://github.com/libuv/libuv/issues/4785
2025-08-25 16:22:15 +02:00
Ben Noordhuis
36d6a17c9a
unix: fix build on the bsds (#4870)
Fix build breakage introduced a couple of days ago in commit 3813460d
("unix: replace uv__io_t callback pointer with enum"). Mea culpa.

Fixes: https://github.com/libuv/libuv/issues/4864
2025-08-25 16:21:37 +02:00
Ben Noordhuis
3813460d57
unix: replace uv__io_t callback pointer with enum (#4854)
Rationale for changing it to an enum:

- frees up some bits that can be used for other things
- is potentially faster (direct vs. indirect call)
- is potentially more secure (makes UAF or overruns harder to exploit,
  no arbitrary function pointer to clobber)

Fixes: https://github.com/libuv/libuv/issues/4842
2025-08-23 20:41:01 +02:00
Anton Kirilov
3d9d7c7ef6
unix: improve uv__cpu_relax() on arm (#4863)
The AArch64 YIELD instruction affects processors that support
symmetric multithreading, while on other implementations (which
are the majority on the market) it is equivalent to NOP, thus
failing to achieve the desired delay effect inside uv__async_spin().
Instead, use the ISB instruction, following one of Arm's
recommendations [1].

[1] https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/multi-threaded-applications-arm

Signed-off-by: Anton Kirilov <anton.kirilov@arm.com>
2025-08-20 21:15:37 +02:00
Ben Noordhuis
2e7c07f4d1
linux: handle cgroups cpu.max with limit < period (#4853)
This apparently manifests when one passes `--cpu=.5` to docker because
then /sys/fs/cgroup/cpu.max looks like `50000 100000`, and 50000 divided
by 100000 is zero when using integer math.

Return 1 in that case, indicating there is at least one CPU available.
Returning 0 makes no sense because there is always at least one CPU
available, otherwise the program wouldn't be running.

Fixes: https://github.com/nodejs/node/issues/59200
2025-07-31 11:54:57 +02:00
Ben Noordhuis
33b192c845
unix: fix udp sendmmsg fallback path (#4849)
Fix a logic bug in the fallback code for platforms that don't have a
sendmmsg-like system call. It only sent at most one packet, even when
there were more available, and that was observable through a failing
test on such systems.

Fixes: https://github.com/libuv/libuv/issues/4848
2025-07-29 01:06:40 +02:00
Juan José
55f5fce1cc
unix: deduplicate uv_free_interface_addresses (#4818)
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-07-05 13:05:46 +02:00
Juan José
db3d0ff33a
unix: handle possible ENOMEM in uv__pipe_listen (#4817)
Refs: https://github.com/libuv/libuv/issues/4755
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-07-03 21:04:46 +02:00
Deep C
04fc1580d4
qnx: add qnx 8 support (#4801)
Fixes: https://github.com/libuv/libuv/issues/4710
2025-06-30 08:26:11 +02:00
Juan José Arboleda
513751e2fc unix: handle possible ENOMEM in uv__tcp_listen
Refs: https://github.com/libuv/libuv/issues/4755
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-06-24 10:50:34 +02:00
Ben Noordhuis
b00c5d1a09
linux: fix -Wformat-truncation warning (#4793) 2025-05-29 22:11:40 +02:00
Andy Pan
3a9a6e3e6b
tcp: support customizing TCP_KEEPINTVL and TCP_KEEPCNT
Implement `uv_tcp_keepalive_ex` function that extends
`uv_tcp_keepalive` to support `TCP_KEEPINTVL` and `TCP_KEEPCN`
socket options in addition to TCP_KEEPIDLE.
2025-05-21 08:43:53 +02:00
Ryan Liptak
2b76a4fafa
unix: fix uv_thread_{get,set}priority error codes (#4782)
pthread_getschedparam and pthread_setschedparam do not use errno but
instead return the error code directly.

https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_getschedparam.html

Also include a fix to return UV_ESRCH instead of UV_EBADF on Windows,
like Unix systems do.
2025-05-15 09:16:25 +02:00
Juan José
e6c0007fae
sunos: improve fs event watcher OOM handling (#4759)
Propagate errors from uv__io_init_start() back to the caller.

Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-04-23 23:24:52 +02:00
Juan José
414a5e7333
kqueue: improve fs event watcher OOM handling (#4758)
Propagate errors from uv__io_init_start() back to the caller.

Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-04-23 23:21:37 +02:00
Juan José
69d2dfec14
linux: align CPU quota calculation with Rust (#4746)
Align CPU quota calculation with Rust's cgroup heuristics.

Fixes: https://github.com/libuv/libuv/issues/4740
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-04-22 22:12:30 +02:00
Ben Noordhuis
942e1418ea
unix: improve uv_loop_init OOM handling (#4757)
Handle out-of-memory conditions in uv_loop_init better, albeit still
not perfect: bubble up the error instead of aborting.

Also fixes a file descriptor leak on Linux (and likely other platforms)
that the new test caught; the backend epoll fd was being leaked in the
error path.

Fixes: https://github.com/libuv/libuv/issues/4755
2025-04-18 16:23:51 +02:00
AE1020
bf6c8870dc
haiku: use uint32 instead of uint32_t (#4754)
Haiku has parallel types to stdint.h, and their APIs use these
types.  In the Haiku-specific haiku.h file, it is passing an
address of a uint32_t to get_cpu_topology_info(), that expects
the other uint32:

  648fa5897c/src/system/libroot/os/system_info.cpp (L187)

You get an "incompatible-pointer-types" warning in gcc if the
warnings are turned up.  But if you pass the pointer to Haiku's
notion of uint32, then the warning goes away.
2025-04-16 14:47:07 +02:00
crupest
bcc799a16e
unix: use pipe_fname if getsockname returns nothing (#4748)
On some platforms (like GNU/Hurd), `getsockname` returns an empty
string for sockets in the UNIX domain. However, we do have stored the
path info in `pipe_fname` of `uv_pipe_t`, so we can try with it
if `getsockname` returns an empty string.
2025-04-08 10:49:34 +02:00