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