Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Added option USE_EXECMGR for including all Execution Manager staff
Browse files Browse the repository at this point in the history
Public release versions of SDK and internal for developers have
different components. Now the public version doesn't have Execution
Manager. USE_EXECMGR allows turn off Execution Manager for public
releases.
  • Loading branch information
Vsevolod Lebedev authored and Vadim Lomovtsev committed Feb 14, 2023
1 parent c898eae commit ef1d45c
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 9 deletions.
2 changes: 1 addition & 1 deletion deps/uv/include/uv/unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ typedef struct {
char* errmsg;
} uv_lib_t;

#ifdef __KOS__
#if (USE_EXECMGR == 1)
#define CHILD_WATCHER uv_timer_t
#else
#define CHILD_WATCHER uv_signal_t
Expand Down
89 changes: 89 additions & 0 deletions deps/uv/src/kos/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
#include <fcntl.h>
#include <poll.h>
#include "kos-trace.h"

#if (USE_EXECMGR == 1)
#include "kos-execmgr.h"
#endif

extern char **environ;

#if (USE_EXECMGR == 1)
static void uv__chld(uv_timer_t* handle) {
uv_process_t* process;
uv_loop_t* loop;
Expand Down Expand Up @@ -91,6 +95,73 @@ static void uv__chld(uv_timer_t* handle) {
}
assert(QUEUE_EMPTY(&pending));
}
#else
static void uv__chld(uv_signal_t* handle, int signum) {
uv_process_t* process;
uv_loop_t* loop;
int exit_status;
int term_signal;
int status;
pid_t pid;
QUEUE pending;
QUEUE* q;
QUEUE* h;

assert(signum == SIGCHLD);

QUEUE_INIT(&pending);
loop = handle->loop;

h = &loop->process_handles;
q = QUEUE_HEAD(h);
while (q != h) {
process = QUEUE_DATA(q, uv_process_t, queue);
q = QUEUE_NEXT(q);

do
pid = waitpid(process->pid, &status, WNOHANG);
while (pid == -1 && errno == EINTR);

if (pid == 0)
continue;

if (pid == -1) {
if (errno != ECHILD)
abort();
continue;
}

process->status = status;
QUEUE_REMOVE(&process->queue);
QUEUE_INSERT_TAIL(&pending, &process->queue);
}

h = &pending;
q = QUEUE_HEAD(h);
while (q != h) {
process = QUEUE_DATA(q, uv_process_t, queue);
q = QUEUE_NEXT(q);

QUEUE_REMOVE(&process->queue);
QUEUE_INIT(&process->queue);
uv__handle_stop(process);

if (process->exit_cb == NULL)
continue;

exit_status = 0;
if (WIFEXITED(process->status))
exit_status = WEXITSTATUS(process->status);

term_signal = 0;
if (WIFSIGNALED(process->status))
term_signal = WTERMSIG(process->status);

process->exit_cb(process, exit_status, term_signal);
}
assert(QUEUE_EMPTY(&pending));
}
#endif

/*
* Used for initializing stdio streams like options.stdin_stream. Returns
Expand Down Expand Up @@ -186,6 +257,8 @@ static void uv__write_errno(int error_fd) {
int uv_spawn(uv_loop_t* loop,
uv_process_t* process,
const uv_process_options_t* options) {

#if (USE_EXECMGR == 1)
KOS_TEST_INF("[attempt to SPAWN (fork)]");

assert(options->file != NULL);
Expand Down Expand Up @@ -222,6 +295,11 @@ int uv_spawn(uv_loop_t* loop,
process->exit_cb = options->exit_cb;

return !err ? 0 : UV_ENOSYS;
#else
KOS_TEST_INF("[attempt to SPAWN (fork)]");
/* fork is marked __WATCHOS_PROHIBITED __TVOS_PROHIBITED. */
return UV_ENOSYS;
#endif
}


