Solaris provides sendmmsg() as of 11.3.32.
It was added at the same time as MSG_WAITFORONE.
The same is seen in Illumos guarded by __BSD_VISIBLE
Fixes: https://github.com/libuv/libuv/issues/4715
Windows provides the `ENABLE_VIRTUAL_TERMINAL_INPUT` flag for TTY input
streams as a companion flag to `ENABLE_VIRTUAL_TERMINAL_PROCESSING`,
which libuv is already setting for TTY output streams.
Setting this flag lets the terminal emulator perform some of the
processing that libuv already currently does for input events,
but most notably enables receiving control sequences that are
otherwise entirely unavailable, e.g. for bracketed paste
(which the Node.js readline implementation added basic support for
in https://github.com/nodejs/node/commit/87af913b66eab78088acfd).
libuv currently already provides translations for key events to
control sequences, i.e. what this mode is intended to provide,
but libuv does not and cannot translate all such events.
Since the control sequences differ from the ones that Windows
has chosen to standardize on, and applications may not be expecting
this change, this is opt-in for now (but ideally will be the default
behavior starting in libuv v2.x, should that ever happen).
Another downside of this change is that not all shells reset
this mode when an application exits. For example, when running a
Node.js program with this flag enabled inside of PowerShell in
Windows terminal, if the application exits while in raw TTY input mode,
neither the shell nor the terminal emulator reset this flag, rendering
the input stream unusable.
While there's general awareness of the problem that console state is
global state rather than per-process (same as on UNIX platforms),
it seems that applications like PowerShell aren't expecting to need to
unset this flag on the input stream, only its output counterpart
(e.g. 4e7942135f/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs (L1156)).
Hence, `uv_tty_reset_mode()` is extended to reset the terminal
to its original state if the new mode is being used.
Refs: 87af913b66
Refs: https://github.com/microsoft/terminal/issues/4954
Extend uv_fs_utime, uv_fs_futime and uv_fs_lutime to accept NAN and
INFINITY, with NAN meaning "don't touch the timestamp" and INFINITY
meaning "set to the current timestamp."
Ugly, but it avoids having to add uv_fs_utime2, etc.
UV_FS_UTIME_NOW and UV_FS_UTIME_OMIT constants have been added to make
it more palatable.
Fixes: https://github.com/libuv/libuv/issues/4665
On macOS, when calling `spawn`, the child process's stdio buffer
size is 8192 bytes. This is due to the AF_UNIX socket buffer size
being 8192 bytes in the XNU kernel.
When large amounts of data are transferred through the child
process's stdio, this buffer size can cause performance issues.
To mitigate this, the buffer size has been increased to 65536
bytes, aligning it with the behavior on Linux.
The CreateProcess API on Windows is still not longPathAware,
even if the process itself is. So, if the cwd used for CreateProcess
is too long, then the call fails with a 'INVALID_DIRECTORY' error.
To deal with this, check the length of the cwd and shorten it if it
is longer than MAX_PATH.
Said symbols are not by default available on Windows Server 2016 but
libuv can still use them when
api-ms-win-core-processthreads-l1-1-3.dll is present.
Fixes: https://github.com/libuv/libuv/issues/4677
This patch will update Android API in CI to 29 and will set up the fdsan
in the test runner.
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
Fixes: https://github.com/libuv/libuv/issues/4369
Replace comparison of `alloc_cb_called` with the total bytes
read (`bytes_read`) to validate the test's correctness.
Fixes: https://github.com/libuv/libuv/issues/4650
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
Add a version of uv_udp_try_send that can send multiple datagrams.
Uses sendmmsg(2) on platforms that support it (Linux, FreeBSD, macOS),
falls back to a regular sendmsg(2) loop elsewhere.
This work was sponsored by ISC, the Internet Systems Consortium.
Shuffle around and DRY the sendmsg logic in preparation for
uv_udp_try_send2(). NFC barring bugs.
This work was sponsored by ISC, the Internet Systems Consortium.
io_uring support was default-disabled because of numerous kernel bugs
but those are all in the sqpoll (file i/o) parts of io_uring.
Batching of epoll_ctl calls through io_uring works fine, is a nice
optimization, and is therefore unconditionally enabled again.
The UV_USE_IO_URING environment variable now only affects sqpoll, and
only when the UV_LOOP_ENABLE_IO_URING_SQPOLL event loop flag is set.
Fixes: https://github.com/libuv/libuv/issues/4616
Libuv looks for "Processor" in /proc/cpuinfo but it's been reported
that on at least some Raspberry Pi models, it's called "model name".
Look for both.
Fixes: https://github.com/nodejs/node/issues/56105
Upgrade GHA image to Ubuntu 24.04 and use the distro-provided qemu.
It should not be necessary anymore to install qemu from .deb because
the stock qemu is new enough in 24.04.
`uv_thread_setname()` sets the name of the current thread. Different
platforms define different limits on the max number of characters
a thread name can be: Linux, IBMi (16), macOS (64), Windows (32767),
and NetBSD (32), etc. `uv_thread_setname()` will truncate it in case
`name` is larger than the limit of the platform.
`uv_thread_getname()` gets the name of the thread specified by `tid`.
The thread name is copied into the buffer pointed to by `name`. The
`size` parameter specifies the size of the buffer pointed to by `name`.
The buffer should be large enough to hold the name of the thread plus
the trailing NUL, or it will be truncated to fit.
This commit introduces the `uv_thread_detach` for thread detaching,
allowing threads to be detached state on both UNIX and Windows platforms.
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
For any API that takes a buffer and size pointer, check both pointers
and the pointed-to size and return UV_EINVAL in case of error.
Example:
```
int uv_foo(char* buffer, size_t* size) {
if (buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL;
...
}
```
In order to "peek" the necessary size for dynamic allocation, the
following pattern can be used:
```
char *buf;
char scratch[1];
size_t len = sizeof(scratch);
int r;
r = uv_foo(scratch, &len);
assert(r == UV_ENOBUFS);
buf = malloc(len);
r = uv_foo(buf, &len);
...
```
Requires updating the android builder, since the arm emulator is
deprecated and unavailable now. Switch to using a Github Action plugin
instead of a container, so that hopefully future updates will be
delivered via that channel instead.
Changed the idna test since printf returns EILSEQ for some byte
sequences in the format on Android in glibc. We don't fully understand
the cause, but we can avoid that by not asking it to reencode the bytes
in the current locale settings.
The compile-time detection check from commit 7b75935 ("kqueue: use
EVFILT_USER for async if available") was not being used, breaking
numerous operating systems. This commit hopefully unbreaks them.
Fixes; https://github.com/libuv/libuv/issues/4608
Signed-off-by: Jeffrey H. Johnson <trnsz@pobox.com>
uv_wtf8_length_as_utf16() checks if codepoints are > 0xFFFF (to see if
it should be encoded as a surrogate pair), therefore uv_wtf8_to_utf16()
should too. Instead it checked > 0x1000. Harmonize the checks.
Fixes: https://github.com/nodejs/node/issues/55914
Establishes a user event for kqueue to eliminate the overhead
of the pipe and the system call read(2) per wakeup event.
Relands commit 27134547ff using VSCode merge, since it shows the
conflict is just on the order of #ifdef calls.
Co-authored-by: Andy Pan <panjf2000@gmail.com>
Fixes a deprecation warning with new cmake versions.
Changing the minimum from 3.9 to 3.10 should be safe because there isn't
even a non-EoL'd distro left that ships 3.10, let alone 3.9.
Fixes: https://github.com/libuv/libuv/issues/4603
It happens due to the default firewall configuration on macOS >= 13.
Note: GH action runners have their firewall disabled, and yet, the test
fails all the same. Oh well...
Closes: https://github.com/libuv/libuv/issues/4263
Changes since version 1.49.1:
* win,fs: remove trailing slash in junctions (Hüseyin Açacak)
* Revert "linux: eliminate a read on eventfd per wakeup" (Ben Noordhuis)
* win: Fix linked list logic in getaddrinfo (Thad House)
* win: fix compilation against Windows 24H2 SDK (Thad House)
* win: remap ERROR_NOACCESS and ERROR_BUFFER_OVERFLOW (Jameson Nash)
* win,fs: match trailing slash presence in junctions to user input
(Jameson Nash)
It seemed incorrect to map a segfault to EACCES, since posix would typically
map this to EFAULT. The ERROR_BUFFER_OVERFLOW is literally "the filename is too
long", and is not typically an invalid parameter in posix.
Test originally added in #1060 to test the API, not the value.
This reverts commit e5cb1d3d3d.
Reason: bisecting says it breaks dnstap.
Also revert commit 27134547ff ("kqueue: use EVFILT_USER for async if
available") because otherwise the first commit doesn't revert cleanly,
with enough conflicts in src/unix/async.c that I'm not comfortable
fixing those up manually.
Fixes: https://github.com/libuv/libuv/issues/4584
Make sure `UV__SOLARIS_11_4` is not set for `smartOS`/`illumOS`. In our
codebase is used only twice:
- Detect correct implementation of `SO_REUSEPORT`, which is not even
implemented on `illumOS`.
- Detect the time unit used for the TCP keepalive options. If set to
`0`, which was the case for `illumOS`, it chose milliseconds, which is
not correct for `illumOS` either as it uses seconds.
The implementation of IPC pipe in libuv on Windows does not properly support
async reading. This means we cannot set the more parameter without likely
causing hangs. Sorry this is yet another followup to #4511.
Fixes#4548
After commit 18266a6969, it changed to return `ENOTDIR`, which makes it
consistent with other platforms but it also can be considered a breaking
change.
Route ftruncate() system calls through io_uring instead of the thread
pool when the kernel is new enough to support it (linux >= 6.9).
This commit harmonizes how libuv checks if the kernel is new enough.
Some ops were checking against `uv__kernel_version()` directly while
others stored the result of the version check as a feature flag.
Because the kernel version is cached, and because it is more direct
than a feature flag, I opted for the former approach.
Introduced in Linux 6.6, it tells the kernel to omit the sqarray from
the ring buffer.
Libuv initalizes the array once to an identity mapping and then forgets
about it, so not only does it save a little memory (ca. 1 KiB per ring)
but it also makes things more efficient kernel-side because it removes
a level of indirection.
Delete the fs_event_error_reporting test. It fails in different ways,
most frequently on the TSan sanitizer buildbot, due to running out of
file descriptors when that is not expected, or vice versa, *not*
running out of file descriptors when that *is* expected.
The test creates a large number of event loops and expects to,
eventually, hit EMFILE but it sometimes hits it too early, and
sometimes not at all.
I don't think TSan is really responsible here, it just makes the
invalid assumption in the test itself more visible.
Fixes: https://github.com/libuv/libuv/issues/4368
Libuv stores the `struct termios` for use inside uv_tty_reset_mode().
Node.js uses said function to restore the tty to its original mode
on SIGINT or SIGTERM, when there is no opportunity to shut down the
process normally.
Track uv_tty_t handle closing, otherwise we might be trying to use a
stale termios.
The current solution is not ideal because there can be multiple handles
that refer to the same tty/pty and, for various reasons, we can't really
determine when we close the last handle. The last handle may not even be
inside the current process.
Still, all things considered, it's probably (hopefully!) an improvement
over the status quo.
Refs: https://github.com/libuv/libuv/issues/4398
Yet another followup to #4511. The functional/legacy/increment_spec.lua
test failed most of the time without this, and passes consistently with
it. It seemed unexpected this code path gets reached (perhaps imply
that the user wrote zero bytes?), but good to fix of course.
Fixes commit 58dfb6c89b from a few days ago. DWORD_PTR is 32 bits on
x86 Windows. Use the right bit count when checking the population count.
Interestingly enough, it manifested itself as double counting online
processors, presumably because the compiler emits a ROR instead of SHR.
Fixes: https://github.com/libuv/libuv/issues/4524
Use GetProcessAffinityMask() to estimate the available parallelism.
Before this commit, it simply used the number of available CPUs.
Fixes: https://github.com/libuv/libuv/issues/4520
In #4470, I accidentally copied the bug from unix, where calling
uv_stream_set_blocking can cause the whole process to hang on a read.
However, unlike unix, where libuv attempts to set the O_NONBLOCK flag in
uv_pipe_open (as long as the handle never gets passed to uv_spawn), the
NT kernel is not capable of enabling OVERLAPPED operation later (but
fortunately, it also cannot disable it later too).
This implementation might be good to copy to unix (using FIONREAD) to
address the same bug that happens there if the user has called uv_spawn
or uv_stream_set_non_blocking on this handle in the past.
Establishes a user event for kqueue to eliminate the overhead
of the pipe and the system call read(2) per wakeup event.
---------
Signed-off-by: Andy Pan <i@andypan.me>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Autobinding is a feature that lets the kernel pick a name for the
abstract socket, instead of userspace having to provide one.
Two bugs that this change exposed are also fixed:
1. strlen(sa.sun_path) can read past the end if the file path is exactly
sizeof(sa.sun_path) long (use memchr instead), and
2. don't return UV_ENOBUFS for abstract sockets when the buffer is
exactly large enough to hold the result; per commit e5f4b79809,
abstract socket names are not zero-terminated
Refactor / cleanup arithmetic for unix -> win filetime conversion
in order to avoid multiplication overflow.
Fixes:
```
src/win/fs.c:106:48: runtime error: signed integer overflow: 1702781567 * 10 cannot be represented in type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/win/fs.c:106:48 in
```
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
The SQPOLL io_uring instance wasn't providing consistent behaviour to
users depending on kernel versions, load shape, ... creating issues
difficult to track and fix. Don't use this ring by default but allow
enabling it by calling `uv_loop_configure()` with
`UV_LOOP_ENABLE_IO_URING_SQPOLL`.
MSVC does not actually support ubsan. There is a long-standing ticket
requesting this:
https://developercommunity.visualstudio.com/t/add-support-for-ubsan/840750
There are no known compilers that currently accept the
`/fsanitize=undefined` spelling. clang-cl accepts `-fsanitize...`,
same as regular clang.
Also passes no-sanitizer-recover so that tests actually fail.
Fix various ubsan-detected errors, including:
* win: fix req-inl.h ubsan failure
Don't use CONTAINING_RECORD macro from WinSDK, as it doesn't use the
right trick which avoids member access on null pointer.
Fixes:
```
src/win/req-inl.h:86:10: runtime error: member access within null pointer of type 'uv_req_t' (aka 'struct uv_req_s')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior D:/a/libuv/libuv/src/win/req-inl.h:86:10
```
* test: fix ubsan failure on udp_ref3
Don't call functions through different function type.
Fixes:
```
src/win/udp.c:537:5: runtime error: call to function req_cb through pointer to incorrect function type 'void (*)(struct uv_udp_send_s *, int)'
test\test-ref.c:66: note: req_cb defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/win/udp.c:537:5 in
```
* win: fix process-stdio.c ubsan failure
When accessing HANDLEs within the stdio buffer, use memcpy / memset in order to respect alignment.
Fixes:
```
src/win/process-stdio.c:197:5: runtime error: store to misaligned address 0x0230ee72d107 for type 'HANDLE' (aka 'void *'), which requires 8 byte alignment
0x0230ee72d107: note: pointer points here
00 00 cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd fd fd fd fd
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/win/process-stdio.c:197:5 in
```
* win: fix getaddrinfo.c ubsan failure
Reworks buffer alignment handling to respect requirements.
Fixes:
```
src/win/getaddrinfo.c:157:23: runtime error: member access within misaligned address 0x0290e4c6a17c for type 'struct addrinfo', which requires 8 byte alignment
0x0290e4c6a17c: note: pointer points here
00 00 00 00 cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd cd
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/win/getaddrinfo.c:157:23 in
```
* win: fix pipe.c ubsan failure
Changes "random" representation from pointer to number.
Fixes:
```
src/win/pipe.c:234:11: runtime error: applying non-zero offset to non-null pointer 0xffffffffffffffff produced null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/win/pipe.c:234:11 in
```
* unix: fix stream.c ubsan failure
Avoids performing pointer arithmetic on null pointer.
Fixes:
```
src/unix/stream.c:701:15: runtime error: applying zero offset to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/runner/work/libuv/libuv/src/unix/stream.c:701:15 in
```
This fixes a race condition if multiple threads are reading from the
same NamedPipe, which could previously lead to a deadlock situation. We
also substantially improve performance now also, since the PeekFile
call is unnecessary overhead with this change. This API was added in
Windows Vista.
Related to #4467, though doesn't address any of the problems there. I
believe that someone could now implement uv__pipe_try_write using
this same code pattern however.
Windows added a new API for file information, which doesn't have to
open the file thus greatly improving performance:
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfileinformationbyname
The stat functions are already covered by tests, so no test was added
here. I considered comparing the result of old and new code, but that
would require exposing internal fs functions, and we would be testing
Windows functionality, not libuv.
Register the eventfd with EPOLLET to enable edge-triggered notification
where we're able to eliminate the overhead of reading the eventfd via
system call on each wakeup event.
When the eventfd counter reaches the maximum value of the unsigned 64-bit,
which may not happen for the entire lifetime of the process, we rewind the
counter and retry.
This optimization saves one system call on each event-loop wakeup,
eliminating the overhead of read(2) as well as the extra latency
for each epoll wakeup.
If the corresponding environment variables are empty, the
uv_us_homedir() and uv_os_tmpdir() return garbage values. The reason
for this situation is the Windows API which doesn't return an error
even if the path is empty.
This PR fixes this problem by checking the return value of the API
call. If it is not an error and the length of the value is less than 3,
uv_us_homedir() and uv_os_tmpdir() will return UV_ENOENT.
Fixes: https://github.com/libuv/libuv/issues/2328
Under rare but benign circumstances (on XNU), incoming datagrams appear
to be dropped by the operating system after libuv has been notified of
their arrival but before libuv has had a chance to receive them.
Fixes: https://github.com/libuv/libuv/issues/4219
This was incorrectly mapped originally, which makes for confusing error
messages about an EPIPE if a program happens to (unwisely) set PIPE_WAIT
on the handle. It is unclear to me if libuv should try to handle this in
some meaningful way, and very unclear what that way would look like, but
at least expose this to the caller with the correct errno translation.
It's complaining in the post-run step about a missing symbol:
/__e/node20/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version
`GLIBC_2.28' not found (required by /__e/node20/bin/node)
For now pin actions/checkout to node 16.
CreateProcessW() in uv_spawn() on Windows will fail with
ERROR_BAD_EXE_FORMAT if attempting to run a file that is not
an executable.
Refs: https://github.com/libuv/libuv/issues/2348
On IBM AIX (and PASE for IBM i), use st_timespec_t
when _XOPEN_SOURCE>=700 and _ALL_SOURCE is defined.
Signed-off-by: Jeffrey H. Johnson <trnsz@pobox.com>
This commit changes the timestamps in the file, the ownership and the
group.
Fixes: https://github.com/libuv/libuv/issues/3125
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
Should hopefully make it easier to debug CI flakiness because
currently the test sometimes fails without a clear indication why.
Refs: https://github.com/libuv/libuv/issues/4106
Make it less likely for the thread-local error value to get
clobbered between performing the operation and checking the result.
Refs: https://github.com/libuv/libuv/issues/4338
The file descriptor leak in the inner path was pointed out by @theanarkh
and I subsequently spotted another one in the outer loop. Rewrite the
function to process all control messages.
Refs: https://github.com/libuv/libuv/pull/4357
Benchmarking shows that sendmsg() is persistently around 1% faster for
single datagrams, and that kind of stands to reason because there is
less setup overhead, and the kernel has to copy in less data.
Fixes: https://github.com/libuv/libuv/issues/4320
uv_udp_init() creates the UDP socket lazily but to set socket options
there must be, well, a socket to set the options on. Document how and
when that requirement is met.
Fixes: https://github.com/libuv/libuv/issues/4370
Perform EPOLL_CTL_DEL immediately instead of going through
io_uring's submit queue, otherwise the file descriptor may
be closed by the time the kernel starts the operation.
Fixes: https://github.com/libuv/libuv/issues/4323
I removed the fallback code back in October but it prevents Node.js
from upgrading libuv in their v20.x release line because they support
systems older than we do. Bring back a dlsym-based fallback path.
Fixes: https://github.com/libuv/libuv/issues/4332
The kernel that ships with the new Ubuntu 22.04 CI image seems to have a
PIE slide that is bigger than the sanitizer runtimes can handle.
It makes ASan fail with thousands of "AddressSanitizer:DEADLYSIGNAL"
warnings, and MSan error with complaints about memory accesses outside
known ranges. Disabling address space layout randomization fixes both.
This commit also fixes a small bug in the platform_output test where
the cgroups v1 logic did not handle the "unlimited quota" special case
properly. Ubuntu 20.04 still uses cgroups v1.
It might happen that only using `WaitForSingleObject()` with timeout 0
could return WAIT_TIMEOUT as the process might not have been signaled
yet. To improve things, first use `GetExitCodeProcess()` and check
that `status` is not `STILL_ACTIVE`. Then, to cover for the case that the exit
code was actually `STILL_ACTIVE` use `WaitForSingleObject()`. This could
still be prone to the race condition but only for that case.
According to the documentation for Cygwin, the penultimate field
of /proc/pid/stat corresponds to the RSS, so the method is basically
the same as in the Linux version. The only difference is that getpagesize()
will return wincap.allocation_granularity(), but in this mapping, RSS is
calculated using wincap.page_size(), which can be accessed by sysinfo.mem_unit.
uv_available_parallelism does not handle container cpu limit
set by systems like Docker or Kubernetes. This patch fixes
this limitation by comparing the amount of available cpus
returned by syscall with the quota of cpus available defined
in the cgroup.
Fixes: https://github.com/libuv/libuv/issues/4146
It's been reported that creating many event loops introduces measurable
overhead now that libuv creates an sqpoll-enabled ring.
I don't really see any change in CPU time with or without this change
but deferring ring creation until it's actually used seems like a good
idea, and comes with no downsides that I can think of, so let's do it.
Fixes: https://github.com/libuv/libuv/issues/4308
Add a process options flag to enable the optional behavior. Most users
are likely recommended to set this flag by default, but it was deemed
potentially breaking to set it by default in libuv.
Co-authored-by: Kyle Edwards <kyle.edwards@kitware.com>
Since `io_uring` support was added, libuv's signal handler randomly
segfaults on ppc64 when interrupting `epoll_pwait`. Disable it
pending further investigation.
Issue: https://github.com/libuv/libuv/issues/4283
Solaris claimed it supported the TCP-Alives mechanism,
but TCP_KEEPIDLE, TCP_KEEPINTVL, and TCP_KEEPCNT were not
available on Solaris until the latest version 11.4.
Therefore, we need to simulate the TCP-Alives mechanism on
other platforms via TCP_KEEPALIVE_THRESHOLD + TCP_KEEPALIVE_ABORT_THRESHOLD.
The clangd index, before creating the `compile_commands.json` file will
create the indexes under a `.cache` folder. This does not need to be
tracked by the repo.
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
The `\0` character has no special significance in abstract sockets, so
the addrlen field in both `bind()` and `connect()` should take that into
account.
Calling `uv_timer_start(h, cb, 0, 0)` from a timer callback resulted in
the timer running immediately because it was inserted at the front of
the timer heap.
If the callback did that every time, libuv would effectively busy-loop
in `uv__run_timers()` and never make forward progress.
Work around that by collecting all expired timers into a queue and only
running their callback afterwards.
Fixes: https://github.com/libuv/libuv/issues/4245
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
On IBM i this test fails asserting the write queue size.
The test expects the queue size to be greater than 0 but
the queue size is 0 on IBM i.
66160d6973/test/test-tcp-write-in-a-row.c (L75)
The test expects the write to get queued because the size of the data
is larger than the send and receive buffers.
66160d6973/test/test-tcp-write-in-a-row.c (L39-L40)
For some reason the request does not seem to get queued on IBM i.
The root cause of the issue will need further investigation.
Part of #4143
Introduced long ago for old Linux/libc flavors libuv no longer supports.
We include <ifaddrs.h> unconditionally elsewhere so there is no point in
special-casing it here.
Fixes: https://github.com/libuv/libuv/issues/4242
On Fedora's build system, the build environment runs on btrfs. This
revealed a bug in the test on i686 systems, where this comparison was
being performed as a comparison of two signed integers, but the
filesystem type of btrfs happens to use the higher-order bits, resulting
in it appearing as a negative value.
BTRFS_SUPER_MAGIC 0x9123683e
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
Passing a socket name without a trailing nul byte to uv_pipe_bind2() or
(on Windows) uv_pipe_connect2() resulted in reading beyond the end of
the name buffer when copying or converting it.
Fix that by copying the socket name to temporary storage first and add
the trailing nul byte explicitly.
Add a check for embedded nul bytes in the socket name.
Fix a small memory leak in the Windows error path of uv_pipe_bind2().
There is no length at which this gets truncated on Windows. The
underlying file system will just not successfully connect to a longer
path (in WTF-16 characters), which will return an error asynchronously
with the existing API.
Refs: #4040
This was incorrectly dropped by #4030, where previously connecting to ""
might fail eventually, now instead it would return EINVAL and then fail
to initialize the struct or call the callback.
Add uv_thread_setpriority for setting priority for threads created by
uv_thread_create. Add uv_thread_getpriority for getting thread priority.
For Linux by default, if the scheduling policy is SCHED_OTHER and the
priority is 0, we need to set the nice value.
Fixes: https://github.com/libuv/libuv/issues/4051
Passing this to uv__is_ipv6_link_local() is causing a segmentation
fault. Note that the documentation for getifaddrs() explicitly states
that this value may be NULL.
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
I suggested in https://github.com/libuv/libuv/pull/4182 to add the flag
to configure.ac as well but seems we already link to it.
I've removed the first one, not the second one, in case libuv is linked
with --as-needed.
uv_run_tests.exe fails to start up with exit code 0xC0000135 a.k.a.
STATUS_DLL_NOT_FOUND, suggesting it cannot find the ASAN runtime
libraries. Disable the buildbot until we figure out how to fix that.
Refs: https://github.com/libuv/libuv/issues/4210
Changes since version 1.46.0:
* test: fix license blurb (Ben Noordhuis)
* linux: fix harmless warn_unused_result warning (Shuduo Sang)
* darwin: fix build warnings (小明)
* linux: don't use io_uring on pre-5.10.186 kernels (Ben Noordhuis)
* fs: fix WTF-8 decoding issue (Jameson Nash)
* test: enable disabled tcp_connect6_error_fault (Ben Noordhuis)
* test: enable disabled fs_link (Ben Noordhuis)
* test: enable disabled spawn_same_stdout_stderr (Ben Noordhuis)
* linux: handle UNAME26 personality (Ben Noordhuis)
* build: move cmake_minimum_required version to 3.9 (Keith Winstein)
* unix: set ipv6 scope id for link-local addresses (Ben Noordhuis)
* unix: match kqueue and epoll code (Trevor Norris)
* win,spawn: allow `%PATH%` to be unset (Kyle Edwards)
* doc: switch to Furo, a more modern Sphinx theme (Saúl Ibarra Corretgé)
* darwin: make TCP_KEEPINTVL and TCP_KEEPCNT available (小明)
* win,fs: avoid winapi macro redefinition (Brad King)
* linux: add missing riscv syscall numbers (michalbiesek)
* doc: fix broken "Shared library" Wikipedia link (Alois Klink)
* unix: get mainline kernel version in Ubuntu (Santiago Gimeno)
* unix: get mainline kernel version in Debian (Ben Noordhuis)
* build: fix qemu install in CI-unix workflow (Santiago Gimeno)
* unix: disable io_uring close on selected kernels (Santiago Gimeno)
* test: skip tests when ipv6 is not available (Santiago Gimeno)
* ibmi: implement ifaddrs, getifaddrs, freeifaddrs (Abdirahim Musse)
* unix: reset signal counters after fork (SmorkalovG)
* win,process: avoid assert after spawning Store app (Jameson Nash)
* unix: remove pread/preadv conditionals (Ben Noordhuis)
* unix: remove pwrite/pwritev conditionals (Ben Noordhuis)
* darwin: remove workaround for data corruption bug (Ben Noordhuis)
* src: default to stream=stderr in handle printer (Ben Noordhuis)
* test: switch to new-style ASSERT_EQ macros (Pleuvens)
* zos: correctly get cpu model in uv_cpu_info() (jolai)
* test: fix get_passwd2 on IBM i (Abdirahim Musse)
* unix: don't malloc on sync uv_fs_read (Ben Noordhuis)
* freebsd: get fs event path with fcntl(F_KINFO) (David Carlier)
* test: switch from ASSERT_* to ASSERT_PTR_* (Pleuvens)
* darwin: workaround apple pthread_cond_wait bug (Julien Roncaglia)
* doc: uv_close should be called after exit callback (Pleuvens)
* test: 192.0.2.0/24 is the actual -TEST-NET-1 (prubel)
* unix: add back preadv/pwritev fallback (Ben Noordhuis)
* unix: rename variable for consistency (Ben Noordhuis)
* unix: merge read/write code into single functions (Ben Noordhuis)
* doc: filename arg to uv_fs_event_cb can be NULL (Ben Noordhuis)
* build,win: we need to link against shell32.lib (Per Allansson)
* unix: no preadv/pwritev workaround if not needed (Jeffrey H. Johnson)
* build: add CI for Windows ARM64 (build only) (Per Allansson)
* linux: disable io_uring on 32 bits arm systems (Ben Noordhuis)
* build: run sanitizers on macos ci (Ben Noordhuis)
* misc: export WTF8 conversion utilities (Jameson Nash)
* build: fix libuv.a file name for cmake (Jameson Nash)
* build: add windows ubsan and clang ci (Matheus Izvekov)
* win: improve accuracy of ProductName between arch (Christian Heimlich)
uv_os_uname() on Windows queries the registry value "HKEY_LOCAL_MACHINE\
SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName" to fill
uv_utsname_t. If calling application was compiled for x86 and run on a
x86_64 host, that query is redirected to "Computer\HKEY_LOCAL_MACHINE\
SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\ProductName"
instead.
For whatever reason, the value of 'ProductName' in the 32-bit registry
section on 64-bit Windows sometimes differs from the 64-bit equivalent
value and is inaccurate (e.g. containing the data
"Windows 10 Enterprise" while the 64-bit value accurately contains
"Windows 10 Pro").
Adds the 'KEY_WOW64_64KEY' security descriptor when opening the
appropriate registry key so that the value of ProductName is always
taken from the primary registry on 64-bit systems, regardless of
compiled architecture. The descriptor is safely ignored on 32-bit hosts.
Fixes a detected error: incompatible pointer to integer conversion
passing 'uv_os_fd_t' (aka 'void *') to parameter of type 'SOCKET' (aka
'unsigned long long').
Use upstream llvm to work-around broken VS2022 clang unable to link.
This makes cmake more consistent about how to name this file, otherwise
sometimes it names it uv.lib and sometimes libuv.a depending on which
compiler is selected or if ./configure is used.
Refs: https://github.com/libuv/libuv/pull/2085#issuecomment-1735276640
As promised in #2970, this attempts to migrate code to a common set of
utilities in a common place in the code and use them everywhere. This
also exports the functionality, since the Windows API with
WideCharToMultiByte is fairly verbose relative to what libuv and
libuv's clients typically need, so it is useful not to require clients
to reimplement this conversion logic unnecessarily (and because Windows
is not 64-bit ready here, but this implementation is.)
The workaround for preadv/pwritev is needed only
for Solaris, not illumos, so avoid it on illumos.
Haiku R1/prebeta5 (and later) provide preadv and
pwritev, so only use workaround on lower versions.
Signed-off-by: Jeffrey H. Johnson <trnsz@pobox.com>
The recently added support for minidumps use SHGetKnownFolderPath which
requires shell32.lib - for some reason the builds work without that on
x64, while failing on arm.
Implement in terms of pread/pwrite and only try to read/write the first
buffer. Callers are supposed to handle partial reads and libuv takes
care of partial writes.
(Our own fs_read_bufs test doesn't but that's fine because this commit
is a fix-up for unsupported platforms that aren't in our CI matrix.)
Fixes: https://github.com/libuv/libuv/issues/4176
Under heavy workloads pthread_cond_wait on macOS can return EINVAL while
all the input parameters are correct.
As it happens due to a syscall having an errno of EBUSY we can detect it
and work around it.
Fixes: https://github.com/libuv/libuv/issues/4165
We can use the |bufs| argument directly instead of always copying it
and sometimes heap-allocating it.
The same trick doesn't work for uv_fs_write() because the iterator
mutates the buffers in the list and that's visible to the caller.
Fixes: https://github.com/libuv/libuv/issues/4038
The previous implementation using si11v1cpcmodel did not return a valid
cpu model on z/OS. So use PCCA instead to correctly get the cpu model.
Co-authored-by: Wayne Zhang <shuowang.zhang@ibm.com>
Co-authored-by: Gaby Baghdadi <baghdadi@ca.ibm.com>
Co-authored-by: Jonathan Lai <jonathan.lai@ibm.com>
Fixes: https://github.com/libuv/libuv/issues/4102
Switch from old-style ASSERT macro to new-style ASSERT_EQ,... macros.
Using new-style macros makes it easier to debug test failures
Fixes: https://github.com/libuv/libuv/issues/2974
Make printing handles from gdb a little easier because it doesn't always
know how to locate the stdout or stderr globals from libc.
With this commit `call uv_print_all_handles(0, 0)` prints the handles
from the default loop to stderr.
XNU kernels anno ~2010 had a data corrruption bug where concurrent
write and pwrite calls sometimes resulted in blocks of zeroes being
written instead of the actual data.
Libuv works around that by serializing all writes with a process-wide
mutex, meaning oncurrent writes (for all files, not just single files)
have a concurrency of 1. Obviously that's not great for performance.
Modern day macOS no longer has this bug, so remove the workaround.
Make sure this handle is functional. The Windows kernel seems to have a
bug that if the first use of AssignProcessToJobObject is for a Windows
Store program, subsequent attempts to use the handle with fail with
INVALID_PARAMETER (87). This is possilby because all uses of the handle
must be for the same Terminal Services session. We can ensure it is
tied to our current session now by adding ourself to it. We could
remove ourself afterwards, but there doesn't seem to be a reason to.
Secondly, we start the process suspended so that we can make sure we
added it to the job control object before it does anything itself (such
as launch more jobs or exit).
Fixes: https://github.com/JuliaLang/julia/issues/51461
If a signal was received but was not dispatched before fork then
caught_signals counter should be reset. Closing of signal pipe makes
impossible to receive the signal that was counted.
There is no need in this signal because it was sent to parent process
Fixes: https://github.com/libuv/libuv/issues/3483
Adjust include order to avoid redefining `CTL_CODE`, `FILE_READ_ACCESS`,
and `FILE_WRITE_ACCESS`. Without this, compilation shows:
```
...\um\winioctl.h(273): warning C4005: 'CTL_CODE': macro redefinition
...\src\win\winapi.h(4497): note: see previous definition of 'CTL_CODE'
...\um\winioctl.h(320): warning C4005: 'FILE_READ_ACCESS': macro redefinition
...\src\win\winapi.h(4488): note: see previous definition of 'FILE_READ_ACCESS'
...\um\winioctl.h(321): warning C4005: 'FILE_WRITE_ACCESS': macro redefinition
...\src\win\winapi.h(4492): note: see previous definition of 'FILE_WRITE_ACCESS'
```
Match the implementation for linux.c to kqueue.c in the code around the
calls to kevent and epoll.
In linux.c the code was made more DRY by moving the nfds check up
(including a comment of why it's possible) and combining two if checks
into one.
In kqueue.c the assert to check the timeout when nfds == 0 has been
moved to be called directly after the EINTR check. Since it should
always be true regardless.
Ref: https://github.com/libuv/libuv/pull/3893
Ref: https://github.com/nodejs/node/issues/48490
Link-local addresses (prefix fe80::/64) don't route unless you specify
the network interface to use so make libuv do that.
Fixes: https://github.com/nodejs/node/issues/48846
The test was added in commit e3f2631127 from 2011 but it appears the
author forgot to add it to the test list.
The other test from that commit was enabled by yours truly in 2012 in
7447048981 but apparently I overlooked the second test as well.
Work around a poorly understood bug in older kernels where closing a
file descriptor pointing to /foo/bar results in ETXTBSY errors when
trying to execve("/foo/bar") later on.
The bug seems to have been fixed somewhere between 5.15.85 and 5.15.90.
I couldn't pinpoint the responsible commit but good candidates are the
several data race fixes.
Interestingly, it seems to manifest only when running under Docker so
the possibility of a Docker bug can't be completely ruled out either.
This commit moves uv__kernel_version() from fs.c to linux.c because the
latter now uses it more than the former.
Fixes: https://github.com/nodejs/node/issues/48444
The initial run of timers shouldn't happen if uv_stop() has been run
before uv_run() was called, and for backwards compatibility they also
shouldn't run if they have been unref'd before calling uv_run().
Apple's documentation claims ru_maxrss is reported in kilobytes but the
XNU source code suggests the actual unit is bytes, like macOS.
Fixes: https://github.com/libuv/libuv/issues/4025
Recent versions of gcc have started emitting warnings about the liberal
type casting inside the QUEUE macros. Although the warnings are false
positives, let's use them as the impetus to switch to a type-safer and
arguably cleaner approach.
Fixes: https://github.com/libuv/libuv/issues/4019
The threadpool_multiple_event_loops test already calls RETURN_SKIP when
needed. Remove it from the callback function where it isn't needed work
(nor works) and generates a build warning when compiling for qemu.
Fixes: https://github.com/libuv/libuv/issues/4014
In the case of trying to write more than `IOV_MAX` buffers, the
`IORING_OP_WRITEV` operation will return `EINVAL`. As a temporal fix,
fallback to the old ways. In the future we might implement this by
linking multiple `IORING_OP_WRITEV` requests using `IOSQE_IO_LINK`.
`FreeBSD` defines `ENODATA` in /usr/include/c++/v1/errno.h which is only visible
if C++ is the compilation unit. This can cause interop issues when
integrating libuv build with C on a C++ project. Avoid this issue by
directly defining with the value defined in the file previously
mentioned.
Instead of suppressing the VLA warning, use a fixed-size buffer that is
big enough to receive at least one control message but not so big that
IBMi PASE rejects it.
When there are more than 128 concurrent cq completions the CQ ring
overflows as signaled via the `UV__IORING_SQ_CQ_OVERFLOW`. If this
happens we have to enter the kernel to get the remaining items.
This commit adds the ability to dump core when sending the `SIGQUIT`
signal on Windows. The change reads in the current registry setting for
local dumps, and attempts to write out to that location before killing
the process. See [collecting-user-mode-dumps] for registry and pathing
details. This behavior mimics that of the dumps created by the typical
Windows Error Reporting mechanism.
[collecting-user-mode-dumps]: https://learn.microsoft.com/en-us/windows/win32/wer/collecting-user-mode-dumps
* Revert "macos: fix source not being followed when cloning (#3941)"
This reverts commit 507f2f950d.
* Revert "darwin: bring back macos-specific copyfile(3) (#3654)"
This reverts commit d4eb276eea.
The worker pool calls all callbacks locally within the queue. So the
value of nevents doesn't properly reflect that case. Increase the number
of events directly from the worker pool's callback to correct this.
In order to properly determine if the events_waiting counter needs to be
incremented, store the timeout value at the time the event provider was
called.
The signal_multiple_loops test is flaky when run under AddressSanitizer
and MemorySanitizer. Sometimes thread creation fails, other times it
simply times out.
Fixes: https://github.com/libuv/libuv/issues/3956
Fix a valgrind warning that only manifested with clang (not gcc!) by
explicitly passing 0L instead of plain 0 as the |sigsz| argument to
io_uring_enter(). That is, pass a long instead of an int.
On x86_64, |sigsz| is passed on the stack (the other arguments are
passed in registers) but where gcc emits a `push $0` that zeroes the
entire stack slot, clang emits a `movl $0,(%rsp)` that leaves the upper
32 bits untouched.
It's academic though since we don't pass IORING_ENTER_EXT_ARG and the
kernel therefore completely ignores the argument.
Refs: https://github.com/libuv/libuv/pull/3952
Add io_uring support for several asynchronous file operations:
- read, write
- fsync, fdatasync
- stat, fstat, lstat
io_uring is used when the kernel is new enough, otherwise libuv simply
falls back to the thread pool.
Performance looks great; an 8x increase in throughput has been observed.
This work was sponsored by ISC, the Internet Systems Consortium.
Fixes: https://github.com/libuv/libuv/issues/1947
Don't use a static buffer to hold human-readable "big" numbers.
The buffer isn't big enough for benchmarks like fs_stat that print a
large number of them. Have the caller pass in a buffer instead.
Issue observed on Solaris with ISC BIND 9.18 which reported "unable to
open route socket: unexpected error". illumos did not hit it because it
does not have SO_REUSEPORT (open RFE
https://www.illumos.org/issues/12455)
The last major distro that supported the oabi calling convention was
Debian 5 (Lenny) and that went out of support in February 2012. It seems
like a fairly safe assumption that nothing speaks oabi anymore in this
day and age.
Fixes: https://github.com/libuv/libuv/issues/3935
Replace the throw-type-safety-to-the-wind CAST() macro with an inline
function that is hopefully harder to misuse. It should make the inotify
code slightly more legible if nothing else.
The maximum number of times timers should run when uv_run() is called
with UV_RUN_ONCE and UV_RUN_NOWAIT is 1. Do that by conditionally
calling timers before entering the while loop when called with
UV_RUN_DEFAULT.
The reason to always run timers at the end of the while loop, instead of
at the beginning, is to help enforce the conceptual event loop model.
Which starts when entering the event provider (e.g. calling poll).
Other than only allowing timers to be processed once per uv_run()
execution, the only other noticeable change this will show is if all the
following are true:
* uv_run() is called with UV_RUN_NOWAIT or UV_RUN_ONCE.
* An event is waiting to be received when poll is called.
* Execution time between the call to uv_timer_start() and entering the
while loop is longer than the timeout.
If all these are true, then timers that would have executed before
entering the event provider will now be executed afterward.
Fixes: https://github.com/libuv/libuv/issues/3686
Co-authored-by: Momtchil Momtchev <momtchil@momtchev.com>
Pass the loop to MAKE_VALGRIND_HAPPY() so it's explicit on which loop
needs to be cleaned up. Since it asserts on uv_loop_close(), need to
remove a couple of those that were being done before the call.
Cleanup where loop was assigned, so the entire test either uses loop or
uv_default_loop(). Not both.
Also take care of any reqs that may have been left uncleaned.
This code would previously get confused between rounds of the barrier
being called and a thread might incorrectly get stuck (deadlock) if the
next round started before that thread had exited the current round.
Avoid that by not starting the next round in++ before out-- has reached
zero indicating that all threads have left the prior round.
And fix it that on Windows by replacing the implementation with the one
from unix. There are some awkward platform-specific redirection here
with an extra malloc that is not needed on Win32, but that will be fixed
in libuv v2.
Fixes: https://github.com/libuv/libuv/issue/3872
The call to uv__cwd() always returns a new allocation. The previously
allocated utf16_buffer needs to be free'd before passing it in to
receive the next allocation.
ThreadSanitizer complains about unsynchronized access to the
handle->loop->cf_state pointer.
The warning is probably benign but the fsevents thread already knows
the pointer. It doesn't have to read it, it just needs to propagate it.
Refs: https://github.com/libuv/libuv/issues/3880
The conditional bind-to-port logic in tcp.c had an error path that
closed the socket file descriptor while it was still owned by the
uv_tcp_t handle.
Fix that by not closing the file descriptor and refactoring the code so
it is hopefully harder to get wrong in the future.
The refactoring also makes the code a little flatter, removes duplicated
code, and, arguably, is in a more idiomatic libuv style.
Fixes: https://github.com/libuv/libuv/issues/3461
Replaces: https://github.com/libuv/libuv/pull/3462
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
Remove expectations around uv_cond_timedwait() maximum sleep time.
The OpenBSD buildbot sleeps more than 5x longer than requested. It no
longer makes sense to expect some reasonable upper bound because at that
point we've moved well beyond reasonable.
Fixes: https://github.com/libuv/libuv/issues/3896
Since we are emulating this event, but are not using the pending_queue,
we need to make sure it is accounted for properly. Also DRY some of the
reset_timeout code here.
This was observed to cause a hang in certain rare cases, particularly on
M1 machines.
Do a bit of code cleanup too, since we do not need to initialize the
internal signal handling pipe if it will not be used.
When run under distcheck, the libuv source permissions are read-only,
which makes this test copyfile fail without explicit correction to the
permissions.
ThreadSanitizer's complaints about data races are likely legitimate but
they are pre-existing and not straightforward to fix with the current
design. Something for later.
Refs: https://github.com/libuv/libuv/issues/3681
Legitimate if fairly benign warning: the `stop` global variable was
read and written without proper synchronization; `volatile` isn't
sufficient.
Refs: https://github.com/libuv/libuv/issues/3681
The current fix (libuv#2231) was found to be slow in certain cases. This
change should improve scalabaility a bit by only incurring the spin loop
delay while closing an UV_ASYNC. It also is intended to slightly improve
the behavior after uv_loop_close is called, by parking all of the
pending flags as set, so that it will not access the loop at all (until
the uv_async_t memory is freed, which we leave still to the
responsibility of the user).
Note that this bug appears to still exist on Win32, though it's harder
to address without the refactoring done to this code on libuv master.
Takes some inspiration from https://github.com/libuv/libuv/pull/2654
Takes some inspiration from https://github.com/libuv/libuv/pull/2656
Refs: https://github.com/libuv/libuv/pull/2231
```
warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
note: in expansion of macro 'ASSERT_BASE'
#define ASSERT_EQ(a, b) ASSERT_BASE(a, ==, b, int64_t, PRId64)
warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but
argument 3 has type ‘uint32_t’ {aka ‘unsigned int’}
```
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
GitHub gets confused by the non-standard format of the LICENSE file.
Move the extra bits into the creatively named LICENSE-extra file.
Fixes: https://github.com/libuv/libuv/issues/3875
File system operations may return uid and gid values, which we may want
to pretty-print. We already have the code for getting information for
the current user, so just need to add a parameter to make it exposed for
every user. We expose information about groups in a similar manner also.
In Node.js, fs.readlink() on a non-symlink file used to throw an UNKNOWN
error on Windows. This change maps ERROR_NOT_A_REPARSE_POINT to
UV_EINVAL, so that now it throws EINVAL just like other platforms.
This is handled explicitly in `fs__readlink`, since elsewhere it might
map to EPERM instead (such as in `link`).
On Linux, CPUs can come online or go offline while uv_cpu_info() is busy
gathering data. Change uv_cpu_info() in the following ways:
1. Learn online CPUs from /proc/stat
2. Get the model name from /proc/cpuinfo when it has a matching CPU,
or default to "unknown"
3. Get speed from /sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq
when it exists, or default to 0
Before this commit, libuv read the speed from /proc/cpuinfo but that
reports the base frequency, not the actual frequency. My system has
two cores running permanently at 3.6 GHz but libuv thought all 12 ran
at 2.2 GHz.
Fixes: https://github.com/libuv/libuv/issues/2351
Fixes: https://github.com/libuv/libuv/issues/3858
Increase the timer interval. That hopefully ameliorates the problem of
FSEvents.framework missing events on the macOS CI buildbot.
Not really a fix, more a mitigation.
Fixes: https://github.com/libuv/libuv/issues/3862
As of recent, the fs_partial_read and fs_partial_write tests reliably
fail on that architecture.
An upgrade from Ubuntu 20.04 to 22.04 on the CI machines is suspected,
not any changes in libuv itself.
Perhaps it's possible to work around it in the tests but as Alpha is a
dead architecture, it doesn't seem worthwhile to sink time in that.
Let's remove it from the CI matrix instead.
Fixes: https://github.com/libuv/libuv/issues/3843
Return `UV_EAGAIN` on `ERROR_OPERATION_ABORTED`.
Use the correct format for `overlapped.hEvent`.
Some refactoring to always wait for the overlapped result.
Modernize tests and some improvements.
Calling uv_fs_fstat for file types other then disk type was resulting in
error on Windows while it was retrieving data on Linux. This change
enables getting fstat for pipes and character files on Windows with data
fetched being as reasonable as possible.
A simple test is also added to check this behavior on all platforms. It
uses stdin, stdout and stderr. uv_fs_fstat needs to pass with disk files
pipes and character files (eg. console).
Refs: https://github.com/nodejs/node/issues/40006
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
The old Linux baseline was essentially RHEL 6 but that distro has been
out of support for two years now. Move to RHEL 7.
This commit also moves FreeBSD to tier 2 because it isn't actually
part of libuv's CI matrix, only Node's.
Fixes: https://github.com/libuv/libuv/issues/3822
The following metrics are now always recorded and available via the new
uv_metrics_info() API.
* loop_count: Number of event loop iterations.
* events: Total number of events processed by the event handler.
* events_waiting: Total number of events waiting in the event queue when
the event provider request was made.
Benchmarking has shown no noticeable impact recording these metrics.
PR-URL: https://github.com/libuv/libuv/pull/3749
Make unices and windows consistent when closing a pipe while it's
connecting so they all return `UV_ECANCELED`.
Avoid race condition between `pipe_connect_thread_proc()` and `uv_close()` when
accessing `handle->name`.
Fixes: https://github.com/libuv/libuv/issues/3578
So `WaitNamedPipe()` doesn't fail. Increase the number of clients in
`pipe_connect_multiple` so `CreateFile()` returns `ERROR_PIPE_BUSY` and
the codepath leading to `WaitNamedPipe()` is exercised.
This reverts commit 87f0765159 and
implements a work-around instead. This has been reported to be
unnecessary, and also returns the wrong answer (off by exactly 100x),
so it is not particularly useful.
This also reverts the bugfixes to the original PR:
Revert "darwin: fix iOS compilation and functionality"
This reverts commit 1addf9b88a.
Revert "macos: fix the cfdata length in uv__get_cpu_speed (#3356)"
This reverts commit 1e7074913e.
Revert "darwin: fix -Wsometimes-uninitialized warning"
This reverts commit 6085bcef8d.
Revert "macos: fix memleaks in uv__get_cpu_speed"
This reverts commit d2482ae121.
The expected behavior on failure to read this info is to report 0 (for
example
https://github.com/libuv/libuv/blob/8975c05d199558b0cc2e98f26ce33c6090d1
d7a1/src/unix/linux.c#L834), which is which was not the case before
this PR for macos.
However hw.cpufrequency sysctl seems to be missing on darwin/arm64
(Apple Silicon), so we instead hardcode a plausible value. This value
matches what the mach kernel will report when running Rosetta apps.
Fixes: https://github.com/libuv/libuv/issues/3642
Fixes: https://github.com/libuv/libuv/issues/2911
Refs: https://github.com/libuv/libuv/pull/2912
Backported thread affinity feature and related dependency commits
from master. It will add support for those APIs: uv_cpumask_size,
uv_thread_setaffinity, uv_thread_getaffinity.
The supported platforms are Linux, Freebsd, and Windows.
Empty implementations (returning UV_ENOTSUP) on non-supported platforms
(such as OS X and AIX).
In the old version of uv_pipe_open, the parent process ID is used
always. If the open pipe is used in the same process, the parent
process will be obtained incorrectly.
Now we first get the client pid and compare it with its own pid. If it
is the same, then get the server pid. If the two are the same, then the
pipe is from the same process.
Fixes: https://github.com/libuv/libuv/issues/3766
- unpoison results from linux system call wrappers
- unpoison results from stat/fstat/lstat to pacify clang 14
(fixed in later versions)
- add MSAN build option
- turn on MSAN CI build
I split up linux.c around 2012 for no real reason and now I'm merging
it back together, again for no real reason.
I half-jest. I like the idea of having everything together because I
practically forgot linux-inotify.c existed. It also makes io_uring
experiments a little easier.
Last but not least, it removes about 100 lines of license boilerplate.
preadv, pwritev, dup3 and utimensat all exist in 2.6.32 kernels, libuv's
minimum supported kernel.
The wrapper for utimensat was already gone, only the define remained.
I recently changed it to download a fixed .deb but seems it's updated
more frequently than I anticipated because the dfsg-7ubuntu1_package is
already gone, replaced with dfsg-7ubuntu2.
Bring back the downloader logic that fetches the filename from the
directory listing.
uv_fs_scandir() leaked an entry when you called it on a directory with
a single entry _and_ you didn't run the iterator until UV_EOF.
Fixes: https://github.com/libuv/libuv/issues/3748
epoll.c is only used on Android and Linux after commit 5fe59726 ("sunos:
restore use of event ports") so move it back into linux-core.c
This commit removes a workaround for pre-2.6.27 kernels that don't have
the epoll_create1() system call.
Remove the TODO that says to batch up kevent(EV_DELETE) system calls.
It's unduly complicated in case of errors.
If you pass an out array to kevent(), it will store error records that
tell you which file descriptor caused the error but it also stores new
events in the array, complicating state management.
If you don't pass an out array, it simply doesn't tell you anything
except that _something_ failed. Optimistically trying batch deletion
and falling back to one-by-one deletion is probably possible but is
something of a deoptimization and also feels somewhat dangerous.
macOS has a mostly-undocumented kevent_qos() system call that accepts a
KEVENT_FLAG_ERROR_EVENTS flag that fixes the first problem but that of
course isn't portable.
Long story short, it seems like too much hassle for too little payoff.
Libuv has been doing one-by-one deletion for over a decade now and no
one complained about performance so far so let's just stick with that.
Dynamic loading with musl only works with libc.so because it is
is implemented in musl's dynamic linker, not in libc proper.
libc.a contains just a stub dlopen() that always fails with a "Dynamic
loading not supported" error message. Update the test to handle that.
Fix: https://github.com/libuv/libuv/issues/3706
Another thread can change the working directory between calls to
GetCurrentDirectoryW().
The first call was used to determine the size of the buffer to use in
the second call. Retry if the reported size does not match the expected
size because the buffer's contents is undefined in that case.
uv_exepath() wrote the nul byte *after* the end of the buffer. It's not
necessary to write said nul byte in the first place because that was a
workaround for a bug in the Windows XP version of GetModuleFileName().
Fix uv_cwd() in the same fashion, it doesn't need the nul byte either.
Fixes: https://github.com/libuv/libuv/issues/3691
After analysis of many real-world programs I've come to conclude that
accepting in a loop is nearly always suboptimal.
1. 99.9% of the time the second accept() call fails with EAGAIN, meaning
there are no additional connections to accept. Not super expensive
in isolation but it adds up.
2. When there are more connections to accept but the listen socket is
shared between multiple processes (ex. the Node.js cluster module),
libuv's greedy behavior necessitated the UV_TCP_SINGLE_ACCEPT hack
to slow it down in order to give other processes a chance.
Accepting a single connection and relying on level-triggered polling to
get notified on the next incoming connection both simplifies the code
and optimizes for the common case.
This was a kludge for a bug in old versions (API level <= 16) of the
Android SDK.
The os390 port had a build dependency on the file but does not actually
use it so that too has been removed.
Split this off from endgame, so that it can be handled separately and
earlier, rather than trying to detect inside endgame which case we are
in. There appear to be some race conditions on the `handle` field still
however, which this does not yet attempt to address.
Some setsockopt() implememantations may return with errno of EINVAL
when the socket has been shut down already, as documented in the
Open Group Specifications Issue 7, 2018.
When this happens, reset errno and continue to mark the socket closed
and handle any callback.
Port the changes made to AIX and other unix systems in #611 to z/OS.
Defers the signal watcher that is used for process management until
after the dispatch of regular i/o watchers.
Refs: https://github.com/libuv/libuv/pull/611
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
Once the write queue is empty, we can fire the event immediately,
without needing a lot of syscalls and then waiting for the kernel to
feed us the event on the next tick. This also makes it more similar to
how it would behave if there was a write still in the queue also, which
we dispatch later in the same event loop iteration, then drain.
EINTR is explicitly documented as a possible error code of tcsetattr().
The documentation for tcgetattr() is silent on the subject but better
safe than sorry.
Fixes: https://github.com/libuv/libuv/issues/3645
The UV_ECANCELED codepath had an incorrect comment, and the
implementation was generally less robust (for example, not checking if
`cb` was NULL), so we can merge these codepaths for cleaner code.
The errno value is only meaningful if bind() fails and returns -1.
Some bind() implementations may return success but modify errno value
internally, like the socket_wrapper library used by the Samba testsuite.
This fixes an early exit bug in z/OS implementation of epoll_wait(),
resulting in some file events not being correctly captured.
The problem is that reventcount should only be incremented by 1, because
_NFDS counts as 1 even for fds with multiple revents set.
Also makes a few minor improvements to remove redundant checks.
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
Fixes an issue where under certain conditions, dynamically allocated
ip addresses, strings, and buffers were either leaking memory, being
incorrectly freed, or not performing error checks.
Also fixes an issue where the uv_interface_address_t struct was not
correctly initialized to 0, so use calloc() instead of malloc().
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
Use SIOCGIFNETMASK ioctl to retrieve the netmask for IPv4. However, this
approach is not supported for IPv6.
For IPv6 netmask, z/OS currently only provides the prefix length through
the __nif6e_prefixlen in __net_ifconf6entry_t struct, but this can be
used to calculate the IPv6 netmask similar to android implementation.
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
On z/OS, the interface address name contains EBCDIC and may be padded
with whitespaces. The whitespace padding needs to be trimmed, and the
interface address name needs to be converted from EBCDIC to ASCII.
Co-authored-by: John Barboza <jbarboza@ca.ibm.com>
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
On z/OS, fs events are implemented by registering file interest. When
closing a fs event handle, it's possible that a change notification has
already been generated. In that case, the attempt to unregister file
interest will fail with EALREADY. This will result in the fs event being
delivered even though the handle is closing, which should not happen.
Fixes: https://github.com/libuv/libuv/issues/3601
On z/OS, EPERM is returned if the process being killed is a zombie.
However, this shouldn't be treated as an error, so return 0 instead.
Co-authored-by: Muntasir Mallick <mmallick@ca.ibm.com>
Co-authored-by: Gaby Baghdadi <baghdadi@ca.ibm.com>
On NetBSD with libuv 1.44.1 we see that cmake occasionally hangs
waiting for a child process to exit, with libuv waiting forever for
`kevent` to deliver more events that never come. The child process has
already exited and is waiting to be collected with `waitpid`.
The hang occurs when the batch of events returned by one call to
`kevent` contains both a EVFILT_READ event for an fd and a later
EVFILT_PROC record for the PID with the same value as the earlier fd.
What happens is that `uv__platform_invalidate_fd` is called to
invalidate events later in the same batch for the fd, but
`uv__platform_invalidate_fd` invalidates the later EVFILT_PROC event
too because it sees the same "ident" value and does not check the
"filter" value to differentiate "ident" values that refer to fds vs.
"ident" values that refer to PIDs.
Add a check for the "filter" value to avoid confusing these two
different kinds of event "ident" values.
Previously, Windows would always defer event processing to the loop
after they were received. This could cause confusion for users who were
using prepare and idle callbacks, as seen from this bug in nodejs[^1] and
this discussion in libuv[^2], and even some discrepancies in the libuv
tests too[^3].
[^1]: https://github.com/nodejs/node/pull/42340
[^2]: https://github.com/libuv/libuv/discussions/3550
[^3]: See change to test-spawn.c in this PR
So rather than declare those usages to be wrong, we change libuv to meet
those users expectations.
Replaces: https://github.com/libuv/libuv/pull/3585
If `uv_close` was called while a connect was pending, we would fail to
release the resources for the connection, since we had not yet set the
type of the struct.
Fix a thread data-race on slow connect path code: only permitted to
write to `req` on threads, as anything else causes data race
corruption.
There seemed be a small variety of other resource management bugs in
edge cases, which turned out to make this a lot larger than initially
expected.
Refs: https://github.com/libuv/libuv/pull/3598#issuecomment-1111513567
This test has always been disabled for the 10 years of its existence and
there are other tests that exercise "what happens when" event ordering.
Fixes: https://github.com/libuv/libuv/issues/3618
Use MSG_CMSG_CLOEXEC on Unix-y platforms that support it (all except
macOS and SunOS spawn.)
Remove the feature test for Linux. Libuv's kernel baseline is 2.6.32
and MSG_CMSG_CLOEXEC was added in 2.6.23.
Use libtoolize --force to ensure it updates m4 directory with the
latest files. Add an option "release" to the autogen.sh script that
checks the versions of the input tools, so that we know they are always
using the latest version for each release.
macOS 10.15 has a bug where configuring the working directory with
posix_spawn_file_actions_addchdir_np() makes posix_spawnp() fail with
ENOENT even though the executable is spawned successfully.
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
When the watched file is moved or removed, or an editor (e.g. vim)
renames then creates the file, the __rfim_event 156 occurs. This is an
undocumented event that should not happen, but register it as UV_RENAME
for now since it is functionally equivalent.
Co-authored-by: Gaby Baghdadi <baghdadi@ca.ibm.com>
`rename()` can be used to rename a file path via _RFIM_UNLINK. So
register it as a UV_RENAME event.
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
The file is implicitly unregistered when the change notification is
sent, only one notification is sent per registration. So we need to
re-register interest in a file after each change notification we
receive.
Co-authored-by: Gaby Baghdadi <baghdadi@ca.ibm.com>
On illumos and Solaris, fs events are implemented with
PORT_SOURCE_FILE type event ports. These are one-shot so
need re-arming each time they fire. Once they are armed
and an event occurs, the kernel removes them from the current
cache list and puts them on an event queue to be read by
the application.
There's a window in closing one of these ports when it could
have triggered and be pending delivery. In that case, the
attempt to disarm (dissociate) the event will fail with ENOENT
but libuv still goes ahead and closes down the handle. In
particular, the close callback (uv_close() argument) will be
called but then the event will subsequently be delivered if
the loop is still active; this should not happen.
This commit adds the support for a custom strtok implementation, which
is reentrant. On some systems strtok_r or strstep is available for that
purpose; however, since these are an extension, it is difficult to
control if it will be available on every supported system.
Remove the `TARGET_OS_IPHONE` ifdef to include posix spawn headers for
iOS build. Previously https://github.com/libuv/libuv/pull/3257
introduced posix spawn with \_\_APPLE\_\_ platform only, which resulted
in a number of spawn related definitions not found for iOS (such as
`uv__posix_spawn_fncs_tag`).
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Although the change remapped the error code to the correct one, a lot of
code already depends on the incorrect one, so it's not worth the
breakage.
This reverts commit 04a35efe69.
Refs: https://github.com/nodejs/node/pull/42340
Signed-off-by: Darshan Sen <raisinten@gmail.com>
Define _GNU_SOURCE and link against libdl for dlopen.
Link to freebsd-glue for cmake builds.
This was previously fixed for Makefile builds in
c5d2bf12f7
Using autoconf 2.71 and automake 1.16.5 the CFLAGS from
CC_CHECK_CFLAGS_APPEND does not get set in the Makefile without AC_SUBST
causing compilation to fail on Solaris due to missing -std=gnu89
Github Actions will already hide the output, so we don't need to also
suppress the output. That can sometimes hide problems that might have
only been visible on inspection.
Bug #3504 seems to affect more platforms than just OpenBSD. As this
seems to be a race condition in these kernels, we do not want to fail
because of it. Instead, we remove the WNOHANG flag from waitpid, and
track exactly which processes have exited. Should also be a slight speed
improvement for excessively large numbers of live children.
Now that uv__cloexec_fcntl() is simplified
(https://github.com/libuv/libuv/pull/3492), there is no benefit to
maintaining duplicate code paths for the same thing.
We can save a syscall on most modern systems (required by POSIX 2008),
but not on all systems.
Also handle errors from CLOEXEC. Even though fcntl does not really
define there to be any, it could theoretically be EBADF if the user
happened to pass a bad file descriptor to the same number fd (such that
no other code happened to already fail on that).
From user reports, it appears that OpenBSD has a broken kevent NOTE_EXIT
implementation. However, we can simply go back to the old, slower
version therefore.
Fix: https://github.com/libuv/libuv/issues/3504
Replacement for the usage pattern where people use uv_cpu_info() as an
imperfect heuristic for determining the amount of parallelism that is
available to their programs.
Fixes#3493.
Fixes: https://github.com/libuv/libuv/issues/3050
Refs: https://github.com/libuv/libuv/issues/3086
Refs: https://github.com/libuv/libuv/pull/3064
Refs: https://github.com/libuv/libuv/pull/3107
Refs: https://github.com/libuv/libuv/pull/3064
This reverts commit 217fdf4265, then fixes
several issues with it:
* remove error fast-cleanup code that triggers a nodejs bug
Refs: https://github.com/libuv/libuv/pull/3107#issuecomment-782482608
* protect posix_spawn from EINTR
This is not a documented valid error, but seems to have been observed.
* ignore setuid/setgid syscall
This kernel function is not permitted unless the process is setuid root,
so disable this syscall. Falling back to fork/exec should be okay for
the rare cases that the user decides they need to do setuid(getuid()) or
setuid(geteuid()) for the child.
Refs: https://github.com/libuv/libuv/pull/3107#issuecomment-782482608
* improve posix_spawn path search
Ports the improvements in musl back to this function
* fix some additional problems and formatting issues
We previously might fail to start a watcher, in rare failure cases,
resulting in a zombie that we would fail to kill. Also avoid creating
the signal-pipe unless required (addresses a review comment from Apple)
* fix fd->fd mapping reuse
There was a chance that when duplicating the fd's into stdio_count+fd we
might be closing a currently opened fd with that value.
The GNU/Hurd platform does not define IP_ADD_SOURCE_MEMBERSHIP,
IP_DROP_SOURCE_MEMBERSHIP, MCAST_JOIN_SOURCE_GROUP and
MCAST_LEAVE_SOURCE_GROUP.
Implement a few functions for the GNU/Hurd. Specifically:
* uv_resident_set_memory (from Linux)
* uv_get_free_memory (from Linux)
* uv_get_total_memory (from Linux)
* uv_cpu_info (from cygwin)
* uv__process_title_cleanup (void)
* uv_get_constrained_memory (stub)
* Leave proctitle unimplemented on Hurd for now
* Implement hurdish uv_exepath
* Enable ifaddrs api
* Unbreak udp basics
* Unbreak futime and lutime on Hurd
Added in https://github.com/libuv/libuv/pull/742, these values are
typically defined as unsigned (since Linux 2.4). Only -1 is special,
representing an invalid id (e.g. see setreuid).
The read callback failed to handle the `nread == 0` case, which is rare
to non-existent on the systems we test on but apparently happens often
enough on Solaris on SPARC to draw attention.
Fixes#3469.
Take into account that the data may not be already available in the
socket causing the `recvmsg()` / `recvmmsg()` calls to return `EAGAIN`
or `EWOULDBLOCK`.
Fixes: https://github.com/libuv/libuv/issues/3479
I created `uv__backend_timeout` to be used internally for this reason,
then forgot to use it, resulting in flaky tests and excessive trips
around the uv_run loop.
Fix#3472
- Fixes the declaration of the benchmark in benchmark-list.h (it was not
previously runnable at all)
- Fixes the benchmark itself hanging infinitely because the data was
being dropped via ICMP Destination Unreachable errors (meaning nread
was always zero in pinger_read_cb)
+ The data getting lost was fixed by binding the udp socket
- Properly checks for UV_UDP_MMSG_CHUNK, just as an example of what
should generally be done (buf_free is actually a no-op as the buf is
allocated on the stack)
If we try to use uv_fs_rmdir on a read-only directory on Windows, it
internally calls _wrmdir, which sets _doserrno to ERROR_ACCESS_DENIED
and errno to EACCES. However, ERROR_ACCESS_DENIED is mapped to
UV_EPERM, so I believe it should be remapped to UV_EACCES.
Currently `LoadLibraryA` call first attempts to load the given DLL from
the application working directory before loading it from the system DLL
path. This may pose a security risk if an attacker is able to place a
malicious DLL into the application working directory as that DLL will
be loaded instead of the system DLL. This is especially dangerous if
the application is running with elevated privileges.
This changes the DLL loading to use `LoadLibraryExA` method with
`LOAD_LIBRARY_SEARCH_SYSTEM32` flag which restricts the DLL load
path to system DLL path, ignoring any DLLs in the application working
directory.
Reverts 442aa1f469, since this is an
improved API in Windows Vista that is now usable as a replacement. It
simplifies the code substantially, while returning nearly the same
result (on my system, the performance counters were 6 seconds behind).
The old code also did not work on Wine-5.0 (where I observed that
`data_size == data_block->HeaderLength`, and so no data was present).
The test is very flaky, both on the CI and on people's local machines.
I spent some time trying to fix it but its design is fairly questionable
and it fails to test what it should more often than not because on fast
machines no queueing of data takes place.
Fixes#2307.
- Add `Makefile` for example codes. (cherry-pick from old uvbook repo)
- Add a new example "Default loop" to "Basics of libuv"/"Default loop"
- Document review and update: `Introduction`, `Basics of libuv`, `Filesystem`
+ Update the referenced libuv code snippet
+ Link update: http->https
**Content Updates**:
- `filesystem.rst`#L291-L297: Add note for `uv_fs_event_start`
- `filesystem.rst`#L334: Add description of the callback function parameter `status`
The following examples have been tested manually in WSL2 (Ubuntu 20.04) with libuv 1.42.0:
- helloworld
- default-loop
- idle-basic
- uvcat
- uvtee
- onchange (test on macOS)
Co-authored-by: Nikhil Marathe <nsm.nikhil@gmail.com>
Disable `atime` testing for symlink as this test
is dependant on a race condition on some OSes
(Linux is one) as `lstat` updates the `atime`.
As both `mtime` and `atime` are set by the same
syscall, barring an eventual kernel bug, this
test does not omit any error case.
This adds a workaround for an xnu kernel bug that sometimes results in
SIGCHLD not being delivered. The workaround is to use kevent to listen
for EVFILT_PROC/NOTE_EXIT events instead of relying on SIGCHLD on *BSD.
Apple rdar: FB9529664
Refs: https://github.com/libuv/libuv/pull/3257
The process title mutex was destroyed on library unload without ensuring
it was initialized - and it may not be because it's initialized lazily.
On most platforms it worked by accident because an "all zeroes" mutex is
synonymous with an initialized and unlocked mutex, but not on NetBSD.
Refs: https://github.com/libuv/libuv/pull/3286#issuecomment-1014058782
uv_thread_create_ex() lets you set a stack size that is smaller than is
safe. It enforces a lower bound of PTHREAD_STACK_MIN (when that constant
is defined) but with musl libc that's still too small to receive signals
on.
Put the lower bound at 8192 or PTHREAD_STACK_MIN, whichever is greater.
The same restriction was already in place for the _default_ stack size.
The maximum numbers receivable by the recvmmsg call is defined in
src/unix/udp.c as UV__MMSG_MAXWIDTH with the current value being 20.
Align the size of the receive buffer in the mmsg test to receive the
maximum number of UDP packets in the test.
With MUSL libc, the struct msghdr is padded to align with the types used
in the Linux kernel headers (int vs size_t). When the padding was not
zeroed, the syscall would return EMSGSIZE because the random bytes in
the padding would be read by kernel as part of the size_t type.
Fixes: https://github.com/libuv/libuv/issues/3416
Currently it's checking pointers to the uv_buf_t fields match the size
of the iovec fields. This is true on traditional architectures where
pointers are just machine word-sized integers, but not on CHERI, and
thus Arm's Morello prototype, where pointers contain additional metadata
(including bounds and permissions). Drop the & to fix this.
macOS versions 10.10 and 10.15 - and presumbaly 10.11 to 10.14, too -
have a bug where a race condition causes the kernel to return EPROTOTYPE
because the socket isn't fully constructed.
It's probably the result of the peer closing the connection and that is
why libuv translates it to ECONNRESET.
Previously, libuv retried until the EPROTOTYPE error went away but some
VPN software causes the same behavior except the error is permanent, not
transient, turning the retry mechanism into an infinite loop.
Refs: https://github.com/libuv/libuv/pull/482
Refs: https://github.com/libuv/libuv/pull/3405
It's been reported in the past that OS X 10.10, because of a race
condition in the XNU kernel, sometimes returns a transient EPROTOTYPE
error when trying to write to a socket. Libuv handles that by retrying
the operation until it succeeds or fails with a different error.
Recently it's been reported that current versions of the operating
system formerly known as OS X fail permanently with EPROTOTYPE under
certain conditions, resulting in an infinite loop.
Because Apple isn't exactly forthcoming with bug fixes or even details,
I'm opting to simply remove the workaround and have the error bubble up.
Refs: https://github.com/libuv/libuv/pull/482
Changes since version 1.42.0:
* run test named ip6_sin6_len (Jameson Nash)
* docs: fix wrong information about scheduling (Mohamed Edrah)
* unix: protect fork in uv_spawn from signals (Jameson Nash)
* drop only successfully sent packets post sendmmsg (Supragya Raj)
* test: fix typo in test-tty-escape-sequence-processing.c (Ikko
Ashimine)
* cmake: use standard installation layout always (Sylvain Corlay)
* win,spawn: allow UNC path with forward slash (earnal)
* win,fsevent: fix uv_fs_event_stop() assert (Ben Noordhuis)
* unix: remove redundant include in unix.h (
* doc: mark SmartOS as Tier 3 support (
* doc: fix broken links for netbsd's sysctl manpage (
* misc: adjust stalebot deadline (
* test: remove `dns-server.c` as it is not used anywhere (
* build: fix non-cmake android builds (
* doc: replace pyuv with uvloop (
* asan: fix some tests (
* build: add experimental TSAN configuration (
* pipe: remove useless assertion (
* bsd: destroy mutex in uv__process_title_cleanup() (
* build: add windows build to CI (
* win,fs: fix error code in uv_fs_read() and uv_fs_write() ( Sen)
* build: add macos-latest to ci matrix (
* udp: fix &/&& typo in macro condition (
* build: install cmake package module (Petr Menšík)
* win: fix build for mingw32 (
* build: fix build failures with MinGW new headers (erw7)
* build: fix win build with cmake versions before v3.14 (
* unix: support aarch64 in uv_cpu_info() (
* linux: work around CIFS EPERM bug (
* sunos: Oracle Developer Studio support (
* Revert "sunos: Oracle Developer Studio support (
* sunos: Oracle Developer Studio support (
* stream: permit read after seeing EOF (
* thread: initialize uv_thread_self for all threads (
* kqueue: ignore write-end closed notifications (
* macos: fix the cfdata length in uv__get_cpu_speed ( Bache)
* unix,win: add uv_ip_name to get name from sockaddr (
* win,test: fix a few typos (AJ Heller)
* zos: use destructor for uv__threadpool_cleanup() ( Zhang)
* linux: use MemAvailable instead of MemFree (
* freebsd: call dlerror() only if necessary (
* bsd,windows,zos: fix udp disconnect EINVAL (
On z/OS, instead of calling the uv__threadpool_cleanup() function from
inside uv_library_shutdown(), the destructor attribute must be used;
otherwise, tests will fail with exit code 1 and no output. Additionally,
post() does not need to be called when the destructor attribute is used.
Also adds uv__os390_cleanup() function to clean System V message queue
on z/OS.
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
Co-authored-by: Gaby Baghdadi <baghdadi@ca.ibm.com>
We observed crashes inside CFRelease in uv__get_cpu_speed on the new
Mac Book Pro (arm) hardware. The problem is that the stack got
clobbered. On the new mac hardware the returned length is 8.
For the 4 byte case, a temp variable is used to avoid having to add
endian-sensitive offsets.
Fixes: https://github.com/libuv/libuv/issues/3355
The combination EVFILT_WRITE+EV_EOF is valid and indicates that the
reader has disconnected (called `shutdown(SHUT_RD)`). Probably very rare
in practice, but this seems more correct.
Issue noticed (for UV_DISCONNECT clients of uv_poll), while doing
research for https://github.com/libuv/libuv/pull/3250.
In particular, previously the main thread would have an id of NULL,
which was then not valid to use with any other API that expected a
uv_thread_t handle.
On some streams (notably TTYs), it is permitted to continue reading
after getting EOF. So still stop reading on EOF, but allow the user to
reset the stream and try to read again (which may just get EOF).
This relaxes the constraint added in ce15b8405e.
Refs: https://github.com/libuv/libuv/pull/3006
Oracle Developer Studio requires public functions to be
defined as "__global" when "-fvisibility=hidden" used as
added by [#3005](https://github.com/libuv/libuv/pull/3005).
For documentation on `__global` see Reducing Symbol Scope in
Oracle Developer Studio C/C++ guide
https://www.oracle.com/solaris/technologies/symbol-scope.html.
fs_utime_round test failed as timespec.tv_nsec conversion to
double resulted in negative number. Skip this test for
__SPRO_C builds.
Note that it was necessary to have C99 language features
enabled with Studio compiler (-xc99=all) as version v1.41.0
has other commits that have used C99 features.
Tested with:
- cc: Studio 12.6 Sun C 5.15 SunOS_sparc 152881-05 2019/10/30
- gcc (GCC) 11.2.0
Refs: https://github.com/libuv/libuv/pull/3364
Oracle Solaris linker visibility support. Option "-fvisibility=hidden"
requires public functions to be defined as "__global".
fs_utime_round test failed as timespec.tv_nsec conversion to double
resulted in negative number. Skipped this test.
Note that it was necessary to compile with C99 language features.
It's been reported that copy_file_range() on a CIFS mount fails with
an EPERM error, even though the source and target files have the
appropriate permissions.
This is probably a variation on the EPERM error that libuv handles when
it tries to fchmod() a file on a CIFS mount that hasn't been mounted
with the "noperm" option, so let's handle it here too.
This commit applies minor refactoring because the "work around file
system bugs" section got quite unwieldy.
I also snuck in a bug fix where the workaround for buggy CephFS mounts
disabled copy_file_range() permanently.
Fixes: https://github.com/libuv/libuv/issues/3322
Before v3.14, cmake throws the following error:
```
CMake Error at third_party/libuv/CMakeLists.txt:663 (install):
install Library TARGETS given no DESTINATION!
```
I confirmed on Windows 7 and Windows Server 2016, with about a dozen
cmake versions between 3.7 and 3.22. I also confirmed that the
DESTINATION `${CMAKE_INSTALL_LIBDIR}` is populated with a valid path.
PR-URL: https://github.com/libuv/libuv/pull/3343
A structure definition was added to mstcpip.h in
mingw-w64-x86_64-headers-git 9.0.0.6327.f29c1101f,
which causes a conflict and the build fails. Fix this by
changing the name in the definition in mstcpip.h.
PR-URL: https://github.com/libuv/libuv/pull/3345
Commit e9c524aa from pull request https://github.com/libuv/libuv/pull/3149
introduced a hard dependency on `GetHostnameW`, which isn't declared
yet in mingw distributions (see
https://github.com/msys2/MINGW-packages/issues/9667).
This prevents the current version of libuv from building on many mingw
distributions, until such time the next version of mingw is released with
the correct definition for `GetHostnameW`, preventing a lot of projects
depending on libuv from building on mingw properly, as not all
distributions will update to head immediately anyway.
Instead of waiting, let's find the definition ourselves using
`GetProcAddress` and use the pointer instead.
PR-URL: https://github.com/libuv/libuv/pull/3340
Just like the Unix counterpart, uv_fs_read() and uv_fs_write() should
throw an EBADF instead of throwing an EPERM when the passed fd has not
been opened with the right flags.
Signed-off-by: Darshan Sen <darshan.sen@postman.com>
This assertion was added when req->write_buffer was a pointer. It was
then checking that write_buffer itself was not NULL. Checking that .base
is not NULL is superfluous because WriteFile will return error 998
(ERROR_NO_ACCESS) if the input buffer is invalid. This assertion fires
on zero-length writes when base==NULL&&len==0.
Previously they were just being run incorrectly, but nothing wrong with
the test itself. We were also interpreting an ASAN failure as TEST_SKIP,
so test failures would not actually be reported as CI failures.
Fix a logic error where calling uv_fs_event_stop() from the event
callback tripped on a `handle->dir_handle != INVALID_HANDLE_VALUE`
assert in uv_fs_event_queue_readdirchanges().
Fixes: https://github.com/libuv/libuv/issues/3258
PR-URL: https://github.com/libuv/libuv/pull/3259
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
postion -> position in several comments
PR-URL: https://github.com/libuv/libuv/pull/3284
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
sendmmsg returns with number of packets sent which can
be less than number of packets requested to be sent. Do
not flush entire write queue and use the returned info
to partially clear the write queue.
Refs: https://github.com/libuv/libuv/issues/3129 (fixes one issue listed)
PR-URL: https://github.com/libuv/libuv/pull/3265
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Years ago, we found that various kernels (linux, macOS) were known to
fail if they try to deliver a signal during this syscall, so we prevent
that from happening. They may have fixed those issues, but it is
generally just a bad time for signals to arrive (glibc blocks them here,
for example, including some more internal ones that it won't let us
touch here).
We try to be a bit conservative, and leave many signals unblocked which
could happen during normal execution and should terminate the process if
they do. There is a small race window after the child starts before we
clear the old handlers, if the user was to send an fake signal from
elsewhere, but that should be quite unlikely.
PR-URL: https://github.com/libuv/libuv/pull/3251
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
On illumos, the global errno variable is not thread-safe by default,
requiring that the application be built with gcc's -pthread option, or
that it defines -D_REENTRANT.
This was done already for the autotools build, but not for CMake.
PR-URL: https://github.com/libuv/libuv/pull/3243
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
The sunos platform currently covers at least the Solaris and illumos
operating systems. Although these diverged 11 years ago they still share
some common features such as support for event ports.
illumos also has a compatibility wrapper for epoll but this is not
recommended for use over event ports. From the NOTES section of
https://illumos.org/man/5/epoll:
The epoll facility is implemented for purposes of offering
compatibility to and portability of Linux-borne
applications; native applications should continue to prefer
using event ports... In particular, use of epoll in a
multithreaded environment is fraught with peril...
Restore the event ports code so that libuv can continue to be used
on Solaris, and to avoid the problems that come with using epoll()
on illumos. The separation of epoll into src/unix/epoll.c has been
retained.
Fixes: https://github.com/libuv/libuv/issues/3241
PR-URL: https://github.com/libuv/libuv/pull/3242
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
`strnlen` was not available on Solaris 10, so provide a fallback
implementation for it.
PR-URL: https://github.com/libuv/libuv/pull/3152
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Don't use x86 inline assembly in these cases, but fall back to
__sync_fetch_and_or, similar to _InterlockedOr8 in the MSVC case.
This corresponds to what is done in src/unix/atomic-ops.h, where
ARM/AArch64 cases end up implementing cmpxchgi with
__sync_val_compare_and_swap.
PR-URL: https://github.com/libuv/libuv/pull/3236
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
While most users will likely typically call uv_close in their
uv_shutdown callback, some callers (notable nodejs) do not always do
so. This can result in libuv keeping the loop active, even though there
are no outstanding reqs left to handle.
This bug was added in 80f2f826bf, where
the premise of that commit appears to have simply been incorrect, as
demonstrated by the added test.
Refs: https://github.com/libuv/libuv/issues/3202
PR-URL: https://github.com/libuv/libuv/pull/3233
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Prior to this patch a race condition may occur in case a thread tries
to destroy the barrier while other awaiting threads were not notified.
Since the internal mutex and condition variables are destroyed this may
cause an undefined behavior as described by the man pages.
So in order to prevent such scenarios the detroy function will not wait
until all awaiting threads are finished before proceeding.
Fixes: https://github.com/libuv/libuv/issues/3102
PR-URL: https://github.com/libuv/libuv/pull/3162
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
uv_tty_set_mode() allows a tty device to be set to raw mode with
UV_TTY_MODE_RAW, which correctly sets MIN and TIME to appropriate
values for character input. When UV_TTY_MODE_IO is passed, on illumos
systems a compatibility implementation of cfmakeraw() is used that does
_not_ set MIN or TIME. As a result, consumers of IO mode will block
until a minimum of 4 bytes is available on the tty instead of just 1 as
is expected.
PR-URL: https://github.com/libuv/libuv/pull/3219
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
libuv was vulnerable to out-of-bounds reads in the uv__idna_toascii()
function which is used to convert strings to ASCII. This is called by
the DNS resolution function and can lead to information disclosures or
crashes.
Reported by Eric Sesterhenn in collaboration with Cure53 and ExpressVPN.
Reported-By: Eric Sesterhenn <eric.sesterhenn@x41-dsec.de>
Fixes: https://github.com/libuv/libuv/issues/3147
PR-URL: https://github.com/libuv/libuv-private/pull/1
Refs: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-22918
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
We also tell the compiler it is not allowed to reorder the PAUSE
instruction relative to other instructions. It is a mostly theoretical
issue, but better safe than sorry.
PR-URL: https://github.com/libuv/libuv/pull/2590
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This is an attempt to fix some resource management issues on Windows.
Win32 sockets have an issue where it sends an RST packet if there is an
outstanding overlapped calls. We can avoid that by being certain to
explicitly cancel our read and write requests first.
This also removes some conditional cleanup code, since we might as well
clean it up eagerly (like unix). Otherwise, it looks to me like these
might cause the accept callbacks to be run after the endgame had freed
the memory for them.
The comment here seems mixed up between send and recv buffers. The
default behavior on calling `closesocket` is already to do a graceful
shutdown (see
https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-closesocket
with default l_onoff=zero) if it is the last open handle. The expected
behavior if there are pending reads in flight is to send an RST packet,
notifying the client that the server connection was destroyed before
acknowledging the EOF.
Additionally, we need to cancel writes explicitly: we need to notify
Win32 that it is okay to cancel these writes (so it doesn't also
generate an RST packet on the wire).
Refs: https://github.com/libuv/libuv/pull/3035
Refs: https://github.com/nodejs/node/pull/35946
Refs: https://github.com/nodejs/node/issues/35904
Fixes: https://github.com/libuv/libuv/issues/3034
PR-URL: https://github.com/libuv/libuv/pull/3036
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
These functions are declared with one set of conditionals in the
header, and defined with another set of conditionals in the c file.
This commit makes all decisions regarding `uv__{nonblock,cloexec}_ioctl`
depend on a boolean macro instead.
There's one function that expects `uv__nonblock_ioctl` to be defined,
so that bit of the function is also conditionally compiled.
PR-URL: https://github.com/libuv/libuv/pull/3163
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Still returns ENOSYS, until the send/recv functions are implemented.
PR-URL: https://github.com/libuv/libuv/pull/3040
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Just like the unix counterpart, uv_fs_read and uv_fs_write should throw
an EBADF instead of manually throwing an EPERM when the passed fd has
not been opened with the right access flags.
PR-URL: https://github.com/libuv/libuv/pull/3180
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
`uv_try_write2(stream, bufs, nbufs, send_handle)` acts like
`uv_try_write()` and extended write function for sending handles over a
pipe like `uv_write2`. It always returns `UV_EAGAIN` instead of
`UV_ENOSYS` on Windows so we can easily write cross-platform code
without special treatment.
PR-URL: https://github.com/libuv/libuv/pull/3183
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Windows API gethostname(buffer, size) return unicode string in char
array. It will cause garbled code if the host name contains non ascii
characters without cast into multi byte char.
This change keep the same encoding with the implementation on
Unix/macOS platform, which is utf-8.
Requires Windows 8 / Server 2012.
Fixes: https://github.com/libuv/libuv/issues/3148
PR-URL: https://github.com/libuv/libuv/pull/3149
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This is more clear about the intended semantics with multiple threads.
PR-URL: https://github.com/libuv/libuv/pull/3124
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
libuv is packaged for OmniOS, an illumos distribution (OpenSolaris fork), and on that platform `libdl.so` is just a legacy stub library that does not need to be linked. `dlopen()` and friends are present in libc.
Changing to using `AC_SEARCH_LIBS()` instead of `AC_CHECK_LIB()` stops the unnecessary linking of libdl.
PR-URL: https://github.com/libuv/libuv/pull/3113
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
When compiling the current code MSVC prints this warning:
warning C4090: '=': different 'const' qualifiers
This warning was introduced with dc6fdcd where the `(char*)` cast for
the call to `wcstombs` was removed.
Re-adding this cast to silence the warning.
PR-URL: https://github.com/libuv/libuv/pull/3146
Refs: https://github.com/libuv/libuv/pull/2938
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
The TAP specification [1] explicitely states:
A harness must only read TAP output from standard output and
not from standard error.
[1] https://testanything.org/tap-specification.html
PR-URL: https://github.com/libuv/libuv/pull/3153
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
PR-URL: https://github.com/libuv/libuv/pull/3166
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
IBM i interface names are based off the associated line description.
Since line descriptions are objects, they have 10 character limit on
their names. However, since IBM i 7.2 interface names may be up to 16
characters long if the interface is for a a VLAN (eg. MYETHLINE1.4094).
To handle this, we must strip off a VLAN ID to get the actual line
description name, since that's what the QDCRLIND API wants. One issue
exists because line descriptions can contain periods and numbers; so
for interface names less than 10 characters long ETH2.4 could be a line
description name or it could be ETH2 with VLAN 4. We follow the
method that the XPF ioctls use: try the interface name directly first
and if an error occurs, try to strip off the VLAN ID.
https://www.ibm.com/docs/en/i/7.4?topic=ssw_ibm_i_74/apis/ioctl.htm#unotes
Fixes: https://github.com/libuv/libuv/issues/3062
PR-URL: https://github.com/libuv/libuv/pull/3144
Reviewed-By: Richard Lau <rlau@redhat.com>
The previous implementation using rcepool would return a value that is
slightly off from the true value of the system's total memory. So use
CVTRLSTG to get total memory instead, which is more accurate. For more
information on CVTRLSTG, see MVS Data Areas Volumes 1 and 3.
Co-authored-by: Gaby Baghdadi <49249542+gabylb@users.noreply.github.com>
PR-URL: https://github.com/libuv/libuv/pull/3141
Reviewed-By: Richard Lau <rlau@redhat.com>
The previous implementation of `uv_get_free_memory()` on z/OS return
incorrect values. This is because the rceafc field being dereferenced
for the memory values needs to be treated as unsigned int.
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
Co-authored-by: Alex Yung <alex.yung@ibm.com>
Co-authored-by: CW Cheung <ccw.280231@ca.ibm.com>
PR-URL: https://github.com/libuv/libuv/pull/3141
Reviewed-By: Richard Lau <rlau@redhat.com>
Implementation is based on RLIMIT_MEMLIMIT.
Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
PR-URL: https://github.com/libuv/libuv/pull/3133
Reviewed-By: Richard Lau <rlau@redhat.com>
Thread Sanitizer can't intercept syscall(SYS_close, fd) that's used
instead of close(fd); on Linux. That leads to false positives as Thread
Sanitizer thinks the descriptor is still being used by the thread.
clang defines pre- and post- syscall actions, so wrap the close
syscall() into the action macros. For gcc, use close() from glibc
instead of the syscall. This allows the thread sanitizer to intercept
closing of the file descriptor when libuv is compiled with Thread
Sanitizer.
PR-URL: https://github.com/libuv/libuv/pull/3112
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
`pthread_attr_init` is highly unlikely to fail on macOS. Removing the
fallback behavior here to be consistent with other parts of libuv (e.g.
`src/unix/thread.c`), which simply call `abort()`.
PR-URL: https://github.com/libuv/libuv/pull/3132
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This fixes `SIGBUS` crashes on macOS 10.15 due a new change in
`FSEvents.framework` that makes it allocate a large stack array for
event paths. (See the linked nodejs/node issue for details on the
`FSEvents.framework` memory requirements change itself.)
The existing size (`4 * PTHREAD_STACK_MIN` or 32KB) causes a stack
overflow when more than ~1000 events are received at once. Setting this
to `uv__thread_stack_size()` increases it to 8192KB (by default) on
64-bit machines. This value can be configured at runtime on macOS with
`ulimit -s <size-kb>`.
The 32KB limit was originally added to reduce virtual memory
fragmentation on 32-bit systems, which is not a concern on 64-bit
systems.
Fixes: nodejs/node#37697
Refs: joyent/libuv#964
PR-URL: https://github.com/libuv/libuv/pull/3132
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This function will be used by `uv__fsevents_loop_init` in a future
commit to determine the initial FSEvents pthread stack size.
PR-URL: https://github.com/libuv/libuv/pull/3132
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
In both `test-tcp-open` and `test-udp-open`.
PR-URL: https://github.com/libuv/libuv/pull/3137
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
There is no CMAKE_LINKER_FLAGS_DEBUG.
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
PR-URL: https://github.com/libuv/libuv/pull/3137
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
In the codebase we have used empty for loop for infinite conditions, so
to bring consistency replaced other occurrences of while in the codebase
with for loop.
PR-URL: https://github.com/libuv/libuv/pull/3128
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
PR-URL: https://github.com/libuv/libuv/pull/3130
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
To properly handle sending UDP packet to unreachable address.
PR-URL: https://github.com/libuv/libuv/pull/2872
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
The Linux kernel suppresses some ICMP error messages by default for UDP
sockets. This commit sets IP_RECVERR/IPV6_RECVERR on the socket to
enable full ICMP error reporting, hopefully resulting in faster failover
to working name servers.
PR-URL: https://github.com/libuv/libuv/pull/2872
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
ZOSLIB uses `argv[0]` to determine the exepath. So it is necessary to
use an implementation of proctitle that does not modify `argv[0]`. Since
there is currently no support for process titles on z/OS, the custom
proctitle implementation simply stores the desired title in memory.
This resolves failure in tests `get_currentexe` and `process_title` on
z/OS.
PR-URL: https://github.com/libuv/libuv/pull/3060
Reviewed-By: Richard Lau <rlau@redhat.com>
On z/OS, `execvp()` does not set the environment for child process from
`environ` when ran in ASCII mode. Instead, `execvpe()` provided by
ZOSLIB must be used to set the environment explicitly.
PR-URL: https://github.com/libuv/libuv/pull/3060
Reviewed-By: Richard Lau <rlau@redhat.com>
`__rfim_utok` is treated as text when it should be treated as binary
while running in ASCII mode, resulting in an unwanted autoconversion. So
undo the conversion explicitly.
PR-URL: https://github.com/libuv/libuv/pull/3060
Reviewed-By: Richard Lau <rlau@redhat.com>
Since `nanosleep()` is implemented in ZOSLIB, we will remove the libuv
implementation to resolve conflict. The ZOSLIB implementation uses
BPX4CTW (cond_timed_wait).
PR-URL: https://github.com/libuv/libuv/pull/3060
Reviewed-By: Richard Lau <rlau@redhat.com>
Since `strnlen()` is implemented in ZOSLIB, we will remove the libuv
implementation to resolve conflict. The ZOSLIB implementation uses asm.
PR-URL: https://github.com/libuv/libuv/pull/3060
Reviewed-By: Richard Lau <rlau@redhat.com>
This commit introduces ZOSLIB for z/OS, which is a C/C++ library that
implements additional POSIX APIs not available in the LE C Runtime
Library, and provides API for EBCDIC <-> ASCII conversion. This library
requires the linker to be set to CXX when building for z/OS. ZOSLIB is
designed to be installed separately, and then linked to libuv with the
`-DZOSLIB_DIR` option.
PR-URL: https://github.com/libuv/libuv/pull/3060
Reviewed-By: Richard Lau <rlau@redhat.com>
Nanosecond resolution for the timestamp fields `st_atim`, `st_mtim`, and
`st_ctim` are not supported on z/OS.
PR-URL: https://github.com/libuv/libuv/pull/3060
Reviewed-By: Richard Lau <rlau@redhat.com>
Moving to new style test macros will make debugging easier in case
of test failure and improve redability. This commit will replace all
ASSERT macros matching the statement:
`ASSERT(identifier (== or !=) value);`
to:
`ASSERT_(NOT_)NULL(identifier);`
Refs: https://github.com/libuv/libuv/issues/2974
PR-URL: https://github.com/libuv/libuv/pull/3081
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Applications running on hardened runtime based on Chromium/Electron
create mmap regions using MAP_JIT flag. With macOS Big Sur the fork()
calls done by uv_spawn have become slow. This is because fork() seems
to physically copy all JIT memory regions (no-copy-on-write). On
previous OS, these regions weren't accessible at all in the forked
process, explaining the regression.
The fix is to use posix_spawn() on macOS. This spawns a new process
directly, without copying any memory mappings.
Note that fork() is still used on earlier versions of macOS if the
necessary posix_spawn() platform-specific extensions are not available.
Fixes: https://github.com/libuv/libuv/issues/3050
PR-URL: https://github.com/libuv/libuv/pull/3064
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Consider the following scenario:
uv_poll_init(loop, poll, fd);
uv_poll_start(poll, UV_READABLE, cb);
// the cb gets invoked etc.
uv_poll_stop(poll);
close(fd);
fd = allocate_new_socket(); // allocate_new_socket() is assigned the same fd by "bad luck" from the OS
// some time later:
uv_poll_init(loop, otherpoll, fd);
uv_poll_start(otherpoll, UV_READABLE, cb);
uv_close(poll); // uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
According to documentation, "however the fd can be safely closed
immediately after a call to uv_poll_stop() or uv_close()."
Though, in this scenario, we close()'d our file descriptor, and by
bad luck we got the same file descriptor again and register a new
handle for it and start polling.
Previously that would lead to an assertion failure, if we were to
properly free the original handle via uv_close().
This commit fixes that by moving the check whether a only a single
poll handle is active to uv_poll_start() instead of the stopping
routines.
Fixes: https://github.com/libuv/libuv/issues/1172
Fixes: https://github.com/bwoebi/php-uv/issues/81
Fixes: https://github.com/b2wdigital/aiologger/issues/82
Fixes: https://github.com/invenia/LibPQ.jl/issues/140
PR-URL: https://github.com/libuv/libuv/pull/2686
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
* Windows 7 went out of support earlier this year.
* As did Python 2.7. We no longer have to worry about MSVC 2008.
Python 3.5 and up use VS 2015.
PR-URL: https://github.com/libuv/libuv/pull/2821
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Joao Reis <reis@janeasystems.com>
RFC 2606 reserves the .invalid top-level domain for this purpose.
PR-URL: https://github.com/libuv/libuv/pull/3063
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
PR-URL: https://github.com/libuv/libuv/pull/3061
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
`uv_fs_utime()` and `uv_fs_futime()` receive the timestamp as
a `double` and then convert it to `struct timeval` or `struct timespec`
where necessary but the calculation for the sub-second part exhibited
rounding errors for dates in the deep past or the far-flung future,
causing the timestamps to be off by sometimes over half a second on
unix, or to be reinterpreted as unsigned and end up off by more than
just sign but many also decades.
Fixes: https://github.com/nodejs/node/issues/32369 (partially)
PR-URL: https://github.com/libuv/libuv/pull/2747
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`check_utime()` already calls `uv_fs_stat()`, no point in doing it
twice.
PR-URL: https://github.com/libuv/libuv/pull/2747
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: https://github.com/libuv/libuv/pull/3031
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
With the addition of `uv_timer_get_due_in()` it's observable with tools like
valgrind that the `timer->timeout` field isn't initialized until the timer
is started.
Fixes the following valgrind warning when running the `timer_init` test:
==325215== Conditional jump or move depends on uninitialised value(s)
==325215== at 0x1B0131: uv_timer_get_due_in (timer.c:134)
==325215== by 0x19AF09: run_test_timer_init (test-timer.c:164)
==325215== by 0x119FF1: run_test_part (runner.c:376)
==325215== by 0x11875D: main (run-tests.c:68)
==325215==
==325215== Conditional jump or move depends on uninitialised value(s)
==325215== at 0x19AF1F: run_test_timer_init (test-timer.c:164)
==325215== by 0x119FF1: run_test_part (runner.c:376)
==325215== by 0x11875D: main (run-tests.c:68)
Fixes: https://github.com/libuv/libuv/issues/3020
PR-URL: https://github.com/libuv/libuv/pull/3038
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Equivalents of `pipe` and `socketpair` for cross-platform use.
PR-URL: https://github.com/libuv/libuv/pull/2953
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Return `UV_EINVAL` when one or more arguments are NULL.
Fixes: https://github.com/libuv/help/issues/137
PR-URL: https://github.com/libuv/libuv/pull/2795
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
The behavior of `uv_read_start()` when the handle is closing or already
busy reading wasn't consistent across platforms. Now it is.
Fixes: https://github.com/libuv/help/issues/137
PR-URL: https://github.com/libuv/libuv/pull/2795
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
The seccomp filter with older Android SDKs kills the process when libuv
tries to make system calls it doesn't know about.
This commit adds ifdef guards that stop libuv from making those system
calls with affected SDKs.
Fixes: https://github.com/libuv/libuv/issues/2923
PR-URL: https://github.com/libuv/libuv/pull/3027
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
`ssize_t` is 32 bits on 32 bits architectures, `off_t` is 64 bits
(because libuv builds with `-D_LARGEFILE_SOURCE`.)
Introduced in commit ca10e36149 ("linux: use copy_file_range for
uv_fs_copyfile when possible") merged in July of this year.
Fixes: https://github.com/libuv/libuv/issues/3011
PR-URL: https://github.com/libuv/libuv/pull/3028
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Added notes to documentation of `uv_poll_t`:
- The callback will be called over-and-over again as long as the socket
remains readable/writable.
- uv_poll_stop() cancels pending callbacks of already happened events.
Fixes: https://github.com/libuv/libuv/issues/1078
PR-URL: https://github.com/libuv/libuv/pull/1100
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
PR-URL: https://github.com/libuv/libuv/pull/3029
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
It defers the error to uv_listen() or uv_tcp_connect().
PR-URL: https://github.com/libuv/libuv/pull/2218
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Fix a bug where libuv forgets about EADDRINUSE errors reported earlier:
uv_tcp_bind() + uv_tcp_connect() seemingly succeed but the socket isn't
actually bound to the requested address.
This bug goes back to at least 2011 if indeed it ever worked at all.
PR-URL: https://github.com/libuv/libuv/pull/2218
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
PR-URL: https://github.com/libuv/libuv/pull/3010
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Android/i386 doesn't have separate sendmmsg/recvmmsg system calls,
they're multiplexed through the socketcall system call.
(More precisely, the system calls may be present but the standard
seccomp filter rejects them, whereas socketcall is whitelisted.)
This commit removes the flags and timeout arguments from libuv's
internal system call wrappers because they're always zero and it
makes EINVAL/ENOSYS detection after a failed socketcall() easier.
Fixes: https://github.com/libuv/libuv/issues/2923
PR-URL: https://github.com/libuv/libuv/pull/2925
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit initializes user_timeout in uv__io_poll to avoid a
maybe-uninitialized warning:
$ cmake .. -DCMAKE_C_FLAGS="-Wmaybe-uninitialized -O3"
...
[ 14%] Building C object CMakeFiles/uv.dir/src/unix/tty.c.o
/libuv/libuv/src/unix/linux-core.c: In function ‘uv__io_poll’:
/libuv/libuv/src/unix/linux-core.c:351:10: warning:
‘user_timeout’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
351 | if (timeout == -1)
| ^
PR-URL: https://github.com/libuv/libuv/pull/2976
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit includes patches from dports to fix the DragonFly
BSD build. It also removes the now unused uv_exepath_procfs().
PR-URL: https://github.com/libuv/libuv/pull/2952
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
On Windows allow utf-16 surrogate pars to pass through, which allows
conhost on newer Windows versions and other terminal emulators to be
able to render them.
Fixes: https://github.com/libuv/libuv/issues/2909
PR-URL: https://github.com/libuv/libuv/pull/2971
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Changes since version 1.38.1:
* unix: use relaxed loads/stores for clock id (Ben Noordhuis)
* build,win: link to user32.lib and advapi32.lib (George Zhao)
* unix: squelch harmless valgrind warning (ssrlive)
* include: fx c++ style comments warnings (Turbinya)
* build,cmake: Change installation location on MinGW (erw7)
* linux: use copy_file_range for uv_fs_copyfile when possible (Carter
Li)
* win,tcp: avoid reinserting a pending request (
* docs: improve the descriptions for get memory info (Juan Sebastian
velez Posada)
* test: add udp-mmsg test (Ryan Liptak)
* udp: add uv_udp_using_recvmmsg query (Ryan Liptak)
* doc: add more error constants (TK-one)
* zos: fix potential event loop stall (Trevor Norris)
* include: add internal fields struct to uv_loop_t (Trevor Norris)
* core: add API to measure event loop idle time (Trevor Norris)
* win,fs: use CreateDirectoryW instead of _wmkdir (Mustafa M)
* win,nfc: fix integer comparison signedness (escherstair)
* win,nfc: use
* win,nfc: removed some unused variables (escherstair)
* win,nfc: add missing return statement (escherstair)
* win,nfc: disable clang-format for
* darwin: use IOKit for uv_cpu_info (Evan Lucas)
* test: fix thread race in process_title_threadsafe (Ben Noordhuis)
* win,fs: avoid implicit access to _doserrno (Jameson Nash)
* test: give hrtime test a custom 20s timeout (Jameson Nash)
* build: add more failed test, for qemu version bump (gengjiawen)
* unix: handle src, dest same in uv_fs_copyfile() (cjihrig)
* unix: error when uv_setup_args() is not called (Ryan Liptak)
* aix: protect uv_exepath() from uv_set_process_title() (Richard Lau)
* fs: clobber req->path on uv_fs_mkstemp() error (tjarlama)
* cmake: fix compile error C2001 on Chinese Windows (司徒玟琅)
* test: avoid double evaluation in ASSERT_BASE macro (tjarlama)
* tcp: fail instantly if local port is unbound (Bartosz Sosnowski)
* doc: fix most sphinx warnings (Jameson Nash)
* nfci: address some style nits (Jameson Nash)
* unix: don't use _POSIX_PATH_MAX (Ben Noordhuis)
Libuv was using _POSIX_PATH_MAX wrong. Bug introduced in commit b56d279b
("unix: do not require PATH_MAX to be defined") from September 2018.
_POSIX_PATH_MAX is the minimum max path size guaranteed by POSIX, not
the actual max path size of the system libuv runs on. _POSIX_PATH_MAX
is always 256, the real max is often much bigger.
This commit fixes buffer overruns when processing very long paths in
uv_fs_readlink() and uv_fs_realpath() because libuv was not allocating
enough memory to store the result.
Fixes: https://github.com/libuv/libuv/issues/2965
PR-URL: https://github.com/libuv/libuv/pull/2966
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
On Windows when connecting to an unavailable port, the connect() will
retry for 2s, even on loopback devices. This uses a call to WSAIoctl to
make the connect() call fail instantly on local connections.
PR-URL: https://github.com/libuv/libuv/pull/2896
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Passing expression as an argument to a function-like macro will replace
all occurrence of the arguments with expressions during preprocessing.
This result in multiple evaluation of the same expression and can
slow-down the program or even change program state. Here ASSERT_BASE
macro gets an expression involving a and b as first argument and macro
definition has a print statement with a and b, which means there is
double evaluation of a and b when the expression evaluates to false. To
avoid double evaluation temporary variables are created to store results
of a and b.
Since the expression argument is dropped from ASSERT_BASE, the macro no
longer works for string assertions. So a new macro, ASSERT_BASE_STR, is
introduced to deal with strings. ASSERT_BASE can still work with
pointers.
Fixes: https://github.com/libuv/libuv/issues/2916
PR-URL: https://github.com/libuv/libuv/pull/2926
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Contents of template variable passed for posix call mkstemp on error
code EINVAL is unknown. On AIX platform, template will get clobbered
on EINVAL and any attempt to read template might result in error.
In libuv, req->path is passed directly to the mkstemp call and
behavior of this string on error is platform dependent. To avoid
portability issues, it's better to have a common behavior on all
platform. For both unix and windows platform libuv will rewrite path
with an empty string on all error cases.
Fixes: https://github.com/libuv/libuv/issues/2913
Refs: https://github.com/nodejs/node/pull/33549
Refs: https://github.com/libuv/libuv/pull/2933
PR-URL: https://github.com/libuv/libuv/pull/2938
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Store a copy of the original argv[0] to protect `uv_exepath()`
against `uv_set_process_title()` changing the value of argv[0].
Extract common code for finding a program on the current PATH.
Fixes: https://github.com/libuv/libuv/issues/2674
PR-URL: https://github.com/libuv/libuv/pull/2677
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This commit updates uv_{get,set}_process_title() to return an
error when uv_setup_args() is needed, but has not been called.
Per-platform behavior after this commit:
- Windows: uv_setup_args() does nothing, get/set process title
works as before.
- Unix: get/set process title will return ENOBUFS if
uv_setup_args() wasn't called, if it failed, or if the process
title memory has been freed by uv__process_title_cleanup()
(via uv_library_shutdown()).
- AIX: set process title returns ENOBUFS if uv_setup_args()
wasn't called, if it failed to allocate memory for the argv
copy, or if the proctitle memory has been freed by
uv__process_title_cleanup() (via uv_library_shutdown).
Getting the process title will do the same except it can
still succeed if uv_setup_args() was called but failed to
allocate memory for the argv copy.
- BSD: uv_setup_args() is only needed for getting the initial
process title; if uv_setup_args() is not called then any
get_process_title calls() before a set_process_title() call
will return an empty string.
- Platforms that use no-proctitle.c: get will return an empty
string, set is a no-op (these are the same as before this commit)
Fixes: https://github.com/libuv/libuv/issues/2845
PR-URL: https://github.com/libuv/libuv/pull/2853
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This commit handles the case where the source and destination
are the same. This behavior was originally addressed in #2298,
but the test added in that PR doesn't validate the file size
after the operation. This commit also updates the test to check
for that case.
Refs: https://github.com/libuv/libuv/pull/2298
Refs: https://github.com/nodejs/node/issues/34624
PR-URL: https://github.com/libuv/libuv/pull/2947
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Libuv calls uv__process_title_cleanup() on shutdown, which raced with
one of the threads from the test that calls uv_get_process_title() in
an infinite loop. Change the test to properly shut down the thread
before exiting.
PR-URL: https://github.com/libuv/libuv/pull/2946
Refs: https://github.com/libuv/libuv/pull/2853#issuecomment-665259082
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This switches uv_cpu_info from using sysctlbyname to
using IOKit to get the speed of the processors.
macOS on ARM does not currently have the hw.cpufrequency
sysctl. We are able to reliable get the clock frequency
on all architectures by using IOKit.
Fixes: https://github.com/libuv/libuv/issues/2911
PR-URL: https://github.com/libuv/libuv/pull/2914
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
No functional changes are intended [NFCI], but this may make it easier
in the future to implement and respect the `modes` flag.
PR-URL: https://github.com/libuv/libuv/pull/2921
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
The API addition `uv_metrics_idle_time()` is a thread safe call that
allows the user to retrieve the amount of time the event loop has spent
in the kernel's event provider (i.e. poll). It was done this way to
allow retrieving this value without needing to interrupt the execution
of the event loop. This option can be enabled by passing
`UV_METRICS_IDLE_TIME` to `uv_loop_configure()`.
One important aspect of this change is, when enabled, to always first
call the event provider with a `timeout == 0`. This allows libuv to know
whether any events were waiting in the event queue when the event
provider was called. The importance of this is because libuv is tracking
the amount of "idle time", not "poll time". Thus the provider entry time
is not recorded when `timeout == 0` (the event provider never idles in
this case).
While this does add a small amount of overhead, when enabled, but the
overhead decreases when the event loop has a heavier load. This is
because poll events will be waiting when the event provider is called.
Thus never actually recording the provider entry time.
Checking if `uv_loop_t` is configured with `UV_METRICS_IDLE_TIME` always
happens in `uv__metrics_set_provider_entry_time()` and
`uv__metrics_update_idle_time()`. Making the conditional logic wrapping
each call simpler and allows for instrumentation to always hook into
those two function calls.
Rather than placing the fields directly on `uv__loop_internal_fields_t`
add the struct `uv__loop_metrics_t` as a location for future metrics API
additions.
Tests and additional documentation has been included.
PR-URL: https://github.com/libuv/libuv/pull/2725
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Add struct `uv__loop_internal_fields_t` as a location for future
additions to `uv_loop_t` while also maintaining v1.x compatibility.
Currently `uv__loop_internal_fields_t` only contains the `flags` field.
The reason for adding the `flags` field is because the same field was
never added to `UV_LOOP_PRIVATE_FIELDS` in Windows as it was in Unix.
The idea for creating a struct and attaching it to `uv_loop_t` for
future API enhancements was taken from a comment by bnoordhuis in:
https://github.com/libuv/libuv/issues/2506#issuecomment-540050665
Also add `internal_fields` to `uv_loop_t` to store the pointer to
`uv__loop_internal_fields_t`. This naming makes more sense than just
using `active_reqs.unused[1]`. To maintain ABI compatibility, shrink the
`unused` array.
PR-URL: https://github.com/libuv/libuv/pull/2725
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This is a port of 70002c80 to z/OS to fix the same potential issue that
could effectively enter an infinite loop (but not a busy loop) under
certain conditions when polling for events.
PR-URL: https://github.com/libuv/libuv/pull/2725
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
Allows for determining if a buffer large enough for multiple dgrams
should be allocated in alloc_cb of uv_udp_recvstart, for example.
Contributes towards #2822.
PR-URL: https://github.com/libuv/libuv/pull/2830
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This fix avoids inserting a duplicate pending request in the case where
`WSARecv()` returns an error (e.g. when a connection has been terminated
by its peer) when `uv_read_start()` is called in a read callback.
Fixes: https://github.com/libuv/libuv/issues/2687
PR-URL: https://github.com/libuv/libuv/pull/2688
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
MinGW prefers a POSIX like file system hierarchy. Therefore, it is appropriate
that the installation destination is the same as UNIX.
PR-URL: https://github.com/libuv/libuv/pull/2697
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
PR-URL: https://github.com/libuv/libuv/pull/2895
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This was part of commit c70dd705 ("unix: use relaxed loads/stores for
feature checks") and was reviewed as such but I accidentally dropped
it in the rebase before the final merge.
Fixes: https://github.com/libuv/libuv/issues/2884
PR-URL: https://github.com/libuv/libuv/pull/2886
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
This issue manifested on `connected` udp sockets trying to send
datagrams to a non-existent server and returning `ECONNREFUSED` because
an ICMP error was received before the actual sending was performed.
PR-URL: https://github.com/libuv/libuv/pull/2899
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
It was reported that mach_absolute_time() can jump backward in time when
the machine is suspended. Use mach_continuous_time() when available to
work around that (macOS 10.12 and up.)
Fixes: https://github.com/libuv/libuv/issues/2891
PR-URL: https://github.com/libuv/libuv/pull/2894
Reviewed-By: Phil Willoughby <philwill@fb.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
`__atomic_load_n()` and friends were added in gcc 4.7.0 but we still
have some centos6 machines with a vintage gcc 4.4.7 from 2012 in the
CI matrix.
PR-URL: https://github.com/libuv/libuv/pull/2888
Refs: https://github.com/libuv/libuv/pull/2886
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
It was reported that the addition of that file without adding an
exception to m4/.gitignore breaks the tarball autotools build because
the file isn't distributed.
Fixes: https://github.com/libuv/libuv/issues/2862
PR-URL: https://github.com/libuv/libuv/pull/2885
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Make ThreadSanitizer stop complaining about the static variables that
libuv uses to record the presence (or lack) of system calls and other
kernel features.
Fixes: https://github.com/libuv/libuv/issues/2884
PR-URL: https://github.com/libuv/libuv/pull/2886
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
The variable uv__read_console_status is left as IN_PROGRESS when the
operation is canceled ahead of time by the main thread requesting a
trap (race condition?).
This confuses the next call to uv__cancel_read_console(...) causing
a deadlock due to a semaphore acquisition that is never released by
the reading thread.
Setting the status variable back to COMPLETE or NOT_STARTED fixes
the issue.
Ref: https://github.com/nodejs/node/issues/32999
PR-URL: https://github.com/libuv/libuv/pull/2882
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
It was reported that uv_loadavg() reports the wrong values inside an
lxc container.
Libuv calls sysinfo(2) but that isn't intercepted by lxc. /proc/loadavg
however is because /proc is a FUSE fs inside the container.
This commit makes libuv try /proc/loadavg first and fall back to
sysinfo(2) in case /proc isn't mounted.
This commit is very similar to commit 3a1be725 ("linux: read free/total
memory from /proc/meminfo") from April 2019.
Fixes: https://github.com/nodejs/node/issues/33791
PR-URL: https://github.com/libuv/libuv/pull/2876
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Move common logic into a separate function that will be reused in a
follow-up commit. This commit also adds a minor correctness fix in
that the `read(2)` system call is now retried on `EINTR`.
PR-URL: https://github.com/libuv/libuv/pull/2876
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This test was consistently timing out on macOS. Some printf()
debugging on the CI showed that the test was still making forward
progress, but legitimately timed out. This commit bumps the test
timeout to a value that should provide much more than enough time.
Fixes: https://github.com/libuv/libuv/issues/2775
PR-URL: https://github.com/libuv/libuv/pull/2865
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
The QEMU CI broke recently. The calculation to determine the QEMU
version to install now returns multiple versions. This commit
updates the logic to only take the last result (which I think will
be the newest matching version).
PR-URL: https://github.com/libuv/libuv/pull/2864
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit runs the test suite via QEMU on GitHub Actions on
a variety of platforms.
Fixes: https://github.com/libuv/libuv/issues/2842
PR-URL: https://github.com/libuv/libuv/pull/2846
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Previously libuv was tested under the user class QSECOFR on IBM i.
But most IBM i users does not have that authority.
Refine some assertions to support common user profiles on IBM i.
Fixes: https://github.com/libuv/libuv/issues/2851
PR-URL: https://github.com/libuv/libuv/pull/2852
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
It was reported that `getrlimit(RLIMIT_STACK)` fails on some aarch64
systems due to a glibc bug, where the getrlimit() system call wrapper
invokes the wrong system call.
Libuv could work around that by issuing a `prlimit(2)` system call
instead but since it can't assume that said system call is available
(it was added in Linux 2.6.36, libuv's baseline is 2.6.32) it seems
easier to just use the default 2M stack size when the call fails.
Fixes: https://github.com/nodejs/node/issues/33244
Refs: https://bugzilla.redhat.com/show_bug.cgi?id=1813089
PR-URL: https://github.com/libuv/libuv/pull/2848
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Using AC_CHECK_LIB ignores symbols already provided by
other libraries, or in other words it links libuv against
libraries that it does not need.
Attempts to remove specific libraries were met with arguments
that older libc versions would still require them.[0]
Fix this by using AC_SEARCH_LIBS instead of AC_CHECK_LIB while
using AX_PTHREAD for POSIX threads.
[0] E.g. https://github.com/libuv/libuv/pull/2493
PR-URL: https://github.com/libuv/libuv/pull/2823
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Libuv was copying `sizeof(struct sockaddr_storage)` bytes from source to
destination but the source was only `sizeof(struct sockaddr_in6)` bytes
big, or approximately 128 vs. 16 bytes.
Fixes: https://github.com/libuv/libuv/issues/2840
PR-URL: https://github.com/libuv/libuv/pull/2841
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Replace two biggish `struct sockaddr_storage` instances with a union
of `struct sockaddr_in` and `struct sockaddr_in6`, the latter being
the largest that function supports.
PR-URL: https://github.com/libuv/libuv/pull/2841
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
`uv_signal_init()` leads to the allocation of an IO watcher,
so if the loop initialization fails at a later point,
the `loop->watchers` list needs to be released.
PR-URL: https://github.com/libuv/libuv/pull/2837
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Exposes the original system error of the filesystem syscalls. Adds a new
uv_fs_get_system_error which returns orignal errno on Linux or
GetLastError on Windows.
Ref: https://github.com/libuv/libuv/issues/2348
PR-URL: https://github.com/libuv/libuv/pull/2810
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
I was getting some weird results when copying a 5GB file on Alpine
Linux on Raspberry Pi. Out of the 5GB only 1.1GB would get copied and
the process would finish without an error. After some digging I found
out that there's a problem that some data types have smaller number of
bytes on Alpine Linux on Raspberry Pi than on other platforms
apparently.
When getting the size of the file in bytes, stat holds the size in
off_t data type, like this:
struct stat {
...
off_t st_size; /* total size, in bytes */
...
};
In my case, off_t has 8 bytes which is enough to hold a value up to
some exabytes. The problem is that it gets assigned to bytes_to_send
variable, which is size_t. In my case, size_t is only 4 bytes, which
is only good for about 4GB. If the file is any larger, there's an
overflow when assigning it from stat to bytes_to_send. That's easy
to fix, I just changed the data type of bytes_to_send to off_t.
However there's more.
The other 2 variables - in_offset and bytes_written also have to be
able to hold the size of the entire file, therefore it makes sense to
change them to off_t as well.
The last problem is that bytes_to_send is passed down to
uv_fs_sendfile() which converts it to size_t again. I could go and
change the types everywhere across the whole codebase to off_t but
that could break other things, so it seams a bit too much. A much
better solution is to have a proxy variable bytes_chunk that is
size_t type and copy as much bytes as possible at a time that can
fit into size_t. That way it will work the same as before on other
platforms, where size_t is more than 4 bytes.
PR-URL: https://github.com/libuv/libuv/pull/2758
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Commit 3d713663 ("freebsd,linux: add recvmmsg() + sendmmsg() udp
implementation") forgot to zero some of the members of the msghdr
struct. It seems to work by accident, not by design.
PR-URL: https://github.com/libuv/libuv/pull/2819
Refs: https://github.com/libuv/libuv/pull/2818
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
The Windows documentation states these should not be possible
but several people have reported that they do in fact happen.
Try with a smallish stack-allocated buffer first and switch to
a heap-allocated buffer if the first one is too small.
Fixes: https://github.com/libuv/libuv/issues/2587
PR-URL: https://github.com/libuv/libuv/pull/2589
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Make the documentation reflect that the init/start/stop functions
for check/idle/prepare handles always succeed.
PR-URL: https://github.com/libuv/libuv/pull/2803
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Adds manifest file that makes the test runner work with long filenames
when those are enabled in the system.
PR-URL: https://github.com/libuv/libuv/pull/2789
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Since Windows 10 1607 some WinApi functions no longer have a MAX_PATH
limit on the filenames length. This removes this hard-coded path length
limit from various places in libuv, switching to dynamically allocating
string buffers.
Fixes: https://github.com/libuv/libuv/issues/2331
PR-URL: https://github.com/libuv/libuv/pull/2788
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Commit 5736658b ("udp: add flag to enable recvmmsg(2) explicitly") added
the flag but didn't update the validation logic in src/win/udp.c.
This commit moves the validation logic to src/uv-common.c. The flag is
now accepted as a no-op on Windows.
Fixes: https://github.com/libuv/libuv/issues/2806
PR-URL: https://github.com/libuv/libuv/pull/2809
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Removes warnings W4100, W4127, W4201, W4206, W4210, W4232, W4456, W4457,
W4459, W4706 and W4996 when building with MSVC.
PR-URL: https://github.com/libuv/libuv/pull/2777
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This was causing a warning during the documentation build.
PR-URL: https://github.com/libuv/libuv/pull/2797
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This seems to be the case from reading the code of uv_cancel().
Also fixes a broken link due to a markup typo.
PR-URL: https://github.com/libuv/libuv/pull/2797
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: https://github.com/libuv/libuv/pull/2798
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Libuv already works without that API since commit 153ea114ff but still
had it as a hard requirement in the import table. This code uses the
`pGetQueuedCompletionStatusEx` function pointer instead, hence it also
works on systems that don't export `GetQueuedCompletionStatusEx`.
This simple fix improves compatibility of libuv with ReactOS and
Windows XP (latter using Vista+ compatibility libraries like
https://github.com/MyTDT-Mysoft/DllCompat)
PR-URL: https://github.com/libuv/libuv/pull/2800
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Make it possible to explicitly tell libuv to release any resources
it's still holding onto (memory, threads, file descriptors, etc.)
Before this commit, cleanup was performed in various destructors.
This commit centralizes the cleanup logic, enabling the addition of
`uv_library_shutdown()`, but maintains the current observable behavior
of cleaning up when libuv is unloaded by means of `dlclose(3)`.
Fixes: https://github.com/libuv/libuv/issues/2763
PR-URL: https://github.com/libuv/libuv/pull/2764
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
On Linux, cpu_times have been calculated differently to all other
platforms for a while. Other platforms (FreeBSD, Mac, Windows) are all
in milliseconds, but Linux has been returning values ten times larger.
libuv has not previously documented what unit cpu_times uses, even
though NodeJS did - as milliseconds.
Here we're both documenting that the cpu_times are indeed in
milliseconds, and fixing the inconsistency on Linux.
Fixes: https://github.com/libuv/libuv/issues/2773
PR-URL: https://github.com/libuv/libuv/pull/2796
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Changes since version 1.36.0:
* timer: remove redundant check in heap compare (Yash Ladha)
* udp: add flag to enable recvmmsg(2) explicitly (Saúl Ibarra Corretgé)
`timer_less_than()` function is basically a comparator function
that returns true or false. In the end of the function we were
checking for the comparison of id, but the later if is redundant
as we are anyways in the end are returning `0`. That extra check
can thus be safely removed.
PR-URL: https://github.com/libuv/libuv/pull/2785
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
* [AliceO2](https://github.com/AliceO2Group/AliceO2): The framework and detector specific code for the reconstruction, calibration and simulation for the ALICE experiment at CERN.
* [Beam](https://github.com/BeamMW/beam): A scalable, confidential cryptocurrency based on the Mimblewimble protocol.
* [BIND 9](https://bind.isc.org/): DNS software system including an authoritative server, a recursive resolver and related utilities.
* [racer](https://libraries.io/rubygems/racer): Ruby web server written as an C extension
* [scala-native-loop](https://github.com/scala-native/scala-native-loop): Extensible event loop and async-oriented IO for Scala Native; powered by libuv
* [Socket Runtime](https://sockets.sh): A runtime for creating native cross-platform software on mobile and desktop using HTML, CSS, and JavaScript
* [spider-gazelle](https://github.com/cotag/spider-gazelle): Ruby web server using libuv bindings
* [Suave](http://suave.io/): A simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition
* [Swish](https://github.com/becls/swish/): Concurrency engine with Erlang-like concepts. Includes a web server.
* [Trevi](https://github.com/Yoseob/Trevi): A powerful Swift Web Application Server Framework Project
* [Urbit](http://urbit.org): runtime
* [uv_callback](https://github.com/litesync/uv_callback) libuv thread communication
* [uvloop](https://github.com/MagicStack/uvloop): Ultra fast implementation of python's asyncio event loop on top of libuv
* [WPILib](https://github.com/wpilibsuite/allwpilib): Libraries for creating robot programs for the roboRIO.
* [Wren CLI](https://github.com/wren-lang/wren-cli): For io, process, scheduler and timer modules
### Other
* [libtuv](https://github.com/Samsung/libtuv): libuv fork for IoT and embedded systems
The libuv Conan recipe is kept up to date by Conan maintainers and community contributors.
If the version is out of date, please [create an issue or pull request](https://github.com/conan-io/conan-center-index) on the ConanCenterIndex repository.
### Running tests
### Running tests
Some tests are timing sensitive. Relaxing test timeouts may be necessary
Some tests are timing sensitive. Relaxing test timeouts may be necessary
@ -286,6 +309,16 @@ listed in `test/benchmark-list.h`.
Check the [SUPPORTED_PLATFORMS file](SUPPORTED_PLATFORMS.md).
Check the [SUPPORTED_PLATFORMS file](SUPPORTED_PLATFORMS.md).
### `-fno-strict-aliasing`
It is recommended to turn on the `-fno-strict-aliasing` compiler flag in
projects that use libuv. The use of ad hoc "inheritance" in the libuv API
may not be safe in the presence of compiler optimizations that depend on
strict aliasing.
MSVC does not have an equivalent flag but it also does not appear to need it
at the time of writing (December 2019.)
### AIX Notes
### AIX Notes
AIX compilation using IBM XL C/C++ requires version 12.1 or greater.
AIX compilation using IBM XL C/C++ requires version 12.1 or greater.
@ -298,6 +331,13 @@ describes the package in more detail.
### z/OS Notes
### z/OS Notes
z/OS compilation requires [ZOSLIB](https://github.com/ibmruntimes/zoslib) to be installed. When building with [CMake][], use the flag `-DZOSLIB_DIR` to specify the path to [ZOSLIB](https://github.com/ibmruntimes/zoslib):
Currently, we are providing security updates for the latest release in the v1.x series:
| Version | Supported |
| ------- | ------------------ |
| Latest v1.x | :white_check_mark: |
## Reporting a Vulnerability
If you believe you have found a security vulnerability in `libuv`, please use the [GitHub's private vulnerability reporting feature](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability#privately-reporting-a-security-vulnerability) in the [libuv repository](https://github.com/libuv/libuv) to report it to us.
This will allow us to assess the risk, and make a fix available before we add a bug report to the GitHub repository.
Please do:
* Provide as much information as you can about the vulnerability.
* Provide details about your configuration and environment, if applicable.
Please do not:
* Post any information about the vulnerability in public places.
* Attempt to exploit the vulnerability yourself.
We take all security bugs seriously. Thank you for improving the security of `libuv`. We appreciate your efforts and responsible disclosure and will make every effort to acknowledge your contributions.
Equivalent to :man:`realpath(3)` on Unix. Windows uses `GetFinalPathNameByHandle<https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea>`_.
Equivalent to :man:`realpath(3)` on Unix. Windows uses `GetFinalPathNameByHandleW<https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew>`_.
The resulting string is stored in `req->ptr`.
The resulting string is stored in `req->ptr`.
..warning::
..warning::
@ -463,10 +492,6 @@ API
The background story and some more details on these issues can be checked
The background story and some more details on these issues can be checked
For a OS-dependent handle, get the file descriptor in the C runtime.
For a OS-dependent handle, get the file descriptor in the C runtime.
On UNIX, returns the ``os_fd`` intact. On Windows, this calls `_open_osfhandle <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/open-osfhandle?view=vs-2019>`_.
On UNIX, returns the ``os_fd`` intact. On Windows, this calls `_open_osfhandle <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/open-osfhandle?view=vs-2019>`_.
Note that the return value is still owned by the CRT,
Note that this consumes the argument, any attempts to close it or to use it
any attempts to close it or to use it after closing the handle may lead to malfunction.
after closing the return value may lead to malfunction.
@ -87,6 +87,7 @@ nothing, except start a loop which will exit immediately.
..rubric:: helloworld/main.c
..rubric:: helloworld/main.c
..literalinclude:: ../../code/helloworld/main.c
..literalinclude:: ../../code/helloworld/main.c
:language:c
:linenos:
:linenos:
This program quits immediately because it has no events to process. A libuv
This program quits immediately because it has no events to process. A libuv
@ -108,6 +109,11 @@ A default loop is provided by libuv and can be accessed using
``uv_default_loop()``. You should use this loop if you only want a single
``uv_default_loop()``. You should use this loop if you only want a single
loop.
loop.
..rubric:: default-loop/main.c
..literalinclude:: ../../code/default-loop/main.c
:language:c
:linenos:
..note::
..note::
node.js uses the default loop as its main loop. If you are writing bindings
node.js uses the default loop as its main loop. If you are writing bindings
@ -118,9 +124,9 @@ loop.
Error handling
Error handling
--------------
--------------
Initialization functions or synchronous functions which may fail return a negative number on error. Async functions that may fail will pass a status parameter to their callbacks. The error messages are defined as ``UV_E*```constants`_.
Initialization functions or synchronous functions which may fail return a negative number on error. Async functions that may fail will pass a status parameter to their callbacks. The error messages are defined as ``UV_E*```constants`_.
:returns:0 on success, or an error code < 0 on failure.
:returns:0 on success, or an error code < 0 on failure.
..versionchanged:: 1.49.0 added the ``UV_UDP_REUSEPORT`` flag.
..note::
``UV_UDP_REUSEPORT`` flag is available only on Linux 3.9+, DragonFlyBSD 3.6+,
FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+ at the moment. On other platforms
this function will return an UV_ENOTSUP error.
For platforms where `SO_REUSEPORT`s have the capability of load balancing,
specifying both ``UV_UDP_REUSEADDR`` and ``UV_UDP_REUSEPORT`` in flags is allowed
and `SO_REUSEPORT` will always override the behavior of `SO_REUSEADDR`.
For platforms where `SO_REUSEPORT`s don't have the capability of load balancing,
specifying both ``UV_UDP_REUSEADDR`` and ``UV_UDP_REUSEPORT`` in flags will fail,
returning an UV_ENOTSUP error.
..c:function:: int uv_udp_connect(uv_udp_t* handle, const struct sockaddr* addr)
..c:function:: int uv_udp_connect(uv_udp_t* handle, const struct sockaddr* addr)
Associate the UDP handle to a remote address and port, so every
Associate the UDP handle to a remote address and port, so every
@ -257,7 +312,9 @@ API
local sockets.
local sockets.
:param handle:UDP handle. Should have been initialized with
:param handle:UDP handle. Should have been initialized with
:c:func:`uv_udp_init`.
:c:func:`uv_udp_init_ex` as either ``AF_INET`` or ``AF_INET6``, or have
been bound to an address explicitly with :c:func:`uv_udp_bind`, or
implicitly with :c:func:`uv_udp_send()` or :c:func:`uv_udp_recv_start`.
:param on:1 for on, 0 for off.
:param on:1 for on, 0 for off.
@ -268,7 +325,9 @@ API
Set the multicast ttl.
Set the multicast ttl.
:param handle:UDP handle. Should have been initialized with
:param handle:UDP handle. Should have been initialized with
:c:func:`uv_udp_init`.
:c:func:`uv_udp_init_ex` as either ``AF_INET`` or ``AF_INET6``, or have
been bound to an address explicitly with :c:func:`uv_udp_bind`, or
implicitly with :c:func:`uv_udp_send()` or :c:func:`uv_udp_recv_start`.
:param ttl:1 through 255.
:param ttl:1 through 255.
@ -279,7 +338,9 @@ API
Set the multicast interface to send or receive data on.
Set the multicast interface to send or receive data on.
:param handle:UDP handle. Should have been initialized with
:param handle:UDP handle. Should have been initialized with
:c:func:`uv_udp_init`.
:c:func:`uv_udp_init_ex` as either ``AF_INET`` or ``AF_INET6``, or have
been bound to an address explicitly with :c:func:`uv_udp_bind`, or
implicitly with :c:func:`uv_udp_send()` or :c:func:`uv_udp_recv_start`.
:param interface_addr:interface address.
:param interface_addr:interface address.
@ -290,7 +351,9 @@ API
Set broadcast on or off.
Set broadcast on or off.
:param handle:UDP handle. Should have been initialized with
:param handle:UDP handle. Should have been initialized with
:c:func:`uv_udp_init`.
:c:func:`uv_udp_init_ex` as either ``AF_INET`` or ``AF_INET6``, or have
been bound to an address explicitly with :c:func:`uv_udp_bind`, or
implicitly with :c:func:`uv_udp_send()` or :c:func:`uv_udp_recv_start`.
:param on:1 for on, 0 for off.
:param on:1 for on, 0 for off.
@ -301,7 +364,9 @@ API
Set the time to live.
Set the time to live.
:param handle:UDP handle. Should have been initialized with
:param handle:UDP handle. Should have been initialized with
:c:func:`uv_udp_init`.
:c:func:`uv_udp_init_ex` as either ``AF_INET`` or ``AF_INET6``, or have
been bound to an address explicitly with :c:func:`uv_udp_bind`, or
implicitly with :c:func:`uv_udp_send()` or :c:func:`uv_udp_recv_start`.
:param ttl:1 through 255.
:param ttl:1 through 255.
@ -361,6 +426,20 @@ API
..versionchanged:: 1.27.0 added support for connected sockets
..versionchanged:: 1.27.0 added support for connected sockets
..c:function:: int uv_udp_try_send2(uv_udp_t* handle, unsigned int count, uv_buf_t* bufs[/*count*/], unsigned int nbufs[/*count*/], struct sockaddr* addrs[/*count*/], unsigned int flags)
Like :c:func:`uv_udp_try_send`, but can send multiple datagrams.
Lightweight abstraction around :man:`sendmmsg(2)`, with a :man:`sendmsg(2)`
fallback loop for platforms that do not support the former. The handle must
be fully initialized; call c:func:`uv_udp_bind` first.
:returns:>= 0: number of datagrams sent. Zero only if `count` was zero.
< 0: negative error code. Only if sending the first datagram fails,
otherwise returns a positive send count. ``UV_EAGAIN`` when datagrams
cannot be sent right now; fall back to :c:func:`uv_udp_send`.
..versionadded:: 1.50.0
..c:function:: int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb)
..c:function:: int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb)
Prepare for receiving data. If the socket has not previously been bound
Prepare for receiving data. If the socket has not previously been bound
@ -376,9 +455,27 @@ API
:returns:0 on success, or an error code < 0 on failure.
:returns:0 on success, or an error code < 0 on failure.
..note::
When using :man:`recvmmsg(2)`, the number of messages received at a time is limited
by the number of max size dgrams that will fit into the buffer allocated in `alloc_cb`, and
`suggested_size` in `alloc_cb` for udp_recv is always set to the size of 1 max size dgram.
..versionchanged:: 1.35.0 added support for :man:`recvmmsg(2)` on supported platforms).
..versionchanged:: 1.35.0 added support for :man:`recvmmsg(2)` on supported platforms).
The use of this feature requires a buffer larger than
The use of this feature requires a buffer larger than
2 * 64KB to be passed to `alloc_cb`.
2 * 64KB to be passed to `alloc_cb`.
..versionchanged:: 1.37.0 :man:`recvmmsg(2)` support is no longer enabled implicitly,
it must be explicitly requested by passing the `UV_UDP_RECVMMSG` flag to
:c:func:`uv_udp_init_ex`.
..versionchanged:: 1.39.0 :c:func:`uv_udp_using_recvmmsg` can be used in `alloc_cb` to
determine if a buffer sized for use with :man:`recvmmsg(2)` should be
allocated for the current handle/platform.
..c:function:: int uv_udp_using_recvmmsg(uv_udp_t* handle)
Returns 1 if the UDP handle was created with the `UV_UDP_RECVMMSG` flag
and the platform supports :man:`recvmmsg(2)`, 0 otherwise.
..versionadded:: 1.39.0
..c:function:: int uv_udp_recv_stop(uv_udp_t* handle)
..c:function:: int uv_udp_recv_stop(uv_udp_t* handle)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.