Make child an even smaller example, still not working
This commit is contained in:
@@ -12,7 +12,6 @@ if {[expr !$use_usb_driver && !$use_nic_driver] ||
|
|||||||
set build_components {
|
set build_components {
|
||||||
core init
|
core init
|
||||||
drivers/timer drivers/nic
|
drivers/timer drivers/nic
|
||||||
lib/vfs/lwip
|
|
||||||
app/child app/hello
|
app/child app/hello
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,15 +53,8 @@ set config {
|
|||||||
<resource name="RAM" quantum="1M"/>
|
<resource name="RAM" quantum="1M"/>
|
||||||
<provides> <service name="Timer"/> </provides>
|
<provides> <service name="Timer"/> </provides>
|
||||||
</start>
|
</start>
|
||||||
<start name="child" caps="200">
|
<start name="child" caps="300">
|
||||||
<resource name="RAM" quantum="8M"/>
|
<resource name="RAM" quantum="8M"/>
|
||||||
<config>
|
|
||||||
<vfs>
|
|
||||||
<dir name="dev"> <log/> </dir>
|
|
||||||
<dir name="socket"> <lwip dhcp="yes"/> </dir>
|
|
||||||
</vfs>
|
|
||||||
<libc stdout="/dev/log" stderr="/dev/log" socket="/socket"/>
|
|
||||||
</config>
|
|
||||||
</start>}
|
</start>}
|
||||||
|
|
||||||
append_if [have_spec gpio] config "
|
append_if [have_spec gpio] config "
|
||||||
@@ -85,13 +77,6 @@ append_if $use_usb_driver config {
|
|||||||
|
|
||||||
append_platform_drv_config
|
append_platform_drv_config
|
||||||
|
|
||||||
append_if $use_nic_driver config {
|
|
||||||
<start name="nic_drv" caps="130">
|
|
||||||
<resource name="RAM" quantum="20M"/>
|
|
||||||
<provides><service name="Nic"/></provides>
|
|
||||||
} [nic_drv_config] {
|
|
||||||
</start>}
|
|
||||||
|
|
||||||
append config {
|
append config {
|
||||||
</config>
|
</config>
|
||||||
}
|
}
|
||||||
@@ -102,10 +87,10 @@ install_config $config
|
|||||||
# Boot image
|
# Boot image
|
||||||
#
|
#
|
||||||
|
|
||||||
build_boot_image { core ld.lib.so init child hello nic_drv vfs_lwip.lib.so timer libc.lib.so vfs.lib.so }
|
build_boot_image { core ld.lib.so init child hello timer }
|
||||||
|
|
||||||
append qemu_args " -nographic "
|
append qemu_args " -nographic "
|
||||||
|
|
||||||
append_if [have_spec lan9118] qemu_args " -net nic,macaddr=02:00:00:00:01:03 -net nic,model=lan9118 -net tap,ifname=tap0,script=no "
|
#append_if [have_spec lan9119] qemu_args " -net nic,macaddr=02:00:00:00:01:03 -net nic,model=lan9118 -net tap,ifname=tap0,script=no "
|
||||||
|
|
||||||
run_genode_until forever
|
run_genode_until forever
|
||||||
|
|||||||
@@ -1,134 +1,93 @@
|
|||||||
#include <base/component.h>
|
#include <base/component.h>
|
||||||
#include <base/log.h>
|
#include <base/log.h>
|
||||||
#include <libc/component.h>
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
|
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
|
|
||||||
#include <base/child.h>
|
#include <base/child.h>
|
||||||
#include <init/child_policy.h>
|
#include <init/child_policy.h>
|
||||||
|
|
||||||
namespace xyz {
|
#include <rom_session/connection.h>
|
||||||
class Parent_service : public Genode::Parent_service {
|
|
||||||
private:
|
|
||||||
Genode::Registry<Parent_service>::Element _reg_elem;
|
|
||||||
|
|
||||||
public:
|
#include <loader_session/connection.h>
|
||||||
Parent_service(Genode::Registry<Parent_service> ®istry, Genode::Env &env,
|
|
||||||
Service::Name const &name)
|
|
||||||
:
|
|
||||||
Genode::Parent_service(env, name), _reg_elem(registry, *this) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
class MyChild : public Genode::Child_policy {
|
using namespace Genode;
|
||||||
Name const _name;
|
|
||||||
|
|
||||||
Genode::Env &_env;
|
class MyChild : public Child_policy {
|
||||||
|
public:
|
||||||
|
typedef Genode::Registered<Genode::Parent_service> Parent_service;
|
||||||
|
typedef Genode::Registry<Parent_service> Parent_services;
|
||||||
|
private:
|
||||||
|
Env &_env;
|
||||||
|
Cap_quota const _cap_quota {50};
|
||||||
|
Ram_quota const _ram_quota {1 * 1024 * 1024};
|
||||||
|
|
||||||
Genode::Cap_quota const _cap_quota;
|
Parent_services &_parent_services;
|
||||||
Genode::Ram_quota const _ram_quota;
|
|
||||||
|
|
||||||
Genode::Registry<xyz::Parent_service> &_parent_services;
|
Child _child;
|
||||||
|
|
||||||
Genode::Rpc_entrypoint _child_ep;
|
template <typename T>
|
||||||
|
static Genode::Service *_find_service(Genode::Registry<T> &services,
|
||||||
|
Genode::Service::Name const &name)
|
||||||
|
{
|
||||||
|
Genode::Service *service = nullptr;
|
||||||
|
services.for_each([&] (T &s) {
|
||||||
|
if (!service && (s.name() == name))
|
||||||
|
service = &s; });
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
Init::Child_policy_provide_rom_file _binary_policy;
|
public:
|
||||||
|
MyChild(Env &env, Parent_services &parent_services)
|
||||||
|
:
|
||||||
|
_env(env), _parent_services(parent_services), _child(_env.rm(), _env.ep().rpc_ep(), *this)
|
||||||
|
{}
|
||||||
|
~MyChild() { };
|
||||||
|
|
||||||
Genode::Child _child;
|
Name name() const override { return "hello"; };
|
||||||
|
|
||||||
template <typename T>
|
Pd_session &ref_pd() override { return _env.pd(); }
|
||||||
static Genode::Service *_find_service(Genode::Registry<T> &services,
|
Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); }
|
||||||
Genode::Service::Name const &name)
|
|
||||||
{
|
|
||||||
Genode::Service *service = nullptr;
|
|
||||||
services.for_each([&] (T &s) {
|
|
||||||
if (!service && (s.name() == name))
|
|
||||||
service = &s; });
|
|
||||||
return service;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
void init(Pd_session &pd, Pd_session_capability pd_cap) override
|
||||||
|
{
|
||||||
|
pd.ref_account(ref_pd_cap());
|
||||||
|
ref_pd().transfer_quota(pd_cap, _cap_quota);
|
||||||
|
ref_pd().transfer_quota(pd_cap, _ram_quota);
|
||||||
|
}
|
||||||
|
|
||||||
MyChild(Genode::Env &env,
|
Genode::Child_policy::Route
|
||||||
Genode::Session_label const &label,
|
resolve_session_request(Genode::Service::Name const &service_name,
|
||||||
Genode::Cap_quota cap_quota,
|
Genode::Session_label const &label) override
|
||||||
Genode::Ram_quota ram_quota,
|
{
|
||||||
Genode::Registry<xyz::Parent_service> parent_services,
|
auto route = [&] (Genode::Service &service) {
|
||||||
Genode::Dataspace_capability binary) :
|
return Genode::Child_policy::Route { .service = service,
|
||||||
_name(label),
|
.label = label,
|
||||||
_env(env),
|
.diag = Genode::Session::Diag() }; };
|
||||||
_cap_quota(Genode::Child::effective_quota(cap_quota)),
|
|
||||||
_ram_quota(Genode::Child::effective_quota(ram_quota)),
|
|
||||||
_parent_services(parent_services),
|
|
||||||
_child_ep{&_env.pd(), 12 * 1024, name().string()},
|
|
||||||
_binary_policy(name(), binary, &_child_ep),
|
|
||||||
_child(_env.rm(), _env.ep().rpc_ep(), *this)
|
|
||||||
{ };
|
|
||||||
~MyChild() { };
|
|
||||||
|
|
||||||
Name name() const override { return _name; }
|
Genode::Service *service = nullptr;
|
||||||
|
service = _find_service(_parent_services, service_name);
|
||||||
|
return route(*service);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Genode::Pd_session &ref_pd() override { return _env.pd(); }
|
void Component::construct(Genode::Env &env)
|
||||||
Genode::Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); }
|
|
||||||
|
|
||||||
void init(Genode::Pd_session &session,
|
|
||||||
Genode::Pd_session_capability cap) override
|
|
||||||
{
|
|
||||||
session.ref_account(_env.pd_session_cap());
|
|
||||||
_env.pd().transfer_quota(cap, _cap_quota);
|
|
||||||
_env.pd().transfer_quota(cap, _ram_quota);
|
|
||||||
}
|
|
||||||
|
|
||||||
Genode::Service &resolve_session_request(Genode::Service::Name const &service_name,
|
|
||||||
Genode::Session_state::Args const &args) override
|
|
||||||
{
|
|
||||||
Genode::Service *service = nullptr;
|
|
||||||
if ((service = _binary_policy.resolve_session_request(service_name.string(), args.string())))
|
|
||||||
{
|
|
||||||
Genode::log("Service from policy: ", service_name, "/", args);
|
|
||||||
return *service;
|
|
||||||
}
|
|
||||||
|
|
||||||
Genode::log("Service from parent: ", service_name, "/", args);
|
|
||||||
|
|
||||||
return *_find_service(_parent_services, service_name);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void Libc::Component::construct(Libc::Env &env)
|
|
||||||
{
|
{
|
||||||
Libc::with_libc([&] () {
|
Genode::log("Hello World from child!");
|
||||||
struct sockaddr_in srv_addr;
|
|
||||||
srv_addr.sin_port = htons(8080);
|
|
||||||
srv_addr.sin_family = AF_INET;
|
|
||||||
srv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
|
||||||
|
|
||||||
int sd = ::socket(AF_INET, SOCK_STREAM, 0);
|
Genode::Heap _heap {env.ram(), env.rm()};
|
||||||
::connect(sd, (struct sockaddr *)&srv_addr, sizeof(srv_addr));
|
|
||||||
|
|
||||||
Genode::Ram_dataspace_capability ds;
|
static const char *names[] = {
|
||||||
ds = env.pd().alloc(1 * 1024 * 1024);
|
/* core services */
|
||||||
Genode::addr_t addr = env.rm().attach(ds);
|
"RM", "PD", "CPU", "IO_MEM", "IO_PORT", "IRQ", "ROM", "LOG",
|
||||||
|
|
||||||
::recv(sd, (void *)addr, 16383, 0);
|
0 /* null-termination */
|
||||||
Genode::String<16383> s((const char *)addr);
|
};
|
||||||
Genode::log(s);
|
MyChild::Parent_services _parent_services { };
|
||||||
|
for (unsigned i = 0; names[i]; i++)
|
||||||
|
new (_heap) MyChild::Parent_service(_parent_services, env, names[i]);
|
||||||
|
|
||||||
Genode::Heap _heap { env.ram(), env.rm() };
|
MyChild mychild(env, _parent_services);
|
||||||
|
|
||||||
Genode::Registry<xyz::Parent_service> parent_services;
|
while(1) {
|
||||||
static const char *names[] = { "PD", "CPU", "LOG", "ROM", 0 };
|
}
|
||||||
for (unsigned i = 0; names[i]; i++)
|
|
||||||
new (_heap) xyz::Parent_service(parent_services, env, names[i]);
|
|
||||||
xyz::MyChild child { env, Genode::Session_label("app"), Genode::Cap_quota{6}, Genode::Ram_quota{1 * 1024 * 1024}, parent_services, ds };
|
|
||||||
|
|
||||||
while(1) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
TARGET = child
|
TARGET = child
|
||||||
SRC_CC = main.cc
|
SRC_CC = main.cc
|
||||||
LIBS = base libc
|
LIBS = base
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
void Component::construct(Genode::Env &env)
|
void Component::construct(Genode::Env &env)
|
||||||
{
|
{
|
||||||
Genode::log("Hello World!");
|
Genode::log("Hello World from hello!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user