Expand All @@ -231,15 +309,26 @@ int uv_process_kill(uv_process_t* process, int signum) {


int uv_kill(int pid, int signum) {
#if (USE_EXECMGR == 1)
int err = kos_execmgr_kill(pid);

return !err ? 0 : UV_ENOSYS;
#else
if (kill(pid, signum))
return UV__ERR(errno);
else
return 0;
#endif
}


void uv__process_close(uv_process_t* handle) {
QUEUE_REMOVE(&handle->queue);
uv__handle_stop(handle);
if (QUEUE_EMPTY(&handle->loop->process_handles))
#if (USE_EXECMGR == 1)
uv_timer_stop(&handle->loop->child_watcher);
#else
uv_signal_stop(&handle->loop->child_watcher);
#endif
}
2 changes: 1 addition & 1 deletion deps/uv/src/unix/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int uv_loop_init(uv_loop_t* loop) {
goto fail_platform_init;

uv__signal_global_once_init();
#ifdef __KOS__
#if (USE_EXECMGR == 1)
err = uv_timer_init(loop, &loop->child_watcher);
#else
err = uv_signal_init(loop, &loop->child_watcher);
Expand Down
20 changes: 18 additions & 2 deletions deps/uv/uv.gyp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
'variables': {
'node_addons_lib_enabled': '<!(echo $NODE_ADDONS_LIB_ENABLED)',
'node_use_execmgr': '<!(echo $USE_EXECMGR)',
'conditions': [
['OS=="win"', {
'shared_unix_defines': [ ],
Expand Down Expand Up @@ -162,6 +163,9 @@
],
},
}, { # Not Windows i.e. POSIX
'defines': [
'USE_EXECMGR=node_use_execmgr',
],
'sources': [
'include/uv/unix.h',
'include/uv/linux.h',
Expand Down Expand Up @@ -275,8 +279,10 @@
},
}],
[ 'OS=="kos"', {
'cflags_cc': [ '-fexceptions' ],
'defines': [ '_GNU_SOURCE' ],
'defines': [
'_GNU_SOURCE',
'USE_EXECMGR=node_use_execmgr'
],
'sources': [
'src/unix/core.c',
'src/unix/fs.c',
Expand All @@ -292,6 +298,16 @@
'src/unix/procfs-exepath.c',
'src/unix/random-getrandom.c',
'src/kos/random-sysctl-kos.c',
],
}],
['OS == "kos" and node_use_execmgr==1', {
'cflags_cc': [
'-fexceptions'
],
'defines': [
'USE_EXECMGR=1',
],
'sources': [
'src/kos/kos-execmgr.cc',
],
'link_settings': {
Expand Down
1 change: 1 addition & 0 deletions kos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dump-vars:
@echo " [VAR] NODE_ADDONS_LIB_ENABLED=$(NODE_ADDONS_LIB_ENABLED)"
@echo " [VAR] NODE_ADDONS_BUILD_PATH=$(NODE_ADDONS_BUILD_PATH)"
@echo " [VAR] QEMU_OPTS=$(QEMU_OPTS)"
@echo " [VAR] USE_EXECMGR=$(USE_EXECMGR)"

# Help info with respect to build/make targets
.PHONY: help
Expand Down
9 changes: 5 additions & 4 deletions kos/image_builder/einit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ set (ENTITIES
${tls_ENTITY}
${rump_DHCPCD_ENTITY}
${ns_ENTITY}
${certificate_storage_ENTITY}
ExecMgrEntity
${blob_container_ENTITY}
${romfs_storage_ENTITY})
${certificate_storage_ENTITY})

if (USE_KLOG)
list (APPEND ENTITIES KlogStorageEntity)
endif()

if (USE_EXECMGR)
list (APPEND ENTITIES ExecMgrEntity ${blob_container_ENTITY} ${romfs_storage_ENTITY})
endif()

set (SECURITY_PSL_FILE "src/psl/security.psl")

if (ROOTFS_SDCARD)
Expand Down
10 changes: 9 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'node_builtin_modules_path%': '',
'node_addons_lib_enabled': '<!(echo $NODE_ADDONS_LIB_ENABLED)',
'node_addons_lib_path': '<!(echo $NODE_ADDONS_BUILD_PATH)',
'node_use_execmgr': '<!(echo $USE_EXECMGR)',
# We list the deps/ files out instead of globbing them in js2c.py since we
# only include a subset of all the files under these directories.
# The lengths of their file names combined should not exceed the
Expand Down Expand Up @@ -196,10 +197,17 @@
'ldflags': [
'-Wl,--whole-archive',
'-lvfs_remote',
'-lromfs_storage_lib',
'-Wl,--no-whole-archive'
],
}],
['OS == "kos" and node_use_execmgr==1', {
'defines': [
'USE_EXECMGR=1',
],
'ldflags': [
'-lromfs_storage_lib',
],
}],
['OS=="kos" and node_addons_lib_enabled==1', {
'ldflags': [
'-L<(node_addons_lib_path)',
Expand Down

0 comments on commit ef1d45c

Please sign in to comment.