diff --git a/.goarc b/.goarc new file mode 100644 index 0000000..4253517 --- /dev/null +++ b/.goarc @@ -0,0 +1,16 @@ +set version(chelmuth/api/base) 2021-05-27 +set version(chelmuth/api/libc) 2021-05-04 +set version(chelmuth/src/vfs_lxip) 2021-05-27 + +set version(genodelabs/api/base) 2021-02-22 +set version(genodelabs/api/libc) 2021-02-22 +# https://depot.genode.org/genodelabs/api/os/2021-02-22.tar.xz.sig +set version(genodelabs/api/os) 2021-02-22 + +# https://depot.genode.org/genodelabs/src/libc/2021-03-22.tar.xz.sig +set version(genodelabs/src/libc) 2021-03-22 +set version(genodelabs/src/vfs) 2021-02-22 +# https://depot.genode.org/genodelabs/src/vfs_lxip/2021-04-26.tar.xz.sig +set version(genodelabs/src/vfs_lxip) 2021-04-26 +# https://depot.genode.org/genodelabs/src/sandbox/2021-04-23.tar.xz.sig +set version(genodelabs/src/sandbox) 2021-04-23 diff --git a/pkg/genode-js-xs/archives b/pkg/genode-js-xs/archives index 05abcb4..c7587dd 100644 --- a/pkg/genode-js-xs/archives +++ b/pkg/genode-js-xs/archives @@ -1,2 +1,4 @@ -nfeske/src/libc -nfeske/src/vfs +genodelabs/src/libc +genodelabs/src/vfs +genodelabs/src/vfs_lxip +genodelabs/src/sandbox diff --git a/pkg/genode-js-xs/runtime b/pkg/genode-js-xs/runtime index df87d9f..a71629b 100644 --- a/pkg/genode-js-xs/runtime +++ b/pkg/genode-js-xs/runtime @@ -1,10 +1,18 @@ - + + + - - - - - + + + + + + + + + + + - + \ No newline at end of file diff --git a/raw/js-xs.config b/raw/js-xs.config index a81b862..478c9fe 100644 --- a/raw/js-xs.config +++ b/raw/js-xs.config @@ -6,9 +6,19 @@ + - + + + + + + + + + + @@ -16,6 +26,10 @@ + + + + diff --git a/src/FFIgenode.cpp b/src/FFIgenode.cpp index a91216c..28a6468 100644 --- a/src/FFIgenode.cpp +++ b/src/FFIgenode.cpp @@ -1,6 +1,28 @@ #include +#include /* @@debug */ +#include "app.h" + extern "C" void genode_log(const char* message) { Genode::log(message); +} + +extern "C" +int genode_sandbox_apply_config(char *context, char const *text) +{ + fprintf(stderr, "genode_sandbox_apply_config(%p, %s)\n", context, text); + // App::HasSandbox *app = reinterpret_cast(context); + App::HasSandbox *app = theApp; + fprintf(stderr, "got app %p@@\n", app); + try { + Genode::Xml_node config(text); + fprintf(stderr, "config tag type: %s\n", config.type().string()); + app->applyConfig(config); + return 0; + } + catch (Genode::Xml_node::Invalid_syntax) { + fprintf(stderr, "@@Invalid_syntax\n"); + return -1; + } } \ No newline at end of file diff --git a/src/FFImod.c b/src/FFImod.c index 260b49d..6cdebb7 100644 --- a/src/FFImod.c +++ b/src/FFImod.c @@ -2,9 +2,32 @@ // see FFIgenode.cpp extern void genode_log(); +extern int genode_sandbox_apply_config(char* context, const char *text); void xs_fun(xsMachine *the) { const char* message = xsToString(xsArg(0)); genode_log(message); } + +static void *getSandbox(xsMachine *the) +{ + void *result = xsGetHostData(xsThis); + if (!result) + xsUnknownError("no sandbox host data"); + return result; +} + +void applyConfig(xsMachine *the) +{ + fprintf(stderr, "applyConfig...\n"); + void *sandbox = getSandbox(the); + fprintf(stderr, "applyConfig sandbox: %p\n", sandbox); + const char* text = xsToString(xsArg(0)); + fprintf(stderr, "applyConfig sandbox config text: %s\n", text); + const int err = genode_sandbox_apply_config(sandbox, text); + fprintf(stderr, "applyConfig err: %d\n", err); + if (err != 0) { + xsUnknownError("bad config %s", text); + } +} \ No newline at end of file diff --git a/src/app.h b/src/app.h new file mode 100644 index 0000000..a423522 --- /dev/null +++ b/src/app.h @@ -0,0 +1,17 @@ +#ifndef __APP__ +#define __APP__ +#include + + +namespace App { + using namespace Genode; + + struct HasSandbox { + virtual void show(const char *message) = 0; + virtual void applyConfig(Xml_node const &config) = 0; + }; +} + +extern App::HasSandbox *theApp; + +#endif diff --git a/src/genode.c b/src/genode.c index a389d05..0aa0bb0 100644 --- a/src/genode.c +++ b/src/genode.c @@ -19,6 +19,8 @@ struct sxJob { txNumber interval; }; +extern void applyConfig(xsMachine *the); // see FFImod.c + static void fxQueuePromiseJobsCallback(txJob* job); static void fxRunLoop(txMachine* the); @@ -26,25 +28,29 @@ int main(int argc, char* argv[]) // here { int error = 0; - xsMachine* machine = fxPrepareMachine(NULL, xsPreparation(), "tool", NULL, NULL); + xsMachine* machine = fxPrepareMachine(NULL, xsPreparation(), argv[0], NULL, NULL); xsBeginHost(machine); { - xsVars(3); + xsVars(5); { xsTry { - int argi; - xsVar(0) = xsNewArray(0); - for (argi = 1; argi < argc; argi++) { - xsSetAt(xsVar(0), xsInteger(argi - 1), xsString(argv[argi])); + if (argc != -1) { + xsRangeError("expected argc == -1 to signal novel use of argv"); } + xsVar(0) = xsNewObject(); + xsVar(4) = xsNewHostFunction(applyConfig, 1); + xsVar(3) = xsNewHostObject(NULL); + xsSetHostData(xsVar(3), argv[0]); + xsDefine(xsVar(0), xsID("sandbox"), xsVar(3), xsDontSet); + xsDefine(xsVar(3), xsID("applyConfig"), xsVar(4), xsDontSet); // printf("lin_xs_cli: loading top-level main.js\n"); xsVar(1) = xsAwaitImport("main", XS_IMPORT_DEFAULT); // printf(" lin_xs_cli: loaded\n"); // printf("lin_xs_cli: invoking main(argv)\n"); - xsVar(2) = xsCallFunction1(xsVar(1), xsUndefined, xsVar(0)); + xsVar(2) = xsCallFunction2(xsVar(1), xsUndefined, xsVar(0), xsVar(3)); if (!xsIsInstanceOf(xsVar(2), xsPromisePrototype)) { // fprintf(stderr, "main() returned immediate value (not a promise). exiting\n"); exit(xsToInteger(xsVar(2))); diff --git a/src/genode_construct.cpp b/src/genode_construct.cpp index 050c1dd..da83f76 100644 --- a/src/genode_construct.cpp +++ b/src/genode_construct.cpp @@ -1,33 +1,155 @@ /* Genode includes */ #include +#include +#include +#include +#include /* libc includes */ #include /* 'exit' */ +#include /*@@debug fprintf*/ + +#include "app.h" extern char **genode_argv; -extern int genode_argc; +extern int genode_argc; extern char **genode_envp; /* provided by the application */ -extern "C" int main(int argc, char ** argv, char **envp); +extern "C" int main(int argc, char **argv, char **envp); + +static char **no_env = {}; + +namespace App +{ + + using namespace Genode; + + struct Log_session_component; + struct Main; +} // namespace App + +struct App::Log_session_component : Session_object +{ + template + Log_session_component(ARGS &&... args) : Session_object(args...) {} + + void write(String const &msg) override + { + /* omit line break and zero termination supplied by 'msg' */ + if (msg.size() > 1) + log("local LOG service: ", Cstring(msg.string(), msg.size() - 2)); + } +}; + +struct App::Main : Sandbox::Local_service_base::Wakeup, App::HasSandbox +{ + Env &_env; + + Heap _heap{_env.ram(), _env.rm()}; + + struct State_handler : Sandbox::State_handler + { + void handle_sandbox_state() override {} + + } _state_handler{}; + + Sandbox _sandbox{_env, _state_handler}; -static char** no_args = {}; -static char** no_env = {}; + typedef Sandbox::Local_service Log_service; -static void construct_component(Libc::Env &env) + Log_service _log_service{_sandbox, *this}; + + void _generate_sandbox_config(Xml_generator &xml) const + { + xml.node("parent-provides", [&]() { + auto service_node = [&](char const *name) { xml.node("service", [&]() { xml.attribute("name", name); }); }; + + service_node("ROM"); + service_node("CPU"); + service_node("PD"); + service_node("LOG"); + }); + } + + /** + * Sandbox::Local_service_base::Wakeup interface + */ + void wakeup_local_service() override + { + _log_service.for_each_requested_session([&](Log_service::Request &request) { + Log_session_component &session = *new (_heap) + Log_session_component(_env.ep(), + request.resources, + request.label, + request.diag); + + request.deliver_session(session); + }); + + _log_service.for_each_upgraded_session([&](Log_session_component &, + Session::Resources const &amount) { + log("received RAM upgrade of ", amount.ram_quota); + return Log_service::Upgrade_response::CONFIRMED; + }); + + _log_service.for_each_session_to_close([&](Log_session_component &session) { + destroy(_heap, &session); + return Log_service::Close_response::CLOSED; + }); + } + + void show(const char *message) override + { + log(message); + } + + void applyConfig(Xml_node const &config) override + { + fprintf(stderr, "applyConfig()\n"); + _sandbox.apply_config(config); + } + + Main(Env &env) : _env(env) + { + log("hello, world!@@@"); + Buffered_xml const config{_heap, "config", [&](Xml_generator &xml) { _generate_sandbox_config(xml); }}; + + config.with_xml_node([&](Xml_node const &config) { + log("generated config: ", config); + + _sandbox.apply_config(config); + }); + log("sandbox config applied@@@"); + } +}; + +App::HasSandbox *theApp; + +static int construct_component(Libc::Env &env, App::Main &app) { using Genode::Xml_node; - env.config([&] (Xml_node const &node) { - // never mind args, env for now - genode_argc = 0; - genode_argv = no_args; + env.config([&](Xml_node const &node) { + // Squeeze app pointer thru argv + genode_argc = -1; + fprintf(stderr, "app: %p\n", &app); + static char *the_args[] = {reinterpret_cast(&app)}; + theApp = &app; + genode_argv = (char**)the_args; genode_envp = no_env; }); - exit(main(genode_argc, genode_argv, genode_envp)); + return main(genode_argc, genode_argv, genode_envp); } void Libc::Component::construct(Libc::Env &env) { - Libc::with_libc([&] () { construct_component(env); }); + App::Main app(env); + + Libc::with_libc([&]() { + app.show("@@construct!"); + int result = construct_component(env, app); + app.show("@@print!"); + exit(result); + }); } diff --git a/src/main.js b/src/main.js index 3d91295..f03a75c 100644 --- a/src/main.js +++ b/src/main.js @@ -2,7 +2,7 @@ import * as animals from './animals'; import { fun } from './FFI'; -export default async function main() { +export default async function main(io) { let message = "Hello, world - sample"; trace(message + "\n"); @@ -11,4 +11,33 @@ export default async function main() { trace('genode logging:\n'); fun("js to genode"); + + trace(JSON.stringify({ io, ty: typeof io.sandbox.applyConfig })); + const { sandbox } = io; + sandbox.applyConfig(` + + + + + + + + + + + + + + + + + + + + + + + + + `); } diff --git a/tap-setup.sh b/tap-setup.sh new file mode 100644 index 0000000..77701cc --- /dev/null +++ b/tap-setup.sh @@ -0,0 +1,9 @@ +dev=tap0 +# $LOGNAME turned into root +user=connolly + +ip tuntap add dev $dev mode tap user $user +ip address flush dev $dev +ip address add 10.0.2.1/24 brd 10.0.2.255 dev $dev +ip link set dev $dev addr 02:00:00:ca:fe:01 +ip link set dev $dev up \ No newline at end of file diff --git a/used_apis b/used_apis index 1737fea..b0bd8dc 100644 --- a/used_apis +++ b/used_apis @@ -1,4 +1,7 @@ # nfeske=https://github.com/genodelabs/genode/tree/master/depot/nfeske # -> https://depot.genode.org/nfeske/ -nfeske/api/base -nfeske/api/libc +# https://depot.genode.org/chelmuth/api/base/2021-05-27.tar.xz.sig +# https://depot.genode.org/genodelabs/src/ +genodelabs/api/base +genodelabs/api/libc +genodelabs/api/os