hw: turn Native_utcb into restrictive class

fix #958
This commit is contained in:
Martin Stein 2013-11-21 17:26:44 +01:00 committed by Norman Feske
parent 5e3d505ef4
commit 2b8e5d7b19
7 changed files with 43 additions and 31 deletions

View File

@ -57,17 +57,17 @@ namespace Genode
* \param MAX_SIZE maximum size the object is allowed to take
*/
template <size_t MAX_SIZE>
struct Message;
struct Message_tpl;
/**
* Message that is communicated from a thread creator to the new thread
* Information that a thread creator hands out to a new thread
*/
class Start_info;
/**
* Memory region that is exclusive to every thread and known by the kernel
*/
struct Native_utcb;
class Native_utcb;
struct Cap_dst_policy
{
@ -119,7 +119,7 @@ namespace Genode
}
template <Genode::size_t MAX_SIZE>
class Genode::Message
class Genode::Message_tpl
{
private:
@ -150,8 +150,9 @@ class Genode::Message
* \return buf_size size of receive buffer
*/
void info_about_await_request(void * & buf_base, size_t & buf_size)
const
{
buf_base = this;
buf_base = (void *)this;
buf_size = MAX_SIZE;
}
@ -165,10 +166,11 @@ class Genode::Message
*/
void info_about_send_request(void * & msg_base, size_t & msg_size,
void * & buf_base, size_t & buf_size)
const
{
msg_base = this;
msg_base = (void *)this;
msg_size = _size();
buf_base = this;
buf_base = (void *)this;
buf_size = MAX_SIZE;
}
@ -179,8 +181,9 @@ class Genode::Message
* \return msg_size size of complete send-message data
*/
void info_about_send_reply(void * & msg_base, size_t & msg_size)
const
{
msg_base = this;
msg_base = (void *)this;
msg_size = _size();
}
@ -250,19 +253,28 @@ class Genode::Start_info
Native_thread_id thread_id() const { return _thread_id; }
};
struct Genode::Native_utcb
class Genode::Native_utcb
{
enum { SIZE = 1 << MIN_MAPPING_SIZE_LOG2 };
private:
union {
uint8_t data[SIZE];
Message<SIZE> message;
Start_info start_info;
};
uint8_t _data[1 << MIN_MAPPING_SIZE_LOG2];
size_t size() const { return SIZE; }
public:
void * base() const { return (void *)data; }
typedef Message_tpl<sizeof(_data)/sizeof(_data[0])> Message;
/***************
** Accessors **
***************/
Message * message() const { return (Message *)_data; }
Start_info * start_info() const { return (Start_info *)_data; }
size_t size() const { return sizeof(_data)/sizeof(_data[0]); }
void * base() const { return (void *)_data; }
};
#endif /* _BASE__NATIVE_TYPES_H_ */

View File

