-
-
Save zgzollers/397f56b66179f3276e048be8a8a7a543 to your computer and use it in GitHub Desktop.
Code for parent component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <base/component.h> | |
#include <base/log.h> | |
#include <base/child.h> | |
namespace Tutorial { struct Child; } | |
struct Tutorial::Child : Genode::Child_policy | |
{ | |
Genode::Env& _env; | |
Child_policy::Name _name; | |
Genode::Heap _heap { _env.ram(), _env.rm() }; | |
Genode::Child _child { _env.rm(), _env.ep().rpc_ep(), *this }; | |
Child_policy::Name name() const override | |
{ | |
return _name; | |
} | |
Child_policy::Route resolve_session_request(Genode::Service::Name const& name, Genode::Session_label const& label, Genode::Session::Diag const diag) override | |
{ | |
Genode::log("Child requested session: ", name); | |
// I feel like this line may be causing issues. I am aware that not keeping track of the pointers | |
// is bad, but I don't have a great solution for that either. | |
Child_policy::Route route = { *new (_heap) Genode::Parent_service(_env, name), label, diag }; | |
return route; | |
} | |
Genode::Pd_session& ref_pd() override | |
{ | |
return _env.pd(); | |
} | |
Genode::Pd_session_capability ref_pd_cap() const override | |
{ | |
return _env.pd_session_cap(); | |
} | |
void resource_request(Genode::Parent::Resource_args const& args) override | |
{ | |
Genode::log("Child requested resource: ", args); | |
} | |
void init(Genode::Pd_session& pd, Genode::Pd_session_capability pd_cap) override | |
{ | |
pd.ref_account(ref_pd_cap()); | |
ref_pd().transfer_quota(pd_cap, Genode::Cap_quota{_env.pd().avail_caps().value >> 1}); | |
ref_pd().transfer_quota(pd_cap, Genode::Ram_quota{_env.pd().avail_ram().value >> 1}); | |
Genode::log("Transfered initial resource quotas to child"); | |
} | |
Child(Genode::Env& env, Child_policy::Name name) : _env(env), _name(name) { } | |
}; | |
namespace Tutorial { struct Main; } | |
struct Tutorial::Main | |
{ | |
Genode::Env& _env; | |
Main(Genode::Env& env) : _env(env) | |
{ | |
Tutorial::Child child(_env, "hello"); | |
} | |
}; | |
void Component::construct(Genode::Env& env) | |
{ | |
static Tutorial::Main main(env); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build { core init app/parent app/hello timer } | |
create_boot_directory | |
install_config { | |
<config verbose="true"> | |
<parent-provides> | |
<service name="LOG"/> | |
<service name="PD"/> | |
<service name="CPU"/> | |
<service name="ROM"/> | |
</parent-provides> | |
<default-route> | |
<any-service> <parent/> <any-child/> </any-service> | |
</default-route> | |
<default caps="60"/> | |
<start name="timer"> | |
<resource name="RAM" quantum="1M"/> | |
<provides> <service name="Timer"/> </provides> | |
</start> | |
<start name="parent" caps="100"> | |
<resource name="RAM" quantum="100M"/> | |
</start> | |
</config> | |
} | |
build_boot_image { core init parent hello timer } | |
append qemu_args "-nographic -m 256" | |
run_genode_until forever |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment