libuv 1.48.0.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4828 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-02-07 23:12:32 +00:00
parent e98802f5b2
commit 6765254f43
53 changed files with 1172 additions and 305 deletions

View File

@ -114,7 +114,7 @@ static int uv__split_path(const WCHAR* filename, WCHAR** dir,
}
}
*file = wcsdup(filename);
*file = _wcsdup(filename);
} else {
if (dir) {
*dir = (WCHAR*)uv__malloc((i + 2) * sizeof(WCHAR));

View File

@ -407,8 +407,8 @@ void fs__open(uv_fs_t* req) {
/* Obtain the active umask. umask() never fails and returns the previous
* umask. */
current_umask = umask(0);
umask(current_umask);
current_umask = _umask(0);
_umask(current_umask);
/* convert flags and mode to CreateFile parameters */
switch (flags & (UV_FS_O_RDONLY | UV_FS_O_WRONLY | UV_FS_O_RDWR)) {

View File

@ -98,6 +98,14 @@ static void eof_timer_destroy(uv_pipe_t* pipe);
static void eof_timer_close_cb(uv_handle_t* handle);
/* Does the file path contain embedded nul bytes? */
static int includes_nul(const char *s, size_t n) {
if (n == 0)
return 0;
return NULL != memchr(s, '\0', n);
}
static void uv__unique_pipe_name(char* ptr, char* name, size_t size) {
snprintf(name, size, "\\\\?\\pipe\\uv\\%p-%lu", ptr, GetCurrentProcessId());
}
@ -191,7 +199,7 @@ static void close_pipe(uv_pipe_t* pipe) {
if (pipe->u.fd == -1)
CloseHandle(pipe->handle);
else
close(pipe->u.fd);
_close(pipe->u.fd);
pipe->u.fd = -1;
pipe->handle = INVALID_HANDLE_VALUE;
@ -705,6 +713,7 @@ int uv_pipe_bind2(uv_pipe_t* handle,
uv_loop_t* loop = handle->loop;
int i, err;
uv_pipe_accept_t* req;
char* name_copy;
if (flags & ~UV_PIPE_NO_TRUNCATE) {
return UV_EINVAL;
@ -718,16 +727,10 @@ int uv_pipe_bind2(uv_pipe_t* handle,
return UV_EINVAL;
}
if (*name == '\0') {
if (includes_nul(name, namelen)) {
return UV_EINVAL;
}
if (flags & UV_PIPE_NO_TRUNCATE) {
if (namelen > 256) {
return UV_EINVAL;
}
}
if (handle->flags & UV_HANDLE_BOUND) {
return UV_EINVAL;
}
@ -736,14 +739,24 @@ int uv_pipe_bind2(uv_pipe_t* handle,
return UV_EINVAL;
}
name_copy = uv__malloc(namelen + 1);
if (name_copy == NULL) {
return UV_ENOMEM;
}
memcpy(name_copy, name, namelen);
name_copy[namelen] = '\0';
if (!(handle->flags & UV_HANDLE_PIPESERVER)) {
handle->pipe.serv.pending_instances = default_pending_pipe_instances;
}
err = UV_ENOMEM;
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)
return UV_ENOMEM;
if (handle->pipe.serv.accept_reqs == NULL) {
goto error;
}
for (i = 0; i < handle->pipe.serv.pending_instances; i++) {
req = &handle->pipe.serv.accept_reqs[i];
@ -753,9 +766,14 @@ int uv_pipe_bind2(uv_pipe_t* handle,
req->next_pending = NULL;
}
err = uv__convert_utf8_to_utf16(name, &handle->name);
if (err)
return err;
/* TODO(bnoordhuis) Add converters that take a |length| parameter. */
err = uv__convert_utf8_to_utf16(name_copy, &handle->name);
uv__free(name_copy);
name_copy = NULL;
if (err) {
goto error;
}
/*
* Attempt to create the first pipe with FILE_FLAG_FIRST_PIPE_INSTANCE.
@ -767,9 +785,11 @@ int uv_pipe_bind2(uv_pipe_t* handle,
TRUE)) {
err = GetLastError();
if (err == ERROR_ACCESS_DENIED) {
err = WSAEADDRINUSE; /* Translates to UV_EADDRINUSE. */
err = UV_EADDRINUSE;
} else if (err == ERROR_PATH_NOT_FOUND || err == ERROR_INVALID_NAME) {
err = WSAEACCES; /* Translates to UV_EACCES. */
err = UV_EACCES;
} else {
err = uv_translate_sys_error(err);
}
goto error;
}
@ -781,10 +801,13 @@ int uv_pipe_bind2(uv_pipe_t* handle,
return 0;
error:
uv__free(handle->pipe.serv.accept_reqs);
uv__free(handle->name);
uv__free(name_copy);
handle->pipe.serv.accept_reqs = NULL;
handle->name = NULL;
return uv_translate_sys_error(err);
return err;
}
@ -834,7 +857,19 @@ void uv_pipe_connect(uv_connect_t* req,
uv_pipe_t* handle,
const char* name,
uv_connect_cb cb) {
uv_pipe_connect2(req, handle, name, strlen(name), 0, cb);
uv_loop_t* loop;
int err;
err = uv_pipe_connect2(req, handle, name, strlen(name), 0, cb);
if (err) {
loop = handle->loop;
/* Make this req pending reporting an error. */
SET_REQ_ERROR(req, err);
uv__insert_pending_req(loop, (uv_req_t*) req);
handle->reqs_pending++;
REGISTER_HANDLE_REQ(loop, handle, req);
}
}
@ -844,11 +879,20 @@ int uv_pipe_connect2(uv_connect_t* req,
size_t namelen,
unsigned int flags,
uv_connect_cb cb) {
uv_loop_t* loop = handle->loop;
uv_loop_t* loop;
int err;
size_t nameSize;
HANDLE pipeHandle = INVALID_HANDLE_VALUE;
DWORD duplex_flags;
char* name_copy;
loop = handle->loop;
UV_REQ_INIT(req, UV_CONNECT);
req->handle = (uv_stream_t*) handle;
req->cb = cb;
req->u.connect.pipeHandle = INVALID_HANDLE_VALUE;
req->u.connect.duplex_flags = 0;
req->u.connect.name = NULL;
if (flags & ~UV_PIPE_NO_TRUNCATE) {
return UV_EINVAL;
@ -862,22 +906,17 @@ int uv_pipe_connect2(uv_connect_t* req,
return UV_EINVAL;
}
if (*name == '\0') {
if (includes_nul(name, namelen)) {
return UV_EINVAL;
}
if (flags & UV_PIPE_NO_TRUNCATE) {
if (namelen > 256) {
return UV_EINVAL;
}
name_copy = uv__malloc(namelen + 1);
if (name_copy == NULL) {
return UV_ENOMEM;
}
UV_REQ_INIT(req, UV_CONNECT);
req->handle = (uv_stream_t*) handle;
req->cb = cb;
req->u.connect.pipeHandle = INVALID_HANDLE_VALUE;
req->u.connect.duplex_flags = 0;
req->u.connect.name = NULL;
memcpy(name_copy, name, namelen);
name_copy[namelen] = '\0';
if (handle->flags & UV_HANDLE_PIPESERVER) {
err = ERROR_INVALID_PARAMETER;
@ -889,7 +928,11 @@ int uv_pipe_connect2(uv_connect_t* req,
}
uv__pipe_connection_init(handle);
err = uv__convert_utf8_to_utf16(name, &handle->name);
/* TODO(bnoordhuis) Add converters that take a |length| parameter. */
err = uv__convert_utf8_to_utf16(name_copy, &handle->name);
uv__free(name_copy);
name_copy = NULL;
if (err) {
err = ERROR_NO_UNICODE_TRANSLATION;
goto error;
@ -935,6 +978,8 @@ int uv_pipe_connect2(uv_connect_t* req,
return 0;
error:
uv__free(name_copy);
if (handle->name) {
uv__free(handle->name);
handle->name = NULL;

View File

@ -26,7 +26,7 @@
#include <signal.h>
#include <limits.h>
#include <wchar.h>
#include <malloc.h> /* alloca */
#include <malloc.h> /* _alloca */
#include "uv.h"
#include "internal.h"
@ -304,8 +304,9 @@ static WCHAR* path_search_walk_ext(const WCHAR *dir,
* - If there's really only a filename, check the current directory for file,
* then search all path directories.
*
* - If filename specified has *any* extension, search for the file with the
* specified extension first.
* - If filename specified has *any* extension, or already contains a path
* and the UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME flag is specified,
* search for the file with the exact specified filename first.
*
* - If the literal filename is not found in a directory, try *appending*
* (not replacing) .com first and then .exe.
@ -331,7 +332,8 @@ static WCHAR* path_search_walk_ext(const WCHAR *dir,
*/
static WCHAR* search_path(const WCHAR *file,
WCHAR *cwd,
const WCHAR *path) {
const WCHAR *path,
unsigned int flags) {
int file_has_dir;
WCHAR* result = NULL;
WCHAR *file_name_start;
@ -372,16 +374,18 @@ static WCHAR* search_path(const WCHAR *file,
file, file_name_start - file,
file_name_start, file_len - (file_name_start - file),
cwd, cwd_len,
name_has_ext);
name_has_ext || (flags & UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME));
} else {
dir_end = path;
/* The file is really only a name; look in cwd first, then scan path */
result = path_search_walk_ext(L"", 0,
file, file_len,
cwd, cwd_len,
name_has_ext);
if (NeedCurrentDirectoryForExePathW(L"")) {
/* The file is really only a name; look in cwd first, then scan path */
result = path_search_walk_ext(L"", 0,
file, file_len,
cwd, cwd_len,
name_has_ext);
}
while (result == NULL) {
if (dir_end == NULL || *dir_end == L'\0') {
@ -509,7 +513,7 @@ WCHAR* quote_cmd_arg(const WCHAR *source, WCHAR *target) {
}
}
target[0] = L'\0';
wcsrev(start);
_wcsrev(start);
*(target++) = L'"';
return target;
}
@ -613,8 +617,8 @@ int env_strncmp(const wchar_t* a, int na, const wchar_t* b) {
assert(b_eq);
nb = b_eq - b;
A = alloca((na+1) * sizeof(wchar_t));
B = alloca((nb+1) * sizeof(wchar_t));
A = _alloca((na+1) * sizeof(wchar_t));
B = _alloca((nb+1) * sizeof(wchar_t));
r = LCMapStringW(LOCALE_INVARIANT, LCMAP_UPPERCASE, a, na, A, na);
assert(r==na);
@ -691,7 +695,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
if (dst_copy == NULL && env_len > 0) {
return UV_ENOMEM;
}
env_copy = alloca(env_block_count * sizeof(WCHAR*));
env_copy = _alloca(env_block_count * sizeof(WCHAR*));
ptr = dst_copy;
ptr_copy = env_copy;
@ -933,6 +937,7 @@ int uv_spawn(uv_loop_t* loop,
assert(!(options->flags & ~(UV_PROCESS_DETACHED |
UV_PROCESS_SETGID |
UV_PROCESS_SETUID |
UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME |
UV_PROCESS_WINDOWS_HIDE |
UV_PROCESS_WINDOWS_HIDE_CONSOLE |
UV_PROCESS_WINDOWS_HIDE_GUI |
@ -1012,7 +1017,8 @@ int uv_spawn(uv_loop_t* loop,
application_path = search_path(application,
cwd,
path);
path,
options->flags);
if (application_path == NULL) {
/* Not found. */
err = ERROR_FILE_NOT_FOUND;
@ -1210,9 +1216,18 @@ static int uv__kill(HANDLE process_handle, int signum) {
(PVOID) dump_folder,
&dump_folder_len);
if (ret != ERROR_SUCCESS) {
/* Workaround for missing uuid.dll on MinGW. */
static const GUID FOLDERID_LocalAppData_libuv = {
0xf1b32785, 0x6fba, 0x4fcf,
{0x9d, 0x55, 0x7b, 0x8e, 0x7f, 0x15, 0x70, 0x91}
};
/* Default value for `dump_folder` is `%LOCALAPPDATA%\CrashDumps`. */
WCHAR* localappdata;
SHGetKnownFolderPath(&FOLDERID_LocalAppData, 0, NULL, &localappdata);
SHGetKnownFolderPath(&FOLDERID_LocalAppData_libuv,
0,
NULL,
&localappdata);
_snwprintf_s(dump_folder,
sizeof(dump_folder),
_TRUNCATE,
@ -1292,7 +1307,6 @@ static int uv__kill(HANDLE process_handle, int signum) {
case SIGINT: {
/* Unconditionally terminate the process. On Windows, killed processes
* normally return 1. */
DWORD status;
int err;
if (TerminateProcess(process_handle, 1))
@ -1302,8 +1316,7 @@ static int uv__kill(HANDLE process_handle, int signum) {
* TerminateProcess will fail with ERROR_ACCESS_DENIED. */
err = GetLastError();
if (err == ERROR_ACCESS_DENIED &&
GetExitCodeProcess(process_handle, &status) &&
status != STILL_ACTIVE) {
WaitForSingleObject(process_handle, 0) == WAIT_OBJECT_0) {
return UV_ESRCH;
}
@ -1312,15 +1325,16 @@ static int uv__kill(HANDLE process_handle, int signum) {
case 0: {
/* Health check: is the process still alive? */
DWORD status;
if (!GetExitCodeProcess(process_handle, &status))
return uv_translate_sys_error(GetLastError());
if (status != STILL_ACTIVE)
return UV_ESRCH;
return 0;
switch (WaitForSingleObject(process_handle, 0)) {
case WAIT_OBJECT_0:
return UV_ESRCH;
case WAIT_FAILED:
return uv_translate_sys_error(GetLastError());
case WAIT_TIMEOUT:
return 0;
default:
return UV_UNKNOWN;
}
}
default:
@ -1355,7 +1369,7 @@ int uv_kill(int pid, int signum) {
if (pid == 0) {
process_handle = GetCurrentProcess();
} else {
process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
FALSE,
pid);
}

View File

@ -695,7 +695,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
DWORD records_left, records_read;
uv_buf_t buf;
off_t buf_used;
_off_t buf_used;
assert(handle->type == UV_TTY);
assert(handle->flags & UV_HANDLE_TTY_READABLE);
@ -2246,7 +2246,7 @@ void uv__tty_close(uv_tty_t* handle) {
if (handle->u.fd == -1)
CloseHandle(handle->handle);
else
close(handle->u.fd);
_close(handle->u.fd);
handle->u.fd = -1;
handle->handle = INVALID_HANDLE_VALUE;

View File

@ -1466,6 +1466,48 @@ int uv_os_setpriority(uv_pid_t pid, int priority) {
return r;
}
int uv_thread_getpriority(uv_thread_t tid, int* priority) {
int r;
if (priority == NULL)
return UV_EINVAL;
r = GetThreadPriority(tid);
if (r == THREAD_PRIORITY_ERROR_RETURN)
return uv_translate_sys_error(GetLastError());
*priority = r;
return 0;
}
int uv_thread_setpriority(uv_thread_t tid, int priority) {
int r;
switch (priority) {
case UV_THREAD_PRIORITY_HIGHEST:
r = SetThreadPriority(tid, THREAD_PRIORITY_HIGHEST);
break;
case UV_THREAD_PRIORITY_ABOVE_NORMAL:
r = SetThreadPriority(tid, THREAD_PRIORITY_ABOVE_NORMAL);
break;
case UV_THREAD_PRIORITY_NORMAL:
r = SetThreadPriority(tid, THREAD_PRIORITY_NORMAL);
break;
case UV_THREAD_PRIORITY_BELOW_NORMAL:
r = SetThreadPriority(tid, THREAD_PRIORITY_BELOW_NORMAL);
break;
case UV_THREAD_PRIORITY_LOWEST:
r = SetThreadPriority(tid, THREAD_PRIORITY_LOWEST);
break;
default:
return 0;
}
if (r == 0)
return uv_translate_sys_error(GetLastError());
return 0;
}
int uv_os_uname(uv_utsname_t* buffer) {
/* Implementation loosely based on