2013-07-05 09:44:55 +00:00
|
|
|
/*
|
2013-08-20 19:24:52 +00:00
|
|
|
* \brief Guard to save a UTCB and restore it during guard destruction
|
2013-07-05 09:44:55 +00:00
|
|
|
* \author Alexander Boettcher
|
|
|
|
* \date 2013-07-05
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-07-05 09:44:55 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-07-05 09:44:55 +00:00
|
|
|
*/
|
|
|
|
|
2013-08-20 19:24:52 +00:00
|
|
|
#ifndef _INCLUDE__VMM__UTCB_GUARD_H_
|
|
|
|
#define _INCLUDE__VMM__UTCB_GUARD_H_
|
2013-07-05 09:44:55 +00:00
|
|
|
|
2013-08-20 19:24:52 +00:00
|
|
|
/* Genode includes */
|
2013-07-05 09:44:55 +00:00
|
|
|
#include <base/printf.h>
|
2013-08-20 19:24:52 +00:00
|
|
|
#include <util/string.h>
|
|
|
|
|
|
|
|
/* NOVA syscalls */
|
2013-07-05 09:44:55 +00:00
|
|
|
#include <nova/syscalls.h>
|
|
|
|
|
|
|
|
|
2013-08-20 19:24:52 +00:00
|
|
|
namespace Vmm {
|
|
|
|
using namespace Genode;
|
|
|
|
class Utcb_guard;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Vmm::Utcb_guard
|
|
|
|
{
|
2016-03-08 15:59:43 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
struct Utcb_backup { char buf[Nova::Utcb::size()]; };
|
|
|
|
|
2013-07-05 09:44:55 +00:00
|
|
|
private:
|
2013-08-20 19:24:52 +00:00
|
|
|
|
2016-03-08 15:59:43 +00:00
|
|
|
Utcb_backup &_backup_utcb;
|
2013-07-05 09:44:55 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-03-08 15:59:43 +00:00
|
|
|
Utcb_guard(Utcb_backup &backup_utcb) : _backup_utcb(backup_utcb)
|
2013-07-05 09:44:55 +00:00
|
|
|
{
|
|
|
|
Nova::Utcb *utcb =
|
2016-05-04 10:27:17 +00:00
|
|
|
reinterpret_cast<Nova::Utcb *>(Thread::myself()->utcb());
|
2013-07-05 09:44:55 +00:00
|
|
|
|
2017-04-12 09:55:08 +00:00
|
|
|
unsigned header_len = (char *)utcb->msg() - (char *)utcb;
|
2013-07-05 09:44:55 +00:00
|
|
|
unsigned len = header_len + utcb->msg_words() * sizeof(Nova::mword_t);
|
|
|
|
Genode::memcpy(&_backup_utcb, utcb, len);
|
|
|
|
|
|
|
|
if (utcb->msg_items())
|
2013-08-20 19:24:52 +00:00
|
|
|
PWRN("Error: msg items on UTCB are not saved and restored!");
|
2013-07-05 09:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Utcb_guard()
|
|
|
|
{
|
|
|
|
Nova::Utcb *utcb = reinterpret_cast<Nova::Utcb *>(&_backup_utcb);
|
|
|
|
|
2017-04-12 09:55:08 +00:00
|
|
|
unsigned header_len = (char *)utcb->msg() - (char *)utcb;
|
2013-07-05 09:44:55 +00:00
|
|
|
unsigned len = header_len + utcb->msg_words() * sizeof(Nova::mword_t);
|
2016-05-04 10:27:17 +00:00
|
|
|
Genode::memcpy(Thread::myself()->utcb(), utcb, len);
|
2013-07-05 09:44:55 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-20 19:24:52 +00:00
|
|
|
#endif /* _INCLUDE__VMM__UTCB_GUARD_H_ */
|