Compare commits

...

602 Commits

Author SHA1 Message Date
Ben Noordhuis
16d6a0b49d
unix: handle out of memory in iface name copy (#4724)
Allocate storage upfront, that way we can never run out of memory
halfway through processing the interface list.

Fixes: https://github.com/libuv/libuv/issues/4723
2025-02-27 23:30:29 +01:00
Stacey Marshall
436c04048e
unix,sunos: enable use of sendmmsg on Solaris and Illumos (#4717)
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
2025-02-27 12:24:40 -05:00
Tobias Nießen
feddddb56b
doc: fix rendering of threading.html (#4716) 2025-02-25 19:03:07 -05:00
Colin Ihrig
f61f9c29d8
test: handle UV_ENOTSUP in platform_output (#4714)
Fixes: https://github.com/libuv/libuv/issues/4713
2025-02-25 13:22:10 -05:00
Anna Henningsen
843b64faf5
win: add ENABLE_VIRTUAL_TERMINAL_INPUT raw tty mode (#4688)
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
2025-02-21 23:34:53 +01:00
Ben Noordhuis
85b526f56a
unix,win: accept NAN/INFINITY as file timestamps (#4702)
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
2025-02-21 23:08:15 +01:00
Paolo Insogna
8a94b7b2ec
unix: enable getrusage for SunOS (#4707)
Fixes: https://github.com/libuv/libuv/issues/4706
2025-02-21 22:02:18 +01:00
rainlow
b807450e98
unix: add thread affinity support on openharmony (#4705) 2025-02-21 22:01:16 +01:00
Hüseyin Açacak
82cdfb75ff win: fix the inconsistency in volume serial number 2025-02-17 08:35:37 +01:00
Juan José Arboleda
dcace2a393 unix: remove unnecessary errno.h include in poll.c
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-02-17 07:51:25 +01:00
Velikiy Kirill
378edb28f4
doc: add C3 bindings to LINKS.md (#4699) 2025-02-15 11:11:35 -05:00
Jinho Jang
7894072528
macos: increase child process stdio buffer size (#4694)
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.
2025-02-10 10:07:50 -05:00
Hüseyin Açacak
abe59d6319 win: fix order of FILE_STAT_BASIC_INFORMATION struct fields 2025-02-10 12:32:57 +01:00
Julio Jordán
e399e00e78
doc: fix README link text (#4693) 2025-02-08 09:42:12 -05:00
Andrey
51477bc711
macos,bsd: handle missing /dev/null in chroot env (#4689)
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
2025-02-04 21:43:18 +01:00
Morten Engelhardt Olsen
23632e9104
win: check cwd length before spawning a child process
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.
2025-01-29 22:51:06 +01:00
Ben Noordhuis
a6ddf41edf
linux: try preadv64/pwritev64 before preadv/pwritev (#4683)
Fixes: https://github.com/libuv/libuv/issues/4678
Refs: https://github.com/libuv/libuv/issues/4532
2025-01-28 09:27:58 +01:00
Ben Noordhuis
82351168b3
win: lazy-load [GS]etThreadDescription symbols (#4679)
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
2025-01-24 21:53:22 +01:00
Saúl Ibarra Corretgé
bc19beadbd docs: fix RTD build
Setting the configuration key is now mandatory: https://about.readthedocs.com/blog/2024/12/deprecate-config-files-without-sphinx-or-mkdocs-config/
2025-01-24 14:11:13 +01:00
Saúl Ibarra Corretgé
f15c602bd0 win: fix leak in uv_os_tmpdir
Fixes: https://github.com/libuv/libuv/issues/4680
2025-01-24 11:46:16 +01:00
Santiago Gimeno
0f31978c30
Now working on version 1.50.1 2025-01-15 19:11:00 +01:00
Santiago Gimeno
a2ba04f83f Add SHA to ChangeLog 2025-01-15 19:05:30 +01:00
Santiago Gimeno
8fb9cb9194 2025.01.15, Version 1.50.0 (Stable)
Changes since version 1.49.2:

* ci: run macOS and iOS tests also on macOS 14 (Saúl Ibarra Corretgé)

* unix,win: map ENOEXEC errno (Saúl Ibarra Corretgé)

* test: skip multicast join test on ENOEXEC (Saúl Ibarra Corretgé)

* ci: make sure the macOS firewall is disabled (Saúl Ibarra Corretgé)

* darwin,test: squelch EBUSY error on multicast join (Saúl Ibarra
  Corretgé)

* build: update minimum cmake to 3.10 (Ben Noordhuis)

* kqueue: use EVFILT_USER for async if available (Jameson Nash)

* unix,win: fix off-by-one in uv_wtf8_to_utf16() (Ben Noordhuis)

* doc: add scala-native-loop to LINKS.md (Julian A Avar C)

* unix: fix build breakage on haiku, openbsd, etc (Jeffrey H. Johnson)

* kqueue: lower overhead in uv__io_check_fd (Andy Pan)

* doc: move cjihrig back to active maintainers (cjihrig)

* build(deps): bump actions/checkout from 3 to 4 (dependabot[bot])

* unix,pipe: fix handling null buffer in uv_pipe_get{sock,peer}name
  (Saúl Ibarra Corretgé)

* unix,win: harmonize buffer checking (Saúl Ibarra Corretgé)

* unix,win: add support for detached threads (Juan José Arboleda)

* src: add uv_thread_set/getname() methods (Santiago Gimeno)

* build: fix qemu builds (Ben Noordhuis)

* win: drop support for windows 8 (Ben Noordhuis)

* linux: fix uv_cpu_info() arm cpu model detection (Ben Noordhuis)

* linux: always use io_uring for epoll batching (Ben Noordhuis)

* doc: clarify repeating timer behavior more (Ben Noordhuis)

* unix,win: handle nbufs=0 in uv_udp_try_send (Ben Noordhuis)

* win: use GetQueuedCompletionStatusEx directly (Saúl Ibarra Corretgé)

* win: enable uv_thread_{get,set}name on MinGW (Saúl Ibarra Corretgé)

* win: drop support for the legacy MinGW (Saúl Ibarra Corretgé)

* win,fs: get (most) fstat when no permission (Jameson Nash)

* win: plug uv_fs_event_start memory leak (amcgoogan)

* test: address FreeBSD kernel bug causing NULL path in fsevents (Juan
  José Arboleda)

* unix: refactor udp sendmsg code (Ben Noordhuis)

* unix,win: add uv_udp_try_send2 (Ben Noordhuis)

* test: fix flaky flaky udp_mmsg test (Juan José Arboleda)

* build: enable fdsan in Android (Juan José Arboleda)

* test: fix udp-multicast-join for FreeBSD (Juan José Arboleda)

* win: fix leak processing fs event (Saúl Ibarra Corretgé)

* src: set a default thread name for workers (Rafael Gonzaga)

* misc: implement uv_getrusage_thread (Juan José Arboleda)
2025-01-15 19:05:29 +01:00
Juan José
be8eec8c5a
misc: implement uv_getrusage_thread (#4666)
Refs: https://github.com/libuv/libuv/issues/3119

Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
Co-authored-by: James M Snell <jasnell@gmail.com>
2025-01-14 14:50:26 +01:00
Rafael Gonzaga
e59e2a9e49
src: set a default thread name for workers (#4664) 2025-01-08 13:58:28 +01:00
Saúl Ibarra Corretgé
ec5a4b54f7 win: fix leak processing fs event
Fixes: https://github.com/libuv/libuv/pull/4376#issuecomment-2544728609
2024-12-16 13:58:43 +01:00
Juan José
beebf02cf6
test: fix udp-multicast-join for FreeBSD (#4655)
Fixes: https://github.com/libuv/libuv/issues/4651

Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2024-12-16 09:05:09 +01:00
Juan José Arboleda
a94f2ad2b7 build: enable fdsan in Android
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
2024-12-16 09:01:15 +01:00
Juan José
3d78d121f4
test: fix flaky flaky udp_mmsg test (#4652)
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>
2024-12-15 20:24:20 +01:00
Ben Noordhuis
e8969bff6c unix,win: add uv_udp_try_send2
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.
2024-12-13 21:52:59 +01:00
Ben Noordhuis
7b4cf04a91 unix: refactor udp sendmsg code
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.
2024-12-13 21:52:59 +01:00
Juan José
acebb97490
test: address FreeBSD kernel bug causing NULL path in fsevents (#4649)
This commit documents a FreeBSD kernel issue where uv_fs_event can
receive a NULL filename and updates test-fs-event.c to skip filename
assertions on FreeBSD.

* Bugzilla: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=197695

Refs: https://github.com/libuv/libuv/issues/4606

Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2024-12-13 15:30:17 -05:00
amcgoogan
88201044ed
win: plug uv_fs_event_start memory leak (#4647)
Co-authored-by: Andrew McGoogan <amcgoogan@cribl.io>
Fixes: https://github.com/nodejs/node/issues/52769
2024-12-13 00:23:36 +01:00
Jameson Nash
72d9abccd7
win,fs: get (most) fstat when no permission (#4566)
Replaces: https://github.com/libuv/libuv/pull/4504
Fixes: https://github.com/libuv/libuv/issues/1980
Fixes: https://github.com/libuv/libuv/issues/3267

Co-authored-by: Hüseyin Açacak <huseyin@janeasystems.com>
2024-12-12 15:05:53 -05:00
Saúl Ibarra Corretgé
16e6e84dcc
win: drop support for the legacy MinGW (#4645)
The OG MinGW has been dead for years, MinGW-w64 has taken its place.
2024-12-12 15:59:30 +01:00
Saúl Ibarra Corretgé
7752218db2 fixup! 2024-12-12 15:55:16 +01:00
Saúl Ibarra Corretgé
88baee1a35 fixup! 2024-12-12 15:55:16 +01:00
Saúl Ibarra Corretgé
264bb335af win: enable uv_thread_{get,set}name on MinGW
It supports the API: 93f3505a75/mingw-w64-headers/include/processthreadsapi.h (L358)
2024-12-12 15:55:16 +01:00
Saúl Ibarra Corretgé
6af08fb527 win: use GetQueuedCompletionStatusEx directly
It was introduced in Vista, so we can assume it's always there now.
2024-12-10 23:44:29 +01:00
Ben Noordhuis
2494c088f0
unix,win: handle nbufs=0 in uv_udp_try_send (#4641) 2024-12-09 21:14:01 +01:00
Ben Noordhuis
467859c2ba
doc: clarify repeating timer behavior more (#4640)
It was already documented but only in the uv_timer_set_repeat section.
Move it to the toplevel and flesh it out more.

Refs: https://github.com/libuv/libuv/issues/181
Refs: https://github.com/libuv/libuv/discussions/4639
2024-12-08 22:32:49 +01:00
Ben Noordhuis
69bad8201b
linux: always use io_uring for epoll batching (#4638)
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
2024-12-06 00:11:05 +01:00
Ben Noordhuis
c431bc39c3
linux: fix uv_cpu_info() arm cpu model detection (#4633)
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
2024-12-03 00:31:06 +01:00
Ben Noordhuis
14644080c8
win: drop support for windows 8 (#4624)
Fixes: https://github.com/libuv/libuv/issues/3889
2024-11-28 22:02:41 +01:00
Ben Noordhuis
3d0578e6eb
build: fix qemu builds (#4630)
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.
2024-11-28 21:06:05 +01:00
Santiago Gimeno
61c966cf0b
src: add uv_thread_set/getname() methods (#4599)
`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.
2024-11-27 12:52:18 +01:00
Ben Noordhuis
b7d07d78e9
Revert "kqueue: change EV_OOBAND to EVFILT_EXCEPT+NOTE_OOB (#4597)" (#4623)
Unsupported on FreeBSD, breaking the build.

This reverts commit b1d30f9489.
2024-11-26 18:58:45 +01:00
Juan José
556a0f1f0f
unix,win: add support for detached threads (#4621)
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>
2024-11-26 08:44:38 -05:00
Juan José
b1d30f9489
kqueue: change EV_OOBAND to EVFILT_EXCEPT+NOTE_OOB (#4597)
Fixes: https://github.com/libuv/libuv/issues/3947
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2024-11-25 22:42:38 +01:00
Saúl Ibarra Corretgé
c6d43bea09
unix,win: harmonize buffer checking
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);
...
```
2024-11-25 15:10:47 +01:00
Saúl Ibarra Corretgé
31ea3411cc unix,pipe: fix handling null buffer in uv_pipe_get{sock,peer}name
Fixes: https://github.com/libuv/libuv/issues/4610
2024-11-22 08:57:45 +01:00
dependabot[bot]
d05744e3ed
build(deps): bump actions/checkout from 3 to 4 (#4490)
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.
2024-11-21 08:38:56 -05:00
Colin Ihrig
1b084f7bbe
doc: move cjihrig back to active maintainers (#4615) 2024-11-20 11:37:56 -05:00
Andy Pan
5dcef22c62
kqueue: lower overhead in uv__io_check_fd (#4617)
Merge kevent calls along with the improvement of code simplicity.

Signed-off-by: Andy Pan <i@andypan.me>
2024-11-20 14:30:14 +01:00
Jeffrey H. Johnson
15e3f84678
unix: fix build breakage on haiku, openbsd, etc (#4618)
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>
2024-11-20 14:24:20 +01:00
Julian A Avar C
2907f6d69e
doc: add scala-native-loop to LINKS.md (#4613) 2024-11-19 19:47:51 +01:00
Ben Noordhuis
c6b67af390
unix,win: fix off-by-one in uv_wtf8_to_utf16() (#4609)
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
2024-11-19 19:09:03 +01:00
Jameson Nash
7b75935b00
kqueue: use EVFILT_USER for async if available (#4588)
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>
2024-11-18 16:13:28 -05:00
Ben Noordhuis
2d8371a06e
build: update minimum cmake to 3.10 (#4604)
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
2024-11-15 18:48:13 +01:00
Saúl Ibarra Corretgé
d4ab6fbba4 darwin,test: squelch EBUSY error on multicast join
The firewall was suspected to be the culprit, but the test
intermittently fails in the CI, not locally.
2024-10-22 10:26:32 +02:00
Saúl Ibarra Corretgé
e129cd7fda ci: make sure the macOS firewall is disabled
It seems to be disabled by default, for now, but let's log its status
and disable it just in case.
2024-10-22 10:26:32 +02:00
Saúl Ibarra Corretgé
a3abfbcb08 test: skip multicast join test on ENOEXEC
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
2024-10-22 10:26:32 +02:00
Saúl Ibarra Corretgé
64f4502b9b unix,win: map ENOEXEC errno 2024-10-22 10:26:32 +02:00
Saúl Ibarra Corretgé
0caf5bb876 ci: run macOS and iOS tests also on macOS 14
The macOS 14 runners are ARM64 (in the non "large" version) whereas
macOS 13 runners are still x64, so keep that one around too.
2024-10-22 10:26:32 +02:00
Santiago Gimeno
94e467ad93
Now working on version 1.49.3 2024-10-18 21:08:15 +02:00
Santiago Gimeno
078180e13d Add SHA to ChangeLog 2024-10-18 21:02:38 +02:00
Santiago Gimeno
e1095c7a43 2024.10.18, Version 1.49.2 (Stable)
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)
2024-10-18 21:02:38 +02:00
Jameson Nash
058c49b7ba
win,fs: match trailing slash presence in junctions to user input (#4590)
Refs: #4582
2024-10-18 21:01:07 +02:00
Jameson Nash
7e6590f31d
win: remap ERROR_NOACCESS and ERROR_BUFFER_OVERFLOW (#4567)
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.
2024-10-17 15:37:00 -04:00
Thad House
9cf0710d71
win: fix compilation against Windows 24H2 SDK (#4576)
Compilation against the 24H2 SDK is broken by #4327.

Fix that issue by only conditionally defining the new values.

Closes #4575
2024-10-17 15:36:45 -04:00
Thad House
52a9243317
win: Fix linked list logic in getaddrinfo (#4578)
The logic in #4254 is incorrect, and results in the addrinfo linked
list only having a single result. Fix this by correcting the logic.

Closes #4577
2024-10-17 15:36:07 -04:00
Ben Noordhuis
18d48bc13c
Revert "linux: eliminate a read on eventfd per wakeup (#4400)" (#4585)
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
2024-10-17 20:41:38 +02:00
Hüseyin Açacak
fbe2d85bd5 win,fs: remove trailing slash in junctions
Fixes: https://github.com/libuv/libuv/issues/3329
2024-10-15 09:48:27 +02:00
Santiago Gimeno
be0b00a80d
Now working on version 1.49.2 2024-10-11 09:21:05 +02:00
Santiago Gimeno
bfbd6db0d6 Add SHA to ChangeLog 2024-10-11 09:13:11 +02:00
Santiago Gimeno
8be336f4ee 2024.10.11, Version 1.49.1 (Stable)
Changes since version 1.49.0:

* build: add darwin-syscalls.h to release tarball (Ben Noordhuis)

* linux: use IORING_SETUP_NO_SQARRAY when available (Ben Noordhuis)

* linux: use IORING_OP_FTRUNCATE when available (Ben Noordhuis)

* win: fix pNtQueryDirectoryFile check (Rialbat)

* win: fix WriteFile() error translation (Santiago Gimeno)

* win,fs: uv_fs_rmdir() to return ENOENT on file (Santiago Gimeno)

* win,pipe: ipc code does not support async read (Jameson Nash)

* netbsd: fix build (Adam)

* win,fs: fix bug in fs__readdir (Hüseyin Açacak)

* unix: workaround gcc bug on armv7 (Santiago Gimeno)

* unix: work around arm-linux-gnueabihf-gcc bug (Ben Noordhuis)

* unix: fix uv_tcp_keepalive in smartOS (Santiago Gimeno)

* unix: fix uv_getrusage ru_maxrss on solaris (Poul T Lomholt)
2024-10-11 09:13:10 +02:00
Poul T Lomholt
7c3abfbf1e
unix: fix uv_getrusage ru_maxrss on solaris (#4572) 2024-10-10 17:04:11 +02:00
Santiago Gimeno
1f36b01ed0
unix: fix uv_tcp_keepalive in smartOS (#4570)
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.
2024-10-09 09:52:00 +02:00
Ben Noordhuis
8d957c56b3
unix: work around arm-linux-gnueabihf-gcc bug (#4565)
Both gcc 11 and 12 emit wrong code for a function call pointer in one
very specific context.

Fixes: https://github.com/libuv/libuv/issues/4532
2024-10-08 08:57:22 +02:00
Santiago Gimeno
0be52c8251
unix: workaround gcc bug on armv7 (#4564)
Disable optimization on `uv__preadv_or_pwritev`.

Fixes: https://github.com/libuv/libuv/issues/4532
Fixes: https://github.com/libuv/libuv/issues/4550
2024-10-07 08:47:16 +02:00
Hüseyin Açacak
1cbffcbd5d win,fs: fix bug in fs__readdir 2024-10-04 13:33:22 +02:00
Adam
670e75ee7e
netbsd: fix build 2024-10-04 09:26:07 +02:00
Jameson Nash
f55efb2f38
win,pipe: ipc code does not support async read (#4555)
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
2024-10-03 22:12:22 +02:00
Santiago Gimeno
88b874e63c
win,fs: uv_fs_rmdir() to return ENOENT on file (#4563)
After commit 18266a6969, it changed to return `ENOTDIR`, which makes it
consistent with other platforms but it also can be considered a breaking
change.
2024-10-03 21:29:10 +02:00
Santiago Gimeno
473dafc593
win: fix WriteFile() error translation (#4562)
Translate `ERROR_BROKEN_PIPE` and `ERROR_NO_DATA` to `UV_EPIPE` instead
of their default translation, which will be used for the rest of cases.

Refs: https://github.com/libuv/libuv/issues/4548#issuecomment-2383998849
2024-10-03 18:53:39 +02:00
Rialbat
65e3735320 win: fix pNtQueryDirectoryFile check
Fixed incorrect verification of the pNtQueryDirectoryFile pointer.
2024-10-03 08:59:39 +02:00
Ben Noordhuis
f806be87d3
linux: use IORING_OP_FTRUNCATE when available (#4554)
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.
2024-09-30 21:55:34 +02:00
Ben Noordhuis
bcc6d1c1fc
linux: use IORING_SETUP_NO_SQARRAY when available (#4553)
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.
2024-09-30 19:44:27 +02:00
Ben Noordhuis
675a5a5396
build: add darwin-syscalls.h to release tarball (#4546)
Overlooked in commit 1c778bd0 ("darwin: add udp mmsg support") from
earlier this month.

Fixes: https://github.com/libuv/libuv/issues/4544
2024-09-26 09:45:36 +02:00
Santiago Gimeno
5467ec969a
Now working on version 1.49.1 2024-09-25 10:37:04 +02:00
Santiago Gimeno
511e202e13 Add SHA to ChangeLog 2024-09-25 10:17:21 +02:00
Santiago Gimeno
d2e56a5e8d 2024.09.25, Version 1.49.0 (Stable)
Changes since version 1.48.0:

* test: fix -Wpointer-to-int-cast on 32 bits systems (Ben Noordhuis)

* build: add alias for libuv to CMakeLists.txt (Anthony Alayo)

* linux: create io_uring sqpoll ring lazily (Ben Noordhuis)

* misc: run sample CI when code changes (Jameson Nash)

* linux: fix uv_available_parallelism using cgroup (Thomas Walter)

* doc: fix tty example segfault (hiiizxf)

* udp,unix: fix sendmsg use-after-free (Geddy)

* cygwin: implement uv_resident_set_memory (Farzin Monsef)

* win: almost fix race detecting ESRCH in uv_kill (Santiago Gimeno)

* test: disable env var test under win32+asan (Ben Noordhuis)

* unix,fs: fix realpath calls that use the system allocator (Saúl Ibarra
  Corretgé)

* sunos: sync tcp keep-alive with other unices (Andy Pan)

* linux: fix /proc/self/stat executable name parsing (Farzin Monsef)

* test,ci: fix [AM]San, disable ASLR (Ben Noordhuis)

* win: remove _alloca usage (Ben Noordhuis)

* unix: reinstate preadv/pwritev fallback code (Ben Noordhuis)

* linux: don't delay EPOLL_CTL_DEL operations (Ben Noordhuis)

* doc: fix typos in ChangeLog (tgolang)

* unix,win: error on zero delay tcp keepalive (Saúl Ibarra Corretgé)

* win: simplify uv_once implementation (Saúl Ibarra Corretgé)

* doc: correct udp socket options documentation (Ben Noordhuis)

* linux: don't use sendmmsg() for single datagrams (Ben Noordhuis)

* unix: fix fd leaks in SCM_RIGHTS error path (Ben Noordhuis)

* win: robustify uv_os_getenv() error checking (Ben Noordhuis)

* test: use newer ASSERT_MEM_EQ macro (Ben Noordhuis)

* unix: de-duplicate conditions for using kqueue (Brad King)

* darwin: simplify uv_hrtime (Saúl Ibarra Corretgé)

* mailmap: update saghul's main email address (Saúl Ibarra Corretgé)

* win: remove no longer needed define (Saúl Ibarra Corretgé)

* doc: fix some typos (josedelinux)

* linux,darwin: make `uv_fs_copyfile` behaves like `cp -r` (Juan José
  Arboleda)

* dragonfly: disable SO_REUSEPORT for UDP socket bindings (Andy Pan)

* test: remove the obsolete HAVE_KQUEUE macro (Andy Pan)

* unix: use the presence of SOCK_* instead of OS macros for socketpair
  (Andy Pan)

* bsd: support pipe2() on *BSD (Andy Pan)

* unix: support SO_REUSEPORT with load balancing for TCP (Andy Pan)

* doc: add entries for extended getpw (Juan José Arboleda)

* test: fix the flaky test-tcp-reuseport (Andy Pan)

* aix,ibmi: fix compilation errors in fs_copyfile (Jeffrey H. Johnson)

* unix: support SO_REUSEPORT with load balancing for UDP (Andy Pan)

* tcpkeepalive: distinguish OS versions and use proper time units (Andy
  Pan)

* win: map ERROR_BAD_EXE_FORMAT to UV_EFTYPE (Hüseyin Açacak)

* doc: add instruction how to install with Conan (Uilian Ries)

* unix,win: remove unused req parameter from macros (Viacheslav
  Muravyev)

* build: fix android ci build (Ben Noordhuis)

* unix,win: export wtf8 functions properly (Ben Noordhuis)

* hurd: add includes and macro prerequisites (Olivier Valentin)

* hurd: stub uv_thread_setpriority() (Olivier Valentin)

* ci: use macOS 12 for macOS and iOS builds (Saúl Ibarra Corretgé)

* darwin: fix crash on iOS(arm64) (郑苏波 (Super Zheng))

* Create dependabot.yml for updating github-actions (Jameson Nash)

* doc: correct names of Win32 APIs in fs.rst (zeertzjq)

* ci: bump upload and download-artifact versions (dependabot[bot])

* ci: bump actions/setup-python from 4 to 5 (dependabot[bot])

* ci: bump KyleMayes/install-llvm-action from 1 to 2 (dependabot[bot])

* win,error: remap ERROR_NO_DATA to EAGAIN (Jameson Nash)

* test: handle zero-length udp datagram (Ben Noordhuis)

* misc: remove splay trees macros (Viacheslav Muravyev)

* test,openbsd: remove superfluous ifdef guard (Ben Noordhuis)

* win,fs: use posix delete semantics, if supported (Ian Butterworth)

* win: fix env var in uv_os_homedir and uv_os_tmpdir (Hüseyin Açacak)

* fsevents: detect watched directory removal (Santiago Gimeno)

* ci: bump actions/checkout to 4 (dependabot[bot])

* linux: eliminate a read on eventfd per wakeup (Andy Pan)

* test: pipe_overlong_path handle ENAMETOOLONG (Abdirahim Musse)

* win,fs: use the new Windows fast stat API (Hüseyin Açacak)

* win,pipe: fix race with concurrent readers (Jameson Nash)

* win,signal: fix data race dispatching SIGWINCH (Jameson Nash)

* build: ubsan fixes (Matheus Izvekov)

* linux: disable SQPOLL io_uring by default (Santiago Gimeno)

* win: fix fs.c ubsan failure (Matheus Izvekov)

* test: rmdir can return `EEXIST` or `ENOTEMPTY` (Richard Lau)

* test: check for `UV_CHANGE` or `UV_RENAME` event (Richard Lau)

* unix,fs: silence -Wunused-result warning (Santiago Gimeno)

* linux: support abstract unix socket autobinding (Ben Noordhuis)

* kqueue: use EVFILT_USER for async if available (Andy Pan)

* win: remove deprecated GetVersionExW call (Shelley Vohr)

* doc: document uv_loop_option (握猫猫)

* doc: fix the `uv_*_set_data` series of functions (握猫猫)

* doc: properly label enumerations and types (握猫猫)

* doc: document specific macOS fs_event behavior (Santiago Gimeno)

* win,pipe: restore fallback handling for blocking pipes (Jameson Nash)

* unix,win: remove unused rb-tree macro parameters (Viacheslav Muravyev)

* win: compute parallelism from process cpu affinity (Ben Noordhuis)

* win: use NtQueryInformationProcess in uv_os_getppid (Zuohui Yang)

* win,pipe: fix missing assignment to success (Jameson Nash)

* win: fix uv_available_parallelism on win32 (Ben Noordhuis)

* win,pipe: fix another missing assignment to success (Jameson Nash)

* kqueue: disallow ill-suited file descriptor kinds (Andy Pan)

* unix: restore tty attributes on handle close (Ben Noordhuis)

* test: delete test with invalid assumption (Ben Noordhuis)

* dragonflybsd: fix compilation failure (Jeffrey H. Johnson)

* test: run android tests on ci (Edigleysson Silva (Edy))

* darwin: add udp mmsg support (Raihaan Shouhell)

* unix: work around arm-linux-gnueabihf-gcc bug (Ben Noordhuis)

* unix: expand uv_available_parallelism() to support more platforms
  (Ondřej Surý)

* doc: add known issue in armv7 (Santiago Gimeno)
2024-09-25 10:17:20 +02:00
Santiago Gimeno
cc2e0aa3cf
doc: add known issue in armv7 (#4541)
Refs: https://github.com/libuv/libuv/issues/4532
2024-09-24 21:31:51 +02:00
Ondřej Surý
e1a5465255 unix: expand uv_available_parallelism() to support more platforms 2024-09-24 10:54:48 +02:00
Ben Noordhuis
32603fd5ff
unix: work around arm-linux-gnueabihf-gcc bug (#4537)
Both gcc 11 and 12 emit wrong code for a function call pointer in one
very specific context.

Fixes: https://github.com/libuv/libuv/issues/4532
2024-09-19 19:53:19 +02:00
Raihaan Shouhell
1c778bd001
darwin: add udp mmsg support (#4527) 2024-09-17 23:15:37 +02:00
Edigleysson Silva (Edy)
5bb19f35ea
test: run android tests on ci (#4517) 2024-09-17 21:30:24 +02:00
Jeffrey H. Johnson
88af4a87d2
dragonflybsd: fix compilation failure (#4534)
Fixes: https://github.com/libuv/libuv/issues/4533
Signed-off-by: Jeffrey H. Johnson <trnsz@pobox.com>
2024-09-17 21:27:18 +02:00
Ben Noordhuis
9dddebab0d
test: delete test with invalid assumption (#4530)
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
2024-09-12 22:19:10 +02:00
Ben Noordhuis
a49f264dff
unix: restore tty attributes on handle close (#4399)
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
2024-09-11 10:33:54 +02:00
Andy Pan
44e61dab7e
kqueue: disallow ill-suited file descriptor kinds (#4513)
Follows up on https://github.com/libuv/libuv/pull/659.

Signed-off-by: Andy Pan <i@andypan.me>
2024-09-09 20:22:15 +02:00
Jameson Nash
0a00e80c36
win,pipe: fix another missing assignment to success (#4523)
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.
2024-09-05 09:46:37 -04:00
Ben Noordhuis
5ff1fc724f
win: fix uv_available_parallelism on win32 (#4525)
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
2024-09-02 11:24:11 +02:00
Jameson Nash
f00d4b6775
win,pipe: fix missing assignment to success (#4515) 2024-08-28 19:59:46 -04:00
Zuohui Yang
5cbc82e369
win: use NtQueryInformationProcess in uv_os_getppid (#4514)
Get parent process ID using NtQueryInformationProcess, it's faster than
using CreateToolhelp32Snapshot.
2024-08-26 20:17:53 +02:00
Ben Noordhuis
58dfb6c89b
win: compute parallelism from process cpu affinity (#4521)
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
2024-08-26 10:22:42 +02:00
Viacheslav Muravyev
b5eb41d882
unix,win: remove unused rb-tree macro parameters (#4518) 2024-08-25 22:54:09 +02:00
Jameson Nash
c869cd1d8a
win,pipe: restore fallback handling for blocking pipes (#4511)
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.
2024-08-22 11:08:08 -04:00
Santiago Gimeno
5cc7175514
doc: document specific macOS fs_event behavior (#4503) 2024-08-17 13:44:37 +02:00
握猫猫
3e1733a053
doc: properly label enumerations and types (#4506) 2024-08-16 19:30:06 +02:00
握猫猫
8809d1df8d
doc: fix the uv_*_set_data series of functions
They have no return value.
2024-08-16 09:13:42 +02:00
握猫猫
1790abb3b2
doc: document uv_loop_option 2024-08-15 11:01:20 +02:00
Shelley Vohr
31d9165999
win: remove deprecated GetVersionExW call (#4486) 2024-08-15 00:47:57 +02:00
Andy Pan
27134547ff kqueue: use EVFILT_USER for async if available
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>
2024-08-13 09:18:24 +02:00
Ben Noordhuis
1eac3310ad
linux: support abstract unix socket autobinding (#4499)
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
2024-08-10 21:04:09 +02:00
Santiago Gimeno
a53e7877e4
unix,fs: silence -Wunused-result warning (#4496) 2024-08-10 11:08:39 +02:00
Richard Lau
c84a2dbe03 test: check for UV_CHANGE or UV_RENAME event
All other checks for `UV_RENAME` in `test-fs-event` also allow
`UV_CHANGE`.
2024-08-08 12:03:25 +01:00
Richard Lau
88ab6e78da test: rmdir can return EEXIST or ENOTEMPTY
POSIX allows `rmdir` to return `EEXIST` or `ENOTEMPTY` for a non-empty
directory, so the test needs to allow both.
2024-08-08 12:03:25 +01:00
Matheus Izvekov
5537d6a689
win: fix fs.c ubsan failure (#4491)
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>
2024-08-07 17:01:07 +02:00
Santiago Gimeno
e78e29c231
linux: disable SQPOLL io_uring by default (#4492)
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`.
2024-08-06 22:10:13 +02:00
Matheus Izvekov
9b3b61f606
build: ubsan fixes (#4254)
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
```
2024-08-05 17:15:53 -04:00
Jameson Nash
a6a987c0de
win,signal: fix data race dispatching SIGWINCH (#4488)
The Event should be reset before reading the value, or libuv might miss
an update that occurred too rapidly after the previously one.

Refs: https://github.com/libuv/libuv/pull/2381
Refs: https://github.com/libuv/libuv/discussions/4485
2024-08-05 16:32:31 -04:00
Jameson Nash
727ee7237e
win,pipe: fix race with concurrent readers (#4470)
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.
2024-08-02 10:50:32 -04:00
Hüseyin Açacak
4e310d0f90
win,fs: use the new Windows fast stat API (#4327)
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.
2024-07-30 08:58:41 -04:00
Abdirahim Musse
f23037fe21
test: pipe_overlong_path handle ENAMETOOLONG 2024-07-30 08:07:52 +02:00
Andy Pan
e5cb1d3d3d
linux: eliminate a read on eventfd per wakeup (#4400)
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.
2024-07-29 19:59:41 -04:00
dependabot[bot]
63b22be083
ci: bump actions/checkout to 4 (#4474)
Held back one due to https://github.com/libuv/libuv/pull/4451
2024-07-29 19:54:23 -04:00
Santiago Gimeno
badecdca14
fsevents: detect watched directory removal (#4376)
Which was broken both in `windows` and `macos`.
2024-07-30 00:59:38 +02:00
Hüseyin Açacak
83306585ff
win: fix env var in uv_os_homedir and uv_os_tmpdir (#4464)
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
2024-07-29 17:50:11 -04:00
Ian Butterworth
18266a6969
win,fs: use posix delete semantics, if supported (#4318)
Implements posix delete for files and dirs, with fallback to the old
method if not supported (e.g. Fat32 or Win8).

Fixes: #3839
2024-07-29 17:38:26 -04:00
Ben Noordhuis
0c36b16d1b
test,openbsd: remove superfluous ifdef guard (#4461)
The test is skipped in its entirety on OpenBSD so there is no point in
compiling out code on said platform later on, it's not run anyway.
2024-07-29 16:45:31 -04:00
Viacheslav Muravyev
e4d47c5357
misc: remove splay trees macros (#4469) 2024-07-29 16:45:12 -04:00
Ben Noordhuis
593aa3b2f6
test: handle zero-length udp datagram (#4344)
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
2024-07-29 16:30:08 -04:00
Jameson Nash
47c833675b
win,error: remap ERROR_NO_DATA to EAGAIN (#4471)
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.
2024-07-29 16:16:49 -04:00
dependabot[bot]
372e4c645e
ci: bump KyleMayes/install-llvm-action from 1 to 2 (#4472) 2024-07-29 16:15:23 -04:00
dependabot[bot]
6ab153cf8e
ci: bump actions/setup-python from 4 to 5 (#4475) 2024-07-29 16:13:46 -04:00
dependabot[bot]
9678211c24
ci: bump upload and download-artifact versions (#4473) 2024-07-29 16:13:00 -04:00
zeertzjq
5d1ccc12c4
doc: correct names of Win32 APIs in fs.rst (#4408)
The docs there link to GetFinalPathNameByHandleA() and CreateFileA(),
but src/win/fs.c uses GetFinalPathNameByHandleW() and CreateFileW().
2024-07-25 12:29:01 -04:00
Jameson Nash
f56f21d7da
Create dependabot.yml for updating github-actions (#4450) 2024-07-25 12:22:22 -04:00
郑苏波 (Super Zheng)
ecc11611d3 darwin: fix crash on iOS(arm64)
Disable sendfile() on iOS with arm64 architecture
to avoid crashes caused by throwing SIGSYS signal.

Fixes: #3187
2024-07-25 12:52:35 +02:00
Saúl Ibarra Corretgé
f279d9e6c6 ci: use macOS 12 for macOS and iOS builds
macOS 11 is gone: https://github.com/actions/runner-images/pull/10198
2024-07-18 13:25:43 +02:00
Olivier Valentin
ae6e146775
hurd: stub uv_thread_setpriority() 2024-07-18 11:33:39 +02:00
Olivier Valentin
90648ea3e5
hurd: add includes and macro prerequisites
- ptsname() needs _XOPEN_SOURCE >= 500
- setenv needs _POSIX_C_SOURCE >= 200112
- setgroups needs grp.h
2024-07-16 22:34:02 +02:00
Ben Noordhuis
2780b87d56
unix,win: export wtf8 functions properly (#4437)
Mark them UV_EXTERN so they are visible on Windows.

Fixes: https://github.com/libuv/libuv/issues/4436
2024-07-12 10:22:26 +02:00
Ben Noordhuis
e37539a46c
build: fix android ci build (#4451)
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.
2024-07-11 22:22:27 +02:00
Viacheslav Muravyev
7c491bde32
unix,win: remove unused req parameter from macros (#4435)
Remove the unused `req` parameter from the uv__req_register and
uv__req_unregister macros.
2024-07-11 21:29:15 +02:00
Uilian Ries
6621fe045a
doc: add instruction how to install with Conan (#4432)
Update the README file with instructions on how
to install libuv through the Conan package manager.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
2024-07-11 21:08:48 +02:00
Hüseyin Açacak
36f0789d83
win: map ERROR_BAD_EXE_FORMAT to UV_EFTYPE (#4445)
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
2024-07-11 20:41:14 +02:00
Andy Pan
fedfa9893e tcpkeepalive: distinguish OS versions and use proper time units
---------

Signed-off-by: Andy Pan <i@andypan.me>
2024-06-27 12:45:51 +02:00
Andy Pan
ba24986f8d
unix: support SO_REUSEPORT with load balancing for UDP (#4419)
Signed-off-by: Andy Pan <i@andypan.me>
2024-06-20 17:17:17 +02:00
Jeffrey H. Johnson
eb5af8e3c0
aix,ibmi: fix compilation errors in fs_copyfile (#4404)
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>
2024-05-30 22:31:15 +02:00
Andy Pan
1ee1063402
test: fix the flaky test-tcp-reuseport
Start connecting to the peers after all threads
to poll for accepting connections.

Ref: #4407
2024-05-30 09:53:44 +02:00
Juan José Arboleda
541329d51f doc: add entries for extended getpw
This patch adds documentation for the introduced `uv_os_get_passwd2`,
`uv_os_get_group`, `uv_os_free_group` methods in
https://github.com/libuv/libuv/pull/3523

Fixes: https://github.com/libuv/libuv/issues/4007
Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
2024-05-28 17:04:30 +02:00
Andy Pan
d2d92b74a8
unix: support SO_REUSEPORT with load balancing for TCP 2024-05-21 13:36:49 +02:00
Andy Pan
c8d4a87f49
bsd: support pipe2() on *BSD (#4412)
---------

Signed-off-by: Andy Pan <i@andypan.me>
2024-05-21 10:07:38 +02:00
Andy Pan
ab3ecf6565 unix: use the presence of SOCK_* instead of OS macros for socketpair
---------

Signed-off-by: Andy Pan <i@andypan.me>
2024-05-21 09:41:03 +02:00
Andy Pan
287987b37c test: remove the obsolete HAVE_KQUEUE macro
---------

Signed-off-by: Andy Pan <i@andypan.me>
2024-05-21 09:40:07 +02:00
Andy Pan
10ccd08471
dragonfly: disable SO_REUSEPORT for UDP socket bindings (#4410)
---------

Signed-off-by: Andy Pan <i@andypan.me>
2024-05-20 12:36:41 +02:00
Juan José
bf61390769
linux,darwin: make uv_fs_copyfile behaves like cp -r (#4396)
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>
2024-05-08 11:30:30 +02:00
josedelinux
520eb622f0
doc: fix some typos 2024-04-26 13:57:26 +02:00
Saúl Ibarra Corretgé
497f3168d1 win: remove no longer needed define
Windows 7 is no longer supported.
2024-04-22 20:39:20 +02:00
Saúl Ibarra Corretgé
8083ab26e0 mailmap: update saghul's main email address 2024-04-15 16:12:10 +02:00
Saúl Ibarra Corretgé
c0a61c3bb3 darwin: simplify uv_hrtime
mach_continuous_time is available since macOS 10.12, but our minimum
version is 11, so no need for a workaround.

Also, prefer that to `clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW)` which
the documentation suggests
(https://developer.apple.com/documentation/driverkit/3438077-mach_continuous_time)
since the latter calls mach_timebase_info every time, unnecessarify: 49dcc07a40/Libc/gen/clock_gettime.c (L107)
2024-04-15 16:12:10 +02:00
Brad King
f50ae53c42
unix: de-duplicate conditions for using kqueue (#4378)
Our platform-specific headers provide a dedicated indicator.
2024-04-14 11:13:21 +02:00
Ben Noordhuis
17219b8f39
test: use newer ASSERT_MEM_EQ macro (#4346)
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
2024-03-31 17:27:04 +02:00
Ben Noordhuis
46c0e1769b
win: robustify uv_os_getenv() error checking (#4339)
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
2024-03-31 17:25:13 +02:00
Ben Noordhuis
4fce06ec96
unix: fix fd leaks in SCM_RIGHTS error path (#4358)
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
2024-03-25 12:45:40 +01:00
Ben Noordhuis
77e4cd5b18
linux: don't use sendmmsg() for single datagrams (#4366)
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
2024-03-25 12:45:23 +01:00
Ben Noordhuis
d05ed869bb
doc: correct udp socket options documentation (#4371)
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
2024-03-25 12:44:52 +01:00
Saúl Ibarra Corretgé
abc9767034
win: simplify uv_once implementation
* win: simplify uv_once implementation

InitOnceExecuteOnce is available in Windows >= Vista.

Ref: https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initonceexecuteonce
2024-03-25 11:57:52 +01:00
Saúl Ibarra Corretgé
6adeeacee7
unix,win: error on zero delay tcp keepalive
Closes: https://github.com/libuv/libuv/pull/4350
Closes: https://github.com/libuv/libuv/issues/3487
2024-03-22 22:11:23 +01:00
tgolang
f55628eed0
doc: fix typos in ChangeLog (#4355)
Signed-off-by: tgolang <seekseat@aliyun.com>
2024-03-22 20:10:41 +01:00
Ben Noordhuis
3ecce91410
linux: don't delay EPOLL_CTL_DEL operations (#4328)
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
2024-03-21 09:23:08 +01:00
Ben Noordhuis
cc23e204d7
unix: reinstate preadv/pwritev fallback code (#4345)
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
2024-03-20 18:39:18 +01:00
Ben Noordhuis
e0c5fc8714
win: remove _alloca usage (#4361)
Remove it since it can cause stack overflows. Use heap allocation
instead.

Fixes: https://github.com/libuv/libuv/issues/4348
2024-03-20 12:09:37 +01:00
Ben Noordhuis
91ba13054a
test,ci: fix [AM]San, disable ASLR (#4365)
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.
2024-03-17 15:53:23 +01:00
Farzin Monsef
b0816180e3
linux: fix /proc/self/stat executable name parsing (#4353)
- The filename of the executable may contain both spaces and parentheses
- Use uv__slurp instead of open/read/close
2024-03-14 09:35:25 +01:00
Andy Pan
fa6745b4f2
sunos: sync tcp keep-alive with other unices (#4337) 2024-03-12 11:16:49 +01:00
Saúl Ibarra Corretgé
6912038d72 unix,fs: fix realpath calls that use the system allocator
Make sure we allocate the memory with uv__malloc so it's in turn freed
with uv__free.

Fixes: https://github.com/libuv/libuv/issues/4329
2024-03-08 10:08:48 +01:00
Ben Noordhuis
2c15345016
test: disable env var test under win32+asan (#4342)
The test hits an honest-to-$deity compiler runtime bug, see the
investigation in the linked issue.

Fixes: https://github.com/libuv/libuv/issues/4338
2024-03-07 09:46:57 +01:00
Santiago Gimeno
ff9587991f
win: almost fix race detecting ESRCH in uv_kill (#4341)
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.
2024-03-05 21:20:50 +01:00
Farzin Monsef
625d3d275a
cygwin: implement uv_resident_set_memory (#4333)
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.
2024-03-02 11:24:57 +01:00
Geddy
a7c44d6748
udp,unix: fix sendmsg use-after-free (#4321)
Issue:
1. uv__io_poll calls uv__udp_io with revents == POLLIN + POLLOUT
2. uv__udp_io calls your recv_cb
3. you close the handle in callback
4. uv__udp_io calls uv__udp_sendmsg
5. uv__udp_sendmsg calls uv__io_feed
6. kaboom!
2024-02-28 17:32:43 -05:00
hiiizxf
e8458b2402
doc: fix tty example segfault (#4322)
Fixes: https://github.com/libuv/libuv/issues/4303
2024-02-28 12:32:24 +01:00
Thomas Walter
6b56200cc8
linux: fix uv_available_parallelism using cgroup (#4278)
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
2024-02-28 12:23:23 +01:00
Jameson Nash
cc9e96147f
misc: run sample CI when code changes (#4324) 2024-02-23 14:15:03 -05:00
Ben Noordhuis
507f3046d1
linux: create io_uring sqpoll ring lazily (#4315)
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
2024-02-14 11:20:44 +01:00
Anthony Alayo
7b9e37c7da
build: add alias for libuv to CMakeLists.txt (#4297)
Fixes: https://github.com/libuv/libuv/issues/4282
2024-02-09 21:08:24 +01:00
Ben Noordhuis
009d7414bc
test: fix -Wpointer-to-int-cast on 32 bits systems (#4309)
The return value from signal(2) is a pointer. Use the right macro.
2024-02-09 19:17:20 +01:00
Santiago Gimeno
08a1e7fd23
Now working on version 1.48.1
Fixes: https://github.com/libuv/libuv/issues/4248
2024-02-07 22:44:52 +01:00
Santiago Gimeno
99e576612d Add SHA to ChangeLog 2024-02-07 21:20:12 +01:00
Santiago Gimeno
e9f29cb984 2024.02.07, Version 1.48.0 (Stable)
Changes since version 1.47.0:

* misc: remove deprecated stalebot file (Jameson Nash)

* build: disable windows asan buildbot (Ben Noordhuis)

* test: don't run tcp_writealot under msan (Ben Noordhuis)

* build,win: remove extraneous -lshell32 (Ben Noordhuis)

* unix: ignore ifaddrs with NULL ifa_addr (Stephen Gallagher)

* unix,win: utility for setting priority for thread (Hao Hu)

* pipe: add back error handling to connect / bind (Jameson Nash)

* test: check if ipv6 link-local traffic is routable (Ben Noordhuis)

* win: remove check for UV_PIPE_NO_TRUNCATE (Jameson Nash)

* linux: disable io_uring on hppa below kernel 6.1.51 (matoro)

* unix,win: fix read past end of pipe name buffer (Ben Noordhuis)

* unix: unbreak macOS < 10.14 (Sergey Fedorov)

* aix: disable ipv6 link local (Abdirahim Musse)

* doc: move cjihrig to emeriti (cjihrig)

* unix: correct pwritev conditional (Bo Anderson)

* test_fs.c: Fix issue on 32-bit systems using btrfs (Stephen Gallagher)

* misc: ignore libuv-release-tool files (Jameson Nash)

* win: honor NoDefaultCurrentDirectoryInExePath env var (Ardi Nugraha)

* idna: fix compilation warning (Saúl Ibarra Corretgé)

* linux: remove HAVE_IFADDRS_H macro (Ben Noordhuis)

* test: skip tcp-write-in-a-row on IBM i (Abdirahim Musse)

* build,win: work around missing uuid.dll on MinGW (Anton Bachin)

* win: stop using deprecated names (Matheus Izvekov)

* unix,win: fix busy loop with zero timeout timers (Matheus Izvekov)

* aix,ibmi: use uv_interface_addresses instead of getifaddrs (Abdirahim
  Musse)

* linux: fix bind/connect for abstract sockets (Santiago Gimeno)

* win: replace c99 comments with c89 comments (Trevor Flynn)

* build: add .cache clangd folder to .gitignore (Juan José Arboleda)

* unix: support full TCP keep-alive on Solaris (Andy Pan)

* freebsd: fix F_KINFO file path handling (David Carlier)

* linux: retry fs op if unsupported by io_uring (Santiago Gimeno)

* freebsd: fix build on non-intel archs (David Carlier)

* unix: optimize uv__tcp_keepalive cpp directives (Andy Pan)

* linux: disable io_uring on ppc64 and ppc64le (Brad King)

* doc: add very basic Security Policy document (Santiago Gimeno)

* build: re-enable msvc-asan job on CI (Jameson Nash)

* win/spawn: optionally run executable paths with no file extension
  (Brad King)

* win: fix ESRCH implementation (Jameson Nash)

* unix,win: reset the timer queue on stop (Santiago Gimeno)

* fix: always zero-terminate idna output (Ben Noordhuis)

* fix: reject zero-length idna inputs (Ben Noordhuis)

* test: empty strings are not valid IDNA (Santiago Gimeno)

* Merge pull request from GHSA-f74f-cvh7-c6q6 (Ben Noordhuis)
2024-02-07 20:20:07 +00:00
Ben Noordhuis
c858a14764
Merge pull request from GHSA-f74f-cvh7-c6q6
* fix: always zero-terminate idna output

* fix: reject zero-length idna inputs

* test: empty strings are not valid IDNA

---------

Co-authored-by: Santiago Gimeno <santiago.gimeno@gmail.com>
2024-02-07 20:53:55 +01:00
Santiago Gimeno
e0327e1d50
test: empty strings are not valid IDNA
Fixes: https://github.com/libuv/libuv/security/advisories/GHSA-f74f-cvh7-c6q6
2024-02-07 20:50:13 +01:00
Ben Noordhuis
3530bcc303
fix: reject zero-length idna inputs
Fixes: https://github.com/libuv/libuv/security/advisories/GHSA-f74f-cvh7-c6q6
2024-02-07 20:50:04 +01:00
Ben Noordhuis
0f2d7e784a
fix: always zero-terminate idna output
Fixes: https://github.com/libuv/libuv/security/advisories/GHSA-f74f-cvh7-c6q6
2024-02-07 20:49:53 +01:00
Santiago Gimeno
bb6fbcf6e7
unix,win: reset the timer queue on stop (#4304)
As there were instances where this didn't happen and could cause memory
corruption issues.

Refs: https://github.com/libuv/libuv/issues/4248
2024-02-07 10:43:29 +01:00
Santiago Gimeno
10f313631c
Revert "unix: restore signal disposition to previous one (#4216)" (#4302)
This reverts commit b9421d7066.

Refs: https://github.com/libuv/libuv/issues/4299
Refs: https://github.com/libuv/libuv/issues/4248
2024-02-06 07:52:21 +01:00
Jameson Nash
129362f356
win: fix ESRCH implementation (#4301)
Per documentation, this was the wrong way to test for ESRCH. This hopefully
fixes it.

Fixes: https://github.com/libuv/libuv/issues/4300
2024-02-05 21:24:07 +01:00
Brad King
3f7191e5c2
win/spawn: optionally run executable paths with no file extension (#4292)
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>
2024-02-05 11:04:05 -05:00
Jameson Nash
535efdf319
build: re-enable msvc-asan job on CI (#4289) 2024-01-21 10:44:34 -05:00
Santiago Gimeno
f98516ddd5
doc: add very basic Security Policy document (#4290) 2024-01-19 19:09:39 +01:00
Brad King
3b6a1a14ca
linux: disable io_uring on ppc64 and ppc64le (#4285)
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
2024-01-13 12:04:01 +01:00
Andy Pan
a7cbda92b6
unix: optimize uv__tcp_keepalive cpp directives (#4275)
Reduce the amount of code being compiled and trim trailing whitespace in
passing.
2024-01-12 11:54:51 +01:00
David CARLIER
a407b232f0
freebsd: fix build on non-intel archs (#4276)
KINFO_FILE_SIZE is only defined on Intel archs.

Fixes: https://github.com/libuv/libuv/issues/4274
2024-01-09 11:10:35 +01:00
Santiago Gimeno
160cd5629e
linux: retry fs op if unsupported by io_uring (#4268)
Fallback to the threadpool if it returns `EOPNOTSUPP`.

Fixes: https://github.com/nodejs/node/issues/50876
2024-01-08 22:25:44 +01:00
David CARLIER
7d092913b3
freebsd: fix F_KINFO file path handling (#4256)
The new F_KINFO flag does not seem to work with directories nor with
deleted entries.

Fixes: https://github.com/libuv/libuv/issues/4255
2024-01-07 12:58:32 +01:00
Andy Pan
a9381cdb03
unix: support full TCP keep-alive on Solaris (#4272)
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.
2024-01-06 10:46:47 +01:00
Juan José
e72a91e063
build: add .cache clangd folder to .gitignore (#4257)
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>
2024-01-05 10:38:15 +01:00
Trevor Flynn
64bd28f5ba
win: replace c99 comments with c89 comments (#4270) 2024-01-05 10:34:33 +01:00
Santiago Gimeno
1dd0ab1315
linux: fix bind/connect for abstract sockets (#4266)
The `\0` character has no special significance in abstract sockets, so
the addrlen field in both `bind()` and `connect()` should take that into
account.
2023-12-25 23:35:14 +01:00
Abdirahim Musse
8861a97efa
aix,ibmi: use uv_interface_addresses instead of getifaddrs (#4222)
AIX and IBM i don't have getifaddrs but we do have code in
`uv_interface_addresses` to get the interface addresses.

Refs: https://github.com/libuv/libuv/issues/4117
2023-12-23 00:58:49 +01:00
Matheus Izvekov
51a22f60d6
unix,win: fix busy loop with zero timeout timers (#4250)
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>
2023-12-22 12:40:50 +01:00
Matheus Izvekov
8a499e1331
win: stop using deprecated names (#4253) 2023-12-22 12:30:48 +01:00
Anton Bachin
34db4c21b1
build,win: work around missing uuid.dll on MinGW (#4261) 2023-12-20 14:27:13 +01:00
Abdirahim Musse
1479b76310
test: skip tcp-write-in-a-row on IBM i (#4197)
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
2023-12-12 15:19:02 -05:00
Ben Noordhuis
a7d5255122
linux: remove HAVE_IFADDRS_H macro (#4243)
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
2023-12-12 15:13:31 -05:00
Saúl Ibarra Corretgé
12bd89bbc3 idna: fix compilation warning
w_target_len is set but unsued in release mode.
2023-12-11 09:42:18 +01:00
Ardi Nugraha
5e302730cd
win: honor NoDefaultCurrentDirectoryInExePath env var (#4238)
Fixes: https://github.com/libuv/libuv/issues/3888
Refs: https://github.com/nodejs/node/issues/46264
2023-11-30 22:54:41 +01:00
Jameson Nash
a5c01d4de3
misc: ignore libuv-release-tool files (#4201) 2023-11-24 11:22:25 +01:00
Stephen Gallagher
de43f42735
test_fs.c: Fix issue on 32-bit systems using btrfs (#4227)
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>
2023-11-24 11:18:51 +01:00
Bo Anderson
fc70430b09
unix: correct pwritev conditional (#4233) 2023-11-24 11:17:52 +01:00
Colin Ihrig
7ba94d3909
doc: move cjihrig to emeriti (#4234) 2023-11-19 08:47:23 -05:00
Abdirahim Musse
bfbe4e38d7
aix: disable ipv6 link local (#4229)
AIX does not implement ifaddrs and when retrieving the network
interfaces with uv_interface_addresses there was a test failure in
tcp_connect6_link_local.

For now disable ipv6 link local on aix to:

1) fix broken aix build
2) stop blocking libuv upgrade in node

Refs: https://github.com/libuv/libuv/pull/4222#issuecomment-1812962233
Refs: https://github.com/nodejs/node/pull/50650
2023-11-18 19:19:16 +01:00
Sergey Fedorov
4785ad6337
unix: unbreak macOS < 10.14 (#4230) 2023-11-18 09:57:40 +01:00
Ben Noordhuis
6be130e1b8
unix,win: fix read past end of pipe name buffer (#4209)
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().
2023-11-16 09:05:51 +01:00
matoro
f144429365
linux: disable io_uring on hppa below kernel 6.1.51 (#4224)
First kernel with support is 6.1, was only fully functional from .51
onwards: https://lore.kernel.org/all/cb912694-b1fe-dbb0-4d8c-d608f3526905@gmx.de/

Co-authored-by: matoro <matoro@users.noreply.github.com>
2023-11-15 23:57:06 +01:00
Jameson Nash
35da5ded3b
win: remove check for UV_PIPE_NO_TRUNCATE (#4221)
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
2023-11-15 15:08:49 +01:00
Viacheslav Muravyev
b9421d7066
unix: restore signal disposition to previous one (#4216)
Fixes: https://github.com/libuv/libuv/issues/2435
2023-11-15 14:39:17 +01:00
Ben Noordhuis
54d8364c24
test: check if ipv6 link-local traffic is routable (#4220)
Fixes: https://github.com/libuv/libuv/issues/4211
2023-11-14 22:09:30 +01:00
Jameson Nash
d843b7cf7f
pipe: add back error handling to connect / bind (#4202)
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.
2023-11-14 09:26:53 -05:00
Hao Hu
e135dfe183
unix,win: utility for setting priority for thread (#4075)
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
2023-11-14 11:30:46 +01:00
Stephen Gallagher
31e4b90c3c
unix: ignore ifaddrs with NULL ifa_addr (#4218)
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>
2023-11-14 10:23:28 +01:00
Ben Noordhuis
874363f652
build,win: remove extraneous -lshell32 (#4213)
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.
2023-11-13 13:25:41 -05:00
Ben Noordhuis
f01219dfb7
test: don't run tcp_writealot under msan (#4214)
The test is prone to time out at the best of times, never mind when
running under MemorySanitizer.
2023-11-10 20:17:31 +01:00
Ben Noordhuis
f067f50ae4
build: disable windows asan buildbot (#4215)
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
2023-11-10 18:56:46 +01:00
Jameson Nash
4107b8d4db
misc: remove deprecated stalebot file (#4199)
Refs: https://github.com/probot/stale/pull/430
2023-11-07 10:53:16 -05:00
Jameson Nash
815693f715 Now working on version 1.47.1
Fixes: https://github.com/libuv/libuv/issues/4186
2023-11-06 13:24:46 -05:00
Jameson Nash
97b7873cba Add SHA to ChangeLog 2023-11-06 13:17:32 -05:00
Jameson Nash
be6b81a352 2023.11.06, Version 1.47.0 (Stable)
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)
2023-11-06 13:17:17 -05:00
Christian Heimlich
66160d6973
win: improve accuracy of ProductName between arch (#4191)
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.
2023-11-01 02:30:10 +01:00
Matheus Izvekov
93efccf4ee
build: add windows ubsan and clang ci (#4138)
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.
2023-10-30 15:16:57 -04:00
Jameson Nash
77991a0761
build: fix libuv.a file name for cmake (#4185)
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
2023-10-28 21:05:42 -04:00
Jameson Nash
f388908593
misc: export WTF8 conversion utilities (#4021)
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.)
2023-10-28 21:04:57 -04:00
Ben Noordhuis
56fca44a4b
build: run sanitizers on macos ci (#4189)
Skip three fs_event tests that time out under Thread Sanitizer.
2023-10-28 15:05:42 +02:00
Ben Noordhuis
a389393ffa
linux: disable io_uring on 32 bits arm systems (#4187)
It's been reported that no released kernels are bug-free enough to use
io_uring without causing regressions.

Fixes: https://github.com/libuv/libuv/issues/4158
2023-10-28 13:18:42 +02:00
Per Allansson
7b34154cf2
build: add CI for Windows ARM64 (build only) (#4184) 2023-10-27 18:53:45 -04:00
Jeffrey H. Johnson
da527d8d2a
unix: no preadv/pwritev workaround if not needed (#4180)
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>
2023-10-26 20:23:36 +02:00
Per Allansson
b8368a1441
build,win: we need to link against shell32.lib (#4182)
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.
2023-10-25 21:48:57 +02:00
Ben Noordhuis
c5f027d6be
doc: filename arg to uv_fs_event_cb can be NULL (#4177)
Refs: https://github.com/libuv/libuv/issues/4160
2023-10-22 11:55:07 +02:00
Ben Noordhuis
9956da1567 unix: merge read/write code into single functions
I split those out in a previous commit in anticipation of changes that
never came. Let's merge them back.
2023-10-22 11:51:35 +02:00
Ben Noordhuis
8ac649e2aa unix: rename variable for consistency
uv__fs_write_do() calls it `r` so call it that in `uv__fs_read_do()`
too.
2023-10-22 11:51:35 +02:00
Ben Noordhuis
8d69f256d1 unix: add back preadv/pwritev fallback
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
2023-10-22 11:51:35 +02:00
prubel
815dd8a25c
test: 192.0.2.0/24 is the actual -TEST-NET-1 (#4133)
Section 3 of rfc 5737 lists 192.0.2.0/24 as TEST-NET-1,
fix confusion about /8 and /24.
2023-10-18 00:24:34 +02:00
Pleuvens
dc1bb0088e
doc: uv_close should be called after exit callback (#4164)
Fixes: https://github.com/libuv/libuv/issues/1911
2023-10-14 13:07:05 +02:00
Julien Roncaglia
197f453b76
darwin: workaround apple pthread_cond_wait bug (#4166)
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
2023-10-13 21:32:46 +02:00
Pleuvens
d8669609d8
test: switch from ASSERT_* to ASSERT_PTR_* (#4163)
Also introduce a new ASSERT_PTR_LT macro.
2023-10-12 20:47:44 +02:00
David CARLIER
004dfd2d4b
freebsd: get fs event path with fcntl(F_KINFO) 2023-10-12 20:43:11 +02:00
Ben Noordhuis
13148457a9
unix: don't malloc on sync uv_fs_read (#4162)
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
2023-10-12 20:40:18 +02:00
Abdirahim Musse
75f7de4010
test: fix get_passwd2 on IBM i (#4154)
uid 0 is `qsecofr` on IBM i.

Refs: https://github.com/libuv/libuv/issues/4143
2023-10-06 18:25:40 +00:00
jolai
fc4840ebc9
zos: correctly get cpu model in uv_cpu_info() (#4136)
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
2023-10-06 19:53:38 +02:00
Pleuvens
011a1ac1a3
test: switch to new-style ASSERT_EQ macros (#4159)
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
2023-10-06 19:50:15 +02:00
Ben Noordhuis
56fada47f2
src: default to stream=stderr in handle printer (#4161)
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.
2023-10-03 13:30:16 +02:00
Ben Noordhuis
737f4f953f darwin: remove workaround for data corruption bug
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.
2023-10-03 13:09:40 +02:00
Ben Noordhuis
fef619608b unix: remove pwrite/pwritev conditionals 2023-10-03 13:09:40 +02:00
Ben Noordhuis
663d88b677 unix: remove pread/preadv conditionals 2023-10-03 13:09:40 +02:00
Jameson Nash
c03569f0df
win,process: avoid assert after spawning Store app (#4152)
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
2023-10-02 15:15:18 +02:00
SmorkalovG
2a4cab70ef
unix: reset signal counters after fork (#3485)
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
2023-09-29 12:54:35 +02:00
Abdirahim Musse
d83fadaf09
ibmi: implement ifaddrs, getifaddrs, freeifaddrs (#4155)
Add PASE implementation of ifaddrs, getifaddrs, freeifaddrs.

Refs: https://github.com/libuv/libuv/issues/4117
2023-09-28 21:16:11 +02:00
Santiago Gimeno
d277f71333
test: skip tests when ipv6 is not available (#4151) 2023-09-26 21:55:32 +02:00
Santiago Gimeno
c811169f91
unix: disable io_uring close on selected kernels (#4141)
Specifically on non-longterm kernels between 5.16.0 (non-longterm) and
6.1.0 (longterm). Starting with longterm 6.1.0, the issue is solved.
2023-09-17 22:09:00 +02:00
Santiago Gimeno
4e416266f6
build: fix qemu install in CI-unix workflow (#4142)
The version of the deb package has changed to 7.2.
2023-09-17 21:18:50 +02:00
Ben Noordhuis
0d78f3c758 unix: get mainline kernel version in Debian (#4131)
In Debian, the mainline kernel version is reported via the `uname()`
`version` field.
2023-09-01 11:24:26 +02:00
Santiago Gimeno
e2c8fed7b3 unix: get mainline kernel version in Ubuntu (#4131)
In Ubuntu, the kernel version reported by `uname()` follows the
versioning format that Ubuntu uses for their kernels which does not have
a direct correspondence with the mainline kernel version they're based
on. Get that version from `/proc/version_signature` as documented in:

https://wiki.ubuntu.com/Kernel/FAQ#Kernel.2FFAQ.2FGeneralVersionRunning.How_can_we_determine_the_version_of_the_running_kernel.3F
2023-09-01 11:24:26 +02:00
Alois Klink
0a02887e62
doc: fix broken "Shared library" Wikipedia link (#4128)
`linkcheck` is printing the following error:

```
( guide/utilities: line  311) broken    https://en.wikipedia.org/wiki/Shared_library#Shared_libraries - Anchor 'Shared_libraries' not found
```
2023-08-28 12:41:40 -04:00
michalbiesek
65dc822d6c
linux: add missing riscv syscall numbers (#4127)
Signed-off-by: Michal Biesek <michalbiesek@gmail.com>
2023-08-25 21:41:56 +02:00
Brad King
b3759772d2
win,fs: avoid winapi macro redefinition (#4123)
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'
```
2023-08-19 12:17:16 +02:00
小明
65541f772f
darwin: make TCP_KEEPINTVL and TCP_KEEPCNT available (#3908)
In earlier versions, macOS only defined TCP_KEEPALIVE, but since macOS
10.8 (Mountain Lion), it has supported TCP_KEEPINTVL and TCP_KEEPCNT.

https://lists.apple.com/archives/macnetworkprog/2012/Jul/msg00005.html
2023-08-14 15:33:12 -04:00
Saúl Ibarra Corretgé
1b4bd9209e
doc: switch to Furo, a more modern Sphinx theme (#4094) 2023-08-14 15:27:18 -04:00
Kyle Edwards
c97017dd1d
win,spawn: allow %PATH% to be unset (#4116)
Fix: https://github.com/libuv/libuv/issues/4115
2023-08-14 15:25:11 -04:00
Trevor Norris
2f82750098
unix: match kqueue and epoll code (#4091)
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
2023-08-04 14:10:53 -06:00
Ben Noordhuis
e893cd6826
unix: set ipv6 scope id for link-local addresses (#4107)
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
2023-08-03 22:18:50 +02:00
Keith Winstein
124d55c970
build: move cmake_minimum_required version to 3.9 (#4111)
CMake 3.27 warns that "Compatibility with CMake < 3.5 will be removed
from a future version of CMake."
(https://cmake.org/cmake/help/latest/release/3.27.html#deprecated-and-removed-features)
2023-08-01 17:30:20 -04:00
Ben Noordhuis
30c3ef9f6f
linux: handle UNAME26 personality (#4109) 2023-07-31 23:40:59 +02:00
Ben Noordhuis
55376b044b
test: enable disabled spawn_same_stdout_stderr (#4105)
This test was added in commit e403a2c486 from 2014 but its author forgot
to enable it.
2023-07-25 16:48:22 +02:00
Ben Noordhuis
9c1de6e93f
test: enable disabled fs_link (#4104)
This test was added in commit 060026ced from 2011 but its author forgot
to actually enable it.
2023-07-25 16:48:04 +02:00
Ben Noordhuis
49d83c0301
test: enable disabled tcp_connect6_error_fault (#4103)
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.
2023-07-25 15:58:08 +02:00
Jameson Nash
d09441ca03
fs: fix WTF-8 decoding issue (#4092)
We forgot to mask off the high bits from the first byte, so we ended up
always failing the subsequent range check.

Refs: #2970
Fixes: https://github.com/nodejs/node/issues/48673
2023-07-13 12:22:07 -04:00
Ben Noordhuis
50b53cbd0d
linux: don't use io_uring on pre-5.10.186 kernels (#4093)
Those kernels have a known resource consumption bug where the sqpoll
thread busy-loops.

Fixes: https://github.com/libuv/libuv/issues/4089
2023-07-12 23:33:49 +02:00
小明
1230fad8f4
darwin: fix build warnings (#4073) 2023-07-12 23:03:36 +02:00
Shuduo Sang
a939d643dd
linux: fix harmless warn_unused_result warning (#4056) 2023-07-12 23:00:59 +02:00
Ben Noordhuis
2f87d5c114
test: fix license blurb (#4085)
Fixes: https://github.com/libuv/libuv/issues/4080
2023-07-10 10:37:38 +02:00
Santiago Gimeno
c5644368b5
Now working on version 1.46.1
Fixes: https://github.com/libuv/libuv/issues/4060
2023-06-30 22:58:52 +02:00
Santiago Gimeno
ad523c20c7 Add SHA to ChangeLog 2023-06-30 18:31:51 +00:00
Santiago Gimeno
f0bb7e40f0 2023.06.30, Version 1.46.0 (Stable)
Changes since version 1.45.0:

* Add SHA to ChangeLog (Santiago Gimeno)

* misc: update readthedocs config (Jameson Nash)

* test: remove erroneous RETURN_SKIP (Ben Noordhuis)

* android: disable io_uring support (Ben Noordhuis)

* linux: add some more iouring backed fs ops (Santiago Gimeno)

* build: add autoconf option for disable-maintainer-mode (Jameson Nash)

* fs: use WTF-8 on Windows (Stefan Karpinski)

* unix,win: replace QUEUE with struct uv__queue (Ben Noordhuis)

* linux: fs_read to use io_uring if iovcnt > IOV_MAX (Santiago Gimeno)

* ios: fix uv_getrusage() ru_maxrss calculation (Ben Noordhuis)

* include: update outdated code comment (Ben Noordhuis)

* linux: support abstract unix sockets (Ben Noordhuis)

* unix,win: add UV_PIPE_NO_TRUNCATE flag (Ben Noordhuis)

* unix: add loongarch support (liuxiang88)

* doc: add DPS8M to LINKS.md (Jeffrey H. Johnson)

* include: add EUNATCH errno mapping (Abdirahim Musse)

* src: don't run timers if loop is stopped/unref'd (Trevor Norris)

* win: fix -Wpointer-to-int-cast warning (Ben Noordhuis)

* test,win: fix -Wunused-variable warning (Ben Noordhuis)

* test,win: fix -Wformat warning (Ben Noordhuis)

* linux: work around io_uring IORING_OP_CLOSE bug (Ben Noordhuis)

* win: remove unused functions (Ben Noordhuis)

* bench: add bench to check uv_loop_alive (Trevor Norris)

* test: add uv_cancel test for threadpool (Trevor Norris)

* unix: skip prohibited syscalls on tvOS and watchOS (小明)

* unix,fs: make no_pwritev access thread-safe (Santiago Gimeno)

* unix: fix build for lower versions of Android (小明)
2023-06-30 18:31:51 +00:00
小明
7b43d70be4
unix: fix build for lower versions of Android (#4046)
Available since Android N (API level 24): getgrgid_r, preadv, pwritev

Refs: https://cs.android.com/android/platform/superproject/+/master:bionic/docs/status.md
2023-06-26 13:47:48 +02:00
Santiago Gimeno
c8fad2ac09
unix,fs: make no_pwritev access thread-safe (#4066) 2023-06-23 13:17:37 +02:00
小明
ca544ed6fc
unix: skip prohibited syscalls on tvOS and watchOS (#4043) 2023-06-23 11:09:53 +02:00
Trevor Norris
6df5a72151
test: add uv_cancel test for threadpool (#4065 2/2)
Check that uv_cancel() returns UV_EBUSY when called while the uv_work_cb
is being executed.
2023-06-21 11:31:44 -06:00
Trevor Norris
3e0b846bdb
bench: add bench to check uv_loop_alive (#4065 1/2) 2023-06-21 11:31:25 -06:00
Ben Noordhuis
4b0fe81758
win: remove unused functions (#4063) 2023-06-20 22:30:31 +02:00
Ben Noordhuis
1752791c9e
linux: work around io_uring IORING_OP_CLOSE bug (#4059)
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
2023-06-20 13:01:12 +02:00
Ben Noordhuis
2bf97f123f test,win: fix -Wformat warning 2023-06-19 21:41:06 +02:00
Ben Noordhuis
9179888c2b test,win: fix -Wunused-variable warning 2023-06-19 21:41:06 +02:00
Ben Noordhuis
dde50f0e22 win: fix -Wpointer-to-int-cast warning 2023-06-19 21:41:06 +02:00
Trevor Norris
24d1d0802d
src: don't run timers if loop is stopped/unref'd (#4048)
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().
2023-06-16 11:00:06 -06:00
Abdirahim Musse
6a9e4293d8
include: add EUNATCH errno mapping (#4047)
add EUNATCH errno mapping
2023-06-16 09:27:39 -04:00
Jeffrey H. Johnson
4002231bd9
doc: add DPS8M to LINKS.md (#4052) 2023-06-16 10:29:26 +02:00
liuxiang88
7ada448d18
unix: add loongarch support (#4054)
Signed-off-by: liuxiang <liuxiang@loongson.cn>
2023-06-16 10:25:25 +02:00
Ben Noordhuis
2f1614b128
unix,win: add UV_PIPE_NO_TRUNCATE flag (#4040)
Libuv's default behavior is to truncate long Unix socket paths. The flag
tells it to return an error instead.

Fixes: https://github.com/libuv/libuv/issues/4036
2023-06-06 17:08:36 +02:00
Ben Noordhuis
b9b6db052b
linux: support abstract unix sockets (#4030)
Add two new APIs for binding and connecting to abstract UNIX sockets.

Fixes: https://github.com/libuv/libuv/issues/4028
2023-06-04 22:43:14 +02:00
Ben Noordhuis
e8ec610f28
include: update outdated code comment (#4037)
I believe it's fair to say at this point that these functions are not
going to be removed in v0.12. They are still deprecated though.
2023-06-04 22:41:58 +02:00
Ben Noordhuis
65c1402ee6
ios: fix uv_getrusage() ru_maxrss calculation (#4027)
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
2023-05-25 13:08:43 +02:00
Santiago Gimeno
e7b9633170
linux: fs_read to use io_uring if iovcnt > IOV_MAX (#4023)
Just cap it to `IOV_MAX` as it's already done when performing reads
using the threadpool.
2023-05-25 12:09:51 +02:00
Ben Noordhuis
1b01b786c0
unix,win: replace QUEUE with struct uv__queue (#4022)
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
2023-05-25 00:04:30 +02:00
Stefan Karpinski
8f32a14afa
fs: use WTF-8 on Windows (#2970)
This allows working with valid filenames that are not well-formed
UTF-16. This is a superset of UTF-8, which does not error when it
encounters an unpaired surrogate but simply allows it.

Fixes: https://github.com/libuv/libuv/issues/2048
Refs: https://simonsapin.github.io/wtf-8/
Replaces: https://github.com/libuv/libuv/pull/2192 by Nikolai Vavilov <vvnicholas@gmail.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
2023-05-23 10:25:38 -04:00
Jameson Nash
6d0d4a3e4d
build: add autoconf option for disable-maintainer-mode (#4000) 2023-05-23 09:15:53 -04:00
Santiago Gimeno
962b8e626c
linux: add some more iouring backed fs ops (#4012)
Specifically: `link`, `mkdir`, `rename`, `symlink` and `unlink`.
2023-05-23 10:42:20 +02:00
Ben Noordhuis
281e6185cc
android: disable io_uring support (#4016)
Android's zealous seccomp filter blocks the io_uring_setup system call.

Fixes: https://github.com/libuv/libuv/issues/4010
2023-05-23 00:25:09 +02:00
Ben Noordhuis
5bf18a6e88
test: remove erroneous RETURN_SKIP (#4015)
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
2023-05-23 00:24:39 +02:00
Jameson Nash
4e766761d0
misc: update readthedocs config (#4009)
Now required: https://docs.readthedocs.io/en/stable/config-file/v2.html#build-os
2023-05-20 09:36:23 -04:00
Santiago Gimeno
a4649f5078 Now working on version 1.45.1
Fixes: https://github.com/libuv/libuv/issues/3887
2023-05-19 13:37:42 +02:00
Santiago Gimeno
d4f8a4ab5d Add SHA to ChangeLog 2023-05-19 13:37:42 +02:00
Santiago Gimeno
b9789a452f 2023.05.19, Version 1.45.0 (Stable)
Changes since version 1.44.2:

* win: remove stdint-msvc2008.h (Ben Noordhuis)

* android: remove pthread-fixes.c (Ben Noordhuis)

* build: enable MSVC_RUNTIME_LIBRARY setting (自发对称破缺)

* unix: switch to c11 atomics (Ben Noordhuis)

* unix: don't accept() connections in a loop (Ben Noordhuis)

* win: fix off-by-1 buffer overrun in uv_exepath() (Ben Noordhuis)

* build: switch ci from macos-10.15 to macos-11 (Ben Noordhuis)

* win: fix thread race in uv_cwd() and uv_chdir() (Ben Noordhuis)

* unix,win: remove UV_HANDLE_SHUTTING flag (Santiago Gimeno)

* win: support Windows 11 in uv_os_uname() (Luan Devecchi)

* unix: fix uv_getrusage() ru_maxrss reporting (Ben Noordhuis)

* doc: add note about offset -1 in uv_fs_read/write (Steven
  Schveighoffer)

* test: fix musl libc.a dlerror() test expectation (Ben Noordhuis)

* kqueue: DRY file descriptor deletion logic (Ben Noordhuis)

* linux: teach uv_get_constrained_memory() cgroupsv2 (Ben Noordhuis)

* build: upgrade qemu-user-static package (Ben Noordhuis)

* linux: move epoll.c back into linux-core.c (Ben Noordhuis)

* unix: remove pre-macos 10.8 compatibility hack (Ben Noordhuis)

* unix,win: fix memory leak in uv_fs_scandir() (Ben Noordhuis)

* build: restore qemu download logic (Ben Noordhuis)

* win: fix uv__pipe_accept memory leak (number201724)

* doc: update LINKS.md (Daniel)

* unix: simplify atomic op in uv_tty_reset_mode() (Ben Noordhuis)

* build: add LIBUV_BUILD_SHARED cmake option (Christian Clason)

* linux: remove unused or obsolete syscall wrappers (Ben Noordhuis)

* linux: merge files back into single file (Ben Noordhuis)

* stream: process more than one write req per loop tick (ywave620)

* unix,win: give thread pool threads an 8 MB stack (Ben Noordhuis)

* build: add MemorySanitizer (MSAN) support (Ben Noordhuis)

* doc: add uv_poll_cb status==UV_EBADF note (jensbjorgensen)

* build: support AddressSanitizer on MSVC (Jameson Nash)

* win,pipe: improve method of obtaining pid for ipc (number201724)

* thread: add support for affinity (daomingq)

* include: map ENODATA error code (Ben Noordhuis)

* build: remove bashism from autogen.sh (Santiago Gimeno)

* win,tcp,udp: remove "active streams" optimization (Saúl Ibarra
  Corretgé)

* win: drop code checking for Windows XP / Server 2k3 (Saúl Ibarra
  Corretgé)

* unix,win: fix 'sprintf' is deprecated warning (twosee)

* doc: mention close_cb can be NULL (Qix)

* win: optimize udp receive performance (ywave620)

* win: fix an incompatible types warning (twosee)

* doc: document 0 return value for free/total memory (Ben Noordhuis)

* darwin: use hw.cpufrequency again for frequency info (Jameson Nash)

* win,test: change format of TEST_PIPENAME's (Santiago Gimeno)

* win,pipe: fixes in uv_pipe_connect() (Santiago Gimeno)

* misc: fix return value of memory functions (theanarkh)

* src: add new metrics APIs (Trevor Norris)

* thread: add uv_thread_getcpu() (daomingq)

* build: don't use ifaddrs.h on solaris 10 (Edward Humes)

* unix,win: add uv_get_available_memory() (Tim Besard)

* test: fix -Wunused-but-set-variable warnings (Ben Noordhuis)

* doc: bump min supported linux and freebsd versions (Ben Noordhuis)

* Add Socket Runtime to the LINKS.md (Sergey Rubanov)

* unix: drop kfreebsd support (Ben Noordhuis)

* win: fix fstat for pipes and character files (Stefan Stojanovic)

* win: fix -Wunused-variable warning (Ben Noordhuis)

* win: fix -Wunused-function warning (Ben Noordhuis)

* build: drop qemu-alpha from ci matrix (Ben Noordhuis)

* win: move child_stdio_buffer out of uv_process_t (Santiago Gimeno)

* test: fix some unreachable code warnings (Santiago Gimeno)

* linux: simplify uv_uptime() (Ben Noordhuis)

* test: unflake fs_event_watch_dir test (Ben Noordhuis)

* darwin: remove unused fsevents symbol lookups (Ben Noordhuis)

* build: add define guard around UV_EXTERN (Zvicii)

* build: add UndefinedBehaviorSanitizer support (Ben Noordhuis)

* build: enable platform_output test on qemu (Ben Noordhuis)

* linux: handle cpu hotplugging in uv_cpu_info() (Ben Noordhuis)

* build: remove unnecessary policy setting (dundargoc)

* docs: add vcpkg instruction step (Jack·Boos·Yu)

* win,fs: fix readlink errno for a non-symlink file (Darshan Sen)

* misc: extend getpw to take uid as an argument (Jameson Nash)

* unix,win: use static_assert when available (Ben Noordhuis)

* docs: delete code Makefile (Jameson Nash)

* docs: add CI for docs PRs (Jameson Nash)

* docs: update Sphinx version on RTD (Jameson Nash)

* doc: clean up license file (Ben Noordhuis)

* test: fix some warnings when compiling tests (panran)

* build,win: add mingw-w64 CI configuration (Jameson Nash)

* build: add CI for distcheck (Jameson Nash)

* unix: remove busy loop from uv_async_send (Jameson Nash)

* doc: document uv_fs_cb type (Tamás Bálint Misius)

* build: Improve build by cmake for Cygwin (erw7)

* build: add libuv:: namespace to libuvConfig.cmake (AJ Heller)

* test: fix ThreadSanitizer thread leak warning (Ben Noordhuis)

* test: fix ThreadSanitizer data race warning (Ben Noordhuis)

* test: fix ThreadSanitizer data race warning (Ben Noordhuis)

* test: fix ThreadSanitizer data race warning (Ben Noordhuis)

* test: cond-skip fork_threadpool_queue_work_simple (Ben Noordhuis)

* test: cond-skip signal_multiple_loops (Ben Noordhuis)

* test: cond-skip tcp_writealot (Ben Noordhuis)

* build: promote tsan ci to must-pass (Ben Noordhuis)

* build: add CI for OpenBSD and FreeBSD (James McCoy)

* build,test: fix distcheck errors (Jameson Nash)

* test: remove bad tty window size assumption (Ben Noordhuis)

* darwin,process: feed kevent the signal to reap children (Jameson Nash)

* unix: abort on clock_gettime() error (Ben Noordhuis)

* test: remove timing-sensitive check (Ben Noordhuis)

* unix: DRY and fix tcp bind error path (Jameson Nash)

* macos: fix fsevents thread race conditions (Ben Noordhuis)

* win: fix leak in uv_chdir (Trevor Norris)

* test: make valgrind happy (Trevor Norris)

* barrier: wait for prior out before next in (Jameson Nash)

* test: fix visual studio 2015 build error (Ben Noordhuis)

* linux: fix ceph copy error truncating readonly files (Bruno Passeri)

* test: silence more valgrind warnings (Trevor Norris)

* doc: add entries to LINKS.md (Trevor Norris)

* win,unix: change execution order of timers (Trevor Norris)

* doc: add trevnorris to maintainers (Trevor Norris)

* linux: remove epoll_pwait() emulation code path (Ben Noordhuis)

* linux: replace unsafe macro with inline function (Ben Noordhuis)

* linux: remove arm oabi support (Ben Noordhuis)

* unix,sunos: SO_REUSEPORT not valid on all sockets (Stacey Marshall)

* doc: consistent single backquote in misc.rst (Jason Zhang)

* src: switch to use C11 atomics where available (Trevor Norris)

* test: don't use static buffer for formatting (Ben Noordhuis)

* linux: introduce io_uring support (Ben Noordhuis)

* linux: fix academic valgrind warning (Ben Noordhuis)

* test: disable signal test under ASan and MSan (Ben Noordhuis)

* linux: add IORING_OP_OPENAT support (Ben Noordhuis)

* linux: add IORING_OP_CLOSE support (Ben Noordhuis)

* linux: remove bug workaround for obsolete kernels (Ben Noordhuis)

* doc: update active maintainers list (Ben Noordhuis)

* test: add ASSERT_OK (Trevor Norris)

* src: fix events/events_waiting metrics counter (Trevor Norris)

* unix,win: add uv_clock_gettime() (Ben Noordhuis)

* build: remove freebsd and openbsd buildbots (Ben Noordhuis)

* win: fix race condition in uv__init_console() (sivadeilra)

* linux: fix logic bug in sqe ring space check (Ben Noordhuis)

* linux: use io_uring to batch epoll_ctl calls (Ben Noordhuis)

* macos: update minimum supported version (Santiago Gimeno)

* docs: fix some typos (cui fliter)

* unix: use memcpy() instead of type punning (Ben Noordhuis)

* test: add additional assert (Mohammed Keyvanzadeh)

* build: export compile_commands.json (Lewis Russell)

* win,process: write minidumps when sending SIGQUIT (Elliot Saba)

* unix: constrained_memory should return UINT64_MAX (Tim Besard)

* unix: handle CQ overflow in iou ring (Santiago Gimeno)

* unix: remove clang compiler warning pragmas (Ben Noordhuis)

* win: fix mingw build (gengjiawen)

* test: fix -Wbool-compare compiler warning (Ben Noordhuis)

* win: define MiniDumpWithAvxXStateContext always (Santiago Gimeno)

* freebsd: hard-code UV_ENODATA definition (Santiago Gimeno)

* linux: work around EOWNERDEAD io_uring kernel bug (Ben Noordhuis)

* linux: fix WRITEV with lots of bufs using io_uring (Santiago Gimeno)
2023-05-19 13:37:42 +02:00
Santiago Gimeno
07261493a7 Revert "win: implement uv_try_write() for pipes(#3825 1/2)"
This reverts commit 244e0e2059.

For some reason this is breaking node.js IPC. I plan to investigate it
but we can let this for the next release.t

PR-URL: https://github.com/libuv/libuv/pull/4003
2023-05-19 11:08:49 +02:00
Santiago Gimeno
03bb703741 Revert "win: fixes in uv__pipe_try_write() (#3825 2/2)"
This reverts commit e1143f1265.

For some reason this is breaking node.js IPC. I plan to investigate it
but we can let this for the next release.

PR-URL: https://github.com/libuv/libuv/pull/4003
2023-05-19 11:08:49 +02:00
Santiago Gimeno
ef6a9a624d
linux: fix WRITEV with lots of bufs using io_uring (#4004)
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`.
2023-05-19 11:03:17 +02:00
Ben Noordhuis
d23a20f62c
linux: work around EOWNERDEAD io_uring kernel bug (#4002)
io_uring sometimes erroneously returns EOWNERDEAD when the intention was
to return 0. It's harmless and fixed in linux 5.14 so just ignore the
error.

Fixes: https://github.com/libuv/libuv/issues/4001
Refs: https://github.com/torvalds/linux/commit/21f965221e
2023-05-17 16:54:36 +02:00
Santiago Gimeno
6f94701467
freebsd: hard-code UV_ENODATA definition (#3999)
`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.
2023-05-16 20:43:30 +02:00
Santiago Gimeno
d1a2efc77b
win: define MiniDumpWithAvxXStateContext always (#3998) 2023-05-16 16:29:03 +02:00
Ben Noordhuis
1a56f68451
test: fix -Wbool-compare compiler warning (#3996)
Fixes: https://github.com/libuv/libuv/issues/3995
2023-05-16 10:56:41 +02:00
Jiawen Geng
e7ecd116e0
win: fix mingw build (#3994)
Fixes: https://github.com/libuv/libuv/issues/3992
2023-05-15 23:35:35 +02:00
Ben Noordhuis
44b8153005
unix: remove clang compiler warning pragmas (#3989)
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.
2023-05-15 10:52:23 +02:00
Santiago Gimeno
30fc896cc1
unix: handle CQ overflow in iou ring (#3991)
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.
2023-05-15 10:42:14 +02:00
Tim Besard
6ad347fae4
unix: constrained_memory should return UINT64_MAX (#3753)
Document that we return UINT64_MAX if the cgroup limit is set to the
max. For cgroupv2, that happens if we encounter `max`, while cgroupv1
returns 9223372036854771712 when no limit is set (which according to
[this StackExchange discussion] is derived from LONG_MAX and
PAGE_SIZE). So make sure we also detect this case for cgroupv1.

[this StackExchange discussion]: https://unix.stackexchange.com/questions/420906/what-is-the-value-for-the-cgroups-limit-in-bytes-if-the-memory-is-not-restricte

Addresses: https://github.com/libuv/libuv/pull/3744/files#r974062912
2023-05-12 14:34:20 -04:00
Elliot Saba
748d894e82
win,process: write minidumps when sending SIGQUIT (#3840)
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
2023-05-12 14:28:35 -04:00
Lewis Russell
f70027cbdc
build: export compile_commands.json (#3968)
Allows LSP's like clangd to work.
2023-05-12 14:15:24 -04:00
Mohammed Keyvanzadeh
8a5b0955de
test: add additional assert (#3983)
Add a missing assert that checks whether `uv_pipe_init()`
succeeded or not.
2023-05-12 14:13:23 -04:00
Ben Noordhuis
ff7dcd2654
unix: use memcpy() instead of type punning (#3990)
Libuv makes no claim to being strict aliasing-clean but type punning
makes me feel unclean so replace it with memcpy().
2023-05-12 14:12:47 -04:00
cui fliter
3990fcad62
docs: fix some typos (#3984) 2023-05-12 14:12:01 -04:00
Santiago Gimeno
15e81386bf
macos: revert clonefile (#3987)
* 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.
2023-05-10 17:38:58 +02:00
Santiago Gimeno
3f331e97da
macos: update minimum supported version (#3982)
Only support the versions still maintained by Apple.
2023-05-02 17:04:42 +02:00
Ben Noordhuis
6e073ef5da
linux: use io_uring to batch epoll_ctl calls (#3979)
This work was sponsored by ISC, the Internet Systems Consortium.
2023-05-01 09:00:08 +02:00
Ben Noordhuis
f272082240
linux: fix logic bug in sqe ring space check (#3980)
Handle wraparound properly, otherwise we may end up overwriting elements
that have not been consumed by the kernel yet.
2023-05-01 06:17:26 +02:00
sivadeilra
c51522c08f
win: fix race condition in uv__init_console() (#3973)
Co-authored-by: Arlie Davis <ardavis@microsoft.com>
Fixes: https://github.com/libuv/libuv/issues/3970
2023-04-29 12:59:56 +02:00
Ben Noordhuis
932092e95d
build: remove freebsd and openbsd buildbots (#3974)
The buildbots are super flaky compared to other platforms and no one
seems invested enough to investigate. They don't add nearly enough value
for the friction they cause so away they go.

Fixes: https://github.com/libuv/libuv/issues/3934
Fixes: https://github.com/libuv/libuv/issues/3972
Refs: https://github.com/libuv/libuv/pull/3548
2023-04-27 22:15:01 +02:00
Ben Noordhuis
c8a1e6132b
unix,win: add uv_clock_gettime() (#3971)
Fixes: https://github.com/libuv/libuv/issues/1674
2023-04-27 22:13:46 +02:00
Trevor Norris
e02642cf3b src: fix events/events_waiting metrics counter (#3957)
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.
2023-04-24 15:29:14 -06:00
Trevor Norris
b60f08e782 test: add ASSERT_OK (#3957)
The majority of uses for ASSERT_EQ are to check if the return value is
0. So make a macro specifically for this and make things easier to read.
2023-04-24 15:29:14 -06:00
Ben Noordhuis
4fc331f8e8
doc: update active maintainers list (#3967)
Move Bert and Fedor to emeriti.
2023-04-23 17:52:41 +02:00
Lewis Russell
507f2f950d
macos: fix source not being followed when cloning (#3941)
Fixes: https://github.com/libuv/libuv/issues/3940
2023-04-23 11:54:25 +02:00
Ben Noordhuis
1c935a3445
linux: remove bug workaround for obsolete kernels (#3965)
Libuv no longer supports such kernels so the workaround can be removed.
2023-04-20 12:15:32 +02:00
Ben Noordhuis
dfae365f84
linux: add IORING_OP_CLOSE support (#3964) 2023-04-20 10:44:16 +02:00
Ben Noordhuis
5ca5e475bb
linux: add IORING_OP_OPENAT support (#3963) 2023-04-20 10:17:06 +02:00
Ben Noordhuis
3ba75f1300
test: disable signal test under ASan and MSan (#3961)
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
2023-04-19 07:40:18 +02:00
Ben Noordhuis
a7ff759ca1
linux: fix academic valgrind warning (#3960)
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
2023-04-19 07:39:10 +02:00
Ben Noordhuis
d2c31f429b
linux: introduce io_uring support (#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
2023-04-18 12:32:08 +02:00
Ben Noordhuis
cb5da59226
test: don't use static buffer for formatting (#3953)
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.
2023-04-14 16:54:28 +02:00
Trevor Norris
2f33980a91
src: switch to use C11 atomics where available (#3950)
Switch all code in unix/ to use C11 atomics directly.

Change uv_library_shutdown() to use an exchange instead of load/store.

Unfortunately MSVC only started supporting C11 atomics in VS2022 version
17.5 Preview 2 as experimental. So resort to using the Interlocked API.

Ref: https://devblogs.microsoft.com/cppblog/c11-atomics-in-visual-studio-2022-version-17-5-preview-2/
Fixes: https://github.com/libuv/libuv/issues/3948
2023-04-12 13:54:22 -06:00
Jason Zhang
e189c31375
doc: consistent single backquote in misc.rst (#3946)
Fixes: https://github.com/libuv/libuv/issues/3928
2023-04-11 19:50:31 +02:00
Stacey Marshall
1eae55984d
unix,sunos: SO_REUSEPORT not valid on all sockets (#3949)
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)
2023-04-11 19:49:25 +02:00
Ben Noordhuis
244df24bf4
linux: remove arm oabi support (#3942)
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
2023-04-02 00:20:26 +02:00
Ben Noordhuis
28b9f1e68b
linux: replace unsafe macro with inline function (#3933)
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.
2023-03-31 10:09:48 +02:00
Ben Noordhuis
0c8eccc3fc
linux: remove epoll_pwait() emulation code path (#3936)
This was removed before in 2018 but then reinstated again in 2019 to
fix building with old Android SDKs. Well, time marches on; this time
it's gone for good.

Refs: https://github.com/libuv/libuv/pull/1372
Refs: https://github.com/libuv/libuv/pull/2358
2023-03-28 11:58:56 +02:00
Trevor Norris
7b84d5b0ec
doc: add trevnorris to maintainers (#3931) 2023-03-20 14:23:50 -06:00
Trevor Norris
6600954906
win,unix: change execution order of timers (#3927)
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>
2023-03-20 10:04:57 -06:00
Trevor Norris
4a65e10f5e
doc: add entries to LINKS.md (#3925)
Add the libuv wrapper nsuv to the list, along with other C++ apps that
were found to use libuv extensively and have been maintained recently.
2023-03-15 22:35:18 -06:00
Niklas Mischkulnig
d4eb276eea
darwin: bring back macos-specific copyfile(3) (#3654)
Co-authored-by: Mingye Wang <arthur200126@gmail.com>
2023-03-13 11:54:31 +01:00
Trevor Norris
91a7e49846
test: silence more valgrind warnings (#3917)
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.
2023-03-12 14:59:00 +01:00
Bruno Passeri
dfb206c8b0
linux: fix ceph copy error truncating readonly files (#3920)
Trying to copy a read-only file onto a ceph-fuse filesystem fails,
returning an `EACCES` error. This happens when the destination
doesn't exist yet, and a new file is created.

By checking that the error matches, and that the destination file
is empty, we can fix this issue while waiting for a proper Ceph
fix to be upstreamed.

Fixes: https://github.com/libuv/libuv/issues/3919
Refs: https://github.com/nodejs/node/issues/37284
Refs: https://github.com/libuv/libuv/issues/3117
Refs: https://github.com/libuv/libuv/issues/3322
2023-03-12 12:05:45 +01:00
Ben Noordhuis
9581e3df0c
test: fix visual studio 2015 build error (#3918) 2023-03-10 11:41:35 +01:00
Jameson Nash
964f79f7c8
barrier: wait for prior out before next in (#3905)
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
2023-03-06 17:57:25 -05:00
Trevor Norris
460accf9be
test: make valgrind happy (#3916)
Missing a call to MAKE_VALGRIND_HAPPY() to silence valgrind output.
2023-03-03 15:52:31 -05:00
Trevor Norris
780b40ea7b
win: fix leak in uv_chdir (#3912)
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.
2023-02-27 13:58:12 -05:00
Ben Noordhuis
e613fdd83c
macos: fix fsevents thread race conditions (#3909)
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
2023-02-17 13:59:02 +01:00
Jameson Nash
62c2374a8c
unix: DRY and fix tcp bind error path (#3904)
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>
2023-02-07 14:59:39 -05:00
Ben Noordhuis
84525b26fe
test: remove timing-sensitive check (#3899)
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
2023-02-07 11:15:59 -05:00
Ben Noordhuis
be2ddacb90
unix: abort on clock_gettime() error (#3898)
Per standard libuv operating procedures, abort on unexpected failure.
Don't silently ignore the error and return garbage.
2023-02-01 22:10:36 +01:00
Jameson Nash
42cc412c4a
darwin,process: feed kevent the signal to reap children (#3893)
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.
2023-02-01 13:42:26 -05:00
Ben Noordhuis
f1b4c76648
test: remove bad tty window size assumption (#3895)
Fixes: https://github.com/libuv/libuv/issues/3894
2023-01-31 18:35:18 +01:00
Jameson Nash
ee206367d4
build,test: fix distcheck errors (#3886)
When run under distcheck, the libuv source permissions are read-only,
which makes this test copyfile fail without explicit correction to the
permissions.
2023-01-22 15:26:22 -06:00
James McCoy
2638237e1f
build: add CI for OpenBSD and FreeBSD (#3548)
Fixes: https://github.com/libuv/libuv/issues/3510
2023-01-21 13:52:36 +01:00
Ben Noordhuis
67063ead60 build: promote tsan ci to must-pass
Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
a3b7dfcfca test: cond-skip tcp_writealot
Too slow to run under ThreadSanitizer.

Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
bcbaf671a9 test: cond-skip signal_multiple_loops
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
2023-01-20 22:38:59 +01:00
Ben Noordhuis
c58cd28279 test: cond-skip fork_threadpool_queue_work_simple
Skip the test when ThreadSanitizer is active because the latter doesn't
support forking in multi-threaded processes.

Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
f328457cb1 test: fix ThreadSanitizer data race warning
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
2023-01-20 22:38:59 +01:00
Ben Noordhuis
7b5a21deaa test: fix ThreadSanitizer data race warning
Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
895a1c03be test: fix ThreadSanitizer data race warning
Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
Ben Noordhuis
679d679f25 test: fix ThreadSanitizer thread leak warning
Refs: https://github.com/libuv/libuv/issues/3681
2023-01-20 22:38:59 +01:00
AJ Heller
0235e150e2
build: add libuv:: namespace to libuvConfig.cmake (#3596)
This may be breaking, but is still quite new, and seems to follow cmake
best practices.
2023-01-19 16:07:29 -06:00
erw7
17ea56ee73
build: Improve build by cmake for Cygwin (#2085)
- Fix build on Cygwin.
- Simplify file name of static library.

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
2023-01-19 15:33:07 -06:00
Tamás Bálint Misius
b4440f5aa2
doc: document uv_fs_cb type (#3517) 2023-01-19 14:05:07 -06:00
Jameson Nash
fe7ee4a624
unix: remove busy loop from uv_async_send (#3879)
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
2023-01-19 14:03:59 -06:00
Jameson Nash
a40058dbd1
build: add CI for distcheck (#3571)
Refs: https://github.com/libuv/libuv/issues/2190#issuecomment-465974240
Refs: https://github.com/libuv/libuv/issues/2199

Co-authored-by: Richard Lau <rlau@redhat.com>
2023-01-19 14:00:45 -06:00
Jameson Nash
c70cc5832b
build,win: add mingw-w64 CI configuration (#3885)
Co-authored-by: Nicolas Noble <pixel@nobis-crew.org>
2023-01-19 14:00:15 -06:00
panran
a4ba1bd73e
test: fix some warnings when compiling tests (#3816)
```
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>
2023-01-19 10:48:13 -06:00
Ben Noordhuis
61e0bbda6b
doc: clean up license file (#3876)
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
2023-01-19 10:46:25 -06:00
Jameson Nash
a38c4dfa99
docs: update Sphinx version on RTD (#3882)
python3.9 -mvirtualenv sphinx
    . sphinx/bin/activate
    pip install Sphinx
    pip freeze > requirements.txt
2023-01-18 12:15:48 -06:00
Jameson Nash
975f685d69
docs: add CI for docs PRs (#3884) 2023-01-18 11:29:10 -06:00
Jameson Nash
4155405e60
docs: delete code Makefile (#3883)
This Makefile was a fairly poor sample, while now we have CMake for
these to use for testing.
2023-01-18 10:16:29 -06:00
Ben Noordhuis
55b5d88b01
unix,win: use static_assert when available (#3189)
Fixes: https://github.com/libuv/libuv/issues/3131
2023-01-17 22:26:41 -06:00
Jameson Nash
2f110a50df
misc: extend getpw to take uid as an argument (#3523)
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.
2023-01-17 21:51:28 -06:00
Darshan Sen
7fd7e8264f
win,fs: fix readlink errno for a non-symlink file (#3719)
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`).
2023-01-17 21:04:52 -06:00
Jack·Boos·Yu
1279a20c03
docs: add vcpkg instruction step (#3747)
Co-authored-by: JackBoosY <yuzaiyang@beyondsoft.com>
2023-01-17 20:54:36 -06:00
dundargoc
39f9189f34
build: remove unnecessary policy setting (#3873)
All cmake policies up to CMP0065 are set to NEW by default since the
minimum required version is 3.4.
2023-01-14 11:12:51 +01:00
Ben Noordhuis
434eb4b0ac
linux: handle cpu hotplugging in uv_cpu_info() (#3861)
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
2023-01-14 05:08:15 +01:00
Ben Noordhuis
5ee455ffc2
build: enable platform_output test on qemu (#3878)
The test was disabled because of a qemu bug that is presumed to have
since been fixed.

Refs: https://github.com/libuv/libuv/pull/3861
2023-01-12 15:22:19 +01:00
Ben Noordhuis
e972c6705f
build: add UndefinedBehaviorSanitizer support (#3870)
- add UBSAN build option

- turn on UBSAN CI build

Fixes: https://github.com/libuv/libuv/issues/3869
2023-01-04 23:43:50 +01:00
Zvicii
12b8c116a4
build: add define guard around UV_EXTERN (#3855)
Incidentally lets users control the definition of UV_EXTERN.
2023-01-03 22:03:37 +01:00
Ben Noordhuis
e9d91fccfc
darwin: remove unused fsevents symbol lookups (#3867)
One hasn't been in use since 2017, the other since 2013.
2022-12-22 00:51:19 +01:00
Ben Noordhuis
d5cfb89959
test: unflake fs_event_watch_dir test (#3863)
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
2022-12-21 07:51:50 +01:00
Ben Noordhuis
a3de1384c3
linux: simplify uv_uptime() (#3859)
Drop support for old kernels. Assume support for CLOCK_BOOTTIME.
2022-12-15 12:57:14 +01:00
Santiago Gimeno
abf77a9eda
test: fix some unreachable code warnings (#3851) 2022-12-10 19:36:46 +01:00
Santiago Gimeno
75d9411e80
win: move child_stdio_buffer out of uv_process_t (#3850) 2022-12-09 13:27:52 +01:00
Ben Noordhuis
cc000cfb5e
build: drop qemu-alpha from ci matrix (#3848)
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
2022-12-06 22:57:52 +01:00
Santiago Gimeno
e1143f1265 win: fixes in uv__pipe_try_write() (#3825 2/2)
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.
2022-12-01 23:16:58 +01:00
Ben Noordhuis
244e0e2059 win: implement uv_try_write() for pipes(#3825 1/2) 2022-12-01 23:16:58 +01:00
Ben Noordhuis
1a91508857 win: fix -Wunused-function warning 2022-12-01 11:27:49 +01:00
Ben Noordhuis
a138041c59 win: fix -Wunused-variable warning 2022-12-01 11:27:49 +01:00
Stefan Stojanovic
c17bd99f1c
win: fix fstat for pipes and character files (#3811)
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>
2022-11-29 17:46:09 -05:00
Ben Noordhuis
5102b2c093
unix: drop kfreebsd support (#3835)
Because kFreeBSD is dead. RIP.

Fixes: https://github.com/libuv/libuv/issues/3833
2022-11-28 22:45:28 +01:00
Sergey Rubanov
2c6858a018
Add Socket Runtime to the LINKS.md
PR-URL: https://github.com/libuv/libuv/pull/3834
2022-11-28 09:51:45 -05:00
Ben Noordhuis
8ddffeeea3
doc: bump min supported linux and freebsd versions (#3830)
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
2022-11-28 12:00:27 +01:00
Ben Noordhuis
238ba3b625
test: fix -Wunused-but-set-variable warnings (#3829) 2022-11-26 22:30:04 +01:00
Tim Besard
988d225cf0
unix,win: add uv_get_available_memory() (#3754) 2022-11-24 22:09:32 +01:00
Edward Humes
a737255791
build: don't use ifaddrs.h on solaris 10 (#3826)
Disable usage of ifaddrs.h on Solaris 10 at configuration time.
2022-11-22 21:46:55 +01:00
daomingq
64669fdd8d
thread: add uv_thread_getcpu() (#3803)
Add uv_thread_getcpu() api to get the cpu number on which the calling
thread is running.
2022-11-15 18:01:29 +01:00
Trevor Norris
e141586053
src: add new metrics APIs (#3749)
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
2022-11-11 16:21:58 +01:00
theanarkh
6f69654294
misc: fix return value of memory functions (#3818)
Specifically uv_get_free_memory and uv_get_total_memory.
2022-11-11 10:56:06 +01:00
Santiago Gimeno
3706c4f855 win,pipe: fixes in uv_pipe_connect()
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
2022-11-11 10:44:34 +01:00
Santiago Gimeno
96637d032f win,test: change format of TEST_PIPENAME's
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.
2022-11-11 10:44:34 +01:00
Jameson Nash
3300502231
darwin: use hw.cpufrequency again for frequency info (#3679)
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
2022-11-08 12:40:17 -05:00
Ben Noordhuis
8975c05d19
doc: document 0 return value for free/total memory (#3817)
Refs: https://github.com/libuv/libuv/discussions/3809
2022-11-08 17:33:19 +01:00
twosee
07949ce2ae
win: fix an incompatible types warning (#3798) 2022-11-08 10:24:45 +01:00
ywave620
dff3f8ccab
win: optimize udp receive performance (#3807)
Do at most 32 nonblocking udp receive in a row.

Fixes: https://github.com/libuv/libuv/issues/3704
2022-11-08 10:23:40 +01:00
Qix
8a1f378f05
doc: mention close_cb can be NULL (#3810) 2022-11-08 09:57:54 +01:00
twosee
ec5130c3f9
unix,win: fix 'sprintf' is deprecated warning (#3813) 2022-11-08 09:56:14 +01:00
Saúl Ibarra Corretgé
a7b16bfb33 win: drop code checking for Windows XP / Server 2k3
Our minimum requirements are Windows 8 now.
2022-11-08 06:51:07 +01:00
Saúl Ibarra Corretgé
2b4b293ebb win,tcp,udp: remove "active streams" optimization
It has been disabled for 11 years, I guess it should remain that way.
2022-11-04 22:11:21 +01:00
Santiago Gimeno
c880de3004 build: remove bashism from autogen.sh 2022-11-04 10:34:57 +01:00
Ben Noordhuis
c83b9bd9c6
include: map ENODATA error code (#3802)
Fixes: https://github.com/libuv/libuv/issues/3795
2022-10-25 13:00:45 +02:00
daomingq
e900006642
thread: add support for affinity (#3774)
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).
2022-10-21 09:18:10 -04:00
number201724
357d28a256
win,pipe: improve method of obtaining pid for ipc (#3765)
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
2022-10-21 09:14:48 -04:00
Jameson Nash
1de43a1a17
build: support AddressSanitizer on MSVC (#3692)
Fixes: https://github.com/libuv/libuv/issues/3682
2022-10-21 09:10:19 -04:00
jensbjorgensen
821b0ba8cb
doc: add uv_poll_cb status==UV_EBADF note (#3797) 2022-10-21 11:02:43 +02:00
Ben Noordhuis
acfe668ecb
build: add MemorySanitizer (MSAN) support (#3788)
- 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
2022-10-18 23:21:42 +02:00
Ben Noordhuis
73b0c1f947
unix,win: give thread pool threads an 8 MB stack (#3787)
Give the threads in the thread pool a stack size that is consistent
across platforms and architectures.

Fixes: https://github.com/libuv/libuv/issues/3786
2022-10-18 23:06:47 +02:00
ywave620
3e7d2a6492
stream: process more than one write req per loop tick (#3728)
Fixes: https://github.com/libuv/libuv/issues/3668
2022-10-08 10:23:01 +02:00
Ben Noordhuis
cd1a510d16
linux: merge files back into single file (#3778)
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.
2022-10-02 14:09:42 +02:00
Ben Noordhuis
9a5a5140e5
linux: remove unused or obsolete syscall wrappers (#3777)
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.
2022-10-02 13:34:12 +02:00
Christian Clason
f610339f74
build: add LIBUV_BUILD_SHARED cmake option (#3762)
Co-authored-by: Tim Tavlintsev <ttavlintsev@enttec.com>
Fixes: https://github.com/libuv/libuv/issues/3637
2022-10-01 19:51:09 +02:00
Ben Noordhuis
71a782b641
unix: simplify atomic op in uv_tty_reset_mode() (#3773)
Compare-and-exchange is only useful in a loop. Replace it with a simple
exchange.
2022-10-01 13:43:47 +02:00
Daniel
cdbba74d7a
doc: update LINKS.md (#3772) 2022-09-27 17:43:40 +02:00
number201724
81264cfcaf
win: fix uv__pipe_accept memory leak (#3767) 2022-09-26 11:35:23 +02:00
Ben Noordhuis
c798dd7ae5
build: restore qemu download logic (#3768)
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.
2022-09-26 11:29:50 +02:00
Ben Noordhuis
b00d1bd225
unix,win: fix memory leak in uv_fs_scandir() (#3760)
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
2022-09-22 09:25:55 +02:00
Ben Noordhuis
47effc4bd3
unix: remove pre-macos 10.8 compatibility hack (#3759) 2022-09-22 09:25:35 +02:00
Ben Noordhuis
d651403b47 linux: move epoll.c back into linux-core.c
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.
2022-09-19 00:24:24 +02:00
Ben Noordhuis
48c90d3781 build: upgrade qemu-user-static package
4.2 is three years old by now. The linux/alpha emulator in that version
doesn't support the epoll_create1() system call.
2022-09-19 00:24:24 +02:00
Ben Noordhuis
d59b2905f9
linux: teach uv_get_constrained_memory() cgroupsv2 (#3744)
Fixes: https://github.com/libuv/libuv/issues/2315
2022-09-15 08:56:56 +02:00
Ben Noordhuis
0f478a7de7
kqueue: DRY file descriptor deletion logic (#3746)
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.
2022-09-12 22:59:43 +02:00
Ben Noordhuis
9d898acc56
test: fix musl libc.a dlerror() test expectation (#3735)
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
2022-09-07 11:21:24 -04:00
Steven Schveighoffer
a855c74183
doc: add note about offset -1 in uv_fs_read/write (#3677) 2022-09-07 11:19:08 -04:00
Ben Noordhuis
fb76f210eb
unix: fix uv_getrusage() ru_maxrss reporting (#3721)
Most platforms report it in kilobytes but macOS and Solaris report it in
bytes and pages respectively.

Fixes: https://github.com/nodejs/node/issues/44332
2022-08-21 23:29:42 +02:00
Luan Devecchi
97dcdb1926
win: support Windows 11 in uv_os_uname() (#3718)
Fixes: https://github.com/libuv/libuv/issues/3381
Fixes: https://github.com/nodejs/node/issues/40862
2022-08-13 18:16:28 +02:00
Santiago Gimeno
7bccb562e4
unix,win: remove UV_HANDLE_SHUTTING flag (#3705)
Replace it with a `uv__is_stream_shutting()` macro that checks the
`shutdown_req` field.

It partially fixes: https://github.com/libuv/libuv/issues/3663.
2022-08-03 15:24:32 -04:00
Ben Noordhuis
4db0a9a6b7
win: fix thread race in uv_cwd() and uv_chdir() (#3708)
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.
2022-07-28 00:34:03 +02:00
Ben Noordhuis
850f002cb2
build: switch ci from macos-10.15 to macos-11 (#3707)
The former will be removed by GitHub in August.

Fixes: https://github.com/libuv/libuv/issues/3697
2022-07-27 22:53:28 +02:00
Ben Noordhuis
df0ac426f3
win: fix off-by-1 buffer overrun in uv_exepath() (#3695)
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
2022-07-27 21:11:41 +02:00
Ben Noordhuis
6c692ad1cb
unix: don't accept() connections in a loop (#3696)
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.
2022-07-20 12:42:50 +02:00
Ben Noordhuis
ac5180e29c
unix: switch to c11 atomics (#3688)
Fixes: https://github.com/libuv/libuv/issues/3683
2022-07-19 10:09:09 +02:00
自发对称破缺
fb85db1d3e
build: enable MSVC_RUNTIME_LIBRARY setting (#3624) 2022-07-18 15:49:17 -04:00
Ben Noordhuis
06948c6ee5
android: remove pthread-fixes.c (#3674)
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.
2022-07-15 11:18:38 +02:00
Ben Noordhuis
495ffca2c2
win: remove stdint-msvc2008.h (#3673)
Support for VS 2008 was removed two years ago in commit a779fccfd so
this file can safely be deleted.
2022-07-15 10:39:14 +02:00
Jameson Nash
e81cc74ca2 Now working on version 1.44.3
Fixes: https://github.com/libuv/libuv/issues/3586
2022-07-12 12:22:04 -04:00
Jameson Nash
57a9a7196f Add SHA to ChangeLog 2022-07-12 12:17:13 -04:00
Jameson Nash
0c1fa696aa 2022.07.12, Version 1.44.2 (Stable)
Changes since version 1.44.1:

* Add SHA to ChangeLog (Jameson Nash)

* aix, ibmi: handle server hang when remote sends TCP RST (V-for-Vasili)

* build: make CI a bit noisier (Jameson Nash)

* process: reset the signal mask if the fork fails (Jameson Nash)

* zos: implement cmpxchgi() using assembly (Shuowang (Wayne) Zhang)

* build: AC_SUBST for AM_CFLAGS (Claes Nästén)

* ibmi: Implement UDP disconnect (V-for-Vasili)

* doc: update active maintainers list (Ben Noordhuis)

* build: fix kFreeBSD build (James McCoy)

* build: remove Windows 2016 workflows (Darshan Sen)

* Revert "win,errors: remap ERROR_ACCESS_DENIED to UV_EACCES" (Darshan
  Sen)

* unix: simplify getpwuid call (Jameson Nash)

* build: filter CI by paths and branches (Jameson Nash)

* build: add iOS to macos CI (Jameson Nash)

* build: re-enable CI for windows changes (Jameson Nash)

* process,iOS: fix build breakage in process.c (Denny C. Dai)

* test: remove unused declarations in tcp_rst test (V-for-Vasili)

* core: add thread-safe strtok implementation (Guilherme Íscaro)

* win: fix incompatible-types warning (twosee)

* test: fix flaky file watcher test (Ben Noordhuis)

* build: fix AIX xlc autotools build (V-for-Vasili)

* unix,win: fix UV_RUN_ONCE + uv_idle_stop loop hang (Ben Noordhuis)

* win: fix unexpected ECONNRESET error on TCP socket (twosee)

* doc: make sample cross-platform build (gengjiawen)

* test: separate some static variables by test cases (Hannah Shi)

* sunos: fs-event callback can be called after uv_close() (Andy
  Fiddaman)

* uv: re-register interest in a file after change (Shuowang (Wayne)
  Zhang)

* uv: register UV_RENAME event for _RFIM_UNLINK (Shuowang (Wayne) Zhang)

* uv: register __rfim_event 156 as UV_RENAME (Shuowang (Wayne) Zhang)

* doc: remove smartos from supported platforms (Ben Noordhuis)

* macos: avoid posix_spawnp() cwd bug (Jameson Nash)

* release: check versions of autogen scripts are newer (Jameson Nash)

* test: rewrite embed test (Ben Noordhuis)

* openbsd: use utimensat instead of lutimes (tuftedocelot)

* doc: fix link to uvwget example main() function (blogdaren)

* unix: use MSG_CMSG_CLOEXEC where supported (Ben Noordhuis)

* test: remove disabled callback_order test (Ben Noordhuis)

* win,pipe: fix bugs with pipe resource lifetime management (Jameson
  Nash)

* loop: better align order-of-events behavior between platforms (Jameson
  Nash)

* aix,test: uv_backend_fd is not supported by poll (V-for-Vasili)

* kqueue: skip EVFILT_PROC when invalidating fds (chucksilvers)

* darwin: fix atomic-ops.h ppc64 build (Sergey Fedorov)

* zos: don't err when killing a zombie process (Shuowang (Wayne) Zhang)

* zos: avoid fs event callbacks after uv_close() (Shuowang (Wayne)
  Zhang)

* zos: correctly format interface addresses names (Shuowang (Wayne)
  Zhang)

* zos: add uv_interface_addresses() netmask support (Shuowang (Wayne)
  Zhang)

* zos: improve memory management of ip addresses (Shuowang (Wayne)
  Zhang)

* tcp,pipe: fail `bind` or `listen` after `close` (theanarkh)

* zos: implement uv_available_parallelism() (Shuowang (Wayne) Zhang)

* udp,win: fix UDP compiler warning (Jameson Nash)

* zos: fix early exit of epoll_wait() (Shuowang (Wayne) Zhang)

* unix,tcp: fix errno handling in uv__tcp_bind() (Samuel Cabrero)

* shutdown,unix: reduce code duplication (Jameson Nash)

* unix: fix c99 comments (Ben Noordhuis)

* unix: retry tcgetattr/tcsetattr() on EINTR (Ben Noordhuis)

* docs: update introduction.rst (Ikko Ashimine)

* unix,stream: optimize uv_shutdown() codepath (Jameson Nash)

* zos: delay signal handling until after normal i/o (Shuowang (Wayne)
  Zhang)

* stream: uv__drain() always needs to stop POLLOUT (Jameson Nash)

* unix,tcp: allow EINVAL errno from setsockopt in uv_tcp_close_reset()
  (Stacey Marshall)

* win,shutdown: improve how shutdown is dispatched (Jameson Nash)
2022-07-12 12:16:33 -04:00
Jameson Nash
ee970e38a6
win,shutdown: improve how shutdown is dispatched (#3649)
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.
2022-07-11 12:30:20 -04:00
Stacey Marshall
f5e4d85cd2
unix,tcp: allow EINVAL errno from setsockopt in uv_tcp_close_reset() (#3662)
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.
2022-07-11 12:29:25 -04:00
Jameson Nash
47e95602c4
stream: uv__drain() always needs to stop POLLOUT (#3675)
Regression caused by 1a91b51976 mistake.

Refs: https://github.com/libuv/libuv/pull/3648
Fixes: https://github.com/libuv/libuv/pull/3648/3671
2022-07-11 12:24:49 -04:00
Wayne Zhang
c4d73c306b
zos: delay signal handling until after normal i/o (#3643)
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>
2022-07-07 18:21:37 -04:00
Jameson Nash
6999994def
unix,stream: optimize uv_shutdown() codepath (#3646)
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.
2022-07-07 15:24:35 -04:00
Ikko Ashimine
f1635257cb
docs: update introduction.rst (#3664)
Github -> GitHub
2022-07-07 14:07:29 -04:00
Ben Noordhuis
7ca20a2679
unix: retry tcgetattr/tcsetattr() on EINTR (#3669)
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
2022-07-06 07:41:51 +02:00
Ben Noordhuis
3136561cd0
unix: fix c99 comments (#3667)
Causes compilation errors for people that build libuv with a C89
compiler.

Refs: https://github.com/libuv/libuv/discussions/3666
2022-07-06 07:02:05 +02:00
Jameson Nash
1a91b51976
shutdown,unix: reduce code duplication (#3648)
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.
2022-06-28 23:44:03 -04:00
Samuel Cabrero
2108309302
unix,tcp: fix errno handling in uv__tcp_bind() (#3652)
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.
2022-06-28 23:42:52 -04:00
Wayne Zhang
27eec099d6
zos: fix early exit of epoll_wait() (#3653)
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>
2022-06-28 23:42:11 -04:00
Jameson Nash
e3aaff185f
udp,win: fix UDP compiler warning (#3647)
Previously it would pass a pointer to uninitialized memory to WSASendTo,
which triggered a compiler warning. However, `addrlen` will be 0, so it
seems unlikely to trigger an error or uninitialized memory access.

Refs: https://github.com/libuv/leps/pull/10
Refs: https://github.com/libuv/libuv/pull/1872
Refs: https://github.com/libuv/libuv/pull/2217
2022-06-17 16:06:15 -04:00
Wayne Zhang
0b1c752b5c
zos: implement uv_available_parallelism() (#3650)
Implement uv_available_parallelism() for z/OS by reporting the number of
online cpu using __get_num_online_cpus() from ZOSLIB.
2022-06-17 11:55:44 +01:00
theanarkh
8bcd689c04
tcp,pipe: fail bind or listen after close (#3641)
Return `UV_EINVAL` in `bind` and `listen` when `handle` is
`UV_HANDLE_CLOSING` or `UV_HANDLE_CLOSED`.

Fixes: https://github.com/libuv/libuv/issues/3503
2022-06-11 00:32:08 -04:00
Wayne Zhang
d938c104e1 zos: improve memory management of ip addresses (#3640 3/3)
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>
2022-06-11 00:26:43 -04:00
Wayne Zhang
524c5ed87d zos: add uv_interface_addresses() netmask support (#3640 2/3)
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>
2022-06-11 00:26:33 -04:00
Wayne Zhang
75ad046bfb zos: correctly format interface addresses names (#3640 1/3)
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>
2022-06-11 00:26:21 -04:00
Wayne Zhang
77c8e993ec
zos: avoid fs event callbacks after uv_close() (#3620)
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
2022-06-11 00:22:06 -04:00
Wayne Zhang
51dcac5da7
zos: don't err when killing a zombie process (#3625)
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>
2022-05-25 09:12:57 -04:00
Sergey Fedorov
99ab53e998
darwin: fix atomic-ops.h ppc64 build (#3634) 2022-05-24 17:04:47 +02:00
chucksilvers
730e07e2f7
kqueue: skip EVFILT_PROC when invalidating fds (#3629)
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.
2022-05-17 13:43:52 +02:00
V-for-Vasili
1b8cc56194
aix,test: uv_backend_fd is not supported by poll (#3621)
Fixes: https://github.com/libuv/libuv/issues/3614
Co-authored-by: Vasili Skurydzin <vasili.skurydzin@ibm.com>
2022-05-13 12:43:28 +02:00
Jameson Nash
ee3718dd71
loop: better align order-of-events behavior between platforms (#3598)
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
2022-05-13 12:41:33 +02:00
Jameson Nash
ec67735412
win,pipe: fix bugs with pipe resource lifetime management (#3611)
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
2022-05-13 12:40:02 +02:00
Ben Noordhuis
7825bfb49d
test: remove disabled callback_order test (#3619)
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
2022-05-09 09:17:35 +02:00
Ben Noordhuis
03a698b9c6
unix: use MSG_CMSG_CLOEXEC where supported (#3609)
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.
2022-04-27 22:44:00 +02:00
blogdaren
e0680d3061
doc: fix link to uvwget example main() function (#3605) 2022-04-27 10:23:28 +02:00
tuftedocelot
4e63e48879
openbsd: use utimensat instead of lutimes (#3607)
OpenBSD doesn't have lutimes so utimensat should be used instead.
2022-04-27 10:19:28 +02:00
Ben Noordhuis
a302ad427d
test: rewrite embed test (#3608)
- fix busy loop
- fix multi-thread race conditions
- reduce amount of platform-specific code

Fixes: https://github.com/libuv/libuv/issues/3606
2022-04-27 10:18:40 +02:00
Jameson Nash
9e59aa1bc8
release: check versions of autogen scripts are newer (#3554)
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.
2022-04-19 11:16:25 -04:00
Jameson Nash
7c9b3938df
macos: avoid posix_spawnp() cwd bug (#3597)
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>
2022-04-15 14:10:27 -04:00
Ben Noordhuis
6dfcdb9878
doc: remove smartos from supported platforms (#3594)
Commit 3af55129 from 2017 distinguished between smartos and other sunos
spawn but [0] makes it clear ("a new chapter" - barf) that smartos is
dead.

Stop mentioning smartos and put everything under the sunos umbrella.

[0] https://www.joyent.com/blog/a-new-chapter-begins-for-triton-and-smartos
2022-04-12 12:18:01 +02:00
Wayne Zhang
6d9275e412 uv: register __rfim_event 156 as UV_RENAME (#3540 3/3)
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>
2022-04-11 11:31:57 -04:00
Wayne Zhang
571f898192 uv: register UV_RENAME event for _RFIM_UNLINK (#3540 2/3)
`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>
2022-04-11 11:31:38 -04:00
Wayne Zhang
07c4cacb58 uv: re-register interest in a file after change (#3540 1/3)
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>
2022-04-11 11:30:13 -04:00
Andy Fiddaman
612c28b89f
sunos: fs-event callback can be called after uv_close() (#3542)
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.
2022-04-11 11:25:59 -04:00
Hannah Shi
b51e940dfa
test: separate some static variables by test cases (#3567) 2022-04-11 11:22:37 -04:00
Jiawen Geng
a78671543b
doc: make sample cross-platform build (#3592)
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
2022-04-11 09:52:28 +08:00
twosee
69ebb2d720
win: fix unexpected ECONNRESET error on TCP socket (#3584) 2022-04-07 21:44:45 -04:00
Ben Noordhuis
1fe609ea05
unix,win: fix UV_RUN_ONCE + uv_idle_stop loop hang (#3590)
Wrong accounting of idle handles in uv_run() made it sleep when there
was nothing left to do. Do a non-blocking poll for I/O instead.
2022-04-06 15:49:21 +02:00
V-for-Vasili
7233c428ec
build: fix AIX xlc autotools build (#3588) 2022-04-06 13:07:05 +01:00
Ben Noordhuis
223e526f27
test: fix flaky file watcher test (#3591)
FSEvents on macOS sometimes sends one change event, sometimes two.
Make the test more lenient.

Fixes #3589.
2022-04-06 13:40:51 +02:00
twosee
e6c67bf803
win: fix incompatible-types warning (#3581)
Introduced by https://github.com/libuv/libuv/pull/3350.
2022-03-31 13:53:41 -04:00
Guilherme Íscaro
2a31fe8552
core: add thread-safe strtok implementation (#3553)
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.
2022-03-22 15:15:00 -04:00
V-for-Vasili
9f2ed35da0
test: remove unused declarations in tcp_rst test (#3574)
Refs: https://github.com/libuv/libuv/pull/3482
2022-03-22 15:13:10 -04:00
Denny C. Dai
264f16dcf6
process,iOS: fix build breakage in process.c (#3563)
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>
2022-03-22 15:11:26 -04:00
Jameson Nash
abf201a894
build: re-enable CI for windows changes (#3572)
I got the conditional reversed in https://github.com/libuv/libuv/pull/3564
2022-03-22 15:09:06 -04:00
Jameson Nash
e64ec13c13
build: add iOS to macos CI (#3564)
Smokescreen for build errors on iOS, currently ignoring failures due to
aforementioned build errors.
2022-03-21 20:32:22 -04:00
Jameson Nash
8528c622b0
build: filter CI by paths and branches (#3569)
Avoids some unnecessary CI work, particularly on forks, which would
often start a build on every push.
2022-03-21 18:34:00 -04:00
Jameson Nash
93309c6dbf
unix: simplify getpwuid call (#3535)
As suggested in https://github.com/libuv/libuv/pull/3523#discussion_r821550169
2022-03-21 15:44:43 -04:00
Darshan Sen
a6ba1d709e
Revert "win,errors: remap ERROR_ACCESS_DENIED to UV_EACCES (#3193)" (#3565)
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>
2022-03-20 11:06:14 +01:00
Darshan Sen
4d8af0c945
build: remove Windows 2016 workflows (#3379)
Refs: https://github.blog/changelog/2021-10-19-github-actions-the-windows-2016-runner-image-will-be-removed-from-github-hosted-runners-on-march-15-2022/
Signed-off-by: Darshan Sen <darshan.sen@postman.com>
2022-03-20 11:04:19 +01:00
James McCoy
0b23a1ee7e
build: fix kFreeBSD build (#3566)
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
2022-03-19 11:30:36 +01:00
Ben Noordhuis
ff8290179c
doc: update active maintainers list (#3527) 2022-03-19 10:32:33 +01:00
V-for-Vasili
c1128f3db3
ibmi: Implement UDP disconnect (#3561)
On IBM i a connectionless transport socket can be disconnected by
either setting the addr parameter to NULL or setting the
addr_length parameter to zero, and issuing another connect().

Refs: https://www.ibm.com/docs/en/i/7.4?topic=ssw_ibm_i_74/apis/connec.htm
2022-03-18 12:03:47 +00:00
Claes Nästén
739e441d4d
build: AC_SUBST for AM_CFLAGS (#3551)
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
2022-03-15 13:51:00 +01:00
Wayne Zhang
442e471cfc
zos: implement cmpxchgi() using assembly (#3543)
Use hand-rolled assembly to resolve a runtime bug related to the codegen
from builtin __plo_CSST.

Co-authored-by: ccw <ccw.280231@ca.ibm.com>
2022-03-13 22:50:09 +01:00
Jameson Nash
bc9cd56345
process: reset the signal mask if the fork fails (#3537)
Fix a regression that sneaked into posix spawn changes.

Refs: https://github.com/libuv/libuv/pull/3257
2022-03-11 12:05:24 -05:00
Jameson Nash
08fe5aabff
build: make CI a bit noisier (#3532)
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.
2022-03-11 11:59:38 -05:00
V-for-Vasili
5ec89b8c50
aix, ibmi: handle server hang when remote sends TCP RST (#3482)
Workaround getsockname() not working for a TCP handle that has
received RST from the remote.

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
2022-03-10 23:53:04 +00:00
Jameson Nash
df63ee1a1d Now working on version 1.44.2
Fixes: https://github.com/libuv/libuv/issues/3522
2022-03-09 12:58:37 -05:00
Jameson Nash
ee2668e586 Add SHA to ChangeLog 2022-03-09 12:55:07 -05:00
Jameson Nash
e8b7eb6908 2022.03.09, Version 1.44.1 (Stable)
Changes since version 1.44.0:

* process: simplify uv__write_int calls (Jameson Nash)

* macos: don't use thread-unsafe strtok() (Ben Noordhuis)

* process: fix hang after NOTE_EXIT (Jameson Nash)
2022-03-09 12:54:54 -05:00
Jameson Nash
bae2992cb0
process: fix hang after NOTE_EXIT (#3521)
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.
2022-03-09 12:25:51 -05:00
Ben Noordhuis
3c569c00df
macos: don't use thread-unsafe strtok() (#3524)
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
2022-03-09 11:06:39 +01:00
Jameson Nash
4296fec7f5
process: simplify uv__write_int calls (#3519) 2022-03-07 17:07:49 -05:00
Jameson Nash
761de533b2 Now working on version 1.44.1
Fixes: https://github.com/libuv/libuv/issues/3452
2022-03-07 12:18:03 -05:00
Jameson Nash
8367fc2aac Add SHA to ChangeLog 2022-03-07 11:39:19 -05:00
Jameson Nash
d2bff50845 2022.03.07, Version 1.44.0 (Stable)
Changes since version 1.43.0:

* darwin: remove EPROTOTYPE error workaround (Ben Noordhuis)

* doc: fix v1.43.0 changelog entries (cjihrig)

* win: replace CRITICAL_SECTION+Semaphore with SRWLock (David Machaj)

* darwin: translate EPROTOTYPE to ECONNRESET (Ben Noordhuis)

* android: use libc getifaddrs() (Ben Noordhuis)

* unix: fix STATIC_ASSERT to check what it means to check (Jessica
  Clarke)

* unix: ensure struct msghdr is zeroed in recvmmsg (Ondřej Surý)

* test: test with maximum recvmmsg buffer (Ondřej Surý)

* unix: don't allow too small thread stack size (Ben Noordhuis)

* bsd: ensure mutex is initialized (Ben Noordhuis)

* doc: add gengjiawen as maintainer (gengjiawen)

* process: monitor for exit with kqueue on BSDs (Jeremy Rose)

* test: fix flaky uv_fs_lutime test (Momtchil Momtchev)

* build: fix cmake install locations (Jameson Nash)

* thread,win: fix C90 style nit (ssrlive)

* build: rename CFLAGS to AM_CFLAGS (Jameson Nash)

* doc/guide: update content and sample code (woclass)

* process,bsd: handle kevent NOTE_EXIT failure (Jameson Nash)

* test: remove flaky test ipc_closed_handle (Ben Noordhuis)

* darwin: bump minimum supported version to 10.15 (Ben Noordhuis)

* win: return fractional seconds in uv_uptime() (Luca Adrian L)

* build: export uv_a for cmake (WenTao Ou)

* loop: add pending work to loop-alive check (Jameson Nash)

* win: use GetTickCount64 for uptime again (Jameson Nash)

* win: restrict system DLL load paths (jonilaitinen)

* win,errors: remap ERROR_ACCESS_DENIED to UV_EACCES (Darshan Sen)

* bench: add `uv_queue_work` ping-pong measurement (Momtchil Momtchev)

* build: fix error C4146 on MSVC (UMU)

* test: fix benchmark-ping-udp (Ryan Liptak)

* win,fs: consider broken pipe error a normal EOF (Momtchil Momtchev)

* document the values of enum uv_stdio_flags (Paul Evans)

* win,loop: add missing uv_update_time (twosee)

* win,fs: avoid closing an invalid handle (Jameson Nash)

* fix oopsie from

* doc: clarify android api level (Ben Noordhuis)

* win: fix style nits [NFC] (Jameson Nash)

* test: fix flaky udp_mmsg test (Santiago Gimeno)

* test: fix ipc_send_recv_pipe flakiness (Ben Noordhuis)

* doc: checkout -> check out (wyckster)

* core: change uv_get_password uid/gid to unsigned (Jameson Nash)

* hurd: unbreak build on GNU/Hurd (Vittore F. Scolari)

* freebsd: use copy_file_range() in uv_fs_sendfile() (David Carlier)

* test: use closefd in runner-unix.c (Guilherme Íscaro)

* Reland "macos: use posix_spawn instead of fork" (Jameson Nash)

* android: fix build error when no ifaddrs.h (ssrlive)

* unix,win: add uv_available_parallelism() (Ben Noordhuis)

* process: remove OpenBSD from kevent list (Jameson Nash)

* zos: fix build breakage (Ben Noordhuis)

* process: only use F_DUPFD_CLOEXEC if it is defined (Jameson Nash)

* win,poll: add the MSAFD GUID for AF_UNIX (roflcopter4)

* unix: simplify uv__cloexec_fcntl() (Ben Noordhuis)

* doc: add secondary GPG ID for vtjnash (Jameson Nash)

* unix: remove uv__cloexec_ioctl() (Jameson Nash)
2022-03-07 11:39:08 -05:00
Jameson Nash
20a2b1c341
unix: remove uv__cloexec_ioctl() (#3515)
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.
2022-03-06 15:01:33 -05:00
Jameson Nash
538d718ff4
doc: add secondary GPG ID for vtjnash 2022-03-05 13:07:13 -05:00
Ben Noordhuis
c8583bbdf1
unix: simplify uv__cloexec_fcntl() (#3492)
FD_CLOEXEC is the only defined flag for fcntl(F_SETFD) so don't bother
getting the status of that flag first with fcntl(F_GETFD), just set it.
2022-03-05 12:55:49 -05:00
roflcopter4
8e67d8b364
win,poll: add the MSAFD GUID for AF_UNIX (#3511)
Enables the "fast poll" mechanism for the new(ish) Unix sockets in
Windows 10.
2022-03-05 12:54:41 -05:00
Jameson Nash
6ac063d10e
process: only use F_DUPFD_CLOEXEC if it is defined (#3512)
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).
2022-03-05 12:52:04 -05:00
Ben Noordhuis
fd34b17f90
zos: fix build breakage (#3513)
Introduced earlier today in commit f250c6c7. _SC_NPROCESSORS_ONLN does
not seem to be defined on that platform.
2022-03-05 10:12:26 +01:00
Jameson Nash
60fbcad9ac
process: remove OpenBSD from kevent list (#3506)
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
2022-03-04 21:38:31 -05:00
Ben Noordhuis
f250c6c73e
unix,win: add uv_available_parallelism() (#3499)
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.
2022-03-04 22:35:14 +01:00
ssrlive
c40f8cb9f8
android: fix build error when no ifaddrs.h (#3505) 2022-03-03 13:18:28 +01:00
Jameson Nash
83efa3dd71
Reland "macos: use posix_spawn instead of fork" (#3257)
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.
2022-03-02 15:15:39 -05:00
Guilherme Íscaro
56e279021f
test: use closefd in runner-unix.c (#3497)
This commit changes the plain close calls to
the closefd function, which will properly check if
close() returns an error.
2022-02-27 11:49:58 +01:00
David CARLIER
993e9ebd07
freebsd: use copy_file_range() in uv_fs_sendfile() (#3496)
Use copy_file_range() on FreeBSD 13 and above.
2022-02-27 11:49:29 +01:00
Vittore F. Scolari
7ae0c9543d
hurd: unbreak build on GNU/Hurd (#3450)
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
2022-02-23 12:04:18 -05:00
Jameson Nash
f3e0bffcb1
core: change uv_get_password uid/gid to unsigned (#3476)
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).
2022-02-22 10:59:06 -05:00
wyckster
c2a345fa67
doc: checkout -> check out (#3489)
"check out" is a verb phrase, but "checkout" is a noun. Since it is
being used as a verb, the spelling "check out" is required.
2022-02-22 10:58:43 -05:00
Ben Noordhuis
e0a5f58d2c
test: fix ipc_send_recv_pipe flakiness (#3478)
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.
2022-02-20 12:17:13 +01:00
Santiago Gimeno
2bc22c40eb test: fix flaky udp_mmsg test
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
2022-02-17 17:34:36 +01:00
Jameson Nash
d54c92e3e6
win: fix style nits [NFC] (#3474)
Internal functions usually have a uv__ prefix.
2022-02-15 10:13:24 -05:00
Ben Noordhuis
d41a9a07e4
doc: clarify android api level (#3480)
Google goes to great lengths to obscure the relationship between the two
so explicitly call out the API version matching Android 7.0.
2022-02-15 10:10:22 -05:00
Jameson Nash
cc7dbaa3a1
fix oopsie from #3466 (#3475)
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
2022-02-14 13:37:05 -05:00
Jameson Nash
3b2c25d223
win,fs: avoid closing an invalid handle (#3473)
While usually functional, calling CloseHandle(INVALID_HANDLE_VALUE) can
result in debug builds (and/or wine) being unhappy and aborting there.
2022-02-14 12:29:47 -05:00
twosee
0209466496
win,loop: add missing uv_update_time (#3175)
Time of loop should be updated after the IOCP wait.
2022-02-14 11:40:42 -05:00
Paul Evans
722d003076
document the values of enum uv_stdio_flags (#3039)
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
2022-02-14 11:37:19 -05:00
Momtchil Momtchev
df78de04e4
win,fs: consider broken pipe error a normal EOF (#3053)
This would later get translated in src/win/error.c this way, which
previously could lead to rather confusing and inaccurate error messages.
2022-02-13 01:40:10 -05:00
Ryan Liptak
912bb8c577
test: fix benchmark-ping-udp (#2817)
- 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)
2022-02-13 01:04:41 -05:00
UMU
8ec1732af0
build: fix error C4146 on MSVC (#3271)
> error C4146: unary minus operator applied to unsigned type, result still unsigned
2022-02-13 00:57:43 -05:00
Momtchil Momtchev
636cb8633b
bench: add uv_queue_work ping-pong measurement (#3425) 2022-02-13 00:40:35 -05:00
Darshan Sen
04a35efe69
win,errors: remap ERROR_ACCESS_DENIED to UV_EACCES (#3193)
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.
2022-02-13 00:31:59 -05:00
jonilaitinen
cf7f70c25d
win: restrict system DLL load paths (#3395)
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.
2022-02-13 00:26:55 -05:00
Jameson Nash
d0e500c876
win: use GetTickCount64 for uptime again (#3470)
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).
2022-02-13 00:24:34 -05:00
Jameson Nash
939a05633f
loop: add pending work to loop-alive check (#3466)
Pending work may be either (on any platform) pending_queue callbacks or
(on unix) watcher_queue handles to add to the io poll object.
Previously, we might have gotten somewhat stuck if the user caused an
event to be added to one of these in the idle or prepare callbacks, or
was embedding libuv.

Refs: https://github.com/libuv/libuv/pull/3234
Refs: https://github.com/libuv/libuv/issues/3101
Refs: https://github.com/libuv/libuv/pull/3308
2022-02-13 00:12:11 -05:00
WenTao Ou
7a68f5ab4b
build: export uv_a for cmake (#3373) 2022-02-08 11:43:19 -05:00
Luca Adrian L
50c1d00839
win: return fractional seconds in uv_uptime() (#3455)
Some systems return fractional seconds, some return full seconds.
On Windows uptime was artificially rounded down.

Fixes #3447.
2022-02-08 14:23:39 +01:00
Ben Noordhuis
de24da8c11
darwin: bump minimum supported version to 10.15 (#3406)
We can't realistically claim to support 10.7 or any version that Apple
no longer supports so let's bump the baseline to something more
realistic.

Refs: https://github.com/libuv/libuv/pull/482
Refs: https://github.com/libuv/libuv/pull/3405
2022-02-08 14:18:29 +01:00
Ben Noordhuis
038086dc08
test: remove flaky test ipc_closed_handle (#3464)
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.
2022-02-08 14:18:10 +01:00
Jameson Nash
953f901dd2
process,bsd: handle kevent NOTE_EXIT failure (#3451)
The kernel may return ESRCH if the child has already exited here.
This is rather annoying, and means we must indirectly handle
notification to our event loop of the process exit.

Refs: https://github.com/libuv/libuv/pull/3441
Refs: https://github.com/libuv/libuv/pull/3257
2022-02-01 15:27:12 -05:00
woclass
870828c8af
doc/guide: update content and sample code (#3408)
- 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>
2022-01-31 16:52:42 -05:00
Jameson Nash
930af43437
build: rename CFLAGS to AM_CFLAGS (#3431)
The CFLAGS variable is reserved and should never be set:
https://www.gnu.org/software/automake/manual/html_node/User-Variables.html
2022-01-31 16:50:32 -05:00
ssrlive
cdced3a3ad
thread,win: fix C90 style nit (#3393) 2022-01-31 16:49:01 -05:00
Jameson Nash
125da33f82
build: fix cmake install locations (#3415)
Adds static libraries and DLL import libraries, as well as making sure
the DLLs go to the correct folder.

Closes #3414
2022-01-31 16:25:20 -05:00
Momtchil Momtchev
e89abc80ea
test: fix flaky uv_fs_lutime test (#3424)
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.
2022-01-31 16:25:05 -05:00
Jeremy Rose
d9e90857f0
process: monitor for exit with kqueue on BSDs (#3441)
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
2022-01-31 14:49:22 -05:00
Jiawen Geng
bb0b4bb783
doc: add gengjiawen as maintainer (#3430) 2022-01-20 22:08:14 +08:00
Ben Noordhuis
e43eb667b5
bsd: ensure mutex is initialized (#3428)
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
2022-01-17 12:55:41 +01:00
Ben Noordhuis
b5fa965bcb
unix: don't allow too small thread stack size (#3423)
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.
2022-01-17 09:36:26 +01:00
Ondřej Surý
d5ed7f1256 test: test with maximum recvmmsg buffer (#3419)
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.
2022-01-15 06:24:37 +01:00
Ondřej Surý
e9cb18484e unix: ensure struct msghdr is zeroed in recvmmsg (#3419)
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
2022-01-15 06:24:37 +01:00
Jessica Clarke
2fbfa0358b
unix: fix STATIC_ASSERT to check what it means to check (#3417)
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.
2022-01-13 06:20:14 +01:00
Ben Noordhuis
c8cbdbd2c4
android: use libc getifaddrs() (#3412)
Fixes: https://github.com/libuv/libuv/issues/3411
2022-01-13 05:55:25 +01:00
Ben Noordhuis
3a7b95593a
darwin: translate EPROTOTYPE to ECONNRESET (#3413)
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
2022-01-12 16:11:43 +01:00
David Machaj
a3e02e5e4a
win: replace CRITICAL_SECTION+Semaphore with SRWLock (#3383)
Fixes: https://github.com/libuv/libuv/issues/3382
2022-01-12 16:07:17 +01:00
Colin Ihrig
2e42847f4e
doc: fix v1.43.0 changelog entries
PR-URL: https://github.com/libuv/libuv/pull/3407
2022-01-09 19:51:43 -05:00
Ben Noordhuis
abb109f30f
darwin: remove EPROTOTYPE error workaround (#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
2022-01-09 12:20:15 +01:00
cjihrig
bb6248bca4
Now working on version 1.43.1
Fixes: https://github.com/libuv/libuv/issues/3397
2022-01-04 09:27:20 -05:00
cjihrig
2c31ecb8fa
Add SHA to ChangeLog 2022-01-04 09:18:00 -05:00
373 changed files with 24878 additions and 15749 deletions

7
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,7 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

23
.github/stale.yml vendored
View File

@ -1,23 +0,0 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 28
# Number of days of inactivity before a stale issue is closed
# Set to false to disable. If disabled, issues still need to be closed
# manually, but will remain marked as stale.
daysUntilClose: false
# Issues with these labels will never be considered stale
exemptLabels:
- v2
- enhancement
- good first issue
- feature-request
- doc
- bug
- not-stale
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. Thank you for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false

25
.github/workflows/CI-docs.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: CI-docs
on:
pull_request:
paths:
- 'docs/**'
- '!docs/code/**'
- '.github/workflows/CI-docs.yml'
jobs:
docs-src:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
cache: 'pip' # caching pip dependencies
- run: pip install -r docs/requirements.txt
- name: html
run: |
make -C docs html
- name: linkcheck
run: |
make -C docs linkcheck

33
.github/workflows/CI-sample.yml vendored Normal file
View File

@ -0,0 +1,33 @@
name: ci-sample
on:
pull_request:
paths:
- '**'
- '!docs/**'
- '!.**'
- 'docs/code/**'
- '.github/workflows/CI-sample.yml'
push:
branches:
- v[0-9].*
- master
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
- name: setup
run: cmake -E make_directory ${{runner.workspace}}/libuv/docs/code/build
- name: configure
# you may like use Ninja on unix-like OS, but for windows, the only easy way is to use Visual Studio if you want Ninja
run: cmake ..
working-directory: ${{runner.workspace}}/libuv/docs/code/build
- name: build
run: cmake --build .
working-directory: ${{runner.workspace}}/libuv/docs/code/build

182
.github/workflows/CI-unix.yml vendored Normal file
View File

@ -0,0 +1,182 @@
name: CI-unix
on:
pull_request:
paths:
- '**'
- '!docs/**'
- '!src/win/**'
- '!.**'
- '.github/workflows/CI-unix.yml'
push:
branches:
- v[0-9].*
- master
jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: configure
run: |
./autogen.sh
mkdir build
(cd build && ../configure)
- name: distcheck
run: |
make -C build distcheck
build-android:
runs-on: ubuntu-latest
env:
ANDROID_AVD_HOME: /root/.android/avd
steps:
- uses: actions/checkout@v4
- name: Envinfo
run: npx envinfo
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Build and Test
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 30
arch: x86_64
target: google_apis
ram-size: 2048M
emulator-options: -no-audio -no-window -gpu off -no-boot-anim -netdelay none -netspeed full -writable-system -no-snapshot-save -no-snapshot-load -no-snapshot
disable-animations: true
script: |
echo "::group::Configure"
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI="x86_64" -DANDROID_PLATFORM=android-30
echo "::endgroup::"
echo "::group::Build"
cmake --build build
## Correct some ld bugs that cause problems with libuv tests
wget "https://github.com/termux/termux-elf-cleaner/releases/download/v2.2.1/termux-elf-cleaner" -P build
chmod a+x build/termux-elf-cleaner
build/termux-elf-cleaner --api-level 30 ./build/uv_run_tests
build/termux-elf-cleaner --api-level 30 ./build/uv_run_tests_a
adb shell "su 0 setenforce 0" # to allow some syscalls like link, chmod, etc.
## Push the build and test fixtures to the device
adb push build /data/local/tmp
adb shell mkdir /data/local/tmp/build/test
adb push test/fixtures /data/local/tmp/build/test
echo "::endgroup::"
## Run the tests
file build/uv_run_tests_a
adb shell "cd /data/local/tmp/build && env UV_TEST_TIMEOUT_MULTIPLIER=5 ./uv_run_tests_a"
build-macos:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-13, macos-14]
steps:
- uses: actions/checkout@v4
- name: Envinfo
run: npx envinfo
- name: Disable Firewall
run: |
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 0
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
- name: Setup
run: |
brew install ninja automake libtool
- name: Configure
run: |
mkdir build
cd build
cmake .. -DBUILD_TESTING=ON -G Ninja
- name: Build
run: |
cmake --build build
ls -lh
- name: platform_output
run: |
./build/uv_run_tests platform_output
- name: platform_output_a
run: |
./build/uv_run_tests_a platform_output
- name: Test
run: |
cd build && ctest -V
- name: Autotools configure
if: always()
run: |
./autogen.sh
mkdir build-auto
(cd build-auto && ../configure)
make -C build-auto -j4
build-ios:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-13, macos-14]
steps:
- uses: actions/checkout@v4
- name: Configure
run: |
mkdir build-ios
cd build-ios
cmake .. -GXcode -DCMAKE_SYSTEM_NAME:STRING=iOS -DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED:BOOL=NO -DCMAKE_CONFIGURATION_TYPES:STRING=Release
- name: Build
run: |
cmake --build build-ios
ls -lh build-ios
build-cross-qemu:
runs-on: ubuntu-24.04
name: build-cross-qemu-${{ matrix.config.target }}
strategy:
fail-fast: false
matrix:
config:
- {target: arm, toolchain: gcc-arm-linux-gnueabi, cc: arm-linux-gnueabi-gcc, qemu: qemu-arm }
- {target: armhf, toolchain: gcc-arm-linux-gnueabihf, cc: arm-linux-gnueabihf-gcc, qemu: qemu-arm }
- {target: aarch64, toolchain: gcc-aarch64-linux-gnu, cc: aarch64-linux-gnu-gcc, qemu: qemu-aarch64 }
- {target: riscv64, toolchain: gcc-riscv64-linux-gnu, cc: riscv64-linux-gnu-gcc, qemu: qemu-riscv64 }
- {target: ppc, toolchain: gcc-powerpc-linux-gnu, cc: powerpc-linux-gnu-gcc, qemu: qemu-ppc }
- {target: ppc64, toolchain: gcc-powerpc64-linux-gnu, cc: powerpc64-linux-gnu-gcc, qemu: qemu-ppc64 }
- {target: ppc64le, toolchain: gcc-powerpc64le-linux-gnu, cc: powerpc64le-linux-gnu-gcc, qemu: qemu-ppc64le }
- {target: s390x, toolchain: gcc-s390x-linux-gnu, cc: s390x-linux-gnu-gcc, qemu: qemu-s390x }
- {target: mips, toolchain: gcc-mips-linux-gnu, cc: mips-linux-gnu-gcc, qemu: qemu-mips }
- {target: mips64, toolchain: gcc-mips64-linux-gnuabi64, cc: mips64-linux-gnuabi64-gcc, qemu: qemu-mips64 }
- {target: mipsel, toolchain: gcc-mipsel-linux-gnu, cc: mipsel-linux-gnu-gcc, qemu: qemu-mipsel }
- {target: mips64el, toolchain: gcc-mips64el-linux-gnuabi64, cc: mips64el-linux-gnuabi64-gcc,qemu: qemu-mips64el }
- {target: arm (u64 slots), toolchain: gcc-arm-linux-gnueabi, cc: arm-linux-gnueabi-gcc, qemu: qemu-arm }
- {target: aarch64 (u64 slots), toolchain: gcc-aarch64-linux-gnu, cc: aarch64-linux-gnu-gcc, qemu: qemu-aarch64 }
- {target: ppc (u64 slots), toolchain: gcc-powerpc-linux-gnu, cc: powerpc-linux-gnu-gcc, qemu: qemu-ppc }
- {target: ppc64 (u64 slots), toolchain: gcc-powerpc64-linux-gnu, cc: powerpc64-linux-gnu-gcc, qemu: qemu-ppc64 }
steps:
- uses: actions/checkout@v4
- name: Install qemu and ${{ matrix.config.toolchain }}
run: |
sudo apt update
sudo apt install qemu-user qemu-user-binfmt ${{ matrix.config.toolchain }} -y
- name: Configure with ${{ matrix.config.cc }}
run: |
mkdir build
cd build
cmake .. -DBUILD_TESTING=ON -DQEMU=ON -DCMAKE_C_COMPILER=${{ matrix.config.cc }}
- name: Build
run: |
cmake --build build
ls -lh build
- name: Test
run: |
${{ matrix.config.qemu }} build/uv_run_tests_a

129
.github/workflows/CI-win.yml vendored Normal file
View File

@ -0,0 +1,129 @@
name: CI-win
on:
pull_request:
paths:
- '**'
- '!docs/**'
- '!src/unix/**'
- '!.**'
- '.github/workflows/CI-win.yml'
push:
branches:
- v[0-9].*
- master
jobs:
build-windows:
runs-on: windows-${{ matrix.config.server }}
name: build-${{ join(matrix.config.*, '-') }}
strategy:
fail-fast: false
matrix:
config:
- {toolchain: Visual Studio 16 2019, arch: Win32, server: 2019}
- {toolchain: Visual Studio 16 2019, arch: x64, server: 2019}
- {toolchain: Visual Studio 17 2022, arch: Win32, server: 2022}
- {toolchain: Visual Studio 17 2022, arch: x64, server: 2022}
- {toolchain: Visual Studio 17 2022, arch: x64, server: 2022, config: ASAN}
- {toolchain: Visual Studio 17 2022, arch: x64, server: 2022, config: UBSAN}
- {toolchain: Visual Studio 17 2022, arch: arm64, server: 2022}
steps:
- uses: actions/checkout@v4
- name: Build
run:
cmake -S . -B build -DBUILD_TESTING=ON
-G "${{ matrix.config.toolchain }}" -A ${{ matrix.config.arch }}
${{ matrix.config.config == 'ASAN' && '-DASAN=on -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded' || '' }}
cmake --build build --config RelWithDebInfo
${{ matrix.config.config == 'ASAN' && 'Copy-Item -Path "build\\*.exe" -Destination "build\\RelWithDebInfo\\"' || '' }}
${{ matrix.config.config == 'ASAN' && 'Copy-Item -Path "build\\*.dll" -Destination "build\\RelWithDebInfo\\"' || '' }}
ls -l build
ls -l build\\RelWithDebInfo
- name: platform_output_a
if: ${{ matrix.config.arch != 'arm64' }}
shell: cmd
run:
build\\RelWithDebInfo\\uv_run_tests_a.exe platform_output
- name: platform_output
if: ${{ matrix.config.arch != 'arm64' }}
shell: cmd
run:
build\\RelWithDebInfo\\uv_run_tests.exe platform_output
- name: Test
# only valid with libuv-master with the fix for
# https://github.com/libuv/leps/blob/master/005-windows-handles-not-fd.md
if: ${{ matrix.config.config != 'ASAN' && matrix.config.arch != 'arm64' }}
shell: cmd
run:
cd build
ctest -C RelWithDebInfo -V
- name: Test only static
if: ${{ matrix.config.config == 'ASAN' && matrix.config.arch != 'arm64' }}
shell: cmd
run:
build\\RelWithDebInfo\\uv_run_tests_a.exe
build-mingw:
runs-on: ubuntu-latest
name: build-mingw-${{ matrix.config.arch }}
strategy:
fail-fast: false
matrix:
config:
- {arch: i686, server: 2022, libgcc: dw2 }
- {arch: x86_64, server: 2022, libgcc: seh }
steps:
- uses: actions/checkout@v4
- name: Install mingw32 environment
run: |
sudo apt update
sudo apt install mingw-w64 ninja-build -y
- name: Build
run: |
cmake -S . -B build -G Ninja -DHOST_ARCH=${{ matrix.config.arch }} -DBUILD_TESTING=ON -DCMAKE_TOOLCHAIN_FILE=cmake-toolchains/cross-mingw32.cmake
cmake --build build
cmake --install build --prefix "`pwd`/build/usr"
mkdir -p build/usr/test build/usr/bin
cp -av test/fixtures build/usr/test
cp -av build/uv_run_tests_a.exe build/uv_run_tests.exe build/uv_run_tests_a_no_ext build/uv_run_tests_no_ext \
`${{ matrix.config.arch }}-w64-mingw32-gcc -print-file-name=libgcc_s_${{ matrix.config.libgcc }}-1.dll` \
`${{ matrix.config.arch }}-w64-mingw32-gcc -print-file-name=libwinpthread-1.dll` \
`${{ matrix.config.arch }}-w64-mingw32-gcc -print-file-name=libatomic-1.dll` \
build/usr/bin
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: mingw-${{ matrix.config.arch }}
path: build/usr/**/*
retention-days: 2
test-mingw:
runs-on: windows-${{ matrix.config.server }}
name: test-mingw-${{ matrix.config.arch }}
needs: build-mingw
strategy:
fail-fast: false
matrix:
config:
- {arch: i686, server: 2022}
- {arch: x86_64, server: 2022}
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: mingw-${{ matrix.config.arch }}
- name: Test
shell: cmd
run: |
bin\uv_run_tests_a.exe
- name: Test
shell: cmd
run: |
bin\uv_run_tests.exe

View File

@ -1,118 +0,0 @@
name: CI
on: [push, pull_request]
jobs:
build-windows:
runs-on: windows-${{ matrix.config.server }}
name: build-${{ matrix.config.toolchain}}-${{ matrix.config.arch}}
strategy:
fail-fast: false
matrix:
config:
- {toolchain: Visual Studio 15 2017, arch: Win32, server: 2016}
- {toolchain: Visual Studio 15 2017, arch: x64, server: 2016}
- {toolchain: Visual Studio 16 2019, arch: Win32, server: 2019}
- {toolchain: Visual Studio 16 2019, arch: x64, server: 2019}
- {toolchain: Visual Studio 17 2022, arch: Win32, server: 2022}
- {toolchain: Visual Studio 17 2022, arch: x64, server: 2022}
steps:
- uses: actions/checkout@v2
- name: Envinfo
run: npx envinfo
- name: Build
shell: cmd
run: |
mkdir -p build
cd build
cmake .. -DBUILD_TESTING=ON -G "${{ matrix.config.toolchain }}" -A ${{ matrix.config.arch }}
cmake --build .
- name: Test
shell: cmd
run: |
cd build
ctest -C Debug --output-on-failure
build-android:
runs-on: ubuntu-latest
container: reactnativecommunity/react-native-android:2020-5-20
steps:
- uses: actions/checkout@v2
- name: Envinfo
run: npx envinfo
- name: Build android arm64
# see build options you can use in https://developer.android.com/ndk/guides/cmake
run: |
mkdir build && cd build
$ANDROID_HOME/cmake/3.10.2.4988404/bin/cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/20.0.5594570/build/cmake/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI="arm64-v8a" -DANDROID_PLATFORM=android-21 ..
$ANDROID_HOME/cmake/3.10.2.4988404/bin/cmake --build .
build-macos:
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
- name: Envinfo
run: npx envinfo
- name: Setup
run: |
brew install ninja
- name: Build
run: |
mkdir build
cd build && cmake .. -DBUILD_TESTING=ON -G Ninja
cmake --build .
ls -lh
- name: Test
run: |
cd build && ctest -V
build-cross-qemu:
runs-on: ubuntu-latest
name: build-cross-qemu-${{ matrix.config.target }}
strategy:
fail-fast: false
matrix:
config:
- {target: arm, toolchain: gcc-arm-linux-gnueabi, cc: arm-linux-gnueabi-gcc, qemu: qemu-arm-static }
- {target: armhf, toolchain: gcc-arm-linux-gnueabihf, cc: arm-linux-gnueabihf-gcc, qemu: qemu-arm-static }
- {target: aarch64, toolchain: gcc-aarch64-linux-gnu, cc: aarch64-linux-gnu-gcc, qemu: qemu-aarch64-static }
- {target: riscv64, toolchain: gcc-riscv64-linux-gnu, cc: riscv64-linux-gnu-gcc, qemu: qemu-riscv64-static }
- {target: ppc, toolchain: gcc-powerpc-linux-gnu, cc: powerpc-linux-gnu-gcc, qemu: qemu-ppc-static }
- {target: ppc64, toolchain: gcc-powerpc64-linux-gnu, cc: powerpc64-linux-gnu-gcc, qemu: qemu-ppc64-static }
- {target: ppc64le, toolchain: gcc-powerpc64le-linux-gnu, cc: powerpc64le-linux-gnu-gcc, qemu: qemu-ppc64le-static }
- {target: s390x, toolchain: gcc-s390x-linux-gnu, cc: s390x-linux-gnu-gcc, qemu: qemu-s390x-static }
- {target: mips, toolchain: gcc-mips-linux-gnu, cc: mips-linux-gnu-gcc, qemu: qemu-mips-static }
- {target: mips64, toolchain: gcc-mips64-linux-gnuabi64, cc: mips64-linux-gnuabi64-gcc, qemu: qemu-mips64-static }
- {target: mipsel, toolchain: gcc-mipsel-linux-gnu, cc: mipsel-linux-gnu-gcc, qemu: qemu-mipsel-static }
- {target: mips64el,toolchain: gcc-mips64el-linux-gnuabi64, cc: mips64el-linux-gnuabi64-gcc,qemu: qemu-mips64el-static }
- {target: alpha, toolchain: gcc-alpha-linux-gnu, cc: alpha-linux-gnu-gcc, qemu: qemu-alpha-static }
- {target: arm (u64 slots), toolchain: gcc-arm-linux-gnueabi, cc: arm-linux-gnueabi-gcc, qemu: qemu-arm-static}
- {target: aarch64 (u64 slots), toolchain: gcc-aarch64-linux-gnu, cc: aarch64-linux-gnu-gcc, qemu: qemu-aarch64-static}
- {target: ppc (u64 slots), toolchain: gcc-powerpc-linux-gnu, cc: powerpc-linux-gnu-gcc, qemu: qemu-ppc-static}
- {target: ppc64 (u64 slots), toolchain: gcc-powerpc64-linux-gnu, cc: powerpc64-linux-gnu-gcc, qemu: qemu-ppc64-static}
steps:
- uses: actions/checkout@v2
- name: Install QEMU
# this ensure install latest qemu on ubuntu, apt get version is old
env:
QEMU_SRC: "http://archive.ubuntu.com/ubuntu/pool/universe/q/qemu"
QEMU_VER: "qemu-user-static_4\\.2-.*_amd64.deb$"
run: |
DEB=`curl -s $QEMU_SRC/ | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | grep $QEMU_VER | tail -1`
wget $QEMU_SRC/$DEB
sudo dpkg -i $DEB
- name: Install ${{ matrix.config.toolchain }}
run: |
sudo apt update
sudo apt install ${{ matrix.config.toolchain }} -y
- name: Build
run: |
mkdir build
cd build && cmake .. -DBUILD_TESTING=ON -DQEMU=ON -DCMAKE_C_COMPILER=${{ matrix.config.cc }}
cmake --build .
ls -lh
- name: Test
run: |
${{ matrix.config.qemu }} build/uv_run_tests_a

View File

@ -1,26 +1,128 @@
name: Sanitizer checks
on: [push, pull_request]
on:
pull_request:
paths:
- '**'
- '!docs/**'
- '!.**'
- '.github/workflows/sanitizer.yml'
push:
branches:
- v[0-9].*
- master
jobs:
sanitizers:
runs-on: ubuntu-latest
sanitizers-linux:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup
run: |
sudo apt-get install ninja-build
- name: Envinfo
run: npx envinfo
- name: TSAN
# [AM]SAN fail on newer kernels due to a bigger PIE slide
- name: Disable ASLR
run: |
mkdir build-tsan
(cd build-tsan && cmake .. -G Ninja -DBUILD_TESTING=ON -DTSAN=ON -DCMAKE_BUILD_TYPE=Release)
cmake --build build-tsan
./build-tsan/uv_run_tests_a || true # currently permit failures
- name: ASAN
sudo sysctl -w kernel.randomize_va_space=0
- name: ASAN Build
run: |
mkdir build-asan
(cd build-asan && cmake .. -G Ninja -DBUILD_TESTING=ON -DASAN=ON -DCMAKE_BUILD_TYPE=Debug)
cmake --build build-asan
- name: ASAN Test
run: |
./build-asan/uv_run_tests_a
- name: MSAN Build
run: |
mkdir build-msan
(cd build-msan && cmake .. -G Ninja -DBUILD_TESTING=ON -DMSAN=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang)
cmake --build build-msan
- name: MSAN Test
run: |
./build-msan/uv_run_tests_a
- name: TSAN Build
run: |
mkdir build-tsan
(cd build-tsan && cmake .. -G Ninja -DBUILD_TESTING=ON -DTSAN=ON -DCMAKE_BUILD_TYPE=Release)
cmake --build build-tsan
- name: TSAN Test
# Note: path must be absolute because some tests chdir.
# TSan exits with an error when it can't find the file.
run: |
env TSAN_OPTIONS="suppressions=$PWD/tsansupp.txt" ./build-tsan/uv_run_tests_a
- name: UBSAN Build
run: |
mkdir build-ubsan
(cd build-ubsan && cmake .. -G Ninja -DBUILD_TESTING=ON -DUBSAN=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang)
cmake --build build-ubsan
- name: UBSAN Test
run: |
./build-ubsan/uv_run_tests_a
sanitizers-macos:
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- name: Envinfo
run: npx envinfo
- name: ASAN Build
run: |
mkdir build-asan
(cd build-asan && cmake .. -DBUILD_TESTING=ON -DASAN=ON -DCMAKE_BUILD_TYPE=Debug)
cmake --build build-asan
- name: ASAN Test
run: |
./build-asan/uv_run_tests_a
- name: TSAN Build
run: |
mkdir build-tsan
(cd build-tsan && cmake .. -DBUILD_TESTING=ON -DTSAN=ON -DCMAKE_BUILD_TYPE=Release)
cmake --build build-tsan
- name: TSAN Test
run: |
./build-tsan/uv_run_tests_a
- name: UBSAN Build
run: |
mkdir build-ubsan
(cd build-ubsan && cmake .. -DBUILD_TESTING=ON -DUBSAN=ON -DCMAKE_BUILD_TYPE=Debug)
cmake --build build-ubsan
- name: UBSAN Test
run: |
./build-ubsan/uv_run_tests_a
sanitizers-windows:
runs-on: windows-2022
steps:
- uses: actions/checkout@v4
- name: Setup
run: |
choco install ninja
# Note: clang shipped with VS2022 has an issue where the UBSAN runtime doesn't link.
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v2
with:
version: "17"
- name: Envinfo
run: npx envinfo
- name: UBSAN Build
run: |
mkdir build-ubsan
cmake -B build-ubsan -G Ninja -DBUILD_TESTING=ON -DUBSAN=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang
cmake --build build-ubsan
- name: UBSAN Test
run: |
./build-ubsan/uv_run_tests_a

4
.gitignore vendored
View File

@ -7,9 +7,11 @@
*.sdf
*.suo
.vs/
.vscode/
*.VC.db
*.VC.opendb
core
.cache
vgcore.*
.buildstamp
.dirstamp
@ -74,3 +76,5 @@ cmake-build-debug/
# make dist output
libuv-*.tar.*
/dist.libuv.org/
/libuv-release-tool/

View File

@ -4,6 +4,7 @@ Aaron Bieber <qbit@deftly.net> <deftly@gmail.com>
Alan Gutierrez <alan@prettyrobots.com> <alan@blogometer.com>
Andrius Bentkus <andrius.bentkus@gmail.com> <toxedvirus@gmail.com>
Andy Fiddaman <andy@omniosce.org> <omnios@citrus-it.co.uk>
Andy Pan <panjf2000@gmail.com> <i@andypan.me>
Bert Belder <bertbelder@gmail.com> <i@bertbelder.com>
Bert Belder <bertbelder@gmail.com> <info@2bs.nl>
Bert Belder <bertbelder@gmail.com> <user@ChrUbuntu.(none)>
@ -18,6 +19,7 @@ David Carlier <devnexen@gmail.com>
Devchandra Meetei Leishangthem <dlmeetei@gmail.com>
Fedor Indutny <fedor.indutny@gmail.com> <fedor@indutny.com>
Frank Denis <github@pureftpd.org>
Hüseyin Açacak <110401522+huseyinacacak-janea@users.noreply.github.com> <huseyin@janeasystems.com>
Imran Iqbal <imrani@ca.ibm.com> <imran@imraniqbal.org>
Isaac Z. Schlueter <i@izs.me>
Jason Williams <necmon@yahoo.com>
@ -29,6 +31,7 @@ Keno Fischer <kenof@stanford.edu> <kfischer+github@college.harvard.edu>
Keno Fischer <kenof@stanford.edu> <kfischer@college.harvard.edu>
Leith Bade <leith@leithalweapon.geek.nz> <leith@mapbox.com>
Leonard Hecker <leonard.hecker91@gmail.com> <leonard@hecker.io>
Lewis Russell <me@lewisr.dev> <lewis6991@gmail.com>
Maciej Małecki <maciej.malecki@notimplemented.org> <me@mmalecki.com>
Marc Schlaich <marc.schlaich@googlemail.com> <marc.schlaich@gmail.com>
Michael <michael_dawson@ca.ibm.com>
@ -36,6 +39,7 @@ Michael Neumann <mneumann@think.localnet> <mneumann@ntecs.de>
Michael Penick <michael.penick@datastax.com> <mpenick@users.noreply.github.com>
Nicholas Vavilov <vvnicholas@gmail.com>
Nick Logan <ugexe@cpan.org> <nlogan@gmail.com>
Olivier Valentin <ovalenti@redhat.com> <valentio@free.fr>
Rasmus Christian Pedersen <zerhacken@yahoo.com>
Rasmus Christian Pedersen <zerhacken@yahoo.com> <ruysch@outlook.com>
Richard Lau <rlau@redhat.com> <riclau@uk.ibm.com>
@ -46,7 +50,8 @@ Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Sam Roberts <vieuxtech@gmail.com> <sam@strongloop.com>
San-Tai Hsu <vanilla@fatpipi.com>
Santiago Gimeno <santiago.gimeno@quantion.es> <santiago.gimeno@gmail.com>
Saúl Ibarra Corretgé <saghul@gmail.com>
Saúl Ibarra Corretgé <s@saghul.net>
Saúl Ibarra Corretgé <s@saghul.net> <saghul@gmail.com>
Saúl Ibarra Corretgé <saghul@gmail.com> <s@saghul.net>
Shigeki Ohtsu <ohtsu@iij.ad.jp> <ohtsu@ohtsu.org>
Shuowang (Wayne) Zhang <shuowang.zhang@ibm.com>
@ -60,5 +65,7 @@ gengjiawen <technicalcute@gmail.com>
jBarz <jBarz@users.noreply.github.com> <jbarboza@ca.ibm.com>
jBarz <jBarz@users.noreply.github.com> <jbarz@users.noreply.github.com>
ptlomholt <pt@lomholt.com>
theanarkh <2923878201@qq.com> <theratliter@gmail.com>
tjarlama <59913901+tjarlama@users.noreply.github.com> <tjarlama@gmail.com>
ywave620 <rogertyang@tencent.com> <60539365+ywave620@users.noreply.github.com>
zlargon <zlargon1988@gmail.com>

View File

@ -2,10 +2,14 @@ version: 2
sphinx:
builder: html
configuration: null
configuration: docs/src/conf.py
fail_on_warning: false
build:
os: "ubuntu-22.04"
tools:
python: "3.9"
python:
version: 3.8
install:
- requirements: docs/requirements.txt

96
AUTHORS
View File

@ -496,3 +496,99 @@ Jesper Storm Bache <jsbache@users.noreply.github.com>
Campbell He <duskmoon314@users.noreply.github.com>
Andrey Hohutkin <andrey.hohutkin@gmail.com>
deal <halx99@live.com>
David Machaj <46852402+dmachaj@users.noreply.github.com>
Jessica Clarke <jrtc27@jrtc27.com>
Jeremy Rose <nornagon@nornagon.net>
woclass <git@wo-class.cn>
Luca Adrian L <info@lucalindhorst.de>
WenTao Ou <owt5008137@live.com>
jonilaitinen <joni.laitinen@iki.fi>
UMU <UMU618@users.noreply.github.com>
Paul Evans <leonerd@leonerd.org.uk>
wyckster <wyckster@hotmail.com>
Vittore F. Scolari <vittore.scolari@gmail.com>
roflcopter4 <15476346+roflcopter4@users.noreply.github.com>
V-for-Vasili <vasili.skurydzin@protonmail.com>
Denny C. Dai <dennycd@me.com>
Hannah Shi <hannahshisfb@gmail.com>
tuftedocelot <tuftedocelot@fastmail.fm>
blogdaren <blogdaren@163.com>
chucksilvers <chuq@chuq.com>
Sergey Fedorov <vital.had@gmail.com>
theanarkh <2923878201@qq.com>
Samuel Cabrero <samuelcabrero@gmail.com>
自发对称破缺 <429839446@qq.com>
Luan Devecchi <luan@engineer.com>
Steven Schveighoffer <schveiguy@gmail.com>
number201724 <number201724@me.com>
Daniel <reymond315qq@gmail.com>
Christian Clason <christian.clason@uni-due.de>
ywave620 <rogertyang@tencent.com>
jensbjorgensen <jbj1@ultraemail.net>
daomingq <daoming.qiu@intel.com>
Qix <Qix-@users.noreply.github.com>
Edward Humes <29870961+aurxenon@users.noreply.github.com>
Tim Besard <tim.besard@gmail.com>
Sergey Rubanov <chi187@gmail.com>
Stefan Stojanovic <StefanStojanovic@users.noreply.github.com>
Zvicii <zvicii@qq.com>
dundargoc <33953936+dundargoc@users.noreply.github.com>
Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com>
panran <310762957@qq.com>
Tamás Bálint Misius <lbphacker@gmail.com>
Bruno Passeri <Varstahl@users.noreply.github.com>
Jason Zhang <xzha4350@gmail.com>
Lewis Russell <me@lewisr.dev>
sivadeilra <arlie.davis@gmail.com>
cui fliter <imcusg@gmail.com>
Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
Stefan Karpinski <stefan@karpinski.org>
liuxiang88 <94350585+liuxiang88@users.noreply.github.com>
Jeffrey H. Johnson <trnsz@pobox.com>
Abdirahim Musse <33973272+abmusse@users.noreply.github.com>
小明 <7737673+caobug@users.noreply.github.com>
Shuduo Sang <sangshuduo@gmail.com>
Keith Winstein <keithw@cs.stanford.edu>
michalbiesek <michalbiesek@gmail.com>
Alois Klink <alois@aloisklink.com>
SmorkalovG <smorkalov.g@gmail.com>
Pleuvens <pleuvens.fervil@gmail.com>
jolai <58589285+laijonathan@users.noreply.github.com>
Julien Roncaglia <fox@vbfox.net>
prubel <paul@rubels.net>
Per Allansson <65364157+per-allansson@users.noreply.github.com>
Matheus Izvekov <mizvekov@gmail.com>
Christian Heimlich <chris@pcserenity.com>
Hao Hu <33607772+hhu8@users.noreply.github.com>
matoro <12038583+matoro@users.noreply.github.com>
Bo Anderson <mail@boanderson.me>
Ardi Nugraha <33378542+ardi-nugraha@users.noreply.github.com>
Anton Bachin <antonbachin@yahoo.com>
Trevor Flynn <trevorflynn@liquidcrystalstudios.com>
Andy Pan <panjf2000@gmail.com>
Viacheslav Muravyev <slavamuravey@mail.ru>
Anthony Alayo <anthony.alayo@gmail.com>
Thomas Walter <31201229+waltoss@users.noreply.github.com>
hiiizxf <385122613@qq.com>
Geddy <guandichao@163.com>
Farzin Monsef <monseffarzin@gmail.com>
tgolang <154592711+tgolang@users.noreply.github.com>
josedelinux <josedelinux@hotmail.com>
Hüseyin Açacak <110401522+huseyinacacak-janea@users.noreply.github.com>
Uilian Ries <uilianries@gmail.com>
Olivier Valentin <ovalenti@redhat.com>
郑苏波 (Super Zheng) <superzheng@tencent.com>
zeertzjq <zeertzjq@outlook.com>
Ian Butterworth <i.r.butterworth@gmail.com>
握猫猫 <164346864@qq.com>
Zuohui Yang <274048862@qq.com>
Edigleysson Silva (Edy) <edigleyssonsilva@gmail.com>
Raihaan Shouhell <raihaanhimself@gmail.com>
Rialbat <miha-wead@mail.ru>
Adam <adam@NetBSD.org>
Poul T Lomholt <ptlomholt@users.noreply.github.com>
Thad House <ThadHouse@users.noreply.github.com>
Julian A Avar C <28635807+julian-a-avar-c@users.noreply.github.com>
amcgoogan <105525867+amcgoogan@users.noreply.github.com>
Rafael Gonzaga <rafael.nunu@hotmail.com>

View File

@ -1,8 +1,13 @@
cmake_minimum_required(VERSION 3.4)
project(libuv LANGUAGES C)
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0057 NEW) # Enable IN_LIST operator
cmake_policy(SET CMP0064 NEW) # Support if (TEST) operator
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW) # Enable MSVC_RUNTIME_LIBRARY setting
endif()
if(POLICY CMP0092)
cmake_policy(SET CMP0092 NEW) # disable /W3 warning, if possible
endif()
project(libuv LANGUAGES C)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
@ -17,9 +22,13 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_C_STANDARD 90)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(LIBUV_BUILD_SHARED "Build shared lib" ON)
cmake_dependent_option(LIBUV_BUILD_TESTS
"Build the unit tests when BUILD_TESTING is enabled and we are the root project" ON
"BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
"BUILD_TESTING;LIBUV_BUILD_SHARED;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
cmake_dependent_option(LIBUV_BUILD_BENCH
"Build the benchmarks when building unit tests and we are the root project" ON
"LIBUV_BUILD_TESTS" OFF)
@ -27,28 +36,66 @@ cmake_dependent_option(LIBUV_BUILD_BENCH
# Qemu Build
option(QEMU "build for qemu" OFF)
if(QEMU)
add_definitions(-D__QEMU__=1)
list(APPEND uv_defines __QEMU__=1)
endif()
# Note: these are mutually exclusive.
option(ASAN "Enable AddressSanitizer (ASan)" OFF)
option(MSAN "Enable MemorySanitizer (MSan)" OFF)
option(TSAN "Enable ThreadSanitizer (TSan)" OFF)
option(UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)
if((ASAN OR TSAN) AND NOT (CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang"))
message(SEND_ERROR "Sanitizer support requires clang or gcc. Try again with -DCMAKE_C_COMPILER.")
if(MSAN AND NOT CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang")
message(SEND_ERROR "MemorySanitizer requires clang. Try again with -DCMAKE_C_COMPILER=clang")
endif()
if(ASAN)
add_definitions(-D__ASAN__=1)
list(APPEND uv_defines __ASAN__=1)
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
elseif(MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fsanitize=address")
else()
message(SEND_ERROR "AddressSanitizer support requires clang, gcc, or msvc. Try again with -DCMAKE_C_COMPILER.")
endif()
endif()
if(MSAN)
list(APPEND uv_defines __MSAN__=1)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=memory")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=memory")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=memory")
endif()
if(TSAN)
add_definitions(-D__TSAN__=1)
list(APPEND uv_defines __TSAN__=1)
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
else()
message(SEND_ERROR "ThreadSanitizer support requires clang or gcc. Try again with -DCMAKE_C_COMPILER.")
endif()
endif()
if(UBSAN)
cmake_minimum_required(VERSION 3.13)
list(APPEND uv_defines __UBSAN__=1)
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang")
add_compile_options("-fsanitize=undefined" "-fno-sanitize-recover=undefined")
if (NOT WIN32)
add_link_options("-fsanitize=undefined")
endif()
if(MSVC)
add_compile_options("/Oy-")
else()
add_compile_options("-fno-omit-frame-pointer")
endif()
else()
message(SEND_ERROR "UndefinedBehaviorSanitizer support requires clang or gcc. Try again with -DCMAKE_C_COMPILER.")
endif()
endif()
# Compiler check
@ -119,12 +166,19 @@ list(APPEND uv_cflags ${lint-utf8-msvc} )
check_c_compiler_flag(-fno-strict-aliasing UV_F_STRICT_ALIASING)
list(APPEND uv_cflags $<$<BOOL:${UV_F_STRICT_ALIASING}>:-fno-strict-aliasing>)
if (MSVC)
# Error on calling undeclared functions.
list(APPEND uv_cflags "/we4013")
endif()
set(uv_sources
src/fs-poll.c
src/idna.c
src/inet.c
src/random.c
src/strscpy.c
src/strtok.c
src/thread-common.c
src/threadpool.c
src/timer.c
src/uv-common.c
@ -132,14 +186,17 @@ set(uv_sources
src/version.c)
if(WIN32)
list(APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0602)
list(APPEND uv_defines WIN32_LEAN_AND_MEAN _WIN32_WINNT=0x0A00 _CRT_DECLARE_NONSTDC_NAMES=0)
list(APPEND uv_libraries
psapi
user32
advapi32
iphlpapi
userenv
ws2_32)
ws2_32
dbghelp
ole32
shell32)
list(APPEND uv_sources
src/win/async.c
src/win/core.c
@ -215,16 +272,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Android")
list(APPEND uv_defines _GNU_SOURCE)
list(APPEND uv_libraries dl)
list(APPEND uv_sources
src/unix/android-ifaddrs.c
src/unix/linux-core.c
src/unix/linux-inotify.c
src/unix/linux-syscalls.c
src/unix/linux.c
src/unix/procfs-exepath.c
src/unix/pthread-fixes.c
src/unix/random-getentropy.c
src/unix/random-getrandom.c
src/unix/random-sysctl-linux.c
src/unix/epoll.c)
src/unix/random-sysctl-linux.c)
endif()
if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "Android|Linux")
@ -259,17 +311,26 @@ if(APPLE)
src/unix/fsevents.c)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "GNU")
list(APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112 _XOPEN_SOURCE=500)
list(APPEND uv_libraries dl)
list(APPEND uv_sources
src/unix/bsd-ifaddrs.c
src/unix/no-fsevents.c
src/unix/no-proctitle.c
src/unix/posix-hrtime.c
src/unix/posix-poll.c
src/unix/hurd.c)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND uv_defines _GNU_SOURCE _POSIX_C_SOURCE=200112)
list(APPEND uv_libraries dl rt)
list(APPEND uv_sources
src/unix/linux-core.c
src/unix/linux-inotify.c
src/unix/linux-syscalls.c
src/unix/linux.c
src/unix/procfs-exepath.c
src/unix/random-getrandom.c
src/unix/random-sysctl-linux.c
src/unix/epoll.c)
src/unix/random-sysctl-linux.c)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
@ -300,7 +361,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
list(APPEND uv_defines _XOPEN_SOURCE=600)
list(APPEND uv_defines _XOPEN_SOURCE_EXTENDED)
list(APPEND uv_sources
src/unix/pthread-fixes.c
src/unix/os390.c
src/unix/os390-syscalls.c
src/unix/os390-proctitle.c)
@ -338,6 +398,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS400")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
if(CMAKE_SYSTEM_VERSION STREQUAL "5.10")
list(APPEND uv_defines SUNOS_NO_IFADDRS)
list(APPEND uv_libraries rt)
endif()
list(APPEND uv_defines __EXTENSIONS__ _XOPEN_SOURCE=500 _REENTRANT)
list(APPEND uv_libraries kstat nsl sendfile socket)
list(APPEND uv_sources
@ -372,25 +436,42 @@ if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD")
list(APPEND uv_test_libraries util)
endif()
add_library(uv SHARED ${uv_sources})
target_compile_definitions(uv
if(CYGWIN OR MSYS)
list(APPEND uv_defines _GNU_SOURCE)
list(APPEND uv_sources
src/unix/cygwin.c
src/unix/bsd-ifaddrs.c
src/unix/no-fsevents.c
src/unix/no-proctitle.c
src/unix/posix-hrtime.c
src/unix/posix-poll.c
src/unix/procfs-exepath.c
src/unix/sysinfo-loadavg.c
src/unix/sysinfo-memory.c)
endif()
if(LIBUV_BUILD_SHARED)
add_library(uv SHARED ${uv_sources})
target_compile_definitions(uv
INTERFACE
USING_UV_SHARED=1
PRIVATE
BUILDING_UV_SHARED=1
${uv_defines})
target_compile_options(uv PRIVATE ${uv_cflags})
target_include_directories(uv
target_compile_options(uv PRIVATE ${uv_cflags})
target_include_directories(uv
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
target_include_directories(uv PUBLIC $<BUILD_INTERFACE:${ZOSLIB_DIR}/include>)
set_target_properties(uv PROPERTIES LINKER_LANGUAGE CXX)
endif()
target_link_libraries(uv ${uv_libraries})
set_target_properties(uv PROPERTIES OUTPUT_NAME "uv")
endif()
target_link_libraries(uv ${uv_libraries})
add_library(uv_a STATIC ${uv_sources})
target_compile_definitions(uv_a PRIVATE ${uv_defines})
@ -406,6 +487,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OS390")
set_target_properties(uv_a PROPERTIES LINKER_LANGUAGE CXX)
endif()
target_link_libraries(uv_a ${uv_libraries})
set_target_properties(uv_a PROPERTIES OUTPUT_NAME "uv")
if(WIN32)
set_target_properties(uv_a PROPERTIES PREFIX "lib")
endif()
if(LIBUV_BUILD_TESTS)
# Small hack: use ${uv_test_sources} now to get the runner skeleton,
@ -418,6 +503,7 @@ if(LIBUV_BUILD_TESTS)
test/benchmark-fs-stat.c
test/benchmark-getaddrinfo.c
test/benchmark-loop-count.c
test/benchmark-queue-work.c
test/benchmark-million-async.c
test/benchmark-million-timers.c
test/benchmark-multi-accept.c
@ -447,7 +533,6 @@ if(LIBUV_BUILD_TESTS)
test/test-async-null-cb.c
test/test-async.c
test/test-barrier.c
test/test-callback-order.c
test/test-callback-stack.c
test/test-close-fd.c
test/test-close-order.c
@ -487,6 +572,7 @@ if(LIBUV_BUILD_TESTS)
test/test-hrtime.c
test/test-idle.c
test/test-idna.c
test/test-iouring-pollhup.c
test/test-ip4-addr.c
test/test-ip6-addr.c
test/test-ip-name.c
@ -546,10 +632,12 @@ if(LIBUV_BUILD_TESTS)
test/test-spawn.c
test/test-stdio-over-pipes.c
test/test-strscpy.c
test/test-strtok.c
test/test-tcp-alloc-cb-fail.c
test/test-tcp-bind-error.c
test/test-tcp-bind6-error.c
test/test-tcp-close-accept.c
test/test-tcp-close-after-read-timeout.c
test/test-tcp-close-while-connecting.c
test/test-tcp-close.c
test/test-tcp-close-reset.c
@ -562,9 +650,12 @@ if(LIBUV_BUILD_TESTS)
test/test-tcp-oob.c
test/test-tcp-open.c
test/test-tcp-read-stop.c
test/test-tcp-reuseport.c
test/test-tcp-read-stop-start.c
test/test-tcp-rst.c
test/test-tcp-shutdown-after-write.c
test/test-tcp-try-write.c
test/test-tcp-write-in-a-row.c
test/test-tcp-try-write-error.c
test/test-tcp-unexpected-read.c
test/test-tcp-write-after-connect.c
@ -573,8 +664,11 @@ if(LIBUV_BUILD_TESTS)
test/test-tcp-write-to-half-open-connection.c
test/test-tcp-writealot.c
test/test-test-macros.c
test/test-thread-affinity.c
test/test-thread-equal.c
test/test-thread.c
test/test-thread-name.c
test/test-thread-priority.c
test/test-threadpool-cancel.c
test/test-threadpool.c
test/test-timer-again.c
@ -605,6 +699,8 @@ if(LIBUV_BUILD_TESTS)
test/test-udp-sendmmsg-error.c
test/test-udp-send-unreachable.c
test/test-udp-try-send.c
test/test-udp-recv-in-a-row.c
test/test-udp-reuseport.c
test/test-uname.c
test/test-walk-handles.c
test/test-watcher-cross-stop.c)
@ -621,6 +717,12 @@ if(LIBUV_BUILD_TESTS)
set_tests_properties(uv_test PROPERTIES ENVIRONMENT
"LIBPATH=${CMAKE_BINARY_DIR}:$ENV{LIBPATH}")
endif()
if(WIN32)
add_custom_command(TARGET uv_run_tests POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:uv_run_tests>"
"$<TARGET_FILE_DIR:uv_run_tests>/uv_run_tests_no_ext")
endif()
add_executable(uv_run_tests_a ${uv_test_sources} uv_win_longpath.manifest)
target_compile_definitions(uv_run_tests_a PRIVATE ${uv_defines})
target_compile_options(uv_run_tests_a PRIVATE ${uv_cflags})
@ -637,6 +739,12 @@ if(LIBUV_BUILD_TESTS)
set_target_properties(uv_run_tests PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(uv_run_tests_a PROPERTIES LINKER_LANGUAGE CXX)
endif()
if(WIN32)
add_custom_command(TARGET uv_run_tests_a POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:uv_run_tests_a>"
"$<TARGET_FILE_DIR:uv_run_tests_a>/uv_run_tests_a_no_ext")
endif()
endif()
# Now for some gibbering horrors from beyond the stars...
@ -648,30 +756,55 @@ string(REPLACE ";" " " LIBS "${LIBS}")
file(STRINGS configure.ac configure_ac REGEX ^AC_INIT)
string(REGEX MATCH "([0-9]+)[.][0-9]+[.][0-9]+" PACKAGE_VERSION "${configure_ac}")
set(UV_VERSION_MAJOR "${CMAKE_MATCH_1}")
# The version in the filename is mirroring the behaviour of autotools.
set_target_properties(uv PROPERTIES
VERSION ${UV_VERSION_MAJOR}.0.0
SOVERSION ${UV_VERSION_MAJOR})
set(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
set(prefix ${CMAKE_INSTALL_PREFIX})
configure_file(libuv.pc.in libuv.pc @ONLY)
configure_file(libuv-static.pc.in libuv-static.pc @ONLY)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(FILES ${PROJECT_BINARY_DIR}/libuv.pc ${PROJECT_BINARY_DIR}/libuv-static.pc
install(FILES LICENSE-extra DESTINATION ${CMAKE_INSTALL_DOCDIR})
install(FILES ${PROJECT_BINARY_DIR}/libuv-static.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(TARGETS uv EXPORT libuvConfig
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS uv_a ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(EXPORT libuvConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libuv)
install(TARGETS uv_a EXPORT libuvConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(EXPORT libuvConfig
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libuv
NAMESPACE libuv::)
if(LIBUV_BUILD_SHARED)
# The version in the filename is mirroring the behaviour of autotools.
set_target_properties(uv PROPERTIES
VERSION ${UV_VERSION_MAJOR}.0.0
SOVERSION ${UV_VERSION_MAJOR})
configure_file(libuv.pc.in libuv.pc @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/libuv.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(TARGETS uv EXPORT libuvConfig
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if(MSVC)
set(CMAKE_DEBUG_POSTFIX d)
get_filename_component(CMAKE_C_COMPILER_DIR ${CMAKE_C_COMPILER} DIRECTORY)
if(ASAN)
file(INSTALL "${CMAKE_C_COMPILER_DIR}/llvm-symbolizer.exe" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
file(INSTALL "${CMAKE_C_COMPILER_DIR}/clang_rt.asan_dynamic-x86_64.dll" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
file(INSTALL "${CMAKE_C_COMPILER_DIR}/clang_rt.asan_dbg_dynamic-x86_64.dll" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
endif()
endif()
if(BUILD_SHARED_LIBS)
set(LIB_SELECTED uv)
else()
set(LIB_SELECTED uv_a)
endif()
add_library(libuv::libuv ALIAS ${LIB_SELECTED})
message(STATUS "summary of build options:
Install prefix: ${CMAKE_INSTALL_PREFIX}
Target system: ${CMAKE_SYSTEM_NAME}

1204
ChangeLog

File diff suppressed because it is too large Load Diff

51
LICENSE
View File

@ -1,6 +1,3 @@
libuv is licensed for use as follows:
====
Copyright (c) 2015-present libuv project contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy
@ -20,51 +17,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
====
This license applies to parts of libuv originating from the
https://github.com/joyent/libuv repository:
====
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
====
This license applies to all parts of libuv that are not externally
maintained libraries.
The externally maintained libraries used by libuv are:
- tree.h (from FreeBSD), copyright Niels Provos. Two clause BSD license.
- inet_pton and inet_ntop implementations, contained in src/inet.c, are
copyright the Internet Systems Consortium, Inc., and licensed under the ISC
license.
- stdint-msvc2008.h (from msinttypes), copyright Alexander Chemeris. Three
clause BSD license.
- pthread-fixes.c, copyright Google Inc. and Sony Mobile Communications AB.
Three clause BSD license.
- android-ifaddrs.h, android-ifaddrs.c, copyright Berkeley Software Design
Inc, Kenneth MacKay and Emergya (Cloud4all, FP7/2007-2013, grant agreement
n° 289016). Three clause BSD license.

36
LICENSE-extra Normal file
View File

@ -0,0 +1,36 @@
This license applies to parts of libuv originating from the
https://github.com/joyent/libuv repository:
====
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
====
This license applies to all parts of libuv that are not externally
maintained libraries.
The externally maintained libraries used by libuv are:
- tree.h (from FreeBSD), copyright Niels Provos. Two clause BSD license.
- inet_pton and inet_ntop implementations, contained in src/inet.c, are
copyright the Internet Systems Consortium, Inc., and licensed under the ISC
license.

View File

@ -1,16 +1,20 @@
### Apps / VM
* [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.
* [cjdns](https://github.com/cjdelisle/cjdns): Encrypted self-configuring network/VPN routing engine
* [clearskies_core](https://github.com/larroy/clearskies_core): Clearskies file synchronization program. (C++11)
* [CMake](https://cmake.org) open-source, cross-platform family of tools designed to build, test and package software
* [Cocos-Engine](https://github.com/cocos/cocos-engine): The runtime framework for Cocos Creator editor.
* [Coherence](https://github.com/liesware/coherence/): Cryptographic server for modern web apps.
* [DPS8M](https://dps8m.gitlab.io): GE Honeywell Bull DPS8/M and 6180/L68 mainframe simulator.
* [DPS-For-IoT](https://github.com/intel/dps-for-iot/wiki): Fully distributed publish/subscribe protocol.
* [HashLink](https://github.com/HaxeFoundation/hashlink): Haxe run-time with libuv support included.
* [Haywire](https://github.com/kellabyte/Haywire): Asynchronous HTTP server.
* [H2O](https://github.com/h2o/h2o): An optimized HTTP server with support for HTTP/1.x and HTTP/2.
* [Igropyr](https://github.com/guenchi/Igropyr): a async Scheme http server base on libuv.
* [Julia](http://julialang.org/): Scientific computing programming language
* [Kestrel](https://github.com/aspnet/AspNetCore/tree/master/src/Servers/Kestrel): web server (C# + libuv + [ASP.NET Core](http://github.com/aspnet))
* [Kestrel](https://github.com/dotnet/aspnetcore/tree/main/src/Servers/Kestrel): web server (C# + libuv + [ASP.NET Core](http://github.com/aspnet))
* [Knot DNS Resolver](https://www.knot-resolver.cz/): A minimalistic DNS caching resolver
* [Lever](http://leverlanguage.com): runtime, libuv at the 0.9.0 release
* [libnode](https://github.com/plenluno/libnode): C++ implementation of Node.js
@ -30,8 +34,11 @@
* [phastlight](https://github.com/phastlight/phastlight): Command line tool and web server written in PHP 5.3+ inspired by Node.js
* [pilight](https://www.pilight.org/): home automation ("domotica")
* [pixie](https://github.com/pixie-lang/pixie): clojure-inspired lisp with a tracing JIT
* [Pixie-io](https://github.com/pixie-io/pixie): Open-source observability tool for Kubernetes applications.
* [potion](https://github.com/perl11/potion)/[p2](https://github.com/perl11/p2): runtime
* [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.
@ -39,6 +46,7 @@
* [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
@ -59,6 +67,7 @@
* [lluv](https://github.com/moteus/lua-lluv)
* C++11
* [uvpp](https://github.com/larroy/uvpp) - Not complete, exposes very few aspects of `libuv`
* [nsuv](https://github.com/nodesource/nsuv) - Template wrapper focused on enforcing compile-time type safety when propagating data
* C++17
* [uvw](https://github.com/skypjack/uvw) - Header-only, event based, tiny and easy to use *libuv* wrapper in modern C++.
* Python
@ -99,3 +108,5 @@
* [node.pas](https://github.com/vovach777/node.pas) NodeJS-like ecosystem
* Haskell
* [Z.Haskell](https://z.haskell.world)
* C3
* [libuv.c3l](https://github.com/velikoss/libuv.c3l)

View File

@ -1,23 +1,16 @@
# Project Maintainers
libuv is currently managed by the following individuals:
* **Anna Henningsen** ([@addaleax](https://github.com/addaleax))
* **Bartosz Sosnowski** ([@bzoz](https://github.com/bzoz))
* **Ben Noordhuis** ([@bnoordhuis](https://github.com/bnoordhuis))
- GPG key: D77B 1E34 243F BAF0 5F8E 9CC3 4F55 C8C8 46AB 89B9 (pubkey-bnoordhuis)
* **Bert Belder** ([@piscisaureus](https://github.com/piscisaureus))
* **Colin Ihrig** ([@cjihrig](https://github.com/cjihrig))
- GPG key: 94AE 3667 5C46 4D64 BAFA 68DD 7434 390B DBE9 B9C5 (pubkey-cjihrig)
- GPG key: 5735 3E0D BDAA A7E8 39B6 6A1A FF47 D5E4 AD8B 4FDC (pubkey-cjihrig-kb)
* **Fedor Indutny** ([@indutny](https://github.com/indutny))
- GPG key: AF2E EA41 EC34 47BF DD86 FED9 D706 3CCE 19B7 E890 (pubkey-indutny)
* **Imran Iqbal** ([@imran-iq](https://github.com/imran-iq))
- GPG key: 9DFE AA5F 481B BF77 2D90 03CE D592 4925 2F8E C41A (pubkey-iwuzhere)
* **Jameson Nash** ([@vtjnash](https://github.com/vtjnash))
- GPG key: AEAD 0A4B 6867 6775 1A0E 4AEF 34A2 5FB1 2824 6514 (pubkey-vtjnash)
* **John Barboza** ([@jbarz](https://github.com/jbarz))
- GPG key: CFBB 9CA9 A5BE AFD7 0E2B 3C5A 79A6 7C55 A367 9C8B (pubkey2022-vtjnash)
* **Jiawen Geng** ([@gengjiawen](https://github.com/gengjiawen))
* **Kaoru Takanashi** ([@erw7](https://github.com/erw7))
- GPG Key: 5804 F999 8A92 2AFB A398 47A0 7183 5090 6134 887F (pubkey-erw7)
* **Richard Lau** ([@richardlau](https://github.com/richardlau))
@ -26,6 +19,18 @@ libuv is currently managed by the following individuals:
- GPG key: 612F 0EAD 9401 6223 79DF 4402 F28C 3C8D A33C 03BE (pubkey-santigimeno)
* **Saúl Ibarra Corretgé** ([@saghul](https://github.com/saghul))
- GPG key: FDF5 1936 4458 319F A823 3DC9 410E 5553 AE9B C059 (pubkey-saghul)
* **Trevor Norris** ([@trevnorris](https://github.com/trevnorris))
- GPG key: AEFC 279A 0C93 0676 7E58 29A1 251C A676 820D C7F3 (pubkey-trevnorris)
## Project Maintainers emeriti
* **Anna Henningsen** ([@addaleax](https://github.com/addaleax))
* **Bartosz Sosnowski** ([@bzoz](https://github.com/bzoz))
* **Bert Belder** ([@piscisaureus](https://github.com/piscisaureus))
* **Fedor Indutny** ([@indutny](https://github.com/indutny))
- GPG key: AF2E EA41 EC34 47BF DD86 FED9 D706 3CCE 19B7 E890 (pubkey-indutny)
* **Imran Iqbal** ([@imran-iq](https://github.com/imran-iq))
* **John Barboza** ([@jbarz](https://github.com/jbarz))
## Storing a maintainer key in Git

View File

@ -27,8 +27,8 @@ uvinclude_HEADERS = include/uv/errno.h \
CLEANFILES =
lib_LTLIBRARIES = libuv.la
libuv_la_CFLAGS = @CFLAGS@
libuv_la_LDFLAGS = -no-undefined -version-info 1:0:0
libuv_la_CFLAGS = $(AM_CFLAGS)
libuv_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-info 1:0:0
libuv_la_SOURCES = src/fs-poll.c \
src/heap-inl.h \
src/idna.c \
@ -38,12 +38,15 @@ libuv_la_SOURCES = src/fs-poll.c \
src/random.c \
src/strscpy.c \
src/strscpy.h \
src/thread-common.c \
src/threadpool.c \
src/timer.c \
src/uv-data-getter-setters.c \
src/uv-common.c \
src/uv-common.h \
src/version.c
src/version.c \
src/strtok.c \
src/strtok.h
if SUNOS
# Can't be turned into a CC_CHECK_CFLAGS in configure.ac, it makes compilers
@ -56,7 +59,7 @@ if WINNT
uvinclude_HEADERS += include/uv/win.h include/uv/tree.h
AM_CPPFLAGS += -I$(top_srcdir)/src/win \
-DWIN32_LEAN_AND_MEAN \
-D_WIN32_WINNT=0x0602
-D_WIN32_WINNT=0x0A00
libuv_la_SOURCES += src/win/async.c \
src/win/atomicops-inl.h \
src/win/core.c \
@ -94,7 +97,6 @@ else # WINNT
uvinclude_HEADERS += include/uv/unix.h
AM_CPPFLAGS += -I$(top_srcdir)/src/unix
libuv_la_SOURCES += src/unix/async.c \
src/unix/atomic-ops.h \
src/unix/core.c \
src/unix/dl.c \
src/unix/fs.c \
@ -108,7 +110,6 @@ libuv_la_SOURCES += src/unix/async.c \
src/unix/process.c \
src/unix/random-devurandom.c \
src/unix/signal.c \
src/unix/spinlock.h \
src/unix/stream.c \
src/unix/tcp.c \
src/unix/thread.c \
@ -120,18 +121,26 @@ endif # WINNT
EXTRA_DIST = test/fixtures/empty_file \
test/fixtures/load_error.node \
test/fixtures/lorem_ipsum.txt \
test/fixtures/one_file/one_file \
include \
docs \
img \
CONTRIBUTING.md \
LICENSE \
LICENSE-extra \
README.md
TESTS = test/run-tests
check_PROGRAMS = test/run-tests
test_run_tests_CFLAGS =
test_run_tests_CFLAGS = $(AM_CFLAGS)
if WINNT
check-am: test/run-tests_no_ext
test/run-tests_no_ext: test/run-tests$(EXEEXT)
cp test/run-tests$(EXEEXT) test/run-tests_no_ext
endif
if SUNOS
# Can't be turned into a CC_CHECK_CFLAGS in configure.ac, it makes compilers
@ -139,7 +148,7 @@ if SUNOS
test_run_tests_CFLAGS += -pthreads
endif
test_run_tests_LDFLAGS =
test_run_tests_LDFLAGS = $(AM_LDFLAGS)
test_run_tests_SOURCES = test/blackhole-server.c \
test/echo-server.c \
test/run-tests.c \
@ -150,7 +159,6 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-async.c \
test/test-async-null-cb.c \
test/test-barrier.c \
test/test-callback-order.c \
test/test-callback-stack.c \
test/test-close-fd.c \
test/test-close-order.c \
@ -190,6 +198,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-hrtime.c \
test/test-idle.c \
test/test-idna.c \
test/test-iouring-pollhup.c \
test/test-ip4-addr.c \
test/test-ip6-addr.c \
test/test-ip-name.c \
@ -250,11 +259,13 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-spawn.c \
test/test-stdio-over-pipes.c \
test/test-strscpy.c \
test/test-strtok.c \
test/test-tcp-alloc-cb-fail.c \
test/test-tcp-bind-error.c \
test/test-tcp-bind6-error.c \
test/test-tcp-close-accept.c \
test/test-tcp-close-while-connecting.c \
test/test-tcp-close-after-read-timeout.c \
test/test-tcp-close.c \
test/test-tcp-close-reset.c \
test/test-tcp-create-socket-early.c \
@ -265,7 +276,9 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-tcp-flags.c \
test/test-tcp-open.c \
test/test-tcp-read-stop.c \
test/test-tcp-reuseport.c \
test/test-tcp-read-stop-start.c \
test/test-tcp-rst.c \
test/test-tcp-shutdown-after-write.c \
test/test-tcp-unexpected-read.c \
test/test-tcp-oob.c \
@ -274,11 +287,15 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-tcp-writealot.c \
test/test-tcp-write-fail.c \
test/test-tcp-try-write.c \
test/test-tcp-write-in-a-row.c \
test/test-tcp-try-write-error.c \
test/test-tcp-write-queue-order.c \
test/test-test-macros.c \
test/test-thread-equal.c \
test/test-thread.c \
test/test-thread-affinity.c \
test/test-thread-name.c \
test/test-thread-priority.c \
test/test-threadpool-cancel.c \
test/test-threadpool.c \
test/test-timer-again.c \
@ -309,6 +326,8 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-udp-sendmmsg-error.c \
test/test-udp-send-unreachable.c \
test/test-udp-try-send.c \
test/test-udp-recv-in-a-row.c \
test/test-udp-reuseport.c \
test/test-uname.c \
test/test-walk-handles.c \
test/test-watcher-cross-stop.c
@ -388,10 +407,7 @@ libuv_la_SOURCES += src/unix/aix-common.c \
endif
if ANDROID
uvinclude_HEADERS += include/uv/android-ifaddrs.h
libuv_la_CFLAGS += -D_GNU_SOURCE
libuv_la_SOURCES += src/unix/android-ifaddrs.c \
src/unix/pthread-fixes.c
endif
if CYGWIN
@ -415,6 +431,7 @@ libuv_la_CFLAGS += -D_DARWIN_UNLIMITED_SELECT=1
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/darwin-proctitle.c \
src/unix/darwin-stub.h \
src/unix/darwin-syscalls.h \
src/unix/darwin.c \
src/unix/fsevents.c \
src/unix/kqueue.c \
@ -457,23 +474,22 @@ endif
if HURD
uvinclude_HEADERS += include/uv/posix.h
libuv_la_SOURCES += src/unix/no-fsevents.c \
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/no-fsevents.c \
src/unix/no-proctitle.c \
src/unix/posix-hrtime.c \
src/unix/posix-poll.c
src/unix/posix-poll.c \
src/unix/hurd.c
endif
if LINUX
uvinclude_HEADERS += include/uv/linux.h
libuv_la_CFLAGS += -D_GNU_SOURCE
libuv_la_SOURCES += src/unix/linux-core.c \
src/unix/linux-inotify.c \
src/unix/linux-syscalls.c \
src/unix/linux-syscalls.h \
libuv_la_SOURCES += src/unix/linux.c \
src/unix/procfs-exepath.c \
src/unix/proctitle.c \
src/unix/random-getrandom.c \
src/unix/random-sysctl-linux.c \
src/unix/epoll.c
src/unix/random-sysctl-linux.c
test_run_tests_LDFLAGS += -lutil
endif
@ -537,8 +553,7 @@ libuv_la_CFLAGS += -D_UNIX03_THREADS \
-qXPLINK \
-qFLOAT=IEEE
libuv_la_LDFLAGS += -qXPLINK
libuv_la_SOURCES += src/unix/pthread-fixes.c \
src/unix/os390.c \
libuv_la_SOURCES += src/unix/os390.c \
src/unix/os390-syscalls.c \
src/unix/proctitle.c
endif

View File

@ -43,8 +43,11 @@ The ABI/API changes can be tracked [here](http://abi-laboratory.pro/tracker/time
## Licensing
libuv is licensed under the MIT license. Check the [LICENSE file](LICENSE).
The documentation is licensed under the CC BY 4.0 license. Check the [LICENSE-docs file](LICENSE-docs).
libuv is licensed under the MIT license. Check the [LICENSE](LICENSE) and
[LICENSE-extra](LICENSE-extra) files.
The documentation is licensed under the CC BY 4.0 license. Check the
[LICENSE-docs file](LICENSE-docs).
## Community
@ -220,6 +223,27 @@ Make sure that you specify the architecture you wish to build for in the
"ARCHS" flag. You can specify more than one by delimiting with a space
(e.g. "x86_64 i386").
### Install with vcpkg
```bash
$ git clone https://github.com/microsoft/vcpkg.git
$ ./bootstrap-vcpkg.bat # for powershell
$ ./bootstrap-vcpkg.sh # for bash
$ ./vcpkg install libuv
```
### Install with Conan
You can install pre-built binaries for libuv or build it from source using [Conan](https://conan.io/). Use the following command:
```bash
conan install --requires="libuv/[*]" --build=missing
```
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
Some tests are timing sensitive. Relaxing test timeouts may be necessary

27
SECURITY.md Normal file
View File

@ -0,0 +1,27 @@
# Security Policy
## Supported Versions
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.

View File

@ -2,17 +2,16 @@
| System | Support type | Supported versions | Notes |
|---|---|---|---|
| GNU/Linux | Tier 1 | Linux >= 2.6.32 with glibc >= 2.12 | |
| macOS | Tier 1 | macOS >= 10.7 | |
| Windows | Tier 1 | >= Windows 8 | VS 2015 and later are supported |
| FreeBSD | Tier 1 | >= 10 | |
| GNU/Linux | Tier 1 | Linux >= 3.10 with glibc >= 2.17 | |
| macOS | Tier 1 | macOS >= 11 | Currently supported macOS releases |
| Windows | Tier 1 | >= Windows 10 | VS 2015 and later are supported |
| FreeBSD | Tier 2 | >= 12 | |
| AIX | Tier 2 | >= 6 | Maintainers: @libuv/aix |
| IBM i | Tier 2 | >= IBM i 7.2 | Maintainers: @libuv/ibmi |
| z/OS | Tier 2 | >= V2R2 | Maintainers: @libuv/zos |
| Linux with musl | Tier 2 | musl >= 1.0 | |
| SmartOS | Tier 3 | >= 14.4 | |
| Android | Tier 3 | NDK >= r15b | |
| MinGW | Tier 3 | MinGW32 and MinGW-w64 | |
| Android | Tier 3 | NDK >= r15b | Android 7.0, `-DANDROID_PLATFORM=android-24` |
| MinGW | Tier 3 | MinGW-w64 | |
| SunOS | Tier 3 | Solaris 121 and later | |
| Other | Tier 3 | N/A | |

View File

@ -14,9 +14,16 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
set -eu
cd `dirname "$0"`
if [ "$LIBTOOLIZE" = "" ] && [ "`uname`" = "Darwin" ]; then
if [ "${1:-dev}" = "release" ]; then
export LIBUV_RELEASE=true
else
export LIBUV_RELEASE=false
fi
if [ "${LIBTOOLIZE:-}" = "" ] && [ "`uname`" = "Darwin" ]; then
LIBTOOLIZE=glibtoolize
fi
@ -25,9 +32,17 @@ AUTOCONF=${AUTOCONF:-autoconf}
AUTOMAKE=${AUTOMAKE:-automake}
LIBTOOLIZE=${LIBTOOLIZE:-libtoolize}
aclocal_version=`"$ACLOCAL" --version | head -n 1 | sed 's/[^.0-9]//g'`
autoconf_version=`"$AUTOCONF" --version | head -n 1 | sed 's/[^.0-9]//g'`
automake_version=`"$AUTOMAKE" --version | head -n 1 | sed 's/[^.0-9]//g'`
automake_version_major=`echo "$automake_version" | cut -d. -f1`
automake_version_minor=`echo "$automake_version" | cut -d. -f2`
libtoolize_version=`"$LIBTOOLIZE" --version | head -n 1 | sed 's/[^.0-9]//g'`
if [ $aclocal_version != $automake_version ]; then
echo "FATAL: aclocal version appears not to be from the same as automake"
exit 1
fi
UV_EXTRA_AUTOMAKE_FLAGS=
if test "$automake_version_major" -gt 1 || \
@ -39,8 +54,22 @@ fi
echo "m4_define([UV_EXTRA_AUTOMAKE_FLAGS], [$UV_EXTRA_AUTOMAKE_FLAGS])" \
> m4/libuv-extra-automake-flags.m4
set -ex
"$LIBTOOLIZE" --copy
(set -x
"$LIBTOOLIZE" --copy --force
"$ACLOCAL" -I m4
)
if $LIBUV_RELEASE; then
"$AUTOCONF" -o /dev/null m4/libuv-check-versions.m4
echo "
AC_PREREQ($autoconf_version)
AC_INIT([libuv-release-check], [0.0])
AM_INIT_AUTOMAKE([$automake_version])
LT_PREREQ($libtoolize_version)
AC_OUTPUT
" > m4/libuv-check-versions.m4
fi
(
set -x
"$AUTOCONF"
"$AUTOMAKE" --add-missing --copy
)

View File

@ -0,0 +1,17 @@
if(NOT HOST_ARCH)
message(SEND_ERROR "-DHOST_ARCH required to be specified")
endif()
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
HOST_ARCH
)
SET(CMAKE_SYSTEM_NAME Windows)
set(COMPILER_PREFIX "${HOST_ARCH}-w64-mingw32")
find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres)
find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc)
find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

View File

@ -13,12 +13,13 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AC_PREREQ(2.57)
AC_INIT([libuv], [1.43.0], [https://github.com/libuv/libuv/issues])
AC_INIT([libuv], [1.50.1-dev], [https://github.com/libuv/libuv/issues])
AC_CONFIG_MACRO_DIR([m4])
m4_include([m4/libuv-extra-automake-flags.m4])
m4_include([m4/as_case.m4])
m4_include([m4/libuv-check-flags.m4])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects] UV_EXTRA_AUTOMAKE_FLAGS)
AM_MAINTAINER_MODE([enable]) # pass --disable-maintainer-mode if autotools may be unavailable
AC_CANONICAL_HOST
AC_ENABLE_SHARED
AC_ENABLE_STATIC
@ -28,7 +29,9 @@ AM_PROG_CC_C_O
CC_ATTRIBUTE_VISIBILITY([default], [
CC_FLAG_VISIBILITY([CFLAGS="${CFLAGS} -fvisibility=hidden"])
])
CC_CHECK_CFLAGS_APPEND([-fno-strict-aliasing])
# Xlc has a flag "-f<filename>". Need to use CC_CHECK_FLAG_SUPPORTED_APPEND so
# we exclude -fno-strict-aliasing for xlc
CC_CHECK_FLAG_SUPPORTED_APPEND([-fno-strict-aliasing])
CC_CHECK_CFLAGS_APPEND([-g])
CC_CHECK_CFLAGS_APPEND([-std=gnu89])
CC_CHECK_CFLAGS_APPEND([-Wall])
@ -59,7 +62,7 @@ AM_CONDITIONAL([ANDROID], [AS_CASE([$host_os],[linux-android*],[true], [false])
AM_CONDITIONAL([CYGWIN], [AS_CASE([$host_os],[cygwin*], [true], [false])])
AM_CONDITIONAL([DARWIN], [AS_CASE([$host_os],[darwin*], [true], [false])])
AM_CONDITIONAL([DRAGONFLY],[AS_CASE([$host_os],[dragonfly*], [true], [false])])
AM_CONDITIONAL([FREEBSD], [AS_CASE([$host_os],[*freebsd*], [true], [false])])
AM_CONDITIONAL([FREEBSD], [AS_CASE([$host_os],[freebsd*], [true], [false])])
AM_CONDITIONAL([HAIKU], [AS_CASE([$host_os],[haiku], [true], [false])])
AM_CONDITIONAL([HURD], [AS_CASE([$host_os],[gnu*], [true], [false])])
AM_CONDITIONAL([LINUX], [AS_CASE([$host_os],[linux*], [true], [false])])
@ -71,12 +74,12 @@ AM_CONDITIONAL([OS400], [AS_CASE([$host_os],[os400], [true], [false])
AM_CONDITIONAL([SUNOS], [AS_CASE([$host_os],[solaris*], [true], [false])])
AM_CONDITIONAL([WINNT], [AS_CASE([$host_os],[mingw*], [true], [false])])
AS_CASE([$host_os],[mingw*], [
LIBS="$LIBS -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -luser32"
LIBS="$LIBS -lws2_32 -lpsapi -liphlpapi -luserenv -luser32 -ldbghelp -lole32 -lshell32"
])
AS_CASE([$host_os], [solaris2.10], [
CFLAGS="$CFLAGS -DSUNOS_NO_IFADDRS"
])
AS_CASE([$host_os], [netbsd*], [AC_CHECK_LIB([kvm], [kvm_open])])
AS_CASE([$host_os], [kfreebsd*], [
LIBS="$LIBS -lfreebsd-glue"
])
AS_CASE([$host_os], [haiku], [
LIBS="$LIBS -lnetwork"
])
@ -85,4 +88,5 @@ AC_CONFIG_FILES([Makefile libuv.pc])
AC_CONFIG_LINKS([test/fixtures/empty_file:test/fixtures/empty_file])
AC_CONFIG_LINKS([test/fixtures/load_error.node:test/fixtures/load_error.node])
AC_CONFIG_LINKS([test/fixtures/lorem_ipsum.txt:test/fixtures/lorem_ipsum.txt])
AC_CONFIG_LINKS([test/fixtures/one_file/one_file:test/fixtures/one_file/one_file])
AC_OUTPUT

3
docs/code/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*/*
!*.c
!*.h

51
docs/code/CMakeLists.txt Normal file
View File

@ -0,0 +1,51 @@
cmake_minimum_required(VERSION 3.5)
project(libuv_sample)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_subdirectory("../../" build)
set(SIMPLE_SAMPLES
cgi
helloworld
dns
detach
default-loop
idle-basic
idle-compute
interfaces
locks
onchange
pipe-echo-server
ref-timer
spawn
tcp-echo-server
thread-create
udp-dhcp
uvcat
uvstop
uvtee
)
IF (NOT WIN32)
list(APPEND SIMPLE_SAMPLES
signal
progress
queue-cancel
queue-work
tty
tty-gravity
)
ENDIF()
foreach (X IN LISTS SIMPLE_SAMPLES)
add_executable(${X} ${X}/main.c)
target_link_libraries(${X} uv_a)
endforeach ()
FIND_PACKAGE(CURL)
IF(CURL_FOUND)
add_executable(uvwget uvwget/main.c)
target_link_libraries(uvwget uv_a ${CURL_LIBRARIES})
ENDIF(CURL_FOUND)

View File

@ -15,8 +15,8 @@ void cleanup_handles(uv_process_t *req, int64_t exit_status, int term_signal) {
}
void invoke_cgi_script(uv_tcp_t *client) {
size_t size = 500;
char path[size];
char path[500];
size_t size = sizeof(path);
uv_exepath(path, &size);
strcpy(path + (strlen(path) - strlen("cgi")), "tick");

View File

@ -0,0 +1,12 @@
#include <stdio.h>
#include <uv.h>
int main() {
uv_loop_t *loop = uv_default_loop();
printf("Default loop.\n");
uv_run(loop, UV_RUN_DEFAULT);
uv_loop_close(loop);
return 0;
}

View File

@ -11,17 +11,17 @@ int main() {
printf("Number of interfaces: %d\n", count);
while (i--) {
uv_interface_address_t interface = info[i];
uv_interface_address_t interface_a = info[i];
printf("Name: %s\n", interface.name);
printf("Internal? %s\n", interface.is_internal ? "Yes" : "No");
printf("Name: %s\n", interface_a.name);
printf("Internal? %s\n", interface_a.is_internal ? "Yes" : "No");
if (interface.address.address4.sin_family == AF_INET) {
uv_ip4_name(&interface.address.address4, buf, sizeof(buf));
if (interface_a.address.address4.sin_family == AF_INET) {
uv_ip4_name(&interface_a.address.address4, buf, sizeof(buf));
printf("IPv4 address: %s\n", buf);
}
else if (interface.address.address4.sin_family == AF_INET6) {
uv_ip6_name(&interface.address.address6, buf, sizeof(buf));
else if (interface_a.address.address4.sin_family == AF_INET6) {
uv_ip6_name(&interface_a.address.address6, buf, sizeof(buf));
printf("IPv6 address: %s\n", buf);
}

View File

@ -1,5 +1,4 @@
#include <stdio.h>
#include <unistd.h>
#include <uv.h>
@ -7,7 +6,7 @@ void hare(void *arg) {
int tracklen = *((int *) arg);
while (tracklen) {
tracklen--;
sleep(1);
uv_sleep(1000);
fprintf(stderr, "Hare ran another step\n");
}
fprintf(stderr, "Hare done running!\n");
@ -18,7 +17,7 @@ void tortoise(void *arg) {
while (tracklen) {
tracklen--;
fprintf(stderr, "Tortoise ran another step\n");
sleep(3);
uv_sleep(3000);
}
fprintf(stderr, "Tortoise done running!\n");
}

View File

@ -5,25 +5,27 @@
uv_loop_t *loop;
uv_tty_t tty;
int main() {
loop = uv_default_loop();
int main() {
uv_write_t req;
uv_buf_t buf;
uv_write_t req1;
uv_buf_t buf1;
loop = uv_default_loop();
uv_tty_init(loop, &tty, STDOUT_FILENO, 0);
uv_tty_set_mode(&tty, UV_TTY_MODE_NORMAL);
if (uv_guess_handle(1) == UV_TTY) {
uv_write_t req;
uv_buf_t buf;
buf.base = "\033[41;37m";
buf.len = strlen(buf.base);
uv_write(&req, (uv_stream_t*) &tty, &buf, 1, NULL);
buf1.base = "\033[41;37m";
buf1.len = strlen(buf1.base);
uv_write(&req1, (uv_stream_t*) &tty, &buf1, 1, NULL);
}
uv_write_t req;
uv_buf_t buf;
buf.base = "Hello TTY\n";
buf.len = strlen(buf.base);
uv_write(&req, (uv_stream_t*) &tty, &buf, 1, NULL);
uv_tty_reset_mode();
return uv_run(loop, UV_RUN_DEFAULT);
}

View File

@ -53,7 +53,8 @@ uv_buf_t make_discover_msg() {
// HOPS
buffer.base[3] = 0x0;
// XID 4 bytes
buffer.base[4] = (unsigned int) random();
if (uv_random(NULL, NULL, &buffer.base[4], 4, 0, NULL))
abort();
// SECS
buffer.base[8] = 0x0;
// FLAGS

View File

@ -1,7 +1,6 @@
#include <assert.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <uv.h>
void on_read(uv_fs_t *req);

View File

@ -1,6 +1,5 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

View File

@ -1,42 +1,36 @@
# primary
Sphinx==3.5.4
furo==2023.5.20
Sphinx==6.1.3
# dependencies
alabaster==0.7.12
appdirs==1.4.3
Babel==2.9.0
CacheControl==0.12.6
certifi==2019.11.28
chardet==3.0.4
colorama==0.4.3
contextlib2==0.6.0
distlib==0.3.0
distro==1.4.0
docutils==0.16
html5lib==1.0.1
idna==2.8
imagesize==1.2.0
ipaddr==2.2.0
Jinja2==2.11.3
lockfile==0.12.2
MarkupSafe==1.1.1
msgpack==0.6.2
packaging==20.3
pep517==0.8.2
progress==1.5
Pygments==2.8.1
pyparsing==2.4.6
pytoml==0.1.21
pytz==2021.1
requests==2.22.0
retrying==1.3.3
six==1.14.0
snowballstemmer==2.1.0
sphinxcontrib-applehelp==1.0.2
alabaster==0.7.13
Babel==2.11.0
beautifulsoup4==4.12.2
certifi==2022.12.7
charset-normalizer==3.0.1
colorama==0.4.6
docutils==0.19
idna==3.4
imagesize==1.4.1
importlib-metadata==6.0.0
Jinja2==3.1.2
livereload==2.6.3
MarkupSafe==2.1.2
packaging==23.0
Pygments==2.14.0
pytz==2022.7.1
requests==2.28.2
six==1.16.0
snowballstemmer==2.2.0
soupsieve==2.4.1
sphinx-autobuild==2021.3.14
sphinx-basic-ng==1.0.0b2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
urllib3==1.25.8
webencodings==0.5.1
sphinxcontrib-serializinghtml==1.1.5
sphinxcontrib.applehelp==1.0.3
tornado==6.3.2
urllib3==1.26.14
zipp==3.11.0

View File

@ -118,7 +118,7 @@ pygments_style = 'sphinx'
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'nature'
html_theme = 'furo'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the

View File

@ -60,16 +60,15 @@ stages of a loop iteration:
:align: center
#. The loop concept of 'now' is updated. The event loop caches the current time at the start of
the event loop tick in order to reduce the number of time-related system calls.
#. The loop concept of 'now' is initially set.
#. Due timers are run if the loop was run with ``UV_RUN_DEFAULT``. All active timers scheduled
for a time before the loop's concept of *now* get their callbacks called.
#. If the loop is *alive* an iteration is started, otherwise the loop will exit immediately. So,
when is a loop considered to be *alive*? If a loop has active and ref'd handles, active
requests or closing handles it's considered to be *alive*.
#. Due timers are run. All active timers scheduled for a time before the loop's concept of *now*
get their callbacks called.
#. Pending callbacks are called. All I/O callbacks are called right after polling for I/O, for the
most part. There are cases, however, in which calling such a callback is deferred for the next
loop iteration. If the previous iteration deferred any I/O callback it will be run at this point.
@ -101,9 +100,11 @@ stages of a loop iteration:
#. Close callbacks are called. If a handle was closed by calling :c:func:`uv_close` it will
get the close callback called.
#. Special case in case the loop was run with ``UV_RUN_ONCE``, as it implies forward progress.
It's possible that no I/O callbacks were fired after blocking for I/O, but some time has passed
so there might be timers which are due, those timers get their callbacks called.
#. The loop concept of 'now' is updated.
#. Due timers are run. Note that 'now' is not updated again until the next loop iteration.
So if a timer became due while other timers were being processed, it won't be run until
the following event loop iteration.
#. Iteration ends. If the loop was run with ``UV_RUN_NOWAIT`` or ``UV_RUN_ONCE`` modes the
iteration ends and :c:func:`uv_run` will return. If the loop was run with ``UV_RUN_DEFAULT``
@ -125,7 +126,7 @@ File I/O
Unlike network I/O, there are no platform-specific file I/O primitives libuv could rely on,
so the current approach is to run blocking file I/O operations in a thread pool.
For a thorough explanation of the cross-platform file I/O landscape, checkout
For a thorough explanation of the cross-platform file I/O landscape, check out
`this post <https://blog.libtorrent.org/2012/10/asynchronous-disk-io/>`_.
libuv currently uses a global thread pool on which all loops can queue work. 3 types of

View File

@ -339,6 +339,9 @@ Error constants
socket type not supported
.. c:macro:: UV_EUNATCH
protocol driver not attached
API
---

View File

@ -12,6 +12,15 @@ otherwise it will be performed asynchronously.
All file operations are run on the threadpool. See :ref:`threadpool` for information
on the threadpool size.
Starting with libuv v1.45.0, some file operations on Linux are handed off to
`io_uring <https://en.wikipedia.org/wiki/Io_uring>` when possible. Apart from
a (sometimes significant) increase in throughput there should be no change in
observable behavior. Libuv reverts to using its threadpool when the necessary
kernel features are unavailable or unsuitable. Starting with libuv v1.49.0 this
behavior was reverted and Libuv on Linux by default will be using the threadpool
again. In order to enable io_uring the :c:type:`uv_loop_t` instance must be
configured with the :c:type:`UV_LOOP_ENABLE_IO_URING_SQPOLL` option.
.. note::
On Windows `uv_fs_*` functions use utf-8 encoding.
@ -24,7 +33,8 @@ Data types
.. c:type:: uv_timespec_t
Portable equivalent of ``struct timespec``.
Y2K38-unsafe data type for storing times with nanosecond resolution.
Will be replaced with :c:type:`uv_timespec64_t` in libuv v2.0.
::
@ -122,10 +132,9 @@ Data types
uint64_t f_spare[4];
} uv_statfs_t;
.. c:enum:: uv_dirent_t
.. c:enum:: uv_dirent_type_t
Cross platform (reduced) equivalent of ``struct dirent``.
Used in :c:func:`uv_fs_scandir_next`.
Type of dirent.
::
@ -140,6 +149,14 @@ Data types
UV_DIRENT_BLOCK
} uv_dirent_type_t;
.. c:type:: uv_dirent_t
Cross platform (reduced) equivalent of ``struct dirent``.
Used in :c:func:`uv_fs_scandir_next`.
::
typedef struct uv_dirent_s {
const char* name;
uv_dirent_type_t type;
@ -160,6 +177,10 @@ Data types
size_t nentries;
} uv_dir_t;
.. c:type:: void (*uv_fs_cb)(uv_fs_t* req)
Callback called when a request is completed asynchronously.
Public members
^^^^^^^^^^^^^^
@ -218,7 +239,8 @@ API
.. c:function:: int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Equivalent to :man:`preadv(2)`.
Equivalent to :man:`preadv(2)`. If the `offset` argument is `-1`, then
the current file offset is used and updated.
.. warning::
On Windows, under non-MSVC environments (e.g. when GCC or Clang is used
@ -231,7 +253,8 @@ API
.. c:function:: int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Equivalent to :man:`pwritev(2)`.
Equivalent to :man:`pwritev(2)`. If the `offset` argument is `-1`, then
the current file offset is used and updated.
.. warning::
On Windows, under non-MSVC environments (e.g. when GCC or Clang is used
@ -407,6 +430,12 @@ API
Equivalent to :man:`utime(2)`, :man:`futimes(3)` and :man:`lutimes(3)` respectively.
Passing `UV_FS_UTIME_NOW` as the atime or mtime sets the timestamp to the
current time.
Passing `UV_FS_UTIME_OMIT` as the atime or mtime leaves the timestamp
untouched.
.. note::
z/OS: `uv_fs_lutime()` is not implemented for z/OS. It can still be called but will return
``UV_ENOSYS``.
@ -441,7 +470,7 @@ API
.. c:function:: int uv_fs_realpath(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb)
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`.
.. warning::
@ -463,10 +492,6 @@ API
The background story and some more details on these issues can be checked
`here <https://github.com/nodejs/node/issues/7726>`_.
.. note::
This function is not implemented on Windows XP and Windows Server 2003.
On these systems, UV_ENOSYS is returned.
.. versionadded:: 1.8.0
.. c:function:: int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_uid_t uid, uv_gid_t gid, uv_fs_cb cb)
@ -644,7 +669,7 @@ File open constants
.. note::
`UV_FS_O_RANDOM` is only supported on Windows via
`FILE_FLAG_RANDOM_ACCESS <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea>`_.
`FILE_FLAG_RANDOM_ACCESS <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew>`_.
.. c:macro:: UV_FS_O_RDONLY
@ -661,7 +686,7 @@ File open constants
.. note::
`UV_FS_O_SEQUENTIAL` is only supported on Windows via
`FILE_FLAG_SEQUENTIAL_SCAN <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea>`_.
`FILE_FLAG_SEQUENTIAL_SCAN <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew>`_.
.. c:macro:: UV_FS_O_SHORT_LIVED
@ -669,7 +694,7 @@ File open constants
.. note::
`UV_FS_O_SHORT_LIVED` is only supported on Windows via
`FILE_ATTRIBUTE_TEMPORARY <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea>`_.
`FILE_ATTRIBUTE_TEMPORARY <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew>`_.
.. c:macro:: UV_FS_O_SYMLINK
@ -690,7 +715,7 @@ File open constants
.. note::
`UV_FS_O_TEMPORARY` is only supported on Windows via
`FILE_ATTRIBUTE_TEMPORARY <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea>`_.
`FILE_ATTRIBUTE_TEMPORARY <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew>`_.
.. c:macro:: UV_FS_O_TRUNC

View File

@ -39,11 +39,20 @@ Data types
.. c:type:: void (*uv_fs_event_cb)(uv_fs_event_t* handle, const char* filename, int events, int status)
Callback passed to :c:func:`uv_fs_event_start` which will be called repeatedly
after the handle is started. If the handle was started with a directory the
`filename` parameter will be a relative path to a file contained in the directory.
The `events` parameter is an ORed mask of :c:type:`uv_fs_event` elements.
after the handle is started.
.. c:type:: uv_fs_event
If the handle was started with a directory the `filename` parameter will
be a relative path to a file contained in the directory, or `NULL` if the
file name cannot be determined.
The `events` parameter is an ORed mask of :c:enum:`uv_fs_event` elements.
.. note::
For FreeBSD path could sometimes be `NULL` due to a kernel bug.
.. _Reference: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=197695
.. c:enum:: uv_fs_event
Event types that :c:type:`uv_fs_event_t` handles monitor.
@ -54,7 +63,7 @@ Data types
UV_CHANGE = 2
};
.. c:type:: uv_fs_event_flags
.. c:enum:: uv_fs_event_flags
Flags that can be passed to :c:func:`uv_fs_event_start` to control its
behavior.
@ -105,10 +114,13 @@ API
.. c:function:: int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb, const char* path, unsigned int flags)
Start the handle with the given callback, which will watch the specified
`path` for changes. `flags` can be an ORed mask of :c:type:`uv_fs_event_flags`.
`path` for changes. `flags` can be an ORed mask of :c:enum:`uv_fs_event_flags`.
.. note:: Currently the only supported flag is ``UV_FS_EVENT_RECURSIVE`` and
only on OSX and Windows.
.. note:: On macOS, events collected by the OS immediately before calling
``uv_fs_event_start`` might be reported to the `uv_fs_event_cb`
callback.
.. c:function:: int uv_fs_event_stop(uv_fs_event_t* handle)

View File

@ -71,7 +71,7 @@ architecture of libuv and its background. If you have no prior experience with
either libuv or libev, it is a quick, useful watch.
libuv's event loop is explained in more detail in the `documentation
<http://docs.libuv.org/en/v1.x/design.html#the-i-o-loop>`_.
<https://docs.libuv.org/en/v1.x/design.html#the-i-o-loop>`_.
.. raw:: html
@ -109,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
loop.
.. rubric:: default-loop/main.c
.. literalinclude:: ../../code/default-loop/main.c
:language: c
:linenos:
.. note::
node.js uses the default loop as its main loop. If you are writing bindings
@ -121,7 +126,7 @@ 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`_.
.. _constants: http://docs.libuv.org/en/v1.x/errors.html#error-constants
.. _constants: https://docs.libuv.org/en/v1.x/errors.html#error-constants
You can use the ``uv_strerror(int)`` and ``uv_err_name(int)`` functions
to get a ``const char *`` describing the error or the error name respectively.
@ -169,6 +174,16 @@ handle is used for.
typedef struct uv_udp_send_s uv_udp_send_t;
typedef struct uv_fs_s uv_fs_t;
typedef struct uv_work_s uv_work_t;
typedef struct uv_random_s uv_random_t;
/* None of the above. */
typedef struct uv_env_item_s uv_env_item_t;
typedef struct uv_cpu_info_s uv_cpu_info_t;
typedef struct uv_interface_address_s uv_interface_address_t;
typedef struct uv_dirent_s uv_dirent_t;
typedef struct uv_passwd_s uv_passwd_t;
typedef struct uv_utsname_s uv_utsname_t;
typedef struct uv_statfs_s uv_statfs_t;
Handles represent long-lived objects. Async operations on such handles are

View File

@ -13,7 +13,7 @@ Simple filesystem read/write is achieved using the ``uv_fs_*`` functions and the
watchers registered with the event loop when application interaction is
required.
.. _thread pool: http://docs.libuv.org/en/v1.x/threadpool.html#thread-pool-work-scheduling
.. _thread pool: https://docs.libuv.org/en/v1.x/threadpool.html#thread-pool-work-scheduling
All filesystem functions have two forms - *synchronous* and *asynchronous*.
@ -66,7 +66,7 @@ The ``result`` field of a ``uv_fs_t`` is the file descriptor in case of the
.. literalinclude:: ../../code/uvcat/main.c
:language: c
:linenos:
:lines: 26-40
:lines: 26-39
:emphasize-lines: 2,8,12
In the case of a read call, you should pass an *initialized* buffer which will
@ -91,7 +91,7 @@ callbacks.
.. literalinclude:: ../../code/uvcat/main.c
:language: c
:linenos:
:lines: 16-24
:lines: 17-24
:emphasize-lines: 6
.. warning::
@ -132,6 +132,7 @@ same patterns as the read/write/open calls, returning the result in the
int uv_fs_copyfile(uv_loop_t* loop, uv_fs_t* req, const char* path, const char* new_path, int flags, uv_fs_cb cb);
int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, uv_fs_cb cb);
int uv_fs_mkdtemp(uv_loop_t* loop, uv_fs_t* req, const char* tpl, uv_fs_cb cb);
int uv_fs_mkstemp(uv_loop_t* loop, uv_fs_t* req, const char* tpl, uv_fs_cb cb);
int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb);
int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent);
@ -149,6 +150,7 @@ same patterns as the read/write/open calls, returning the result in the
int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode, uv_fs_cb cb);
int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, double mtime, uv_fs_cb cb);
int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime, double mtime, uv_fs_cb cb);
int uv_fs_lutime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, double mtime, uv_fs_cb cb);
int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path, const char* new_path, uv_fs_cb cb);
int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path, const char* new_path, int flags, uv_fs_cb cb);
@ -158,6 +160,7 @@ same patterns as the read/write/open calls, returning the result in the
int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_uid_t uid, uv_gid_t gid, uv_fs_cb cb);
int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_uid_t uid, uv_gid_t gid, uv_fs_cb cb);
int uv_fs_lchown(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_uid_t uid, uv_gid_t gid, uv_fs_cb cb);
int uv_fs_statfs(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb);
.. _buffers-and-streams:
@ -190,7 +193,7 @@ and freed by the application.
.. ERROR::
THIS PROGRAM DOES NOT ALWAYS WORK, NEED SOMETHING BETTER**
**THIS PROGRAM DOES NOT ALWAYS WORK, NEED SOMETHING BETTER**
To demonstrate streams we will need to use ``uv_pipe_t``. This allows streaming
local files [#]_. Here is a simple tee utility using libuv. Doing all operations
@ -209,7 +212,7 @@ opened as bidirectional by default.
.. literalinclude:: ../../code/uvtee/main.c
:language: c
:linenos:
:lines: 61-80
:lines: 62-80
:emphasize-lines: 4,5,15
The third argument of ``uv_pipe_init()`` should be set to 1 for IPC using named
@ -285,6 +288,13 @@ a command whenever any of the watched files change::
./onchange <command> <file1> [file2] ...
.. note::
Currently this example only works on OSX and Windows.
Refer to the `notes of uv_fs_event_start`_ function.
.. _notes of uv_fs_event_start: https://docs.libuv.org/en/v1.x/fs_event.html#c.uv_fs_event_start
The file change notification is started using ``uv_fs_event_init()``:
.. rubric:: onchange/main.c - The setup
@ -319,9 +329,9 @@ The callback will receive the following arguments:
#. ``const char *filename`` - If a directory is being monitored, this is the
file which was changed. Only non-``null`` on Linux and Windows. May be ``null``
even on those platforms.
#. ``int flags`` - one of ``UV_RENAME`` or ``UV_CHANGE``, or a bitwise OR of
#. ``int events`` - one of ``UV_RENAME`` or ``UV_CHANGE``, or a bitwise OR of
both.
#. ``int status`` - Currently 0.
#. ``int status`` - If ``status < 0``, there is an :ref:`libuv error<libuv-error-handling>`.
In our example we simply print the arguments and run the command using
``system()``.

View File

@ -8,7 +8,7 @@ It is meant to cover the main areas of libuv, but is not a comprehensive
reference discussing every function and data structure. The `official libuv
documentation`_ may be consulted for full details.
.. _official libuv documentation: http://docs.libuv.org/en/v1.x/
.. _official libuv documentation: https://docs.libuv.org/en/v1.x/
This book is still a work in progress, so sections may be incomplete, but
I hope you will enjoy it as it grows.
@ -47,25 +47,23 @@ Since then libuv has continued to mature and become a high quality standalone
library for system programming. Users outside of node.js include Mozilla's
Rust_ programming language, and a variety_ of language bindings.
This book and the code is based on libuv version `v1.3.0`_.
This book and the code is based on libuv version `v1.42.0`_.
Code
----
All the code from this book is included as part of the source of the book on
Github. `Clone`_/`Download`_ the book, then build libuv::
All the example code and the source of the book is included as part of
the libuv_ project on GitHub.
Clone or Download libuv_, then build it::
cd libuv
./autogen.sh
sh autogen.sh
./configure
make
There is no need to ``make install``. To build the examples run ``make`` in the
``code/`` directory.
``docs/code/`` directory.
.. _Clone: https://github.com/nikhilm/uvbook
.. _Download: https://github.com/nikhilm/uvbook/downloads
.. _v1.3.0: https://github.com/libuv/libuv/tags
.. _v1.42.0: https://github.com/libuv/libuv/releases/tag/v1.42.0
.. _V8: https://v8.dev
.. _libev: http://software.schmorp.de/pkg/libev.html
.. _libuv: https://github.com/libuv/libuv

View File

@ -164,7 +164,7 @@ IPv6 stack only
IPv6 sockets can be used for both IPv4 and IPv6 communication. If you want to
restrict the socket to IPv6 only, pass the ``UV_UDP_IPV6ONLY`` flag to
``uv_udp_bind`` [#]_.
``uv_udp_bind``.
Multicast
~~~~~~~~~
@ -250,7 +250,6 @@ times, with each address being reported once.
----
.. [#] https://beej.us/guide/bgnet/html/#broadcast-packetshello-world
.. [#] on Windows only supported on Windows Vista and later.
.. [#] https://www.tldp.org/HOWTO/Multicast-HOWTO-6.html#ss6.1
.. [#] libuv use the system ``getaddrinfo`` in the libuv threadpool. libuv
v0.8.0 and earlier also included c-ares_ as an alternative, but this has been

View File

@ -53,6 +53,8 @@ ID of the child process.
The exit callback will be invoked with the *exit status* and the type of *signal*
which caused the exit.
Note that it is important **not** to call ``uv_close`` before the exit callback.
.. rubric:: spawn/main.c
.. literalinclude:: ../../code/spawn/main.c
:language: c
@ -126,7 +128,8 @@ of ``uv_kill`` is::
For processes started using libuv, you may use ``uv_process_kill`` instead,
which accepts the ``uv_process_t`` watcher as the first argument, rather than
the pid. In this case, **remember to call** ``uv_close`` on the watcher.
the pid. In this case, **remember to call** ``uv_close`` on the watcher _after_
the exit callback has been called.
Signals
-------
@ -330,7 +333,7 @@ to hand off their I/O to other processes. Applications include load-balancing
servers, worker processes and other ways to make optimum use of CPU. libuv only
supports sending **TCP sockets or other pipes** over pipes for now.
To demonstrate, we will look at a echo server implementation that hands of
To demonstrate, we will look at an echo server implementation that hands off
clients to worker processes in a round-robin fashion. This program is a bit
involved, and while only snippets are included in the book, it is recommended
to read the full code to really understand it.

View File

@ -220,7 +220,7 @@ progress with the download whenever libuv notifies of I/O readiness.
.. literalinclude:: ../../code/uvwget/main.c
:language: c
:linenos:
:lines: 1-9,140-
:lines: 1-9,142-
:emphasize-lines: 7,21,24-25
The way each library is integrated with libuv will vary. In the case of
@ -235,7 +235,7 @@ Our downloader is to be invoked as::
$ ./uvwget [url1] [url2] ...
So we add each argument as an URL
So we add each argument as a URL
.. rubric:: uvwget/main.c - Adding urls
.. literalinclude:: ../../code/uvwget/main.c
@ -363,7 +363,7 @@ to get the error message.
argument. ``init_plugin_function`` is a function pointer to the sort of
function we are looking for in the application's plugins.
.. _shared libraries: https://en.wikipedia.org/wiki/Shared_library#Shared_libraries
.. _shared libraries: https://en.wikipedia.org/wiki/Shared_library
TTY
---

View File

@ -94,7 +94,7 @@ Public members
.. c:member:: uv_handle_type uv_handle_t.type
The :c:type:`uv_handle_type`, indicating the type of the underlying handle. Readonly.
The :c:enum:`uv_handle_type`, indicating the type of the underlying handle. Readonly.
.. c:member:: void* uv_handle_t.data
@ -153,6 +153,9 @@ API
In-progress requests, like uv_connect_t or uv_write_t, are cancelled and
have their callbacks called asynchronously with status=UV_ECANCELED.
`close_cb` can be `NULL` in cases where no cleanup or deallocation is
necessary.
.. c:function:: void uv_ref(uv_handle_t* handle)
Reference the given handle. References are idempotent, that is, if a handle
@ -245,7 +248,7 @@ just for some handle types.
.. versionadded:: 1.19.0
.. c:function:: void* uv_handle_set_data(uv_handle_t* handle, void* data)
.. c:function:: void uv_handle_set_data(uv_handle_t* handle, void* data)
Sets `handle->data` to `data`.

View File

@ -58,5 +58,5 @@ libuv can be downloaded from `here <https://dist.libuv.org/dist/>`_.
Installation
------------
Installation instructions can be found in `the README <https://github.com/libuv/libuv/blob/master/README.md>`_.
Installation instructions can be found in the `README <https://github.com/libuv/libuv/blob/master/README.md>`_.

View File

@ -16,6 +16,19 @@ Data types
Loop data type.
.. c:enum:: uv_loop_option
Additional loop options.
See :c:func:`uv_loop_configure`.
::
typedef enum {
UV_LOOP_BLOCK_SIGNAL = 0,
UV_METRICS_IDLE_TIME,
UV_LOOP_USE_IO_URING_SQPOLL
} uv_loop_option;
.. c:enum:: uv_run_mode
Mode used to run the loop with :c:func:`uv_run`.
@ -73,8 +86,13 @@ API
This option is necessary to use :c:func:`uv_metrics_idle_time`.
- UV_LOOP_ENABLE_IO_URING_SQPOLL: Enable SQPOLL io_uring instance to handle
asynchronous file system operations.
.. versionchanged:: 1.39.0 added the UV_METRICS_IDLE_TIME option.
.. versionchanged:: 1.49.0 added the UV_LOOP_ENABLE_IO_URING_SQPOLL option.
.. c:function:: int uv_loop_close(uv_loop_t* loop)
Releases all internal loop resources. Call this function only when the loop
@ -238,7 +256,7 @@ API
.. versionadded:: 1.19.0
.. c:function:: void* uv_loop_set_data(uv_loop_t* loop, void* data)
.. c:function:: void uv_loop_set_data(uv_loop_t* loop, void* data)
Sets `loop->data` to `data`.

View File

@ -4,8 +4,46 @@
Metrics operations
======================
libuv provides a metrics API to track the amount of time the event loop has
spent idle in the kernel's event provider.
libuv provides a metrics API to track various internal operations of the event
loop.
Data types
----------
.. c:type:: uv_metrics_t
The struct that contains event loop metrics. It is recommended to retrieve
these metrics in a :c:type:`uv_prepare_cb` in order to make sure there are
no inconsistencies with the metrics counters.
::
typedef struct {
uint64_t loop_count;
uint64_t events;
uint64_t events_waiting;
/* private */
uint64_t* reserved[13];
} uv_metrics_t;
Public members
^^^^^^^^^^^^^^
.. c:member:: uint64_t uv_metrics_t.loop_count
Number of event loop iterations.
.. c:member:: uint64_t uv_metrics_t.events
Number of events that have been processed by the event handler.
.. c:member:: uint64_t uv_metrics_t.events_waiting
Number of events that were waiting to be processed when the event provider
was called.
API
---
@ -25,3 +63,9 @@ API
:c:type:`UV_METRICS_IDLE_TIME`.
.. versionadded:: 1.39.0
.. c:function:: int uv_metrics_info(uv_loop_t* loop, uv_metrics_t* metrics)
Copy the current set of event loop metrics to the ``metrics`` pointer.
.. versionadded:: 1.45.0

View File

@ -73,7 +73,8 @@ Data types
.. c:type:: uv_timeval_t
Data type for storing times.
Y2K38-unsafe data type for storing times with microsecond resolution.
Will be replaced with :c:type:`uv_timeval64_t` in libuv v2.0.
::
@ -84,7 +85,7 @@ Data types
.. c:type:: uv_timeval64_t
Alternative data type for storing times.
Y2K38-safe data type for storing times with microsecond resolution.
::
@ -93,6 +94,28 @@ Data types
int32_t tv_usec;
} uv_timeval64_t;
.. c:type:: uv_timespec64_t
Y2K38-safe data type for storing times with nanosecond resolution.
::
typedef struct {
int64_t tv_sec;
int32_t tv_nsec;
} uv_timespec64_t;
.. c:enum:: uv_clock_id
Clock source for :c:func:`uv_clock_gettime`.
::
typedef enum {
UV_CLOCK_MONOTONIC,
UV_CLOCK_REALTIME
} uv_clock_id;
.. c:type:: uv_rusage_t
Data type for resource usage results.
@ -119,7 +142,10 @@ Data types
} uv_rusage_t;
Members marked with `(X)` are unsupported on Windows.
See :man:`getrusage(2)` for supported fields on Unix
See :man:`getrusage(2)` for supported fields on UNIX-like platforms.
The maximum resident set size is reported in kilobytes, the unit most
platforms use natively.
.. c:type:: uv_cpu_info_t
@ -173,6 +199,18 @@ Data types
char* homedir;
} uv_passwd_t;
.. c:type:: uv_group_t
Data type for group file information.
::
typedef struct uv_group_s {
char* groupname;
unsigned long gid;
char** members;
} uv_group_t;
.. c:type:: uv_utsname_t
Data type for operating system name and version information.
@ -211,7 +249,7 @@ API
type of the stdio streams.
For :man:`isatty(3)` equivalent functionality use this function and test
for ``UV_TTY``.
for `UV_TTY`.
.. c:function:: int uv_replace_allocator(uv_malloc_func malloc_func, uv_realloc_func realloc_func, uv_calloc_func calloc_func, uv_free_func free_func)
@ -225,8 +263,8 @@ API
after all resources have been freed and thus libuv doesn't reference
any allocated memory chunk.
On success, it returns 0, if any of the function pointers is NULL it
returns UV_EINVAL.
On success, it returns 0, if any of the function pointers is `NULL` it
returns `UV_EINVAL`.
.. warning:: There is no protection against changing the allocator multiple
times. If the user changes it they are responsible for making
@ -312,7 +350,7 @@ API
.. c:function:: int uv_uptime(double* uptime)
Gets the current system uptime.
Gets the current system uptime. Depending on the system full or fractional seconds are returned.
.. c:function:: int uv_getrusage(uv_rusage_t* rusage)
@ -322,6 +360,17 @@ API
On Windows not all fields are set, the unsupported fields are filled with zeroes.
See :c:type:`uv_rusage_t` for more details.
.. c:function:: int uv_getrusage_thread(uv_rusage_t* rusage)
Gets the resource usage measures for the calling thread.
.. versionadded:: 1.50.0
.. note::
Not supported on all platforms. May return `UV_ENOTSUP`.
On macOS and Windows not all fields are set, the unsupported fields are filled with zeroes.
See :c:type:`uv_rusage_t` for more details.
.. c:function:: uv_pid_t uv_os_getpid(void)
Returns the current process ID.
@ -334,15 +383,41 @@ API
.. versionadded:: 1.16.0
.. c:function:: unsigned int uv_available_parallelism(void)
Returns an estimate of the default amount of parallelism a program should
use. Always returns a non-zero value.
On Linux, inspects the calling thread's CPU affinity mask to determine if
it has been pinned to specific CPUs.
On Windows, the available parallelism may be underreported on systems with
more than 64 logical CPUs.
On other platforms, reports the number of CPUs that the operating system
considers to be online.
.. versionadded:: 1.44.0
.. c:function:: int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count)
Gets information about the CPUs on the system. The `cpu_infos` array will
have `count` elements and needs to be freed with :c:func:`uv_free_cpu_info`.
Use :c:func:`uv_available_parallelism` if you need to know how many CPUs
are available for threads or child processes.
.. c:function:: void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count)
Frees the `cpu_infos` array previously allocated with :c:func:`uv_cpu_info`.
.. c:function:: int uv_cpumask_size(void)
Returns the maximum size of the mask used for process/thread affinities,
or `UV_ENOTSUP` if affinities are not supported on the current platform.
.. versionadded:: 1.45.0
.. c:function:: int uv_interface_addresses(uv_interface_address_t** addresses, int* count)
Gets address information about the network interfaces on the system. An
@ -514,6 +589,35 @@ API
.. versionadded:: 1.9.0
.. c:function:: int uv_os_get_passwd2(uv_passwd_t* pwd, uv_uid_t uid)
Gets a subset of the password file entry for the provided uid.
The populated data includes the username, euid, gid, shell,
and home directory. On non-Windows systems, all data comes from
:man:`getpwuid_r(3)`. On Windows, uid and gid are set to -1 and have no
meaning, and shell is `NULL`. After successfully calling this function, the
memory allocated to `pwd` needs to be freed with
:c:func:`uv_os_free_passwd`.
.. versionadded:: 1.45.0
.. c:function:: int uv_os_get_group(uv_group_t* group, uv_uid_t gid)
Gets a subset of the group file entry for the provided uid.
The populated data includes the group name, gid, and members. On non-Windows
systems, all data comes from :man:`getgrgid_r(3)`. On Windows, uid and gid
are set to -1 and have no meaning. After successfully calling this function,
the memory allocated to `group` needs to be freed with
:c:func:`uv_os_free_group`.
.. versionadded:: 1.45.0
.. c:function:: void uv_os_free_group(uv_passwd_t* pwd)
Frees the memory previously allocated with :c:func:`uv_os_get_group`.
.. versionadded:: 1.45.0
.. c:function:: void uv_os_free_passwd(uv_passwd_t* pwd)
Frees the `pwd` memory previously allocated with :c:func:`uv_os_get_passwd`.
@ -522,18 +626,21 @@ API
.. c:function:: uint64_t uv_get_free_memory(void)
Gets the amount of free memory available in the system, as reported by the kernel (in bytes).
Gets the amount of free memory available in the system, as reported by
the kernel (in bytes). Returns 0 when unknown.
.. c:function:: uint64_t uv_get_total_memory(void)
Gets the total amount of physical memory in the system (in bytes).
Returns 0 when unknown.
.. c:function:: uint64_t uv_get_constrained_memory(void)
Gets the amount of memory available to the process (in bytes) based on
Gets the total amount of memory available to the process (in bytes) based on
limits imposed by the OS. If there is no such constraint, or the constraint
is unknown, `0` is returned. Note that it is not unusual for this value to
be less than or greater than :c:func:`uv_get_total_memory`.
is unknown, `0` is returned. If there is a constraining mechanism, but there
is no constraint set, `UINT64_MAX` is returned. Note that it is not unusual
for this value to be less than or greater than :c:func:`uv_get_total_memory`.
.. note::
This function currently only returns a non-zero value on Linux, based
@ -541,9 +648,23 @@ API
.. versionadded:: 1.29.0
.. c:function:: uint64_t uv_get_available_memory(void)
Gets the amount of free memory that is still available to the process (in bytes).
This differs from :c:func:`uv_get_free_memory` in that it takes into account any
limits imposed by the OS. If there is no such constraint, or the constraint
is unknown, the amount returned will be identical to :c:func:`uv_get_free_memory`.
.. note::
This function currently only returns a value that is different from
what :c:func:`uv_get_free_memory` reports on Linux, based
on cgroups if it is present.
.. versionadded:: 1.45.0
.. c:function:: uint64_t uv_hrtime(void)
Returns the current high-resolution real time. This is expressed in
Returns the current high-resolution timestamp. This is expressed in
nanoseconds. It is relative to an arbitrary time in the past. It is not
related to the time of day and therefore not subject to clock drift. The
primary use is for measuring performance between intervals.
@ -552,6 +673,19 @@ API
Not every platform can support nanosecond resolution; however, this value will always
be in nanoseconds.
.. c:function:: int uv_clock_gettime(uv_clock_id clock_id, uv_timespec64_t* ts)
Obtain the current system time from a high-resolution real-time or monotonic
clock source.
The real-time clock counts from the UNIX epoch (1970-01-01) and is subject
to time adjustments; it can jump back in time.
The monotonic clock counts from an arbitrary point in the past and never
jumps back in time.
.. versionadded:: 1.45.0
.. c:function:: void uv_print_all_handles(uv_loop_t* loop, FILE* stream)
Prints all handles associated with the given `loop` to the given `stream`.
@ -757,3 +891,50 @@ API
Causes the calling thread to sleep for `msec` milliseconds.
.. versionadded:: 1.34.0
String manipulation functions
-----------------------------
These string utilities are needed internally for dealing with Windows, and are
exported to allow clients to work uniformly with this data when the libuv API
is not complete.
.. c:function:: size_t uv_utf16_length_as_wtf8(const uint16_t* utf16, ssize_t utf16_len)
Get the length of a UTF-16 (or UCS-2) `utf16` value after converting it to
WTF-8. If `utf16` is NUL terminated, `utf16_len` can be set to -1,
otherwise it must be specified.
.. versionadded:: 1.47.0
.. c:function:: int uv_utf16_to_wtf8(const uint16_t* utf16, ssize_t utf16_len, char** wtf8_ptr, size_t* wtf8_len_ptr)
Convert UTF-16 (or UCS-2) data in `utf16` to WTF-8 data in `*wtf8_ptr`. The
`utf16_len` count (in characters) gives the length of `utf16`. If `utf16`
is NUL terminated, `utf16_len` can be set to -1, otherwise it must be
specified. If `wtf8_ptr` is `NULL`, no result will be computed, but the
length (equal to `uv_utf16_length_as_wtf8`) will be stored in `wtf8_ptr`.
If `*wtf8_ptr` is `NULL`, space for the conversion will be allocated and
returned in `wtf8_ptr` and the length will be returned in `wtf8_len_ptr`.
Otherwise, the length of `*wtf8_ptr` must be passed in `wtf8_len_ptr`. The
`wtf8_ptr` must contain an extra space for an extra NUL after the result.
If the result is truncated, `UV_ENOBUFS` will be returned and
`wtf8_len_ptr` will be the length of the required `wtf8_ptr` to contain the
whole result.
.. versionadded:: 1.47.0
.. c:function:: ssize_t uv_wtf8_length_as_utf16(const char* wtf8)
Get the length in characters of a NUL-terminated WTF-8 `wtf8` value
after converting it to UTF-16 (or UCS-2), including NUL terminator.
.. versionadded:: 1.47.0
.. c:function:: void uv_wtf8_to_utf16(const char* utf8, uint16_t* utf16, size_t utf16_len)
Convert NUL-terminated WTF-8 data in `wtf8` to UTF-16 (or UCS-2) data
in `utf16`. The `utf16_len` count (in characters) must include space
for the NUL terminator.
.. versionadded:: 1.47.0

View File

@ -55,17 +55,61 @@ API
Bind the pipe to a file path (Unix) or a name (Windows).
Does not support Linux abstract namespace sockets,
unlike :c:func:`uv_pipe_bind2`.
Alias for ``uv_pipe_bind2(handle, name, strlen(name), 0)``.
.. note::
Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes, typically between
92 and 108 bytes.
Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes,
typically between 92 and 108 bytes.
.. c:function:: int uv_pipe_bind2(uv_pipe_t* handle, const char* name, size_t namelen, unsigned int flags)
Bind the pipe to a file path (Unix) or a name (Windows).
``flags`` must be zero or ``UV_PIPE_NO_TRUNCATE``. Returns ``UV_EINVAL``
for unsupported flags without performing the bind operation.
Supports Linux abstract namespace sockets. ``namelen`` must include
the leading nul byte but not the trailing nul byte.
.. versionadded:: 1.46.0
.. note::
Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes,
typically between 92 and 108 bytes, unless the ``UV_PIPE_NO_TRUNCATE``
flag is specified, in which case an ``UV_EINVAL`` error is returned.
.. c:function:: void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, const char* name, uv_connect_cb cb)
Connect to the Unix domain socket or the named pipe.
Connect to the Unix domain socket or the Windows named pipe.
Does not support Linux abstract namespace sockets,
unlike :c:func:`uv_pipe_connect2`.
Alias for ``uv_pipe_connect2(req, handle, name, strlen(name), 0, cb)``.
.. note::
Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes, typically between
92 and 108 bytes.
Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes,
typically between 92 and 108 bytes.
.. c:function:: void uv_pipe_connect2(uv_connect_t* req, uv_pipe_t* handle, const char* name, size_t namelen, unsigned int flags, uv_connect_cb cb)
Connect to the Unix domain socket or the Windows named pipe.
``flags`` must be zero or ``UV_PIPE_NO_TRUNCATE``. Returns ``UV_EINVAL``
for unsupported flags without performing the connect operation.
Supports Linux abstract namespace sockets. ``namelen`` must include
the leading nul byte but not the trailing nul byte.
.. versionadded:: 1.46.0
.. note::
Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes,
typically between 92 and 108 bytes, unless the ``UV_PIPE_NO_TRUNCATE``
flag is specified, in which case an ``UV_EINVAL`` error is returned.
.. c:function:: int uv_pipe_getsockname(const uv_pipe_t* handle, char* buffer, size_t* size)

View File

@ -45,7 +45,7 @@ Data types
Type definition for callback passed to :c:func:`uv_poll_start`.
.. c:type:: uv_poll_event
.. c:enum:: uv_poll_event
Poll event types
@ -101,7 +101,9 @@ API
with one of the `UV_E*` error codes (see :ref:`errors`). The user should
not close the socket while the handle is active. If the user does that
anyway, the callback *may* be called reporting an error status, but this is
**not** guaranteed.
**not** guaranteed. If `status == UV_EBADF` polling is discontinued for the
file handle and no further events will be reported. The user should
then call :c:func:`uv_close` on the handle.
.. note::
Calling :c:func:`uv_poll_start` on a handle that is already active is

View File

@ -40,7 +40,7 @@ Data types
will indicate the exit status and the signal that caused the process to
terminate, if any.
.. c:type:: uv_process_flags
.. c:enum:: uv_process_flags
Flags to be set on the flags field of :c:type:`uv_process_options_t`.
@ -85,7 +85,14 @@ Data types
* option is only meaningful on Windows systems. On Unix it is silently
* ignored.
*/
UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6)
UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6),
/*
* On Windows, if the path to the program to execute, specified in
* uv_process_options_t's file field, has a directory component,
* search for the exact file name before trying variants with
* extensions like '.exe' or '.cmd'.
*/
UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME = (1 << 7)
};
.. c:type:: uv_stdio_container_t
@ -109,10 +116,39 @@ Data types
::
typedef enum {
/*
* The following four options are mutually-exclusive, and define
* the operation to perform for the corresponding file descriptor
* in the child process:
*/
/*
* No file descriptor will be provided (or redirected to
* `/dev/null` if it is fd 0, 1 or 2).
*/
UV_IGNORE = 0x00,
/*
* Open a new pipe into `data.stream`, per the flags below. The
* `data.stream` field must point to a uv_pipe_t object that has
* been initialized with `uv_pipe_init(loop, data.stream, ipc);`,
* but not yet opened or connected.
/*
UV_CREATE_PIPE = 0x01,
/*
* The child process will be given a duplicate of the parent's
* file descriptor given by `data.fd`.
*/
UV_INHERIT_FD = 0x02,
/*
* The child process will be given a duplicate of the parent's
* file descriptor being used by the stream handle given by
* `data.stream`.
*/
UV_INHERIT_STREAM = 0x04,
/*
* When UV_CREATE_PIPE is specified, UV_READABLE_PIPE and UV_WRITABLE_PIPE
* determine the direction of flow, from the child process' perspective. Both
@ -120,6 +156,7 @@ Data types
*/
UV_READABLE_PIPE = 0x10,
UV_WRITABLE_PIPE = 0x20,
/*
* When UV_CREATE_PIPE is specified, specifying UV_NONBLOCK_PIPE opens the
* handle in non-blocking mode in the child. This may cause loss of data,
@ -153,7 +190,7 @@ Public members
Command line arguments. args[0] should be the path to the program. On
Windows this uses `CreateProcess` which concatenates the arguments into a
string this can cause some strange errors. See the
``UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS`` flag on :c:type:`uv_process_flags`.
``UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS`` flag on :c:enum:`uv_process_flags`.
.. c:member:: char** uv_process_options_t.env
@ -166,7 +203,7 @@ Public members
.. c:member:: unsigned int uv_process_options_t.flags
Various flags that control how :c:func:`uv_spawn` behaves. See
:c:type:`uv_process_flags`.
:c:enum:`uv_process_flags`.
.. c:member:: int uv_process_options_t.stdio_count
.. c:member:: uv_stdio_container_t* uv_process_options_t.stdio
@ -232,6 +269,9 @@ API
.. versionchanged:: 1.24.0 Added `UV_PROCESS_WINDOWS_HIDE_CONSOLE` and
`UV_PROCESS_WINDOWS_HIDE_GUI` flags.
.. versionchanged:: 1.48.0 Added the
`UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME` flag.
.. c:function:: int uv_process_kill(uv_process_t* handle, int signum)
Sends the specified signal to the given process handle. Check the documentation

View File

@ -21,17 +21,9 @@ Data types
Union of all request types.
.. c:enum:: uv_req_type
Public members
^^^^^^^^^^^^^^
.. c:member:: void* uv_req_t.data
Space for user-defined arbitrary data. libuv does not use this field.
.. c:member:: uv_req_type uv_req_t.type
Indicated the type of request. Readonly.
The kind of the libuv request.
::
@ -50,6 +42,18 @@ Public members
} uv_req_type;
Public members
^^^^^^^^^^^^^^
.. c:member:: void* uv_req_t.data
Space for user-defined arbitrary data. libuv does not use this field.
.. c:member:: uv_req_type uv_req_t.type
The :c:enum:`uv_req_type`, indicating the type of the request. Readonly.
API
---
@ -95,7 +99,7 @@ API
.. versionadded:: 1.19.0
.. c:function:: void* uv_req_set_data(uv_req_t* req, void* data)
.. c:function:: void uv_req_set_data(uv_req_t* req, void* data)
Sets `req->data` to `data`.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -16,6 +16,28 @@ Data types
TCP handle type.
.. c:enum:: uv_tcp_flags
Flags used in :c:func:`uv_tcp_bind`.
::
enum uv_tcp_flags {
/* Used with uv_tcp_bind, when an IPv6 address is used. */
UV_TCP_IPV6ONLY = 1,
/* Enable SO_REUSEPORT socket option when binding the handle.
* This allows completely duplicate bindings by multiple processes
* or threads if they all set SO_REUSEPORT before binding the port.
* Incoming connections are distributed across the participating
* listener sockets.
*
* This flag is available only on Linux 3.9+, DragonFlyBSD 3.6+,
* FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+ for now.
*/
UV_TCP_REUSEPORT = 2,
};
Public members
^^^^^^^^^^^^^^
@ -65,6 +87,10 @@ API
at the end of this procedure, then the handle is destroyed with a
``UV_ETIMEDOUT`` error passed to the corresponding callback.
If `delay` is less than 1 then ``UV_EINVAL`` is returned.
.. versionchanged:: 1.49.0 If `delay` is less than 1 then ``UV_EINVAL``` is returned.
.. c:function:: int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable)
Enable / disable simultaneous asynchronous accept requests that are
@ -77,16 +103,34 @@ API
.. c:function:: int uv_tcp_bind(uv_tcp_t* handle, const struct sockaddr* addr, unsigned int flags)
Bind the handle to an address and port. `addr` should point to an
initialized ``struct sockaddr_in`` or ``struct sockaddr_in6``.
Bind the handle to an address and port.
When the port is already taken, you can expect to see an ``UV_EADDRINUSE``
error from :c:func:`uv_listen` or :c:func:`uv_tcp_connect`. That is,
a successful call to this function does not guarantee that the call
to :c:func:`uv_listen` or :c:func:`uv_tcp_connect` will succeed as well.
error from :c:func:`uv_listen` or :c:func:`uv_tcp_connect` unless you specify
``UV_TCP_REUSEPORT`` in `flags` for all the binding sockets. That is, a successful
call to this function does not guarantee that the call to :c:func:`uv_listen` or
:c:func:`uv_tcp_connect` will succeed as well.
`flags` can contain ``UV_TCP_IPV6ONLY``, in which case dual-stack support
is disabled and only IPv6 is used.
:param handle: TCP handle. It should have been initialized with :c:func:`uv_tcp_init`.
:param addr: Address to bind to. It should point to an initialized ``struct sockaddr_in``
or ``struct sockaddr_in6``.
:param flags: Flags that control the behavior of binding the socket.
``UV_TCP_IPV6ONLY`` can be contained in `flags` to disable dual-stack
support and only use IPv6.
``UV_TCP_REUSEPORT`` can be contained in `flags` to enable the socket option
`SO_REUSEPORT` with the capability of load balancing that distribute incoming
connections across all listening sockets in multiple processes or threads.
:returns: 0 on success, or an error code < 0 on failure.
.. versionchanged:: 1.49.0 added the ``UV_TCP_REUSEPORT`` flag.
.. note::
``UV_TCP_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.
.. c:function:: int uv_tcp_getsockname(const uv_tcp_t* handle, struct sockaddr* name, int* namelen)

View File

@ -78,6 +78,14 @@ Threads
.. versionchanged:: 1.4.1 returns a UV_E* error code on failure
.. c:function:: int uv_thread_detach(uv_thread_t* tid)
Detaches a thread. Detached threads automatically release their
resources upon termination, eliminating the need for the application to
call `uv_thread_join`.
.. versionadded:: 1.50.0
.. c:function:: int uv_thread_create_ex(uv_thread_t* tid, const uv_thread_options_t* params, uv_thread_cb entry, void* arg)
Like :c:func:`uv_thread_create`, but additionally specifies options for creating a new thread.
@ -88,10 +96,89 @@ Threads
.. versionadded:: 1.26.0
.. c:function:: int uv_thread_setaffinity(uv_thread_t* tid, char* cpumask, char* oldmask, size_t mask_size)
Sets the specified thread's affinity to cpumask, which is specified in
bytes. Optionally returning the previous affinity setting in oldmask.
On Unix, uses :man:`pthread_getaffinity_np(3)` to get the affinity setting
and maps the cpu_set_t to bytes in oldmask. Then maps the bytes in cpumask
to a cpu_set_t and uses :man:`pthread_setaffinity_np(3)`. On Windows, maps
the bytes in cpumask to a bitmask and uses SetThreadAffinityMask() which
returns the previous affinity setting.
The mask_size specifies the number of entries (bytes) in cpumask / oldmask,
and must be greater-than-or-equal-to :c:func:`uv_cpumask_size`.
.. note::
Thread affinity setting is not atomic on Windows. Unsupported on macOS.
.. versionadded:: 1.45.0
.. c:function:: int uv_thread_getaffinity(uv_thread_t* tid, char* cpumask, size_t mask_size)
Gets the specified thread's affinity setting. On Unix, this maps the
cpu_set_t returned by :man:`pthread_getaffinity_np(3)` to bytes in cpumask.
The mask_size specifies the number of entries (bytes) in cpumask,
and must be greater-than-or-equal-to :c:func:`uv_cpumask_size`.
.. note::
Thread affinity getting is not atomic on Windows. Unsupported on macOS.
.. versionadded:: 1.45.0
.. c:function:: int uv_thread_getcpu(void)
Gets the CPU number on which the calling thread is running.
.. note::
Currently only implemented on Windows, Linux and FreeBSD.
.. versionadded:: 1.45.0
.. c:function:: uv_thread_t uv_thread_self(void)
.. c:function:: int uv_thread_join(uv_thread_t *tid)
.. c:function:: int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2)
.. c:function:: int uv_thread_setname(const char* name)
Sets the name of the current thread. Different platforms define different limits on the max number of characters
a thread name can be: Linux, IBM i (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.
Not supported on Windows Server 2016, returns `UV_ENOSYS`.
.. versionadded:: 1.50.0
.. c:function:: int uv_thread_getname(uv_thread_t* tid, char* name, size_t* size)
Gets the name of the thread specified by `tid`. The thread name is copied, with the trailing NUL, 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
with the trailing NUL.
Not supported on Windows Server 2016, returns `UV_ENOSYS`.
.. versionadded:: 1.50.0
.. c:function:: int uv_thread_setpriority(uv_thread_t tid, int priority)
If the function succeeds, the return value is 0.
If the function fails, the return value is less than zero.
Sets the scheduling priority of the thread specified by tid. It requires elevated
privilege to set specific priorities on some platforms.
The priority can be set to the following constants. UV_THREAD_PRIORITY_HIGHEST,
UV_THREAD_PRIORITY_ABOVE_NORMAL, UV_THREAD_PRIORITY_NORMAL,
UV_THREAD_PRIORITY_BELOW_NORMAL, UV_THREAD_PRIORITY_LOWEST.
.. c:function:: int uv_thread_getpriority(uv_thread_t tid, int* priority)
If the function succeeds, the return value is 0.
If the function fails, the return value is less than zero.
Retrieves the scheduling priority of the thread specified by tid. The value in the
output parameter priority is platform dependent.
For Linux, when schedule policy is SCHED_OTHER (default), priority is 0.
Thread-local storage
^^^^^^^^^^^^^^^^^^^^

View File

@ -14,6 +14,11 @@ is 1024).
.. versionchanged:: 1.30.0 the maximum UV_THREADPOOL_SIZE allowed was increased from 128 to 1024.
.. versionchanged:: 1.45.0 threads now have an 8 MB stack instead of the
(sometimes too low) platform default.
.. versionchanged:: 1.50.0 threads now have a default name of libuv-worker.
The threadpool is global and shared across all event loops. When a particular
function makes use of the threadpool (i.e. when using :c:func:`uv_queue_work`)
libuv preallocates and initializes the maximum number of threads allowed by

View File

@ -6,6 +6,15 @@
Timer handles are used to schedule callbacks to be called in the future.
Timers are either single-shot or repeating. Repeating timers do not adjust
for overhead but are rearmed relative to the event loop's idea of "now".
Libuv updates its idea of "now" right before executing timer callbacks, and
right after waking up from waiting for I/O. See also :c:func:`uv_update_time`.
Example: a repeating timer with a 50 ms interval whose callback takes 17 ms
to complete, runs again 33 ms later. If other tasks take longer than 33 ms,
the timer callback runs as soon as possible.
Data types
----------
@ -64,11 +73,6 @@ API
duration, and will follow normal timer semantics in the case of a
time-slice overrun.
For example, if a 50ms repeating timer first runs for 17ms, it will be
scheduled to run again 33ms later. If other tasks consume more than the
33ms following the first timer callback, then the callback will run as soon
as possible.
.. note::
If the repeat value is set from a timer callback it does not immediately take effect.
If the timer was non-repeating before, it will have been stopped. If it was repeating,

View File

@ -27,10 +27,15 @@ Data types
typedef enum {
/* Initial/normal terminal mode */
UV_TTY_MODE_NORMAL,
/* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
/*
* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled).
* May become equivalent to UV_TTY_MODE_RAW_VT in future libuv versions.
*/
UV_TTY_MODE_RAW,
/* Binary-safe I/O mode for IPC (Unix-only) */
UV_TTY_MODE_IO
UV_TTY_MODE_IO,
/* Raw input mode. On Windows ENABLE_VIRTUAL_TERMINAL_INPUT is also set. */
UV_TTY_MODE_RAW_VT
} uv_tty_mode_t;
.. c:enum:: uv_tty_vtermstate_t
@ -98,7 +103,7 @@ API
.. c:function:: int uv_tty_set_mode(uv_tty_t* handle, uv_tty_mode_t mode)
.. versionchanged:: 1.2.0: the mode is specified as a
:c:type:`uv_tty_mode_t` value.
:c:enum:`uv_tty_mode_t` value.
Set the TTY using the specified terminal mode.

View File

@ -18,7 +18,7 @@ Data types
UDP send request type.
.. c:type:: uv_udp_flags
.. c:enum:: uv_udp_flags
Flags used in :c:func:`uv_udp_bind` and :c:type:`uv_udp_recv_cb`..
@ -33,12 +33,14 @@ Data types
*/
UV_UDP_PARTIAL = 2,
/*
* Indicates if SO_REUSEADDR will be set when binding the handle in
* uv_udp_bind.
* This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other
* Unix platforms, it sets the SO_REUSEADDR flag. What that means is that
* multiple threads or processes can bind to the same address without error
* (provided they all set the flag) but only the last one to bind will receive
* Indicates if SO_REUSEADDR will be set when binding the handle.
* This sets the SO_REUSEPORT socket flag on the BSDs (except for
* DragonFlyBSD), OS X, and other platforms where SO_REUSEPORTs don't
* have the capability of load balancing, as the opposite of what
* UV_UDP_REUSEPORT would do. On other Unix platforms, it sets the
* SO_REUSEADDR flag. What that means is that multiple threads or
* processes can bind to the same address without error (provided
* they all set the flag) but only the last one to bind will receive
* any traffic, in effect "stealing" the port from the previous listener.
*/
UV_UDP_REUSEADDR = 4,
@ -56,11 +58,23 @@ Data types
/*
* Indicates if IP_RECVERR/IPV6_RECVERR will be set when binding the handle.
* This sets IP_RECVERR for IPv4 and IPV6_RECVERR for IPv6 UDP sockets on
* Linux. This stops the Linux kernel from supressing some ICMP error messages
* Linux. This stops the Linux kernel from suppressing some ICMP error messages
* and enables full ICMP error reporting for faster failover.
* This flag is no-op on platforms other than Linux.
*/
UV_UDP_LINUX_RECVERR = 32,
/*
* Indicates if SO_REUSEPORT will be set when binding the handle.
* This sets the SO_REUSEPORT socket option on supported platforms.
* Unlike UV_UDP_REUSEADDR, this flag will make multiple threads or
* processes that are binding to the same address and port "share"
* the port, which means incoming datagrams are distributed across
* the receiving sockets among threads or processes.
*
* This flag is available only on Linux 3.9+, DragonFlyBSD 3.6+,
* FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+ for now.
*/
UV_UDP_REUSEPORT = 64,
/*
* Indicates that recvmmsg should be used, if available.
*/
@ -186,11 +200,24 @@ API
with the address and port to bind to.
:param flags: Indicate how the socket will be bound,
``UV_UDP_IPV6ONLY``, ``UV_UDP_REUSEADDR``, and ``UV_UDP_RECVERR``
are supported.
``UV_UDP_IPV6ONLY``, ``UV_UDP_REUSEADDR``, ``UV_UDP_REUSEPORT``,
and ``UV_UDP_RECVERR`` are supported.
: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)
Associate the UDP handle to a remote address and port, so every
@ -285,7 +312,9 @@ API
local sockets.
: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.
@ -296,7 +325,9 @@ API
Set the multicast ttl.
: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.
@ -307,7 +338,9 @@ API
Set the multicast interface to send or receive data on.
: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.
@ -318,7 +351,9 @@ API
Set broadcast on or off.
: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.
@ -329,7 +364,9 @@ API
Set the time to live.
: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.
@ -389,6 +426,20 @@ API
.. 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)
Prepare for receiving data. If the socket has not previously been bound

View File

@ -31,6 +31,7 @@ extern "C" {
#error "Define either BUILDING_UV_SHARED or USING_UV_SHARED, not both."
#endif
#ifndef UV_EXTERN
#ifdef _WIN32
/* Windows - set up dll import/export decorators. */
# if defined(BUILDING_UV_SHARED)
@ -50,17 +51,20 @@ extern "C" {
#else
# define UV_EXTERN /* nothing */
#endif
#endif /* UV_EXTERN */
#include "uv/errno.h"
#include "uv/version.h"
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv/stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
/* Internal type, do not use. */
struct uv__queue {
struct uv__queue* next;
struct uv__queue* prev;
};
#if defined(_WIN32)
# include "uv/win.h"
@ -152,6 +156,9 @@ extern "C" {
XX(EFTYPE, "inappropriate file type or format") \
XX(EILSEQ, "illegal byte sequence") \
XX(ESOCKTNOSUPPORT, "socket type not supported") \
XX(ENODATA, "no data available") \
XX(EUNATCH, "protocol driver not attached") \
XX(ENOEXEC, "exec format error") \
#define UV_HANDLE_TYPE_MAP(XX) \
XX(ASYNC, async) \
@ -247,12 +254,17 @@ typedef struct uv_cpu_info_s uv_cpu_info_t;
typedef struct uv_interface_address_s uv_interface_address_t;
typedef struct uv_dirent_s uv_dirent_t;
typedef struct uv_passwd_s uv_passwd_t;
typedef struct uv_group_s uv_group_t;
typedef struct uv_utsname_s uv_utsname_t;
typedef struct uv_statfs_s uv_statfs_t;
typedef struct uv_metrics_s uv_metrics_t;
typedef enum {
UV_LOOP_BLOCK_SIGNAL = 0,
UV_METRICS_IDLE_TIME
UV_METRICS_IDLE_TIME,
UV_LOOP_USE_IO_URING_SQPOLL
#define UV_LOOP_USE_IO_URING_SQPOLL UV_LOOP_USE_IO_URING_SQPOLL
} uv_loop_option;
typedef enum {
@ -282,13 +294,13 @@ UV_EXTERN int uv_loop_init(uv_loop_t* loop);
UV_EXTERN int uv_loop_close(uv_loop_t* loop);
/*
* NOTE:
* This function is DEPRECATED (to be removed after 0.12), users should
* This function is DEPRECATED, users should
* allocate the loop manually and use uv_loop_init instead.
*/
UV_EXTERN uv_loop_t* uv_loop_new(void);
/*
* NOTE:
* This function is DEPRECATED (to be removed after 0.12). Users should use
* This function is DEPRECATED. Users should use
* uv_loop_close and free the memory manually instead.
*/
UV_EXTERN void uv_loop_delete(uv_loop_t*);
@ -344,11 +356,32 @@ typedef void (*uv_random_cb)(uv_random_t* req,
void* buf,
size_t buflen);
typedef enum {
UV_CLOCK_MONOTONIC,
UV_CLOCK_REALTIME
} uv_clock_id;
/* XXX(bnoordhuis) not 2038-proof, https://github.com/libuv/libuv/issues/3864 */
typedef struct {
long tv_sec;
long tv_nsec;
} uv_timespec_t;
typedef struct {
int64_t tv_sec;
int32_t tv_nsec;
} uv_timespec64_t;
/* XXX(bnoordhuis) not 2038-proof, https://github.com/libuv/libuv/issues/3864 */
typedef struct {
long tv_sec;
long tv_usec;
} uv_timeval_t;
typedef struct {
int64_t tv_sec;
int32_t tv_usec;
} uv_timeval64_t;
typedef struct {
uint64_t st_dev;
@ -437,7 +470,7 @@ struct uv_shutdown_s {
uv_handle_type type; \
/* private */ \
uv_close_cb close_cb; \
void* handle_queue[2]; \
struct uv__queue handle_queue; \
union { \
int fd; \
void* reserved[4]; \
@ -575,7 +608,18 @@ UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
enum uv_tcp_flags {
/* Used with uv_tcp_bind, when an IPv6 address is used. */
UV_TCP_IPV6ONLY = 1
UV_TCP_IPV6ONLY = 1,
/* Enable SO_REUSEPORT socket option when binding the handle.
* This allows completely duplicate bindings by multiple processes
* or threads if they all set SO_REUSEPORT before binding the port.
* Incoming connections are distributed across the participating
* listener sockets.
*
* This flag is available only on Linux 3.9+, DragonFlyBSD 3.6+,
* FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+ for now.
*/
UV_TCP_REUSEPORT = 2,
};
UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle,
@ -616,10 +660,13 @@ enum uv_udp_flags {
UV_UDP_PARTIAL = 2,
/*
* Indicates if SO_REUSEADDR will be set when binding the handle.
* This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other
* Unix platforms, it sets the SO_REUSEADDR flag. What that means is that
* multiple threads or processes can bind to the same address without error
* (provided they all set the flag) but only the last one to bind will receive
* This sets the SO_REUSEPORT socket flag on the BSDs (except for
* DragonFlyBSD), OS X, and other platforms where SO_REUSEPORTs don't
* have the capability of load balancing, as the opposite of what
* UV_UDP_REUSEPORT would do. On other Unix platforms, it sets the
* SO_REUSEADDR flag. What that means is that multiple threads or
* processes can bind to the same address without error (provided
* they all set the flag) but only the last one to bind will receive
* any traffic, in effect "stealing" the port from the previous listener.
*/
UV_UDP_REUSEADDR = 4,
@ -642,6 +689,18 @@ enum uv_udp_flags {
* This flag is no-op on platforms other than Linux.
*/
UV_UDP_LINUX_RECVERR = 32,
/*
* Indicates if SO_REUSEPORT will be set when binding the handle.
* This sets the SO_REUSEPORT socket option on supported platforms.
* Unlike UV_UDP_REUSEADDR, this flag will make multiple threads or
* processes that are binding to the same address and port "share"
* the port, which means incoming datagrams are distributed across
* the receiving sockets among threads or processes.
*
* This flag is available only on Linux 3.9+, DragonFlyBSD 3.6+,
* FreeBSD 12.0+, Solaris 11.4, and AIX 7.2.5+ for now.
*/
UV_UDP_REUSEPORT = 64,
/*
* Indicates that recvmmsg should be used, if available.
*/
@ -718,6 +777,12 @@ UV_EXTERN int uv_udp_try_send(uv_udp_t* handle,
const uv_buf_t bufs[],
unsigned int nbufs,
const struct sockaddr* addr);
UV_EXTERN 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);
UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle,
uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb);
@ -741,10 +806,15 @@ struct uv_tty_s {
typedef enum {
/* Initial/normal terminal mode */
UV_TTY_MODE_NORMAL,
/* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
/*
* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled).
* May become equivalent to UV_TTY_MODE_RAW_VT in future libuv versions.
*/
UV_TTY_MODE_RAW,
/* Binary-safe I/O mode for IPC (Unix-only) */
UV_TTY_MODE_IO
UV_TTY_MODE_IO,
/* Raw input mode. On Windows ENABLE_VIRTUAL_TERMINAL_INPUT is also set. */
UV_TTY_MODE_RAW_VT
} uv_tty_mode_t;
typedef enum {
@ -779,6 +849,10 @@ inline int uv_tty_set_mode(uv_tty_t* handle, int mode) {
UV_EXTERN uv_handle_type uv_guess_handle(uv_file file);
enum {
UV_PIPE_NO_TRUNCATE = 1u << 0
};
/*
* uv_pipe_t is a subclass of uv_stream_t.
*
@ -795,10 +869,20 @@ struct uv_pipe_s {
UV_EXTERN int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc);
UV_EXTERN int uv_pipe_open(uv_pipe_t*, uv_file file);
UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name);
UV_EXTERN int uv_pipe_bind2(uv_pipe_t* handle,
const char* name,
size_t namelen,
unsigned int flags);
UV_EXTERN void uv_pipe_connect(uv_connect_t* req,
uv_pipe_t* handle,
const char* name,
uv_connect_cb cb);
UV_EXTERN int uv_pipe_connect2(uv_connect_t* req,
uv_pipe_t* handle,
const char* name,
size_t namelen,
unsigned int flags,
uv_connect_cb cb);
UV_EXTERN int uv_pipe_getsockname(const uv_pipe_t* handle,
char* buffer,
size_t* size);
@ -1063,7 +1147,14 @@ enum uv_process_flags {
* option is only meaningful on Windows systems. On Unix it is silently
* ignored.
*/
UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6)
UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6),
/*
* On Windows, if the path to the program to execute, specified in
* uv_process_options_t's file field, has a directory component,
* search for the exact file name before trying variants with
* extensions like '.exe' or '.cmd'.
*/
UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME = (1 << 7)
};
/*
@ -1133,12 +1224,18 @@ struct uv_interface_address_s {
struct uv_passwd_s {
char* username;
long uid;
long gid;
unsigned long uid;
unsigned long gid;
char* shell;
char* homedir;
};
struct uv_group_s {
char* groupname;
unsigned long gid;
char** members;
};
struct uv_utsname_s {
char sysname[256];
char release[256];
@ -1184,16 +1281,6 @@ UV_EXTERN int uv_uptime(double* uptime);
UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd);
UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd);
typedef struct {
long tv_sec;
long tv_usec;
} uv_timeval_t;
typedef struct {
int64_t tv_sec;
int32_t tv_usec;
} uv_timeval64_t;
typedef struct {
uv_timeval_t ru_utime; /* user CPU time used */
uv_timeval_t ru_stime; /* system CPU time used */
@ -1214,11 +1301,15 @@ typedef struct {
} uv_rusage_t;
UV_EXTERN int uv_getrusage(uv_rusage_t* rusage);
UV_EXTERN int uv_getrusage_thread(uv_rusage_t* rusage);
UV_EXTERN int uv_os_homedir(char* buffer, size_t* size);
UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size);
UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd);
UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd);
UV_EXTERN int uv_os_get_passwd2(uv_passwd_t* pwd, uv_uid_t uid);
UV_EXTERN int uv_os_get_group(uv_group_t* grp, uv_uid_t gid);
UV_EXTERN void uv_os_free_group(uv_group_t* grp);
UV_EXTERN uv_pid_t uv_os_getpid(void);
UV_EXTERN uv_pid_t uv_os_getppid(void);
@ -1242,8 +1333,21 @@ UV_EXTERN uv_pid_t uv_os_getppid(void);
UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int* priority);
UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority);
enum {
UV_THREAD_PRIORITY_HIGHEST = 2,
UV_THREAD_PRIORITY_ABOVE_NORMAL = 1,
UV_THREAD_PRIORITY_NORMAL = 0,
UV_THREAD_PRIORITY_BELOW_NORMAL = -1,
UV_THREAD_PRIORITY_LOWEST = -2,
};
UV_EXTERN int uv_thread_getpriority(uv_thread_t tid, int* priority);
UV_EXTERN int uv_thread_setpriority(uv_thread_t tid, int priority);
UV_EXTERN unsigned int uv_available_parallelism(void);
UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
UV_EXTERN int uv_cpumask_size(void);
UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
int* count);
@ -1276,6 +1380,15 @@ UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size);
UV_EXTERN int uv_os_uname(uv_utsname_t* buffer);
struct uv_metrics_s {
uint64_t loop_count;
uint64_t events;
uint64_t events_waiting;
/* private */
uint64_t* reserved[13];
};
UV_EXTERN int uv_metrics_info(uv_loop_t* loop, uv_metrics_t* metrics);
UV_EXTERN uint64_t uv_metrics_idle_time(uv_loop_t* loop);
typedef enum {
@ -1478,6 +1591,8 @@ UV_EXTERN int uv_fs_chmod(uv_loop_t* loop,
const char* path,
int mode,
uv_fs_cb cb);
#define UV_FS_UTIME_NOW (INFINITY)
#define UV_FS_UTIME_OMIT (NAN)
UV_EXTERN int uv_fs_utime(uv_loop_t* loop,
uv_fs_t* req,
const char* path,
@ -1709,7 +1824,9 @@ UV_EXTERN int uv_chdir(const char* dir);
UV_EXTERN uint64_t uv_get_free_memory(void);
UV_EXTERN uint64_t uv_get_total_memory(void);
UV_EXTERN uint64_t uv_get_constrained_memory(void);
UV_EXTERN uint64_t uv_get_available_memory(void);
UV_EXTERN int uv_clock_gettime(uv_clock_id clock_id, uv_timespec64_t* ts);
UV_EXTERN uint64_t uv_hrtime(void);
UV_EXTERN void uv_sleep(unsigned int msec);
@ -1768,6 +1885,7 @@ UV_EXTERN int uv_gettimeofday(uv_timeval64_t* tv);
typedef void (*uv_thread_cb)(void* arg);
UV_EXTERN int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg);
UV_EXTERN int uv_thread_detach(uv_thread_t* tid);
typedef enum {
UV_THREAD_NO_FLAGS = 0x00,
@ -1786,9 +1904,20 @@ UV_EXTERN int uv_thread_create_ex(uv_thread_t* tid,
const uv_thread_options_t* params,
uv_thread_cb entry,
void* arg);
UV_EXTERN int uv_thread_setaffinity(uv_thread_t* tid,
char* cpumask,
char* oldmask,
size_t mask_size);
UV_EXTERN int uv_thread_getaffinity(uv_thread_t* tid,
char* cpumask,
size_t mask_size);
UV_EXTERN int uv_thread_getcpu(void);
UV_EXTERN uv_thread_t uv_thread_self(void);
UV_EXTERN int uv_thread_join(uv_thread_t *tid);
UV_EXTERN int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2);
UV_EXTERN int uv_thread_setname(const char* name);
UV_EXTERN int uv_thread_getname(uv_thread_t* tid, char* name, size_t size);
/* The presence of these unions force similar struct layout. */
#define XX(_, name) uv_ ## name ## _t name;
@ -1807,7 +1936,7 @@ struct uv_loop_s {
void* data;
/* Loop reference counting. */
unsigned int active_handles;
void* handle_queue[2];
struct uv__queue handle_queue;
union {
void* unused;
unsigned int count;
@ -1822,6 +1951,18 @@ struct uv_loop_s {
UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
/* Unicode utilities needed for dealing with Windows. */
UV_EXTERN size_t uv_utf16_length_as_wtf8(const uint16_t* utf16,
ssize_t utf16_len);
UV_EXTERN int uv_utf16_to_wtf8(const uint16_t* utf16,
ssize_t utf16_len,
char** wtf8_ptr,
size_t* wtf8_len_ptr);
UV_EXTERN ssize_t uv_wtf8_length_as_utf16(const char* wtf8);
UV_EXTERN void uv_wtf8_to_utf16(const char* wtf8,
uint16_t* utf16,
size_t utf16_len);
/* Don't export the private CPP symbols. */
#undef UV_HANDLE_TYPE_PRIVATE
#undef UV_REQ_TYPE_PRIVATE

View File

@ -1,54 +0,0 @@
/*
* Copyright (c) 1995, 1999
* Berkeley Software Design, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
*/
#ifndef _IFADDRS_H_
#define _IFADDRS_H_
struct ifaddrs {
struct ifaddrs *ifa_next;
char *ifa_name;
unsigned int ifa_flags;
struct sockaddr *ifa_addr;
struct sockaddr *ifa_netmask;
struct sockaddr *ifa_dstaddr;
void *ifa_data;
};
/*
* This may have been defined in <net/if.h>. Note that if <net/if.h> is
* to be included it must be included before this header file.
*/
#ifndef ifa_broadaddr
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
#endif
#include <sys/cdefs.h>
__BEGIN_DECLS
extern int getifaddrs(struct ifaddrs **ifap);
extern void freeifaddrs(struct ifaddrs *ifa);
__END_DECLS
#endif

View File

@ -40,7 +40,7 @@
void* cf_state; \
uv_mutex_t cf_mutex; \
uv_sem_t cf_sem; \
void* cf_signals[2]; \
struct uv__queue cf_signals; \
#define UV_PLATFORM_FS_EVENT_FIELDS \
uv__io_t event_watcher; \
@ -48,8 +48,8 @@
int realpath_len; \
int cf_flags; \
uv_async_t* cf_cb; \
void* cf_events[2]; \
void* cf_member[2]; \
struct uv__queue cf_events; \
struct uv__queue cf_member; \
int cf_error; \
uv_mutex_t cf_mutex; \

View File

@ -413,7 +413,6 @@
#elif defined(__APPLE__) || \
defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__FreeBSD_kernel__) || \
defined(__NetBSD__) || \
defined(__OpenBSD__)
# define UV__EHOSTDOWN (-64)
@ -457,4 +456,28 @@
# define UV__ESOCKTNOSUPPORT (-4025)
#endif
/* FreeBSD defines ENODATA in /usr/include/c++/v1/errno.h which is only visible
* if C++ is being used. Define it directly to avoid problems when integrating
* libuv in a C++ project.
*/
#if defined(ENODATA) && !defined(_WIN32)
# define UV__ENODATA UV__ERR(ENODATA)
#elif defined(__FreeBSD__)
# define UV__ENODATA (-9919)
#else
# define UV__ENODATA (-4024)
#endif
#if defined(EUNATCH) && !defined(_WIN32)
# define UV__EUNATCH UV__ERR(EUNATCH)
#else
# define UV__EUNATCH (-4023)
#endif
#if defined(ENOEXEC) && !defined(_WIN32)
# define UV__ENOEXEC UV__ERR(ENOEXEC)
#else
# define UV__ENOEXEC (-4022)
#endif
#endif /* UV_ERRNO_H_ */

View File

@ -28,7 +28,7 @@
int inotify_fd; \
#define UV_PLATFORM_FS_EVENT_FIELDS \
void* watchers[2]; \
struct uv__queue watchers; \
int wd; \
#endif /* UV_LINUX_H */

View File

@ -1,247 +0,0 @@
// ISO C9x compliant stdint.h for Microsoft Visual Studio
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
//
// Copyright (c) 2006-2008 Alexander Chemeris
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. The name of the author may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef _MSC_VER // [
#error "Use this header only with Microsoft Visual C++ compilers!"
#endif // _MSC_VER ]
#ifndef _MSC_STDINT_H_ // [
#define _MSC_STDINT_H_
#if _MSC_VER > 1000
#pragma once
#endif
#include <limits.h>
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
// or compiler give many errors like this:
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
#ifdef __cplusplus
extern "C" {
#endif
# include <wchar.h>
#ifdef __cplusplus
}
#endif
// Define _W64 macros to mark types changing their size, like intptr_t.
#ifndef _W64
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
# define _W64 __w64
# else
# define _W64
# endif
#endif
// 7.18.1 Integer types
// 7.18.1.1 Exact-width integer types
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
// realize that, e.g. char has the same size as __int8
// so we give up on __intX for them.
#if (_MSC_VER < 1300)
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#else
typedef signed __int8 int8_t;
typedef signed __int16 int16_t;
typedef signed __int32 int32_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
#endif
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
// 7.18.1.2 Minimum-width integer types
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
typedef int64_t int_least64_t;
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
typedef uint64_t uint_least64_t;
// 7.18.1.3 Fastest minimum-width integer types
typedef int8_t int_fast8_t;
typedef int16_t int_fast16_t;
typedef int32_t int_fast32_t;
typedef int64_t int_fast64_t;
typedef uint8_t uint_fast8_t;
typedef uint16_t uint_fast16_t;
typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;
// 7.18.1.4 Integer types capable of holding object pointers
#ifdef _WIN64 // [
typedef signed __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
#else // _WIN64 ][
typedef _W64 signed int intptr_t;
typedef _W64 unsigned int uintptr_t;
#endif // _WIN64 ]
// 7.18.1.5 Greatest-width integer types
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
// 7.18.2 Limits of specified-width integer types
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
// 7.18.2.1 Limits of exact-width integer types
#define INT8_MIN ((int8_t)_I8_MIN)
#define INT8_MAX _I8_MAX
#define INT16_MIN ((int16_t)_I16_MIN)
#define INT16_MAX _I16_MAX
#define INT32_MIN ((int32_t)_I32_MIN)
#define INT32_MAX _I32_MAX
#define INT64_MIN ((int64_t)_I64_MIN)
#define INT64_MAX _I64_MAX
#define UINT8_MAX _UI8_MAX
#define UINT16_MAX _UI16_MAX
#define UINT32_MAX _UI32_MAX
#define UINT64_MAX _UI64_MAX
// 7.18.2.2 Limits of minimum-width integer types
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
// 7.18.2.3 Limits of fastest minimum-width integer types
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
// 7.18.2.4 Limits of integer types capable of holding object pointers
#ifdef _WIN64 // [
# define INTPTR_MIN INT64_MIN
# define INTPTR_MAX INT64_MAX
# define UINTPTR_MAX UINT64_MAX
#else // _WIN64 ][
# define INTPTR_MIN INT32_MIN
# define INTPTR_MAX INT32_MAX
# define UINTPTR_MAX UINT32_MAX
#endif // _WIN64 ]
// 7.18.2.5 Limits of greatest-width integer types
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
// 7.18.3 Limits of other integer types
#ifdef _WIN64 // [
# define PTRDIFF_MIN _I64_MIN
# define PTRDIFF_MAX _I64_MAX
#else // _WIN64 ][
# define PTRDIFF_MIN _I32_MIN
# define PTRDIFF_MAX _I32_MAX
#endif // _WIN64 ]
#define SIG_ATOMIC_MIN INT_MIN
#define SIG_ATOMIC_MAX INT_MAX
#ifndef SIZE_MAX // [
# ifdef _WIN64 // [
# define SIZE_MAX _UI64_MAX
# else // _WIN64 ][
# define SIZE_MAX _UI32_MAX
# endif // _WIN64 ]
#endif // SIZE_MAX ]
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
#ifndef WCHAR_MIN // [
# define WCHAR_MIN 0
#endif // WCHAR_MIN ]
#ifndef WCHAR_MAX // [
# define WCHAR_MAX _UI16_MAX
#endif // WCHAR_MAX ]
#define WINT_MIN 0
#define WINT_MAX _UI16_MAX
#endif // __STDC_LIMIT_MACROS ]
// 7.18.4 Limits of other integer types
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
// 7.18.4.1 Macros for minimum-width integer constants
#define INT8_C(val) val##i8
#define INT16_C(val) val##i16
#define INT32_C(val) val##i32
#define INT64_C(val) val##i64
#define UINT8_C(val) val##ui8
#define UINT16_C(val) val##ui16
#define UINT32_C(val) val##ui32
#define UINT64_C(val) val##ui64
// 7.18.4.2 Macros for greatest-width integer constants
#define INTMAX_C INT64_C
#define UINTMAX_C UINT64_C
#endif // __STDC_CONSTANT_MACROS ]
#endif // _MSC_STDINT_H_ ]

View File

@ -31,7 +31,7 @@ struct uv__work {
void (*work)(struct uv__work *w);
void (*done)(struct uv__work *w, int status);
struct uv_loop_s* loop;
void* wq[2];
struct uv__queue wq;
};
#endif /* UV_THREADPOOL_H_ */

View File

@ -35,21 +35,7 @@
#endif
/*
* This file defines data structures for different types of trees:
* splay trees and red-black trees.
*
* A splay tree is a self-organizing data structure. Every operation
* on the tree causes a splay to happen. The splay moves the requested
* node to the root of the tree and partly rebalances it.
*
* This has the benefit that request locality causes faster lookups as
* the requested nodes move to the top of the tree. On the other hand,
* every lookup causes memory writes.
*
* The Balance Theorem bounds the total access time for m operations
* and n inserts on an initially empty tree as O((m + n)lg n). The
* amortized cost for a sequence of m accesses to a splay tree is O(lg n);
*
* This file defines data structures for red-black trees.
* A red-black tree is a binary search tree with the node color as an
* extra attribute. It fulfills a set of conditions:
* - every search path from the root to a leaf consists of the
@ -61,239 +47,6 @@
* The maximum height of a red-black tree is 2lg (n+1).
*/
#define SPLAY_HEAD(name, type) \
struct name { \
struct type *sph_root; /* root of the tree */ \
}
#define SPLAY_INITIALIZER(root) \
{ NULL }
#define SPLAY_INIT(root) do { \
(root)->sph_root = NULL; \
} while (/*CONSTCOND*/ 0)
#define SPLAY_ENTRY(type) \
struct { \
struct type *spe_left; /* left element */ \
struct type *spe_right; /* right element */ \
}
#define SPLAY_LEFT(elm, field) (elm)->field.spe_left
#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right
#define SPLAY_ROOT(head) (head)->sph_root
#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL)
/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */
#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \
SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \
SPLAY_RIGHT(tmp, field) = (head)->sph_root; \
(head)->sph_root = tmp; \
} while (/*CONSTCOND*/ 0)
#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \
SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \
SPLAY_LEFT(tmp, field) = (head)->sph_root; \
(head)->sph_root = tmp; \
} while (/*CONSTCOND*/ 0)
#define SPLAY_LINKLEFT(head, tmp, field) do { \
SPLAY_LEFT(tmp, field) = (head)->sph_root; \
tmp = (head)->sph_root; \
(head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \
} while (/*CONSTCOND*/ 0)
#define SPLAY_LINKRIGHT(head, tmp, field) do { \
SPLAY_RIGHT(tmp, field) = (head)->sph_root; \
tmp = (head)->sph_root; \
(head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \
} while (/*CONSTCOND*/ 0)
#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \
SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \
SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field); \
SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \
SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \
} while (/*CONSTCOND*/ 0)
/* Generates prototypes and inline functions */
#define SPLAY_PROTOTYPE(name, type, field, cmp) \
void name##_SPLAY(struct name *, struct type *); \
void name##_SPLAY_MINMAX(struct name *, int); \
struct type *name##_SPLAY_INSERT(struct name *, struct type *); \
struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \
\
/* Finds the node with the same key as elm */ \
static __inline struct type * \
name##_SPLAY_FIND(struct name *head, struct type *elm) \
{ \
if (SPLAY_EMPTY(head)) \
return(NULL); \
name##_SPLAY(head, elm); \
if ((cmp)(elm, (head)->sph_root) == 0) \
return (head->sph_root); \
return (NULL); \
} \
\
static __inline struct type * \
name##_SPLAY_NEXT(struct name *head, struct type *elm) \
{ \
name##_SPLAY(head, elm); \
if (SPLAY_RIGHT(elm, field) != NULL) { \
elm = SPLAY_RIGHT(elm, field); \
while (SPLAY_LEFT(elm, field) != NULL) { \
elm = SPLAY_LEFT(elm, field); \
} \
} else \
elm = NULL; \
return (elm); \
} \
\
static __inline struct type * \
name##_SPLAY_MIN_MAX(struct name *head, int val) \
{ \
name##_SPLAY_MINMAX(head, val); \
return (SPLAY_ROOT(head)); \
}
/* Main splay operation.
* Moves node close to the key of elm to top
*/
#define SPLAY_GENERATE(name, type, field, cmp) \
struct type * \
name##_SPLAY_INSERT(struct name *head, struct type *elm) \
{ \
if (SPLAY_EMPTY(head)) { \
SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \
} else { \
int __comp; \
name##_SPLAY(head, elm); \
__comp = (cmp)(elm, (head)->sph_root); \
if(__comp < 0) { \
SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field); \
SPLAY_RIGHT(elm, field) = (head)->sph_root; \
SPLAY_LEFT((head)->sph_root, field) = NULL; \
} else if (__comp > 0) { \
SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field); \
SPLAY_LEFT(elm, field) = (head)->sph_root; \
SPLAY_RIGHT((head)->sph_root, field) = NULL; \
} else \
return ((head)->sph_root); \
} \
(head)->sph_root = (elm); \
return (NULL); \
} \
\
struct type * \
name##_SPLAY_REMOVE(struct name *head, struct type *elm) \
{ \
struct type *__tmp; \
if (SPLAY_EMPTY(head)) \
return (NULL); \
name##_SPLAY(head, elm); \
if ((cmp)(elm, (head)->sph_root) == 0) { \
if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \
(head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \
} else { \
__tmp = SPLAY_RIGHT((head)->sph_root, field); \
(head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \
name##_SPLAY(head, elm); \
SPLAY_RIGHT((head)->sph_root, field) = __tmp; \
} \
return (elm); \
} \
return (NULL); \
} \
\
void \
name##_SPLAY(struct name *head, struct type *elm) \
{ \
struct type __node, *__left, *__right, *__tmp; \
int __comp; \
\
SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL; \
__left = __right = &__node; \
\
while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \
if (__comp < 0) { \
__tmp = SPLAY_LEFT((head)->sph_root, field); \
if (__tmp == NULL) \
break; \
if ((cmp)(elm, __tmp) < 0){ \
SPLAY_ROTATE_RIGHT(head, __tmp, field); \
if (SPLAY_LEFT((head)->sph_root, field) == NULL) \
break; \
} \
SPLAY_LINKLEFT(head, __right, field); \
} else if (__comp > 0) { \
__tmp = SPLAY_RIGHT((head)->sph_root, field); \
if (__tmp == NULL) \
break; \
if ((cmp)(elm, __tmp) > 0){ \
SPLAY_ROTATE_LEFT(head, __tmp, field); \
if (SPLAY_RIGHT((head)->sph_root, field) == NULL) \
break; \
} \
SPLAY_LINKRIGHT(head, __left, field); \
} \
} \
SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \
} \
\
/* Splay with either the minimum or the maximum element \
* Used to find minimum or maximum element in tree. \
*/ \
void name##_SPLAY_MINMAX(struct name *head, int __comp) \
{ \
struct type __node, *__left, *__right, *__tmp; \
\
SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL; \
__left = __right = &__node; \
\
for (;;) { \
if (__comp < 0) { \
__tmp = SPLAY_LEFT((head)->sph_root, field); \
if (__tmp == NULL) \
break; \
if (__comp < 0){ \
SPLAY_ROTATE_RIGHT(head, __tmp, field); \
if (SPLAY_LEFT((head)->sph_root, field) == NULL) \
break; \
} \
SPLAY_LINKLEFT(head, __right, field); \
} else if (__comp > 0) { \
__tmp = SPLAY_RIGHT((head)->sph_root, field); \
if (__tmp == NULL) \
break; \
if (__comp > 0) { \
SPLAY_ROTATE_LEFT(head, __tmp, field); \
if (SPLAY_RIGHT((head)->sph_root, field) == NULL) \
break; \
} \
SPLAY_LINKRIGHT(head, __left, field); \
} \
} \
SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \
}
#define SPLAY_NEGINF -1
#define SPLAY_INF 1
#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y)
#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y)
#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y)
#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y)
#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \
: name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF))
#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \
: name##_SPLAY_MIN_MAX(x, SPLAY_INF))
#define SPLAY_FOREACH(x, name, head) \
for ((x) = SPLAY_MIN(name, head); \
(x) != NULL; \
(x) = SPLAY_NEXT(name, head, x))
/* Macros that define a red-black tree */
#define RB_HEAD(name, type) \
struct name { \
@ -730,8 +483,8 @@ name##_RB_MINMAX(struct name *head, int val) \
#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y)
#define RB_FIND(name, x, y) name##_RB_FIND(x, y)
#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y)
#define RB_NEXT(name, x, y) name##_RB_NEXT(y)
#define RB_PREV(name, x, y) name##_RB_PREV(y)
#define RB_NEXT(name, x) name##_RB_NEXT(x)
#define RB_PREV(name, x) name##_RB_PREV(x)
#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF)
#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF)

View File

@ -59,7 +59,6 @@
# include "uv/darwin.h"
#elif defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__FreeBSD_kernel__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__)
# include "uv/bsd.h"
@ -93,8 +92,8 @@ typedef struct uv__io_s uv__io_t;
struct uv__io_s {
uv__io_cb cb;
void* pending_queue[2];
void* watcher_queue[2];
struct uv__queue pending_queue;
struct uv__queue watcher_queue;
unsigned int pevents; /* Pending event mask i.e. mask at next tick. */
unsigned int events; /* Current event mask. */
int fd;
@ -221,21 +220,21 @@ typedef struct {
#define UV_LOOP_PRIVATE_FIELDS \
unsigned long flags; \
int backend_fd; \
void* pending_queue[2]; \
void* watcher_queue[2]; \
struct uv__queue pending_queue; \
struct uv__queue watcher_queue; \
uv__io_t** watchers; \
unsigned int nwatchers; \
unsigned int nfds; \
void* wq[2]; \
struct uv__queue wq; \
uv_mutex_t wq_mutex; \
uv_async_t wq_async; \
uv_rwlock_t cloexec_lock; \
uv_handle_t* closing_handles; \
void* process_handles[2]; \
void* prepare_handles[2]; \
void* check_handles[2]; \
void* idle_handles[2]; \
void* async_handles[2]; \
struct uv__queue process_handles; \
struct uv__queue prepare_handles; \
struct uv__queue check_handles; \
struct uv__queue idle_handles; \
struct uv__queue async_handles; \
void (*async_unused)(void); /* TODO(bnoordhuis) Remove in libuv v2. */ \
uv__io_t async_io_watcher; \
int async_wfd; \
@ -258,7 +257,7 @@ typedef struct {
#define UV_PRIVATE_REQ_TYPES /* empty */
#define UV_WRITE_PRIVATE_FIELDS \
void* queue[2]; \
struct uv__queue queue; \
unsigned int write_index; \
uv_buf_t* bufs; \
unsigned int nbufs; \
@ -266,13 +265,16 @@ typedef struct {
uv_buf_t bufsml[4]; \
#define UV_CONNECT_PRIVATE_FIELDS \
void* queue[2]; \
struct uv__queue queue; \
#define UV_SHUTDOWN_PRIVATE_FIELDS /* empty */
#define UV_UDP_SEND_PRIVATE_FIELDS \
void* queue[2]; \
struct sockaddr_storage addr; \
struct uv__queue queue; \
union { \
struct sockaddr addr; \
struct sockaddr_storage storage; \
} u; \
unsigned int nbufs; \
uv_buf_t* bufs; \
ssize_t status; \
@ -287,8 +289,8 @@ typedef struct {
uv_connect_t *connect_req; \
uv_shutdown_t *shutdown_req; \
uv__io_t io_watcher; \
void* write_queue[2]; \
void* write_completed_queue[2]; \
struct uv__queue write_queue; \
struct uv__queue write_completed_queue; \
uv_connection_cb connection_cb; \
int delayed_error; \
int accepted_fd; \
@ -301,35 +303,38 @@ typedef struct {
uv_alloc_cb alloc_cb; \
uv_udp_recv_cb recv_cb; \
uv__io_t io_watcher; \
void* write_queue[2]; \
void* write_completed_queue[2]; \
struct uv__queue write_queue; \
struct uv__queue write_completed_queue; \
#define UV_PIPE_PRIVATE_FIELDS \
const char* pipe_fname; /* strdup'ed */
const char* pipe_fname; /* NULL or strdup'ed */
#define UV_POLL_PRIVATE_FIELDS \
uv__io_t io_watcher;
#define UV_PREPARE_PRIVATE_FIELDS \
uv_prepare_cb prepare_cb; \
void* queue[2]; \
struct uv__queue queue; \
#define UV_CHECK_PRIVATE_FIELDS \
uv_check_cb check_cb; \
void* queue[2]; \
struct uv__queue queue; \
#define UV_IDLE_PRIVATE_FIELDS \
uv_idle_cb idle_cb; \
void* queue[2]; \
struct uv__queue queue; \
#define UV_ASYNC_PRIVATE_FIELDS \
uv_async_cb async_cb; \
void* queue[2]; \
struct uv__queue queue; \
int pending; \
#define UV_TIMER_PRIVATE_FIELDS \
uv_timer_cb timer_cb; \
void* heap_node[3]; \
union { \
void* heap[3]; \
struct uv__queue queue; \
} node; \
uint64_t timeout; \
uint64_t repeat; \
uint64_t start_id;
@ -353,7 +358,7 @@ typedef struct {
int retcode;
#define UV_PROCESS_PRIVATE_FIELDS \
void* queue[2]; \
struct uv__queue queue; \
int status; \
#define UV_FS_PRIVATE_FIELDS \
@ -418,6 +423,8 @@ typedef struct {
# define UV_FS_O_DIRECT 0x04000
#elif defined(__linux__) && defined(__x86_64__)
# define UV_FS_O_DIRECT 0x04000
#elif defined(__linux__) && defined(__loongarch__)
# define UV_FS_O_DIRECT 0x04000
#elif defined(O_DIRECT)
# define UV_FS_O_DIRECT O_DIRECT
#else

View File

@ -31,10 +31,10 @@
*/
#define UV_VERSION_MAJOR 1
#define UV_VERSION_MINOR 43
#define UV_VERSION_PATCH 0
#define UV_VERSION_IS_RELEASE 1
#define UV_VERSION_SUFFIX ""
#define UV_VERSION_MINOR 50
#define UV_VERSION_PATCH 1
#define UV_VERSION_IS_RELEASE 0
#define UV_VERSION_SUFFIX "dev"
#define UV_VERSION_HEX ((UV_VERSION_MAJOR << 16) | \
(UV_VERSION_MINOR << 8) | \

View File

@ -20,7 +20,7 @@
*/
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# define _WIN32_WINNT 0x0A00
#endif
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
@ -32,20 +32,12 @@ typedef intptr_t ssize_t;
#include <winsock2.h>
#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
typedef struct pollfd {
SOCKET fd;
short events;
short revents;
} WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD;
#endif
#ifndef LOCALE_INVARIANT
# define LOCALE_INVARIANT 0x007f
#endif
#include <mswsock.h>
// Disable the typedef in mstcpip.h of MinGW.
/* Disable the typedef in mstcpip.h of MinGW. */
#define _TCP_INITIAL_RTO_PARAMETERS _TCP_INITIAL_RTO_PARAMETERS__AVOID
#define TCP_INITIAL_RTO_PARAMETERS TCP_INITIAL_RTO_PARAMETERS__AVOID
#define PTCP_INITIAL_RTO_PARAMETERS PTCP_INITIAL_RTO_PARAMETERS__AVOID
@ -59,12 +51,7 @@ typedef struct pollfd {
#include <signal.h>
#include <fcntl.h>
#include <sys/stat.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv/stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
#include <stdint.h>
#include "uv/tree.h"
#include "uv/threadpool.h"
@ -75,6 +62,11 @@ typedef struct pollfd {
# define S_IFLNK 0xA000
#endif
/* Define missing in Windows Kit Include\{VERSION}\ucrt\sys\stat.h */
#if defined(_CRT_INTERNAL_NONSTDC_NAMES) && _CRT_INTERNAL_NONSTDC_NAMES && !defined(S_IFIFO)
# define S_IFIFO _S_IFIFO
#endif
/* Additional signals supported by uv_signal and or uv_kill. The CRT defines
* the following signals already:
*
@ -91,6 +83,7 @@ typedef struct pollfd {
* variants (Linux and Darwin)
*/
#define SIGHUP 1
#define SIGQUIT 3
#define SIGKILL 9
#define SIGWINCH 28
@ -223,7 +216,7 @@ typedef struct _AFD_POLL_INFO {
AFD_POLL_HANDLE_INFO Handles[1];
} AFD_POLL_INFO, *PAFD_POLL_INFO;
#define UV_MSAFD_PROVIDER_COUNT 3
#define UV_MSAFD_PROVIDER_COUNT 4
/**
@ -263,29 +256,23 @@ typedef union {
} unused_; /* TODO: retained for ABI compatibility; remove me in v2.x. */
} uv_cond_t;
typedef union {
struct {
unsigned int num_readers_;
CRITICAL_SECTION num_readers_lock_;
HANDLE write_semaphore_;
} state_;
/* TODO: remove me in v2.x. */
struct {
SRWLOCK unused_;
} unused1_;
/* TODO: remove me in v2.x. */
struct {
uv_mutex_t unused1_;
uv_mutex_t unused2_;
} unused2_;
typedef struct {
SRWLOCK read_write_lock_;
/* TODO: retained for ABI compatibility; remove me in v2.x */
#ifdef _WIN64
unsigned char padding_[72];
#else
unsigned char padding_[44];
#endif
} uv_rwlock_t;
typedef struct {
unsigned int n;
unsigned int count;
unsigned threshold;
unsigned in;
uv_mutex_t mutex;
uv_sem_t turnstile1;
uv_sem_t turnstile2;
/* TODO: in v2 make this a uv_cond_t, without unused_ */
CONDITION_VARIABLE cond;
unsigned out;
} uv_barrier_t;
typedef struct {
@ -295,8 +282,8 @@ typedef struct {
#define UV_ONCE_INIT { 0, NULL }
typedef struct uv_once_s {
unsigned char ran;
HANDLE event;
unsigned char unused;
INIT_ONCE init_once;
} uv_once_t;
/* Platform-specific definitions for uv_spawn support. */
@ -355,14 +342,14 @@ typedef struct {
uv_idle_t* next_idle_handle; \
/* This handle holds the peer sockets for the fast variant of uv_poll_t */ \
SOCKET poll_peer_sockets[UV_MSAFD_PROVIDER_COUNT]; \
/* Counter to keep track of active tcp streams */ \
/* No longer used. */ \
unsigned int active_tcp_streams; \
/* Counter to keep track of active udp streams */ \
/* No longer used. */ \
unsigned int active_udp_streams; \
/* Counter to started timer */ \
uint64_t timer_counter; \
/* Threadpool */ \
void* wq[2]; \
struct uv__queue wq; \
uv_mutex_t wq_mutex; \
uv_async_t wq_async;
@ -384,6 +371,13 @@ typedef struct {
OVERLAPPED overlapped; \
size_t queued_bytes; \
} io; \
/* in v2, we can move these to the UV_CONNECT_PRIVATE_FIELDS */ \
struct { \
ULONG_PTR result; /* overlapped.Internal is reused to hold the result */\
HANDLE pipeHandle; \
DWORD duplex_flags; \
WCHAR* name; \
} connect; \
} u; \
struct uv_req_s* next_req;
@ -484,7 +478,7 @@ typedef struct {
uint32_t payload_remaining; \
uint64_t dummy; /* TODO: retained for ABI compat; remove this in v2.x. */ \
} ipc_data_frame; \
void* ipc_xfer_queue[2]; \
struct uv__queue ipc_xfer_queue; \
int ipc_xfer_queue_length; \
uv_write_t* non_overlapped_writes_tail; \
CRITICAL_SECTION readfile_thread_lock; \
@ -498,15 +492,18 @@ typedef struct {
struct { uv_pipe_connection_fields } conn; \
} pipe;
/* TODO: put the parser states in an union - TTY handles are always half-duplex
/* TODO: put the parser states in a union - TTY handles are always half-duplex
* so read-state can safely overlap write-state. */
#define UV_TTY_PRIVATE_FIELDS \
HANDLE handle; \
union { \
struct { \
/* Used for readable TTY handles */ \
union { \
/* TODO: remove me in v2.x. */ \
HANDLE unused_; \
int mode; \
} mode; \
uv_buf_t read_line_buffer; \
HANDLE read_raw_wait; \
/* Fields used for translating win keystrokes into vt100 characters */ \
@ -548,7 +545,10 @@ typedef struct {
unsigned char events;
#define UV_TIMER_PRIVATE_FIELDS \
void* heap_node[3]; \
union { \
void* heap[3]; \
struct uv__queue queue; \
} node; \
int unused; \
uint64_t timeout; \
uint64_t repeat; \
@ -606,7 +606,7 @@ typedef struct {
struct uv_process_exit_s { \
UV_REQ_FIELDS \
} exit_req; \
BYTE* child_stdio_buffer; \
void* unused; /* TODO: retained for ABI compat; remove this in v2.x. */ \
int exit_signal; \
HANDLE wait_handle; \
HANDLE process_handle; \

View File

@ -8,5 +8,5 @@ Version: @PACKAGE_VERSION@
Description: multi-platform support library with a focus on asynchronous I/O.
URL: http://libuv.org/
Libs: -L${libdir} -luv_a @LIBS@
Libs: -L${libdir} -l:libuv.a @LIBS@
Cflags: -I${includedir}

View File

@ -2,6 +2,7 @@ prefix=@prefix@
exec_prefix=${prefix}
libdir=@libdir@
includedir=@includedir@
LIBUV_STATIC=-L${libdir} -l:libuv.a @LIBS@
Name: libuv
Version: @PACKAGE_VERSION@

View File

@ -1,6 +1,7 @@
dnl Macros to check the presence of generic (non-typed) symbols.
dnl Copyright (c) 2006-2008 Diego Pettenò <flameeyes gmail com>
dnl Copyright (c) 2006-2008 xine project
dnl Copyright (c) 2021 libuv project
dnl
dnl This program is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
@ -63,7 +64,7 @@ AC_DEFUN([CC_CHECK_CFLAGS], [
])
dnl CC_CHECK_CFLAG_APPEND(FLAG, [action-if-found], [action-if-not-found])
dnl Check for CFLAG and appends them to CFLAGS if supported
dnl Check for CFLAG and appends them to AM_CFLAGS if supported
AC_DEFUN([CC_CHECK_CFLAG_APPEND], [
AC_CACHE_CHECK([if $CC supports $1 flag],
AS_TR_SH([cc_cv_cflags_$1]),
@ -71,7 +72,9 @@ AC_DEFUN([CC_CHECK_CFLAG_APPEND], [
)
AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
[CFLAGS="$CFLAGS $1"; DEBUG_CFLAGS="$DEBUG_CFLAGS $1"; $2], [$3])
[AM_CFLAGS="$AM_CFLAGS $1"; DEBUG_CFLAGS="$DEBUG_CFLAGS $1"; $2], [$3])
AC_SUBST([AM_CFLAGS])
])
dnl CC_CHECK_CFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not])
@ -101,6 +104,20 @@ AC_DEFUN([CC_CHECK_LDFLAGS], [
[$2], [$3])
])
dnl Check if flag is supported by both compiler and linker
dnl If so, append it to AM_CFLAGS
dnl CC_CHECK_FLAG_SUPPORTED_APPEND([FLAG])
AC_DEFUN([CC_CHECK_FLAG_SUPPORTED_APPEND], [
CC_CHECK_CFLAGS([$1],
[CC_CHECK_LDFLAGS([$1],
[AM_CFLAGS="$AM_CFLAGS $1";
DEBUG_CFLAGS="$DEBUG_CFLAGS $1";
AC_SUBST([AM_CFLAGS])
])
])
])
dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for
dnl the current linker to avoid undefined references in a shared object.
AC_DEFUN([CC_NOUNDEFINED], [

View File

@ -0,0 +1,7 @@
AC_PREREQ(2.71)
AC_INIT([libuv-release-check], [0.0])
AM_INIT_AUTOMAKE([1.16.5])
LT_PREREQ(2.4.7)
AC_OUTPUT

View File

@ -25,7 +25,7 @@
#ifdef _WIN32
#include "win/internal.h"
#include "win/handle-inl.h"
#define uv__make_close_pending(h) uv_want_endgame((h)->loop, (h))
#define uv__make_close_pending(h) uv__want_endgame((h)->loop, (h))
#else
#include "unix/internal.h"
#endif
@ -139,6 +139,9 @@ int uv_fs_poll_getpath(uv_fs_poll_t* handle, char* buffer, size_t* size) {
struct poll_ctx* ctx;
size_t required_len;
if (buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL;
if (!uv_is_active((uv_handle_t*)handle)) {
*size = 0;
return UV_EINVAL;

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2011, 2018 Ben Noordhuis <info@bnoordhuis.nl>
/* Copyright libuv contributors. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -18,9 +18,55 @@
*/
#include "uv.h"
#include "uv-common.h"
#include "idna.h"
#include <assert.h>
#include <string.h>
#include <limits.h> /* UINT_MAX */
static int32_t uv__wtf8_decode1(const char** input) {
uint32_t code_point;
uint8_t b1;
uint8_t b2;
uint8_t b3;
uint8_t b4;
b1 = **input;
if (b1 <= 0x7F)
return b1; /* ASCII code point */
if (b1 < 0xC2)
return -1; /* invalid: continuation byte */
code_point = b1;
b2 = *++*input;
if ((b2 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b2 & 0x3F);
if (b1 <= 0xDF)
return 0x7FF & code_point; /* two-byte character */
b3 = *++*input;
if ((b3 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b3 & 0x3F);
if (b1 <= 0xEF)
return 0xFFFF & code_point; /* three-byte character */
b4 = *++*input;
if ((b4 & 0xC0) != 0x80)
return -1; /* invalid: not a continuation byte */
code_point = (code_point << 6) | (b4 & 0x3F);
if (b1 <= 0xF4) {
code_point &= 0x1FFFFF;
if (code_point <= 0x10FFFF)
return code_point; /* four-byte character */
}
/* code point too large */
return -1;
}
static unsigned uv__utf8_decode1_slow(const char** p,
const char* pe,
@ -88,6 +134,7 @@ static unsigned uv__utf8_decode1_slow(const char** p,
return a;
}
unsigned uv__utf8_decode1(const char** p, const char* pe) {
unsigned a;
@ -101,6 +148,7 @@ unsigned uv__utf8_decode1(const char** p, const char* pe) {
return uv__utf8_decode1_slow(p, pe, a);
}
static int uv__idna_toascii_label(const char* s, const char* se,
char** d, char* de) {
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz0123456789";
@ -129,7 +177,7 @@ static int uv__idna_toascii_label(const char* s, const char* se,
while (s < se) {
c = uv__utf8_decode1(&s, se);
if (c == -1u)
if (c == UINT_MAX)
return UV_EINVAL;
if (c < 128)
@ -151,7 +199,7 @@ static int uv__idna_toascii_label(const char* s, const char* se,
s = ss;
while (s < se) {
c = uv__utf8_decode1(&s, se);
assert(c != -1u);
assert(c != UINT_MAX);
if (c > 127)
continue;
@ -182,7 +230,7 @@ static int uv__idna_toascii_label(const char* s, const char* se,
while (s < se) {
c = uv__utf8_decode1(&s, se);
assert(c != -1u);
assert(c != UINT_MAX);
if (c >= n)
if (c < m)
@ -201,7 +249,7 @@ static int uv__idna_toascii_label(const char* s, const char* se,
s = ss;
while (s < se) {
c = uv__utf8_decode1(&s, se);
assert(c != -1u);
assert(c != UINT_MAX);
if (c < n)
if (++delta == 0)
@ -266,13 +314,17 @@ static int uv__idna_toascii_label(const char* s, const char* se,
return 0;
}
long uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
ssize_t uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
const char* si;
const char* st;
unsigned c;
char* ds;
int rc;
if (s == se)
return UV_EINVAL;
ds = d;
si = s;
@ -280,7 +332,7 @@ long uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
st = si;
c = uv__utf8_decode1(&si, se);
if (c == -1u)
if (c == UINT_MAX)
return UV_EINVAL;
if (c != '.')
@ -307,8 +359,202 @@ long uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
return rc;
}
if (d < de)
*d++ = '\0';
if (d >= de)
return UV_EINVAL;
*d++ = '\0';
return d - ds; /* Number of bytes written. */
}
ssize_t uv_wtf8_length_as_utf16(const char* source_ptr) {
size_t w_target_len = 0;
int32_t code_point;
do {
code_point = uv__wtf8_decode1(&source_ptr);
if (code_point < 0)
return -1;
if (code_point > 0xFFFF)
w_target_len++;
w_target_len++;
} while (*source_ptr++);
return w_target_len;
}
void uv_wtf8_to_utf16(const char* source_ptr,
uint16_t* w_target,
size_t w_target_len) {
int32_t code_point;
do {
code_point = uv__wtf8_decode1(&source_ptr);
/* uv_wtf8_length_as_utf16 should have been called and checked first. */
assert(code_point >= 0);
if (code_point > 0xFFFF) {
assert(code_point < 0x10FFFF);
*w_target++ = (((code_point - 0x10000) >> 10) + 0xD800);
*w_target++ = ((code_point - 0x10000) & 0x3FF) + 0xDC00;
w_target_len -= 2;
} else {
*w_target++ = code_point;
w_target_len -= 1;
}
} while (*source_ptr++);
(void)w_target_len;
assert(w_target_len == 0);
}
static int32_t uv__get_surrogate_value(const uint16_t* w_source_ptr,
ssize_t w_source_len) {
uint16_t u;
uint16_t next;
u = w_source_ptr[0];
if (u >= 0xD800 && u <= 0xDBFF && w_source_len != 1) {
next = w_source_ptr[1];
if (next >= 0xDC00 && next <= 0xDFFF)
return 0x10000 + ((u - 0xD800) << 10) + (next - 0xDC00);
}
return u;
}
size_t uv_utf16_length_as_wtf8(const uint16_t* w_source_ptr,
ssize_t w_source_len) {
size_t target_len;
int32_t code_point;
target_len = 0;
while (w_source_len) {
code_point = uv__get_surrogate_value(w_source_ptr, w_source_len);
/* Can be invalid UTF-8 but must be valid WTF-8. */
assert(code_point >= 0);
if (w_source_len < 0 && code_point == 0)
break;
if (code_point < 0x80)
target_len += 1;
else if (code_point < 0x800)
target_len += 2;
else if (code_point < 0x10000)
target_len += 3;
else {
target_len += 4;
w_source_ptr++;
if (w_source_len > 0)
w_source_len--;
}
w_source_ptr++;
if (w_source_len > 0)
w_source_len--;
}
return target_len;
}
int uv_utf16_to_wtf8(const uint16_t* w_source_ptr,
ssize_t w_source_len,
char** target_ptr,
size_t* target_len_ptr) {
size_t target_len;
char* target;
char* target_end;
int32_t code_point;
/* If *target_ptr is provided, then *target_len_ptr must be its length
* (excluding space for NUL), otherwise we will compute the target_len_ptr
* length and may return a new allocation in *target_ptr if target_ptr is
* provided. */
if (target_ptr == NULL || *target_ptr == NULL) {
target_len = uv_utf16_length_as_wtf8(w_source_ptr, w_source_len);
if (target_len_ptr != NULL)
*target_len_ptr = target_len;
} else {
target_len = *target_len_ptr;
}
if (target_ptr == NULL)
return 0;
if (*target_ptr == NULL) {
target = uv__malloc(target_len + 1);
if (target == NULL) {
return UV_ENOMEM;
}
*target_ptr = target;
} else {
target = *target_ptr;
}
target_end = target + target_len;
while (target != target_end && w_source_len) {
code_point = uv__get_surrogate_value(w_source_ptr, w_source_len);
/* Can be invalid UTF-8 but must be valid WTF-8. */
assert(code_point >= 0);
if (w_source_len < 0 && code_point == 0) {
w_source_len = 0;
break;
}
if (code_point < 0x80) {
*target++ = code_point;
} else if (code_point < 0x800) {
*target++ = 0xC0 | (code_point >> 6);
if (target == target_end)
break;
*target++ = 0x80 | (code_point & 0x3F);
} else if (code_point < 0x10000) {
*target++ = 0xE0 | (code_point >> 12);
if (target == target_end)
break;
*target++ = 0x80 | ((code_point >> 6) & 0x3F);
if (target == target_end)
break;
*target++ = 0x80 | (code_point & 0x3F);
} else {
*target++ = 0xF0 | (code_point >> 18);
if (target == target_end)
break;
*target++ = 0x80 | ((code_point >> 12) & 0x3F);
if (target == target_end)
break;
*target++ = 0x80 | ((code_point >> 6) & 0x3F);
if (target == target_end)
break;
*target++ = 0x80 | (code_point & 0x3F);
/* uv__get_surrogate_value consumed 2 input characters */
w_source_ptr++;
if (w_source_len > 0)
w_source_len--;
}
target_len = target - *target_ptr;
w_source_ptr++;
if (w_source_len > 0)
w_source_len--;
}
if (target != target_end && target_len_ptr != NULL)
/* Did not fill all of the provided buffer, so update the target_len_ptr
* output with the space used. */
*target_len_ptr = target - *target_ptr;
/* Check if input fit into target exactly. */
if (w_source_len < 0 && target == target_end && w_source_ptr[0] == 0)
w_source_len = 0;
*target++ = '\0';
/* Characters remained after filling the buffer, compute the remaining length now. */
if (w_source_len) {
if (target_len_ptr != NULL)
*target_len_ptr = target_len + uv_utf16_length_as_wtf8(w_source_ptr, w_source_len);
return UV_ENOBUFS;
}
return 0;
}

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2011, 2018 Ben Noordhuis <info@bnoordhuis.nl>
/* Copyright libuv contributors. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -26,6 +26,6 @@ unsigned uv__utf8_decode1(const char** p, const char* pe);
* is the number of bytes written to |d|, including the trailing nul byte.
* A return value < 0 is a libuv error code. |s| and |d| can not overlap.
*/
long uv__idna_toascii(const char* s, const char* se, char* d, char* de);
ssize_t uv__idna_toascii(const char* s, const char* se, char* d, char* de);
#endif /* UV_SRC_IDNA_H_ */

View File

@ -17,12 +17,7 @@
#include <stdio.h>
#include <string.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
# include "uv/stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
#include <stdint.h>
#include "uv.h"
#include "uv-common.h"
@ -135,7 +130,7 @@ static int inet_ntop6(const unsigned char *src, char *dst, size_t size) {
tp += strlen(tp);
break;
}
tp += sprintf(tp, "%x", words[i]);
tp += snprintf(tp, sizeof tmp - (tp - tmp), "%x", words[i]);
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) == ARRAY_SIZE(words))

View File

@ -18,91 +18,73 @@
#include <stddef.h>
typedef void *QUEUE[2];
#define uv__queue_data(pointer, type, field) \
((type*) ((char*) (pointer) - offsetof(type, field)))
/* Private macros. */
#define QUEUE_NEXT(q) (*(QUEUE **) &((*(q))[0]))
#define QUEUE_PREV(q) (*(QUEUE **) &((*(q))[1]))
#define QUEUE_PREV_NEXT(q) (QUEUE_NEXT(QUEUE_PREV(q)))
#define QUEUE_NEXT_PREV(q) (QUEUE_PREV(QUEUE_NEXT(q)))
#define uv__queue_foreach(q, h) \
for ((q) = (h)->next; (q) != (h); (q) = (q)->next)
/* Public macros. */
#define QUEUE_DATA(ptr, type, field) \
((type *) ((char *) (ptr) - offsetof(type, field)))
static inline void uv__queue_init(struct uv__queue* q) {
q->next = q;
q->prev = q;
}
/* Important note: mutating the list while QUEUE_FOREACH is
* iterating over its elements results in undefined behavior.
*/
#define QUEUE_FOREACH(q, h) \
for ((q) = QUEUE_NEXT(h); (q) != (h); (q) = QUEUE_NEXT(q))
static inline int uv__queue_empty(const struct uv__queue* q) {
return q == q->next;
}
#define QUEUE_EMPTY(q) \
((const QUEUE *) (q) == (const QUEUE *) QUEUE_NEXT(q))
static inline struct uv__queue* uv__queue_head(const struct uv__queue* q) {
return q->next;
}
#define QUEUE_HEAD(q) \
(QUEUE_NEXT(q))
static inline struct uv__queue* uv__queue_next(const struct uv__queue* q) {
return q->next;
}
#define QUEUE_INIT(q) \
do { \
QUEUE_NEXT(q) = (q); \
QUEUE_PREV(q) = (q); \
} \
while (0)
static inline void uv__queue_add(struct uv__queue* h, struct uv__queue* n) {
h->prev->next = n->next;
n->next->prev = h->prev;
h->prev = n->prev;
h->prev->next = h;
}
#define QUEUE_ADD(h, n) \
do { \
QUEUE_PREV_NEXT(h) = QUEUE_NEXT(n); \
QUEUE_NEXT_PREV(n) = QUEUE_PREV(h); \
QUEUE_PREV(h) = QUEUE_PREV(n); \
QUEUE_PREV_NEXT(h) = (h); \
} \
while (0)
static inline void uv__queue_split(struct uv__queue* h,
struct uv__queue* q,
struct uv__queue* n) {
n->prev = h->prev;
n->prev->next = n;
n->next = q;
h->prev = q->prev;
h->prev->next = h;
q->prev = n;
}
#define QUEUE_SPLIT(h, q, n) \
do { \
QUEUE_PREV(n) = QUEUE_PREV(h); \
QUEUE_PREV_NEXT(n) = (n); \
QUEUE_NEXT(n) = (q); \
QUEUE_PREV(h) = QUEUE_PREV(q); \
QUEUE_PREV_NEXT(h) = (h); \
QUEUE_PREV(q) = (n); \
} \
while (0)
static inline void uv__queue_move(struct uv__queue* h, struct uv__queue* n) {
if (uv__queue_empty(h))
uv__queue_init(n);
else
uv__queue_split(h, h->next, n);
}
#define QUEUE_MOVE(h, n) \
do { \
if (QUEUE_EMPTY(h)) \
QUEUE_INIT(n); \
else { \
QUEUE* q = QUEUE_HEAD(h); \
QUEUE_SPLIT(h, q, n); \
} \
} \
while (0)
static inline void uv__queue_insert_head(struct uv__queue* h,
struct uv__queue* q) {
q->next = h->next;
q->prev = h;
q->next->prev = q;
h->next = q;
}
#define QUEUE_INSERT_HEAD(h, q) \
do { \
QUEUE_NEXT(q) = QUEUE_NEXT(h); \
QUEUE_PREV(q) = (h); \
QUEUE_NEXT_PREV(q) = (q); \
QUEUE_NEXT(h) = (q); \
} \
while (0)
static inline void uv__queue_insert_tail(struct uv__queue* h,
struct uv__queue* q) {
q->next = h;
q->prev = h->prev;
q->prev->next = q;
h->prev = q;
}
#define QUEUE_INSERT_TAIL(h, q) \
do { \
QUEUE_NEXT(q) = (h); \
QUEUE_PREV(q) = QUEUE_PREV(h); \
QUEUE_PREV_NEXT(q) = (q); \
QUEUE_PREV(h) = (q); \
} \
while (0)
#define QUEUE_REMOVE(q) \
do { \
QUEUE_PREV_NEXT(q) = QUEUE_NEXT(q); \
QUEUE_NEXT_PREV(q) = QUEUE_PREV(q); \
} \
while (0)
static inline void uv__queue_remove(struct uv__queue* q) {
q->prev->next = q->next;
q->next->prev = q->prev;
}
#endif /* QUEUE_H_ */

View File

@ -82,7 +82,7 @@ static void uv__random_done(struct uv__work* w, int status) {
uv_random_t* req;
req = container_of(w, uv_random_t, work_req);
uv__req_unregister(req->loop, req);
uv__req_unregister(req->loop);
if (status == 0)
status = req->status;

View File

@ -28,7 +28,7 @@
*/
#include "uv.h"
/* Copies up to |n-1| bytes from |d| to |s| and always zero-terminates
/* Copies up to |n-1| bytes from |s| to |d| and always zero-terminates
* the result, except when |n==0|. Returns the number of bytes copied
* or UV_E2BIG if |d| is too small.
*

52
src/strtok.c Normal file
View File

@ -0,0 +1,52 @@
/* Copyright libuv project contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <stdlib.h>
#include "strtok.h"
char* uv__strtok(char* str, const char* sep, char** itr) {
const char* sep_itr;
char* tmp;
char* start;
if (str == NULL)
start = tmp = *itr;
else
start = tmp = str;
if (tmp == NULL)
return NULL;
while (*tmp != '\0') {
sep_itr = sep;
while (*sep_itr != '\0') {
if (*tmp == *sep_itr) {
*itr = tmp + 1;
*tmp = '\0';
return start;
}
sep_itr++;
}
tmp++;
}
*itr = NULL;
return start;
}

27
src/strtok.h Normal file
View File

@ -0,0 +1,27 @@
/* Copyright libuv project contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef UV_STRTOK_H_
#define UV_STRTOK_H_
char* uv__strtok(char* str, const char* sep, char** itr);
#endif /* UV_STRTOK_H_ */

175
src/thread-common.c Normal file
View File

@ -0,0 +1,175 @@
/* Copyright libuv project contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "uv.h"
#include "uv-common.h"
#include <stdlib.h>
#ifndef _WIN32
#include <pthread.h>
#endif
#if defined(PTHREAD_BARRIER_SERIAL_THREAD)
STATIC_ASSERT(sizeof(uv_barrier_t) == sizeof(pthread_barrier_t));
#endif
/* Note: guard clauses should match uv_barrier_t's in include/uv/unix.h. */
#if defined(_AIX) || \
defined(__OpenBSD__) || \
!defined(PTHREAD_BARRIER_SERIAL_THREAD)
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
int rc;
#ifdef _WIN32
uv_barrier_t* b;
b = barrier;
if (barrier == NULL || count == 0)
return UV_EINVAL;
#else
struct _uv_barrier* b;
if (barrier == NULL || count == 0)
return UV_EINVAL;
b = uv__malloc(sizeof(*b));
if (b == NULL)
return UV_ENOMEM;
#endif
b->in = 0;
b->out = 0;
b->threshold = count;
rc = uv_mutex_init(&b->mutex);
if (rc != 0)
goto error2;
/* TODO(vjnash): remove these uv_cond_t casts in v2. */
rc = uv_cond_init((uv_cond_t*) &b->cond);
if (rc != 0)
goto error;
#ifndef _WIN32
barrier->b = b;
#endif
return 0;
error:
uv_mutex_destroy(&b->mutex);
error2:
#ifndef _WIN32
uv__free(b);
#endif
return rc;
}
int uv_barrier_wait(uv_barrier_t* barrier) {
int last;
#ifdef _WIN32
uv_barrier_t* b;
b = barrier;
#else
struct _uv_barrier* b;
if (barrier == NULL || barrier->b == NULL)
return UV_EINVAL;
b = barrier->b;
#endif
uv_mutex_lock(&b->mutex);
while (b->out != 0)
uv_cond_wait((uv_cond_t*) &b->cond, &b->mutex);
if (++b->in == b->threshold) {
b->in = 0;
b->out = b->threshold;
uv_cond_broadcast((uv_cond_t*) &b->cond);
} else {
do
uv_cond_wait((uv_cond_t*) &b->cond, &b->mutex);
while (b->in != 0);
}
last = (--b->out == 0);
if (last)
uv_cond_broadcast((uv_cond_t*) &b->cond);
uv_mutex_unlock(&b->mutex);
return last;
}
void uv_barrier_destroy(uv_barrier_t* barrier) {
#ifdef _WIN32
uv_barrier_t* b;
b = barrier;
#else
struct _uv_barrier* b;
b = barrier->b;
#endif
uv_mutex_lock(&b->mutex);
assert(b->in == 0);
while (b->out != 0)
uv_cond_wait((uv_cond_t*) &b->cond, &b->mutex);
if (b->in != 0)
abort();
uv_mutex_unlock(&b->mutex);
uv_mutex_destroy(&b->mutex);
uv_cond_destroy((uv_cond_t*) &b->cond);
#ifndef _WIN32
uv__free(barrier->b);
barrier->b = NULL;
#endif
}
#else
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
return UV__ERR(pthread_barrier_init(barrier, NULL, count));
}
int uv_barrier_wait(uv_barrier_t* barrier) {
int rc;
rc = pthread_barrier_wait(barrier);
if (rc != 0)
if (rc != PTHREAD_BARRIER_SERIAL_THREAD)
abort();
return rc == PTHREAD_BARRIER_SERIAL_THREAD;
}
void uv_barrier_destroy(uv_barrier_t* barrier) {
if (pthread_barrier_destroy(barrier))
abort();
}
#endif

View File

@ -37,10 +37,10 @@ static unsigned int slow_io_work_running;
static unsigned int nthreads;
static uv_thread_t* threads;
static uv_thread_t default_threads[4];
static QUEUE exit_message;
static QUEUE wq;
static QUEUE run_slow_work_message;
static QUEUE slow_io_pending_wq;
static struct uv__queue exit_message;
static struct uv__queue wq;
static struct uv__queue run_slow_work_message;
static struct uv__queue slow_io_pending_wq;
static unsigned int slow_work_thread_threshold(void) {
return (nthreads + 1) / 2;
@ -56,9 +56,10 @@ static void uv__cancelled(struct uv__work* w) {
*/
static void worker(void* arg) {
struct uv__work* w;
QUEUE* q;
struct uv__queue* q;
int is_slow_work;
uv_thread_setname("libuv-worker");
uv_sem_post((uv_sem_t*) arg);
arg = NULL;
@ -68,49 +69,49 @@ static void worker(void* arg) {
/* Keep waiting while either no work is present or only slow I/O
and we're at the threshold for that. */
while (QUEUE_EMPTY(&wq) ||
(QUEUE_HEAD(&wq) == &run_slow_work_message &&
QUEUE_NEXT(&run_slow_work_message) == &wq &&
while (uv__queue_empty(&wq) ||
(uv__queue_head(&wq) == &run_slow_work_message &&
uv__queue_next(&run_slow_work_message) == &wq &&
slow_io_work_running >= slow_work_thread_threshold())) {
idle_threads += 1;
uv_cond_wait(&cond, &mutex);
idle_threads -= 1;
}
q = QUEUE_HEAD(&wq);
q = uv__queue_head(&wq);
if (q == &exit_message) {
uv_cond_signal(&cond);
uv_mutex_unlock(&mutex);
break;
}
QUEUE_REMOVE(q);
QUEUE_INIT(q); /* Signal uv_cancel() that the work req is executing. */
uv__queue_remove(q);
uv__queue_init(q); /* Signal uv_cancel() that the work req is executing. */
is_slow_work = 0;
if (q == &run_slow_work_message) {
/* If we're at the slow I/O threshold, re-schedule until after all
other work in the queue is done. */
if (slow_io_work_running >= slow_work_thread_threshold()) {
QUEUE_INSERT_TAIL(&wq, q);
uv__queue_insert_tail(&wq, q);
continue;
}
/* If we encountered a request to run slow I/O work but there is none
to run, that means it's cancelled => Start over. */
if (QUEUE_EMPTY(&slow_io_pending_wq))
if (uv__queue_empty(&slow_io_pending_wq))
continue;
is_slow_work = 1;
slow_io_work_running++;
q = QUEUE_HEAD(&slow_io_pending_wq);
QUEUE_REMOVE(q);
QUEUE_INIT(q);
q = uv__queue_head(&slow_io_pending_wq);
uv__queue_remove(q);
uv__queue_init(q);
/* If there is more slow I/O work, schedule it to be run as well. */
if (!QUEUE_EMPTY(&slow_io_pending_wq)) {
QUEUE_INSERT_TAIL(&wq, &run_slow_work_message);
if (!uv__queue_empty(&slow_io_pending_wq)) {
uv__queue_insert_tail(&wq, &run_slow_work_message);
if (idle_threads > 0)
uv_cond_signal(&cond);
}
@ -118,13 +119,13 @@ static void worker(void* arg) {
uv_mutex_unlock(&mutex);
w = QUEUE_DATA(q, struct uv__work, wq);
w = uv__queue_data(q, struct uv__work, wq);
w->work(w);
uv_mutex_lock(&w->loop->wq_mutex);
w->work = NULL; /* Signal uv_cancel() that the work req is done
executing. */
QUEUE_INSERT_TAIL(&w->loop->wq, &w->wq);
uv__queue_insert_tail(&w->loop->wq, &w->wq);
uv_async_send(&w->loop->wq_async);
uv_mutex_unlock(&w->loop->wq_mutex);
@ -139,12 +140,12 @@ static void worker(void* arg) {
}
static void post(QUEUE* q, enum uv__work_kind kind) {
static void post(struct uv__queue* q, enum uv__work_kind kind) {
uv_mutex_lock(&mutex);
if (kind == UV__WORK_SLOW_IO) {
/* Insert into a separate queue. */
QUEUE_INSERT_TAIL(&slow_io_pending_wq, q);
if (!QUEUE_EMPTY(&run_slow_work_message)) {
uv__queue_insert_tail(&slow_io_pending_wq, q);
if (!uv__queue_empty(&run_slow_work_message)) {
/* Running slow I/O tasks is already scheduled => Nothing to do here.
The worker that runs said other task will schedule this one as well. */
uv_mutex_unlock(&mutex);
@ -153,7 +154,7 @@ static void post(QUEUE* q, enum uv__work_kind kind) {
q = &run_slow_work_message;
}
QUEUE_INSERT_TAIL(&wq, q);
uv__queue_insert_tail(&wq, q);
if (idle_threads > 0)
uv_cond_signal(&cond);
uv_mutex_unlock(&mutex);
@ -191,6 +192,7 @@ void uv__threadpool_cleanup(void) {
static void init_threads(void) {
uv_thread_options_t config;
unsigned int i;
const char* val;
uv_sem_t sem;
@ -219,15 +221,18 @@ static void init_threads(void) {
if (uv_mutex_init(&mutex))
abort();
QUEUE_INIT(&wq);
QUEUE_INIT(&slow_io_pending_wq);
QUEUE_INIT(&run_slow_work_message);
uv__queue_init(&wq);
uv__queue_init(&slow_io_pending_wq);
uv__queue_init(&run_slow_work_message);
if (uv_sem_init(&sem, 0))
abort();
config.flags = UV_THREAD_HAS_STACK_SIZE;
config.stack_size = 8u << 20; /* 8 MB */
for (i = 0; i < nthreads; i++)
if (uv_thread_create(threads + i, worker, &sem))
if (uv_thread_create_ex(threads + i, &config, worker, &sem))
abort();
for (i = 0; i < nthreads; i++)
@ -271,15 +276,19 @@ void uv__work_submit(uv_loop_t* loop,
}
/* TODO(bnoordhuis) teach libuv how to cancel file operations
* that go through io_uring instead of the thread pool.
*/
static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) {
int cancelled;
uv_once(&once, init_once); /* Ensure |mutex| is initialized. */
uv_mutex_lock(&mutex);
uv_mutex_lock(&w->loop->wq_mutex);
cancelled = !QUEUE_EMPTY(&w->wq) && w->work != NULL;
cancelled = !uv__queue_empty(&w->wq) && w->work != NULL;
if (cancelled)
QUEUE_REMOVE(&w->wq);
uv__queue_remove(&w->wq);
uv_mutex_unlock(&w->loop->wq_mutex);
uv_mutex_unlock(&mutex);
@ -289,7 +298,7 @@ static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) {
w->work = uv__cancelled;
uv_mutex_lock(&loop->wq_mutex);
QUEUE_INSERT_TAIL(&loop->wq, &w->wq);
uv__queue_insert_tail(&loop->wq, &w->wq);
uv_async_send(&loop->wq_async);
uv_mutex_unlock(&loop->wq_mutex);
@ -300,22 +309,39 @@ static int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) {
void uv__work_done(uv_async_t* handle) {
struct uv__work* w;
uv_loop_t* loop;
QUEUE* q;
QUEUE wq;
struct uv__queue* q;
struct uv__queue wq;
int err;
int nevents;
loop = container_of(handle, uv_loop_t, wq_async);
uv_mutex_lock(&loop->wq_mutex);
QUEUE_MOVE(&loop->wq, &wq);
uv__queue_move(&loop->wq, &wq);
uv_mutex_unlock(&loop->wq_mutex);
while (!QUEUE_EMPTY(&wq)) {
q = QUEUE_HEAD(&wq);
QUEUE_REMOVE(q);
nevents = 0;
while (!uv__queue_empty(&wq)) {
q = uv__queue_head(&wq);
uv__queue_remove(q);
w = container_of(q, struct uv__work, wq);
err = (w->work == uv__cancelled) ? UV_ECANCELED : 0;
w->done(w, err);
nevents++;
}
/* This check accomplishes 2 things:
* 1. Even if the queue was empty, the call to uv__work_done() should count
* as an event. Which will have been added by the event loop when
* calling this callback.
* 2. Prevents accidental wrap around in case nevents == 0 events == 0.
*/
if (nevents > 1) {
/* Subtract 1 to counter the call to uv__work_done(). */
uv__metrics_inc_events(loop, nevents - 1);
if (uv__get_internal_fields(loop)->current_timeout == 0)
uv__metrics_inc_events_waiting(loop, nevents - 1);
}
}
@ -331,7 +357,7 @@ static void uv__queue_done(struct uv__work* w, int err) {
uv_work_t* req;
req = container_of(w, uv_work_t, work_req);
uv__req_unregister(req->loop, req);
uv__req_unregister(req->loop);
if (req->after_work_cb == NULL)
return;

View File

@ -40,8 +40,8 @@ static int timer_less_than(const struct heap_node* ha,
const uv_timer_t* a;
const uv_timer_t* b;
a = container_of(ha, uv_timer_t, heap_node);
b = container_of(hb, uv_timer_t, heap_node);
a = container_of(ha, uv_timer_t, node.heap);
b = container_of(hb, uv_timer_t, node.heap);
if (a->timeout < b->timeout)
return 1;
@ -60,6 +60,7 @@ int uv_timer_init(uv_loop_t* loop, uv_timer_t* handle) {
handle->timer_cb = NULL;
handle->timeout = 0;
handle->repeat = 0;
uv__queue_init(&handle->node.queue);
return 0;
}
@ -73,7 +74,6 @@ int uv_timer_start(uv_timer_t* handle,
if (uv__is_closing(handle) || cb == NULL)
return UV_EINVAL;
if (uv__is_active(handle))
uv_timer_stop(handle);
clamped_timeout = handle->loop->time + timeout;
@ -87,7 +87,7 @@ int uv_timer_start(uv_timer_t* handle,
handle->start_id = handle->loop->timer_counter++;
heap_insert(timer_heap(handle->loop),
(struct heap_node*) &handle->heap_node,
(struct heap_node*) &handle->node.heap,
timer_less_than);
uv__handle_start(handle);
@ -96,14 +96,16 @@ int uv_timer_start(uv_timer_t* handle,
int uv_timer_stop(uv_timer_t* handle) {
if (!uv__is_active(handle))
return 0;
if (uv__is_active(handle)) {
heap_remove(timer_heap(handle->loop),
(struct heap_node*) &handle->heap_node,
(struct heap_node*) &handle->node.heap,
timer_less_than);
uv__handle_stop(handle);
} else {
uv__queue_remove(&handle->node.queue);
}
uv__queue_init(&handle->node.queue);
return 0;
}
@ -148,7 +150,7 @@ int uv__next_timeout(const uv_loop_t* loop) {
if (heap_node == NULL)
return -1; /* block indefinitely */
handle = container_of(heap_node, uv_timer_t, heap_node);
handle = container_of(heap_node, uv_timer_t, node.heap);
if (handle->timeout <= loop->time)
return 0;
@ -163,17 +165,30 @@ int uv__next_timeout(const uv_loop_t* loop) {
void uv__run_timers(uv_loop_t* loop) {
struct heap_node* heap_node;
uv_timer_t* handle;
struct uv__queue* queue_node;
struct uv__queue ready_queue;
uv__queue_init(&ready_queue);
for (;;) {
heap_node = heap_min(timer_heap(loop));
if (heap_node == NULL)
break;
handle = container_of(heap_node, uv_timer_t, heap_node);
handle = container_of(heap_node, uv_timer_t, node.heap);
if (handle->timeout > loop->time)
break;
uv_timer_stop(handle);
uv__queue_insert_tail(&ready_queue, &handle->node.queue);
}
while (!uv__queue_empty(&ready_queue)) {
queue_node = uv__queue_head(&ready_queue);
uv__queue_remove(queue_node);
uv__queue_init(queue_node);
handle = container_of(queue_node, uv_timer_t, node.queue);
uv_timer_again(handle);
handle->timer_cb(handle);
}

View File

@ -131,11 +131,12 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
void uv__io_poll(uv_loop_t* loop, int timeout) {
uv__loop_internal_fields_t* lfields;
struct pollfd events[1024];
struct pollfd pqry;
struct pollfd* pe;
struct poll_ctl pc;
QUEUE* q;
struct uv__queue* q;
uv__io_t* w;
uint64_t base;
uint64_t diff;
@ -150,16 +151,18 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
int reset_timeout;
if (loop->nfds == 0) {
assert(QUEUE_EMPTY(&loop->watcher_queue));
assert(uv__queue_empty(&loop->watcher_queue));
return;
}
while (!QUEUE_EMPTY(&loop->watcher_queue)) {
q = QUEUE_HEAD(&loop->watcher_queue);
QUEUE_REMOVE(q);
QUEUE_INIT(q);
lfields = uv__get_internal_fields(loop);
w = QUEUE_DATA(q, uv__io_t, watcher_queue);
while (!uv__queue_empty(&loop->watcher_queue)) {
q = uv__queue_head(&loop->watcher_queue);
uv__queue_remove(q);
uv__queue_init(q);
w = uv__queue_data(q, uv__io_t, watcher_queue);
assert(w->pevents != 0);
assert(w->fd >= 0);
assert(w->fd < (int) loop->nwatchers);
@ -217,7 +220,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
base = loop->time;
count = 48; /* Benchmarks suggest this gives the best throughput. */
if (uv__get_internal_fields(loop)->flags & UV_METRICS_IDLE_TIME) {
if (lfields->flags & UV_METRICS_IDLE_TIME) {
reset_timeout = 1;
user_timeout = timeout;
timeout = 0;
@ -232,6 +235,12 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (timeout != 0)
uv__metrics_set_provider_entry_time(loop);
/* Store the current timeout in a location that's globally accessible so
* other locations like uv__work_done() can determine whether the queue
* of events in the callback were waiting when poll was called.
*/
lfields->current_timeout = timeout;
nfds = pollset_poll(loop->backend_fd,
events,
ARRAY_SIZE(events),
@ -321,9 +330,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
nevents++;
}
uv__metrics_inc_events(loop, nevents);
if (reset_timeout != 0) {
timeout = user_timeout;
reset_timeout = 0;
uv__metrics_inc_events_waiting(loop, nevents);
}
if (have_signals != 0) {
@ -389,6 +400,11 @@ uint64_t uv_get_constrained_memory(void) {
}
uint64_t uv_get_available_memory(void) {
return uv_get_free_memory();
}
void uv_loadavg(double avg[3]) {
perfstat_cpu_total_t ps_total;
int result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1);
@ -425,7 +441,7 @@ static char* uv__rawname(const char* cp, char (*dst)[FILENAME_MAX+1]) {
static int uv__path_is_a_directory(char* filename) {
struct stat statbuf;
if (stat(filename, &statbuf) < 0)
if (uv__stat(filename, &statbuf) < 0)
return -1; /* failed: not a directory, assume it is a file */
if (statbuf.st_type == VDIR)
@ -1104,6 +1120,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
struct ifreq *ifr, *p, flg;
struct in6_ifreq if6;
struct sockaddr_dl* sa_addr;
size_t namelen;
char* name;
ifc.ifc_req = NULL;
sock6fd = -1;
@ -1140,6 +1158,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
#define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p))
/* Count all up and running ipv4/ipv6 addresses */
namelen = 0;
ifr = ifc.ifc_req;
while ((char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len) {
p = ifr;
@ -1159,6 +1178,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
continue;
namelen += strlen(ent->ifa_name) + 1;
(*count)++;
}
@ -1166,8 +1186,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
goto cleanup;
/* Alloc the return interface structs */
*addresses = uv__calloc(*count, sizeof(**addresses));
if (!(*addresses)) {
*addresses = uv__calloc(1, *count * sizeof(**addresses) + namelen);
if (*addresses == NULL) {
r = UV_ENOMEM;
goto cleanup;
}
@ -1194,7 +1214,9 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
/* All conditions above must match count loop */
address->name = uv__strdup(p->ifr_name);
namelen = strlen(p->ifr_name) + 1;
address->name = memcpy(name, p->ifr_name, namelen);
name += namelen;
if (inet6)
address->address.address6 = *((struct sockaddr_in6*) &p->ifr_addr);
@ -1267,12 +1289,6 @@ cleanup:
void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
int i;
for (i = 0; i < count; ++i) {
uv__free(addresses[i].name);
}
uv__free(addresses);
}

View File

@ -1,713 +0,0 @@
/*
Copyright (c) 2013, Kenneth MacKay
Copyright (c) 2014, Emergya (Cloud4all, FP7/2007-2013 grant agreement #289016)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "uv/android-ifaddrs.h"
#include "uv-common.h"
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/if_packet.h>
typedef struct NetlinkList
{
struct NetlinkList *m_next;
struct nlmsghdr *m_data;
unsigned int m_size;
} NetlinkList;
static int netlink_socket(pid_t *p_pid)
{
struct sockaddr_nl l_addr;
socklen_t l_len;
int l_socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if(l_socket < 0)
{
return -1;
}
memset(&l_addr, 0, sizeof(l_addr));
l_addr.nl_family = AF_NETLINK;
if(bind(l_socket, (struct sockaddr *)&l_addr, sizeof(l_addr)) < 0)
{
close(l_socket);
return -1;
}
l_len = sizeof(l_addr);
if(getsockname(l_socket, (struct sockaddr *)&l_addr, &l_len) < 0)
{
close(l_socket);
return -1;
}
*p_pid = l_addr.nl_pid;
return l_socket;
}
static int netlink_send(int p_socket, int p_request)
{
char l_buffer[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + NLMSG_ALIGN(sizeof(struct rtgenmsg))];
struct nlmsghdr *l_hdr;
struct rtgenmsg *l_msg;
struct sockaddr_nl l_addr;
memset(l_buffer, 0, sizeof(l_buffer));
l_hdr = (struct nlmsghdr *)l_buffer;
l_msg = (struct rtgenmsg *)NLMSG_DATA(l_hdr);
l_hdr->nlmsg_len = NLMSG_LENGTH(sizeof(*l_msg));
l_hdr->nlmsg_type = p_request;
l_hdr->nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
l_hdr->nlmsg_pid = 0;
l_hdr->nlmsg_seq = p_socket;
l_msg->rtgen_family = AF_UNSPEC;
memset(&l_addr, 0, sizeof(l_addr));
l_addr.nl_family = AF_NETLINK;
return (sendto(p_socket, l_hdr, l_hdr->nlmsg_len, 0, (struct sockaddr *)&l_addr, sizeof(l_addr)));
}
static int netlink_recv(int p_socket, void *p_buffer, size_t p_len)
{
struct sockaddr_nl l_addr;
struct msghdr l_msg;
struct iovec l_iov;
l_iov.iov_base = p_buffer;
l_iov.iov_len = p_len;
for(;;)
{
int l_result;
l_msg.msg_name = (void *)&l_addr;
l_msg.msg_namelen = sizeof(l_addr);
l_msg.msg_iov = &l_iov;
l_msg.msg_iovlen = 1;
l_msg.msg_control = NULL;
l_msg.msg_controllen = 0;
l_msg.msg_flags = 0;
l_result = recvmsg(p_socket, &l_msg, 0);
if(l_result < 0)
{
if(errno == EINTR)
{
continue;
}
return -2;
}
/* Buffer was too small */
if(l_msg.msg_flags & MSG_TRUNC)
{
return -1;
}
return l_result;
}
}
static struct nlmsghdr *getNetlinkResponse(int p_socket, pid_t p_pid, int *p_size, int *p_done)
{
size_t l_size = 4096;
void *l_buffer = NULL;
for(;;)
{
int l_read;
uv__free(l_buffer);
l_buffer = uv__malloc(l_size);
if (l_buffer == NULL)
{
return NULL;
}
l_read = netlink_recv(p_socket, l_buffer, l_size);
*p_size = l_read;
if(l_read == -2)
{
uv__free(l_buffer);
return NULL;
}
if(l_read >= 0)
{
struct nlmsghdr *l_hdr;
for(l_hdr = (struct nlmsghdr *)l_buffer; NLMSG_OK(l_hdr, (unsigned int)l_read); l_hdr = (struct nlmsghdr *)NLMSG_NEXT(l_hdr, l_read))
{
if((pid_t)l_hdr->nlmsg_pid != p_pid || (int)l_hdr->nlmsg_seq != p_socket)
{
continue;
}
if(l_hdr->nlmsg_type == NLMSG_DONE)
{
*p_done = 1;
break;
}
if(l_hdr->nlmsg_type == NLMSG_ERROR)
{
uv__free(l_buffer);
return NULL;
}
}
return l_buffer;
}
l_size *= 2;
}
}
static NetlinkList *newListItem(struct nlmsghdr *p_data, unsigned int p_size)
{
NetlinkList *l_item = uv__malloc(sizeof(NetlinkList));
if (l_item == NULL)
{
return NULL;
}
l_item->m_next = NULL;
l_item->m_data = p_data;
l_item->m_size = p_size;
return l_item;
}
static void freeResultList(NetlinkList *p_list)
{
NetlinkList *l_cur;
while(p_list)
{
l_cur = p_list;
p_list = p_list->m_next;
uv__free(l_cur->m_data);
uv__free(l_cur);
}
}
static NetlinkList *getResultList(int p_socket, int p_request, pid_t p_pid)
{
int l_size;
int l_done;
NetlinkList *l_list;
NetlinkList *l_end;
if(netlink_send(p_socket, p_request) < 0)
{
return NULL;
}
l_list = NULL;
l_end = NULL;
l_done = 0;
while(!l_done)
{
NetlinkList *l_item;
struct nlmsghdr *l_hdr = getNetlinkResponse(p_socket, p_pid, &l_size, &l_done);
/* Error */
if(!l_hdr)
{
freeResultList(l_list);
return NULL;
}
l_item = newListItem(l_hdr, l_size);
if (!l_item)
{
freeResultList(l_list);
return NULL;
}
if(!l_list)
{
l_list = l_item;
}
else
{
l_end->m_next = l_item;
}
l_end = l_item;
}
return l_list;
}
static size_t maxSize(size_t a, size_t b)
{
return (a > b ? a : b);
}
static size_t calcAddrLen(sa_family_t p_family, int p_dataSize)
{
switch(p_family)
{
case AF_INET:
return sizeof(struct sockaddr_in);
case AF_INET6:
return sizeof(struct sockaddr_in6);
case AF_PACKET:
return maxSize(sizeof(struct sockaddr_ll), offsetof(struct sockaddr_ll, sll_addr) + p_dataSize);
default:
return maxSize(sizeof(struct sockaddr), offsetof(struct sockaddr, sa_data) + p_dataSize);
}
}
static void makeSockaddr(sa_family_t p_family, struct sockaddr *p_dest, void *p_data, size_t p_size)
{
switch(p_family)
{
case AF_INET:
memcpy(&((struct sockaddr_in*)p_dest)->sin_addr, p_data, p_size);
break;
case AF_INET6:
memcpy(&((struct sockaddr_in6*)p_dest)->sin6_addr, p_data, p_size);
break;
case AF_PACKET:
memcpy(((struct sockaddr_ll*)p_dest)->sll_addr, p_data, p_size);
((struct sockaddr_ll*)p_dest)->sll_halen = p_size;
break;
default:
memcpy(p_dest->sa_data, p_data, p_size);
break;
}
p_dest->sa_family = p_family;
}
static void addToEnd(struct ifaddrs **p_resultList, struct ifaddrs *p_entry)
{
if(!*p_resultList)
{
*p_resultList = p_entry;
}
else
{
struct ifaddrs *l_cur = *p_resultList;
while(l_cur->ifa_next)
{
l_cur = l_cur->ifa_next;
}
l_cur->ifa_next = p_entry;
}
}
static int interpretLink(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList)
{
struct ifaddrs *l_entry;
char *l_index;
char *l_name;
char *l_addr;
char *l_data;
struct ifinfomsg *l_info = (struct ifinfomsg *)NLMSG_DATA(p_hdr);
size_t l_nameSize = 0;
size_t l_addrSize = 0;
size_t l_dataSize = 0;
size_t l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifinfomsg));
struct rtattr *l_rta;
for(l_rta = IFLA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
{
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
switch(l_rta->rta_type)
{
case IFLA_ADDRESS:
case IFLA_BROADCAST:
l_addrSize += NLMSG_ALIGN(calcAddrLen(AF_PACKET, l_rtaDataSize));
break;
case IFLA_IFNAME:
l_nameSize += NLMSG_ALIGN(l_rtaSize + 1);
break;
case IFLA_STATS:
l_dataSize += NLMSG_ALIGN(l_rtaSize);
break;
default:
break;
}
}
l_entry = uv__malloc(sizeof(struct ifaddrs) + sizeof(int) + l_nameSize + l_addrSize + l_dataSize);
if (l_entry == NULL)
{
return -1;
}
memset(l_entry, 0, sizeof(struct ifaddrs));
l_entry->ifa_name = "";
l_index = ((char *)l_entry) + sizeof(struct ifaddrs);
l_name = l_index + sizeof(int);
l_addr = l_name + l_nameSize;
l_data = l_addr + l_addrSize;
/* Save the interface index so we can look it up when handling the
* addresses.
*/
memcpy(l_index, &l_info->ifi_index, sizeof(int));
l_entry->ifa_flags = l_info->ifi_flags;
l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifinfomsg));
for(l_rta = IFLA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
{
void *l_rtaData = RTA_DATA(l_rta);
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
switch(l_rta->rta_type)
{
case IFLA_ADDRESS:
case IFLA_BROADCAST:
{
size_t l_addrLen = calcAddrLen(AF_PACKET, l_rtaDataSize);
makeSockaddr(AF_PACKET, (struct sockaddr *)l_addr, l_rtaData, l_rtaDataSize);
((struct sockaddr_ll *)l_addr)->sll_ifindex = l_info->ifi_index;
((struct sockaddr_ll *)l_addr)->sll_hatype = l_info->ifi_type;
if(l_rta->rta_type == IFLA_ADDRESS)
{
l_entry->ifa_addr = (struct sockaddr *)l_addr;
}
else
{
l_entry->ifa_broadaddr = (struct sockaddr *)l_addr;
}
l_addr += NLMSG_ALIGN(l_addrLen);
break;
}
case IFLA_IFNAME:
strncpy(l_name, l_rtaData, l_rtaDataSize);
l_name[l_rtaDataSize] = '\0';
l_entry->ifa_name = l_name;
break;
case IFLA_STATS:
memcpy(l_data, l_rtaData, l_rtaDataSize);
l_entry->ifa_data = l_data;
break;
default:
break;
}
}
addToEnd(p_resultList, l_entry);
return 0;
}
static struct ifaddrs *findInterface(int p_index, struct ifaddrs **p_links, int p_numLinks)
{
int l_num = 0;
struct ifaddrs *l_cur = *p_links;
while(l_cur && l_num < p_numLinks)
{
char *l_indexPtr = ((char *)l_cur) + sizeof(struct ifaddrs);
int l_index;
memcpy(&l_index, l_indexPtr, sizeof(int));
if(l_index == p_index)
{
return l_cur;
}
l_cur = l_cur->ifa_next;
++l_num;
}
return NULL;
}
static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList, int p_numLinks)
{
struct ifaddrmsg *l_info = (struct ifaddrmsg *)NLMSG_DATA(p_hdr);
struct ifaddrs *l_interface = findInterface(l_info->ifa_index, p_resultList, p_numLinks);
size_t l_nameSize = 0;
size_t l_addrSize = 0;
int l_addedNetmask = 0;
size_t l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg));
struct rtattr *l_rta;
struct ifaddrs *l_entry;
char *l_name;
char *l_addr;
for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
{
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
if(l_info->ifa_family == AF_PACKET)
{
continue;
}
switch(l_rta->rta_type)
{
case IFA_ADDRESS:
case IFA_LOCAL:
l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize));
if((l_info->ifa_family == AF_INET || l_info->ifa_family == AF_INET6) && !l_addedNetmask)
{
/* Make room for netmask */
l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize));
l_addedNetmask = 1;
}
break;
case IFA_BROADCAST:
l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize));
break;
case IFA_LABEL:
l_nameSize += NLMSG_ALIGN(l_rtaDataSize + 1);
break;
default:
break;
}
}
l_entry = uv__malloc(sizeof(struct ifaddrs) + l_nameSize + l_addrSize);
if (l_entry == NULL)
{
return -1;
}
memset(l_entry, 0, sizeof(struct ifaddrs));
l_entry->ifa_name = (l_interface ? l_interface->ifa_name : "");
l_name = ((char *)l_entry) + sizeof(struct ifaddrs);
l_addr = l_name + l_nameSize;
l_entry->ifa_flags = l_info->ifa_flags;
if(l_interface)
{
l_entry->ifa_flags |= l_interface->ifa_flags;
}
l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg));
for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
{
void *l_rtaData = RTA_DATA(l_rta);
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
switch(l_rta->rta_type)
{
case IFA_ADDRESS:
case IFA_BROADCAST:
case IFA_LOCAL:
{
size_t l_addrLen = calcAddrLen(l_info->ifa_family, l_rtaDataSize);
makeSockaddr(l_info->ifa_family, (struct sockaddr *)l_addr, l_rtaData, l_rtaDataSize);
if(l_info->ifa_family == AF_INET6)
{
if(IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)l_rtaData) || IN6_IS_ADDR_MC_LINKLOCAL((struct in6_addr *)l_rtaData))
{
((struct sockaddr_in6 *)l_addr)->sin6_scope_id = l_info->ifa_index;
}
}
/* Apparently in a point-to-point network IFA_ADDRESS contains
* the dest address and IFA_LOCAL contains the local address
*/
if(l_rta->rta_type == IFA_ADDRESS)
{
if(l_entry->ifa_addr)
{
l_entry->ifa_dstaddr = (struct sockaddr *)l_addr;
}
else
{
l_entry->ifa_addr = (struct sockaddr *)l_addr;
}
}
else if(l_rta->rta_type == IFA_LOCAL)
{
if(l_entry->ifa_addr)
{
l_entry->ifa_dstaddr = l_entry->ifa_addr;
}
l_entry->ifa_addr = (struct sockaddr *)l_addr;
}
else
{
l_entry->ifa_broadaddr = (struct sockaddr *)l_addr;
}
l_addr += NLMSG_ALIGN(l_addrLen);
break;
}
case IFA_LABEL:
strncpy(l_name, l_rtaData, l_rtaDataSize);
l_name[l_rtaDataSize] = '\0';
l_entry->ifa_name = l_name;
break;
default:
break;
}
}
if(l_entry->ifa_addr && (l_entry->ifa_addr->sa_family == AF_INET || l_entry->ifa_addr->sa_family == AF_INET6))
{
unsigned l_maxPrefix = (l_entry->ifa_addr->sa_family == AF_INET ? 32 : 128);
unsigned l_prefix = (l_info->ifa_prefixlen > l_maxPrefix ? l_maxPrefix : l_info->ifa_prefixlen);
unsigned char l_mask[16] = {0};
unsigned i;
for(i=0; i<(l_prefix/8); ++i)
{
l_mask[i] = 0xff;
}
if(l_prefix % 8)
{
l_mask[i] = 0xff << (8 - (l_prefix % 8));
}
makeSockaddr(l_entry->ifa_addr->sa_family, (struct sockaddr *)l_addr, l_mask, l_maxPrefix / 8);
l_entry->ifa_netmask = (struct sockaddr *)l_addr;
}
addToEnd(p_resultList, l_entry);
return 0;
}
static int interpretLinks(int p_socket, pid_t p_pid, NetlinkList *p_netlinkList, struct ifaddrs **p_resultList)
{
int l_numLinks = 0;
for(; p_netlinkList; p_netlinkList = p_netlinkList->m_next)
{
unsigned int l_nlsize = p_netlinkList->m_size;
struct nlmsghdr *l_hdr;
for(l_hdr = p_netlinkList->m_data; NLMSG_OK(l_hdr, l_nlsize); l_hdr = NLMSG_NEXT(l_hdr, l_nlsize))
{
if((pid_t)l_hdr->nlmsg_pid != p_pid || (int)l_hdr->nlmsg_seq != p_socket)
{
continue;
}
if(l_hdr->nlmsg_type == NLMSG_DONE)
{
break;
}
if(l_hdr->nlmsg_type == RTM_NEWLINK)
{
if(interpretLink(l_hdr, p_resultList) == -1)
{
return -1;
}
++l_numLinks;
}
}
}
return l_numLinks;
}
static int interpretAddrs(int p_socket, pid_t p_pid, NetlinkList *p_netlinkList, struct ifaddrs **p_resultList, int p_numLinks)
{
for(; p_netlinkList; p_netlinkList = p_netlinkList->m_next)
{
unsigned int l_nlsize = p_netlinkList->m_size;
struct nlmsghdr *l_hdr;
for(l_hdr = p_netlinkList->m_data; NLMSG_OK(l_hdr, l_nlsize); l_hdr = NLMSG_NEXT(l_hdr, l_nlsize))
{
if((pid_t)l_hdr->nlmsg_pid != p_pid || (int)l_hdr->nlmsg_seq != p_socket)
{
continue;
}
if(l_hdr->nlmsg_type == NLMSG_DONE)
{
break;
}
if(l_hdr->nlmsg_type == RTM_NEWADDR)
{
if (interpretAddr(l_hdr, p_resultList, p_numLinks) == -1)
{
return -1;
}
}
}
}
return 0;
}
int getifaddrs(struct ifaddrs **ifap)
{
int l_socket;
int l_result;
int l_numLinks;
pid_t l_pid;
NetlinkList *l_linkResults;
NetlinkList *l_addrResults;
if(!ifap)
{
return -1;
}
*ifap = NULL;
l_socket = netlink_socket(&l_pid);
if(l_socket < 0)
{
return -1;
}
l_linkResults = getResultList(l_socket, RTM_GETLINK, l_pid);
if(!l_linkResults)
{
close(l_socket);
return -1;
}
l_addrResults = getResultList(l_socket, RTM_GETADDR, l_pid);
if(!l_addrResults)
{
close(l_socket);
freeResultList(l_linkResults);
return -1;
}
l_result = 0;
l_numLinks = interpretLinks(l_socket, l_pid, l_linkResults, ifap);
if(l_numLinks == -1 || interpretAddrs(l_socket, l_pid, l_addrResults, ifap, l_numLinks) == -1)
{
l_result = -1;
}
freeResultList(l_linkResults);
freeResultList(l_addrResults);
close(l_socket);
return l_result;
}
void freeifaddrs(struct ifaddrs *ifa)
{
struct ifaddrs *l_cur;
while(ifa)
{
l_cur = ifa;
ifa = ifa->ifa_next;
uv__free(l_cur);
}
}

View File

@ -24,9 +24,9 @@
#include "uv.h"
#include "internal.h"
#include "atomic-ops.h"
#include <errno.h>
#include <stdatomic.h>
#include <stdio.h> /* snprintf() */
#include <assert.h>
#include <stdlib.h>
@ -38,8 +38,37 @@
#include <sys/eventfd.h>
#endif
#if UV__KQUEUE_EVFILT_USER
static uv_once_t kqueue_runtime_detection_guard = UV_ONCE_INIT;
static int kqueue_evfilt_user_support = 1;
static void uv__kqueue_runtime_detection(void) {
int kq;
struct kevent ev[2];
struct timespec timeout = {0, 0};
/* Perform the runtime detection to ensure that kqueue with
* EVFILT_USER actually works. */
kq = kqueue();
EV_SET(ev, UV__KQUEUE_EVFILT_USER_IDENT, EVFILT_USER,
EV_ADD | EV_CLEAR, 0, 0, 0);
EV_SET(ev + 1, UV__KQUEUE_EVFILT_USER_IDENT, EVFILT_USER,
0, NOTE_TRIGGER, 0, 0);
if (kevent(kq, ev, 2, ev, 1, &timeout) < 1 ||
ev[0].filter != EVFILT_USER ||
ev[0].ident != UV__KQUEUE_EVFILT_USER_IDENT ||
ev[0].flags & EV_ERROR)
/* If we wind up here, we can assume that EVFILT_USER is defined but
* broken on the current system. */
kqueue_evfilt_user_support = 0;
uv__close(kq);
}
#endif
static void uv__async_send(uv_loop_t* loop);
static int uv__async_start(uv_loop_t* loop);
static void uv__cpu_relax(void);
int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
@ -52,8 +81,9 @@ int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
uv__handle_init(loop, (uv_handle_t*)handle, UV_ASYNC);
handle->async_cb = async_cb;
handle->pending = 0;
handle->u.fd = 0; /* This will be used as a busy flag. */
QUEUE_INSERT_TAIL(&loop->async_handles, &handle->queue);
uv__queue_insert_tail(&loop->async_handles, &handle->queue);
uv__handle_start(handle);
return 0;
@ -61,46 +91,54 @@ int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
int uv_async_send(uv_async_t* handle) {
_Atomic int* pending;
_Atomic int* busy;
pending = (_Atomic int*) &handle->pending;
busy = (_Atomic int*) &handle->u.fd;
/* Do a cheap read first. */
if (ACCESS_ONCE(int, handle->pending) != 0)
if (atomic_load_explicit(pending, memory_order_relaxed) != 0)
return 0;
/* Tell the other thread we're busy with the handle. */
if (cmpxchgi(&handle->pending, 0, 1) != 0)
return 0;
/* Set the loop to busy. */
atomic_fetch_add(busy, 1);
/* Wake up the other thread's event loop. */
if (atomic_exchange(pending, 1) == 0)
uv__async_send(handle->loop);
/* Tell the other thread we're done. */
if (cmpxchgi(&handle->pending, 1, 2) != 1)
abort();
/* Set the loop to not-busy. */
atomic_fetch_add(busy, -1);
return 0;
}
/* Only call this from the event loop thread. */
static int uv__async_spin(uv_async_t* handle) {
/* Wait for the busy flag to clear before closing.
* Only call this from the event loop thread. */
static void uv__async_spin(uv_async_t* handle) {
_Atomic int* pending;
_Atomic int* busy;
int i;
int rc;
pending = (_Atomic int*) &handle->pending;
busy = (_Atomic int*) &handle->u.fd;
/* Set the pending flag first, so no new events will be added by other
* threads after this function returns. */
atomic_store(pending, 1);
for (;;) {
/* 997 is not completely chosen at random. It's a prime number, acyclical
* by nature, and should therefore hopefully dampen sympathetic resonance.
/* 997 is not completely chosen at random. It's a prime number, acyclic by
* nature, and should therefore hopefully dampen sympathetic resonance.
*/
for (i = 0; i < 997; i++) {
/* rc=0 -- handle is not pending.
* rc=1 -- handle is pending, other thread is still working with it.
* rc=2 -- handle is pending, other thread is done.
*/
rc = cmpxchgi(&handle->pending, 2, 0);
if (rc != 1)
return rc;
if (atomic_load(busy) == 0)
return;
/* Other thread is busy with this handle, spin until it's done. */
cpu_relax();
uv__cpu_relax();
}
/* Yield the CPU. We may have preempted the other thread while it's
@ -114,7 +152,7 @@ static int uv__async_spin(uv_async_t* handle) {
void uv__async_close(uv_async_t* handle) {
uv__async_spin(handle);
QUEUE_REMOVE(&handle->queue);
uv__queue_remove(&handle->queue);
uv__handle_stop(handle);
}
@ -122,13 +160,18 @@ void uv__async_close(uv_async_t* handle) {
static void uv__async_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
char buf[1024];
ssize_t r;
QUEUE queue;
QUEUE* q;
struct uv__queue queue;
struct uv__queue* q;
uv_async_t* h;
_Atomic int *pending;
assert(w == &loop->async_io_watcher);
#if UV__KQUEUE_EVFILT_USER
for (;!kqueue_evfilt_user_support;) {
#else
for (;;) {
#endif
r = read(w->fd, buf, sizeof(buf));
if (r == sizeof(buf))
@ -146,16 +189,18 @@ static void uv__async_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
abort();
}
QUEUE_MOVE(&loop->async_handles, &queue);
while (!QUEUE_EMPTY(&queue)) {
q = QUEUE_HEAD(&queue);
h = QUEUE_DATA(q, uv_async_t, queue);
uv__queue_move(&loop->async_handles, &queue);
while (!uv__queue_empty(&queue)) {
q = uv__queue_head(&queue);
h = uv__queue_data(q, uv_async_t, queue);
QUEUE_REMOVE(q);
QUEUE_INSERT_TAIL(&loop->async_handles, q);
uv__queue_remove(q);
uv__queue_insert_tail(&loop->async_handles, q);
if (0 == uv__async_spin(h))
continue; /* Not pending. */
/* Atomically fetch and clear pending flag */
pending = (_Atomic int*) &h->pending;
if (atomic_exchange(pending, 0) == 0)
continue;
if (h->async_cb == NULL)
continue;
@ -182,6 +227,17 @@ static void uv__async_send(uv_loop_t* loop) {
len = sizeof(val);
fd = loop->async_io_watcher.fd; /* eventfd */
}
#elif UV__KQUEUE_EVFILT_USER
struct kevent ev;
if (kqueue_evfilt_user_support) {
fd = loop->async_io_watcher.fd; /* magic number for EVFILT_USER */
EV_SET(&ev, fd, EVFILT_USER, 0, NOTE_TRIGGER, 0, 0);
r = kevent(loop->backend_fd, &ev, 1, NULL, 0, NULL);
if (r == 0)
return;
abort();
}
#endif
do
@ -202,6 +258,9 @@ static void uv__async_send(uv_loop_t* loop) {
static int uv__async_start(uv_loop_t* loop) {
int pipefd[2];
int err;
#if UV__KQUEUE_EVFILT_USER
struct kevent ev;
#endif
if (loop->async_io_watcher.fd != -1)
return 0;
@ -213,6 +272,36 @@ static int uv__async_start(uv_loop_t* loop) {
pipefd[0] = err;
pipefd[1] = -1;
#elif UV__KQUEUE_EVFILT_USER
uv_once(&kqueue_runtime_detection_guard, uv__kqueue_runtime_detection);
if (kqueue_evfilt_user_support) {
/* In order not to break the generic pattern of I/O polling, a valid
* file descriptor is required to take up a room in loop->watchers,
* thus we create one for that, but this fd will not be actually used,
* it's just a placeholder and magic number which is going to be closed
* during the cleanup, as other FDs. */
err = uv__open_cloexec("/", O_RDONLY);
if (err < 0)
return err;
pipefd[0] = err;
pipefd[1] = -1;
/* When using EVFILT_USER event to wake up the kqueue, this event must be
* registered beforehand. Otherwise, calling kevent() to issue an
* unregistered EVFILT_USER event will get an ENOENT.
* Since uv__async_send() may happen before uv__io_poll() with multi-threads,
* we can't defer this registration of EVFILT_USER event as we did for other
* events, but must perform it right away. */
EV_SET(&ev, err, EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, 0);
err = kevent(loop->backend_fd, &ev, 1, NULL, 0, NULL);
if (err < 0)
return UV__ERR(errno);
} else {
err = uv__make_pipe(pipefd, UV_NONBLOCK_PIPE);
if (err < 0)
return err;
}
#else
err = uv__make_pipe(pipefd, UV_NONBLOCK_PIPE);
if (err < 0)
@ -223,24 +312,39 @@ static int uv__async_start(uv_loop_t* loop) {
uv__io_start(loop, &loop->async_io_watcher, POLLIN);
loop->async_wfd = pipefd[1];
#if UV__KQUEUE_EVFILT_USER
/* Prevent the EVFILT_USER event from being added to kqueue redundantly
* and mistakenly later in uv__io_poll(). */
if (kqueue_evfilt_user_support)
loop->async_io_watcher.events = loop->async_io_watcher.pevents;
#endif
return 0;
}
int uv__async_fork(uv_loop_t* loop) {
if (loop->async_io_watcher.fd == -1) /* never started */
return 0;
uv__async_stop(loop);
return uv__async_start(loop);
}
void uv__async_stop(uv_loop_t* loop) {
struct uv__queue queue;
struct uv__queue* q;
uv_async_t* h;
if (loop->async_io_watcher.fd == -1)
return;
/* Make sure no other thread is accessing the async handle fd after the loop
* cleanup.
*/
uv__queue_move(&loop->async_handles, &queue);
while (!uv__queue_empty(&queue)) {
q = uv__queue_head(&queue);
h = uv__queue_data(q, uv_async_t, queue);
uv__queue_remove(q);
uv__queue_insert_tail(&loop->async_handles, q);
uv__async_spin(h);
}
if (loop->async_wfd != -1) {
if (loop->async_wfd != loop->async_io_watcher.fd)
uv__close(loop->async_wfd);
@ -251,3 +355,58 @@ void uv__async_stop(uv_loop_t* loop) {
uv__close(loop->async_io_watcher.fd);
loop->async_io_watcher.fd = -1;
}
int uv__async_fork(uv_loop_t* loop) {
struct uv__queue queue;
struct uv__queue* q;
uv_async_t* h;
if (loop->async_io_watcher.fd == -1) /* never started */
return 0;
uv__queue_move(&loop->async_handles, &queue);
while (!uv__queue_empty(&queue)) {
q = uv__queue_head(&queue);
h = uv__queue_data(q, uv_async_t, queue);
uv__queue_remove(q);
uv__queue_insert_tail(&loop->async_handles, q);
/* The state of any thread that set pending is now likely corrupt in this
* child because the user called fork, so just clear these flags and move
* on. Calling most libc functions after `fork` is declared to be undefined
* behavior anyways, unless async-signal-safe, for multithreaded programs
* like libuv, and nothing interesting in pthreads is async-signal-safe.
*/
h->pending = 0;
/* This is the busy flag, and we just abruptly lost all other threads. */
h->u.fd = 0;
}
/* Recreate these, since they still exist, but belong to the wrong pid now. */
if (loop->async_wfd != -1) {
if (loop->async_wfd != loop->async_io_watcher.fd)
uv__close(loop->async_wfd);
loop->async_wfd = -1;
}
uv__io_stop(loop, &loop->async_io_watcher, POLLIN);
uv__close(loop->async_io_watcher.fd);
loop->async_io_watcher.fd = -1;
return uv__async_start(loop);
}
static void uv__cpu_relax(void) {
#if defined(__i386__) || defined(__x86_64__)
__asm__ __volatile__ ("rep; nop" ::: "memory"); /* a.k.a. PAUSE */
#elif (defined(__arm__) && __ARM_ARCH >= 7) || defined(__aarch64__)
__asm__ __volatile__ ("yield" ::: "memory");
#elif (defined(__ppc__) || defined(__ppc64__)) && defined(__APPLE__)
__asm volatile ("" : : : "memory");
#elif !defined(__APPLE__) && (defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__))
__asm__ __volatile__ ("or 1,1,1; or 2,2,2" ::: "memory");
#endif
}

View File

@ -1,63 +0,0 @@
/* Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef UV_ATOMIC_OPS_H_
#define UV_ATOMIC_OPS_H_
#include "internal.h" /* UV_UNUSED */
#if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
#include <atomic.h>
#endif
UV_UNUSED(static int cmpxchgi(int* ptr, int oldval, int newval));
UV_UNUSED(static void cpu_relax(void));
/* Prefer hand-rolled assembly over the gcc builtins because the latter also
* issue full memory barriers.
*/
UV_UNUSED(static int cmpxchgi(int* ptr, int oldval, int newval)) {
#if defined(__i386__) || defined(__x86_64__)
int out;
__asm__ __volatile__ ("lock; cmpxchg %2, %1;"
: "=a" (out), "+m" (*(volatile int*) ptr)
: "r" (newval), "0" (oldval)
: "memory");
return out;
#elif defined(__MVS__)
unsigned int op4;
if (__plo_CSST(ptr, (unsigned int*) &oldval, newval,
(unsigned int*) ptr, *ptr, &op4))
return oldval;
else
return op4;
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
return atomic_cas_uint((uint_t *)ptr, (uint_t)oldval, (uint_t)newval);
#else
return __sync_val_compare_and_swap(ptr, oldval, newval);
#endif
}
UV_UNUSED(static void cpu_relax(void)) {
#if defined(__i386__) || defined(__x86_64__)
__asm__ __volatile__ ("rep; nop" ::: "memory"); /* a.k.a. PAUSE */
#elif (defined(__arm__) && __ARM_ARCH >= 7) || defined(__aarch64__)
__asm__ __volatile__ ("yield" ::: "memory");
#elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__)
__asm__ __volatile__ ("or 1,1,1; or 2,2,2" ::: "memory");
#endif
}
#endif /* UV_ATOMIC_OPS_H_ */

View File

@ -27,7 +27,7 @@
#include <ifaddrs.h>
#include <net/if.h>
#if !defined(__CYGWIN__) && !defined(__MSYS__)
#if !defined(__CYGWIN__) && !defined(__MSYS__) && !defined(__GNU__)
#include <net/if_dl.h>
#endif
@ -40,7 +40,7 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
return 1;
if (ent->ifa_addr == NULL)
return 1;
#if !defined(__CYGWIN__) && !defined(__MSYS__)
#if !defined(__CYGWIN__) && !defined(__MSYS__) && !defined(__GNU__)
/*
* If `exclude_type` is `UV__EXCLUDE_IFPHYS`, return whether `sa_family`
* equals `AF_LINK`. Otherwise, the result depends on the operating
@ -65,13 +65,13 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
return 0;
}
/* TODO(bnoordhuis) share with linux.c */
int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
uv_interface_address_t* address;
struct ifaddrs* addrs;
struct ifaddrs* ent;
uv_interface_address_t* address;
#if !(defined(__CYGWIN__) || defined(__MSYS__))
int i;
#endif
size_t namelen;
char* name;
*count = 0;
*addresses = NULL;
@ -80,9 +80,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
return UV__ERR(errno);
/* Count the number of interfaces */
namelen = 0;
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
continue;
namelen += strlen(ent->ifa_name) + 1;
(*count)++;
}
@ -92,20 +94,22 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
}
/* Make sure the memory is initiallized to zero using calloc() */
*addresses = uv__calloc(*count, sizeof(**addresses));
*addresses = uv__calloc(1, *count * sizeof(**addresses) + namelen);
if (*addresses == NULL) {
freeifaddrs(addrs);
return UV_ENOMEM;
}
name = (char*) &(*addresses)[*count];
address = *addresses;
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
continue;
address->name = uv__strdup(ent->ifa_name);
namelen = strlen(ent->ifa_name) + 1;
address->name = memcpy(name, ent->ifa_name, namelen);
name += namelen;
if (ent->ifa_addr->sa_family == AF_INET6) {
address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr);
@ -126,9 +130,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
address++;
}
#if !(defined(__CYGWIN__) || defined(__MSYS__))
#if !(defined(__CYGWIN__) || defined(__MSYS__)) && !defined(__GNU__)
/* Fill in physical addresses for each interface */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
int i;
if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFPHYS))
continue;
@ -151,13 +157,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
}
/* TODO(bnoordhuis) share with linux.c */
void uv_free_interface_addresses(uv_interface_address_t* addresses,
int count) {
int i;
for (i = 0; i < count; i++) {
uv__free(addresses[i].name);
}
uv__free(addresses);
}

View File

@ -38,6 +38,7 @@ static void init_process_title_mutex_once(void) {
void uv__process_title_cleanup(void) {
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_destroy(&process_title_mutex);
}

File diff suppressed because it is too large Load Diff

View File

@ -36,9 +36,45 @@ int uv_uptime(double* uptime) {
}
int uv_resident_set_memory(size_t* rss) {
/* FIXME: read /proc/meminfo? */
*rss = 0;
char buf[1024];
const char* s;
long val;
int rc;
int i;
struct sysinfo si;
/* rss: 24th element */
rc = uv__slurp("/proc/self/stat", buf, sizeof(buf));
if (rc < 0)
return rc;
/* find the last ')' */
s = strrchr(buf, ')');
if (s == NULL)
goto err;
for (i = 1; i <= 22; i++) {
s = strchr(s + 1, ' ');
if (s == NULL)
goto err;
}
errno = 0;
val = strtol(s, NULL, 10);
if (val < 0 || errno != 0)
goto err;
do
rc = sysinfo(&si);
while (rc == -1 && errno == EINTR);
if (rc == -1)
return UV__ERR(errno);
*rss = val * si.mem_unit;
return 0;
err:
return UV_EINVAL;
}
int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
@ -51,3 +87,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uint64_t uv_get_constrained_memory(void) {
return 0; /* Memory constraints are unknown. */
}
uint64_t uv_get_available_memory(void) {
return uv_get_free_memory();
}

View File

@ -33,25 +33,9 @@
#include "darwin-stub.h"
#endif
static int uv__pthread_setname_np(const char* name) {
char namebuf[64]; /* MAXTHREADNAMESIZE */
int err;
strncpy(namebuf, name, sizeof(namebuf) - 1);
namebuf[sizeof(namebuf) - 1] = '\0';
err = pthread_setname_np(namebuf);
if (err)
return UV__ERR(err);
return 0;
}
int uv__set_process_title(const char* title) {
#if TARGET_OS_IPHONE
return uv__pthread_setname_np(title);
return uv__thread_setname(title);
#else
CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
const char*,
@ -177,7 +161,7 @@ int uv__set_process_title(const char* title) {
goto out;
}
uv__pthread_setname_np(title); /* Don't care if it fails. */
uv__thread_setname(title); /* Don't care if it fails. */
err = 0;
out:

View File

@ -27,7 +27,6 @@
struct CFArrayCallBacks;
struct CFRunLoopSourceContext;
struct FSEventStreamContext;
struct CFRange;
typedef double CFAbsoluteTime;
typedef double CFTimeInterval;
@ -43,23 +42,13 @@ typedef unsigned CFStringEncoding;
typedef void* CFAllocatorRef;
typedef void* CFArrayRef;
typedef void* CFBundleRef;
typedef void* CFDataRef;
typedef void* CFDictionaryRef;
typedef void* CFMutableDictionaryRef;
typedef struct CFRange CFRange;
typedef void* CFRunLoopRef;
typedef void* CFRunLoopSourceRef;
typedef void* CFStringRef;
typedef void* CFTypeRef;
typedef void* FSEventStreamRef;
typedef uint32_t IOOptionBits;
typedef unsigned int io_iterator_t;
typedef unsigned int io_object_t;
typedef unsigned int io_service_t;
typedef unsigned int io_registry_entry_t;
typedef void (*FSEventStreamCallback)(const FSEventStreamRef,
void*,
size_t,
@ -80,11 +69,6 @@ struct FSEventStreamContext {
void* pad[3];
};
struct CFRange {
CFIndex location;
CFIndex length;
};
static const CFStringEncoding kCFStringEncodingUTF8 = 0x8000100;
static const OSStatus noErr = 0;

Some files were not shown because too many files have changed in this diff Show More