From 19398159e1f0e2b12456cf0d5116b756237a088c Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 19 Dec 2012 15:49:44 +0100 Subject: [PATCH] base-hw: use Genode::memcpy in base/ipc.cc Ref #583 --- base-hw/include/base/native_types.h | 14 ++---- base-hw/src/base/ipc.cc | 77 ++++++++++------------------- 2 files changed, 28 insertions(+), 63 deletions(-) diff --git a/base-hw/include/base/native_types.h b/base-hw/include/base/native_types.h index e411a0edcd..832e3accf8 100644 --- a/base-hw/include/base/native_types.h +++ b/base-hw/include/base/native_types.h @@ -86,25 +86,17 @@ namespace Genode struct Native_utcb { /* UTCB payload */ - union { - char bytes[1< utcb->size() || size > msgbuf->size()) { + kernel_log() << __PRETTY_FUNCTION__ << ": truncate message\n"; + size = utcb->size() < msgbuf->size() ? utcb->size() : msgbuf->size(); + } +} /** * Copy message payload to message buffer */ -static void copy_utcb_to_msgbuf(Msgbuf_base * const receive_buffer, - size_t const message_size) +static void utcb_to_msgbuf(Msgbuf_base * const msgbuf, size_t size) { - /* log data that is received via IPC */ - enum { VERBOSE = 0 }; - - /* get pointers and message attributes */ - Native_utcb * const utcb = Thread_base::myself()->utcb(); - unsigned * const msgbuf = (unsigned *)receive_buffer->buf; - size_t const message_wsize = size_in_words(message_size); - - /* assertions, avoid 'printf' in here, it may lead to infinite recursion */ - if (message_wsize > size_in_words(utcb->size())) - { - kernel_log() << __PRETTY_FUNCTION__ << ": Oversized message\n"; - while (1) ; - } - /* fill message buffer with message */ - for (unsigned i=0; i < message_wsize; i++) - msgbuf[i] = *utcb->word(i); + Native_utcb * const utcb = Thread_base::myself()->utcb(); + limit_msg_size(msgbuf, utcb, size); + memcpy(msgbuf->buf, utcb->base(), size); } /** * Copy message payload to the UTCB */ -static void copy_msgbuf_to_utcb(Msgbuf_base * const send_buffer, - size_t const message_size, - unsigned const local_name) +static void msgbuf_to_utcb(Msgbuf_base * const msgbuf, size_t size, + unsigned const local_name) { - /* log data that is send via IPC */ - enum { VERBOSE = 0 }; - - /* get pointers and message attributes */ - Native_utcb * const utcb = Thread_base::myself()->utcb(); - unsigned * const msgbuf = (unsigned *)send_buffer->buf; - size_t const message_wsize = size_in_words(message_size); - - /* assertions, avoid 'printf' in here, it may lead to infinite recursion */ - if (message_wsize > size_in_words(utcb->size())) - { - kernel_log() << __PRETTY_FUNCTION__ << ": Oversized message\n"; - while (1) ; - } - /* address message to an object that the targeted thread knows */ - *utcb->word(0) = local_name; - - /* write message payload */ - for (unsigned i = 1; i < message_wsize; i++) - *utcb->word(i) = msgbuf[i]; + Native_utcb * const utcb = Thread_base::myself()->utcb(); + *(unsigned *)utcb->base() = local_name; + size += sizeof(local_name); + limit_msg_size(msgbuf, utcb, size); + memcpy((unsigned *)utcb->base() + 1, (unsigned *)msgbuf->buf + 1, size); } @@ -144,10 +119,9 @@ void Ipc_client::_call() using namespace Kernel; /* send request and receive reply */ - copy_msgbuf_to_utcb(_snd_msg, _write_offset, - Ipc_ostream::_dst.local_name()); + msgbuf_to_utcb(_snd_msg, _write_offset, Ipc_ostream::_dst.local_name()); size_t const s = request_and_wait(Ipc_ostream::_dst.dst(), _write_offset); - copy_utcb_to_msgbuf(_rcv_msg, s); + utcb_to_msgbuf(_rcv_msg, s); /* reset unmarshaller */ _write_offset = _read_offset = RPC_OBJECT_ID_SIZE; @@ -187,7 +161,7 @@ void Ipc_server::_prepare_next_reply_wait() void Ipc_server::_wait() { /* receive next request */ - copy_utcb_to_msgbuf(_rcv_msg, Kernel::wait_for_request()); + utcb_to_msgbuf(_rcv_msg, Kernel::wait_for_request()); /* update server state */ _prepare_next_reply_wait(); @@ -206,9 +180,8 @@ void Ipc_server::_reply_wait() return; } /* send reply and receive next request */ - copy_msgbuf_to_utcb(_snd_msg, _write_offset, - Ipc_ostream::_dst.local_name()); - copy_utcb_to_msgbuf(_rcv_msg, Kernel::reply(_write_offset, 1)); + msgbuf_to_utcb(_snd_msg, _write_offset, Ipc_ostream::_dst.local_name()); + utcb_to_msgbuf(_rcv_msg, Kernel::reply(_write_offset, 1)); /* update server state */ _prepare_next_reply_wait();