Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/v1.x' into v1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Feb 11, 2025
2 parents 6b2a1ae + 7894072 commit 969bffb
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2

sphinx:
builder: html
configuration: null
configuration: docs/src/conf.py
fail_on_warning: false

build:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ libuv can be downloaded from `here <https://dist.libuv.org/dist/>`_.
Installation
------------

Installation instructions can be found in `the README <https://github.com/libuv/libuv/blob/master/README.md>`_.
Installation instructions can be found in the `README <https://github.com/libuv/libuv/blob/master/README.md>`_.

4 changes: 4 additions & 0 deletions docs/src/threading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ Threads
a thread name can be: Linux, IBM i (16), macOS (64), Windows (32767), and NetBSD (32), etc. `uv_thread_setname()`
will truncate it in case `name` is larger than the limit of the platform.
Not supported on Windows Server 2016, returns `UV_ENOSYS`.
.. versionadded:: 1.50.0
.. c:function:: int uv_thread_getname(uv_thread_t* tid, char* name, size_t* size)
Expand All @@ -155,6 +157,8 @@ Threads
The buffer should be large enough to hold the name of the thread plus the trailing NUL, or it will be truncated to fit
with the trailing NUL.
Not supported on Windows Server 2016, returns `UV_ENOSYS`.
.. versionadded:: 1.50.0
.. c:function:: int uv_thread_setpriority(uv_thread_t tid, int priority)
Expand Down
2 changes: 1 addition & 1 deletion src/unix/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static int uv__async_start(uv_loop_t* loop) {
* thus we create one for that, but this fd will not be actually used,
* it's just a placeholder and magic number which is going to be closed
* during the cleanup, as other FDs. */
err = uv__open_cloexec("/dev/null", O_RDONLY);
err = uv__open_cloexec("/", O_RDONLY);
if (err < 0)
return err;

Expand Down
17 changes: 7 additions & 10 deletions src/unix/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,7 @@ static ssize_t uv__pwritev_emul(int fd,

/* The function pointer cache is an uintptr_t because _Atomic void*
* doesn't work on macos/ios/etc...
* Disable optimization on armv7 to work around the bug described in
* https://github.com/libuv/libuv/issues/4532
*/
#if defined(__arm__) && (__ARM_ARCH == 7)
__attribute__((optimize("O0")))
#endif
static ssize_t uv__preadv_or_pwritev(int fd,
const struct iovec* bufs,
size_t nbufs,
Expand All @@ -479,18 +474,20 @@ static ssize_t uv__preadv_or_pwritev(int fd,
p = (void*) atomic_load_explicit(cache, memory_order_relaxed);
if (p == NULL) {
#ifdef RTLD_DEFAULT
p = dlsym(RTLD_DEFAULT, is_pread ? "preadv" : "pwritev");
/* Try _LARGEFILE_SOURCE version of preadv/pwritev first,
* then fall back to the plain version, for libcs like musl.
*/
p = dlsym(RTLD_DEFAULT, is_pread ? "preadv64" : "pwritev64");
if (p == NULL)
p = dlsym(RTLD_DEFAULT, is_pread ? "preadv" : "pwritev");
dlerror(); /* Clear errors. */
#endif /* RTLD_DEFAULT */
if (p == NULL)
p = is_pread ? uv__preadv_emul : uv__pwritev_emul;
atomic_store_explicit(cache, (uintptr_t) p, memory_order_relaxed);
}

/* Use memcpy instead of `f = p` to work around a compiler bug,
* see https://github.com/libuv/libuv/issues/4532
*/
memcpy(&f, &p, sizeof(p));
f = p;
return f(fd, bufs, nbufs, off);
}

Expand Down
17 changes: 15 additions & 2 deletions src/unix/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@ void uv__wait_children(uv_loop_t* loop) {
static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
int mask;
int fd;
int ret;
int size;
int i;

mask = UV_IGNORE | UV_CREATE_PIPE | UV_INHERIT_FD | UV_INHERIT_STREAM;
size = 64 * 1024;

switch (container->flags & mask) {
case UV_IGNORE:
Expand All @@ -199,8 +203,17 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
assert(container->data.stream != NULL);
if (container->data.stream->type != UV_NAMED_PIPE)
return UV_EINVAL;
else
return uv_socketpair(SOCK_STREAM, 0, fds, 0, 0);
else {
ret = uv_socketpair(SOCK_STREAM, 0, fds, 0, 0);

if (ret == 0)
for (i = 0; i < 2; i++) {
setsockopt(fds[i], SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
setsockopt(fds[i], SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
}
}

return ret;

case UV_INHERIT_FD:
case UV_INHERIT_STREAM:
Expand Down
14 changes: 12 additions & 2 deletions src/win/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ int uv_spawn(uv_loop_t* loop,
*env = NULL, *cwd = NULL;
STARTUPINFOW startup;
PROCESS_INFORMATION info;
DWORD process_flags;
DWORD process_flags, cwd_len;
BYTE* child_stdio_buffer;

uv__process_init(loop, process);
Expand Down Expand Up @@ -947,9 +947,10 @@ int uv_spawn(uv_loop_t* loop,
if (err)
goto done_uv;

cwd_len = wcslen(cwd);
} else {
/* Inherit cwd */
DWORD cwd_len, r;
DWORD r;

cwd_len = GetCurrentDirectoryW(0, NULL);
if (!cwd_len) {
Expand All @@ -970,6 +971,15 @@ int uv_spawn(uv_loop_t* loop,
}
}

/* If cwd is too long, shorten it */
if (cwd_len >= MAX_PATH) {
cwd_len = GetShortPathNameW(cwd, cwd, cwd_len);
if (cwd_len == 0) {
err = GetLastError();
goto done;
}
}

/* Get PATH environment variable. */
path = find_path(env);
if (path == NULL) {
Expand Down
28 changes: 26 additions & 2 deletions src/win/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ STATIC_ASSERT(sizeof(uv_thread_t) <= sizeof(void*));

static uv_key_t uv__current_thread_key;
static uv_once_t uv__current_thread_init_guard = UV_ONCE_INIT;
static uv_once_t uv__thread_name_once = UV_ONCE_INIT;
HRESULT (WINAPI *pGetThreadDescription)(HANDLE, PWSTR*);
HRESULT (WINAPI *pSetThreadDescription)(HANDLE, PCWSTR);


static void uv__init_current_thread_key(void) {
Expand Down Expand Up @@ -278,12 +281,28 @@ int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2) {
}


static void uv__thread_name_init_once(void) {
HMODULE m;

m = GetModuleHandleA("api-ms-win-core-processthreads-l1-1-3.dll");
if (m != NULL) {
pGetThreadDescription = (void*) GetProcAddress(m, "GetThreadDescription");
pSetThreadDescription = (void*) GetProcAddress(m, "SetThreadDescription");
}
}


int uv_thread_setname(const char* name) {
HRESULT hr;
WCHAR* namew;
int err;
char namebuf[UV_PTHREAD_MAX_NAMELEN_NP];

uv_once(&uv__thread_name_once, uv__thread_name_init_once);

if (pSetThreadDescription == NULL)
return UV_ENOSYS;

if (name == NULL)
return UV_EINVAL;

Expand All @@ -295,7 +314,7 @@ int uv_thread_setname(const char* name) {
if (err)
return err;

hr = SetThreadDescription(GetCurrentThread(), namew);
hr = pSetThreadDescription(GetCurrentThread(), namew);
uv__free(namew);
if (FAILED(hr))
return uv_translate_sys_error(HRESULT_CODE(hr));
Expand All @@ -312,6 +331,11 @@ int uv_thread_getname(uv_thread_t* tid, char* name, size_t size) {
int r;
DWORD exit_code;

uv_once(&uv__thread_name_once, uv__thread_name_init_once);

if (pGetThreadDescription == NULL)
return UV_ENOSYS;

if (name == NULL || size == 0)
return UV_EINVAL;

Expand All @@ -324,7 +348,7 @@ int uv_thread_getname(uv_thread_t* tid, char* name, size_t size) {

namew = NULL;
thread_name = NULL;
hr = GetThreadDescription(*tid, &namew);
hr = pGetThreadDescription(*tid, &namew);
if (FAILED(hr))
return uv_translate_sys_error(HRESULT_CODE(hr));

Expand Down
5 changes: 4 additions & 1 deletion src/win/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ int uv_os_homedir(char* buffer, size_t* size) {


int uv_os_tmpdir(char* buffer, size_t* size) {
int r;
wchar_t *path;
size_t len;

Expand Down Expand Up @@ -1054,7 +1055,9 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
path[len] = L'\0';
}

return uv__copy_utf16_to_utf8(path, len, buffer, size);
r = uv__copy_utf16_to_utf8(path, len, buffer, size);
uv__free(path);
return r;
}


Expand Down
11 changes: 1 addition & 10 deletions src/win/winapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4145,8 +4145,8 @@ typedef struct _FILE_STAT_BASIC_INFORMATION {
ULONG DeviceType;
ULONG DeviceCharacteristics;
ULONG Reserved;
FILE_ID_128 FileId128;
LARGE_INTEGER VolumeSerialNumber;
FILE_ID_128 FileId128;
} FILE_STAT_BASIC_INFORMATION;
#endif

Expand Down Expand Up @@ -4828,13 +4828,4 @@ typedef int (WINAPI *uv_sGetHostNameW)
int);
extern uv_sGetHostNameW pGetHostNameW;

/* processthreadsapi.h */
#if defined(__MINGW32__)
WINBASEAPI
HRESULT WINAPI GetThreadDescription(HANDLE hThread,
PWSTR *ppszThreadDescription);
WINBASEAPI
HRESULT WINAPI SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription);
#endif

#endif /* UV_WIN_WINAPI_H_ */

0 comments on commit 969bffb

Please sign in to comment.