Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .goarc
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions pkg/genode-js-xs/archives
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
nfeske/src/libc
nfeske/src/vfs
genodelabs/src/libc
genodelabs/src/vfs
genodelabs/src/vfs_lxip
genodelabs/src/sandbox
22 changes: 15 additions & 7 deletions pkg/genode-js-xs/runtime
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<runtime ram="300M" caps="5000" binary="init" config="js-xs.config">

<requires>
<nic />
</requires>
<content>
<rom label="hello"/>
<rom label="js-xs.config"/>
<rom label="libc.lib.so"/>
<rom label="libm.lib.so"/>
<rom label="vfs.lib.so"/>
<rom label="hello" />
<rom label="js-xs.config" />
<rom label="libc.lib.so" />
<rom label="libm.lib.so" />
<rom label="vfs.lib.so" />
<rom label="vfs" />
<rom label="linux_nic_drv" />
<rom label="vfs_lxip.lib.so" />
<rom label="lxip.lib.so" />
<rom label="sandbox.lib.so" />

</content>
</runtime>
</runtime>
16 changes: 15 additions & 1 deletion raw/js-xs.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,30 @@
<service name="CPU" />
<service name="PD" />
<service name="Timer" />
<service name="Nic" />
</parent-provides>

<start name="hello" caps="100">
<default-route>
<any-service>
<parent />
<any-child />
</any-service>
</default-route>

<default caps="500" />

<start name="hello">
<resource name="RAM" quantum="200M" />
<config>
<libc stdout="/dev/log" stderr="/dev/log" rtc="/dev/null" />
<vfs>
<dir name="dev">
<null />
<log />
<dir name="socket">
<!-- depends on tap device. see https://genodians.org/chelmuth/2019-01-31-network-dev -->
<lxip ip_addr="10.0.2.55" netmask="255.255.255.0" gateway="10.0.2.1" />
</dir>
</dir>
</vfs>
</config>
Expand Down
22 changes: 22 additions & 0 deletions src/FFIgenode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#include <base/log.h>

#include <stdio.h> /* @@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<App::HasSandbox *>(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;
}
}
23 changes: 23 additions & 0 deletions src/FFImod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
17 changes: 17 additions & 0 deletions src/app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __APP__
#define __APP__
#include <util/xml_node.h>


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
20 changes: 13 additions & 7 deletions src/genode.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,38 @@ struct sxJob {
txNumber interval;
};

extern void applyConfig(xsMachine *the); // see FFImod.c

static void fxQueuePromiseJobsCallback(txJob* job);
static void fxRunLoop(txMachine* the);

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)));
Expand Down
144 changes: 133 additions & 11 deletions src/genode_construct.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,155 @@
/* Genode includes */
#include <libc/component.h>
#include <log_session/log_session.h>
#include <base/session_object.h>
#include <os/buffered_xml.h>
#include <os/sandbox.h>

/* libc includes */
#include <stdlib.h> /* 'exit' */
#include <stdio.h> /*@@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<Log_session>
{
template <typename... ARGS>
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_session_component> 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<char*>(&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);
});
}
Loading