os: fix race in 'os/child_policy_dynamic_rom.h'

This commit is contained in:
Norman Feske 2014-09-30 16:04:06 +02:00
parent c48a4ebce8
commit 3a1ecdd5a7
1 changed files with 13 additions and 0 deletions

View File

@ -28,6 +28,15 @@ namespace Genode {
Ram_session *_ram;
/*
* The ROM module may be written and consumed by different threads,
* e.g., written by the main thread and consumed by the child's
* entrypoint that manages the local ROM service for handing out a
* dynamic config. Hence, the '_lock' is used to synchronize the
* 'load' and 'dataspace' functions.
*/
Lock _lock;
/*
* We keep two dataspaces around. The foreground ('_fg') dataspace
* is the one we present to the client. While the foreground
@ -87,6 +96,8 @@ namespace Genode {
*/
void load(void const *data, size_t data_len)
{
Lock::Guard guard(_lock);
if (!_ram) {
PERR("Error: No backing store for loading ROM data");
return;
@ -110,6 +121,8 @@ namespace Genode {
Rom_dataspace_capability dataspace()
{
Lock::Guard guard(_lock);
if (!_fg.size() && !_bg_has_pending_data) {
PERR("Error: no data loaded");
return Rom_dataspace_capability();