@ -79,12 +79,12 @@ void Ipc_client::_call()
/* send request and receive corresponding reply */
unsigned const local_name = Ipc_ostream::_dst.local_name();
Native_utcb * const utcb = Thread_base::myself()->utcb();
utcb->message.prepare_send(_snd_msg->buf, _write_offset, local_name);
utcb->message()->prepare_send(_snd_msg->buf, _write_offset, local_name);
if (Kernel::send_request_msg(Ipc_ostream::_dst.dst())) {
PERR("failed to receive reply");
throw Blocking_canceled();
}
utcb->message.finish_receive(_rcv_msg->buf, _rcv_msg->size());
utcb->message()->finish_receive(_rcv_msg->buf, _rcv_msg->size());
/* reset unmarshaller */
_write_offset = _read_offset = RPC_OBJECT_ID_SIZE;
@ -129,7 +129,7 @@ void Ipc_server::_wait()
throw Blocking_canceled();
}
Native_utcb * const utcb = Thread_base::myself()->utcb();
utcb->message.finish_receive(_rcv_msg->buf, _rcv_msg->size());
utcb->message()->finish_receive(_rcv_msg->buf, _rcv_msg->size());
/* update server state */
_prepare_next_reply_wait();
@ -140,7 +140,7 @@ void Ipc_server::_reply()
{
unsigned const local_name = Ipc_ostream::_dst.local_name();
Native_utcb * const utcb = Thread_base::myself()->utcb();
utcb->message.prepare_send(_snd_msg->buf, _write_offset, local_name);
utcb->message()->prepare_send(_snd_msg->buf, _write_offset, local_name);
Kernel::send_reply_msg(0);
}
@ -155,12 +155,12 @@ void Ipc_server::_reply_wait()
/* send reply and receive next request */
unsigned const local_name = Ipc_ostream::_dst.local_name();
Native_utcb * const utcb = Thread_base::myself()->utcb();
utcb->message.prepare_send(_snd_msg->buf, _write_offset, local_name);
utcb->message()->prepare_send(_snd_msg->buf, _write_offset, local_name);
if (Kernel::send_reply_msg(1)) {
PERR("failed to receive request");
throw Blocking_canceled();
}
utcb->message.finish_receive(_rcv_msg->buf, _rcv_msg->size());
utcb->message()->finish_receive(_rcv_msg->buf, _rcv_msg->size());
/* update server state */
_prepare_next_reply_wait();

View File

@ -21,5 +21,5 @@
void Genode::Thread_base::_thread_bootstrap()
{
Native_utcb * const utcb = Thread_base::myself()->utcb();
_tid.thread_id = utcb->start_info.thread_id();
_tid.thread_id = utcb->start_info()->thread_id();
}

View File

@ -234,7 +234,7 @@ extern "C" void kernel()
static Native_utcb utcb;
static Thread t(Priority::MAX, "core");
_main_thread_utcb = &utcb;
_main_thread_utcb->start_info.init(t.id());
_main_thread_utcb->start_info()->init(t.id());
t.ip = (addr_t)CORE_MAIN;;
t.sp = (addr_t)s + STACK_SIZE;
t.init(0, core_id(), &utcb, 1);

View File

@ -452,7 +452,7 @@ void Thread::_call_await_request_msg()
{
void * buf_base;
size_t buf_size;
_utcb_phys->message.info_about_await_request(buf_base, buf_size);
_utcb_phys->message()->info_about_await_request(buf_base, buf_size);
Ipc_node::await_request(buf_base, buf_size);
}
@ -469,8 +469,8 @@ void Thread::_call_send_request_msg()
size_t msg_size;
void * buf_base;
size_t buf_size;
_utcb_phys->message.info_about_send_request(msg_base, msg_size,
buf_base, buf_size);
_utcb_phys->message()->info_about_send_request(msg_base, msg_size,
buf_base, buf_size);
Ipc_node::send_request_await_reply(dst, msg_base, msg_size,
buf_base, buf_size);
}
@ -480,7 +480,7 @@ void Thread::_call_send_reply_msg()
{
void * msg_base;
size_t msg_size;
_utcb_phys->message.info_about_send_reply(msg_base, msg_size);
_utcb_phys->message()->info_about_send_reply(msg_base, msg_size);
Ipc_node::send_reply(msg_base, msg_size);
bool const await_request_msg = user_arg_1();
if (await_request_msg) { _call_await_request_msg(); }

View File

@ -201,7 +201,7 @@ int Platform_thread::start(void * const ip, void * const sp,
return -1;
}
/* start executing new thread */
_utcb_phys->start_info.init(_id);
_utcb_phys->start_info()->init(_id);
_tlb = Kernel::start_thread(_id, cpu_id, _pd_id, _utcb_phys);
if (!_tlb) {
PERR("failed to start thread");

View File

@ -36,7 +36,7 @@ void Genode::platform_main_bootstrap()
static bool main_thread_id_valid = 0;
if (!main_thread_id_valid) {
Native_utcb * const utcb = Thread_base::myself()->utcb();
_main_thread_id = utcb->startup_info.thread_id();
_main_thread_id = utcb->start_info()->thread_id();
main_thread_id_valid = 1;
}
}