Commit Graph

3245 Commits

Author SHA1 Message Date
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
Rudi Heitbaum
5243d19134 unix: fix discard const
Do not cast const char to char unnecessarily. Refactor function to use
char s only when slash is in the path.

Fixes:

[6/73] Building C object CMakeFiles/uv.dir/src/inet.c.o
../src/inet.c: In function 'uv_inet_pton':
../src/inet.c:157:7: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  157 |     p = strchr(src, '%');
      |       ^

Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
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
StefanStojanovic
01f4f89503 win: fix uv_get_process_title
Fixes: https://github.com/libuv/libuv/issues/2667
2026-02-05 11:54:22 +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
tobil4sk
73bfbb995f
idna: fix assert in wtf8_to_utf16 conversion (#5021)
0x10FFFF is the valid max unicode character, so the check should be
inclusive.

This assert gets triggered because uv__wtf8_decode1 (used by
uv_wtf8_length_as_utf16) has the correct code_point <= 0x10FFFF check,
so the sequence is treated as valid and it will be passed into
uv_wtf8_to_utf16, where the incorrect assert gets triggered:

src/idna.c:397: uv_wtf8_to_utf16: Assertion `code_point < 0x10FFFF' failed.
2026-02-04 21:55:43 +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
Santiago Gimeno
c68ca444e7
win: refactor to support large statfs blocks (#5016)
Accomplish this by replacing `GetDiskFreeSpaceW()` with
`NtQueryVolumeInformationFile()` which allows us to represent blocks
larger than 2^32 - 1 via
`FILE_FS_FULL_SIZE_INFORMATION.TotalAllocationUnits`.

Expanded `fs_statfs` test to check that `uv_fs_statfs()` also works with
files, meaning https://github.com/libuv/libuv/issues/2683 remains fixed
without the need of https://github.com/libuv/libuv/pull/2695.
2026-02-02 10:04:36 +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
Cody Tapscott
588ea9b913
win: readlink support for IO_REPARSE_TAG_LX_SYMLINK (#4994)
This adds support for "Linux"-style Windows symbolic links, reparse tag
0xA000001D (IO_REPARSE_TAG_LX_SYMLINK).
2026-01-16 10:38:18 +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
chemodax
ada5131840 win: Optimize file/directory delete.
Use GetFileInformationByHandleEx(FileBasicInfo) instead of GetFileInformationByHandle() because it's cheaper -- one syscall, instead of two [1]

[1]: https://blog.axiorema.com/engineering/hidden-cost-getfileinformationbyhandle/
2025-12-12 08:46:10 +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
Ben Noordhuis
d7dda9edfe
win: handle sshfs-win quirk in uv_fs_readdir() (#4953)
The initial FindFirstFile can fail with ERROR_FILE_NOT_FOUND, meaning
no matches (read: empty directory), which leaves dir_handle set to
INVALID_HANDLE_VALUE. Not an actual error, it just means no results.

I can't get FindFirstFile to work like that on regular file systems
but it's been reported that it does under sshfs-win and the MSDN
documentation clearly states it's possible. Handle it.

Fixes: https://github.com/libuv/libuv/issues/4952
2025-12-02 16:37:17 +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
8fc70344df
win: fix race in uv_fs_event_start() (#4948)
Fetch file metadata by handle instead of by path, otherwise there is a
race window between fetching and acting on said metadata where another
process can replace the file with another one.

There is still a potential race when upgrading the short path to a long
path but that that one is intrinsic. It's not something libuv can solve
except by refraining from calling GetLongPathName.

Fixes: https://github.com/libuv/libuv/issues/4568
2025-11-29 20:21:40 +01:00
Andy Pan
f6e19be743 win: rename minimal_windows10_version1709() for libuv's convention
---------

Signed-off-by: Andy Pan <i@andypan.me>
2025-11-22 15:43:50 +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
moe li
271d173b6e
unix,win: look up UV_THREADPOOL_SIZE with uv_os_getenv (#4888)
Use libuv's OS-independent implementation to look up UV_THREADPOOL_SIZE.

Fixes: https://github.com/libuv/libuv/issues/4887
2025-09-14 18:14:44 +02:00
Ben Noordhuis
2e86f6b635
win: fix path size calculation (#4878)
_snwprintf_s takes its length argument in characters, not bytes.

Does not appear to be a security issue because the paths are not under
an attacker's control unless the system has been compromised beyond
salvation: requires a combination of being able to set the name of the
executable and/or changing %LOCALAPPDATA% or a registry key.

Refs: https://github.com/libuv/libuv/security/advisories/GHSA-jjrx-vr7q-7732
2025-09-03 08:37:31 +02: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
12fbd34475
win: shrink fd hash table from 2592k to 162k (#4869)
The static initial table reserved space for MxN elements but only used
every Nth element. Removing the excess elements shrinks the table 16x.

I added search/insertion/deletion time logging while here to ensure no
performance regressions.

Fixes: https://github.com/libuv/libuv/issues/4823
2025-08-24 20:22:54 +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
Savas Sahin
3b1ac021e3
win: fix compiler warnings (#4860) 2025-08-20 21:17:02 +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
Keno Fischer
6cf854c11b
win: work around wine bug in uv_fs_{unlink,rmdir} (#4833)
Wine has a bug (https://bugs.winehq.org/show_bug.cgi?id=50771) where
FILE_WRITE_ATTRIBUTES will cause CreateFile to fail if the file is
read-only. The recommended work around is to instead use
FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE, which we do as of #4318.
However, we were still using FILE_WRITE_ATTRIBUTES to create the
initial handle, despite this no longer being required, except for
the fallback path. As a result, libuv is still broken under wine,
even on master. Fix this by removing the `FILE_WRITE_ATTRIBUTES`
from the initial CreateFile call and re-opening the handle in the
fallback path if necessary. Note that we still have the same issue
in fs_chmod and I've requested some guidance from wine on what
to do about this, but this should at least fix unlink.

Refs: https://github.com/JuliaLang/julia/issues/58980
2025-07-24 21:15:39 +02:00
Ben Noordhuis
7484ab251f
win: use ProcessPrng (#4836)
Refs: https://github.com/libuv/libuv/pull/2762#issuecomment-3065018271
2025-07-16 20:18:29 +02:00