seoul: use utcb guard

Forgetting to restore the old utcb content results in hard to debug bugs.
Save only the amount of word items which are actually on the UTCB.

Issue #806
This commit is contained in:
Alexander Boettcher 2013-07-05 11:44:55 +02:00 committed by Norman Feske
parent b9e48e94ec
commit b4283c9121
2 changed files with 57 additions and 4 deletions

View File

@ -28,6 +28,7 @@
/* local includes */
#include <disk.h>
#include <utcb_guard.h>
static Genode::Native_utcb utcb_backup;
@ -67,7 +68,7 @@ void Vancouver_disk::entry()
bool Vancouver_disk::receive(MessageDisk &msg)
{
utcb_backup = *Genode::Thread_base::myself()->utcb();
Utcb_guard guard(utcb_backup);
if (msg.disknr >= MAX_DISKS)
Logging::panic("You configured more disks than supported.\n");
@ -125,7 +126,6 @@ bool Vancouver_disk::receive(MessageDisk &msg)
MessageDiskCommit ro(msg.disknr, msg.usertag,
MessageDisk::DISK_STATUS_DEVICE);
_motherboard()->bus_diskcommit.send(ro);
*Genode::Thread_base::myself()->utcb() = utcb_backup;
return true;
}
@ -207,10 +207,8 @@ bool Vancouver_disk::receive(MessageDisk &msg)
default:
Logging::printf("Got MessageDisk type %x\n", msg.type);
*Genode::Thread_base::myself()->utcb() = utcb_backup;
return false;
}
*Genode::Thread_base::myself()->utcb() = utcb_backup;
return true;
}

View File

@ -0,0 +1,55 @@
/*
* \brief Guard to save a utcb and restore it during Guard desctruction
* \author Alexander Boettcher
* \date 2013-07-05
*/
/*
* Copyright (C) 2013 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _SEOUL_UTCB_GUARD_H_
#define _SEOUL_UTCB_GUARD_H_
#include <base/printf.h>
#include <nova/syscalls.h>
class Utcb_guard {
private:
Genode::Native_utcb &_backup_utcb;
public:
Utcb_guard(Genode::Native_utcb &backup_utcb)
: _backup_utcb(backup_utcb)
{
using namespace Genode;
Nova::Utcb *utcb =
reinterpret_cast<Nova::Utcb *>(Thread_base::myself()->utcb());
unsigned header_len = (char *)utcb->msg - (char *)utcb;
unsigned len = header_len + utcb->msg_words() * sizeof(Nova::mword_t);
Genode::memcpy(&_backup_utcb, utcb, len);
if (utcb->msg_items())
PWRN("Error: msg items on UTCB are not saved and restored !!!");
}
~Utcb_guard()
{
using namespace Genode;
Nova::Utcb *utcb = reinterpret_cast<Nova::Utcb *>(&_backup_utcb);
unsigned header_len = (char *)utcb->msg - (char *)utcb;
unsigned len = header_len + utcb->msg_words() * sizeof(Nova::mword_t);
Genode::memcpy(Thread_base::myself()->utcb(), utcb, len);
}
};
#endif /* _SEOUL_UTCB_GUARD_H_ */