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 {
|
||||
core init
|
||||
drivers/timer drivers/nic
|
||||
lib/vfs/lwip
|
||||
app/child app/hello
|
||||
}
|
||||
|
||||
@@ -54,15 +53,8 @@ set config {
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides> <service name="Timer"/> </provides>
|
||||
</start>
|
||||
<start name="child" caps="200">
|
||||
<start name="child" caps="300">
|
||||
<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>}
|
||||
|
||||
append_if [have_spec gpio] config "
|
||||
@@ -85,13 +77,6 @@ append_if $use_usb_driver 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 {
|
||||
</config>
|
||||
}
|
||||
@@ -102,10 +87,10 @@ install_config $config
|
||||
# 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_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
|
||||
|
||||
@@ -1,45 +1,29 @@
|
||||
#include <base/component.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 <base/child.h>
|
||||
#include <init/child_policy.h>
|
||||
|
||||
namespace xyz {
|
||||
class Parent_service : public Genode::Parent_service {
|
||||
private:
|
||||
Genode::Registry<Parent_service>::Element _reg_elem;
|
||||
#include <rom_session/connection.h>
|
||||
|
||||
public:
|
||||
Parent_service(Genode::Registry<Parent_service> ®istry, Genode::Env &env,
|
||||
Service::Name const &name)
|
||||
:
|
||||
Genode::Parent_service(env, name), _reg_elem(registry, *this) { }
|
||||
};
|
||||
#include <loader_session/connection.h>
|
||||
|
||||
class MyChild : public Genode::Child_policy {
|
||||
Name const _name;
|
||||
using namespace Genode;
|
||||
|
||||
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;
|
||||
Genode::Ram_quota const _ram_quota;
|
||||
Parent_services &_parent_services;
|
||||
|
||||
Genode::Registry<xyz::Parent_service> &_parent_services;
|
||||
|
||||
Genode::Rpc_entrypoint _child_ep;
|
||||
|
||||
Init::Child_policy_provide_rom_file _binary_policy;
|
||||
|
||||
Genode::Child _child;
|
||||
Child _child;
|
||||
|
||||
template <typename T>
|
||||
static Genode::Service *_find_service(Genode::Registry<T> &services,
|
||||
@@ -52,83 +36,58 @@ namespace xyz {
|
||||
return service;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
MyChild(Genode::Env &env,
|
||||
Genode::Session_label const &label,
|
||||
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)
|
||||
{ };
|
||||
public:
|
||||
MyChild(Env &env, Parent_services &parent_services)
|
||||
:
|
||||
_env(env), _parent_services(parent_services), _child(_env.rm(), _env.ep().rpc_ep(), *this)
|
||||
{}
|
||||
~MyChild() { };
|
||||
|
||||
Name name() const override { return _name; }
|
||||
Name name() const override { return "hello"; };
|
||||
|
||||
Genode::Pd_session &ref_pd() override { return _env.pd(); }
|
||||
Genode::Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); }
|
||||
Pd_session &ref_pd() override { return _env.pd(); }
|
||||
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
|
||||
void init(Pd_session &pd, Pd_session_capability pd_cap) override
|
||||
{
|
||||
session.ref_account(_env.pd_session_cap());
|
||||
_env.pd().transfer_quota(cap, _cap_quota);
|
||||
_env.pd().transfer_quota(cap, _ram_quota);
|
||||
pd.ref_account(ref_pd_cap());
|
||||
ref_pd().transfer_quota(pd_cap, _cap_quota);
|
||||
ref_pd().transfer_quota(pd_cap, _ram_quota);
|
||||
}
|
||||
|
||||
Genode::Service &resolve_session_request(Genode::Service::Name const &service_name,
|
||||
Genode::Session_state::Args const &args) override
|
||||
Genode::Child_policy::Route
|
||||
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;
|
||||
if ((service = _binary_policy.resolve_session_request(service_name.string(), args.string())))
|
||||
{
|
||||
Genode::log("Service from policy: ", service_name, "/", args);
|
||||
return *service;
|
||||
service = _find_service(_parent_services, service_name);
|
||||
return route(*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([&] () {
|
||||
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");
|
||||
Genode::log("Hello World from child!");
|
||||
|
||||
int sd = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
::connect(sd, (struct sockaddr *)&srv_addr, sizeof(srv_addr));
|
||||
Genode::Heap _heap {env.ram(), env.rm()};
|
||||
|
||||
Genode::Ram_dataspace_capability ds;
|
||||
ds = env.pd().alloc(1 * 1024 * 1024);
|
||||
Genode::addr_t addr = env.rm().attach(ds);
|
||||
static const char *names[] = {
|
||||
/* core services */
|
||||
"RM", "PD", "CPU", "IO_MEM", "IO_PORT", "IRQ", "ROM", "LOG",
|
||||
|
||||
::recv(sd, (void *)addr, 16383, 0);
|
||||
Genode::String<16383> s((const char *)addr);
|
||||
Genode::log(s);
|
||||
|
||||
Genode::Heap _heap { env.ram(), env.rm() };
|
||||
|
||||
Genode::Registry<xyz::Parent_service> parent_services;
|
||||
static const char *names[] = { "PD", "CPU", "LOG", "ROM", 0 };
|
||||
0 /* null-termination */
|
||||
};
|
||||
MyChild::Parent_services _parent_services { };
|
||||
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 };
|
||||
new (_heap) MyChild::Parent_service(_parent_services, env, names[i]);
|
||||
|
||||
MyChild mychild(env, _parent_services);
|
||||
|
||||
while(1) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
TARGET = child
|
||||
SRC_CC = main.cc
|
||||
LIBS = base libc
|
||||
LIBS = base
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
|
||||
void Component::construct(Genode::Env &env)
|
||||
{
|
||||
Genode::log("Hello World!");
|
||||
Genode::log("Hello World from hello!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user