mirror of
https://github.com/genodelabs/genode.git
synced 2025-05-30 14:14:31 +00:00
parent
da5441292a
commit
0743ea87ed
@ -22,6 +22,7 @@
|
|||||||
#include <base/child.h>
|
#include <base/child.h>
|
||||||
#include <rm_session/connection.h>
|
#include <rm_session/connection.h>
|
||||||
#include <base/attached_ram_dataspace.h>
|
#include <base/attached_ram_dataspace.h>
|
||||||
|
#include <base/attached_rom_dataspace.h>
|
||||||
|
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
|
||||||
@ -30,7 +31,12 @@ using namespace Genode;
|
|||||||
** Child **
|
** Child **
|
||||||
***********/
|
***********/
|
||||||
|
|
||||||
enum { MANAGED_ADDR = 0x10000000 };
|
enum {
|
||||||
|
MANAGED_ADDR = 0x10000000,
|
||||||
|
STOP_TEST = 0xdead,
|
||||||
|
READ_TEST = 0x12345,
|
||||||
|
WRITE_TEST = READ_TEST - 1
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
void read_at(addr_t addr)
|
void read_at(addr_t addr)
|
||||||
@ -40,9 +46,24 @@ void read_at(addr_t addr)
|
|||||||
log("read value ", Hex(value));
|
log("read value ", Hex(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void modify(addr_t addr)
|
bool modify(addr_t addr)
|
||||||
{
|
{
|
||||||
log("modify memory at ", Hex(addr), " to ", Hex(++(*(int *)addr)));
|
addr_t const value = *(addr_t volatile *)addr;
|
||||||
|
|
||||||
|
if (value == STOP_TEST)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (value != READ_TEST + 1)
|
||||||
|
log("modify memory at ", Hex(addr), " to ",
|
||||||
|
Hex(++(*(addr_t volatile *)addr)), " ", Hex(value));
|
||||||
|
|
||||||
|
if (value != READ_TEST && value != READ_TEST + 1)
|
||||||
|
{
|
||||||
|
Genode::error("could modify ROM !!! ", Hex(value));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_child()
|
void main_child()
|
||||||
@ -52,8 +73,7 @@ void main_child()
|
|||||||
/* perform illegal access */
|
/* perform illegal access */
|
||||||
read_at(MANAGED_ADDR);
|
read_at(MANAGED_ADDR);
|
||||||
|
|
||||||
while (true)
|
while (modify(MANAGED_ADDR));
|
||||||
modify(MANAGED_ADDR);
|
|
||||||
|
|
||||||
log("--- child role of region-manager fault test finished ---");
|
log("--- child role of region-manager fault test finished ---");
|
||||||
}
|
}
|
||||||
@ -137,6 +157,8 @@ struct Main_parent
|
|||||||
|
|
||||||
Heap _heap { _env.ram(), _env.rm() };
|
Heap _heap { _env.ram(), _env.rm() };
|
||||||
|
|
||||||
|
Genode::Rom_connection _rom { _env, "config"};
|
||||||
|
|
||||||
/* parent services */
|
/* parent services */
|
||||||
struct Parent_services : Test_child_policy::Parent_services
|
struct Parent_services : Test_child_policy::Parent_services
|
||||||
{
|
{
|
||||||
@ -170,12 +192,25 @@ struct Main_parent
|
|||||||
|
|
||||||
long volatile &_child_value() { return *_ds.local_addr<long volatile>(); }
|
long volatile &_child_value() { return *_ds.local_addr<long volatile>(); }
|
||||||
|
|
||||||
|
void _check_for_write_fault(addr_t const child_virt_addr)
|
||||||
|
{
|
||||||
|
if (_child_value() == WRITE_TEST) {
|
||||||
|
_child_value() = STOP_TEST;
|
||||||
|
Genode::log("got fault on ROM");
|
||||||
|
_env.parent().exit(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Genode::log("test WRITE fault on ROM (config)");
|
||||||
|
|
||||||
|
_child_value() = WRITE_TEST;
|
||||||
|
|
||||||
|
_address_space.attach_at(_rom.dataspace(), child_virt_addr);
|
||||||
|
}
|
||||||
|
|
||||||
void _handle_fault()
|
void _handle_fault()
|
||||||
{
|
{
|
||||||
if (_fault_cnt++ == 4) {
|
enum { FAULT_CNT = 4 };
|
||||||
log("--- parent role of region-manager fault test finished ---");
|
|
||||||
_env.parent().exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
log("received region-map fault signal, request fault state");
|
log("received region-map fault signal, request fault state");
|
||||||
|
|
||||||
@ -188,7 +223,7 @@ struct Main_parent
|
|||||||
|
|
||||||
log("rm session state is ", state_name, ", pf_addr=", Hex(state.addr));
|
log("rm session state is ", state_name, ", pf_addr=", Hex(state.addr));
|
||||||
|
|
||||||
/* ignore spuriuous fault signal */
|
/* ignore spurious fault signal */
|
||||||
if (state.type == Region_map::State::READY) {
|
if (state.type == Region_map::State::READY) {
|
||||||
log("ignoring spurious fault signal");
|
log("ignoring spurious fault signal");
|
||||||
return;
|
return;
|
||||||
@ -196,14 +231,23 @@ struct Main_parent
|
|||||||
|
|
||||||
addr_t child_virt_addr = state.addr & ~(4096 - 1);
|
addr_t child_virt_addr = state.addr & ~(4096 - 1);
|
||||||
|
|
||||||
|
if (_fault_cnt++ >= FAULT_CNT) {
|
||||||
|
if (_fault_cnt == FAULT_CNT)
|
||||||
|
log("--- parent role of region-manager fault test finished ---");
|
||||||
|
|
||||||
|
_check_for_write_fault(child_virt_addr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* allocate dataspace to resolve the fault */
|
/* allocate dataspace to resolve the fault */
|
||||||
log("attach dataspace to the child at ", Hex(child_virt_addr));
|
log("attach dataspace to the child at ", Hex(child_virt_addr));
|
||||||
_child_value() = 0x1234;
|
|
||||||
|
_child_value() = READ_TEST;
|
||||||
|
|
||||||
_address_space.attach_at(_ds.cap(), child_virt_addr);
|
_address_space.attach_at(_ds.cap(), child_virt_addr);
|
||||||
|
|
||||||
/* poll until our child modifies the dataspace content */
|
/* poll until our child modifies the dataspace content */
|
||||||
while (_child_value() == 0x1234);
|
while (_child_value() == READ_TEST);
|
||||||
|
|
||||||
log("child modified dataspace content, new value is ",
|
log("child modified dataspace content, new value is ",
|
||||||
Hex(_child_value()));
|
Hex(_child_value()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user