diff options
author | cjihrig <cjihrig@gmail.com> | 2017-10-02 19:44:44 -0400 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-10-05 12:08:33 -0700 |
commit | fca6c5839a6154275913656dfedb3242959031e3 (patch) | |
tree | e1fed70c4929b71306e6a18a92bf5501245a286c /deps/uv/src | |
parent | b9a55a93c91fb7fd7ac81e182f843f28014179ca (diff) | |
download | android-node-v8-fca6c5839a6154275913656dfedb3242959031e3.tar.gz android-node-v8-fca6c5839a6154275913656dfedb3242959031e3.tar.bz2 android-node-v8-fca6c5839a6154275913656dfedb3242959031e3.zip |
deps: upgrade libuv to 1.15.0
PR-URL: https://github.com/nodejs/node/pull/15745
Refs: https://github.com/nodejs/node/pull/15380
Refs: https://github.com/nodejs/node/issues/15683
Fixes: https://github.com/nodejs/node/issues/15394
Fixes: https://github.com/nodejs/node/issues/15770
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'deps/uv/src')
-rw-r--r-- | deps/uv/src/unix/android-ifaddrs.c | 8 | ||||
-rw-r--r-- | deps/uv/src/unix/bsd-ifaddrs.c | 6 | ||||
-rw-r--r-- | deps/uv/src/unix/core.c | 14 | ||||
-rw-r--r-- | deps/uv/src/unix/fs.c | 13 | ||||
-rw-r--r-- | deps/uv/src/unix/fsevents.c | 28 | ||||
-rw-r--r-- | deps/uv/src/unix/internal.h | 3 | ||||
-rw-r--r-- | deps/uv/src/unix/kqueue.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/netbsd.c | 24 | ||||
-rw-r--r-- | deps/uv/src/unix/os390-syscalls.c | 93 | ||||
-rw-r--r-- | deps/uv/src/unix/os390-syscalls.h | 1 | ||||
-rw-r--r-- | deps/uv/src/unix/os390.c | 3 | ||||
-rw-r--r-- | deps/uv/src/unix/stream.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/sunos.c | 1 | ||||
-rw-r--r-- | deps/uv/src/unix/thread.c | 75 | ||||
-rw-r--r-- | deps/uv/src/unix/tty.c | 36 | ||||
-rw-r--r-- | deps/uv/src/unix/udp.c | 8 | ||||
-rw-r--r-- | deps/uv/src/win/error.c | 2 | ||||
-rw-r--r-- | deps/uv/src/win/process.c | 7 | ||||
-rw-r--r-- | deps/uv/src/win/signal.c | 2 | ||||
-rw-r--r-- | deps/uv/src/win/thread.c | 5 | ||||
-rw-r--r-- | deps/uv/src/win/timer.c | 2 | ||||
-rw-r--r-- | deps/uv/src/win/tty.c | 117 | ||||
-rw-r--r-- | deps/uv/src/win/util.c | 4 |
23 files changed, 355 insertions, 101 deletions
diff --git a/deps/uv/src/unix/android-ifaddrs.c b/deps/uv/src/unix/android-ifaddrs.c index 1a842ced48..bf30b14179 100644 --- a/deps/uv/src/unix/android-ifaddrs.c +++ b/deps/uv/src/unix/android-ifaddrs.c @@ -457,7 +457,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList, char *l_name; char *l_addr; - for(l_rta = IFLA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) + for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) { size_t l_rtaDataSize = RTA_PAYLOAD(l_rta); if(l_info->ifa_family == AF_PACKET) @@ -479,7 +479,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList, l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize)); break; case IFA_LABEL: - l_nameSize += NLMSG_ALIGN(l_rtaSize + 1); + l_nameSize += NLMSG_ALIGN(l_rtaDataSize + 1); break; default: break; @@ -504,7 +504,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList, } l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg)); - for(l_rta = IFLA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) + for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) { void *l_rtaData = RTA_DATA(l_rta); size_t l_rtaDataSize = RTA_PAYLOAD(l_rta); @@ -567,7 +567,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList, { unsigned l_maxPrefix = (l_entry->ifa_addr->sa_family == AF_INET ? 32 : 128); unsigned l_prefix = (l_info->ifa_prefixlen > l_maxPrefix ? l_maxPrefix : l_info->ifa_prefixlen); - char l_mask[16] = {0}; + unsigned char l_mask[16] = {0}; unsigned i; for(i=0; i<(l_prefix/8); ++i) { diff --git a/deps/uv/src/unix/bsd-ifaddrs.c b/deps/uv/src/unix/bsd-ifaddrs.c index ffcf156440..2593b9ff33 100644 --- a/deps/uv/src/unix/bsd-ifaddrs.c +++ b/deps/uv/src/unix/bsd-ifaddrs.c @@ -50,7 +50,11 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) { */ if (ent->ifa_addr->sa_family == AF_LINK) return 1; -#elif defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) + if (ent->ifa_addr->sa_family != PF_INET && + ent->ifa_addr->sa_family != PF_INET6) + return 1; +#elif defined(__OpenBSD__) if (ent->ifa_addr->sa_family != PF_INET) return 1; #endif diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c index bee641cb44..ef82ee27b8 100644 --- a/deps/uv/src/unix/core.c +++ b/deps/uv/src/unix/core.c @@ -58,13 +58,19 @@ #if defined(__DragonFly__) || \ defined(__FreeBSD__) || \ - defined(__FreeBSD_kernel__) + defined(__FreeBSD_kernel__) || \ + defined(__NetBSD__) # include <sys/sysctl.h> # include <sys/filio.h> # include <sys/wait.h> # define UV__O_CLOEXEC O_CLOEXEC # if defined(__FreeBSD__) && __FreeBSD__ >= 10 # define uv__accept4 accept4 +# endif +# if defined(__NetBSD__) +# define uv__accept4(a, b, c, d) paccept((a), (b), (c), NULL, (d)) +# endif +# if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__) # define UV__SOCK_NONBLOCK SOCK_NONBLOCK # define UV__SOCK_CLOEXEC SOCK_CLOEXEC # endif @@ -462,7 +468,9 @@ int uv__accept(int sockfd) { assert(sockfd >= 0); while (1) { -#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD__ >= 10) +#if defined(__linux__) || \ + (defined(__FreeBSD__) && __FreeBSD__ >= 10) || \ + defined(__NetBSD__) static int no_accept4; if (no_accept4) @@ -988,7 +996,7 @@ int uv__open_cloexec(const char* path, int flags) { int uv__dup2_cloexec(int oldfd, int newfd) { int r; -#if defined(__FreeBSD__) && __FreeBSD__ >= 10 +#if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__) r = dup3(oldfd, newfd, O_CLOEXEC); if (r == -1) return -errno; diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c index 5a172cc780..2684c814a2 100644 --- a/deps/uv/src/unix/fs.c +++ b/deps/uv/src/unix/fs.c @@ -438,7 +438,12 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) { return -1; } +#if defined(__MVS__) + len = os390_readlink(req->path, buf, len); +#else len = readlink(req->path, buf, len); +#endif + if (len == -1) { uv__free(buf); @@ -795,6 +800,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { int64_t in_offset; dstfd = -1; + err = 0; /* Open the source file. */ srcfd = uv_fs_open(NULL, &fs_req, req->path, O_RDONLY, 0, NULL); @@ -809,7 +815,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { goto out; } - dst_flags = O_WRONLY | O_CREAT; + dst_flags = O_WRONLY | O_CREAT | O_TRUNC; if (req->flags & UV_FS_COPYFILE_EXCL) dst_flags |= O_EXCL; @@ -828,6 +834,11 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { goto out; } + if (fchmod(dstfd, statsbuf.st_mode) == -1) { + err = -errno; + goto out; + } + bytes_to_send = statsbuf.st_size; in_offset = 0; while (bytes_to_send != 0) { diff --git a/deps/uv/src/unix/fsevents.c b/deps/uv/src/unix/fsevents.c index 643e233cfe..38837406a6 100644 --- a/deps/uv/src/unix/fsevents.c +++ b/deps/uv/src/unix/fsevents.c @@ -230,6 +230,7 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef, uv_loop_t* loop; uv__cf_loop_state_t* state; uv__fsevents_event_t* event; + FSEventStreamEventFlags flags; QUEUE head; loop = info; @@ -245,8 +246,10 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef, /* Process and filter out events */ for (i = 0; i < numEvents; i++) { + flags = eventFlags[i]; + /* Ignore system events */ - if (eventFlags[i] & kFSEventsSystem) + if (flags & kFSEventsSystem) continue; path = paths[i]; @@ -271,6 +274,9 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef, /* Ignore events with path equal to directory itself */ if (len == 0) continue; +#else + if (len == 0 && (flags & kFSEventStreamEventFlagItemIsDir)) + continue; #endif /* MAC_OS_X_VERSION_10_7 */ /* Do not emit events from subdirectories (without option set) */ @@ -291,12 +297,24 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef, memset(event, 0, sizeof(*event)); memcpy(event->path, path, len + 1); + event->events = UV_RENAME; - if ((eventFlags[i] & kFSEventsModified) != 0 && - (eventFlags[i] & kFSEventsRenamed) == 0) +#ifdef MAC_OS_X_VERSION_10_7 + if (0 != (flags & kFSEventsModified) && + 0 == (flags & kFSEventsRenamed)) { + event->events = UV_CHANGE; + } +#else + if (0 != (flags & kFSEventsModified) && + 0 != (flags & kFSEventStreamEventFlagItemIsDir) && + 0 == (flags & kFSEventStreamEventFlagItemRenamed)) { event->events = UV_CHANGE; - else - event->events = UV_RENAME; + } + if (0 == (flags & kFSEventStreamEventFlagItemIsDir) && + 0 == (flags & kFSEventStreamEventFlagItemRenamed)) { + event->events = UV_CHANGE; + } +#endif /* MAC_OS_X_VERSION_10_7 */ QUEUE_INSERT_TAIL(&head, &event->member); } diff --git a/deps/uv/src/unix/internal.h b/deps/uv/src/unix/internal.h index c0898d982e..3df5c4c3eb 100644 --- a/deps/uv/src/unix/internal.h +++ b/deps/uv/src/unix/internal.h @@ -175,7 +175,8 @@ struct uv__stream_queued_fds_s { defined(__FreeBSD__) || \ defined(__FreeBSD_kernel__) || \ defined(__linux__) || \ - defined(__OpenBSD__) + defined(__OpenBSD__) || \ + defined(__NetBSD__) #define uv__cloexec uv__cloexec_ioctl #define uv__nonblock uv__nonblock_ioctl #else diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c index 300bac07c3..c9adddbdb8 100644 --- a/deps/uv/src/unix/kqueue.c +++ b/deps/uv/src/unix/kqueue.c @@ -59,7 +59,9 @@ int uv__kqueue_init(uv_loop_t* loop) { } +#if defined(__APPLE__) static int uv__has_forked_with_cfrunloop; +#endif int uv__io_fork(uv_loop_t* loop) { int err; diff --git a/deps/uv/src/unix/netbsd.c b/deps/uv/src/unix/netbsd.c index c54c04df28..d9066349c1 100644 --- a/deps/uv/src/unix/netbsd.c +++ b/deps/uv/src/unix/netbsd.c @@ -66,22 +66,32 @@ void uv_loadavg(double avg[3]) { int uv_exepath(char* buffer, size_t* size) { + /* Intermediate buffer, retrieving partial path name does not work + * As of NetBSD-8(beta), vnode->path translator does not handle files + * with longer names than 31 characters. + */ + char int_buf[PATH_MAX]; + size_t int_size; int mib[4]; - size_t cb; - pid_t mypid; if (buffer == NULL || size == NULL || *size == 0) return -EINVAL; - mypid = getpid(); mib[0] = CTL_KERN; mib[1] = KERN_PROC_ARGS; - mib[2] = mypid; - mib[3] = KERN_PROC_ARGV; + mib[2] = -1; + mib[3] = KERN_PROC_PATHNAME; + int_size = ARRAY_SIZE(int_buf); - cb = *size; - if (sysctl(mib, 4, buffer, &cb, NULL, 0)) + if (sysctl(mib, 4, int_buf, &int_size, NULL, 0)) return -errno; + + /* Copy string from the intermediate buffer to outer one with appropriate + * length. + */ + strlcpy(buffer, int_buf, *size); + + /* Set new size. */ *size = strlen(buffer); return 0; diff --git a/deps/uv/src/unix/os390-syscalls.c b/deps/uv/src/unix/os390-syscalls.c index 08623f4eaf..ca539c26f7 100644 --- a/deps/uv/src/unix/os390-syscalls.c +++ b/deps/uv/src/unix/os390-syscalls.c @@ -130,17 +130,17 @@ static void epoll_init(void) { uv__os390_epoll* epoll_create1(int flags) { uv__os390_epoll* lst; - uv_once(&once, epoll_init); - uv_mutex_lock(&global_epoll_lock); lst = uv__malloc(sizeof(*lst)); - if (lst == -1) - return NULL; - QUEUE_INSERT_TAIL(&global_epoll_queue, &lst->member); - uv_mutex_unlock(&global_epoll_lock); + if (lst != NULL) { + /* initialize list */ + lst->size = 0; + lst->items = NULL; + uv_once(&once, epoll_init); + uv_mutex_lock(&global_epoll_lock); + QUEUE_INSERT_TAIL(&global_epoll_queue, &lst->member); + uv_mutex_unlock(&global_epoll_lock); + } - /* initialize list */ - lst->size = 0; - lst->items = NULL; return lst; } @@ -149,8 +149,11 @@ int epoll_ctl(uv__os390_epoll* lst, int op, int fd, struct epoll_event *event) { + uv_mutex_lock(&global_epoll_lock); + if(op == EPOLL_CTL_DEL) { if (fd >= lst->size || lst->items[fd].fd == -1) { + uv_mutex_unlock(&global_epoll_lock); errno = ENOENT; return -1; } @@ -158,6 +161,7 @@ int epoll_ctl(uv__os390_epoll* lst, } else if(op == EPOLL_CTL_ADD) { maybe_resize(lst, fd + 1); if (lst->items[fd].fd != -1) { + uv_mutex_unlock(&global_epoll_lock); errno = EEXIST; return -1; } @@ -165,6 +169,7 @@ int epoll_ctl(uv__os390_epoll* lst, lst->items[fd].events = event->events; } else if(op == EPOLL_CTL_MOD) { if (fd >= lst->size || lst->items[fd].fd == -1) { + uv_mutex_unlock(&global_epoll_lock); errno = ENOENT; return -1; } @@ -172,6 +177,7 @@ int epoll_ctl(uv__os390_epoll* lst, } else abort(); + uv_mutex_unlock(&global_epoll_lock); return 0; } @@ -321,3 +327,72 @@ char* mkdtemp(char* path) { return path; } + + +ssize_t os390_readlink(const char* path, char* buf, size_t len) { + ssize_t rlen; + ssize_t vlen; + ssize_t plen; + char* delimiter; + char old_delim; + char* tmpbuf; + char realpathstr[PATH_MAX + 1]; + + tmpbuf = uv__malloc(len + 1); + if (tmpbuf == NULL) { + errno = ENOMEM; + return -1; + } + + rlen = readlink(path, tmpbuf, len); + if (rlen < 0) { + uv__free(tmpbuf); + return rlen; + } + + if (rlen < 3 || strncmp("/$", tmpbuf, 2) != 0) { + /* Straightforward readlink. */ + memcpy(buf, tmpbuf, rlen); + uv__free(tmpbuf); + return rlen; + } + + /* + * There is a parmlib variable at the beginning + * which needs interpretation. + */ + tmpbuf[rlen] = '\0'; + delimiter = strchr(tmpbuf + 2, '/'); + if (delimiter == NULL) + /* No slash at the end */ + delimiter = strchr(tmpbuf + 2, '\0'); + + /* Read real path of the variable. */ + old_delim = *delimiter; + *delimiter = '\0'; + if (realpath(tmpbuf, realpathstr) == NULL) { + uv__free(tmpbuf); + return -1; + } + + /* realpathstr is not guaranteed to end with null byte.*/ + realpathstr[PATH_MAX] = '\0'; + + /* Reset the delimiter and fill up the buffer. */ + *delimiter = old_delim; + plen = strlen(delimiter); + vlen = strlen(realpathstr); + rlen = plen + vlen; + if (rlen > len) { + uv__free(tmpbuf); + errno = ENAMETOOLONG; + return -1; + } + memcpy(buf, realpathstr, vlen); + memcpy(buf + vlen, delimiter, plen); + + /* Done using temporary buffer. */ + uv__free(tmpbuf); + + return rlen; +} diff --git a/deps/uv/src/unix/os390-syscalls.h b/deps/uv/src/unix/os390-syscalls.h index 61a7cee839..7aba3d27da 100644 --- a/deps/uv/src/unix/os390-syscalls.h +++ b/deps/uv/src/unix/os390-syscalls.h @@ -65,5 +65,6 @@ int scandir(const char* maindir, struct dirent*** namelist, int (*compar)(const struct dirent **, const struct dirent **)); char *mkdtemp(char* path); +ssize_t os390_readlink(const char* path, char* buf, size_t len); #endif /* UV_OS390_SYSCALL_H_ */ diff --git a/deps/uv/src/unix/os390.c b/deps/uv/src/unix/os390.c index 559970de2c..127656db87 100644 --- a/deps/uv/src/unix/os390.c +++ b/deps/uv/src/unix/os390.c @@ -117,7 +117,7 @@ void uv_loadavg(double avg[3]) { int uv__platform_loop_init(uv_loop_t* loop) { uv__os390_epoll* ep; - ep = epoll_create1(UV__EPOLL_CLOEXEC); + ep = epoll_create1(0); loop->ep = ep; if (ep == NULL) return -errno; @@ -386,7 +386,6 @@ int uv_uptime(double* uptime) { int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { uv_cpu_info_t* cpu_info; - int result; int idx; siv1v2 info; data_area_ptr cvt = {0}; diff --git a/deps/uv/src/unix/stream.c b/deps/uv/src/unix/stream.c index c502098dcf..672a7e2d6c 100644 --- a/deps/uv/src/unix/stream.c +++ b/deps/uv/src/unix/stream.c @@ -859,7 +859,7 @@ start: } if (n < 0) { - if (errno != EAGAIN && errno != EWOULDBLOCK) { + if (errno != EAGAIN && errno != EWOULDBLOCK && errno != ENOBUFS) { err = -errno; goto error; } else if (stream->flags & UV_STREAM_BLOCKING) { diff --git a/deps/uv/src/unix/sunos.c b/deps/uv/src/unix/sunos.c index 49de5a7fcd..a72c26a01f 100644 --- a/deps/uv/src/unix/sunos.c +++ b/deps/uv/src/unix/sunos.c @@ -757,7 +757,6 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { uv_interface_address_t* address; struct ifaddrs* addrs; struct ifaddrs* ent; - int i; if (getifaddrs(&addrs)) return -errno; diff --git a/deps/uv/src/unix/thread.c b/deps/uv/src/unix/thread.c index f884622591..abaca295d2 100644 --- a/deps/uv/src/unix/thread.c +++ b/deps/uv/src/unix/thread.c @@ -145,36 +145,55 @@ int pthread_barrier_destroy(pthread_barrier_t* barrier) { #endif -int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { - int err; - pthread_attr_t* attr; -#if defined(__APPLE__) - pthread_attr_t attr_storage; +/* On MacOS, threads other than the main thread are created with a reduced + * stack size by default. Adjust to RLIMIT_STACK aligned to the page size. + * + * On Linux, threads created by musl have a much smaller stack than threads + * created by glibc (80 vs. 2048 or 4096 kB.) Follow glibc for consistency. + */ +static size_t thread_stack_size(void) { +#if defined(__APPLE__) || defined(__linux__) struct rlimit lim; -#endif - /* On OSX threads other than the main thread are created with a reduced stack - * size by default, adjust it to RLIMIT_STACK. - */ -#if defined(__APPLE__) if (getrlimit(RLIMIT_STACK, &lim)) abort(); - attr = &attr_storage; - if (pthread_attr_init(attr)) - abort(); - if (lim.rlim_cur != RLIM_INFINITY) { /* pthread_attr_setstacksize() expects page-aligned values. */ lim.rlim_cur -= lim.rlim_cur % (rlim_t) getpagesize(); - if (lim.rlim_cur >= PTHREAD_STACK_MIN) - if (pthread_attr_setstacksize(attr, lim.rlim_cur)) - abort(); + return lim.rlim_cur; } +#endif + +#if !defined(__linux__) + return 0; +#elif defined(__PPC__) || defined(__ppc__) || defined(__powerpc__) + return 4 << 20; /* glibc default. */ #else - attr = NULL; + return 2 << 20; /* glibc default. */ #endif +} + + +int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { + int err; + size_t stack_size; + pthread_attr_t* attr; + pthread_attr_t attr_storage; + + attr = NULL; + stack_size = thread_stack_size(); + + if (stack_size > 0) { + attr = &attr_storage; + + if (pthread_attr_init(attr)) + abort(); + + if (pthread_attr_setstacksize(attr, stack_size)) + abort(); + } err = pthread_create(tid, attr, (void*(*)(void*)) entry, arg); @@ -222,6 +241,25 @@ int uv_mutex_init(uv_mutex_t* mutex) { } +int uv_mutex_init_recursive(uv_mutex_t* mutex) { + pthread_mutexattr_t attr; + int err; + + if (pthread_mutexattr_init(&attr)) + abort(); + + if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) + abort(); + + err = pthread_mutex_init(mutex, &attr); + + if (pthread_mutexattr_destroy(&attr)) + abort(); + + return -err; +} + + void uv_mutex_destroy(uv_mutex_t* mutex) { if (pthread_mutex_destroy(mutex)) abort(); @@ -385,7 +423,6 @@ int uv_sem_trywait(uv_sem_t* sem) { int uv_sem_init(uv_sem_t* sem, unsigned int value) { uv_sem_t semid; - struct sembuf buf; int err; union { int val; diff --git a/deps/uv/src/unix/tty.c b/deps/uv/src/unix/tty.c index b2d37f4c2c..357f9748f6 100644 --- a/deps/uv/src/unix/tty.c +++ b/deps/uv/src/unix/tty.c @@ -48,6 +48,42 @@ static int uv__tty_is_slave(const int fd) { char dummy[256]; result = ioctl(fd, TIOCPTYGNAME, &dummy) != 0; +#elif defined(__NetBSD__) + /* + * NetBSD as an extension returns with ptsname(3) and ptsname_r(3) the slave + * device name for both descriptors, the master one and slave one. + * + * Implement function to compare major device number with pts devices. + * + * The major numbers are machine-dependent, on NetBSD/amd64 they are + * respectively: + * - master tty: ptc - major 6 + * - slave tty: pts - major 5 + */ + + struct stat sb; + /* Lookup device's major for the pts driver and cache it. */ + static devmajor_t pts = NODEVMAJOR; + + if (pts == NODEVMAJOR) { + pts = getdevmajor("pts", S_IFCHR); + if (pts == NODEVMAJOR) + abort(); + } + + /* Lookup stat structure behind the file descriptor. */ + if (fstat(fd, &sb) != 0) + abort(); + + /* Assert character device. */ + if (!S_ISCHR(sb.st_mode)) + abort(); + + /* Assert valid major. */ + if (major(sb.st_rdev) == NODEVMAJOR) + abort(); + + result = (pts == major(sb.st_rdev)); #else /* Fallback to ptsname */ diff --git a/deps/uv/src/unix/udp.c b/deps/uv/src/unix/udp.c index c556325de0..a475bf5741 100644 --- a/deps/uv/src/unix/udp.c +++ b/deps/uv/src/unix/udp.c @@ -237,8 +237,10 @@ static void uv__udp_sendmsg(uv_udp_t* handle) { size = sendmsg(handle->io_watcher.fd, &h, 0); } while (size == -1 && errno == EINTR); - if (size == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) - break; + if (size == -1) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS) + break; + } req->status = (size == -1 ? -errno : size); @@ -472,7 +474,7 @@ int uv__udp_try_send(uv_udp_t* handle, } while (size == -1 && errno == EINTR); if (size == -1) { - if (errno == EAGAIN || errno == EWOULDBLOCK) + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS) return -EAGAIN; else return -errno; diff --git a/deps/uv/src/win/error.c b/deps/uv/src/win/error.c index 642d1112e1..9b03bfef6b 100644 --- a/deps/uv/src/win/error.c +++ b/deps/uv/src/win/error.c @@ -58,7 +58,7 @@ void uv_fatal_error(const int errorno, const char* syscall) { LocalFree(buf); } - *((char*)NULL) = 0xff; /* Force debug break */ + DebugBreak(); abort(); } diff --git a/deps/uv/src/win/process.c b/deps/uv/src/win/process.c index 97b67ca529..764250e138 100644 --- a/deps/uv/src/win/process.c +++ b/deps/uv/src/win/process.c @@ -1058,15 +1058,18 @@ int uv_spawn(uv_loop_t* loop, startup.hStdOutput = uv__stdio_handle(process->child_stdio_buffer, 1); startup.hStdError = uv__stdio_handle(process->child_stdio_buffer, 2); + process_flags = CREATE_UNICODE_ENVIRONMENT; + if (options->flags & UV_PROCESS_WINDOWS_HIDE) { /* Use SW_HIDE to avoid any potential process window. */ startup.wShowWindow = SW_HIDE; + + /* Hide console windows. */ + process_flags |= CREATE_NO_WINDOW; } else { startup.wShowWindow = SW_SHOWDEFAULT; } - process_flags = CREATE_UNICODE_ENVIRONMENT; - if (options->flags & UV_PROCESS_DETACHED) { /* Note that we're not setting the CREATE_BREAKAWAY_FROM_JOB flag. That * means that libuv might not let you create a fully daemonized process diff --git a/deps/uv/src/win/signal.c b/deps/uv/src/win/signal.c index 7b42dd9928..a174da1f76 100644 --- a/deps/uv/src/win/signal.c +++ b/deps/uv/src/win/signal.c @@ -64,7 +64,7 @@ static int uv__signal_compare(uv_signal_t* w1, uv_signal_t* w2) { } -RB_GENERATE_STATIC(uv_signal_tree_s, uv_signal_s, tree_entry, uv__signal_compare); +RB_GENERATE_STATIC(uv_signal_tree_s, uv_signal_s, tree_entry, uv__signal_compare) /* diff --git a/deps/uv/src/win/thread.c b/deps/uv/src/win/thread.c index 91684e9387..30b2d7793c 100644 --- a/deps/uv/src/win/thread.c +++ b/deps/uv/src/win/thread.c @@ -198,6 +198,11 @@ int uv_mutex_init(uv_mutex_t* mutex) { } +int uv_mutex_init_recursive(uv_mutex_t* mutex) { + return uv_mutex_init(mutex); +} + + void uv_mutex_destroy(uv_mutex_t* mutex) { DeleteCriticalSection(mutex); } diff --git a/deps/uv/src/win/timer.c b/deps/uv/src/win/timer.c index 27ca7716af..7e006fedfa 100644 --- a/deps/uv/src/win/timer.c +++ b/deps/uv/src/win/timer.c @@ -56,7 +56,7 @@ static int uv_timer_compare(uv_timer_t* a, uv_timer_t* b) { } -RB_GENERATE_STATIC(uv_timer_tree_s, uv_timer_s, tree_entry, uv_timer_compare); +RB_GENERATE_STATIC(uv_timer_tree_s, uv_timer_s, tree_entry, uv_timer_compare) int uv_timer_init(uv_loop_t* loop, uv_timer_t* handle) { diff --git a/deps/uv/src/win/tty.c b/deps/uv/src/win/tty.c index c4f99bdc79..4cd1c72129 100644 --- a/deps/uv/src/win/tty.c +++ b/deps/uv/src/win/tty.c @@ -112,14 +112,30 @@ static int uv_tty_virtual_offset = -1; static int uv_tty_virtual_height = -1; static int uv_tty_virtual_width = -1; +/* The console window size + * We keep this separate from uv_tty_virtual_*. We use those values to only + * handle signalling SIGWINCH + */ + +static HANDLE uv__tty_console_handle = INVALID_HANDLE_VALUE; +static int uv__tty_console_height = -1; +static int uv__tty_console_width = -1; + +static DWORD WINAPI uv__tty_console_resize_message_loop_thread(void* param); +static void CALLBACK uv__tty_console_resize_event(HWINEVENTHOOK hWinEventHook, + DWORD event, + HWND hwnd, + LONG idObject, + LONG idChild, + DWORD dwEventThread, + DWORD dwmsEventTime); + /* We use a semaphore rather than a mutex or critical section because in some cases (uv__cancel_read_console) we need take the lock in the main thread and release it in another thread. Using a semaphore ensures that in such scenario the main thread will still block when trying to acquire the lock. */ static uv_sem_t uv_tty_output_lock; -static HANDLE uv_tty_output_handle = INVALID_HANDLE_VALUE; - static WORD uv_tty_default_text_attributes = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; @@ -141,6 +157,18 @@ static void uv__determine_vterm_state(HANDLE handle); void uv_console_init(void) { if (uv_sem_init(&uv_tty_output_lock, 1)) abort(); + uv__tty_console_handle = CreateFileW(L"CONOUT$", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_WRITE, + 0, + OPEN_EXISTING, + 0, + 0); + if (uv__tty_console_handle != NULL) { + QueueUserWorkItem(uv__tty_console_resize_message_loop_thread, + NULL, + WT_EXECUTELONGFUNCTION); + } } @@ -184,11 +212,6 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) { if (uv__vterm_state == UV_UNCHECKED) uv__determine_vterm_state(handle); - /* Store the global tty output handle. This handle is used by TTY read */ - /* streams to update the virtual window when a CONSOLE_BUFFER_SIZE_EVENT */ - /* is received. */ - uv_tty_output_handle = handle; - /* Remember the original console text attributes. */ uv_tty_capture_initial_style(&screen_buffer_info); @@ -705,25 +728,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle, } records_left--; - /* If the window was resized, recompute the virtual window size. This */ - /* will trigger a SIGWINCH signal if the window size changed in an */ - /* way that matters to libuv. */ - if (handle->tty.rd.last_input_record.EventType == WINDOW_BUFFER_SIZE_EVENT) { - CONSOLE_SCREEN_BUFFER_INFO info; - - uv_sem_wait(&uv_tty_output_lock); - - if (uv_tty_output_handle != INVALID_HANDLE_VALUE && - GetConsoleScreenBufferInfo(uv_tty_output_handle, &info)) { - uv_tty_update_virtual_window(&info); - } - - uv_sem_post(&uv_tty_output_lock); - - continue; - } - - /* Ignore other events that are not key or resize events. */ + /* Ignore other events that are not key events. */ if (handle->tty.rd.last_input_record.EventType != KEY_EVENT) { continue; } @@ -1103,9 +1108,6 @@ static int uv__cancel_read_console(uv_tty_t* handle) { static void uv_tty_update_virtual_window(CONSOLE_SCREEN_BUFFER_INFO* info) { - int old_virtual_width = uv_tty_virtual_width; - int old_virtual_height = uv_tty_virtual_height; - uv_tty_virtual_width = info->dwSize.X; uv_tty_virtual_height = info->srWindow.Bottom - info->srWindow.Top + 1; @@ -1125,14 +1127,6 @@ static void uv_tty_update_virtual_window(CONSOLE_SCREEN_BUFFER_INFO* info) { if (uv_tty_virtual_offset < 0) { uv_tty_virtual_offset = 0; } - - /* If the virtual window size changed, emit a SIGWINCH signal. Don't emit */ - /* if this was the first time the virtual window size was computed. */ - if (old_virtual_width != -1 && old_virtual_height != -1 && - (uv_tty_virtual_width != old_virtual_width || - uv_tty_virtual_height != old_virtual_height)) { - uv__signal_dispatch(SIGWINCH); - } } @@ -2280,3 +2274,52 @@ static void uv__determine_vterm_state(HANDLE handle) { uv__vterm_state = UV_SUPPORTED; } + +static DWORD WINAPI uv__tty_console_resize_message_loop_thread(void* param) { + CONSOLE_SCREEN_BUFFER_INFO sb_info; + MSG msg; + + if (!GetConsoleScreenBufferInfo(uv__tty_console_handle, &sb_info)) + return 0; + + uv__tty_console_width = sb_info.dwSize.X; + uv__tty_console_height = sb_info.srWindow.Bottom - sb_info.srWindow.Top + 1; + + if (!SetWinEventHook(EVENT_CONSOLE_LAYOUT, + EVENT_CONSOLE_LAYOUT, + NULL, + uv__tty_console_resize_event, + 0, + 0, + WINEVENT_OUTOFCONTEXT)) + return 0; + + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + return 0; +} + +static void CALLBACK uv__tty_console_resize_event(HWINEVENTHOOK hWinEventHook, + DWORD event, + HWND hwnd, + LONG idObject, + LONG idChild, + DWORD dwEventThread, + DWORD dwmsEventTime) { + CONSOLE_SCREEN_BUFFER_INFO sb_info; + int width, height; + + if (!GetConsoleScreenBufferInfo(uv__tty_console_handle, &sb_info)) + return; + + width = sb_info.dwSize.X; + height = sb_info.srWindow.Bottom - sb_info.srWindow.Top + 1; + + if (width != uv__tty_console_width || height != uv__tty_console_height) { + uv__tty_console_width = width; + uv__tty_console_height = height; + uv__signal_dispatch(SIGWINCH); + } +} diff --git a/deps/uv/src/win/util.c b/deps/uv/src/win/util.c index d2e7f772ce..a2acda1152 100644 --- a/deps/uv/src/win/util.c +++ b/deps/uv/src/win/util.c @@ -1388,7 +1388,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) { if (OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token) == 0) return uv_translate_sys_error(GetLastError()); - bufsize = sizeof(path); + bufsize = ARRAY_SIZE(path); if (!GetUserProfileDirectoryW(token, path, &bufsize)) { r = GetLastError(); CloseHandle(token); @@ -1403,7 +1403,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) { CloseHandle(token); /* Get the username using GetUserNameW() */ - bufsize = sizeof(username); + bufsize = ARRAY_SIZE(username); if (!GetUserNameW(username, &bufsize)) { r = GetLastError(); |