Make child an even smaller example, still not working

This commit is contained in:
2019-02-12 16:56:48 +01:00
parent 8c64e21b17
commit dfea92c1cf
4 changed files with 70 additions and 126 deletions

View File

@@ -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

View File

@@ -1,45 +1,29 @@
#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;
#include <loader_session/connection.h>
using namespace Genode;
class MyChild : public Child_policy {
public: public:
Parent_service(Genode::Registry<Parent_service> &registry, Genode::Env &env, typedef Genode::Registered<Genode::Parent_service> Parent_service;
Service::Name const &name) typedef Genode::Registry<Parent_service> Parent_services;
: private:
Genode::Parent_service(env, name), _reg_elem(registry, *this) { } Env &_env;
}; Cap_quota const _cap_quota {50};
Ram_quota const _ram_quota {1 * 1024 * 1024};
class MyChild : public Genode::Child_policy { Parent_services &_parent_services;
Name const _name;
Genode::Env &_env; Child _child;
Genode::Cap_quota const _cap_quota;
Genode::Ram_quota const _ram_quota;
Genode::Registry<xyz::Parent_service> &_parent_services;
Genode::Rpc_entrypoint _child_ep;
Init::Child_policy_provide_rom_file _binary_policy;
Genode::Child _child;
template <typename T> template <typename T>
static Genode::Service *_find_service(Genode::Registry<T> &services, static Genode::Service *_find_service(Genode::Registry<T> &services,
@@ -53,82 +37,57 @@ namespace xyz {
} }
public: public:
MyChild(Env &env, Parent_services &parent_services)
MyChild(Genode::Env &env, :
Genode::Session_label const &label, _env(env), _parent_services(parent_services), _child(_env.rm(), _env.ep().rpc_ep(), *this)
Genode::Cap_quota cap_quota, {}
Genode::Ram_quota ram_quota,
Genode::Registry<xyz::Parent_service> parent_services,
Genode::Dataspace_capability binary) :
_name(label),
_env(env),
_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() { }; ~MyChild() { };
Name name() const override { return _name; } Name name() const override { return "hello"; };
Genode::Pd_session &ref_pd() override { return _env.pd(); } Pd_session &ref_pd() override { return _env.pd(); }
Genode::Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); } Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); }
void init(Genode::Pd_session &session, void init(Pd_session &pd, Pd_session_capability pd_cap) override
Genode::Pd_session_capability cap) override
{ {
session.ref_account(_env.pd_session_cap()); pd.ref_account(ref_pd_cap());
_env.pd().transfer_quota(cap, _cap_quota); ref_pd().transfer_quota(pd_cap, _cap_quota);
_env.pd().transfer_quota(cap, _ram_quota); ref_pd().transfer_quota(pd_cap, _ram_quota);
} }
Genode::Service &resolve_session_request(Genode::Service::Name const &service_name, Genode::Child_policy::Route
Genode::Session_state::Args const &args) override resolve_session_request(Genode::Service::Name const &service_name,
Genode::Session_label const &label) override
{ {
auto route = [&] (Genode::Service &service) {
return Genode::Child_policy::Route { .service = service,
.label = label,
.diag = Genode::Session::Diag() }; };
Genode::Service *service = nullptr; Genode::Service *service = nullptr;
if ((service = _binary_policy.resolve_session_request(service_name.string(), args.string()))) service = _find_service(_parent_services, service_name);
{ return route(*service);
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) void Component::construct(Genode::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);
::connect(sd, (struct sockaddr *)&srv_addr, sizeof(srv_addr));
Genode::Ram_dataspace_capability ds;
ds = env.pd().alloc(1 * 1024 * 1024);
Genode::addr_t addr = env.rm().attach(ds);
::recv(sd, (void *)addr, 16383, 0);
Genode::String<16383> s((const char *)addr);
Genode::log(s);
Genode::Heap _heap {env.ram(), env.rm()}; Genode::Heap _heap {env.ram(), env.rm()};
Genode::Registry<xyz::Parent_service> parent_services; static const char *names[] = {
static const char *names[] = { "PD", "CPU", "LOG", "ROM", 0 }; /* core services */
"RM", "PD", "CPU", "IO_MEM", "IO_PORT", "IRQ", "ROM", "LOG",
0 /* null-termination */
};
MyChild::Parent_services _parent_services { };
for (unsigned i = 0; names[i]; i++) for (unsigned i = 0; names[i]; i++)
new (_heap) xyz::Parent_service(parent_services, env, names[i]); new (_heap) MyChild::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 };
MyChild mychild(env, _parent_services);
while(1) { while(1) {
} }
});
} }

View File

@@ -1,3 +1,3 @@
TARGET = child TARGET = child
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base libc LIBS = base

View File

@@ -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!");
} }