46 #define E_V(str) { L##str, L##str L"=", sizeof(str) }
83 SECURITY_ATTRIBUTES attr;
84 JOBOBJECT_EXTENDED_LIMIT_INFORMATION
info;
86 memset(&attr, 0,
sizeof attr);
87 attr.bInheritHandle =
FALSE;
90 info.BasicLimitInformation.LimitFlags =
101 JobObjectExtendedLimitInformation,
112 ws_len = MultiByteToWideChar(CP_UTF8,
119 return GetLastError();
122 ws = (WCHAR*)
uv__malloc(ws_len *
sizeof(WCHAR));
124 return ERROR_OUTOFMEMORY;
127 r = MultiByteToWideChar(CP_UTF8,
148 handle->exit_cb_pending = 0;
170 WCHAR *result, *result_pos;
172 if (dir_len > 2 && dir[0] ==
L'\\' && dir[1] ==
L'\\') {
175 }
else if (dir_len >= 1 && (dir[0] ==
L'/' || dir[0] ==
L'\\')) {
178 }
else if (dir_len >= 2 && dir[1] ==
L':' &&
179 (dir_len < 3 || (dir[2] !=
L'/' && dir[2] !=
L'\\'))) {
184 if (cwd_len < 2 || _wcsnicmp(
cwd, dir, 2) != 0) {
190 }
else if (dir_len > 2 && dir[1] ==
L':') {
198 result = result_pos = (WCHAR*)
uv__malloc(
sizeof(WCHAR) *
199 (cwd_len + 1 + dir_len + 1 + name_len + 1 + ext_len + 1));
202 wcsncpy(result_pos,
cwd, cwd_len);
203 result_pos += cwd_len;
206 if (cwd_len && wcsrchr(
L"\\/:", result_pos[-1]) ==
NULL) {
207 result_pos[0] =
L'\\';
212 wcsncpy(result_pos, dir, dir_len);
213 result_pos += dir_len;
216 if (dir_len && wcsrchr(
L"\\/:", result_pos[-1]) ==
NULL) {
217 result_pos[0] =
L'\\';
222 wcsncpy(result_pos,
name, name_len);
223 result_pos += name_len;
227 if (name_len && result_pos[-1] !=
'.') {
228 result_pos[0] =
L'.';
233 wcsncpy(result_pos,
ext, ext_len);
234 result_pos += ext_len;
238 result_pos[0] =
L'\0';
240 attrs = GetFileAttributesW(result);
242 if (attrs != INVALID_FILE_ATTRIBUTES &&
243 !(attrs & FILE_ATTRIBUTE_DIRECTORY)) {
270 if (result !=
NULL) {
280 if (result !=
NULL) {
289 if (result !=
NULL) {
344 WCHAR* result =
NULL;
345 WCHAR *file_name_start;
347 const WCHAR *dir_start, *dir_end, *dir_path;
351 size_t file_len = wcslen(
file);
352 size_t cwd_len = wcslen(
cwd);
358 || (file_len == 1 &&
file[0] ==
L'.')) {
364 for (file_name_start = (WCHAR*)
file + file_len;
365 file_name_start >
file
366 && file_name_start[-1] !=
L'\\'
367 && file_name_start[-1] !=
L'/'
368 && file_name_start[-1] !=
L':';
371 file_has_dir = file_name_start !=
file;
374 dot = wcschr(file_name_start,
L'.');
375 name_has_ext = (dot !=
NULL && dot[1] !=
L'\0');
381 file_name_start, file_len - (file_name_start -
file),
394 while (result ==
NULL) {
395 if (*dir_end ==
L'\0') {
408 if (*dir_start ==
L'"' || *dir_start ==
L'\'') {
409 dir_end = wcschr(dir_start + 1, *dir_start);
410 if (dir_end ==
NULL) {
411 dir_end = wcschr(dir_start,
L'\0');
415 dir_end = wcschr(dir_end,
L';');
416 if (dir_end ==
NULL) {
417 dir_end = wcschr(dir_start,
L'\0');
421 if (dir_end - dir_start == 0) {
425 dir_path = dir_start;
426 dir_len = dir_end - dir_start;
429 if (dir_path[0] ==
'"' || dir_path[0] ==
'\'') {
434 if (dir_path[dir_len - 1] ==
'"' || dir_path[dir_len - 1] ==
'\'') {
507 for (
i =
len;
i > 0; --
i) {
510 if (quote_hit &&
source[
i - 1] ==
L'\\') {
529 WCHAR* temp_buffer =
NULL;
531 size_t temp_buffer_len = 0;
540 arg_len = MultiByteToWideChar(CP_UTF8,
547 return GetLastError();
552 if (arg_len > temp_buffer_len)
553 temp_buffer_len = arg_len;
560 dst_len = dst_len * 2 + arg_count * 2;
565 err = ERROR_OUTOFMEMORY;
570 temp_buffer = (WCHAR*)
uv__malloc(temp_buffer_len *
sizeof(WCHAR));
571 if (temp_buffer ==
NULL) {
572 err = ERROR_OUTOFMEMORY;
581 arg_len = MultiByteToWideChar(CP_UTF8,
586 (
int) (
dst + dst_len -
pos));
588 err = GetLastError();
592 if (verbatim_arguments) {
594 wcscpy(
pos, temp_buffer);
625 a_eq = wcschr(
a,
L'=');
627 na = (
int)(
long)(a_eq -
a);
631 b_eq = wcschr(
b,
L'=');
635 A =
alloca((na+1) *
sizeof(
wchar_t));
636 B =
alloca((nb+1) *
sizeof(
wchar_t));
650 }
else if (AA > BB) {
652 }
else if (!AA && !BB) {
660 wchar_t* astr = *(
wchar_t*
const*)
a;
661 wchar_t* bstr = *(
wchar_t*
const*)
b;
690 size_t env_block_count = 1;
699 if (strchr(*
env,
'=')) {
700 len = MultiByteToWideChar(CP_UTF8,
707 return GetLastError();
715 dst_copy = (WCHAR*)
uv__malloc(env_len *
sizeof(WCHAR));
716 if (dst_copy ==
NULL && env_len > 0) {
717 return ERROR_OUTOFMEMORY;
719 env_copy =
alloca(env_block_count *
sizeof(WCHAR*));
724 if (strchr(*
env,
'=')) {
725 len = MultiByteToWideChar(CP_UTF8,
730 (
int) (env_len - (ptr - dst_copy)));
741 assert(env_len == 0 || env_len == (
size_t) (ptr - dst_copy));
759 required_vars_value_len[
i] = var_size;
776 return ERROR_OUTOFMEMORY;
779 for (ptr =
dst, ptr_copy = env_copy,
i = 0;
785 }
else if (!*ptr_copy) {
794 len = required_vars_value_len[
i];
800 (
int) (env_len - (ptr -
dst)));
801 if (var_size != (
DWORD) (
len - 1)) {
808 len = wcslen(*ptr_copy) + 1;
809 wmemcpy(ptr, *ptr_copy,
len);
833 if ((
env[0] ==
L'P' ||
env[0] ==
L'p') &&
834 (
env[1] ==
L'A' ||
env[1] ==
L'a') &&
835 (
env[2] ==
L'T' ||
env[2] ==
L't') &&
836 (
env[3] ==
L'H' ||
env[3] ==
L'h') &&
870 handle->exit_cb_pending = 0;
881 UnregisterWait(
handle->wait_handle);
889 if (GetExitCodeProcess(
handle->process_handle, &
status)) {
918 if (!
handle->exit_cb_pending) {
930 CloseHandle(
handle->process_handle);
943 WCHAR* application_path =
NULL, *application =
NULL, *arguments =
NULL,
945 STARTUPINFOW startup;
946 PROCESS_INFORMATION
info;
997 cwd_len = GetCurrentDirectoryW(0,
NULL);
999 err = GetLastError();
1005 err = ERROR_OUTOFMEMORY;
1009 r = GetCurrentDirectoryW(cwd_len,
cwd);
1010 if (
r == 0 ||
r >= cwd_len) {
1011 err = GetLastError();
1021 path_len = GetEnvironmentVariableW(
L"PATH",
NULL, 0);
1022 if (path_len == 0) {
1023 err = GetLastError();
1027 alloc_path = (WCHAR*)
uv__malloc(path_len *
sizeof(WCHAR));
1028 if (alloc_path ==
NULL) {
1029 err = ERROR_OUTOFMEMORY;
1034 r = GetEnvironmentVariableW(
L"PATH",
path, path_len);
1035 if (
r == 0 ||
r >= path_len) {
1036 err = GetLastError();
1048 if (application_path ==
NULL) {
1050 err = ERROR_FILE_NOT_FOUND;
1054 startup.cb =
sizeof(startup);
1055 startup.lpReserved =
NULL;
1056 startup.lpDesktop =
NULL;
1057 startup.lpTitle =
NULL;
1058 startup.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
1061 startup.lpReserved2 = (
BYTE*)
process->child_stdio_buffer;
1067 process_flags = CREATE_UNICODE_ENVIRONMENT;
1076 process_flags |= CREATE_NO_WINDOW;
1082 startup.wShowWindow = SW_HIDE;
1084 startup.wShowWindow = SW_SHOWDEFAULT;
1098 process_flags |= DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP;
1101 if (!CreateProcessW(application_path,
1112 err = GetLastError();
1138 if (
err != ERROR_ACCESS_DENIED)
1155 result = RegisterWaitForSingleObject(&
process->wait_handle,
1157 WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE);
1162 CloseHandle(
info.hThread);
1190 if (signum < 0 || signum >=
NSIG) {
1203 if (TerminateProcess(process_handle, 1))
1208 err = GetLastError();
1209 if (
err == ERROR_ACCESS_DENIED &&
1210 GetExitCodeProcess(process_handle, &
status) &&
1211 status != STILL_ACTIVE) {
1222 if (!GetExitCodeProcess(process_handle, &
status))
1225 if (
status != STILL_ACTIVE)
1261 process_handle = GetCurrentProcess();
1263 process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
1268 if (process_handle ==
NULL) {
1269 err = GetLastError();
1270 if (
err == ERROR_INVALID_PARAMETER) {
1278 CloseHandle(process_handle);
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
static mcore_handle handle
RzBinInfo * info(RzBinFile *bf)
static static fork const void static count static fd const char const char static newpath const char static path const char path
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
void uv_fatal_error(const int errorno, const char *syscall)
static INLINE void uv_want_endgame(uv_loop_t *loop, uv_handle_t *handle)
#define uv__handle_close(handle)
#define uv__handle_closing(handle)
#define INVALID_HANDLE_VALUE
return memset(p, 0, total)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
static const char struct stat static buf struct stat static buf static vhangup int options
static const char struct stat static buf struct stat static buf static vhangup int status
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment signum
assert(limit<=UINT32_MAX/2)
void qsort(void *a, size_t n, size_t es, int(*cmp)(const void *, const void *))
#define POST_COMPLETION_FOR_REQ(loop, req)
const WCHAR *const wide_eq
union uv_stdio_container_s::@397 data
void uv__stdio_destroy(BYTE *buffer)
WORD uv__stdio_size(BYTE *buffer)
int uv__stdio_create(uv_loop_t *loop, const uv_process_options_t *options, BYTE **buffer_ptr)
HANDLE uv__stdio_handle(BYTE *buffer, int fd)
int uv_spawn(uv_loop_t *loop, uv_process_t *process, const uv_process_options_t *options)
int uv_kill(int pid, int signum)
int uv_process_kill(uv_process_t *process, int signum)
void error(const char *msg)
void * uv__malloc(size_t size)
#define UV_REQ_INIT(req, typ)
#define uv__handle_init(loop_, h, type_)
#define uv__handle_stop(h)
#define uv__handle_start(h)
@ UV_PROCESS_WINDOWS_HIDE_CONSOLE
@ UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS
@ UV_PROCESS_WINDOWS_HIDE
@ UV_PROCESS_WINDOWS_HIDE_GUI
UV_EXTERN int uv_translate_sys_error(int sys_errno)
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
static int qsort_wcscmp(const void *a, const void *b)
static void uv__init_global_job_handle(void)
WCHAR * quote_cmd_arg(const WCHAR *source, WCHAR *target)
void uv_process_close(uv_loop_t *loop, uv_process_t *handle)
static int uv_utf8_to_utf16_alloc(const char *s, WCHAR **ws_ptr)
static void uv_process_init(uv_loop_t *loop, uv_process_t *handle)
static WCHAR * search_path(const WCHAR *file, WCHAR *cwd, const WCHAR *path)
int env_strncmp(const wchar_t *a, int na, const wchar_t *b)
static uv_once_t uv_global_job_handle_init_guard_
static WCHAR * find_path(WCHAR *env)
static const env_var_t required_vars[]
static WCHAR * path_search_walk_ext(const WCHAR *dir, size_t dir_len, const WCHAR *name, size_t name_len, WCHAR *cwd, size_t cwd_len, int name_has_ext)
static HANDLE uv_global_job_handle_
static WCHAR * search_path_join_test(const WCHAR *dir, size_t dir_len, const WCHAR *name, size_t name_len, const WCHAR *ext, size_t ext_len, const WCHAR *cwd, size_t cwd_len)
void uv_process_endgame(uv_loop_t *loop, uv_process_t *handle)
static void CALLBACK exit_wait_callback(void *data, BOOLEAN didTimeout)
void uv_process_proc_exit(uv_loop_t *loop, uv_process_t *handle)
int make_program_args(char **args, int verbatim_arguments, WCHAR **dst_ptr)
static int uv__kill(HANDLE process_handle, int signum)
int make_program_env(char *env_block[], WCHAR **dst_ptr)
#define JOB_OBJECT_LIMIT_BREAKAWAY_OK
#define JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
#define JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION
#define JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK
static zip_compression_status_t process(void *ud, zip_uint8_t *data, zip_uint64_t *length)