[upstream_utils] Update to libuv 1.47.0 (#5889)

This commit is contained in:
Tyler Veness
2023-11-14 12:12:56 -08:00
committed by GitHub
parent b3a9c3e96b
commit a8b80ca256
32 changed files with 1411 additions and 1565 deletions

View File

@@ -6,37 +6,38 @@ Subject: [PATCH 01/10] Revert "win,process: write minidumps when sending
This reverts commit 748d894e82abcdfff7429cf745003e182c47f163.
---
CMakeLists.txt | 5 +-
CMakeLists.txt | 6 +--
configure.ac | 2 +-
include/uv/win.h | 1 -
src/win/process.c | 116 ----------------------------------------------
4 files changed, 2 insertions(+), 122 deletions(-)
4 files changed, 2 insertions(+), 123 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 93733dd04783436cc1f1a801133e67e315f4af8d..0958dfb1bd93311cd0e20506311e1e41774c5fa4 100644
index 72377851b69f74c5285fd34ae206ad6bed3745c1..3ec6bd00542f5aacfc6245b1f82e365eb1cff02c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -183,10 +183,7 @@ if(WIN32)
@@ -183,11 +183,7 @@ if(WIN32)
advapi32
iphlpapi
userenv
- ws2_32
- dbghelp
- ole32
- uuid)
- uuid
- shell32)
+ ws2_32)
list(APPEND uv_sources
src/win/async.c
src/win/core.c
diff --git a/configure.ac b/configure.ac
index deb083605de639e896df83882715ddca25340fa3..76177a4bc8e5f17bc1e062af3a9028d2dfc76dc9 100644
index 0a1042ce3d384f6a4392a100275c14cb31ba2816..6c87c36039446e04f6c30c23b8fdb9b957dd610d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,7 +74,7 @@ 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 -ldbghelp -lole32 -luuid"
- LIBS="$LIBS -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -luser32 -ldbghelp -lole32 -luuid -lshell32"
+ LIBS="$LIBS -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -luser32"
])
AS_CASE([$host_os], [solaris2.10], [
@@ -54,7 +55,7 @@ index 6f8c47298e407bcb0151cf383a8370b71074f03e..eb74776978340a4910194bae35a9da64
#define SIGWINCH 28
diff --git a/src/win/process.c b/src/win/process.c
index 3e451e2291d6ed200ec258e874becbbea22bbc27..ed44adc67c6d52785a199206d9ba0357e2d0b045 100644
index 43059858f3112e7e7185796525697629b72988df..119b46cb3f37122395c172c6e9700d472a2173ed 100644
--- a/src/win/process.c
+++ b/src/win/process.c
@@ -32,9 +32,6 @@
@@ -67,7 +68,7 @@ index 3e451e2291d6ed200ec258e874becbbea22bbc27..ed44adc67c6d52785a199206d9ba0357
#define SIGKILL 9
@@ -1197,120 +1194,7 @@ static int uv__kill(HANDLE process_handle, int signum) {
@@ -1173,120 +1170,7 @@ static int uv__kill(HANDLE process_handle, int signum) {
return UV_EINVAL;
}

View File

@@ -5,6 +5,7 @@ Subject: [PATCH 02/10] Fix missing casts
---
src/fs-poll.c | 10 ++++----
src/idna.c | 2 +-
src/inet.c | 11 ++++----
src/strscpy.c | 2 +-
src/thread-common.c | 2 +-
@@ -30,19 +31,23 @@ Subject: [PATCH 02/10] Fix missing casts
src/unix/proctitle.c | 2 +-
src/unix/random-sysctl-linux.c | 2 +-
src/unix/stream.c | 31 ++++++++++++-----------
src/unix/tcp.c | 2 +-
src/unix/thread.c | 5 ++--
src/unix/udp.c | 8 +++---
src/uv-common.c | 16 ++++++------
src/win/core.c | 8 +++---
src/win/dl.c | 2 +-
src/win/fs-event.c | 4 +--
src/win/fs-fd-hash-inl.h | 2 +-
src/win/fs.c | 28 ++++++++++-----------
src/win/pipe.c | 12 ++++-----
src/win/process.c | 12 ++++-----
src/win/fs.c | 38 ++++++++++++++--------------
src/win/getaddrinfo.c | 12 ++++-----
src/win/pipe.c | 8 +++---
src/win/process.c | 22 ++++++++--------
src/win/tcp.c | 2 +-
src/win/thread.c | 4 +--
src/win/util.c | 27 ++++++++++----------
38 files changed, 183 insertions(+), 178 deletions(-)
src/win/tty.c | 6 ++---
src/win/util.c | 35 +++++++++++++-------------
43 files changed, 207 insertions(+), 202 deletions(-)
diff --git a/src/fs-poll.c b/src/fs-poll.c
index 1bac1c568e36cadd0b68451926c6f045f88342d2..5a39daed095502b2db34f23fcaf0ab04f31f96ff 100644
@@ -93,6 +98,19 @@ index 1bac1c568e36cadd0b68451926c6f045f88342d2..5a39daed095502b2db34f23fcaf0ab04
it != ctx;
last = it, it = it->previous) {
assert(last->previous != NULL);
diff --git a/src/idna.c b/src/idna.c
index 1c0a60cf3e3becc1badafa394e7c422af7f56833..0c952cf605a88136ed9035f9385f9b1080c30c28 100644
--- a/src/idna.c
+++ b/src/idna.c
@@ -477,7 +477,7 @@ int uv_utf16_to_wtf8(const uint16_t* w_source_ptr,
return 0;
if (*target_ptr == NULL) {
- target = uv__malloc(target_len + 1);
+ target = (char*)uv__malloc(target_len + 1);
if (target == NULL) {
return UV_ENOMEM;
}
diff --git a/src/inet.c b/src/inet.c
index cd77496846e90e8b8e61c63c10f498f153344fe5..dd94bea3886ca37945fcad7909d765e3700e3c21 100644
--- a/src/inet.c
@@ -279,7 +297,7 @@ index 5288083ef04fd78d90c34071cc76281adbc310d8..9bd55dd764b845cf8ea441d525b4e136
if (display_name_key == NULL || *display_name_key == NULL)
goto out;
diff --git a/src/unix/darwin.c b/src/unix/darwin.c
index 90790d701c4327518d17230c5aa69b9a74112e73..9ee5cd8eb9d02fb8b71986c47fe8a686f0983847 100644
index 5e764a65ee4c71efd61876c70b0e999420f24f61..dc93d236b6b7c6da62dc7aa66cb42ddc125575a2 100644
--- a/src/unix/darwin.c
+++ b/src/unix/darwin.c
@@ -217,7 +217,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
@@ -314,10 +332,10 @@ index 191bc8bc213ffddb15c5e04baa66e2a0a8d69a3d..1bd63886b823be6451ac013d94e29885
uv__free(*cpu_infos);
return UV_ENOMEM;
diff --git a/src/unix/fs.c b/src/unix/fs.c
index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99ae2cb4f7 100644
index 891306daedcc6a9b493bdfefcdb7d43c7efbb622..bc00c90b07a32a823412b216df6f2d758dbc423b 100644
--- a/src/unix/fs.c
+++ b/src/unix/fs.c
@@ -140,7 +140,7 @@ extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */
@@ -134,7 +134,7 @@ extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */
size_t new_path_len; \
path_len = strlen(path) + 1; \
new_path_len = strlen(new_path) + 1; \
@@ -326,7 +344,7 @@ index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99
if (req->path == NULL) \
return UV_ENOMEM; \
req->new_path = req->path + path_len; \
@@ -568,7 +568,7 @@ static ssize_t uv__fs_scandir(uv_fs_t* req) {
@@ -496,7 +496,7 @@ static ssize_t uv__fs_scandir(uv_fs_t* req) {
static int uv__fs_opendir(uv_fs_t* req) {
uv_dir_t* dir;
@@ -335,7 +353,7 @@ index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99
if (dir == NULL)
goto error;
@@ -592,7 +592,7 @@ static int uv__fs_readdir(uv_fs_t* req) {
@@ -520,7 +520,7 @@ static int uv__fs_readdir(uv_fs_t* req) {
unsigned int dirent_idx;
unsigned int i;
@@ -344,7 +362,7 @@ index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99
dirent_idx = 0;
while (dirent_idx < dir->nentries) {
@@ -634,7 +634,7 @@ error:
@@ -562,7 +562,7 @@ error:
static int uv__fs_closedir(uv_fs_t* req) {
uv_dir_t* dir;
@@ -353,7 +371,7 @@ index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99
if (dir->dir != NULL) {
closedir(dir->dir);
@@ -663,7 +663,7 @@ static int uv__fs_statfs(uv_fs_t* req) {
@@ -591,7 +591,7 @@ static int uv__fs_statfs(uv_fs_t* req) {
#endif /* defined(__sun) */
return -1;
@@ -362,7 +380,7 @@ index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99
if (stat_fs == NULL) {
errno = ENOMEM;
return -1;
@@ -727,7 +727,7 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
@@ -655,7 +655,7 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
maxlen = uv__fs_pathmax_size(req->path);
#endif
@@ -371,7 +389,7 @@ index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99
if (buf == NULL) {
errno = ENOMEM;
@@ -747,7 +747,7 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
@@ -675,7 +675,7 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
/* Uncommon case: resize to make room for the trailing nul byte. */
if (len == maxlen) {
@@ -380,7 +398,7 @@ index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99
if (buf == NULL)
return -1;
@@ -770,7 +770,7 @@ static ssize_t uv__fs_realpath(uv_fs_t* req) {
@@ -698,7 +698,7 @@ static ssize_t uv__fs_realpath(uv_fs_t* req) {
ssize_t len;
len = uv__fs_pathmax_size(req->path);
@@ -389,8 +407,8 @@ index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99
if (buf == NULL) {
errno = ENOMEM;
@@ -1984,7 +1984,7 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
req->nbufs = nbufs;
@@ -1886,7 +1886,7 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml))
- req->bufs = uv__malloc(nbufs * sizeof(*bufs));
@@ -398,7 +416,7 @@ index 6b051c124f2fd9b0f72b41d7d7ba9c715e9686e1..e25d02e54dbe93e4b9c22b0140108c99
if (req->bufs == NULL)
return UV_ENOMEM;
@@ -2171,7 +2171,7 @@ int uv_fs_write(uv_loop_t* loop,
@@ -2071,7 +2071,7 @@ int uv_fs_write(uv_loop_t* loop,
req->nbufs = nbufs;
req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml))
@@ -585,10 +603,10 @@ index 837bba6e2fef7b834a8d104d263bef47eaed0950..5e0fa98d104428534e5264a1c6358e3f
return UV_ENOMEM;
}
diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c
index b78242d3be4e3cf6b7b998f56dc65213982d4bc7..28e55aae6c613576ede7024a5c73d746e134d865 100644
index 94ace58680cf391707f68357d7927173cb1db08e..06fbdb24b4adc4adb781d32150d40836fa745531 100644
--- a/src/unix/kqueue.c
+++ b/src/unix/kqueue.c
@@ -299,8 +299,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
@@ -303,8 +303,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
nevents = 0;
assert(loop->watchers != NULL);
@@ -599,7 +617,7 @@ index b78242d3be4e3cf6b7b998f56dc65213982d4bc7..28e55aae6c613576ede7024a5c73d746
for (i = 0; i < nfds; i++) {
ev = events + i;
fd = ev->ident;
@@ -322,7 +322,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
@@ -326,7 +326,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
/* Skip invalidated events, see uv__platform_invalidate_fd */
if (fd == -1)
continue;
@@ -609,10 +627,10 @@ index b78242d3be4e3cf6b7b998f56dc65213982d4bc7..28e55aae6c613576ede7024a5c73d746
if (w == NULL) {
/* File descriptor that we've stopped watching, disarm it. */
diff --git a/src/unix/linux.c b/src/unix/linux.c
index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba84762a027a1 100644
index 8eeb352e6238a9e9557ec4dfc71f192105135cd7..2b8e1d8fe593a181d049aa50ff9edaf6da258a24 100644
--- a/src/unix/linux.c
+++ b/src/unix/linux.c
@@ -456,8 +456,8 @@ static void uv__iou_init(int epollfd,
@@ -518,8 +518,8 @@ static void uv__iou_init(int epollfd,
char* sqe;
int ringfd;
@@ -623,7 +641,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
if (!uv__use_io_uring())
return;
@@ -496,14 +496,14 @@ static void uv__iou_init(int epollfd,
@@ -558,14 +558,14 @@ static void uv__iou_init(int epollfd,
maxlen = sqlen < cqlen ? cqlen : sqlen;
sqelen = params.sq_entries * sizeof(struct uv__io_uring_sqe);
@@ -640,7 +658,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
sqelen,
PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_POPULATE,
@@ -643,7 +643,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
@@ -705,7 +705,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
int i;
lfields = uv__get_internal_fields(loop);
@@ -649,7 +667,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
/* Invalidate events with same file descriptor */
if (inv != NULL)
@@ -718,7 +718,7 @@ static struct uv__io_uring_sqe* uv__iou_get_sqe(struct uv__iou* iou,
@@ -780,7 +780,7 @@ static struct uv__io_uring_sqe* uv__iou_get_sqe(struct uv__iou* iou,
return NULL; /* No room in ring buffer. TODO(bnoordhuis) maybe flush it? */
slot = tail & mask;
@@ -658,7 +676,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
sqe = &sqe[slot];
memset(sqe, 0, sizeof(*sqe));
sqe->user_data = (uintptr_t) req;
@@ -986,7 +986,7 @@ int uv__iou_fs_statx(uv_loop_t* loop,
@@ -1057,7 +1057,7 @@ int uv__iou_fs_statx(uv_loop_t* loop,
struct uv__statx* statxbuf;
struct uv__iou* iou;
@@ -667,7 +685,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
if (statxbuf == NULL)
return 0;
@@ -1050,7 +1050,7 @@ static void uv__iou_fs_statx_post(uv_fs_t* req) {
@@ -1121,7 +1121,7 @@ static void uv__iou_fs_statx_post(uv_fs_t* req) {
uv_stat_t* buf;
buf = &req->statbuf;
@@ -676,7 +694,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
req->ptr = NULL;
if (req->result == 0) {
@@ -1079,7 +1079,7 @@ static void uv__poll_io_uring(uv_loop_t* loop, struct uv__iou* iou) {
@@ -1150,7 +1150,7 @@ static void uv__poll_io_uring(uv_loop_t* loop, struct uv__iou* iou) {
tail = atomic_load_explicit((_Atomic uint32_t*) iou->cqtail,
memory_order_acquire);
mask = iou->cqmask;
@@ -685,7 +703,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
nevents = 0;
for (i = head; i != tail; i++) {
@@ -1170,7 +1170,7 @@ static void uv__epoll_ctl_prep(int epollfd,
@@ -1241,7 +1241,7 @@ static void uv__epoll_ctl_prep(int epollfd,
pe = &(*events)[slot];
*pe = *e;
@@ -694,7 +712,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
sqe = &sqe[slot];
memset(sqe, 0, sizeof(*sqe));
@@ -1226,7 +1226,7 @@ static void uv__epoll_ctl_flush(int epollfd,
@@ -1297,7 +1297,7 @@ static void uv__epoll_ctl_flush(int epollfd,
while (*ctl->cqhead != *ctl->cqtail) {
slot = (*ctl->cqhead)++ & ctl->cqmask;
@@ -703,7 +721,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
cqe = &cqe[slot];
if (cqe->res == 0)
@@ -1708,7 +1708,7 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
@@ -1758,7 +1758,7 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
snprintf(*models, sizeof(*models), "unknown");
maxcpu = 0;
@@ -712,7 +730,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
if (cpus == NULL)
return UV_ENOMEM;
@@ -1764,9 +1764,9 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
@@ -1816,9 +1816,9 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
/* arm64: translate CPU part code to model name. */
if (*parts) {
@@ -724,7 +742,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
else
p += n + 1;
n = (int) strcspn(p, "\n");
@@ -1815,7 +1815,7 @@ nocpuinfo:
@@ -1868,7 +1868,7 @@ nocpuinfo:
}
size = n * sizeof(**ci) + sizeof(models);
@@ -733,7 +751,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
*count = 0;
if (*ci == NULL) {
@@ -1824,7 +1824,7 @@ nocpuinfo:
@@ -1877,7 +1877,7 @@ nocpuinfo:
}
*count = n;
@@ -742,7 +760,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
i = 0;
for (cpu = 0; cpu < maxcpu; cpu++) {
@@ -1833,19 +1833,19 @@ nocpuinfo:
@@ -1886,19 +1886,19 @@ nocpuinfo:
c = *cpus + cpu;
@@ -766,7 +784,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
};
}
@@ -1902,7 +1902,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
@@ -1955,7 +1955,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
}
/* Make sure the memory is initiallized to zero using calloc() */
@@ -775,7 +793,7 @@ index 48b9c2c43e104079d3ccb5d830d1d79f891fb1a3..9173850bd158eaf9c41deca38f9ba847
if (!(*addresses)) {
freeifaddrs(addrs);
return UV_ENOMEM;
@@ -2470,12 +2470,12 @@ int uv_fs_event_start(uv_fs_event_t* handle,
@@ -2523,12 +2523,12 @@ int uv_fs_event_start(uv_fs_event_t* handle,
goto no_insert;
len = strlen(path) + 1;
@@ -1058,8 +1076,21 @@ index 28c4d5463c4622725a433b8807e5e7bde580dadd..265ddade7aec129eb9dbf07cde2a16a0
for (i = 0; i < queued_fds->offset; i++)
uv__close(queued_fds->fds[i]);
uv__free(handle->queued_fds);
diff --git a/src/unix/tcp.c b/src/unix/tcp.c
index a6b53e5913271d0c83e1d7f7e4cb8140f5f3936d..4c4213a4241b51d245146f1a37a371448d57b3b8 100644
--- a/src/unix/tcp.c
+++ b/src/unix/tcp.c
@@ -274,7 +274,7 @@ int uv__tcp_connect(uv_connect_t* req,
memcpy(&tmp6, addr, sizeof(tmp6));
if (tmp6.sin6_scope_id == 0) {
tmp6.sin6_scope_id = uv__ipv6_link_local_scope_id();
- addr = (void*) &tmp6;
+ addr = (const struct sockaddr*) &tmp6;
}
}
diff --git a/src/unix/thread.c b/src/unix/thread.c
index 4d6f4b8232ec6dc0bd27258a1315340e3e272ae9..531c6211bb4321e5f11031a0644b4e3ab9174396 100644
index f05e6fe0f7dd5ac579f6a9d6f93bffb99e1bcbc2..20409541de3cb300504b823472a73bc95fa38f62 100644
--- a/src/unix/thread.c
+++ b/src/unix/thread.c
@@ -168,8 +168,7 @@ int uv_thread_create_ex(uv_thread_t* tid,
@@ -1118,7 +1149,7 @@ index c2814512a5f507ceb9e764cdb7c6ff3d36e77974..cbee16b22a36b1c82e74f6a81c381105
if (req->bufs == NULL) {
uv__req_unregister(handle->loop, req);
diff --git a/src/uv-common.c b/src/uv-common.c
index 916f3f4e00664ab47f94d2a6ee7c6a9ef0461389..c04f93596ab1f730576256d86e216ccb7f258b72 100644
index 2200fe3f0a41e295acb426f39ccc9f0133994675..69e95801a18104ea910abf86db236d85f62afb66 100644
--- a/src/uv-common.c
+++ b/src/uv-common.c
@@ -54,10 +54,10 @@ static uv__allocator_t uv__allocator = {
@@ -1148,7 +1179,7 @@ index 916f3f4e00664ab47f94d2a6ee7c6a9ef0461389..c04f93596ab1f730576256d86e216ccb
}
void* uv__malloc(size_t size) {
@@ -688,7 +688,7 @@ void uv__fs_scandir_cleanup(uv_fs_t* req) {
@@ -691,7 +691,7 @@ void uv__fs_scandir_cleanup(uv_fs_t* req) {
unsigned int n;
if (req->result >= 0) {
@@ -1157,7 +1188,7 @@ index 916f3f4e00664ab47f94d2a6ee7c6a9ef0461389..c04f93596ab1f730576256d86e216ccb
nbufs = uv__get_nbufs(req);
i = 0;
@@ -721,7 +721,7 @@ int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent) {
@@ -724,7 +724,7 @@ int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent) {
nbufs = uv__get_nbufs(req);
assert(nbufs);
@@ -1166,7 +1197,7 @@ index 916f3f4e00664ab47f94d2a6ee7c6a9ef0461389..c04f93596ab1f730576256d86e216ccb
/* Free previous entity */
if (*nbufs > 0)
@@ -786,7 +786,7 @@ void uv__fs_readdir_cleanup(uv_fs_t* req) {
@@ -789,7 +789,7 @@ void uv__fs_readdir_cleanup(uv_fs_t* req) {
if (req->ptr == NULL)
return;
@@ -1175,7 +1206,7 @@ index 916f3f4e00664ab47f94d2a6ee7c6a9ef0461389..c04f93596ab1f730576256d86e216ccb
dirents = dir->dirents;
req->ptr = NULL;
@@ -832,7 +832,7 @@ uv_loop_t* uv_default_loop(void) {
@@ -835,7 +835,7 @@ uv_loop_t* uv_default_loop(void) {
uv_loop_t* uv_loop_new(void) {
uv_loop_t* loop;
@@ -1217,8 +1248,21 @@ index e9885a0f1ff3890a8d957c8793e22b01cedc0e97..87ade7ad65243ee3ff940320f84e1960
if (timer_heap == NULL) {
err = UV_ENOMEM;
goto fail_timers_alloc;
diff --git a/src/win/dl.c b/src/win/dl.c
index 7880c9595be1f66ea0dcbdbcc4a91ce40577587f..d88400f0e819d74998e13f60f13c67a606dec398 100644
--- a/src/win/dl.c
+++ b/src/win/dl.c
@@ -37,7 +37,7 @@ int uv_dlopen(const char* filename, uv_lib_t* lib) {
return uv__dlerror(lib, filename, ERROR_NO_UNICODE_TRANSLATION);
if ((size_t) r > ARRAY_SIZE(filename_w))
return uv__dlerror(lib, filename, ERROR_INSUFFICIENT_BUFFER);
- uv_wtf8_to_utf16(filename, filename_w, r);
+ uv_wtf8_to_utf16(filename, (uint16_t*)filename_w, r);
lib->handle = LoadLibraryExW(filename_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (lib->handle == NULL) {
diff --git a/src/win/fs-event.c b/src/win/fs-event.c
index 6758c7c78bc1d6a5316a8ae7dc2d1e23cd0f32bc..150467313d576bfe2966b55f3d8cffa23cbb8ea3 100644
index 4a0ca1f70a22b6342e208124838d6ecf3173f1a8..5a07acfe54efe90cf2ab0bca5b5998a961e72ebd 100644
--- a/src/win/fs-event.c
+++ b/src/win/fs-event.c
@@ -73,7 +73,7 @@ static void uv__relative_path(const WCHAR* filename,
@@ -1230,7 +1274,7 @@ index 6758c7c78bc1d6a5316a8ae7dc2d1e23cd0f32bc..150467313d576bfe2966b55f3d8cffa2
if (!*relpath)
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
wcsncpy(*relpath, filename + dirlen + 1, relpathlen);
@@ -242,7 +242,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
@@ -229,7 +229,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
if (short_path_buffer_len == 0) {
goto short_path_done;
}
@@ -1253,28 +1297,53 @@ index 0b532af12d4371c2311bd50a66913287a0716f43..703a8d8f87de1089ac8b18bd817d416d
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
diff --git a/src/win/fs.c b/src/win/fs.c
index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d0841e14b264 100644
index 99c8a2bf8bf1244f0db7114c1eaa8bff22564996..d9c2a4f728c7fb491995c6153b2a63a835b206b7 100644
--- a/src/win/fs.c
+++ b/src/win/fs.c
@@ -258,7 +258,7 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
@@ -280,7 +280,7 @@ INLINE static int fs__readlink_handle(HANDLE handle,
}
assert(target_ptr == NULL || *target_ptr == NULL);
- return uv_utf16_to_wtf8(w_target, w_target_len, target_ptr, target_len_ptr);
+ return uv_utf16_to_wtf8((const uint16_t*)w_target, w_target_len, target_ptr, target_len_ptr);
}
@@ -323,7 +323,7 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
return 0;
}
- buf = uv__malloc(buf_sz);
+ buf = (WCHAR *)uv__malloc(buf_sz);
+ buf = (WCHAR*)uv__malloc(buf_sz);
if (buf == NULL) {
return ERROR_OUTOFMEMORY;
}
@@ -376,7 +376,7 @@ static int fs__wide_to_wtf8(WCHAR* w_source_ptr,
return 0;
@@ -331,7 +331,7 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
pos = buf;
if (*target_ptr == NULL) {
- target = uv__malloc(target_len + 1);
+ target = (char *)uv__malloc(target_len + 1);
if (target == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return -1;
@@ -1575,7 +1575,7 @@ void fs__scandir(uv_fs_t* req) {
if (path != NULL) {
- uv_wtf8_to_utf16(path, pos, pathw_len);
+ uv_wtf8_to_utf16(path, (uint16_t*)pos, pathw_len);
req->file.pathw = pos;
pos += pathw_len;
} else {
@@ -339,7 +339,7 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
}
if (new_path != NULL) {
- uv_wtf8_to_utf16(new_path, pos, new_pathw_len);
+ uv_wtf8_to_utf16(new_path, (uint16_t*)pos, new_pathw_len);
req->fs.info.new_pathw = pos;
pos += new_pathw_len;
} else {
@@ -1390,13 +1390,13 @@ void fs__scandir(uv_fs_t* req) {
continue;
/* Compute the space required to store the filename as WTF-8. */
- wtf8_len = uv_utf16_length_as_wtf8(&info->FileName[0], wchar_len);
+ wtf8_len = uv_utf16_length_as_wtf8((const uint16_t*)&info->FileName[0], wchar_len);
/* Resize the dirent array if needed. */
if (dirents_used >= dirents_size) {
size_t new_dirents_size =
dirents_size == 0 ? dirents_initial_size : dirents_size << 1;
@@ -1283,7 +1352,7 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
uv__realloc(dirents, new_dirents_size * sizeof *dirents);
if (new_dirents == NULL)
@@ -1589,7 +1589,7 @@ void fs__scandir(uv_fs_t* req) {
@@ -1410,7 +1410,7 @@ void fs__scandir(uv_fs_t* req) {
* includes room for the first character of the filename, but `utf8_len`
* doesn't count the NULL terminator at this point.
*/
@@ -1292,7 +1361,16 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
if (dirent == NULL)
goto out_of_memory_error;
@@ -1691,7 +1691,7 @@ void fs__opendir(uv_fs_t* req) {
@@ -1418,7 +1418,7 @@ void fs__scandir(uv_fs_t* req) {
/* Convert file name to UTF-8. */
wtf8 = &dirent->d_name[0];
- if (uv_utf16_to_wtf8(&info->FileName[0], wchar_len, &wtf8, &wtf8_len) != 0)
+ if (uv_utf16_to_wtf8((const uint16_t*)&info->FileName[0], wchar_len, &wtf8, &wtf8_len) != 0)
goto out_of_memory_error;
/* Fill out the type field. */
@@ -1512,7 +1512,7 @@ void fs__opendir(uv_fs_t* req) {
goto error;
}
@@ -1301,7 +1379,7 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
if (dir == NULL) {
SET_REQ_UV_ERROR(req, UV_ENOMEM, ERROR_OUTOFMEMORY);
goto error;
@@ -1706,7 +1706,7 @@ void fs__opendir(uv_fs_t* req) {
@@ -1527,7 +1527,7 @@ void fs__opendir(uv_fs_t* req) {
else
fmt = L"%s\\*";
@@ -1310,7 +1388,7 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
if (find_path == NULL) {
SET_REQ_UV_ERROR(req, UV_ENOMEM, ERROR_OUTOFMEMORY);
goto error;
@@ -1743,7 +1743,7 @@ void fs__readdir(uv_fs_t* req) {
@@ -1564,7 +1564,7 @@ void fs__readdir(uv_fs_t* req) {
int r;
req->flags |= UV_FS_FREE_PTR;
@@ -1319,7 +1397,7 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
dirents = dir->dirents;
memset(dirents, 0, dir->nentries * sizeof(*dir->dirents));
find_data = &dir->find_data;
@@ -1800,7 +1800,7 @@ error:
@@ -1621,7 +1621,7 @@ error:
void fs__closedir(uv_fs_t* req) {
uv_dir_t* dir;
@@ -1328,7 +1406,7 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
FindClose(dir->dir_handle);
uv__free(req->ptr);
SET_REQ_RESULT(req, 0);
@@ -2791,7 +2791,7 @@ static ssize_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) {
@@ -2612,7 +2612,7 @@ static ssize_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) {
return -1;
}
@@ -1337,7 +1415,16 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
if (w_realpath_buf == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return -1;
@@ -2904,7 +2904,7 @@ retry_get_disk_free_space:
@@ -2645,7 +2645,7 @@ static ssize_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) {
}
assert(*realpath_ptr == NULL);
- r = uv_utf16_to_wtf8(w_realpath_ptr, w_realpath_len, realpath_ptr, NULL);
+ r = uv_utf16_to_wtf8((const uint16_t*)w_realpath_ptr, w_realpath_len, realpath_ptr, NULL);
uv__free(w_realpath_buf);
return r;
}
@@ -2725,7 +2725,7 @@ retry_get_disk_free_space:
}
len = MAX_PATH + 1;
@@ -1346,7 +1433,7 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
if (pathw == NULL) {
SET_REQ_UV_ERROR(req, UV_ENOMEM, ERROR_OUTOFMEMORY);
return;
@@ -2920,7 +2920,7 @@ retry_get_full_path_name:
@@ -2741,7 +2741,7 @@ retry_get_full_path_name:
return;
} else if (ret > len) {
len = ret;
@@ -1355,7 +1442,7 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
if (pathw == NULL) {
SET_REQ_UV_ERROR(req, UV_ENOMEM, ERROR_OUTOFMEMORY);
return;
@@ -2936,7 +2936,7 @@ retry_get_full_path_name:
@@ -2757,7 +2757,7 @@ retry_get_full_path_name:
uv__free(pathw);
}
@@ -1364,7 +1451,7 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
if (stat_fs == NULL) {
SET_REQ_UV_ERROR(req, UV_ENOMEM, ERROR_OUTOFMEMORY);
return;
@@ -3095,7 +3095,7 @@ int uv_fs_read(uv_loop_t* loop,
@@ -2916,7 +2916,7 @@ int uv_fs_read(uv_loop_t* loop,
req->fs.info.nbufs = nbufs;
req->fs.info.bufs = req->fs.info.bufsml;
if (nbufs > ARRAY_SIZE(req->fs.info.bufsml))
@@ -1373,7 +1460,7 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
if (req->fs.info.bufs == NULL) {
SET_REQ_UV_ERROR(req, UV_ENOMEM, ERROR_OUTOFMEMORY);
@@ -3128,7 +3128,7 @@ int uv_fs_write(uv_loop_t* loop,
@@ -2949,7 +2949,7 @@ int uv_fs_write(uv_loop_t* loop,
req->fs.info.nbufs = nbufs;
req->fs.info.bufs = req->fs.info.bufsml;
if (nbufs > ARRAY_SIZE(req->fs.info.bufsml))
@@ -1382,38 +1469,64 @@ index fc209c54f470edaa031009979061cff071cbf66d..328c8f2e0513562b53c948ffea59d084
if (req->fs.info.bufs == NULL) {
SET_REQ_UV_ERROR(req, UV_ENOMEM, ERROR_OUTOFMEMORY);
diff --git a/src/win/getaddrinfo.c b/src/win/getaddrinfo.c
index 8b8406ada8e7434e291b2e50caf4ed7f36613fa0..5bc63d8e19411b967a2acf5c24b34b9b17323ccc 100644
--- a/src/win/getaddrinfo.c
+++ b/src/win/getaddrinfo.c
@@ -132,7 +132,7 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
addrinfo_len += addrinfo_struct_len +
ALIGNED_SIZE(addrinfow_ptr->ai_addrlen);
if (addrinfow_ptr->ai_canonname != NULL) {
- name_len = uv_utf16_length_as_wtf8(addrinfow_ptr->ai_canonname, -1);
+ name_len = uv_utf16_length_as_wtf8((const uint16_t*)addrinfow_ptr->ai_canonname, -1);
if (name_len < 0) {
req->retcode = name_len;
goto complete;
@@ -281,9 +281,9 @@ int uv_getaddrinfo(uv_loop_t* loop,
}
/* allocate memory for inputs, and partition it as needed */
- alloc_ptr = uv__malloc(ALIGNED_SIZE(nodesize * sizeof(WCHAR)) +
- ALIGNED_SIZE(servicesize * sizeof(WCHAR)) +
- hintssize);
+ alloc_ptr = (char*)uv__malloc(ALIGNED_SIZE(nodesize * sizeof(WCHAR)) +
+ ALIGNED_SIZE(servicesize * sizeof(WCHAR)) +
+ hintssize);
if (!alloc_ptr)
return UV_ENOMEM;
@@ -294,7 +294,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
* request. The node here has been converted to ascii. */
if (node != NULL) {
req->node = (WCHAR*) alloc_ptr;
- uv_wtf8_to_utf16(node, (WCHAR*) alloc_ptr, nodesize);
+ uv_wtf8_to_utf16(node, (uint16_t*) alloc_ptr, nodesize);
alloc_ptr += ALIGNED_SIZE(nodesize * sizeof(WCHAR));
} else {
req->node = NULL;
@@ -304,7 +304,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
* the req. */
if (service != NULL) {
req->service = (WCHAR*) alloc_ptr;
- uv_wtf8_to_utf16(service, (WCHAR*) alloc_ptr, servicesize);
+ uv_wtf8_to_utf16(service, (uint16_t*) alloc_ptr, servicesize);
alloc_ptr += ALIGNED_SIZE(servicesize * sizeof(WCHAR));
} else {
req->service = NULL;
diff --git a/src/win/pipe.c b/src/win/pipe.c
index f0cac3822564e14052feb5e1934f54c57c78160d..c1739efe82b8755999145860b4da6b50c73518a2 100644
index cec72ff750b5a17e139fd85080ccbdfc3c71d8c0..0f045a873073cf9b07feb457ea199990df521e5f 100644
--- a/src/win/pipe.c
+++ b/src/win/pipe.c
@@ -756,7 +756,7 @@ int uv_pipe_bind2(uv_pipe_t* handle,
/* Convert name to UTF16. */
nameSize = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0) * sizeof(WCHAR);
- handle->name = uv__malloc(nameSize);
+ handle->name = (WCHAR*)uv__malloc(nameSize);
if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
@@ -906,7 +906,7 @@ int uv_pipe_connect2(uv_connect_t* req,
/* Convert name to UTF16. */
nameSize = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0) * sizeof(WCHAR);
- handle->name = uv__malloc(nameSize);
+ handle->name = (WCHAR*)uv__malloc(nameSize);
if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
@@ -924,7 +924,7 @@ int uv_pipe_connect2(uv_connect_t* req,
pipeHandle = open_named_pipe(handle->name, &duplex_flags);
@@ -899,7 +899,7 @@ int uv_pipe_connect2(uv_connect_t* req,
if (pipeHandle == INVALID_HANDLE_VALUE) {
if (GetLastError() == ERROR_PIPE_BUSY) {
nameSize = (wcslen(handle->name) + 1) * sizeof(WCHAR);
- req->u.connect.name = uv__malloc(nameSize);
+ req->u.connect.name = (WCHAR *)uv__malloc(nameSize);
if (!req->u.connect.name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
@@ -1528,7 +1528,7 @@ static int uv__build_coalesced_write_req(uv_write_t* user_req,
@@ -1503,7 +1503,7 @@ static int uv__build_coalesced_write_req(uv_write_t* user_req,
data_length; /* (c) */
/* Allocate buffer. */
@@ -1422,7 +1535,7 @@ index f0cac3822564e14052feb5e1934f54c57c78160d..c1739efe82b8755999145860b4da6b50
if (heap_buffer == NULL)
return ERROR_NOT_ENOUGH_MEMORY; /* Maps to UV_ENOMEM. */
@@ -1777,7 +1777,7 @@ int uv__pipe_write_ipc(uv_loop_t* loop,
@@ -1752,7 +1752,7 @@ int uv__pipe_write_ipc(uv_loop_t* loop,
bufs = stack_bufs;
} else {
/* Use heap-allocated buffer array. */
@@ -1431,7 +1544,7 @@ index f0cac3822564e14052feb5e1934f54c57c78160d..c1739efe82b8755999145860b4da6b50
if (bufs == NULL)
return ERROR_NOT_ENOUGH_MEMORY; /* Maps to UV_ENOMEM. */
}
@@ -2514,7 +2514,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
@@ -2449,7 +2449,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
FileNameInformation);
if (nt_status == STATUS_BUFFER_OVERFLOW) {
name_size = sizeof(*name_info) + tmp_name_info.FileNameLength;
@@ -1439,12 +1552,38 @@ index f0cac3822564e14052feb5e1934f54c57c78160d..c1739efe82b8755999145860b4da6b50
+ name_info = (FILE_NAME_INFORMATION*)uv__malloc(name_size);
if (!name_info) {
*size = 0;
err = UV_ENOMEM;
return UV_ENOMEM;
diff --git a/src/win/process.c b/src/win/process.c
index ed44adc67c6d52785a199206d9ba0357e2d0b045..b383e8b405db56d413985b38df216d09c58ec4a0 100644
index 119b46cb3f37122395c172c6e9700d472a2173ed..0103004c565bb09b7b9c150e874f9c68486ab26c 100644
--- a/src/win/process.c
+++ b/src/win/process.c
@@ -615,8 +615,8 @@ error:
@@ -543,14 +543,14 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
dst_len = dst_len * 2 + arg_count * 2;
/* Allocate buffer for the final command line. */
- dst = uv__malloc(dst_len * sizeof(WCHAR));
+ dst = (WCHAR*)uv__malloc(dst_len * sizeof(WCHAR));
if (dst == NULL) {
err = UV_ENOMEM;
goto error;
}
/* Allocate temporary working buffer. */
- temp_buffer = uv__malloc(temp_buffer_len * sizeof(WCHAR));
+ temp_buffer = (WCHAR*)uv__malloc(temp_buffer_len * sizeof(WCHAR));
if (temp_buffer == NULL) {
err = UV_ENOMEM;
goto error;
@@ -564,7 +564,7 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
arg_len = uv_wtf8_length_as_utf16(*arg);
assert(arg_len > 0);
assert(temp_buffer_len >= (size_t) arg_len);
- uv_wtf8_to_utf16(*arg, temp_buffer, arg_len);
+ uv_wtf8_to_utf16(*arg, (uint16_t*)temp_buffer, arg_len);
if (verbatim_arguments) {
/* Copy verbatim. */
@@ -592,8 +592,8 @@ error:
int env_strncmp(const wchar_t* a, int na, const wchar_t* b) {
@@ -1455,7 +1594,7 @@ index ed44adc67c6d52785a199206d9ba0357e2d0b045..b383e8b405db56d413985b38df216d09
wchar_t* A;
wchar_t* B;
int nb;
@@ -633,8 +633,8 @@ int env_strncmp(const wchar_t* a, int na, const wchar_t* b) {
@@ -610,8 +610,8 @@ int env_strncmp(const wchar_t* a, int na, const wchar_t* b) {
assert(b_eq);
nb = b_eq - b;
@@ -1466,16 +1605,30 @@ index ed44adc67c6d52785a199206d9ba0357e2d0b045..b383e8b405db56d413985b38df216d09
r = LCMapStringW(LOCALE_INVARIANT, LCMAP_UPPERCASE, a, na, A, na);
assert(r==na);
@@ -717,7 +717,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
@@ -684,11 +684,11 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
}
/* second pass: copy to UTF-16 environment block */
- dst_copy = uv__malloc(env_len * sizeof(WCHAR));
+ dst_copy = (WCHAR*)uv__malloc(env_len * sizeof(WCHAR));
if (dst_copy == NULL && env_len > 0) {
return ERROR_OUTOFMEMORY;
return UV_ENOMEM;
}
- env_copy = alloca(env_block_count * sizeof(WCHAR*));
+ env_copy = (WCHAR**)alloca(env_block_count * sizeof(WCHAR*));
ptr = dst_copy;
ptr_copy = env_copy;
@@ -771,7 +771,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
@@ -698,7 +698,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
len = uv_wtf8_length_as_utf16(*env);
assert(len > 0);
assert((size_t) len <= env_len - (ptr - dst_copy));
- uv_wtf8_to_utf16(*env, ptr, len);
+ uv_wtf8_to_utf16(*env, (uint16_t*)ptr, len);
*ptr_copy++ = ptr;
ptr += len;
}
@@ -736,7 +736,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
}
/* final pass: copy, in sort order, and inserting required variables */
@@ -1483,7 +1636,7 @@ index ed44adc67c6d52785a199206d9ba0357e2d0b045..b383e8b405db56d413985b38df216d09
+ dst = (WCHAR*)uv__malloc((1+env_len) * sizeof(WCHAR));
if (!dst) {
uv__free(dst_copy);
return ERROR_OUTOFMEMORY;
return UV_ENOMEM;
diff --git a/src/win/tcp.c b/src/win/tcp.c
index 187f36e2a61c870b0d16e17e9d4a9e1161ba8851..d8da4d941a51b0625fc0c072342ec4edf74c0ea3 100644
--- a/src/win/tcp.c
@@ -1519,11 +1672,51 @@ index 57c25e8f5a861c9d8a4c402c260d3ac235200423..57f1698f595e2410a51044f7f228b5a2
if (ctx == NULL)
return UV_ENOMEM;
diff --git a/src/win/tty.c b/src/win/tty.c
index ac836930d6f3a185d57ba59fb42c817496aa0fdf..3aacaaf0b514ba71755dc51f1bd7263de5cbc308 100644
--- a/src/win/tty.c
+++ b/src/win/tty.c
@@ -528,7 +528,7 @@ static DWORD CALLBACK uv_tty_line_read_thread(void* data) {
if (read_console_success) {
read_bytes = bytes;
- uv_utf16_to_wtf8(utf16,
+ uv_utf16_to_wtf8((const uint16_t*)utf16,
read_chars,
&handle->tty.rd.read_line_buffer.base,
&read_bytes);
@@ -827,7 +827,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
WCHAR utf16_buffer[2];
utf16_buffer[0] = handle->tty.rd.last_utf16_high_surrogate;
utf16_buffer[1] = KEV.uChar.UnicodeChar;
- if (uv_utf16_to_wtf8(utf16_buffer,
+ if (uv_utf16_to_wtf8((const uint16_t*)utf16_buffer,
2,
&last_key_buf,
&char_len))
@@ -835,7 +835,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
handle->tty.rd.last_utf16_high_surrogate = 0;
} else {
/* Single UTF-16 character */
- if (uv_utf16_to_wtf8(&KEV.uChar.UnicodeChar,
+ if (uv_utf16_to_wtf8((const uint16_t*)&KEV.uChar.UnicodeChar,
1,
&last_key_buf,
&char_len))
diff --git a/src/win/util.c b/src/win/util.c
index f6ec79cd57b5010ed5fd6829d952bcdacc8b7671..1cfd7b2caf0d4ad1a6a66df9406c21f4e2b69b04 100644
index 91d88a54fb24a613df45d7915c345b6764dd6ffd..5fbc70f52952f90b36fb22ee03ec7f70e6ed5954 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -160,7 +160,7 @@ static int uv__cwd(WCHAR** buf, DWORD *len) {
@@ -124,7 +124,7 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
/* Convert to UTF-8 */
utf8_len = *size_ptr - 1; /* Reserve space for NUL */
- err = uv_utf16_to_wtf8(utf16_buffer, utf16_len, &buffer, &utf8_len);
+ err = uv_utf16_to_wtf8((const uint16_t*)utf16_buffer, utf16_len, &buffer, &utf8_len);
if (err == UV_ENOBUFS) {
utf8_len = *size_ptr - 1;
err = 0;
@@ -152,7 +152,7 @@ static int uv__cwd(WCHAR** buf, DWORD *len) {
return uv_translate_sys_error(GetLastError());
/* |t| is the size of the buffer _including_ nul. */
@@ -1532,16 +1725,7 @@ index f6ec79cd57b5010ed5fd6829d952bcdacc8b7671..1cfd7b2caf0d4ad1a6a66df9406c21f4
if (p == NULL)
return UV_ENOMEM;
@@ -265,7 +265,7 @@ int uv_chdir(const char* dir) {
if (utf16_len == 0) {
return uv_translate_sys_error(GetLastError());
}
- utf16_buffer = uv__malloc(utf16_len * sizeof(WCHAR));
+ utf16_buffer = (WCHAR*)uv__malloc(utf16_len * sizeof(WCHAR));
if (utf16_buffer == NULL) {
return UV_ENOMEM;
}
@@ -623,14 +623,14 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
@@ -548,14 +548,14 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
GetSystemInfo(&system_info);
cpu_count = system_info.dwNumberOfProcessors;
@@ -1558,7 +1742,7 @@ index f6ec79cd57b5010ed5fd6829d952bcdacc8b7671..1cfd7b2caf0d4ad1a6a66df9406c21f4
if (sppi == NULL) {
err = ERROR_OUTOFMEMORY;
goto error;
@@ -774,7 +774,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
@@ -699,7 +699,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
case ERROR_BUFFER_OVERFLOW:
/* This happens when win_address_buf is NULL or too small to hold all
* adapters. */
@@ -1568,7 +1752,7 @@ index f6ec79cd57b5010ed5fd6829d952bcdacc8b7671..1cfd7b2caf0d4ad1a6a66df9406c21f4
if (win_address_buf == NULL)
return UV_ENOMEM;
@@ -782,7 +783,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
@@ -707,7 +708,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
case ERROR_NO_DATA: {
/* No adapters were found. */
@@ -1577,7 +1761,16 @@ index f6ec79cd57b5010ed5fd6829d952bcdacc8b7671..1cfd7b2caf0d4ad1a6a66df9406c21f4
if (uv_address_buf == NULL)
return UV_ENOMEM;
@@ -859,7 +860,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
@@ -758,7 +759,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
continue;
/* Compute the size of the interface name. */
- name_size = uv_utf16_length_as_wtf8(adapter->FriendlyName, -1);
+ name_size = uv_utf16_length_as_wtf8((const uint16_t*)adapter->FriendlyName, -1);
uv_address_buf_size += name_size + 1;
/* Count the number of addresses associated with this interface, and
@@ -773,7 +774,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
}
/* Allocate space to store interface data plus adapter names. */
@@ -1586,7 +1779,7 @@ index f6ec79cd57b5010ed5fd6829d952bcdacc8b7671..1cfd7b2caf0d4ad1a6a66df9406c21f4
if (uv_address_buf == NULL) {
uv__free(win_address_buf);
return UV_ENOMEM;
@@ -1074,7 +1075,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
@@ -982,7 +983,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
}
/* Include space for terminating null char. */
len += 1;
@@ -1595,25 +1788,46 @@ index f6ec79cd57b5010ed5fd6829d952bcdacc8b7671..1cfd7b2caf0d4ad1a6a66df9406c21f4
if (path == NULL) {
return UV_ENOMEM;
}
@@ -1153,7 +1154,7 @@ int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8) {
/* Allocate the destination buffer adding an extra byte for the terminating
* NULL. If utf16len is not -1 WideCharToMultiByte will not add it, so
* we do it ourselves always, just in case. */
- *utf8 = uv__malloc(bufsize + 1);
+ *utf8 = (char*)uv__malloc(bufsize + 1);
@@ -1019,7 +1020,7 @@ int uv__convert_utf16_to_utf8(const WCHAR* utf16, size_t utf16len, char** utf8)
return UV_EINVAL;
if (*utf8 == NULL)
return UV_ENOMEM;
@@ -1201,7 +1202,7 @@ int uv__convert_utf8_to_utf16(const char* utf8, int utf8len, WCHAR** utf16) {
/* Allocate the destination buffer adding an extra byte for the terminating
* NULL. If utf8len is not -1 MultiByteToWideChar will not add it, so
* we do it ourselves always, just in case. */
- *utf16 = uv__malloc(sizeof(WCHAR) * (bufsize + 1));
+ *utf16 = (WCHAR*)uv__malloc(sizeof(WCHAR) * (bufsize + 1));
*utf8 = NULL;
- return uv_utf16_to_wtf8(utf16, utf16len, utf8, &utf8_len);
+ return uv_utf16_to_wtf8((const uint16_t*)utf16, utf16len, utf8, &utf8_len);
}
@@ -1039,13 +1040,13 @@ int uv__convert_utf8_to_utf16(const char* utf8, WCHAR** utf16) {
return UV__EINVAL;
/* Allocate the destination buffer. */
- *utf16 = uv__malloc(sizeof(WCHAR) * bufsize);
+ *utf16 = (WCHAR*)uv__malloc(sizeof(WCHAR) * bufsize);
if (*utf16 == NULL)
return UV_ENOMEM;
@@ -1242,7 +1243,7 @@ static int uv__getpwuid_r(uv_passwd_t* pwd) {
/* Convert to UTF-16 */
- uv_wtf8_to_utf16(utf8, *utf16, bufsize);
+ uv_wtf8_to_utf16(utf8, (uint16_t*)*utf16, bufsize);
return 0;
}
@@ -1065,11 +1066,11 @@ int uv__copy_utf16_to_utf8(const WCHAR* utf16buffer, size_t utf16len, char* utf8
return UV_EINVAL;
if (*size == 0) {
- *size = uv_utf16_length_as_wtf8(utf16buffer, utf16len);
+ *size = uv_utf16_length_as_wtf8((const uint16_t*)utf16buffer, utf16len);
r = UV_ENOBUFS;
} else {
*size -= 1; /* Reserve space for NUL. */
- r = uv_utf16_to_wtf8(utf16buffer, utf16len, &utf8, size);
+ r = uv_utf16_to_wtf8((const uint16_t*)utf16buffer, utf16len, &utf8, size);
}
if (r == UV_ENOBUFS)
*size += 1; /* Add space for NUL. */
@@ -1099,7 +1100,7 @@ static int uv__getpwuid_r(uv_passwd_t* pwd) {
return uv_translate_sys_error(r);
}
@@ -1622,7 +1836,7 @@ index f6ec79cd57b5010ed5fd6829d952bcdacc8b7671..1cfd7b2caf0d4ad1a6a66df9406c21f4
if (path == NULL) {
CloseHandle(token);
return UV_ENOMEM;
@@ -1323,7 +1324,7 @@ int uv_os_environ(uv_env_item_t** envitems, int* count) {
@@ -1180,7 +1181,7 @@ int uv_os_environ(uv_env_item_t** envitems, int* count) {
for (penv = env, i = 0; *penv != L'\0'; penv += wcslen(penv) + 1, i++);
@@ -1631,7 +1845,7 @@ index f6ec79cd57b5010ed5fd6829d952bcdacc8b7671..1cfd7b2caf0d4ad1a6a66df9406c21f4
if (*envitems == NULL) {
FreeEnvironmentStringsW(env);
return UV_ENOMEM;
@@ -1413,7 +1414,7 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
@@ -1269,7 +1270,7 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
uv__free(var);
varlen = 1 + len;

View File

@@ -5,12 +5,11 @@ Subject: [PATCH 03/10] Fix warnings
---
include/uv/win.h | 5 +++++
src/idna.c | 2 +-
src/idna.c | 4 ++--
src/inet.c | 4 ++++
src/threadpool.c | 4 ++++
src/unix/core.c | 12 ++++++++++--
src/unix/internal.h | 4 ++--
src/unix/linux.c | 15 ++++++++++++---
src/unix/thread.c | 6 ------
src/uv-common.c | 8 ++++++++
src/win/fs-event.c | 2 ++
@@ -19,7 +18,7 @@ Subject: [PATCH 03/10] Fix warnings
src/win/process.c | 2 ++
src/win/thread.c | 4 ++--
src/win/tty.c | 2 ++
15 files changed, 58 insertions(+), 16 deletions(-)
14 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/include/uv/win.h b/include/uv/win.h
index eb74776978340a4910194bae35a9da6493e8c0a6..6d0afe69e7dd4caf4c9459e548fe75cf0c51b501 100644
@@ -43,10 +42,10 @@ index eb74776978340a4910194bae35a9da6493e8c0a6..6d0afe69e7dd4caf4c9459e548fe75cf
typedef PVOID CONDITION_VARIABLE, *PCONDITION_VARIABLE;
#endif
diff --git a/src/idna.c b/src/idna.c
index 93d982ca018f2d39d9c0ffab07998c2c637029eb..36a39a089019fb4c2a35ec84516658c392eec0a3 100644
index 0c952cf605a88136ed9035f9385f9b1080c30c28..fe60fb59bea59986a612cfa1747802b0636482d9 100644
--- a/src/idna.c
+++ b/src/idna.c
@@ -106,7 +106,7 @@ static int uv__idna_toascii_label(const char* s, const char* se,
@@ -153,7 +153,7 @@ static int uv__idna_toascii_label(const char* s, const char* se,
char** d, char* de) {
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz0123456789";
const char* ss;
@@ -55,6 +54,15 @@ index 93d982ca018f2d39d9c0ffab07998c2c637029eb..36a39a089019fb4c2a35ec84516658c3
unsigned h;
unsigned k;
unsigned n;
@@ -382,7 +382,7 @@ ssize_t uv_wtf8_length_as_utf16(const char* source_ptr) {
void uv_wtf8_to_utf16(const char* source_ptr,
uint16_t* w_target,
- size_t w_target_len) {
+ [[maybe_unused]] size_t w_target_len) {
int32_t code_point;
do {
diff --git a/src/inet.c b/src/inet.c
index dd94bea3886ca37945fcad7909d765e3700e3c21..71c9e5b774d64d505e6c6d6ed2637178b8532d4d 100644
--- a/src/inet.c
@@ -132,48 +140,8 @@ index fe5885136039d5332623467b86bf52cd4b32ca0f..98c437dcadec5b5106d697e82d5394d4
s = strrchr(path, '/');
if (s == NULL)
diff --git a/src/unix/linux.c b/src/unix/linux.c
index 9173850bd158eaf9c41deca38f9ba84762a027a1..157443792f1216c83b4221c3810d17c81c5913c4 100644
--- a/src/unix/linux.c
+++ b/src/unix/linux.c
@@ -1718,7 +1718,11 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
return UV__ERR(errno);
}
- fgets(buf, sizeof(buf), fp); /* Skip first line. */
+ /* Skip first line. */
+ if (!fgets(buf, sizeof(buf), fp)) {
+ uv__free(cpus);
+ return UV__ERR(errno);
+ }
for (;;) {
memset(&t, 0, sizeof(t));
@@ -1729,7 +1733,10 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
if (n != 7)
break;
- fgets(buf, sizeof(buf), fp); /* Skip rest of line. */
+ /* Skip rest of line. */
+ if (!fgets(buf, sizeof(buf), fp)) {
+ break;
+ }
if (cpu >= ARRAY_SIZE(*cpus))
continue;
@@ -1809,7 +1816,9 @@ nocpuinfo:
if (fp == NULL)
continue;
- fscanf(fp, "%llu", &(*cpus)[cpu].freq);
+ if (0 > fscanf(fp, "%llu", &(*cpus)[cpu].freq)) {
+ (*cpus)[cpu].freq = 0llu;
+ }
fclose(fp);
fp = NULL;
}
diff --git a/src/unix/thread.c b/src/unix/thread.c
index 531c6211bb4321e5f11031a0644b4e3ab9174396..f8600947e3e7df015c4302af4feee740707b2c46 100644
index 20409541de3cb300504b823472a73bc95fa38f62..688c042e1aedf379264900c29758c8b01a4a90ed 100644
--- a/src/unix/thread.c
+++ b/src/unix/thread.c
@@ -137,12 +137,6 @@ int uv_thread_create_ex(uv_thread_t* tid,
@@ -190,10 +158,10 @@ index 531c6211bb4321e5f11031a0644b4e3ab9174396..f8600947e3e7df015c4302af4feee740
params->flags & UV_THREAD_HAS_STACK_SIZE ? params->stack_size : 0;
diff --git a/src/uv-common.c b/src/uv-common.c
index c04f93596ab1f730576256d86e216ccb7f258b72..cd10b36b4a393e325ea03b93eb9897193ca9800b 100644
index 69e95801a18104ea910abf86db236d85f62afb66..49126e50f07bac16d198775454b731f40630d1d1 100644
--- a/src/uv-common.c
+++ b/src/uv-common.c
@@ -799,6 +799,10 @@ void uv__fs_readdir_cleanup(uv_fs_t* req) {
@@ -802,6 +802,10 @@ void uv__fs_readdir_cleanup(uv_fs_t* req) {
}
}
@@ -204,7 +172,7 @@ index c04f93596ab1f730576256d86e216ccb7f258b72..cd10b36b4a393e325ea03b93eb989719
int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...) {
va_list ap;
@@ -812,6 +816,10 @@ int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...) {
@@ -815,6 +819,10 @@ int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...) {
return err;
}
@@ -216,7 +184,7 @@ index c04f93596ab1f730576256d86e216ccb7f258b72..cd10b36b4a393e325ea03b93eb989719
static uv_loop_t default_loop_struct;
static uv_loop_t* default_loop_ptr;
diff --git a/src/win/fs-event.c b/src/win/fs-event.c
index 150467313d576bfe2966b55f3d8cffa23cbb8ea3..3244a4e4320d7ce98f226b49b2634c65de89c213 100644
index 5a07acfe54efe90cf2ab0bca5b5998a961e72ebd..381220bf241d9572ff64576cf25700d9746d2806 100644
--- a/src/win/fs-event.c
+++ b/src/win/fs-event.c
@@ -19,6 +19,8 @@
@@ -229,7 +197,7 @@ index 150467313d576bfe2966b55f3d8cffa23cbb8ea3..3244a4e4320d7ce98f226b49b2634c65
#include <errno.h>
#include <stdio.h>
diff --git a/src/win/fs.c b/src/win/fs.c
index 328c8f2e0513562b53c948ffea59d0841e14b264..565c05fff13c2e6e74091c1da7b31636d7fd370d 100644
index d9c2a4f728c7fb491995c6153b2a63a835b206b7..7df1df2b9ba23c0ecb96e82a6cfcaae824826b69 100644
--- a/src/win/fs.c
+++ b/src/win/fs.c
@@ -19,6 +19,8 @@
@@ -242,7 +210,7 @@ index 328c8f2e0513562b53c948ffea59d0841e14b264..565c05fff13c2e6e74091c1da7b31636
#include <stdlib.h>
#include <direct.h>
diff --git a/src/win/pipe.c b/src/win/pipe.c
index c1739efe82b8755999145860b4da6b50c73518a2..258d6a684c67f154096a25e7226f1a7d08b93d5b 100644
index 0f045a873073cf9b07feb457ea199990df521e5f..b2348bd0430aada98ff10313f6f926ea2f1c4491 100644
--- a/src/win/pipe.c
+++ b/src/win/pipe.c
@@ -19,6 +19,8 @@
@@ -255,7 +223,7 @@ index c1739efe82b8755999145860b4da6b50c73518a2..258d6a684c67f154096a25e7226f1a7d
#include <io.h>
#include <stdio.h>
diff --git a/src/win/process.c b/src/win/process.c
index b383e8b405db56d413985b38df216d09c58ec4a0..2b1b46259959867482079962d0ea44246a42e7cb 100644
index 0103004c565bb09b7b9c150e874f9c68486ab26c..eeb0f6a984bb0f61b956cb4b907fbfdb3b4ac7e2 100644
--- a/src/win/process.c
+++ b/src/win/process.c
@@ -19,6 +19,8 @@
@@ -283,7 +251,7 @@ index 57f1698f595e2410a51044f7f228b5a235206819..03b33e9b4de6fe2532095d717a8639e8
return UV_EINVAL;
}
diff --git a/src/win/tty.c b/src/win/tty.c
index 7e1f15544b177382a774300f832bc982d85bd62b..abbe1315883257d6825b794344dcd4cba9514097 100644
index 3aacaaf0b514ba71755dc51f1bd7263de5cbc308..c90995afb6166a7cab0a267f5eb513705ce05148 100644
--- a/src/win/tty.c
+++ b/src/win/tty.c
@@ -19,6 +19,8 @@

View File

@@ -14,7 +14,7 @@ Subject: [PATCH 04/10] Preprocessor cleanup
7 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/include/uv.h b/include/uv.h
index 02397dd0fdd43d51f86c0dde9a62046702f12bdb..d5342b0d52232bbf83825948cc6bc09e5d74a4c7 100644
index 5642101c10c351a602a195d3b74027b53bf641d2..aff06cb7f4352eb4fcf93c938f09a789318bddc3 100644
--- a/include/uv.h
+++ b/include/uv.h
@@ -23,9 +23,6 @@
@@ -44,7 +44,7 @@ index 02397dd0fdd43d51f86c0dde9a62046702f12bdb..d5342b0d52232bbf83825948cc6bc09e
UV_EXTERN uv_handle_type uv_guess_handle(uv_file file);
enum {
@@ -1906,7 +1897,4 @@ UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
@@ -1918,7 +1909,4 @@ void uv_wtf8_to_utf16(const char* wtf8,
#undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
#undef UV__ERR
@@ -85,19 +85,19 @@ index 98c437dcadec5b5106d697e82d5394d459f55e47..854d98a16a74c45e0b6cb92b17782de6
/* core */
diff --git a/src/win/fs.c b/src/win/fs.c
index 565c05fff13c2e6e74091c1da7b31636d7fd370d..f415ddc2c39d09eea317fc857777acce1ce7d13e 100644
index 7df1df2b9ba23c0ecb96e82a6cfcaae824826b69..26ba539936786902af5830c2811594292815d2d7 100644
--- a/src/win/fs.c
+++ b/src/win/fs.c
@@ -40,6 +40,7 @@
#include <winioctl.h>
@@ -43,6 +43,7 @@
#include "handle-inl.h"
#include "fs-fd-hash-inl.h"
+#pragma comment(lib, "Advapi32.lib")
#define UV_FS_FREE_PATHS 0x0002
#define UV_FS_FREE_PTR 0x0008
diff --git a/src/win/tty.c b/src/win/tty.c
index abbe1315883257d6825b794344dcd4cba9514097..9bb3d9e830c901122da5e521e0c6b032dfd5044c 100644
index c90995afb6166a7cab0a267f5eb513705ce05148..7adf3cd3ba81a9c41064f4ef2af01667092f27d1 100644
--- a/src/win/tty.c
+++ b/src/win/tty.c
@@ -37,6 +37,8 @@
@@ -110,7 +110,7 @@ index abbe1315883257d6825b794344dcd4cba9514097..9bb3d9e830c901122da5e521e0c6b032
# define InterlockedOr _InterlockedOr
#endif
diff --git a/src/win/util.c b/src/win/util.c
index 1cfd7b2caf0d4ad1a6a66df9406c21f4e2b69b04..af18cfa6c106c5de0996e4fff9b4127aaa3b576b 100644
index 5fbc70f52952f90b36fb22ee03ec7f70e6ed5954..f505cfad4987768fa6470ca27612312c2ba0729d 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -64,12 +64,20 @@

View File

@@ -36,10 +36,10 @@ index 268fc9652f437eb0d0cda2a9e0b06b9e91eb9742..f53adc156a7c454c492abaeac29d90be
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
diff --git a/src/uv-common.c b/src/uv-common.c
index cd10b36b4a393e325ea03b93eb9897193ca9800b..bfcc3ef10f4fd7763221638947da6e02e7a17c33 100644
index 49126e50f07bac16d198775454b731f40630d1d1..3d802cf1d629272f281d07b9ea424ec259b4377e 100644
--- a/src/uv-common.c
+++ b/src/uv-common.c
@@ -799,6 +799,7 @@ void uv__fs_readdir_cleanup(uv_fs_t* req) {
@@ -802,6 +802,7 @@ void uv__fs_readdir_cleanup(uv_fs_t* req) {
}
}
@@ -48,7 +48,7 @@ index cd10b36b4a393e325ea03b93eb9897193ca9800b..bfcc3ef10f4fd7763221638947da6e02
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wvarargs"
diff --git a/src/win/process.c b/src/win/process.c
index 2b1b46259959867482079962d0ea44246a42e7cb..18816d3b1e8c863f8ca74fe0104de1aecd0ae3fa 100644
index eeb0f6a984bb0f61b956cb4b907fbfdb3b4ac7e2..69f94b913f0a4051a36690725c7f79eb3535e594 100644
--- a/src/win/process.c
+++ b/src/win/process.c
@@ -35,7 +35,6 @@

View File

@@ -8,10 +8,10 @@ Subject: [PATCH 07/10] Fix Win32 warning suppression pragma
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/win/util.c b/src/win/util.c
index af18cfa6c106c5de0996e4fff9b4127aaa3b576b..9324992ec521cc3496e3e9304e600963a3f20897 100644
index f505cfad4987768fa6470ca27612312c2ba0729d..8828857db76a54d6e184c7f5714a091e92eba8ed 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -1692,7 +1692,7 @@ int uv_os_uname(uv_utsname_t* buffer) {
@@ -1502,7 +1502,7 @@ int uv_os_uname(uv_utsname_t* buffer) {
} else {
/* Silence GetVersionEx() deprecation warning. */
#ifdef _MSC_VER

View File

@@ -6,13 +6,13 @@ Subject: [PATCH 08/10] Use C++ atomics
---
src/unix/async.c | 25 +++++++++++++------------
src/unix/core.c | 3 ++-
src/unix/fs.c | 32 +++++++++++++++++---------------
src/unix/fs.c | 20 +++++++++++---------
src/unix/kqueue.c | 10 ++++++----
src/unix/linux.c | 45 +++++++++++++++++++++++----------------------
src/unix/tty.c | 5 +++--
src/uv-common.c | 2 +-
src/uv-common.h | 8 +++-----
8 files changed, 68 insertions(+), 62 deletions(-)
8 files changed, 62 insertions(+), 56 deletions(-)
diff --git a/src/unix/async.c b/src/unix/async.c
index 0ff2669e30a628dbb2df9e28ba14b38cf14114e5..fef4ae93343edc0341179a1c4739dcd831ef6e26 100644
@@ -112,19 +112,19 @@ index f53adc156a7c454c492abaeac29d90be436785fc..ce7fd2cdfdd53410dc694450bd56dffc
iovmax = atomic_load_explicit(&iovmax_cached, memory_order_relaxed);
diff --git a/src/unix/fs.c b/src/unix/fs.c
index e25d02e54dbe93e4b9c22b0140108c99ae2cb4f7..aba190a9c0240fba0128fb7fbc5d92d7fa86214b 100644
index bc00c90b07a32a823412b216df6f2d758dbc423b..afdf0c6e592c69961b1286a87b61e62601331763 100644
--- a/src/unix/fs.c
+++ b/src/unix/fs.c
@@ -46,6 +46,8 @@
@@ -45,6 +45,8 @@
#include <fcntl.h>
#include <poll.h>
+#include <atomic>
+
#if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
@@ -313,7 +315,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) {
#if defined(__linux__)
# include <sys/sendfile.h>
#endif
@@ -307,7 +309,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) {
static uv_once_t once = UV_ONCE_INIT;
int r;
#ifdef O_CLOEXEC
@@ -133,7 +133,7 @@ index e25d02e54dbe93e4b9c22b0140108c99ae2cb4f7..aba190a9c0240fba0128fb7fbc5d92d7
#endif
static const char pattern[] = "XXXXXX";
static const size_t pattern_size = sizeof(pattern) - 1;
@@ -338,7 +340,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) {
@@ -332,7 +334,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) {
uv_once(&once, uv__mkostemp_initonce);
#ifdef O_CLOEXEC
@@ -142,7 +142,7 @@ index e25d02e54dbe93e4b9c22b0140108c99ae2cb4f7..aba190a9c0240fba0128fb7fbc5d92d7
uv__mkostemp != NULL) {
r = uv__mkostemp(path, O_CLOEXEC);
@@ -352,7 +354,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) {
@@ -346,7 +348,7 @@ static int uv__fs_mkstemp(uv_fs_t* req) {
/* We set the static variable so that next calls don't even
try to use mkostemp. */
@@ -151,34 +151,7 @@ index e25d02e54dbe93e4b9c22b0140108c99ae2cb4f7..aba190a9c0240fba0128fb7fbc5d92d7
}
#endif /* O_CLOEXEC */
@@ -462,7 +464,7 @@ static ssize_t uv__fs_preadv(uv_file fd,
static ssize_t uv__fs_read(uv_fs_t* req) {
#if TRY_PREADV
- static _Atomic int no_preadv;
+ static std::atomic<int> no_preadv;
#endif
unsigned int iovmax;
ssize_t result;
@@ -486,7 +488,7 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
result = preadv(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
#else
# if TRY_PREADV
- if (atomic_load_explicit(&no_preadv, memory_order_relaxed)) retry:
+ if (atomic_load_explicit(&no_preadv, std::memory_order_relaxed)) retry:
# endif
{
result = uv__fs_preadv(req->file, req->bufs, req->nbufs, req->off);
@@ -498,7 +500,7 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
req->nbufs,
req->off);
if (result == -1 && errno == ENOSYS) {
- atomic_store_explicit(&no_preadv, 1, memory_order_relaxed);
+ atomic_store_explicit(&no_preadv, 1, std::memory_order_relaxed);
goto retry;
}
}
@@ -939,10 +941,10 @@ static int uv__is_cifs_or_smb(int fd) {
@@ -867,10 +869,10 @@ static int uv__is_cifs_or_smb(int fd) {
static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off,
int out_fd, size_t len) {
@@ -191,7 +164,7 @@ index e25d02e54dbe93e4b9c22b0140108c99ae2cb4f7..aba190a9c0240fba0128fb7fbc5d92d7
errno = ENOSYS;
return -1;
}
@@ -961,7 +963,7 @@ static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off,
@@ -889,7 +891,7 @@ static ssize_t uv__fs_try_copy_file_range(int in_fd, off_t* off,
errno = ENOSYS; /* Use fallback. */
break;
case ENOSYS:
@@ -200,34 +173,7 @@ index e25d02e54dbe93e4b9c22b0140108c99ae2cb4f7..aba190a9c0240fba0128fb7fbc5d92d7
break;
case EPERM:
/* It's been reported that CIFS spuriously fails.
@@ -1162,7 +1164,7 @@ static ssize_t uv__fs_lutime(uv_fs_t* req) {
static ssize_t uv__fs_write(uv_fs_t* req) {
#if TRY_PREADV
- static _Atomic int no_pwritev;
+ static std::atomic<int> no_pwritev;
#endif
ssize_t r;
@@ -1191,7 +1193,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
r = pwritev(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
#else
# if TRY_PREADV
- if (atomic_load_explicit(&no_pwritev, memory_order_relaxed)) retry:
+ if (atomic_load_explicit(&no_pwritev, std::memory_order_relaxed)) retry:
# endif
{
r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
@@ -1203,7 +1205,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
req->nbufs,
req->off);
if (r == -1 && errno == ENOSYS) {
- atomic_store_explicit(&no_pwritev, 1, memory_order_relaxed);
+ atomic_store_explicit(&no_pwritev, 1, std::memory_order_relaxed);
goto retry;
}
}
@@ -1483,14 +1485,14 @@ static int uv__fs_statx(int fd,
@@ -1380,14 +1382,14 @@ static int uv__fs_statx(int fd,
uv_stat_t* buf) {
STATIC_ASSERT(UV_ENOSYS != -1);
#ifdef __linux__
@@ -244,7 +190,7 @@ index e25d02e54dbe93e4b9c22b0140108c99ae2cb4f7..aba190a9c0240fba0128fb7fbc5d92d7
return UV_ENOSYS;
dirfd = AT_FDCWD;
@@ -1524,7 +1526,7 @@ static int uv__fs_statx(int fd,
@@ -1421,7 +1423,7 @@ static int uv__fs_statx(int fd,
* implemented, rc might return 1 with 0 set as the error code in which
* case we return ENOSYS.
*/
@@ -254,10 +200,10 @@ index e25d02e54dbe93e4b9c22b0140108c99ae2cb4f7..aba190a9c0240fba0128fb7fbc5d92d7
}
diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c
index 28e55aae6c613576ede7024a5c73d746e134d865..ffe0f9191cc7b0c233447db358077d8814e0217e 100644
index 06fbdb24b4adc4adb781d32150d40836fa745531..939a42696778741f9184be29dcea7c858736d181 100644
--- a/src/unix/kqueue.c
+++ b/src/unix/kqueue.c
@@ -34,6 +34,8 @@
@@ -37,6 +37,8 @@
#include <fcntl.h>
#include <time.h>
@@ -266,7 +212,7 @@ index 28e55aae6c613576ede7024a5c73d746e134d865..ffe0f9191cc7b0c233447db358077d88
/*
* Required on
* - Until at least FreeBSD 11.0
@@ -60,7 +62,7 @@ int uv__kqueue_init(uv_loop_t* loop) {
@@ -63,7 +65,7 @@ int uv__kqueue_init(uv_loop_t* loop) {
#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
@@ -275,7 +221,7 @@ index 28e55aae6c613576ede7024a5c73d746e134d865..ffe0f9191cc7b0c233447db358077d88
#endif
int uv__io_fork(uv_loop_t* loop) {
@@ -84,7 +86,7 @@ int uv__io_fork(uv_loop_t* loop) {
@@ -87,7 +89,7 @@ int uv__io_fork(uv_loop_t* loop) {
*/
atomic_store_explicit(&uv__has_forked_with_cfrunloop,
1,
@@ -284,7 +230,7 @@ index 28e55aae6c613576ede7024a5c73d746e134d865..ffe0f9191cc7b0c233447db358077d88
uv__free(loop->cf_state);
loop->cf_state = NULL;
}
@@ -541,7 +543,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
@@ -555,7 +557,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
goto fallback;
if (0 == atomic_load_explicit(&uv__has_forked_with_cfrunloop,
@@ -293,7 +239,7 @@ index 28e55aae6c613576ede7024a5c73d746e134d865..ffe0f9191cc7b0c233447db358077d88
int r;
/* The fallback fd is no longer needed */
uv__close_nocheckstdio(fd);
@@ -577,7 +579,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
@@ -591,7 +593,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
if (0 == atomic_load_explicit(&uv__has_forked_with_cfrunloop,
@@ -303,7 +249,7 @@ index 28e55aae6c613576ede7024a5c73d746e134d865..ffe0f9191cc7b0c233447db358077d88
r = uv__fsevents_close(handle);
#endif
diff --git a/src/unix/linux.c b/src/unix/linux.c
index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d693e0913c6 100644
index 2b8e1d8fe593a181d049aa50ff9edaf6da258a24..b23d88bd824843eebc3b439e5a18e6f796a747be 100644
--- a/src/unix/linux.c
+++ b/src/unix/linux.c
@@ -27,7 +27,6 @@
@@ -314,7 +260,7 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
#include <stddef.h> /* offsetof */
#include <stdint.h>
#include <stdio.h>
@@ -133,6 +132,8 @@
@@ -139,6 +138,8 @@
# include <netpacket/packet.h>
#endif /* HAVE_IFADDRS_H */
@@ -323,7 +269,7 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
enum {
UV__IORING_SETUP_SQPOLL = 2u,
};
@@ -311,14 +312,14 @@ static struct watcher_root* uv__inotify_watchers(uv_loop_t* loop) {
@@ -317,7 +318,7 @@ static struct watcher_root* uv__inotify_watchers(uv_loop_t* loop) {
unsigned uv__kernel_version(void) {
@@ -332,25 +278,26 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
struct utsname u;
unsigned version;
unsigned major;
unsigned minor;
unsigned patch;
@@ -326,7 +327,7 @@ unsigned uv__kernel_version(void) {
char v_sig[256];
char* needle;
- version = atomic_load_explicit(&cached_version, memory_order_relaxed);
+ version = std::atomic_load_explicit(&cached_version, std::memory_order_relaxed);
if (version != 0)
return version;
@@ -329,7 +330,7 @@ unsigned uv__kernel_version(void) {
return 0;
@@ -382,7 +383,7 @@ unsigned uv__kernel_version(void) {
calculate_version:
version = major * 65536 + minor * 256 + patch;
- atomic_store_explicit(&cached_version, version, memory_order_relaxed);
+ std::atomic_store_explicit(&cached_version, version, std::memory_order_relaxed);
return version;
}
@@ -424,16 +425,16 @@ static int uv__use_io_uring(void) {
return 0; /* Possibly available but blocked by seccomp. */
@@ -480,11 +481,11 @@ static int uv__use_io_uring(void) {
return 0; /* All 32 bits kernels appear buggy. */
#else
/* Ternary: unknown=0, yes=1, no=-1 */
- static _Atomic int use_io_uring;
@@ -362,14 +309,17 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
+ use = std::atomic_load_explicit(&use_io_uring, std::memory_order_relaxed);
if (use == 0) {
val = getenv("UV_USE_IO_URING");
use = val == NULL || atoi(val) ? 1 : -1;
/* Older kernels have a bug where the sqpoll thread uses 100% CPU. */
@@ -495,7 +496,7 @@ static int uv__use_io_uring(void) {
if (val != NULL)
use = atoi(val) ? 1 : -1;
- atomic_store_explicit(&use_io_uring, use, memory_order_relaxed);
+ std::atomic_store_explicit(&use_io_uring, use, std::memory_order_relaxed);
}
return use > 0;
@@ -709,8 +710,8 @@ static struct uv__io_uring_sqe* uv__iou_get_sqe(struct uv__iou* iou,
@@ -771,8 +772,8 @@ static struct uv__io_uring_sqe* uv__iou_get_sqe(struct uv__iou* iou,
if (iou->ringfd == -1)
return NULL;
@@ -380,7 +330,7 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
tail = *iou->sqtail;
mask = iou->sqmask;
@@ -739,12 +740,12 @@ static struct uv__io_uring_sqe* uv__iou_get_sqe(struct uv__iou* iou,
@@ -801,12 +802,12 @@ static struct uv__io_uring_sqe* uv__iou_get_sqe(struct uv__iou* iou,
static void uv__iou_submit(struct uv__iou* iou) {
uint32_t flags;
@@ -397,7 +347,7 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
if (flags & UV__IORING_SQ_NEED_WAKEUP)
if (uv__io_uring_enter(iou->ringfd, 0, 0, UV__IORING_ENTER_SQ_WAKEUP))
@@ -1076,8 +1077,8 @@ static void uv__poll_io_uring(uv_loop_t* loop, struct uv__iou* iou) {
@@ -1147,8 +1148,8 @@ static void uv__poll_io_uring(uv_loop_t* loop, struct uv__iou* iou) {
int rc;
head = *iou->cqhead;
@@ -408,7 +358,7 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
mask = iou->cqmask;
cqe = (uv__io_uring_cqe*)iou->cqe;
nevents = 0;
@@ -1109,15 +1110,15 @@ static void uv__poll_io_uring(uv_loop_t* loop, struct uv__iou* iou) {
@@ -1180,15 +1181,15 @@ static void uv__poll_io_uring(uv_loop_t* loop, struct uv__iou* iou) {
nevents++;
}
@@ -428,7 +378,7 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
if (flags & UV__IORING_SQ_CQ_OVERFLOW) {
do
@@ -1531,7 +1532,7 @@ update_timeout:
@@ -1581,7 +1582,7 @@ update_timeout:
}
uint64_t uv__hrtime(uv_clocktype_t type) {
@@ -437,7 +387,7 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
struct timespec t;
clock_t clock_id;
@@ -1547,7 +1548,7 @@ uint64_t uv__hrtime(uv_clocktype_t type) {
@@ -1597,7 +1598,7 @@ uint64_t uv__hrtime(uv_clocktype_t type) {
if (type != UV_CLOCK_FAST)
goto done;
@@ -446,7 +396,7 @@ index 157443792f1216c83b4221c3810d17c81c5913c4..e3dfb186dc531e5c8197a81681c00d69
if (clock_id != -1)
goto done;
@@ -1556,7 +1557,7 @@ uint64_t uv__hrtime(uv_clocktype_t type) {
@@ -1606,7 +1607,7 @@ uint64_t uv__hrtime(uv_clocktype_t type) {
if (t.tv_nsec <= 1 * 1000 * 1000)
clock_id = CLOCK_MONOTONIC_COARSE;
@@ -486,10 +436,10 @@ index 1bd217b5a15eed13a8349c479b53471dd36ca216..1304c6d8685cfd122cffea066dc668d1
int uv__tcsetattr(int fd, int how, const struct termios *term) {
int rc;
diff --git a/src/uv-common.c b/src/uv-common.c
index bfcc3ef10f4fd7763221638947da6e02e7a17c33..5c6d84155408ae4f7c3c6ff9b48bd09ccd16a92e 100644
index 3d802cf1d629272f281d07b9ea424ec259b4377e..569c6906b7e54c4af1c17564a18066b847ab7ca1 100644
--- a/src/uv-common.c
+++ b/src/uv-common.c
@@ -951,7 +951,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
@@ -954,7 +954,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
__attribute__((destructor))
#endif
void uv_library_shutdown(void) {

View File

@@ -8,10 +8,10 @@ Subject: [PATCH 09/10] Remove static from array indices
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/unix/linux.c b/src/unix/linux.c
index e3dfb186dc531e5c8197a81681c00d693e0913c6..d365b623a0a25228f0c6acf1fa14a5c7a9f1efbf 100644
index b23d88bd824843eebc3b439e5a18e6f796a747be..95a2fe2b42895626f207f740bdccfe938915d836 100644
--- a/src/unix/linux.c
+++ b/src/unix/linux.c
@@ -2060,7 +2060,7 @@ static uint64_t uv__read_uint64(const char* filename) {
@@ -2104,7 +2104,7 @@ static uint64_t uv__read_uint64(const char* filename) {
* finds the location and length of the memory controller mount path.
* This disregards the leading / for easy concatenation of paths.
* Returns NULL if the memory controller wasn't found. */
@@ -20,7 +20,7 @@ index e3dfb186dc531e5c8197a81681c00d693e0913c6..d365b623a0a25228f0c6acf1fa14a5c7
int* n) {
char* p;
@@ -2081,7 +2081,7 @@ static char* uv__cgroup1_find_memory_controller(char buf[static 1024],
@@ -2125,7 +2125,7 @@ static char* uv__cgroup1_find_memory_controller(char buf[static 1024],
return p;
}
@@ -29,7 +29,7 @@ index e3dfb186dc531e5c8197a81681c00d693e0913c6..d365b623a0a25228f0c6acf1fa14a5c7
uint64_t* max) {
char filename[4097];
char* p;
@@ -2121,7 +2121,7 @@ update_limits:
@@ -2165,7 +2165,7 @@ update_limits:
*max = UINT64_MAX;
}
@@ -38,7 +38,7 @@ index e3dfb186dc531e5c8197a81681c00d693e0913c6..d365b623a0a25228f0c6acf1fa14a5c7
uint64_t* max) {
char filename[4097];
char* p;
@@ -2138,7 +2138,7 @@ static void uv__get_cgroup2_memory_limits(char buf[static 1024], uint64_t* high,
@@ -2182,7 +2182,7 @@ static void uv__get_cgroup2_memory_limits(char buf[static 1024], uint64_t* high,
*high = uv__read_uint64(filename);
}
@@ -47,7 +47,7 @@ index e3dfb186dc531e5c8197a81681c00d693e0913c6..d365b623a0a25228f0c6acf1fa14a5c7
uint64_t high;
uint64_t max;
@@ -2164,7 +2164,7 @@ uint64_t uv_get_constrained_memory(void) {
@@ -2208,7 +2208,7 @@ uint64_t uv_get_constrained_memory(void) {
}
@@ -56,7 +56,7 @@ index e3dfb186dc531e5c8197a81681c00d693e0913c6..d365b623a0a25228f0c6acf1fa14a5c7
char filename[4097];
uint64_t current;
char* p;
@@ -2188,7 +2188,7 @@ static uint64_t uv__get_cgroup1_current_memory(char buf[static 1024]) {
@@ -2232,7 +2232,7 @@ static uint64_t uv__get_cgroup1_current_memory(char buf[static 1024]) {
return uv__read_uint64("/sys/fs/cgroup/memory/memory.usage_in_bytes");
}

View File

@@ -27,7 +27,7 @@ index 6d0afe69e7dd4caf4c9459e548fe75cf0c51b501..613065df435d813cd517efbc138b13ee
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
diff --git a/src/win/util.c b/src/win/util.c
index 9324992ec521cc3496e3e9304e600963a3f20897..4b76417fcbac2480725471740c037deb859e17ca 100644
index 8828857db76a54d6e184c7f5714a091e92eba8ed..14295c41342b6dda16f39c5c548a6cc8269bfa0b 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -73,7 +73,9 @@ static char *process_title;

View File

@@ -13,7 +13,7 @@ from upstream_utils import (
def main():
upstream_root = clone_repo("https://github.com/libuv/libuv", "v1.46.0")
upstream_root = clone_repo("https://github.com/libuv/libuv", "v1.47.0")
wpilib_root = get_repo_root()
wpinet = os.path.join(wpilib_root, "wpinet")

View File

@@ -1876,6 +1876,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);
/* String utilities needed internally for dealing with Windows. */
size_t uv_utf16_length_as_wtf8(const uint16_t* utf16,
ssize_t utf16_len);
int uv_utf16_to_wtf8(const uint16_t* utf16,
ssize_t utf16_len,
char** wtf8_ptr,
size_t* wtf8_len_ptr);
ssize_t uv_wtf8_length_as_utf16(const char* wtf8);
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

@@ -31,7 +31,7 @@
*/
#define UV_VERSION_MAJOR 1
#define UV_VERSION_MINOR 46
#define UV_VERSION_MINOR 47
#define UV_VERSION_PATCH 0
#define UV_VERSION_IS_RELEASE 1
#define UV_VERSION_SUFFIX ""

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,11 +18,56 @@
*/
#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,
unsigned a) {
@@ -89,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;
@@ -102,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";
@@ -267,7 +314,8 @@ 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;
@@ -313,3 +361,195 @@ long uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
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,
[[maybe_unused]] 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 > 0x10000) {
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++);
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 = (char*)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

@@ -209,7 +209,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
if (cpuspeed == 0)
/* If sysctl hw.cputype == CPU_TYPE_ARM64, the correct value is unavailable
* from Apple, but we can hard-code it here to a plausible value. */
cpuspeed = 2400000000;
cpuspeed = 2400000000U;
if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
(processor_info_array_t*)&info,
@@ -235,7 +235,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cpu_info->cpu_times.irq = 0;
cpu_info->model = uv__strdup(model);
cpu_info->speed = cpuspeed/1000000;
cpu_info->speed = (int)(cpuspeed / 1000000);
}
vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);

View File

@@ -41,27 +41,12 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include <atomic>
#if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__OpenBSD__) || \
defined(__NetBSD__)
# define HAVE_PREADV 1
#else
# define HAVE_PREADV 0
#endif
/* preadv() and pwritev() were added in Android N (level 24) */
#if defined(__linux__) && !(defined(__ANDROID__) && __ANDROID_API__ < 24)
# define TRY_PREADV 1
#endif
#if defined(__linux__)
# include <sys/sendfile.h>
#endif
@@ -99,6 +84,15 @@
# include <sys/statfs.h>
#endif
#if defined(__CYGWIN__) || \
(defined(__HAIKU__) && B_HAIKU_VERSION < B_HAIKU_VERSION_1_PRE_BETA_5) || \
(defined(__sun) && !defined(__illumos__))
#define preadv(fd, bufs, nbufs, off) \
pread(fd, (bufs)->iov_base, (bufs)->iov_len, off)
#define pwritev(fd, bufs, nbufs, off) \
pwrite(fd, (bufs)->iov_base, (bufs)->iov_len, off)
#endif
#if defined(_AIX) && _XOPEN_SOURCE <= 600
extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */
#endif
@@ -412,123 +406,57 @@ static ssize_t uv__fs_open(uv_fs_t* req) {
}
#if !HAVE_PREADV
static ssize_t uv__fs_preadv(uv_file fd,
uv_buf_t* bufs,
unsigned int nbufs,
off_t off) {
uv_buf_t* buf;
uv_buf_t* end;
ssize_t result;
ssize_t rc;
size_t pos;
assert(nbufs > 0);
result = 0;
pos = 0;
buf = bufs + 0;
end = bufs + nbufs;
for (;;) {
do
rc = pread(fd, buf->base + pos, buf->len - pos, off + result);
while (rc == -1 && errno == EINTR);
if (rc == 0)
break;
if (rc == -1 && result == 0)
return UV__ERR(errno);
if (rc == -1)
break; /* We read some data so return that, ignore the error. */
pos += rc;
result += rc;
if (pos < buf->len)
continue;
pos = 0;
buf += 1;
if (buf == end)
break;
}
return result;
}
#endif
static ssize_t uv__fs_read(uv_fs_t* req) {
#if TRY_PREADV
static std::atomic<int> no_preadv;
#endif
const struct iovec* bufs;
unsigned int iovmax;
ssize_t result;
size_t nbufs;
ssize_t r;
off_t off;
int fd;
fd = req->file;
off = req->off;
bufs = (const struct iovec*) req->bufs;
nbufs = req->nbufs;
iovmax = uv__getiovmax();
if (req->nbufs > iovmax)
req->nbufs = iovmax;
if (nbufs > iovmax)
nbufs = iovmax;
if (req->off < 0) {
if (req->nbufs == 1)
result = read(req->file, req->bufs[0].base, req->bufs[0].len);
else
result = readv(req->file, (struct iovec*) req->bufs, req->nbufs);
r = 0;
if (off < 0) {
if (nbufs == 1)
r = read(fd, bufs->iov_base, bufs->iov_len);
else if (nbufs > 1)
r = readv(fd, bufs, nbufs);
} else {
if (req->nbufs == 1) {
result = pread(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
goto done;
}
#if HAVE_PREADV
result = preadv(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
#else
# if TRY_PREADV
if (atomic_load_explicit(&no_preadv, std::memory_order_relaxed)) retry:
# endif
{
result = uv__fs_preadv(req->file, req->bufs, req->nbufs, req->off);
}
# if TRY_PREADV
else {
result = preadv(req->file,
(struct iovec*) req->bufs,
req->nbufs,
req->off);
if (result == -1 && errno == ENOSYS) {
atomic_store_explicit(&no_preadv, 1, std::memory_order_relaxed);
goto retry;
}
}
# endif
#endif
if (nbufs == 1)
r = pread(fd, bufs->iov_base, bufs->iov_len, off);
else if (nbufs > 1)
r = preadv(fd, bufs, nbufs, off);
}
done:
/* Early cleanup of bufs allocation, since we're done with it. */
if (req->bufs != req->bufsml)
uv__free(req->bufs);
req->bufs = NULL;
req->nbufs = 0;
#ifdef __PASE__
/* PASE returns EOPNOTSUPP when reading a directory, convert to EISDIR */
if (result == -1 && errno == EOPNOTSUPP) {
if (r == -1 && errno == EOPNOTSUPP) {
struct stat buf;
ssize_t rc;
rc = uv__fstat(req->file, &buf);
rc = uv__fstat(fd, &buf);
if (rc == 0 && S_ISDIR(buf.st_mode)) {
errno = EISDIR;
}
}
#endif
return result;
/* We don't own the buffer list in the synchronous case. */
if (req->cb != NULL)
if (req->bufs != req->bufsml)
uv__free(req->bufs);
req->bufs = NULL;
req->nbufs = 0;
return r;
}
@@ -1163,65 +1091,34 @@ static ssize_t uv__fs_lutime(uv_fs_t* req) {
static ssize_t uv__fs_write(uv_fs_t* req) {
#if TRY_PREADV
static std::atomic<int> no_pwritev;
#endif
const struct iovec* bufs;
size_t nbufs;
ssize_t r;
off_t off;
int fd;
/* Serialize writes on OS X, concurrent write() and pwrite() calls result in
* data loss. We can't use a per-file descriptor lock, the descriptor may be
* a dup().
*/
#if defined(__APPLE__)
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
fd = req->file;
off = req->off;
bufs = (const struct iovec*) req->bufs;
nbufs = req->nbufs;
if (pthread_mutex_lock(&lock))
abort();
#endif
if (req->off < 0) {
if (req->nbufs == 1)
r = write(req->file, req->bufs[0].base, req->bufs[0].len);
else
r = writev(req->file, (struct iovec*) req->bufs, req->nbufs);
r = 0;
if (off < 0) {
if (nbufs == 1)
r = write(fd, bufs->iov_base, bufs->iov_len);
else if (nbufs > 1)
r = writev(fd, bufs, nbufs);
} else {
if (req->nbufs == 1) {
r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
goto done;
}
#if HAVE_PREADV
r = pwritev(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
#else
# if TRY_PREADV
if (atomic_load_explicit(&no_pwritev, std::memory_order_relaxed)) retry:
# endif
{
r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
}
# if TRY_PREADV
else {
r = pwritev(req->file,
(struct iovec*) req->bufs,
req->nbufs,
req->off);
if (r == -1 && errno == ENOSYS) {
atomic_store_explicit(&no_pwritev, 1, std::memory_order_relaxed);
goto retry;
}
}
# endif
#endif
if (nbufs == 1)
r = pwrite(fd, bufs->iov_base, bufs->iov_len, off);
else if (nbufs > 1)
r = pwritev(fd, bufs, nbufs, off);
}
done:
#if defined(__APPLE__)
if (pthread_mutex_unlock(&lock))
abort();
#endif
return r;
}
static ssize_t uv__fs_copyfile(uv_fs_t* req) {
uv_fs_t fs_req;
uv_file srcfd;
@@ -1981,9 +1878,14 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
if (bufs == NULL || nbufs == 0)
return UV_EINVAL;
req->off = off;
req->file = file;
req->bufs = (uv_buf_t*) bufs; /* Safe, doesn't mutate |bufs| */
req->nbufs = nbufs;
if (cb == NULL)
goto post;
req->bufs = req->bufsml;
if (nbufs > ARRAY_SIZE(req->bufsml))
req->bufs = (uv_buf_t*)uv__malloc(nbufs * sizeof(*bufs));
@@ -1993,12 +1895,10 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
req->off = off;
if (cb != NULL)
if (uv__iou_fs_read_or_write(loop, req, /* is_read */ 1))
return 0;
if (uv__iou_fs_read_or_write(loop, req, /* is_read */ 1))
return 0;
post:
POST;
}

View File

@@ -30,6 +30,9 @@
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#if defined(__FreeBSD__)
#include <sys/user.h>
#endif
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
@@ -264,6 +267,9 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (nfds == -1)
assert(errno == EINTR);
else if (nfds == 0)
/* Unlimited timeout should only return with events or signal. */
assert(timeout != -1);
if (pset != NULL)
pthread_sigmask(SIG_UNBLOCK, pset, NULL);
@@ -288,8 +294,6 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
timeout = user_timeout;
reset_timeout = 0;
} else if (nfds == 0) {
/* Reached the user timeout value. */
assert(timeout != -1);
return;
}
@@ -481,6 +485,16 @@ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags) {
*/
if (fcntl(handle->event_watcher.fd, F_GETPATH, pathbuf) == 0)
path = uv__basename_r(pathbuf);
#elif defined(F_KINFO)
/* We try to get the file info reference from the file descriptor.
* the struct's kf_structsize must be initialised beforehand
* whether with the KINFO_FILE_SIZE constant or this way.
*/
struct kinfo_file kf;
kf.kf_structsize = sizeof(kf);
if (fcntl(handle->event_watcher.fd, F_KINFO, &kf) == 0)
path = uv__basename_r(kf.kf_path);
#endif
handle->cb(handle, path, events, 0);

View File

@@ -78,6 +78,8 @@
# define __NR_copy_file_range 379
# elif defined(__arc__)
# define __NR_copy_file_range 285
# elif defined(__riscv)
# define __NR_copy_file_range 285
# endif
#endif /* __NR_copy_file_range */
@@ -94,6 +96,8 @@
# define __NR_statx 383
# elif defined(__s390__)
# define __NR_statx 379
# elif defined(__riscv)
# define __NR_statx 291
# endif
#endif /* __NR_statx */
@@ -110,6 +114,8 @@
# define __NR_getrandom 359
# elif defined(__s390__)
# define __NR_getrandom 349
# elif defined(__riscv)
# define __NR_getrandom 278
# endif
#endif /* __NR_getrandom */
@@ -318,17 +324,64 @@ unsigned uv__kernel_version(void) {
unsigned major;
unsigned minor;
unsigned patch;
char v_sig[256];
char* needle;
version = std::atomic_load_explicit(&cached_version, std::memory_order_relaxed);
if (version != 0)
return version;
/* Check /proc/version_signature first as it's the way to get the mainline
* kernel version in Ubuntu. The format is:
* Ubuntu ubuntu_kernel_version mainline_kernel_version
* For example:
* Ubuntu 5.15.0-79.86-generic 5.15.111
*/
if (0 == uv__slurp("/proc/version_signature", v_sig, sizeof(v_sig)))
if (3 == sscanf(v_sig, "Ubuntu %*s %u.%u.%u", &major, &minor, &patch))
goto calculate_version;
if (-1 == uname(&u))
return 0;
/* In Debian we need to check `version` instead of `release` to extract the
* mainline kernel version. This is an example of how it looks like:
* #1 SMP Debian 5.10.46-4 (2021-08-03)
*/
needle = strstr(u.version, "Debian ");
if (needle != NULL)
if (3 == sscanf(needle, "Debian %u.%u.%u", &major, &minor, &patch))
goto calculate_version;
if (3 != sscanf(u.release, "%u.%u.%u", &major, &minor, &patch))
return 0;
/* Handle it when the process runs under the UNAME26 personality:
*
* - kernels >= 3.x identify as 2.6.40+x
* - kernels >= 4.x identify as 2.6.60+x
*
* UNAME26 is a poorly conceived hack that doesn't let us distinguish
* between 4.x kernels and 5.x/6.x kernels so we conservatively assume
* that 2.6.60+x means 4.x.
*
* Fun fact of the day: it's technically possible to observe the actual
* kernel version for a brief moment because uname() first copies out the
* real release string before overwriting it with the backcompat string.
*/
if (major == 2 && minor == 6) {
if (patch >= 60) {
major = 4;
minor = patch - 60;
patch = 0;
} else if (patch >= 40) {
major = 3;
minor = patch - 40;
patch = 0;
}
}
calculate_version:
version = major * 65536 + minor * 256 + patch;
std::atomic_store_explicit(&cached_version, version, std::memory_order_relaxed);
@@ -423,6 +476,9 @@ int uv__io_uring_register(int fd, unsigned opcode, void* arg, unsigned nargs) {
static int uv__use_io_uring(void) {
#if defined(__ANDROID_API__)
return 0; /* Possibly available but blocked by seccomp. */
#elif defined(__arm__) && __SIZEOF_POINTER__ == 4
/* See https://github.com/libuv/libuv/issues/4158. */
return 0; /* All 32 bits kernels appear buggy. */
#else
/* Ternary: unknown=0, yes=1, no=-1 */
static std::atomic<int> use_io_uring;
@@ -432,8 +488,14 @@ static int uv__use_io_uring(void) {
use = std::atomic_load_explicit(&use_io_uring, std::memory_order_relaxed);
if (use == 0) {
/* Older kernels have a bug where the sqpoll thread uses 100% CPU. */
use = uv__kernel_version() >= /* 5.10.186 */ 0x050ABA ? 1 : -1;
/* But users can still enable it if they so desire. */
val = getenv("UV_USE_IO_URING");
use = val == NULL || atoi(val) ? 1 : -1;
if (val != NULL)
use = atoi(val) ? 1 : -1;
std::atomic_store_explicit(&use_io_uring, use, std::memory_order_relaxed);
}
@@ -757,7 +819,9 @@ static void uv__iou_submit(struct uv__iou* iou) {
int uv__iou_fs_close(uv_loop_t* loop, uv_fs_t* req) {
struct uv__io_uring_sqe* sqe;
struct uv__iou* iou;
int kv;
kv = uv__kernel_version();
/* 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
@@ -765,10 +829,17 @@ int uv__iou_fs_close(uv_loop_t* loop, uv_fs_t* req) {
* 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. Yay, computers.
* Also, disable on non-longterm versions between 5.16.0 (non-longterm) and
* 6.1.0 (longterm). Starting with longterm 6.1.x, the issue seems to be
* solved.
*/
if (uv__kernel_version() < /* 5.15.90 */ 0x050F5A)
if (kv < /* 5.15.90 */ 0x050F5A)
return 0;
if (kv >= /* 5.16.0 */ 0x050A00 && kv < /* 6.1.0 */ 0x060100)
return 0;
iou = &uv__get_internal_fields(loop)->iou;
sqe = uv__iou_get_sqe(iou, loop, req);
@@ -1365,41 +1436,20 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
*/
SAVE_ERRNO(uv__update_time(loop));
if (nfds == 0) {
if (nfds == -1)
assert(errno == EINTR);
else if (nfds == 0)
/* Unlimited timeout should only return with events or signal. */
assert(timeout != -1);
if (nfds == 0 || nfds == -1) {
if (reset_timeout != 0) {
timeout = user_timeout;
reset_timeout = 0;
} else if (nfds == 0) {
return;
}
if (timeout == -1)
continue;
if (timeout == 0)
break;
/* We may have been inside the system call for longer than |timeout|
* milliseconds so we need to update the timestamp to avoid drift.
*/
goto update_timeout;
}
if (nfds == -1) {
if (errno != EINTR)
abort();
if (reset_timeout != 0) {
timeout = user_timeout;
reset_timeout = 0;
}
if (timeout == -1)
continue;
if (timeout == 0)
break;
/* Interrupted by a signal. Update timeout and poll again. */
goto update_timeout;
}
@@ -1510,13 +1560,13 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
break;
}
update_timeout:
if (timeout == 0)
break;
if (timeout == -1)
continue;
update_timeout:
assert(timeout > 0);
real_timeout -= (loop->time - base);
@@ -1719,11 +1769,8 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
return UV__ERR(errno);
}
/* Skip first line. */
if (!fgets(buf, sizeof(buf), fp)) {
uv__free(cpus);
return UV__ERR(errno);
}
if (NULL == fgets(buf, sizeof(buf), fp))
abort();
for (;;) {
memset(&t, 0, sizeof(t));
@@ -1734,10 +1781,8 @@ int uv_cpu_info(uv_cpu_info_t** ci, int* count) {
if (n != 7)
break;
/* Skip rest of line. */
if (!fgets(buf, sizeof(buf), fp)) {
break;
}
if (NULL == fgets(buf, sizeof(buf), fp))
abort();
if (cpu >= ARRAY_SIZE(*cpus))
continue;
@@ -1817,9 +1862,8 @@ nocpuinfo:
if (fp == NULL)
continue;
if (0 > fscanf(fp, "%llu", &(*cpus)[cpu].freq)) {
(*cpus)[cpu].freq = 0llu;
}
if (1 != fscanf(fp, "%llu", &(*cpus)[cpu].freq))
abort();
fclose(fp);
fp = NULL;
}

View File

@@ -279,6 +279,8 @@ static int uv__signal_loop_once_init(uv_loop_t* loop) {
int uv__signal_loop_fork(uv_loop_t* loop) {
struct uv__queue* q;
if (loop->signal_pipefd[0] == -1)
return 0;
uv__io_stop(loop, &loop->signal_io_watcher, POLLIN);
@@ -286,6 +288,19 @@ int uv__signal_loop_fork(uv_loop_t* loop) {
uv__close(loop->signal_pipefd[1]);
loop->signal_pipefd[0] = -1;
loop->signal_pipefd[1] = -1;
uv__queue_foreach(q, &loop->handle_queue) {
uv_handle_t* handle = uv__queue_data(q, uv_handle_t, handle_queue);
uv_signal_t* sh;
if (handle->type != UV_SIGNAL)
continue;
sh = (uv_signal_t*) handle;
sh->caught_signals = 0;
sh->dispatched_signals = 0;
}
return uv__signal_loop_once_init(loop);
}

View File

@@ -27,6 +27,17 @@
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#if defined(__PASE__)
#include <as400_protos.h>
#define ifaddrs ifaddrs_pase
#define getifaddrs Qp2getifaddrs
#define freeifaddrs Qp2freeifaddrs
#else
#include <ifaddrs.h>
#endif
static int maybe_bind_socket(int fd) {
union uv__sockaddr s;
@@ -198,11 +209,50 @@ int uv__tcp_bind(uv_tcp_t* tcp,
}
static int uv__is_ipv6_link_local(const struct sockaddr* addr) {
const struct sockaddr_in6* a6;
uint8_t b[2];
if (addr->sa_family != AF_INET6)
return 0;
a6 = (const struct sockaddr_in6*) addr;
memcpy(b, &a6->sin6_addr, sizeof(b));
return b[0] == 0xFE && b[1] == 0x80;
}
static int uv__ipv6_link_local_scope_id(void) {
struct sockaddr_in6* a6;
struct ifaddrs* ifa;
struct ifaddrs* p;
int rv;
if (getifaddrs(&ifa))
return 0;
for (p = ifa; p != NULL; p = p->ifa_next)
if (uv__is_ipv6_link_local(p->ifa_addr))
break;
rv = 0;
if (p != NULL) {
a6 = (struct sockaddr_in6*) p->ifa_addr;
rv = a6->sin6_scope_id;
}
freeifaddrs(ifa);
return rv;
}
int uv__tcp_connect(uv_connect_t* req,
uv_tcp_t* handle,
const struct sockaddr* addr,
unsigned int addrlen,
uv_connect_cb cb) {
struct sockaddr_in6 tmp6;
int err;
int r;
@@ -220,6 +270,14 @@ int uv__tcp_connect(uv_connect_t* req,
if (err)
return err;
if (uv__is_ipv6_link_local(addr)) {
memcpy(&tmp6, addr, sizeof(tmp6));
if (tmp6.sin6_scope_id == 0) {
tmp6.sin6_scope_id = uv__ipv6_link_local_scope_id();
addr = (const struct sockaddr*) &tmp6;
}
}
do {
errno = 0;
r = connect(uv__stream_fd(handle), addr, addrlen);
@@ -374,28 +432,39 @@ int uv__tcp_nodelay(int fd, int on) {
int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
int intvl;
int cnt;
(void) &intvl;
(void) &cnt;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
return UV__ERR(errno);
if (!on)
return 0;
#ifdef TCP_KEEPIDLE
if (on) {
int intvl = 1; /* 1 second; same as default on Win32 */
int cnt = 10; /* 10 retries; same as hardcoded on Win32 */
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
return UV__ERR(errno);
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
return UV__ERR(errno);
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
return UV__ERR(errno);
}
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
return UV__ERR(errno);
/* Solaris/SmartOS, if you don't support keep-alive,
* then don't advertise it in your system headers...
*/
/* FIXME(bnoordhuis) That's possibly because sizeof(delay) should be 1. */
#elif defined(TCP_KEEPALIVE) && !defined(__sun)
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay)))
return UV__ERR(errno);
#endif
/* Solaris/SmartOS, if you don't support keep-alive,
* then don't advertise it in your system headers...
*/
/* FIXME(bnoordhuis) That's possibly because sizeof(delay) should be 1. */
#if defined(TCP_KEEPALIVE) && !defined(__sun)
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay)))
#ifdef TCP_KEEPINTVL
intvl = 1; /* 1 second; same as default on Win32 */
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
return UV__ERR(errno);
#endif
#ifdef TCP_KEEPCNT
cnt = 10; /* 10 retries; same as hardcoded on Win32 */
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
return UV__ERR(errno);
#endif

View File

@@ -782,11 +782,33 @@ void uv_cond_broadcast(uv_cond_t* cond) {
abort();
}
#if defined(__APPLE__) && defined(__MACH__)
void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
int r;
errno = 0;
r = pthread_cond_wait(cond, mutex);
/* Workaround for a bug in OS X at least up to 13.6
* See https://github.com/libuv/libuv/issues/4165
*/
if (r == EINVAL)
if (errno == EBUSY)
return;
if (r)
abort();
}
#else /* !(defined(__APPLE__) && defined(__MACH__)) */
void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
if (pthread_cond_wait(cond, mutex))
abort();
}
#endif
int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
int r;

View File

@@ -559,6 +559,9 @@ static void uv__print_handles(uv_loop_t* loop, int only_active, FILE* stream) {
if (loop == NULL)
loop = uv_default_loop();
if (stream == NULL)
stream = stderr;
uv__queue_foreach(q, &loop->handle_queue) {
h = uv__queue_data(q, uv_handle_t, handle_queue);

View File

@@ -27,18 +27,17 @@ static int uv__dlerror(uv_lib_t* lib, const char* filename, DWORD errorno);
int uv_dlopen(const char* filename, uv_lib_t* lib) {
WCHAR filename_w[32768];
ssize_t r;
lib->handle = NULL;
lib->errmsg = NULL;
if (!MultiByteToWideChar(CP_UTF8,
0,
filename,
-1,
filename_w,
ARRAY_SIZE(filename_w))) {
return uv__dlerror(lib, filename, GetLastError());
}
r = uv_wtf8_length_as_utf16(filename);
if (r < 0)
return uv__dlerror(lib, filename, ERROR_NO_UNICODE_TRANSLATION);
if ((size_t) r > ARRAY_SIZE(filename_w))
return uv__dlerror(lib, filename, ERROR_INSUFFICIENT_BUFFER);
uv_wtf8_to_utf16(filename, (uint16_t*)filename_w, r);
lib->handle = LoadLibraryExW(filename_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (lib->handle == NULL) {

View File

@@ -159,7 +159,8 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv_fs_event_cb cb,
const char* path,
unsigned int flags) {
int name_size, is_path_dir, size;
int is_path_dir;
size_t size;
DWORD attr, last_error;
WCHAR* dir = NULL, *dir_to_watch, *pathw = NULL;
DWORD short_path_buffer_len;
@@ -178,23 +179,9 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv__handle_start(handle);
/* Convert name to UTF16. */
name_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0) *
sizeof(WCHAR);
pathw = (WCHAR*)uv__malloc(name_size);
if (!pathw) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!MultiByteToWideChar(CP_UTF8,
0,
path,
-1,
pathw,
name_size / sizeof(WCHAR))) {
return uv_translate_sys_error(GetLastError());
}
last_error = uv__convert_utf8_to_utf16(path, &pathw);
if (last_error)
goto error_uv;
/* Determine whether path is a file or a directory. */
attr = GetFileAttributesW(pathw);
@@ -335,6 +322,9 @@ short_path_done:
return 0;
error:
last_error = uv_translate_sys_error(last_error);
error_uv:
if (handle->path) {
uv__free(handle->path);
handle->path = NULL;
@@ -367,7 +357,7 @@ error:
uv__free(short_path);
return uv_translate_sys_error(last_error);
return last_error;
}

View File

@@ -33,13 +33,16 @@
#include <stdio.h>
#include "uv.h"
/* <winioctl.h> requires <windows.h>, included via "uv.h" above, but needs to
be included before our "winapi.h", included via "internal.h" below. */
#include <winioctl.h>
#include "internal.h"
#include "req-inl.h"
#include "handle-inl.h"
#include "fs-fd-hash-inl.h"
#include <winioctl.h>
#pragma comment(lib, "Advapi32.lib")
#define UV_FS_FREE_PATHS 0x0002
@@ -147,279 +150,6 @@ void uv__fs_init(void) {
}
static int32_t fs__decode_wtf8_char(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)
if (code_point <= 0x10FFFF)
return code_point; /* four-byte character */
/* code point too large */
return -1;
}
static ssize_t fs__get_length_wtf8(const char* source_ptr) {
size_t w_target_len = 0;
int32_t code_point;
do {
code_point = fs__decode_wtf8_char(&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;
}
static void fs__wtf8_to_wide(const char* source_ptr, WCHAR* w_target) {
int32_t code_point;
do {
code_point = fs__decode_wtf8_char(&source_ptr);
/* fs__get_length_wtf8 should have been called and checked first. */
assert(code_point >= 0);
if (code_point > 0x10000) {
assert(code_point < 0x10FFFF);
*w_target++ = (((code_point - 0x10000) >> 10) + 0xD800);
*w_target++ = ((code_point - 0x10000) & 0x3FF) + 0xDC00;
} else {
*w_target++ = code_point;
}
} while (*source_ptr++);
}
INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
const char* new_path, const int copy_path) {
WCHAR* buf;
WCHAR* pos;
size_t buf_sz = 0;
size_t path_len = 0;
ssize_t pathw_len = 0;
ssize_t new_pathw_len = 0;
/* new_path can only be set if path is also set. */
assert(new_path == NULL || path != NULL);
if (path != NULL) {
pathw_len = fs__get_length_wtf8(path);
if (pathw_len < 0)
return ERROR_INVALID_NAME;
buf_sz += pathw_len * sizeof(WCHAR);
}
if (path != NULL && copy_path) {
path_len = 1 + strlen(path);
buf_sz += path_len;
}
if (new_path != NULL) {
new_pathw_len = fs__get_length_wtf8(new_path);
if (new_pathw_len < 0)
return ERROR_INVALID_NAME;
buf_sz += new_pathw_len * sizeof(WCHAR);
}
if (buf_sz == 0) {
req->file.pathw = NULL;
req->fs.info.new_pathw = NULL;
req->path = NULL;
return 0;
}
buf = (WCHAR *)uv__malloc(buf_sz);
if (buf == NULL) {
return ERROR_OUTOFMEMORY;
}
pos = buf;
if (path != NULL) {
fs__wtf8_to_wide(path, pos);
req->file.pathw = pos;
pos += pathw_len;
} else {
req->file.pathw = NULL;
}
if (new_path != NULL) {
fs__wtf8_to_wide(new_path, pos);
req->fs.info.new_pathw = pos;
pos += new_pathw_len;
} else {
req->fs.info.new_pathw = NULL;
}
req->path = path;
if (path != NULL && copy_path) {
memcpy(pos, path, path_len);
assert(path_len == buf_sz - (pos - buf) * sizeof(WCHAR));
req->path = (char*) pos;
}
req->flags |= UV_FS_FREE_PATHS;
return 0;
}
INLINE static void uv__fs_req_init(uv_loop_t* loop, uv_fs_t* req,
uv_fs_type fs_type, const uv_fs_cb cb) {
uv__once_init();
UV_REQ_INIT(req, UV_FS);
req->loop = loop;
req->flags = 0;
req->fs_type = fs_type;
req->sys_errno_ = 0;
req->result = 0;
req->ptr = NULL;
req->path = NULL;
req->cb = cb;
memset(&req->fs, 0, sizeof(req->fs));
}
static int32_t fs__get_surrogate_value(const WCHAR* w_source_ptr,
size_t w_source_len) {
WCHAR u;
WCHAR 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;
}
static size_t fs__get_length_wide(const WCHAR* w_source_ptr,
size_t w_source_len) {
size_t target_len;
int32_t code_point;
target_len = 0;
for (; w_source_len; w_source_len--, w_source_ptr++) {
code_point = fs__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 (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++;
w_source_len--;
}
}
return target_len;
}
static int fs__wide_to_wtf8(WCHAR* w_source_ptr,
size_t w_source_len,
char** target_ptr,
size_t* target_len_ptr) {
size_t target_len;
char* target;
int32_t code_point;
/* If *target_ptr is provided, then *target_len_ptr must be its length
* (excluding space for null), 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 = fs__get_length_wide(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 = (char *)uv__malloc(target_len + 1);
if (target == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return -1;
}
*target_ptr = target;
} else {
target = *target_ptr;
}
for (; w_source_len; w_source_len--, w_source_ptr++) {
code_point = fs__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 (code_point < 0x80) {
*target++ = code_point;
} else if (code_point < 0x800) {
*target++ = 0xC0 | (code_point >> 6);
*target++ = 0x80 | (code_point & 0x3F);
} else if (code_point < 0x10000) {
*target++ = 0xE0 | (code_point >> 12);
*target++ = 0x80 | ((code_point >> 6) & 0x3F);
*target++ = 0x80 | (code_point & 0x3F);
} else {
*target++ = 0xF0 | (code_point >> 18);
*target++ = 0x80 | ((code_point >> 12) & 0x3F);
*target++ = 0x80 | ((code_point >> 6) & 0x3F);
*target++ = 0x80 | (code_point & 0x3F);
w_source_ptr++;
w_source_len--;
}
}
assert((size_t) (target - *target_ptr) == target_len);
*target++ = '\0';
return 0;
}
INLINE static int fs__readlink_handle(HANDLE handle,
char** target_ptr,
size_t* target_len_ptr) {
@@ -553,7 +283,98 @@ INLINE static int fs__readlink_handle(HANDLE handle,
}
assert(target_ptr == NULL || *target_ptr == NULL);
return fs__wide_to_wtf8(w_target, w_target_len, target_ptr, target_len_ptr);
return uv_utf16_to_wtf8((const uint16_t*)w_target, w_target_len, target_ptr, target_len_ptr);
}
INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
const char* new_path, const int copy_path) {
WCHAR* buf;
WCHAR* pos;
size_t buf_sz = 0;
size_t path_len = 0;
ssize_t pathw_len = 0;
ssize_t new_pathw_len = 0;
/* new_path can only be set if path is also set. */
assert(new_path == NULL || path != NULL);
if (path != NULL) {
pathw_len = uv_wtf8_length_as_utf16(path);
if (pathw_len < 0)
return ERROR_INVALID_NAME;
buf_sz += pathw_len * sizeof(WCHAR);
}
if (path != NULL && copy_path) {
path_len = 1 + strlen(path);
buf_sz += path_len;
}
if (new_path != NULL) {
new_pathw_len = uv_wtf8_length_as_utf16(new_path);
if (new_pathw_len < 0)
return ERROR_INVALID_NAME;
buf_sz += new_pathw_len * sizeof(WCHAR);
}
if (buf_sz == 0) {
req->file.pathw = NULL;
req->fs.info.new_pathw = NULL;
req->path = NULL;
return 0;
}
buf = (WCHAR*)uv__malloc(buf_sz);
if (buf == NULL) {
return ERROR_OUTOFMEMORY;
}
pos = buf;
if (path != NULL) {
uv_wtf8_to_utf16(path, (uint16_t*)pos, pathw_len);
req->file.pathw = pos;
pos += pathw_len;
} else {
req->file.pathw = NULL;
}
if (new_path != NULL) {
uv_wtf8_to_utf16(new_path, (uint16_t*)pos, new_pathw_len);
req->fs.info.new_pathw = pos;
pos += new_pathw_len;
} else {
req->fs.info.new_pathw = NULL;
}
req->path = path;
if (path != NULL && copy_path) {
memcpy(pos, path, path_len);
assert(path_len == buf_sz - (pos - buf) * sizeof(WCHAR));
req->path = (char*) pos;
}
req->flags |= UV_FS_FREE_PATHS;
return 0;
}
INLINE static void uv__fs_req_init(uv_loop_t* loop, uv_fs_t* req,
uv_fs_type fs_type, const uv_fs_cb cb) {
uv__once_init();
UV_REQ_INIT(req, UV_FS);
req->loop = loop;
req->flags = 0;
req->fs_type = fs_type;
req->sys_errno_ = 0;
req->result = 0;
req->ptr = NULL;
req->path = NULL;
req->cb = cb;
memset(&req->fs, 0, sizeof(req->fs));
}
@@ -1572,7 +1393,7 @@ void fs__scandir(uv_fs_t* req) {
continue;
/* Compute the space required to store the filename as WTF-8. */
wtf8_len = fs__get_length_wide(&info->FileName[0], wchar_len);
wtf8_len = uv_utf16_length_as_wtf8((const uint16_t*)&info->FileName[0], wchar_len);
/* Resize the dirent array if needed. */
if (dirents_used >= dirents_size) {
@@ -1600,8 +1421,8 @@ void fs__scandir(uv_fs_t* req) {
/* Convert file name to UTF-8. */
wtf8 = &dirent->d_name[0];
if (fs__wide_to_wtf8(&info->FileName[0], wchar_len, &wtf8, &wtf8_len) == -1)
goto win32_error;
if (uv_utf16_to_wtf8((const uint16_t*)&info->FileName[0], wchar_len, &wtf8, &wtf8_len) != 0)
goto out_of_memory_error;
/* Fill out the type field. */
if (info->FileAttributes & FILE_ATTRIBUTE_DEVICE)
@@ -2827,7 +2648,7 @@ static ssize_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) {
}
assert(*realpath_ptr == NULL);
r = fs__wide_to_wtf8(w_realpath_ptr, w_realpath_len, realpath_ptr, NULL);
r = uv_utf16_to_wtf8((const uint16_t*)w_realpath_ptr, w_realpath_len, realpath_ptr, NULL);
uv__free(w_realpath_buf);
return r;
}

View File

@@ -104,13 +104,14 @@ static void uv__getaddrinfo_work(struct uv__work* w) {
*/
static void uv__getaddrinfo_done(struct uv__work* w, int status) {
uv_getaddrinfo_t* req;
int addrinfo_len = 0;
int name_len = 0;
size_t addrinfo_len = 0;
ssize_t name_len = 0;
size_t addrinfo_struct_len = ALIGNED_SIZE(sizeof(struct addrinfo));
struct addrinfoW* addrinfow_ptr;
struct addrinfo* addrinfo_ptr;
char* alloc_ptr = NULL;
char* cur_ptr = NULL;
int r;
req = container_of(w, uv_getaddrinfo_t, work_req);
@@ -131,19 +132,12 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
addrinfo_len += addrinfo_struct_len +
ALIGNED_SIZE(addrinfow_ptr->ai_addrlen);
if (addrinfow_ptr->ai_canonname != NULL) {
name_len = WideCharToMultiByte(CP_UTF8,
0,
addrinfow_ptr->ai_canonname,
-1,
NULL,
0,
NULL,
NULL);
if (name_len == 0) {
req->retcode = uv_translate_sys_error(GetLastError());
name_len = uv_utf16_length_as_wtf8((const uint16_t*)addrinfow_ptr->ai_canonname, -1);
if (name_len < 0) {
req->retcode = name_len;
goto complete;
}
addrinfo_len += ALIGNED_SIZE(name_len);
addrinfo_len += ALIGNED_SIZE(name_len + 1);
}
addrinfow_ptr = addrinfow_ptr->ai_next;
}
@@ -182,27 +176,14 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
/* convert canonical name to UTF-8 */
if (addrinfow_ptr->ai_canonname != NULL) {
name_len = WideCharToMultiByte(CP_UTF8,
0,
addrinfow_ptr->ai_canonname,
-1,
NULL,
0,
NULL,
NULL);
assert(name_len > 0);
assert(cur_ptr + name_len <= alloc_ptr + addrinfo_len);
name_len = WideCharToMultiByte(CP_UTF8,
0,
addrinfow_ptr->ai_canonname,
-1,
cur_ptr,
name_len,
NULL,
NULL);
assert(name_len > 0);
name_len = alloc_ptr + addrinfo_len - cur_ptr;
r = uv__copy_utf16_to_utf8(addrinfow_ptr->ai_canonname,
-1,
cur_ptr,
(size_t*)&name_len);
assert(r == 0);
addrinfo_ptr->ai_canonname = cur_ptr;
cur_ptr += ALIGNED_SIZE(name_len);
cur_ptr += ALIGNED_SIZE(name_len + 1);
}
assert(cur_ptr <= alloc_ptr + addrinfo_len);
@@ -261,12 +242,11 @@ int uv_getaddrinfo(uv_loop_t* loop,
const char* service,
const struct addrinfo* hints) {
char hostname_ascii[256];
int nodesize = 0;
int servicesize = 0;
int hintssize = 0;
size_t nodesize = 0;
size_t servicesize = 0;
size_t hintssize = 0;
char* alloc_ptr = NULL;
int err;
long rc;
ssize_t rc;
if (req == NULL || (node == NULL && service == NULL)) {
return UV_EINVAL;
@@ -286,56 +266,36 @@ int uv_getaddrinfo(uv_loop_t* loop,
hostname_ascii + sizeof(hostname_ascii));
if (rc < 0)
return rc;
nodesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8, 0, hostname_ascii,
-1, NULL, 0) * sizeof(WCHAR));
if (nodesize == 0) {
err = GetLastError();
goto error;
}
nodesize = strlen(hostname_ascii) + 1;
node = hostname_ascii;
}
if (service != NULL) {
servicesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8,
0,
service,
-1,
NULL,
0) *
sizeof(WCHAR));
if (servicesize == 0) {
err = GetLastError();
goto error;
}
rc = uv_wtf8_length_as_utf16(service);
if (rc < 0)
return rc;
servicesize = rc;
}
if (hints != NULL) {
hintssize = ALIGNED_SIZE(sizeof(struct addrinfoW));
}
/* allocate memory for inputs, and partition it as needed */
alloc_ptr = (char*)uv__malloc(nodesize + servicesize + hintssize);
if (!alloc_ptr) {
err = WSAENOBUFS;
goto error;
}
alloc_ptr = (char*)uv__malloc(ALIGNED_SIZE(nodesize * sizeof(WCHAR)) +
ALIGNED_SIZE(servicesize * sizeof(WCHAR)) +
hintssize);
if (!alloc_ptr)
return UV_ENOMEM;
/* save alloc_ptr now so we can free if error */
req->alloc = (void*)alloc_ptr;
req->alloc = (void*) alloc_ptr;
/* Convert node string to UTF16 into allocated memory and save pointer in the
* request. */
* request. The node here has been converted to ascii. */
if (node != NULL) {
req->node = (WCHAR*)alloc_ptr;
if (MultiByteToWideChar(CP_UTF8,
0,
node,
-1,
(WCHAR*) alloc_ptr,
nodesize / sizeof(WCHAR)) == 0) {
err = GetLastError();
goto error;
}
alloc_ptr += nodesize;
req->node = (WCHAR*) alloc_ptr;
uv_wtf8_to_utf16(node, (uint16_t*) alloc_ptr, nodesize);
alloc_ptr += ALIGNED_SIZE(nodesize * sizeof(WCHAR));
} else {
req->node = NULL;
}
@@ -343,24 +303,16 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* Convert service string to UTF16 into allocated memory and save pointer in
* the req. */
if (service != NULL) {
req->service = (WCHAR*)alloc_ptr;
if (MultiByteToWideChar(CP_UTF8,
0,
service,
-1,
(WCHAR*) alloc_ptr,
servicesize / sizeof(WCHAR)) == 0) {
err = GetLastError();
goto error;
}
alloc_ptr += servicesize;
req->service = (WCHAR*) alloc_ptr;
uv_wtf8_to_utf16(service, (uint16_t*) alloc_ptr, servicesize);
alloc_ptr += ALIGNED_SIZE(servicesize * sizeof(WCHAR));
} else {
req->service = NULL;
}
/* copy hints to allocated memory and save pointer in req */
if (hints != NULL) {
req->addrinfow = (struct addrinfoW*)alloc_ptr;
req->addrinfow = (struct addrinfoW*) alloc_ptr;
req->addrinfow->ai_family = hints->ai_family;
req->addrinfow->ai_socktype = hints->ai_socktype;
req->addrinfow->ai_protocol = hints->ai_protocol;
@@ -387,19 +339,11 @@ int uv_getaddrinfo(uv_loop_t* loop,
uv__getaddrinfo_done(&req->work_req, 0);
return req->retcode;
}
error:
if (req != NULL) {
uv__free(req->alloc);
req->alloc = NULL;
}
return uv_translate_sys_error(err);
}
int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) {
NET_LUID luid;
wchar_t wname[NDIS_IF_MAX_STRING_SIZE + 1]; /* Add one for the NUL. */
DWORD bufsize;
int r;
if (buffer == NULL || size == NULL || *size == 0)
@@ -415,31 +359,7 @@ int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) {
if (r != 0)
return uv_translate_sys_error(r);
/* Check how much space we need */
bufsize = WideCharToMultiByte(CP_UTF8, 0, wname, -1, NULL, 0, NULL, NULL);
if (bufsize == 0) {
return uv_translate_sys_error(GetLastError());
} else if (bufsize > *size) {
*size = bufsize;
return UV_ENOBUFS;
}
/* Convert to UTF-8 */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
wname,
-1,
buffer,
*size,
NULL,
NULL);
if (bufsize == 0)
return uv_translate_sys_error(GetLastError());
*size = bufsize - 1;
return 0;
return uv__copy_utf16_to_utf8(wname, -1, buffer, size);
}
int uv_if_indextoiid(unsigned int ifindex, char* buffer, size_t* size) {

View File

@@ -42,6 +42,7 @@ static void uv__getnameinfo_work(struct uv__work* w) {
uv_getnameinfo_t* req;
WCHAR host[NI_MAXHOST];
WCHAR service[NI_MAXSERV];
size_t size;
int ret;
req = container_of(w, uv_getnameinfo_t, work_req);
@@ -57,29 +58,17 @@ static void uv__getnameinfo_work(struct uv__work* w) {
return;
}
ret = WideCharToMultiByte(CP_UTF8,
0,
host,
-1,
req->host,
sizeof(req->host),
NULL,
NULL);
if (ret == 0) {
req->retcode = uv_translate_sys_error(GetLastError());
size = sizeof(req->host);
ret = uv__copy_utf16_to_utf8(host, -1, req->host, &size);
if (ret < 0) {
req->retcode = ret;
return;
}
ret = WideCharToMultiByte(CP_UTF8,
0,
service,
-1,
req->service,
sizeof(req->service),
NULL,
NULL);
if (ret == 0) {
req->retcode = uv_translate_sys_error(GetLastError());
size = sizeof(req->service);
ret = uv__copy_utf16_to_utf8(service, -1, req->service, &size);
if (ret < 0) {
req->retcode = ret;
}
}

View File

@@ -257,8 +257,9 @@ void uv__util_init(void);
uint64_t uv__hrtime(unsigned int scale);
__declspec(noreturn) void uv_fatal_error(const int errorno, const char* syscall);
int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8);
int uv__convert_utf8_to_utf16(const char* utf8, int utf8len, WCHAR** utf16);
int uv__convert_utf16_to_utf8(const WCHAR* utf16, size_t utf16len, char** utf8);
int uv__copy_utf16_to_utf8(const WCHAR* utf16, size_t utf16len, char* utf8, size_t *size);
int uv__convert_utf8_to_utf16(const char* utf8, WCHAR** utf16);
typedef int (WINAPI *uv__peersockfunc)(SOCKET, struct sockaddr*, int*);

View File

@@ -51,7 +51,7 @@ static const int default_pending_pipe_instances = 4;
/* Pipe prefix */
static char pipe_prefix[] = "\\\\?\\pipe";
static const int pipe_prefix_len = sizeof(pipe_prefix) - 1;
static const size_t pipe_prefix_len = sizeof(pipe_prefix) - 1;
/* IPC incoming xfer queue item. */
typedef struct {
@@ -705,7 +705,7 @@ int uv_pipe_bind2(uv_pipe_t* handle,
size_t namelen,
unsigned int flags) {
uv_loop_t* loop = handle->loop;
int i, err, nameSize;
int i, err;
uv_pipe_accept_t* req;
if (flags & ~UV_PIPE_NO_TRUNCATE) {
@@ -744,9 +744,8 @@ int uv_pipe_bind2(uv_pipe_t* handle,
handle->pipe.serv.accept_reqs = (uv_pipe_accept_t*)
uv__malloc(sizeof(uv_pipe_accept_t) * handle->pipe.serv.pending_instances);
if (!handle->pipe.serv.accept_reqs) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!handle->pipe.serv.accept_reqs)
return UV_ENOMEM;
for (i = 0; i < handle->pipe.serv.pending_instances; i++) {
req = &handle->pipe.serv.accept_reqs[i];
@@ -756,22 +755,9 @@ int uv_pipe_bind2(uv_pipe_t* handle,
req->next_pending = NULL;
}
/* Convert name to UTF16. */
nameSize = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0) * sizeof(WCHAR);
handle->name = (WCHAR*)uv__malloc(nameSize);
if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!MultiByteToWideChar(CP_UTF8,
0,
name,
-1,
handle->name,
nameSize / sizeof(WCHAR))) {
err = GetLastError();
goto error;
}
err = uv__convert_utf8_to_utf16(name, &handle->name);
if (err)
return err;
/*
* Attempt to create the first pipe with FILE_FLAG_FIRST_PIPE_INSTANCE.
@@ -797,10 +783,8 @@ int uv_pipe_bind2(uv_pipe_t* handle,
return 0;
error:
if (handle->name) {
uv__free(handle->name);
handle->name = NULL;
}
uv__free(handle->name);
handle->name = NULL;
return uv_translate_sys_error(err);
}
@@ -863,7 +847,8 @@ int uv_pipe_connect2(uv_connect_t* req,
unsigned int flags,
uv_connect_cb cb) {
uv_loop_t* loop = handle->loop;
int err, nameSize;
int err;
size_t nameSize;
HANDLE pipeHandle = INVALID_HANDLE_VALUE;
DWORD duplex_flags;
@@ -906,26 +891,16 @@ int uv_pipe_connect2(uv_connect_t* req,
}
uv__pipe_connection_init(handle);
/* Convert name to UTF16. */
nameSize = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0) * sizeof(WCHAR);
handle->name = (WCHAR*)uv__malloc(nameSize);
if (!handle->name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
if (!MultiByteToWideChar(CP_UTF8,
0,
name,
-1,
handle->name,
nameSize / sizeof(WCHAR))) {
err = GetLastError();
err = uv__convert_utf8_to_utf16(name, &handle->name);
if (err) {
err = ERROR_NO_UNICODE_TRANSLATION;
goto error;
}
pipeHandle = open_named_pipe(handle->name, &duplex_flags);
if (pipeHandle == INVALID_HANDLE_VALUE) {
if (GetLastError() == ERROR_PIPE_BUSY) {
nameSize = (wcslen(handle->name) + 1) * sizeof(WCHAR);
req->u.connect.name = (WCHAR *)uv__malloc(nameSize);
if (!req->u.connect.name) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
@@ -2441,7 +2416,6 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
FILE_NAME_INFORMATION tmp_name_info;
FILE_NAME_INFORMATION* name_info;
WCHAR* name_buf;
unsigned int addrlen;
unsigned int name_size;
unsigned int name_len;
int err;
@@ -2452,46 +2426,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
if (handle->name != NULL) {
/* The user might try to query the name before we are connected,
* and this is just easier to return the cached value if we have it. */
name_buf = handle->name;
name_len = wcslen(name_buf);
/* check how much space we need */
addrlen = WideCharToMultiByte(CP_UTF8,
0,
name_buf,
name_len,
NULL,
0,
NULL,
NULL);
if (!addrlen) {
*size = 0;
err = uv_translate_sys_error(GetLastError());
return err;
} else if (addrlen >= *size) {
*size = addrlen + 1;
err = UV_ENOBUFS;
goto error;
}
addrlen = WideCharToMultiByte(CP_UTF8,
0,
name_buf,
name_len,
buffer,
addrlen,
NULL,
NULL);
if (!addrlen) {
*size = 0;
err = uv_translate_sys_error(GetLastError());
return err;
}
*size = addrlen;
buffer[addrlen] = '\0';
return 0;
return uv__copy_utf16_to_utf8(handle->name, -1, buffer, size);
}
if (handle->handle == INVALID_HANDLE_VALUE) {
@@ -2519,8 +2454,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
name_info = (FILE_NAME_INFORMATION*)uv__malloc(name_size);
if (!name_info) {
*size = 0;
err = UV_ENOMEM;
goto cleanup;
return UV_ENOMEM;
}
nt_status = pNtQueryInformationFile(handle->handle,
@@ -2553,51 +2487,19 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
name_len /= sizeof(WCHAR);
/* check how much space we need */
addrlen = WideCharToMultiByte(CP_UTF8,
0,
name_buf,
name_len,
NULL,
0,
NULL,
NULL);
if (!addrlen) {
/* "\\\\.\\pipe" + name */
if (*size < pipe_prefix_len) {
*size = 0;
err = uv_translate_sys_error(GetLastError());
goto error;
} else if (pipe_prefix_len + addrlen >= *size) {
/* "\\\\.\\pipe" + name */
*size = pipe_prefix_len + addrlen + 1;
err = UV_ENOBUFS;
goto error;
}
memcpy(buffer, pipe_prefix, pipe_prefix_len);
addrlen = WideCharToMultiByte(CP_UTF8,
0,
name_buf,
name_len,
buffer+pipe_prefix_len,
*size-pipe_prefix_len,
NULL,
NULL);
if (!addrlen) {
*size = 0;
err = uv_translate_sys_error(GetLastError());
goto error;
else {
memcpy(buffer, pipe_prefix, pipe_prefix_len);
*size -= pipe_prefix_len;
}
addrlen += pipe_prefix_len;
*size = addrlen;
buffer[addrlen] = '\0';
err = 0;
err = uv__copy_utf16_to_utf8(name_buf, name_len, buffer+pipe_prefix_len, size);
*size += pipe_prefix_len;
error:
uv__free(name_info);
cleanup:
return err;
}

View File

@@ -103,38 +103,26 @@ static void uv__init_global_job_handle(void) {
&info,
sizeof info))
uv_fatal_error(GetLastError(), "SetInformationJobObject");
if (!AssignProcessToJobObject(uv_global_job_handle_, GetCurrentProcess())) {
/* Make sure this handle is functional. The Windows kernel has 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 possibly 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.
*/
DWORD err = GetLastError();
if (err != ERROR_ACCESS_DENIED)
uv_fatal_error(err, "AssignProcessToJobObject");
}
}
static int uv__utf8_to_utf16_alloc(const char* s, WCHAR** ws_ptr) {
int ws_len, r;
WCHAR* ws;
ws_len = MultiByteToWideChar(CP_UTF8,
0,
s,
-1,
NULL,
0);
if (ws_len <= 0) {
return GetLastError();
}
ws = (WCHAR*) uv__malloc(ws_len * sizeof(WCHAR));
if (ws == NULL) {
return ERROR_OUTOFMEMORY;
}
r = MultiByteToWideChar(CP_UTF8,
0,
s,
-1,
ws,
ws_len);
assert(r == ws_len);
*ws_ptr = ws;
return 0;
return uv__convert_utf8_to_utf16(s, ws_ptr);
}
@@ -394,7 +382,7 @@ static WCHAR* search_path(const WCHAR *file,
name_has_ext);
while (result == NULL) {
if (*dir_end == L'\0') {
if (dir_end == NULL || *dir_end == L'\0') {
break;
}
@@ -537,21 +525,15 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
/* Count the required size. */
for (arg = args; *arg; arg++) {
DWORD arg_len;
ssize_t arg_len;
arg_len = MultiByteToWideChar(CP_UTF8,
0,
*arg,
-1,
NULL,
0);
if (arg_len == 0) {
return GetLastError();
}
arg_len = uv_wtf8_length_as_utf16(*arg);
if (arg_len < 0)
return arg_len;
dst_len += arg_len;
if (arg_len > temp_buffer_len)
if ((size_t) arg_len > temp_buffer_len)
temp_buffer_len = arg_len;
arg_count++;
@@ -562,34 +544,28 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
dst_len = dst_len * 2 + arg_count * 2;
/* Allocate buffer for the final command line. */
dst = (WCHAR*) uv__malloc(dst_len * sizeof(WCHAR));
dst = (WCHAR*)uv__malloc(dst_len * sizeof(WCHAR));
if (dst == NULL) {
err = ERROR_OUTOFMEMORY;
err = UV_ENOMEM;
goto error;
}
/* Allocate temporary working buffer. */
temp_buffer = (WCHAR*) uv__malloc(temp_buffer_len * sizeof(WCHAR));
temp_buffer = (WCHAR*)uv__malloc(temp_buffer_len * sizeof(WCHAR));
if (temp_buffer == NULL) {
err = ERROR_OUTOFMEMORY;
err = UV_ENOMEM;
goto error;
}
pos = dst;
for (arg = args; *arg; arg++) {
DWORD arg_len;
ssize_t arg_len;
/* Convert argument to wide char. */
arg_len = MultiByteToWideChar(CP_UTF8,
0,
*arg,
-1,
temp_buffer,
(int) (dst + dst_len - pos));
if (arg_len == 0) {
err = GetLastError();
goto error;
}
arg_len = uv_wtf8_length_as_utf16(*arg);
assert(arg_len > 0);
assert(temp_buffer_len >= (size_t) arg_len);
uv_wtf8_to_utf16(*arg, (uint16_t*)temp_buffer, arg_len);
if (verbatim_arguments) {
/* Copy verbatim. */
@@ -601,6 +577,7 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
}
*pos++ = *(arg + 1) ? L' ' : L'\0';
assert(pos <= dst + dst_len);
}
uv__free(temp_buffer);
@@ -686,28 +663,22 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
WCHAR* ptr;
char** env;
size_t env_len = 0;
int len;
size_t len;
size_t i;
DWORD var_size;
size_t var_size;
size_t env_block_count = 1; /* 1 for null-terminator */
WCHAR* dst_copy;
WCHAR** ptr_copy;
WCHAR** env_copy;
DWORD required_vars_value_len[ARRAY_SIZE(required_vars)];
size_t required_vars_value_len[ARRAY_SIZE(required_vars)];
/* first pass: determine size in UTF-16 */
for (env = env_block; *env; env++) {
int len;
ssize_t len;
if (strchr(*env, '=')) {
len = MultiByteToWideChar(CP_UTF8,
0,
*env,
-1,
NULL,
0);
if (len <= 0) {
return GetLastError();
}
len = uv_wtf8_length_as_utf16(*env);
if (len < 0)
return len;
env_len += len;
env_block_count++;
}
@@ -716,25 +687,19 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
/* second pass: copy to UTF-16 environment block */
dst_copy = (WCHAR*)uv__malloc(env_len * sizeof(WCHAR));
if (dst_copy == NULL && env_len > 0) {
return ERROR_OUTOFMEMORY;
return UV_ENOMEM;
}
env_copy = (WCHAR**)alloca(env_block_count * sizeof(WCHAR*));
ptr = dst_copy;
ptr_copy = env_copy;
for (env = env_block; *env; env++) {
ssize_t len;
if (strchr(*env, '=')) {
len = MultiByteToWideChar(CP_UTF8,
0,
*env,
-1,
ptr,
(int) (env_len - (ptr - dst_copy)));
if (len <= 0) {
DWORD err = GetLastError();
uv__free(dst_copy);
return err;
}
len = uv_wtf8_length_as_utf16(*env);
assert(len > 0);
assert((size_t) len <= env_len - (ptr - dst_copy));
uv_wtf8_to_utf16(*env, (uint16_t*)ptr, len);
*ptr_copy++ = ptr;
ptr += len;
}
@@ -752,7 +717,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
cmp = -1;
} else {
cmp = env_strncmp(required_vars[i].wide_eq,
required_vars[i].len,
required_vars[i].len,
*ptr_copy);
}
if (cmp < 0) {
@@ -775,7 +740,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
dst = (WCHAR*)uv__malloc((1+env_len) * sizeof(WCHAR));
if (!dst) {
uv__free(dst_copy);
return ERROR_OUTOFMEMORY;
return UV_ENOMEM;
}
for (ptr = dst, ptr_copy = env_copy, i = 0;
@@ -973,26 +938,26 @@ int uv_spawn(uv_loop_t* loop,
err = uv__utf8_to_utf16_alloc(options->file, &application);
if (err)
goto done;
goto done_uv;
err = make_program_args(
options->args,
options->flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS,
&arguments);
if (err)
goto done;
goto done_uv;
if (options->env) {
err = make_program_env(options->env, &env);
if (err)
goto done;
goto done_uv;
}
if (options->cwd) {
/* Explicit cwd */
err = uv__utf8_to_utf16_alloc(options->cwd, &cwd);
if (err)
goto done;
goto done_uv;
} else {
/* Inherit cwd */
@@ -1023,22 +988,19 @@ int uv_spawn(uv_loop_t* loop,
DWORD path_len, r;
path_len = GetEnvironmentVariableW(L"PATH", NULL, 0);
if (path_len == 0) {
err = GetLastError();
goto done;
}
if (path_len != 0) {
alloc_path = (WCHAR*) uv__malloc(path_len * sizeof(WCHAR));
if (alloc_path == NULL) {
err = ERROR_OUTOFMEMORY;
goto done;
}
path = alloc_path;
alloc_path = (WCHAR*) uv__malloc(path_len * sizeof(WCHAR));
if (alloc_path == NULL) {
err = ERROR_OUTOFMEMORY;
goto done;
}
path = alloc_path;
r = GetEnvironmentVariableW(L"PATH", path, path_len);
if (r == 0 || r >= path_len) {
err = GetLastError();
goto done;
r = GetEnvironmentVariableW(L"PATH", path, path_len);
if (r == 0 || r >= path_len) {
err = GetLastError();
goto done;
}
}
}
@@ -1100,6 +1062,7 @@ int uv_spawn(uv_loop_t* loop,
* breakaway.
*/
process_flags |= DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP;
process_flags |= CREATE_SUSPENDED;
}
if (!CreateProcessW(application_path,
@@ -1117,11 +1080,6 @@ int uv_spawn(uv_loop_t* loop,
goto done;
}
/* Spawn succeeded. Beyond this point, failure is reported asynchronously. */
process->process_handle = info.hProcess;
process->pid = info.dwProcessId;
/* If the process isn't spawned as detached, assign to the global job object
* so windows will kill it when the parent process dies. */
if (!(options->flags & UV_PROCESS_DETACHED)) {
@@ -1144,6 +1102,19 @@ int uv_spawn(uv_loop_t* loop,
}
}
if (process_flags & CREATE_SUSPENDED) {
if (ResumeThread(info.hThread) == ((DWORD)-1)) {
err = GetLastError();
TerminateProcess(info.hProcess, 1);
goto done;
}
}
/* Spawn succeeded. Beyond this point, failure is reported asynchronously. */
process->process_handle = info.hProcess;
process->pid = info.dwProcessId;
/* Set IPC pid to all IPC pipes. */
for (i = 0; i < options->stdio_count; i++) {
const uv_stdio_container_t* fdopt = &options->stdio[i];
@@ -1171,8 +1142,13 @@ int uv_spawn(uv_loop_t* loop,
* made or the handle is closed, whichever happens first. */
uv__handle_start(process);
goto done_uv;
/* Cleanup, whether we succeeded or failed. */
done:
err = uv_translate_sys_error(err);
done_uv:
uv__free(application);
uv__free(application_path);
uv__free(arguments);
@@ -1186,7 +1162,7 @@ int uv_spawn(uv_loop_t* loop,
child_stdio_buffer = NULL;
}
return uv_translate_sys_error(err);
return err;
}

View File

@@ -486,9 +486,11 @@ static DWORD CALLBACK uv_tty_line_read_thread(void* data) {
uv_loop_t* loop;
uv_tty_t* handle;
uv_req_t* req;
DWORD bytes, read_bytes;
DWORD bytes;
size_t read_bytes;
WCHAR utf16[MAX_INPUT_BUFFER_LENGTH / 3];
DWORD chars, read_chars;
DWORD chars;
DWORD read_chars;
LONG status;
COORD pos;
BOOL read_console_success;
@@ -529,16 +531,13 @@ static DWORD CALLBACK uv_tty_line_read_thread(void* data) {
NULL);
if (read_console_success) {
read_bytes = WideCharToMultiByte(CP_UTF8,
0,
utf16,
read_chars,
handle->tty.rd.read_line_buffer.base,
bytes,
NULL,
NULL);
read_bytes = bytes;
uv_utf16_to_wtf8((const uint16_t*)utf16,
read_chars,
&handle->tty.rd.read_line_buffer.base,
&read_bytes);
SET_REQ_SUCCESS(req);
req->u.io.overlapped.InternalHigh = read_bytes;
req->u.io.overlapped.InternalHigh = (DWORD) read_bytes;
} else {
SET_REQ_ERROR(req, GetLastError());
}
@@ -802,7 +801,9 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
}
if (KEV.uChar.UnicodeChar != 0) {
int prefix_len, char_len;
int prefix_len;
size_t char_len;
char* last_key_buf;
/* Character key pressed */
if (KEV.uChar.UnicodeChar >= 0xD800 &&
@@ -823,38 +824,31 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
prefix_len = 0;
}
if (KEV.uChar.UnicodeChar >= 0xDC00 &&
KEV.uChar.UnicodeChar < 0xE000) {
char_len = sizeof handle->tty.rd.last_key;
last_key_buf = &handle->tty.rd.last_key[prefix_len];
if (handle->tty.rd.last_utf16_high_surrogate) {
/* UTF-16 surrogate pair */
WCHAR utf16_buffer[2];
utf16_buffer[0] = handle->tty.rd.last_utf16_high_surrogate;
utf16_buffer[1] = KEV.uChar.UnicodeChar;
char_len = WideCharToMultiByte(CP_UTF8,
0,
utf16_buffer,
2,
&handle->tty.rd.last_key[prefix_len],
sizeof handle->tty.rd.last_key,
NULL,
NULL);
if (uv_utf16_to_wtf8((const uint16_t*)utf16_buffer,
2,
&last_key_buf,
&char_len))
char_len = 0;
handle->tty.rd.last_utf16_high_surrogate = 0;
} else {
/* Single UTF-16 character */
char_len = WideCharToMultiByte(CP_UTF8,
0,
&KEV.uChar.UnicodeChar,
1,
&handle->tty.rd.last_key[prefix_len],
sizeof handle->tty.rd.last_key,
NULL,
NULL);
if (uv_utf16_to_wtf8((const uint16_t*)&KEV.uChar.UnicodeChar,
1,
&last_key_buf,
&char_len))
char_len = 0;
}
/* Whatever happened, the last character wasn't a high surrogate. */
handle->tty.rd.last_utf16_high_surrogate = 0;
/* If the utf16 character(s) couldn't be converted something must be
* wrong. */
if (!char_len) {
if (char_len == 0) {
handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle);
handle->read_cb((uv_stream_t*) handle,

View File

@@ -105,7 +105,7 @@ void uv__util_init(void) {
int uv_exepath(char* buffer, size_t* size_ptr) {
int utf8_len, utf16_buffer_len, utf16_len;
size_t utf8_len, utf16_buffer_len, utf16_len;
WCHAR* utf16_buffer;
int err;
@@ -133,25 +133,17 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
}
/* Convert to UTF-8 */
utf8_len = WideCharToMultiByte(CP_UTF8,
0,
utf16_buffer,
-1,
buffer,
(int) *size_ptr,
NULL,
NULL);
if (utf8_len == 0) {
err = GetLastError();
goto error;
utf8_len = *size_ptr - 1; /* Reserve space for NUL */
err = uv_utf16_to_wtf8((const uint16_t*)utf16_buffer, utf16_len, &buffer, &utf8_len);
if (err == UV_ENOBUFS) {
utf8_len = *size_ptr - 1;
err = 0;
}
*size_ptr = utf8_len;
uv__free(utf16_buffer);
/* utf8_len *does* include the terminating null at this point, but the
* returned size shouldn't. */
*size_ptr = utf8_len - 1;
return 0;
return err;
error:
uv__free(utf16_buffer);
@@ -214,45 +206,14 @@ int uv_cwd(char* buffer, size_t* size) {
}
r = uv__cwd(&utf16_buffer, &utf16_len);
if (r < 0) {
if (r < 0)
return r;
}
/* Check how much space we need */
r = WideCharToMultiByte(CP_UTF8,
0,
utf16_buffer,
-1,
NULL,
0,
NULL,
NULL);
if (r == 0) {
uv__free(utf16_buffer);
return uv_translate_sys_error(GetLastError());
} else if (r > (int) *size) {
uv__free(utf16_buffer);
*size = r;
return UV_ENOBUFS;
}
r = uv__copy_utf16_to_utf8(utf16_buffer, utf16_len, buffer, size);
/* Convert to UTF-8 */
r = WideCharToMultiByte(CP_UTF8,
0,
utf16_buffer,
-1,
buffer,
*size > INT_MAX ? INT_MAX : (int) *size,
NULL,
NULL);
uv__free(utf16_buffer);
if (r == 0) {
return uv_translate_sys_error(GetLastError());
}
*size = r - 1;
return 0;
return r;
}
@@ -262,33 +223,10 @@ int uv_chdir(const char* dir) {
WCHAR drive_letter, env_var[4];
int r;
if (dir == NULL) {
return UV_EINVAL;
}
utf16_len = MultiByteToWideChar(CP_UTF8,
0,
dir,
-1,
NULL,
0);
if (utf16_len == 0) {
return uv_translate_sys_error(GetLastError());
}
utf16_buffer = (WCHAR*)uv__malloc(utf16_len * sizeof(WCHAR));
if (utf16_buffer == NULL) {
return UV_ENOMEM;
}
if (MultiByteToWideChar(CP_UTF8,
0,
dir,
-1,
utf16_buffer,
utf16_len) == 0) {
uv__free(utf16_buffer);
return uv_translate_sys_error(GetLastError());
}
/* Convert to UTF-16 */
r = uv__convert_utf8_to_utf16(dir, &utf16_buffer);
if (r)
return r;
if (!SetCurrentDirectoryW(utf16_buffer)) {
uv__free(utf16_buffer);
@@ -426,29 +364,14 @@ int uv_set_process_title(const char* title) {
uv__once_init();
/* Find out how big the buffer for the wide-char title must be */
length = MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0);
if (!length) {
err = GetLastError();
goto done;
}
/* Convert to wide-char string */
title_w = (WCHAR*)uv__malloc(sizeof(WCHAR) * length);
if (!title_w) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
}
length = MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w, length);
if (!length) {
err = GetLastError();
goto done;
}
err = uv__convert_utf8_to_utf16(title, &title_w);
if (err)
return err;
/* If the title must be truncated insert a \0 terminator there */
if (length > MAX_TITLE_LENGTH) {
length = wcslen(title_w);
if (length >= MAX_TITLE_LENGTH)
title_w[MAX_TITLE_LENGTH - 1] = L'\0';
}
if (!SetConsoleTitleW(title_w)) {
err = GetLastError();
@@ -470,20 +393,19 @@ done:
static int uv__get_process_title(void) {
WCHAR title_w[MAX_TITLE_LENGTH];
DWORD wlen;
if (!GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR))) {
return -1;
}
wlen = GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR));
if (wlen == 0)
return uv_translate_sys_error(GetLastError());
if (uv__convert_utf16_to_utf8(title_w, -1, &process_title) != 0)
return -1;
return 0;
return uv__convert_utf16_to_utf8(title_w, wlen, &process_title);
}
int uv_get_process_title(char* buffer, size_t size) {
size_t len;
int r;
if (buffer == NULL || size == 0)
return UV_EINVAL;
@@ -495,9 +417,12 @@ int uv_get_process_title(char* buffer, size_t size) {
* If the process_title was never read before nor explicitly set,
* we must query it with getConsoleTitleW
*/
if (!process_title && uv__get_process_title() == -1) {
LeaveCriticalSection(&process_title_lock);
return uv_translate_sys_error(GetLastError());
if (process_title == NULL) {
r = uv__get_process_title();
if (r) {
LeaveCriticalSection(&process_title_lock);
return r;
}
}
assert(process_title);
@@ -844,19 +769,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
continue;
/* Compute the size of the interface name. */
name_size = WideCharToMultiByte(CP_UTF8,
0,
adapter->FriendlyName,
-1,
NULL,
0,
NULL,
FALSE);
if (name_size <= 0) {
uv__free(win_address_buf);
return uv_translate_sys_error(GetLastError());
}
uv_address_buf_size += name_size;
name_size = uv_utf16_length_as_wtf8((const uint16_t*)adapter->FriendlyName, -1);
uv_address_buf_size += name_size + 1;
/* Count the number of addresses associated with this interface, and
* compute the size. */
@@ -886,30 +800,25 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
adapter != NULL;
adapter = adapter->Next) {
IP_ADAPTER_UNICAST_ADDRESS* unicast_address;
int name_size;
size_t max_name_size;
size_t name_size;
int r;
if (adapter->OperStatus != IfOperStatusUp ||
adapter->FirstUnicastAddress == NULL)
continue;
/* Convert the interface name to UTF8. */
max_name_size = (char*) uv_address_buf + uv_address_buf_size - name_buf;
if (max_name_size > (size_t) INT_MAX)
max_name_size = INT_MAX;
name_size = WideCharToMultiByte(CP_UTF8,
0,
adapter->FriendlyName,
-1,
name_buf,
(int) max_name_size,
NULL,
FALSE);
if (name_size <= 0) {
name_size = (char*) uv_address_buf + uv_address_buf_size - name_buf;
r = uv__copy_utf16_to_utf8(adapter->FriendlyName,
-1,
name_buf,
&name_size);
if (r) {
uv__free(win_address_buf);
uv__free(uv_address_buf);
return uv_translate_sys_error(GetLastError());
return r;
}
name_size += 1; /* Add NUL byte. */
/* Add an uv_interface_address_t element for every unicast address. */
for (unicast_address = (IP_ADAPTER_UNICAST_ADDRESS*)
@@ -1072,7 +981,6 @@ int uv_os_homedir(char* buffer, size_t* size) {
int uv_os_tmpdir(char* buffer, size_t* size) {
wchar_t *path;
DWORD bufsize;
size_t len;
if (buffer == NULL || size == NULL || *size == 0)
@@ -1089,7 +997,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
if (path == NULL) {
return UV_ENOMEM;
}
len = GetTempPathW(len, path);
len = GetTempPathW(len, path);
if (len == 0) {
uv__free(path);
@@ -1104,34 +1012,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
path[len] = L'\0';
}
/* Check how much space we need */
bufsize = WideCharToMultiByte(CP_UTF8, 0, path, -1, NULL, 0, NULL, NULL);
if (bufsize == 0) {
uv__free(path);
return uv_translate_sys_error(GetLastError());
} else if (bufsize > *size) {
uv__free(path);
*size = bufsize;
return UV_ENOBUFS;
}
/* Convert to UTF-8 */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
path,
-1,
buffer,
*size,
NULL,
NULL);
uv__free(path);
if (bufsize == 0)
return uv_translate_sys_error(GetLastError());
*size = bufsize - 1;
return 0;
return uv__copy_utf16_to_utf8(path, len, buffer, size);
}
@@ -1142,95 +1023,71 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
* If utf16 is null terminated, utf16len can be set to -1, otherwise it must
* be specified.
*/
int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8) {
DWORD bufsize;
int uv__convert_utf16_to_utf8(const WCHAR* utf16, size_t utf16len, char** utf8) {
size_t utf8_len = 0;
if (utf16 == NULL)
return UV_EINVAL;
/* Check how much space we need */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
utf16,
utf16len,
NULL,
0,
NULL,
NULL);
if (bufsize == 0)
return uv_translate_sys_error(GetLastError());
/* Allocate the destination buffer adding an extra byte for the terminating
* NULL. If utf16len is not -1 WideCharToMultiByte will not add it, so
* we do it ourselves always, just in case. */
*utf8 = (char*)uv__malloc(bufsize + 1);
if (*utf8 == NULL)
return UV_ENOMEM;
/* Convert to UTF-8 */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
utf16,
utf16len,
*utf8,
bufsize,
NULL,
NULL);
if (bufsize == 0) {
uv__free(*utf8);
*utf8 = NULL;
return uv_translate_sys_error(GetLastError());
}
(*utf8)[bufsize] = '\0';
return 0;
*utf8 = NULL;
return uv_utf16_to_wtf8((const uint16_t*)utf16, utf16len, utf8, &utf8_len);
}
/*
* Converts a UTF-8 string into a UTF-16 one. The resulting string is
* null-terminated.
*
* If utf8 is null terminated, utf8len can be set to -1, otherwise it must
* be specified.
*/
int uv__convert_utf8_to_utf16(const char* utf8, int utf8len, WCHAR** utf16) {
int uv__convert_utf8_to_utf16(const char* utf8, WCHAR** utf16) {
int bufsize;
if (utf8 == NULL)
return UV_EINVAL;
/* Check how much space we need */
bufsize = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8len, NULL, 0);
/* Check how much space we need (including NUL). */
bufsize = uv_wtf8_length_as_utf16(utf8);
if (bufsize < 0)
return UV__EINVAL;
if (bufsize == 0)
return uv_translate_sys_error(GetLastError());
/* Allocate the destination buffer adding an extra byte for the terminating
* NULL. If utf8len is not -1 MultiByteToWideChar will not add it, so
* we do it ourselves always, just in case. */
*utf16 = (WCHAR*)uv__malloc(sizeof(WCHAR) * (bufsize + 1));
/* Allocate the destination buffer. */
*utf16 = (WCHAR*)uv__malloc(sizeof(WCHAR) * bufsize);
if (*utf16 == NULL)
return UV_ENOMEM;
/* Convert to UTF-16 */
bufsize = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8len, *utf16, bufsize);
uv_wtf8_to_utf16(utf8, (uint16_t*)*utf16, bufsize);
if (bufsize == 0) {
uv__free(*utf16);
*utf16 = NULL;
return uv_translate_sys_error(GetLastError());
}
(*utf16)[bufsize] = L'\0';
return 0;
}
/*
* Converts a UTF-16 string into a UTF-8 one in an existing buffer. The
* resulting string is null-terminated.
*
* If utf16 is null terminated, utf16len can be set to -1, otherwise it must
* be specified.
*/
int uv__copy_utf16_to_utf8(const WCHAR* utf16buffer, size_t utf16len, char* utf8, size_t *size) {
int r;
if (utf8 == NULL || size == NULL)
return UV_EINVAL;
if (*size == 0) {
*size = uv_utf16_length_as_wtf8((const uint16_t*)utf16buffer, utf16len);
r = UV_ENOBUFS;
} else {
*size -= 1; /* Reserve space for NUL. */
r = uv_utf16_to_wtf8((const uint16_t*)utf16buffer, utf16len, &utf8, size);
}
if (r == UV_ENOBUFS)
*size += 1; /* Add space for NUL. */
return r;
}
static int uv__getpwuid_r(uv_passwd_t* pwd) {
HANDLE token;
wchar_t username[UNLEN + 1];
@@ -1395,14 +1252,13 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
wchar_t* var;
DWORD varlen;
wchar_t* name_w;
DWORD bufsize;
size_t len;
int r;
if (name == NULL || buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL;
r = uv__convert_utf8_to_utf16(name, -1, &name_w);
r = uv__convert_utf8_to_utf16(name, &name_w);
if (r != 0)
return r;
@@ -1443,35 +1299,7 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
}
}
/* Check how much space we need */
bufsize = WideCharToMultiByte(CP_UTF8, 0, var, -1, NULL, 0, NULL, NULL);
if (bufsize == 0) {
r = uv_translate_sys_error(GetLastError());
goto fail;
} else if (bufsize > *size) {
*size = bufsize;
r = UV_ENOBUFS;
goto fail;
}
/* Convert to UTF-8 */
bufsize = WideCharToMultiByte(CP_UTF8,
0,
var,
-1,
buffer,
*size,
NULL,
NULL);
if (bufsize == 0) {
r = uv_translate_sys_error(GetLastError());
goto fail;
}
*size = bufsize - 1;
r = 0;
r = uv__copy_utf16_to_utf8(var, len, buffer, size);
fail:
@@ -1493,12 +1321,12 @@ int uv_os_setenv(const char* name, const char* value) {
if (name == NULL || value == NULL)
return UV_EINVAL;
r = uv__convert_utf8_to_utf16(name, -1, &name_w);
r = uv__convert_utf8_to_utf16(name, &name_w);
if (r != 0)
return r;
r = uv__convert_utf8_to_utf16(value, -1, &value_w);
r = uv__convert_utf8_to_utf16(value, &value_w);
if (r != 0) {
uv__free(name_w);
@@ -1523,7 +1351,7 @@ int uv_os_unsetenv(const char* name) {
if (name == NULL)
return UV_EINVAL;
r = uv__convert_utf8_to_utf16(name, -1, &name_w);
r = uv__convert_utf8_to_utf16(name, &name_w);
if (r != 0)
return r;
@@ -1540,9 +1368,6 @@ int uv_os_unsetenv(const char* name) {
int uv_os_gethostname(char* buffer, size_t* size) {
WCHAR buf[UV_MAXHOSTNAMESIZE];
size_t len;
char* utf8_str;
int convert_result;
if (buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL;
@@ -1555,22 +1380,7 @@ int uv_os_gethostname(char* buffer, size_t* size) {
if (pGetHostNameW(buf, UV_MAXHOSTNAMESIZE) != 0)
return uv_translate_sys_error(WSAGetLastError());
convert_result = uv__convert_utf16_to_utf8(buf, -1, &utf8_str);
if (convert_result != 0)
return convert_result;
len = strlen(utf8_str);
if (len >= *size) {
*size = len + 1;
uv__free(utf8_str);
return UV_ENOBUFS;
}
memcpy(buffer, utf8_str, len + 1);
uv__free(utf8_str);
*size = len;
return 0;
return uv__copy_utf16_to_utf8(buf, -1, buffer, size);
}
@@ -1676,7 +1486,7 @@ int uv_os_uname(uv_utsname_t* buffer) {
HKEY registry_key;
WCHAR product_name_w[256];
DWORD product_name_w_size;
int version_size;
size_t version_size;
int processor_level;
int r;
@@ -1707,7 +1517,7 @@ int uv_os_uname(uv_utsname_t* buffer) {
r = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0,
KEY_QUERY_VALUE,
KEY_QUERY_VALUE | KEY_WOW64_64KEY,
&registry_key);
if (r == ERROR_SUCCESS) {
@@ -1738,37 +1548,29 @@ int uv_os_uname(uv_utsname_t* buffer) {
}
}
version_size = WideCharToMultiByte(CP_UTF8,
0,
product_name_w,
-1,
buffer->version,
sizeof(buffer->version),
NULL,
NULL);
if (version_size == 0) {
r = uv_translate_sys_error(GetLastError());
version_size = sizeof(buffer->version);
r = uv__copy_utf16_to_utf8(product_name_w,
-1,
buffer->version,
&version_size);
if (r)
goto error;
}
}
}
/* Append service pack information to the version if present. */
if (os_info.szCSDVersion[0] != L'\0') {
if (version_size > 0)
buffer->version[version_size - 1] = ' ';
buffer->version[version_size++] = ' ';
if (WideCharToMultiByte(CP_UTF8,
0,
os_info.szCSDVersion,
-1,
buffer->version + version_size,
sizeof(buffer->version) - version_size,
NULL,
NULL) == 0) {
r = uv_translate_sys_error(GetLastError());
version_size = sizeof(buffer->version) - version_size;
r = uv__copy_utf16_to_utf8(os_info.szCSDVersion,
-1,
buffer->version +
sizeof(buffer->version) - version_size,
&version_size);
if (r)
goto error;
}
}
/* Populate the sysname field. */