2011-12-22 16:19:25 +01:00
|
|
|
/*
|
|
|
|
* \brief Fiasco pager framework
|
|
|
|
* \author Norman Feske
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2006-07-14
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 21:44:47 +01:00
|
|
|
* Copyright (C) 2006-2013 Genode Labs GmbH
|
2011-12-22 16:19:25 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Genode includes */
|
|
|
|
#include <base/env.h>
|
|
|
|
#include <base/printf.h>
|
|
|
|
#include <base/lock.h>
|
|
|
|
|
2015-06-19 14:58:18 +02:00
|
|
|
/* Core includes */
|
|
|
|
#include <pager.h>
|
|
|
|
|
2011-12-22 16:19:25 +01:00
|
|
|
/* Fiasco.OC includes */
|
|
|
|
namespace Fiasco {
|
|
|
|
#include <l4/sys/factory.h>
|
|
|
|
#include <l4/sys/ipc.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
|
2015-07-29 10:58:17 +02:00
|
|
|
void Pager_entrypoint::entry()
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
bool reply_pending = false;
|
|
|
|
while (1) {
|
|
|
|
|
|
|
|
if (reply_pending)
|
2015-07-29 10:58:17 +02:00
|
|
|
_pager.reply_and_wait_for_fault();
|
2011-12-22 16:19:25 +01:00
|
|
|
else
|
2015-07-29 10:58:17 +02:00
|
|
|
_pager.wait_for_fault();
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
reply_pending = false;
|
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
apply(_pager.badge(), [&] (Pager_object *obj) {
|
|
|
|
/* the pager_object might be destroyed, while we got the message */
|
|
|
|
if (!obj) {
|
|
|
|
PWRN("No pager object found!");
|
|
|
|
return;
|
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
switch (_pager.msg_type()) {
|
|
|
|
|
|
|
|
case Ipc_pager::PAGEFAULT:
|
|
|
|
case Ipc_pager::EXCEPTION:
|
|
|
|
{
|
|
|
|
if (_pager.is_exception()) {
|
|
|
|
Lock::Guard guard(obj->state.lock);
|
|
|
|
_pager.get_regs(&obj->state);
|
|
|
|
obj->state.exceptions++;
|
|
|
|
obj->state.in_exception = true;
|
|
|
|
obj->submit_exception_signal();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle request */
|
|
|
|
if (obj->pager(_pager)) {
|
|
|
|
/* could not resolv - leave thread in pagefault */
|
|
|
|
PDBG("Could not resolve pf=%p ip=%p",
|
|
|
|
(void*)_pager.fault_addr(), (void*)_pager.fault_ip());
|
|
|
|
} else {
|
2016-01-23 14:42:55 +01:00
|
|
|
_pager.set_reply_dst(Native_thread(obj->badge()));
|
2015-08-10 13:34:16 +02:00
|
|
|
reply_pending = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
case Ipc_pager::WAKE_UP:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We got a request from one of cores region-manager sessions
|
|
|
|
* to answer the pending page fault of a resolved region-manager
|
|
|
|
* client, or to resume a previously paused thread. Hence, we
|
|
|
|
* have to send a reply to the specified thread and answer the
|
|
|
|
* call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* send reply to the caller */
|
|
|
|
_pager.set_reply_dst(Native_thread());
|
|
|
|
_pager.acknowledge_wakeup();
|
|
|
|
|
|
|
|
{
|
|
|
|
Lock::Guard guard(obj->state.lock);
|
|
|
|
/* revert exception flag */
|
|
|
|
obj->state.in_exception = false;
|
|
|
|
/* set new register contents */
|
|
|
|
_pager.set_regs(obj->state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send wake up message to requested thread */
|
2016-01-23 14:42:55 +01:00
|
|
|
_pager.set_reply_dst(Native_thread(obj->badge()));
|
2015-08-10 13:34:16 +02:00
|
|
|
_pager.acknowledge_exception();
|
|
|
|
break;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
/*
|
|
|
|
* Handle exceptions that are artificially generated by the pause
|
|
|
|
* function of the CPU service.
|
|
|
|
*/
|
|
|
|
case Ipc_pager::PAUSE:
|
2011-12-22 16:19:25 +01:00
|
|
|
{
|
|
|
|
Lock::Guard guard(obj->state.lock);
|
2015-08-10 13:34:16 +02:00
|
|
|
_pager.get_regs(&obj->state);
|
|
|
|
obj->state.exceptions++;
|
|
|
|
obj->state.in_exception = true;
|
2011-12-22 16:19:25 +01:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
/*
|
|
|
|
* It might occur that the thread raises an exception,
|
|
|
|
* after it already got resumed by the cpu_session, in
|
|
|
|
* that case we unblock it immediately.
|
|
|
|
*/
|
|
|
|
if (!obj->state.paused) {
|
2016-01-23 14:42:55 +01:00
|
|
|
_pager.set_reply_dst(Native_thread(obj->badge()));
|
2015-08-10 13:34:16 +02:00
|
|
|
reply_pending = true;
|
|
|
|
}
|
|
|
|
break;
|
2011-12-22 16:19:25 +01:00
|
|
|
}
|
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
default:
|
|
|
|
PERR("Got unknown message type %x!", _pager.msg_type());
|
|
|
|
}
|
|
|
|
});
|
2011-12-22 16:19:25 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Fiasco.OC: several capability ref-counter fixes.
This commit fixes several issues that were triggered e.g. by the
'noux_tool_chain' run-script (fix #208 in part). The following problems
are tackled:
* Don't reference count capability selectors within a task that are actually
controlled by core (all beneath 0x200000), because it's undecideable which
"version" of a capability selector we currently use, e.g. a thread gets
destroyed and a new one gets created immediately some other thread might
have a Native_capability pointing to the already destroyed thread's gate
capability-slot, that is now a new valid one (the one of the new thread)
* In core we cannot invalidate and remove a capability from the so called
Cap_map before each reference to it is destroyed, so don't do this in
Cap_session_component::free, but only reference-decrement within there,
the actual removal can only be done in Cap_map::remove. Because core also
has to invalidate a capability to be removed in all protection-domains
we have to implement a core specific Cap_map::remove method
* When a capability gets inserted into the Cap_map, and we detect an old
invalid entry with the dame id in the tree, don't just overmap that
invalid entry (as there exist remaining references to it), but just remove
it from the tree and allocate an new entry.
* Use the Cap_session_component interface to free a Pager_object when it
gets dissolved, as its also used for allocation
2012-08-29 15:52:18 +02:00
|
|
|
void Pager_entrypoint::dissolve(Pager_object *obj)
|
|
|
|
{
|
|
|
|
/* cleanup at cap session */
|
2016-01-19 20:24:22 +01:00
|
|
|
_cap_factory.free(obj->Object_pool<Pager_object>::Entry::cap());
|
Fiasco.OC: several capability ref-counter fixes.
This commit fixes several issues that were triggered e.g. by the
'noux_tool_chain' run-script (fix #208 in part). The following problems
are tackled:
* Don't reference count capability selectors within a task that are actually
controlled by core (all beneath 0x200000), because it's undecideable which
"version" of a capability selector we currently use, e.g. a thread gets
destroyed and a new one gets created immediately some other thread might
have a Native_capability pointing to the already destroyed thread's gate
capability-slot, that is now a new valid one (the one of the new thread)
* In core we cannot invalidate and remove a capability from the so called
Cap_map before each reference to it is destroyed, so don't do this in
Cap_session_component::free, but only reference-decrement within there,
the actual removal can only be done in Cap_map::remove. Because core also
has to invalidate a capability to be removed in all protection-domains
we have to implement a core specific Cap_map::remove method
* When a capability gets inserted into the Cap_map, and we detect an old
invalid entry with the dame id in the tree, don't just overmap that
invalid entry (as there exist remaining references to it), but just remove
it from the tree and allocate an new entry.
* Use the Cap_session_component interface to free a Pager_object when it
gets dissolved, as its also used for allocation
2012-08-29 15:52:18 +02:00
|
|
|
|
2015-08-10 13:34:16 +02:00
|
|
|
remove(obj);
|
Fiasco.OC: several capability ref-counter fixes.
This commit fixes several issues that were triggered e.g. by the
'noux_tool_chain' run-script (fix #208 in part). The following problems
are tackled:
* Don't reference count capability selectors within a task that are actually
controlled by core (all beneath 0x200000), because it's undecideable which
"version" of a capability selector we currently use, e.g. a thread gets
destroyed and a new one gets created immediately some other thread might
have a Native_capability pointing to the already destroyed thread's gate
capability-slot, that is now a new valid one (the one of the new thread)
* In core we cannot invalidate and remove a capability from the so called
Cap_map before each reference to it is destroyed, so don't do this in
Cap_session_component::free, but only reference-decrement within there,
the actual removal can only be done in Cap_map::remove. Because core also
has to invalidate a capability to be removed in all protection-domains
we have to implement a core specific Cap_map::remove method
* When a capability gets inserted into the Cap_map, and we detect an old
invalid entry with the dame id in the tree, don't just overmap that
invalid entry (as there exist remaining references to it), but just remove
it from the tree and allocate an new entry.
* Use the Cap_session_component interface to free a Pager_object when it
gets dissolved, as its also used for allocation
2012-08-29 15:52:18 +02:00
|
|
|
}
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
Pager_capability Pager_entrypoint::manage(Pager_object *obj)
|
|
|
|
{
|
|
|
|
using namespace Fiasco;
|
|
|
|
|
2016-01-19 20:24:22 +01:00
|
|
|
Native_capability cap(_cap_factory.alloc(Thread_base::_thread_cap));
|
2011-12-22 16:19:25 +01:00
|
|
|
|
|
|
|
/* add server object to object pool */
|
|
|
|
obj->cap(cap);
|
|
|
|
insert(obj);
|
|
|
|
|
|
|
|
/* return capability that uses the object id as badge */
|
|
|
|
return reinterpret_cap_cast<Pager_object>(cap);
|
|
|
|
}
|