1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-04 23:19:41 +02:00
iris/invoke.ccp

1052 lines
36 KiB
Plaintext
Raw Normal View History

2009-05-20 23:07:56 +03:00
#pypp 0
2009-06-01 15:26:42 +03:00
// Iris: micro-kernel for a capability-based operating system.
// invoke.ccp: Capability invocation and kernel responses.
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-05-20 23:07:56 +03:00
#include "kernel.hh"
2009-09-06 12:04:09 +03:00
static void log_message (char const *prefix, unsigned target, unsigned pdata, kCapability::Context *c):
2010-01-24 22:34:24 +02:00
kdebug (prefix)
kdebug (": caller=")
if old_current:
kdebug_num (old_current->id, 2)
else
kdebug ("xx")
kdebug (":")
kdebug_num ((unsigned)old_current)
kdebug ("; target=")
kdebug_num (target)
kdebug ("; pdata=")
kdebug_num (pdata)
kdebug ("; data=")
kdebug_num (c->data[0].h)
kdebug (":")
kdebug_num (c->data[0].l)
kdebug (",")
kdebug_num (c->data[1].h)
kdebug (":")
kdebug_num (c->data[1].l)
2009-10-10 02:31:10 +03:00
if c->reply.valid ():
2010-01-24 22:34:24 +02:00
kdebug ("; reply target=")
kdebug_num ((unsigned)c->reply->target)
kdebug ("; pdata=")
kdebug_num (c->reply->protected_data.l)
2009-10-10 02:31:10 +03:00
if c->arg.valid ():
2010-01-24 22:34:24 +02:00
kdebug ("; arg target=")
kdebug_num ((unsigned)c->arg->target)
kdebug ("; pdata=")
kdebug_num (c->arg->protected_data.l)
kdebug ("\n")
2009-09-06 12:04:09 +03:00
void kThread::raise (unsigned code, unsigned data):
2010-01-24 22:34:24 +02:00
kdebug ("raise ")
2010-01-18 06:01:59 +02:00
if old_current:
2010-01-24 22:34:24 +02:00
kdebug_num (old_current->id, 2)
2010-01-18 06:01:59 +02:00
else:
2010-01-24 22:34:24 +02:00
kdebug ("xx")
kdebug (':')
kdebug_num ((unsigned)old_current)
kdebug ('/')
if code < Iris::NUM_EXCEPTION_CODES:
kdebug (Iris::exception_name[code])
2009-07-25 01:54:12 +03:00
else:
2010-01-24 22:34:24 +02:00
kdebug ("invalid code:")
kdebug_num (code)
kdebug ('/')
kdebug_num (data)
kdebug ('\n')
2009-12-27 01:12:35 +02:00
dpanic (code, "raise")
2009-07-25 01:54:12 +03:00
unrun ()
2009-09-08 22:20:30 +03:00
if slots < 1 || !slot[0].caps || !slot[0].caps->cap (0)->target:
2009-07-25 01:54:12 +03:00
return
kCapability::Context c
c.data[0] = Iris::Num (code, data)
2009-09-08 22:20:30 +03:00
slot[0].caps->cap (0)->invoke (&c)
2009-07-25 01:54:12 +03:00
2009-07-05 11:52:44 +03:00
// From user-provided, thus untrusted, data, find a capability.
kCapRef kThread::find_capability (unsigned code, bool *copy):
*copy = code & CAP_COPY
unsigned c = code & ~CAP_COPY
2009-09-08 22:20:30 +03:00
unsigned s = c >> 16
unsigned num = c & 0xffff
2009-09-08 22:20:30 +03:00
if s >= slots || !slot[s].caps || num >= slot[s].caps->size:
if c != CAP_NONE:
2010-01-24 22:34:24 +02:00
kdebug_num ((unsigned)old_current)
kdebug (": invalid capability ")
kdebug_num (code)
kdebug ('\n')
kdebug_num (num)
kdebug (':')
kdebug_num (s)
kdebug (" > ")
2009-09-08 22:20:30 +03:00
if slot[s].caps:
2010-01-24 22:34:24 +02:00
kdebug_num (slot[s].caps->size)
2009-08-24 22:02:35 +03:00
else:
2010-01-24 22:34:24 +02:00
kdebug ("no caps")
kdebug ('\n')
dpanic (code, "invalid capability")
return kCapRef ()
2009-09-08 22:20:30 +03:00
return kCapRef (slot[s].caps, num)
2009-07-05 11:52:44 +03:00
// Try to deliver a message.
bool kReceiver::try_deliver ():
2009-07-20 01:23:45 +03:00
if !messages:
2009-06-01 02:12:54 +03:00
return false
2009-07-20 01:23:45 +03:00
if !owner || !owner->is_waiting ():
return false
kMessage *m = last_message
2009-06-01 02:12:54 +03:00
if protected_only:
for ; m; m = (kMessage *)m->prev:
2009-09-06 12:04:09 +03:00
if m->protected_data.value () == reply_protected_data.value ():
2009-07-20 01:23:45 +03:00
protected_only = false
2009-06-01 02:12:54 +03:00
break
2009-10-10 02:31:10 +03:00
if !m:
return false
2009-09-06 12:04:09 +03:00
bool dummy
kCapRef c = owner->find_capability (owner->recv_reply, &dummy)
if c.valid ():
c.clone (kCapRef (&m->caps, 0), true)
c = owner->find_capability (owner->recv_arg, &dummy)
if c.valid ():
c.clone (kCapRef (&m->caps, 1), true)
kThread_arch_receive (owner, m->protected_data, m->data)
2009-07-20 01:23:45 +03:00
address_space->free_message (this, m)
2009-06-01 02:12:54 +03:00
owner->unwait ()
return true
2009-07-05 11:52:44 +03:00
// Send a message to a receiver; try to deliver it immediately.
bool kReceiver::send_message (Iris::Num protected_data, kCapability::Context *c):
2009-09-06 12:04:09 +03:00
//log_message ("send_message", (unsigned)this, protected_data.l, c)
2009-10-10 02:31:10 +03:00
if owner && owner->is_waiting () && (!protected_only || protected_data.value () == reply_protected_data.value ()):
if protected_only:
2009-07-25 01:54:12 +03:00
protected_only = false
2009-09-06 12:04:09 +03:00
bool dummy
kCapRef cap = owner->find_capability (owner->recv_reply, &dummy)
if cap.valid ():
cap.clone (c->reply, c->copy[0])
cap = owner->find_capability (owner->recv_arg, &dummy)
if cap.valid ():
cap.clone (c->arg, c->copy[1])
kThread_arch_receive (owner, protected_data, c->data)
2009-07-25 01:54:12 +03:00
owner->unwait ()
return true
2009-06-01 02:12:54 +03:00
// The owner was not waiting, or it was not possible to deliver the message. Put it in the queue.
kMessage *msg = NULL;
if queue_limit:
msg = address_space->alloc_message (this)
if msg:
--queue_limit
if !msg:
// TODO: use sender-provided storage.
2009-06-01 02:12:54 +03:00
if !msg:
return false
2009-09-06 12:04:09 +03:00
msg->protected_data = protected_data
for unsigned i = 0; i < 2; ++i:
2009-06-10 23:54:12 +03:00
msg->data[i] = c->data[i]
2009-09-06 12:04:09 +03:00
msg->caps.clone (0, c->reply, c->copy[0])
msg->caps.clone (1, c->arg, c->copy[1])
2009-06-01 02:12:54 +03:00
return true
2009-09-06 12:04:09 +03:00
static kCapability::Context *context
2009-05-27 19:33:05 +03:00
static void reply_num (Iris::Num num):
2009-10-04 20:47:20 +03:00
kCapability::Context c
c.data[0] = num
c.data[1] = 0
if reply_target:
reply_target->send_message (reply_protected, &c)
2010-05-03 17:46:14 +03:00
else
2009-10-04 20:47:20 +03:00
dpanic (0, "nothing to reply to")
static void reply_num (unsigned num1, unsigned num2 = 0, unsigned num3 = 0):
kCapability::Context c
c.data[0] = Iris::Num (num1, num2)
c.data[1] = num3
2009-09-06 12:04:09 +03:00
if reply_target:
reply_target->send_message (reply_protected, &c)
2010-05-03 17:46:14 +03:00
else
2009-09-06 12:04:09 +03:00
dpanic (0, "nothing to reply to")
2009-06-01 02:12:54 +03:00
static void reply_cap (unsigned target, Iris::Num protected_data, kCapRef *ref, unsigned num = 0):
2010-01-24 22:34:24 +02:00
if !reply_target:
2010-05-03 17:46:14 +03:00
dpanic (0, "nothing to reply to")
2010-01-24 22:34:24 +02:00
return
2009-09-06 12:04:09 +03:00
replied_caps.set (0, (kReceiver *)target, protected_data, kCapRef (), ref)
kCapability::Context c
c.arg = kCapRef (&replied_caps, 0)
c.copy[1] = true
c.data[0] = Iris::Num (num, 0)
2010-01-24 22:34:24 +02:00
reply_target->send_message (reply_protected, &c)
c.arg->invalidate ()
2009-05-25 01:31:35 +03:00
static void receiver_invoke (unsigned cmd, unsigned target, Iris::Num protected_data, kCapability::Context *c):
2009-09-06 12:04:09 +03:00
kReceiver *receiver = (kReceiver *)protected_data.l
switch cmd:
case Iris::Receiver::SET_OWNER & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
if !c->arg.valid ():
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-05-25 01:31:35 +03:00
return
2009-09-06 12:04:09 +03:00
unsigned cap = (unsigned)c->arg->target
if cap != (CAPTYPE_THREAD | CAP_MASTER) && cap != (CAPTYPE_THREAD | Iris::Thread::SET_OWNER):
// FIXME: This makes it impossible to use a fake kThread capability.
return
2009-09-06 12:04:09 +03:00
receiver->own ((kThread *)c->arg->protected_data.l)
2009-06-01 02:12:54 +03:00
break
case Iris::Receiver::CREATE_CAPABILITY & REQUEST_MASK:
reply_cap ((unsigned)receiver, c->data[1], &receiver->capabilities)
return
case Iris::Receiver::CREATE_CALL_CAPABILITY & REQUEST_MASK:
reply_cap (CAPTYPE_RECEIVER | (c->data[0].h ? Iris::Receiver::CALL_ASYNC : Iris::Receiver::CALL), protected_data, &((kObject *)protected_data.l)->refs)
return
case Iris::Receiver::GET_PROTECTED & REQUEST_MASK:
2009-10-04 20:47:20 +03:00
if !c->arg.valid () || c->arg->target != receiver:
2010-01-16 17:13:54 +02:00
if !c->arg.valid ():
2010-01-24 22:34:24 +02:00
kdebug ("invalid arg\n")
2010-01-16 17:13:54 +02:00
else:
2010-01-24 22:34:24 +02:00
kdebug ("target: ")
kdebug_num ((unsigned)c->arg->target)
kdebug ("/")
kdebug_num ((unsigned)c->arg->protected_data.h)
kdebug (":")
kdebug_num ((unsigned)c->arg->protected_data.l)
kdebug ("\n")
2009-10-04 20:47:20 +03:00
dpanic (0, "wrong argument for get_protected")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-10-04 20:47:20 +03:00
return
reply_num (c->arg->protected_data)
return
case Iris::Receiver::GET_REPLY_PROTECTED_DATA & REQUEST_MASK:
reply_num (receiver->reply_protected_data.l, receiver->reply_protected_data.h, receiver->protected_only ? 1 : 0)
return
case Iris::Receiver::SET_REPLY_PROTECTED_DATA & REQUEST_MASK:
receiver->reply_protected_data = c->data[1]
2010-06-07 00:03:25 +03:00
// Adjust target protected data, so the reply will reach the caller.
if receiver == reply_target:
reply_protected = receiver->reply_protected_data
2009-07-20 01:23:45 +03:00
break
case Iris::Receiver::GET_ALARM & REQUEST_MASK:
reply_num (receiver->alarm_count)
return
case Iris::Receiver::SET_ALARM & REQUEST_MASK:
case Iris::Receiver::ADD_ALARM & REQUEST_MASK:
2009-07-20 01:23:45 +03:00
unsigned old = receiver->alarm_count
if cmd == (Iris::Receiver::SET_ALARM & REQUEST_MASK):
receiver->alarm_count = c->data[1].l
2009-07-20 01:23:45 +03:00
else:
receiver->alarm_count += c->data[1].l
2009-07-20 01:23:45 +03:00
if (old == ~0) ^ (receiver->alarm_count == ~0):
// The alarm stopped or started.
if old == ~0:
// It started.
receiver->prev_alarm = NULL
receiver->next_alarm = first_alarm
if receiver->next_alarm:
receiver->next_alarm->prev_alarm = receiver
first_alarm = receiver
else:
// It stopped.
if receiver->prev_alarm:
receiver->prev_alarm->next_alarm = receiver->next_alarm
else:
first_alarm = receiver->next_alarm
if receiver->next_alarm:
receiver->next_alarm->prev_alarm = receiver->prev_alarm
reply_num (receiver->alarm_count)
return
2009-05-25 01:31:35 +03:00
default:
2010-01-24 22:34:24 +02:00
dpanic (cmd, "invalid receiver operation")
reply_num (Iris::ERR_INVALID_OPERATION)
2009-08-24 22:02:35 +03:00
return
reply_num (0)
2009-05-25 01:31:35 +03:00
static void memory_invoke (unsigned cmd, unsigned target, Iris::Num protected_data, kCapability::Context *c):
2009-09-06 12:04:09 +03:00
kMemory *mem = (kMemory *)protected_data.l
switch cmd:
case Iris::Memory::CREATE & REQUEST_MASK:
switch c->data[0].h:
2009-05-25 01:31:35 +03:00
case CAPTYPE_RECEIVER:
kReceiver *ret = mem->alloc_receiver ()
2009-05-25 01:31:35 +03:00
if ret:
reply_cap (CAPTYPE_RECEIVER | CAP_MASTER, (unsigned)ret, &ret->refs)
2009-05-25 01:31:35 +03:00
else:
2009-08-24 22:02:35 +03:00
dpanic (0x03311992, "out of memory creating receiver")
reply_num (Iris::ERR_OUT_OF_MEMORY)
return
2009-05-25 01:31:35 +03:00
case CAPTYPE_MEMORY:
kMemory *ret = mem->alloc_memory ()
2009-05-25 01:31:35 +03:00
if ret:
reply_cap (CAPTYPE_MEMORY | CAP_MASTER, (unsigned)ret, &ret->refs)
2009-05-25 01:31:35 +03:00
else:
2009-08-24 22:02:35 +03:00
dpanic (0x13311992, "out of memory creating memory")
reply_num (Iris::ERR_OUT_OF_MEMORY)
return
2009-05-25 01:31:35 +03:00
case CAPTYPE_THREAD:
kThread *ret = mem->alloc_thread (c->data[1].l)
2009-05-25 01:31:35 +03:00
if ret:
reply_cap (CAPTYPE_THREAD | CAP_MASTER, (unsigned)ret, &ret->refs)
2010-01-31 10:26:23 +02:00
kdebug ("(created thread ")
2010-01-30 10:21:56 +02:00
kdebug_num ((unsigned)ret)
2010-05-05 02:09:32 +03:00
kdebug (")\n")
2009-05-25 01:31:35 +03:00
else:
2009-08-24 22:02:35 +03:00
dpanic (0x23311992, "out of memory creating thread")
reply_num (Iris::ERR_OUT_OF_MEMORY)
return
2009-05-25 01:31:35 +03:00
case CAPTYPE_PAGE:
kPage *ret = mem->alloc_page ()
2009-05-25 01:31:35 +03:00
if ret:
reply_cap (CAPTYPE_PAGE | CAP_MASTER, (unsigned)ret, &ret->refs)
2009-05-25 01:31:35 +03:00
else:
2009-08-24 22:02:35 +03:00
dpanic (0x33311992, "out of memory creating page")
reply_num (Iris::ERR_OUT_OF_MEMORY)
return
case CAPTYPE_CAPS:
kCaps *ret = mem->alloc_caps (c->data[1].l)
2009-05-25 01:31:35 +03:00
if ret:
reply_cap (CAPTYPE_CAPS | CAP_MASTER, (unsigned)ret, &ret->refs)
2009-05-25 01:31:35 +03:00
else:
2009-08-24 22:02:35 +03:00
dpanic (0x43311992, "out of memory creating caps")
reply_num (Iris::ERR_OUT_OF_MEMORY)
return
2009-05-25 01:31:35 +03:00
default:
2009-09-06 12:04:09 +03:00
dpanic (0, "invalid create type")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-05-25 01:31:35 +03:00
return
break
case Iris::Memory::DESTROY & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
if !c->arg.valid () || (unsigned)c->arg->target & ~KERNEL_MASK || !c->arg->target || ((kObject *)c->arg->protected_data.l)->address_space != mem:
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-05-27 15:38:52 +03:00
return
2010-05-03 17:46:14 +03:00
// Send the reply before destroying things, because the target may be destroyed.
reply_num (0)
2009-09-06 12:04:09 +03:00
switch (unsigned)c->arg->target & CAPTYPE_MASK:
2009-05-27 15:38:52 +03:00
case CAPTYPE_RECEIVER:
2009-09-06 12:04:09 +03:00
mem->free_receiver ((kReceiver *)c->arg->protected_data.l)
2009-07-24 15:25:53 +03:00
break
2009-05-27 15:38:52 +03:00
case CAPTYPE_MEMORY:
2009-09-06 12:04:09 +03:00
mem->free_memory ((kMemory *)c->arg->protected_data.l)
2009-07-24 15:25:53 +03:00
break
2009-05-27 15:38:52 +03:00
case CAPTYPE_THREAD:
2009-09-06 12:04:09 +03:00
mem->free_thread ((kThread *)c->arg->protected_data.l)
2009-07-24 15:25:53 +03:00
break
2009-05-27 15:38:52 +03:00
case CAPTYPE_PAGE:
2009-09-06 12:04:09 +03:00
mem->free_page ((kPage *)c->arg->protected_data.l)
2009-07-24 15:25:53 +03:00
break
case CAPTYPE_CAPS:
2009-09-06 12:04:09 +03:00
mem->free_caps ((kCaps *)c->arg->protected_data.l)
2009-07-24 15:25:53 +03:00
break
2009-05-27 15:38:52 +03:00
default:
panic (0x55228930, "invalid case")
2009-07-24 15:25:53 +03:00
return
2010-05-03 17:46:14 +03:00
return
case Iris::Memory::LIST & REQUEST_MASK:
2009-05-25 01:31:35 +03:00
// TODO
break
case Iris::Memory::MAP & REQUEST_MASK:
2009-06-01 02:12:54 +03:00
// FIXME: this should work for fake pages as well.
2009-09-06 12:04:09 +03:00
if !c->arg.valid () || (unsigned)c->arg->target & ~KERNEL_MASK || ((unsigned)c->arg->target & CAPTYPE_MASK) != CAPTYPE_PAGE:
2009-08-24 22:02:35 +03:00
dpanic (0x22993341, "Trying to map non-page")
reply_num (Iris::ERR_INVALID_ARGUMENT)
return
2009-09-06 12:04:09 +03:00
kPage *page = (kPage *)c->arg->protected_data.l
2009-06-01 02:12:54 +03:00
if page->address_space != mem:
2009-08-24 22:02:35 +03:00
dpanic (0x52993341, "Trying to map foreign page")
reply_num (Iris::ERR_INVALID_ARGUMENT)
return
if c->data[1].l & (unsigned)c->arg->target & Iris::Page::READONLY:
2010-01-24 22:34:24 +02:00
kdebug ("Mapping readonly because capability is readonly\n")
page->flags |= Iris::Page::MAPPED_READONLY
2010-01-17 11:01:42 +02:00
mem->map (page, c->data[1].l & PAGE_MASK)
2009-05-25 01:31:35 +03:00
break
case Iris::Memory::MAPPING & REQUEST_MASK:
2010-01-17 11:01:42 +02:00
kPage *page = mem->get_mapping (c->data[1].l)
2010-01-14 19:14:37 +02:00
if !page:
reply_num (Iris::ERR_UNMAPPED_READ)
2010-01-14 19:14:37 +02:00
return
unsigned t = CAPTYPE_PAGE | CAP_MASTER
if page->flags & Iris::Page::MAPPED_READONLY:
t |= Iris::Page::READONLY
reply_cap (t, (unsigned)page, &page->refs)
return
case Iris::Memory::GET_LIMIT & REQUEST_MASK:
2009-05-25 01:31:35 +03:00
reply_num (mem->limit)
return
case Iris::Memory::SET_LIMIT & REQUEST_MASK:
mem->limit = c->data[1].l
2009-05-25 01:31:35 +03:00
break
default:
2009-09-06 12:04:09 +03:00
dpanic (0, "invalid memory operation")
reply_num (Iris::ERR_INVALID_OPERATION)
return
reply_num (0)
2009-05-25 01:31:35 +03:00
static void thread_invoke (unsigned cmd, unsigned target, Iris::Num protected_data, kCapability::Context *c):
2009-09-06 12:04:09 +03:00
kThread *thread = (kThread *)protected_data.l
switch cmd:
case Iris::Thread::GET_INFO & REQUEST_MASK:
switch c->data[0].h:
case Iris::Thread::PC:
reply_num (thread->pc)
return
case Iris::Thread::SP:
reply_num (thread->sp)
return
case Iris::Thread::FLAGS:
reply_num (thread->flags)
return
default:
reply_num (*kThread_arch_info (thread, c->data[0].h))
return
case Iris::Thread::SET_INFO & REQUEST_MASK:
2009-05-27 19:33:05 +03:00
unsigned *value
2010-01-18 06:01:59 +02:00
switch c->data[0].h:
case Iris::Thread::PC:
2009-05-27 19:33:05 +03:00
value = &thread->pc
break
case Iris::Thread::SP:
2009-05-27 19:33:05 +03:00
value = &thread->sp
break
case Iris::Thread::FLAGS:
// It is not possible to set the PRIV flag (but it can be reset).
if c->data[1].l & Iris::Thread::PRIV:
c->data[1].h &= ~Iris::Thread::PRIV
2009-05-27 19:33:05 +03:00
value = &thread->flags
if c->data[1].h & ~Iris::Thread::USER_FLAGS:
unsigned v = (*value & ~c->data[1].h) | (c->data[1].l & c->data[1].h)
if (v & Iris::Thread::WAITING) != (*value & Iris::Thread::WAITING):
if v & Iris::Thread::WAITING:
thread->wait ()
2009-05-27 19:33:05 +03:00
else
2009-07-24 15:25:53 +03:00
thread->unwait ()
if (v & Iris::Thread::RUNNING) != (*value & Iris::Thread::RUNNING):
if v & Iris::Thread::RUNNING:
2009-05-27 19:33:05 +03:00
thread->run ()
2010-01-18 06:01:59 +02:00
else:
2009-05-27 19:33:05 +03:00
thread->unrun ()
break
default:
2010-01-18 06:01:59 +02:00
value = kThread_arch_info (thread, c->data[0].h)
2009-05-27 19:33:05 +03:00
break
if value:
*value = (*value & ~c->data[1].h) | (c->data[1].l & c->data[1].h)
2009-05-27 19:33:05 +03:00
break
case Iris::Thread::USE_SLOT & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
if c->data[1].l >= thread->slots || !c->arg.valid ():
if c->data[1].l == 0xdeadbeef:
bool dummy
dbg_code.h = (unsigned)c->arg.deref ()
break
2009-09-01 20:00:46 +03:00
dbg_send (5, 3)
2009-08-24 22:02:35 +03:00
dpanic (c->data[1].l, "no argument given for USE_SLOT")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-08-19 02:00:05 +03:00
return
// FIXME: This doesn't allow using a fake caps.
if (unsigned)c->arg->target != (CAPTYPE_CAPS | CAP_MASTER) && (unsigned)c->arg->target != (CAPTYPE_CAPS | Iris::Caps::USE):
dpanic ((unsigned)c->arg->target, "argument for USE_SLOT is not a caps")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-08-19 02:00:05 +03:00
return
2009-09-06 12:04:09 +03:00
unsigned slot = c->data[1].l
kCaps *new_caps = (kCaps *)c->arg->protected_data.l
if slot >= thread->slots:
dpanic (0, "using invalid slot")
return
2009-09-08 22:20:30 +03:00
thread->unset_slot (slot)
thread->slot[slot].caps = new_caps
2009-09-06 12:04:09 +03:00
if new_caps:
2009-09-08 22:20:30 +03:00
thread->slot[slot].next = new_caps->first_slot
thread->slot[slot].caps = new_caps
new_caps->first_slot.thread = thread
new_caps->first_slot.index = slot
2009-09-06 12:04:09 +03:00
break
case Iris::Thread::GET_CAPS & REQUEST_MASK:
2009-09-07 00:34:50 +03:00
unsigned slot = c->data[1].l
if slot < thread->slots:
2009-09-08 22:20:30 +03:00
reply_cap (CAPTYPE_CAPS | CAP_MASTER, (unsigned)thread->slot[slot].caps, &thread->slot[slot].caps->refs, thread->slots)
2009-09-07 00:34:50 +03:00
else:
reply_num (thread->slots)
return
case Iris::Thread::SCHEDULE & REQUEST_MASK:
2009-07-20 01:23:45 +03:00
do_schedule = true
return
default:
if !(thread->flags & Iris::Thread::PRIV):
2009-09-06 12:04:09 +03:00
dpanic (0, "invalid thread operation")
reply_num (Iris::ERR_INVALID_OPERATION)
2009-08-24 22:02:35 +03:00
return
switch cmd:
case Iris::Thread::PRIV_REGISTER_INTERRUPT & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
arch_register_interrupt (c->data[1].l, c->arg.valid () && (((unsigned)c->arg->target) & ~REQUEST_MASK) == CAPTYPE_RECEIVER ? (kReceiver *)c->arg->protected_data.l : NULL)
2009-08-24 22:02:35 +03:00
break
case Iris::Thread::PRIV_GET_TOP_MEMORY & REQUEST_MASK:
2009-08-24 22:02:35 +03:00
reply_cap (CAPTYPE_MEMORY | CAP_MASTER, (unsigned)&top_memory, &top_memory.refs)
return
case Iris::Thread::PRIV_MAKE_PRIV & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
if !c->arg.valid () || ((unsigned)c->arg->target) & ~REQUEST_MASK != CAPTYPE_THREAD:
2010-01-18 06:01:59 +02:00
dpanic (0, "not a thread argument for make priv")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-08-24 22:02:35 +03:00
return
((kThread *)c->arg->protected_data.l)->flags |= Iris::Thread::PRIV
2009-08-24 22:02:35 +03:00
break
case Iris::Thread::PRIV_ALLOC_RANGE & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
if !c->arg.valid () || ((unsigned)c->arg->target) & ~REQUEST_MASK != CAPTYPE_MEMORY:
2010-08-24 00:55:51 +03:00
dpanic (0x54365435, "non-memory argument to alloc_range")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-08-24 22:02:35 +03:00
return
2009-09-06 12:04:09 +03:00
kMemory *mem = (kMemory *)c->arg->protected_data.l
2009-08-24 22:02:35 +03:00
if !mem->use (c->data[1].l):
dpanic (0x34365435, "out of memory during alloc_range")
reply_num (Iris::ERR_OUT_OF_MEMORY)
2009-08-24 22:02:35 +03:00
return
unsigned data = phys_alloc (c->data[1].l)
if !data:
mem->unuse (c->data[1].l)
dpanic (0x14365435, "out of memory during alloc_range")
reply_num (Iris::ERR_OUT_OF_MEMORY)
2009-08-24 22:02:35 +03:00
return
reply_num (data & ~0xc0000000)
return
case Iris::Thread::PRIV_ALLOC_PHYSICAL & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
if !c->arg.valid ():
panic (0x71342134, "no argument provided for alloc physical")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-09-06 12:04:09 +03:00
return
if ((unsigned)c->arg->target & ~REQUEST_MASK) != CAPTYPE_PAGE:
2009-08-24 22:02:35 +03:00
panic (0x21342134, "no page provided for alloc physical")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-08-24 22:02:35 +03:00
return
2009-09-06 12:04:09 +03:00
kPage *page = (kPage *)c->arg->protected_data.l
2009-08-24 22:02:35 +03:00
page->forget ()
if !(c->data[1].l & 2):
if page->flags & Iris::Page::PAYING:
page->flags &= ~Iris::Page::PAYING
2009-08-24 22:02:35 +03:00
page->address_space->unuse ()
else:
// This is for mapping allocated ranges. They are already paid for. Record that.
if page->flags & Iris::Page::PAYING:
2009-08-24 22:02:35 +03:00
page->address_space->unuse ()
else:
page->flags |= Iris::Page::PAYING
2010-01-24 22:34:24 +02:00
page->frame = (c->data[1].l & PAGE_MASK) | 0x80000000
page->flags |= Iris::Page::FRAME
2009-08-24 22:02:35 +03:00
if !(c->data[1].l & 1):
page->flags |= Iris::Page::UNCACHED
2009-08-24 22:02:35 +03:00
if !(c->data[1].l & 2):
page->flags |= Iris::Page::PHYSICAL
2009-08-24 22:02:35 +03:00
kPage_arch_update_mapping (page)
break
case Iris::Thread::PRIV_PHYSICAL_ADDRESS & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
if !c->arg.valid () || ((unsigned)c->arg->target) & ~REQUEST_MASK != CAPTYPE_PAGE:
2009-08-24 22:02:35 +03:00
dpanic (0x99049380, "invalid page for physical address")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-08-24 22:02:35 +03:00
return
2009-09-06 12:04:09 +03:00
kPage *page = (kPage *)c->arg->protected_data.l
2009-08-24 22:02:35 +03:00
reply_num (page->frame & ~0xc0000000)
return
case Iris::Thread::PRIV_REBOOT & REQUEST_MASK:
2009-10-04 20:47:20 +03:00
arch_reboot ()
2010-08-10 11:09:50 +03:00
case Iris::Thread::PRIV_POWEROFF & REQUEST_MASK:
arch_poweroff ()
2010-08-22 23:03:06 +03:00
case Iris::Thread::PRIV_BOOT & REQUEST_MASK:
2010-08-24 00:55:51 +03:00
arch_boot (c->data[1].l, c->data[1].h)
case Iris::Thread::PRIV_PANIC & REQUEST_MASK:
2010-01-24 22:34:24 +02:00
if c->data[1].l == 0xdeaddead:
dbg_code.l = 1
break
2009-09-06 12:04:09 +03:00
panic (c->data[1].l, "panic requested by thread")
reply_num (~0)
return
case Iris::Thread::DBG_SEND & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
dbg_send (c->data[1].l, c->data[1].h)
break
2009-08-24 22:02:35 +03:00
default:
2009-09-06 12:04:09 +03:00
dpanic (0, "invalid priv thread operation")
reply_num (Iris::ERR_INVALID_OPERATION)
2009-08-24 22:02:35 +03:00
return
reply_num (0)
return
2009-05-25 01:31:35 +03:00
static void page_invoke (unsigned cmd, unsigned target, Iris::Num protected_data, kCapability::Context *c):
2009-09-06 12:04:09 +03:00
kPage *page = (kPage *)protected_data.l
switch cmd & ~Iris::Page::READONLY:
case Iris::Page::SHARE & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
if !c->arg.valid ():
// Cannot share without a target page.
2010-01-16 17:13:54 +02:00
dpanic (0, "no target page for share")
reply_num (Iris::ERR_INVALID_ARGUMENT)
return
2009-09-06 12:04:09 +03:00
if ((unsigned)c->arg->target & ~REQUEST_MASK) != CAPTYPE_PAGE:
// FIXME: This makes it impossible to use a fake kPage capability.
2010-01-16 17:13:54 +02:00
dpanic (0, "share target is no page")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-08-24 22:02:35 +03:00
return
2009-09-06 12:04:09 +03:00
kPage *t = (kPage *)c->arg->protected_data.l
//kdebug ("sharing from ")
//kdebug_num ((unsigned)page)
//kdebug (" (frame ")
//kdebug_num (page->frame)
//kdebug (") to ")
//kdebug_num ((unsigned)t)
//kdebug (" (frame ")
//kdebug_num (t->frame)
//kdebug (")\n")
2010-01-18 06:01:59 +02:00
if t != page:
t->forget ()
if c->data[0].h & Iris::Page::READONLY || cmd & Iris::Page::READONLY:
t->flags |= Iris::Page::READONLY
if !(page->flags & Iris::Page::FRAME):
2010-01-24 22:34:24 +02:00
kdebug ("share problem: ")
kdebug_num (page->flags)
kdebug ("\n")
2010-01-16 17:13:54 +02:00
dpanic (0, "sharing nothing results in lost page")
2010-01-17 11:01:42 +02:00
kPage_arch_update_mapping (t)
break
if c->data[0].h & Iris::Page::COPY:
if ~t->flags & Iris::Page::PAYING:
2010-01-17 11:01:42 +02:00
kPage_arch_update_mapping (t)
2009-06-01 02:12:54 +03:00
break
if !(c->data[0].h & Iris::Page::FORGET) || page->flags & Iris::Page::SHARED:
unsigned *d = (unsigned *)page->frame
2009-06-01 02:12:54 +03:00
if t == page:
kPage *other = page->share_next ? page->share_next : page->share_prev
if !other:
kPage_arch_update_mapping (t)
break
if page->share_next:
page->share_next->share_prev = page->share_prev
if page->share_prev:
page->share_prev->share_next = page->share_next
page->share_next = NULL
page->share_prev = NULL
other->check_payment ()
2009-06-01 02:12:54 +03:00
else:
t->flags |= Iris::Page::FRAME
t->frame = raw_zalloc ()
2010-01-16 17:13:54 +02:00
for unsigned i = 0; i < PAGE_SIZE; i += 4:
((unsigned *)t->frame)[i >> 2] = d[i >> 2]
if c->data[0].h & Iris::Page::FORGET:
2010-01-18 06:01:59 +02:00
page->frame = NULL
page->flags &= ~Iris::Page::FRAME
2010-01-18 06:01:59 +02:00
kPage_arch_update_mapping (page)
else:
if t != page:
t->frame = page->frame
t->flags |= Iris::Page::FRAME
page->frame = NULL
page->flags &= ~Iris::Page::FRAME
kPage_arch_update_mapping (page)
2010-01-18 06:01:59 +02:00
else:
dpanic (0, "sharing page with itself...")
2009-06-01 02:12:54 +03:00
else:
if t == page:
2010-01-16 17:13:54 +02:00
dpanic (0, "sharing page with itself")
2010-01-17 11:01:42 +02:00
kPage_arch_update_mapping (t)
2009-06-01 02:12:54 +03:00
break
if c->data[0].h & Iris::Page::FORGET:
if ~page->flags & Iris::Page::SHARED:
if t->flags & Iris::Page::PAYING:
t->frame = page->frame
t->flags |= Iris::Page::FRAME
2010-01-18 06:01:59 +02:00
else:
dpanic (0, "move page failed because target is not paying")
page->frame = NULL
page->flags &= ~Iris::Page::FRAME
kPage_arch_update_mapping (page)
2009-06-01 02:12:54 +03:00
else:
t->share_prev = page->share_prev
t->share_next = page->share_next
if t->share_prev:
t->share_prev->share_next = t
if t->share_next:
t->share_next->share_prev = t
page->share_prev = NULL
page->share_next = NULL
page->forget ()
t->check_payment ()
2009-05-29 00:35:27 +03:00
else:
t->share_prev = page->share_prev
t->share_next = page
page->share_prev = t
if t->share_prev:
t->share_prev->share_next = t
2010-01-16 17:13:54 +02:00
t->frame = page->frame
t->flags |= Iris::Page::FRAME
2010-01-17 11:01:42 +02:00
kPage_arch_update_mapping (t)
break
2010-06-07 00:03:25 +03:00
case Iris::Page::GET_FLAGS & REQUEST_MASK:
reply_num (page->flags)
return
case Iris::Page::SET_FLAGS & REQUEST_MASK:
if cmd & Iris::Page::READONLY:
2010-01-16 17:13:54 +02:00
dpanic (0, "setting page flags denied")
reply_num (Iris::ERR_WRITE_DENIED)
return
2009-06-08 14:46:13 +03:00
// Always refuse to set reserved flags.
c->data[1].h &= ~(Iris::Page::PHYSICAL | Iris::Page::UNCACHED)
2009-06-01 02:12:54 +03:00
// Remember the old flags.
unsigned old = page->flags
2009-06-01 02:12:54 +03:00
// Compute the new flags.
2010-01-16 17:13:54 +02:00
page->flags = (page->flags & ~c->data[1].h) | (c->data[1].l & c->data[1].h)
2009-06-01 02:12:54 +03:00
// If we stop paying, see if the frame is still paid for. If not, free it.
if ~page->flags & old & Iris::Page::PAYING:
// Decrease the use counter in any case.
page->address_space->unuse ()
page->check_payment ()
2009-06-01 02:12:54 +03:00
// If we start paying, increase the use counter.
if page->flags & ~old & Iris::Page::PAYING:
if !page->address_space->use():
2010-01-16 17:13:54 +02:00
dpanic (0, "cannot pay for frame")
2009-06-01 02:12:54 +03:00
// If it doesn't work, refuse to set the flag, and refuse to allocate a frame.
page->flags &= ~(Iris::Page::PAYING | Iris::Page::FRAME)
2010-01-16 17:13:54 +02:00
// However, if there already was a frame, keep it.
if old & Iris::Page::FRAME:
page->flags |= Iris::Page::FRAME
2009-06-01 02:12:54 +03:00
// If we want a frame, see if we can get it.
if ~old & page->flags & Iris::Page::FRAME:
if ~page->flags & Iris::Page::PAYING:
2010-01-17 11:01:42 +02:00
dpanic (0, "cannot have frame without paying")
page->flags &= ~Iris::Page::FRAME
2010-01-17 11:01:42 +02:00
else:
page->frame = page->address_space->zalloc ()
kPage_arch_update_mapping (page)
// If we lose a frame, handle it.
if old & ~page->flags & Iris::Page::FRAME:
page->forget ()
2009-05-27 20:29:21 +03:00
break
2009-05-25 01:31:35 +03:00
default:
2009-09-06 12:04:09 +03:00
dpanic (0, "invalid page operation")
reply_num (Iris::ERR_INVALID_OPERATION)
2009-08-24 22:02:35 +03:00
return
2010-01-18 07:45:52 +02:00
if page->flags > 0x7f:
dpanic (page->flags, "weird output from page operation")
2009-08-24 22:02:35 +03:00
reply_num (0)
static void print_cap (kCapRef cap, kCapRef self):
if cap.deref () == self.deref ():
2010-01-24 22:34:24 +02:00
kdebug ('{')
2009-08-24 22:02:35 +03:00
else:
2010-01-24 22:34:24 +02:00
kdebug ('[')
kdebug_num ((unsigned)cap.caps)
kdebug (':')
kdebug_num (cap.index, 1)
2009-09-01 20:00:46 +03:00
if !cap.valid ():
2010-01-24 22:34:24 +02:00
kdebug ('!')
2009-09-06 12:04:09 +03:00
else:
2010-01-24 22:34:24 +02:00
kdebug ('=')
kdebug_num ((unsigned)cap->target)
kdebug (':')
kdebug_num (cap->protected_data.l)
2009-08-24 22:02:35 +03:00
for kCapRef c = cap->children; c.valid (); c = c->sibling_next:
print_cap (c, self)
if cap.deref () == self.deref ():
2010-01-24 22:34:24 +02:00
kdebug ('}')
2009-08-24 22:02:35 +03:00
else:
2010-01-24 22:34:24 +02:00
kdebug (']')
2009-05-25 01:31:35 +03:00
static void caps_invoke (unsigned cmd, unsigned target, Iris::Num protected_data, kCapability::Context *c):
2009-09-06 12:04:09 +03:00
kCaps *caps = (kCapsP)protected_data.l
switch cmd:
case Iris::Caps::GET & REQUEST_MASK:
2009-09-12 23:48:47 +03:00
if c->data[1].l >= caps->size:
reply_num (Iris::ERR_INVALID_ARGUMENT)
2010-01-24 22:34:24 +02:00
kdebug_num ((unsigned)caps)
kdebug (" size: ")
kdebug_num (caps->size)
kdebug ('\n')
dpanic (c->data[1].l, "invalid index for get caps")
2009-09-12 23:48:47 +03:00
return
kCapability *ret = caps->cap (c->data[1].l)
2010-01-24 22:34:24 +02:00
#if 0
kdebug_num ((unsigned)caps)
kdebug (" get cap ")
kdebug_num (c->data[1].l)
kdebug (" = ")
kdebug_num ((unsigned)ret->target)
kdebug ("/")
kdebug_num (ret->protected_data.h)
kdebug (":")
kdebug_num (ret->protected_data.l)
kdebug ("\n")
#endif
reply_cap ((unsigned)ret->target, ret->protected_data, ((unsigned)ret->target & ~KERNEL_MASK) == 0 ? &((kObject *)ret->protected_data.l)->refs : &ret->target->capabilities)
2009-09-12 23:48:47 +03:00
return
case Iris::Caps::GET_SIZE & REQUEST_MASK:
2009-09-12 23:48:47 +03:00
reply_num (caps->size)
return
case Iris::Caps::SET & REQUEST_MASK:
2009-09-06 12:04:09 +03:00
if c->data[1].l >= caps->size:
dpanic (0, "invalid index for set caps")
return
caps->clone (c->data[1].l, c->arg, c->copy[1])
reply_num (0)
2010-01-24 22:34:24 +02:00
//kdebug_num ((unsigned)caps)
//kdebug (" set cap ")
//kdebug_num (c->data[1].l)
//kdebug (" to ")
//kdebug_num ((unsigned)caps->caps[c->data[1].l].target)
//kdebug ("/")
//kdebug_num (caps->caps[c->data[1].l].protected_data.h)
//kdebug (":")
//kdebug_num (caps->caps[c->data[1].l].protected_data.l)
//kdebug ("\n")
2009-09-06 12:04:09 +03:00
return
case Iris::Caps::TRUNCATE & REQUEST_MASK:
2009-09-12 23:48:47 +03:00
dpanic (0, "truncate caps is not implemented yet.")
return
case Iris::Caps::PRINT & REQUEST_MASK:
2009-08-24 22:02:35 +03:00
if c->data[1].l >= caps->size:
dpanic (0, "invalid caps for print")
return
kCapRef cap (caps, c->data[1].l)
kCapRef orig (caps, c->data[1].l)
while cap->parent.valid ():
while cap->sibling_prev.valid ():
if cap->parent.deref () != cap->sibling_prev->parent.deref ():
dpanic (0, "parent problem in cap data")
return
if cap.deref () != cap->sibling_prev->sibling_next.deref ():
dpanic (0, "prev error in cap data")
return
cap = cap->sibling_prev
if cap->parent->children.deref () != cap.deref ():
dpanic (0, "parent error in cap data")
return
cap = cap->parent
while cap->sibling_prev.valid ():
if cap->parent.deref () != cap->sibling_prev->parent.deref ():
dpanic (0, "parent parent problem in cap data")
return
if cap.deref () != cap->sibling_prev->sibling_next.deref ():
dpanic (0, "parent prev error in cap data")
return
cap = cap->sibling_prev
while cap.valid ():
print_cap (cap, orig)
cap = cap->sibling_next
2010-01-24 22:34:24 +02:00
kdebug ('\n')
2009-08-24 22:02:35 +03:00
return
2009-05-25 01:31:35 +03:00
default:
2010-01-30 10:21:56 +02:00
dpanic (cmd, "invalid caps operation")
reply_num (Iris::ERR_INVALID_OPERATION)
2009-08-24 22:02:35 +03:00
return
2009-05-25 01:31:35 +03:00
static void list_invoke (unsigned cmd, unsigned target, Iris::Num protected_data, kCapability::Context *c):
2009-12-30 15:00:37 +02:00
kList *list = (kListP)protected_data.l
if cmd == Iris::List::SET_CB & REQUEST_MASK:
2009-12-30 15:00:37 +02:00
list->owner.clone (0, c->arg, c->copy[1])
return
kListitem *item
if !c->arg.valid ():
item = NULL
else:
if ((unsigned)c->arg->target & ~REQUEST_MASK) != CAPTYPE_LISTITEM:
dpanic (0, "invalid request for list: arg is no listitem")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-12-30 15:00:37 +02:00
return
item = (kListitem *)c->arg->protected_data.l
if item->list != list:
dpanic (0, "item list is not equal to called object")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-12-30 15:00:37 +02:00
return
switch cmd:
case Iris::List::GET_NEXT & REQUEST_MASK:
2009-12-30 15:00:37 +02:00
if !item:
item = list->first_listitem
else:
if ((unsigned)c->arg->target & REQUEST_MASK) != CAP_MASTER && ((unsigned)c->arg->target & REQUEST_MASK) != Iris::Listitem::LIST:
2009-12-30 15:00:37 +02:00
dpanic (0, "trying to get next listitem with insufficient rights")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-12-30 15:00:37 +02:00
return
item = item->next_item
if !item:
reply_num (0)
return
reply_cap (CAPTYPE_LISTITEM | Iris::Listitem::LIST, (unsigned)item, &item->refs)
2009-12-30 15:00:37 +02:00
return
case Iris::List::ADD_ITEM & REQUEST_MASK:
2009-12-30 15:00:37 +02:00
if !item:
dpanic (0, "invalid request: no listitem for List::ADD_ITEM")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-12-30 15:00:37 +02:00
return
if ((unsigned)c->arg->target & REQUEST_MASK) != CAP_MASTER && ((unsigned)c->arg->target & REQUEST_MASK) != Iris::Listitem::ADD:
2009-12-30 15:00:37 +02:00
dpanic (0, "trying to add listitem with insufficient rights")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-12-30 15:00:37 +02:00
return
((kListitem *)c->arg->protected_data.l)->add (list)
break
case Iris::List::GET_INFO & REQUEST_MASK:
2009-12-30 15:00:37 +02:00
if !item:
dpanic (0, "no item for List::GET_INFO")
reply_num (Iris::ERR_INVALID_ARGUMENT, ~0, ~0)
2009-12-30 15:00:37 +02:00
return
reply_num (item->info)
return
case Iris::List::SET_INFO & REQUEST_MASK:
2009-12-30 15:00:37 +02:00
if !item:
dpanic (0, "no item for List::SET_INFO")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-12-30 15:00:37 +02:00
return
item->info = c->data[1]
break
case Iris::List::GET_CAP & REQUEST_MASK:
2009-12-30 15:00:37 +02:00
if !item:
dpanic (0, "no item for List::GET_CAP")
reply_num (Iris::ERR_INVALID_ARGUMENT)
2009-12-30 15:00:37 +02:00
return
kCapability *cap = item->target.cap (0)
reply_cap ((unsigned)cap->target, cap->protected_data, ((unsigned)cap->target & ~KERNEL_MASK) == 0 ? &((kObject *)cap->target)->refs : &cap->target->capabilities)
return
default:
dpanic (0, "invalid list operation")
reply_num (Iris::ERR_INVALID_OPERATION)
2009-12-30 15:00:37 +02:00
return
reply_num (0)
static void listitem_invoke (unsigned cmd, unsigned target, Iris::Num protected_data, kCapability::Context *c):
2009-12-30 15:00:37 +02:00
kListitem *item = (kListitemP)protected_data.l
switch cmd:
case Iris::Listitem::CLEAR & REQUEST_MASK:
2009-12-30 15:00:37 +02:00
// Disable linked capability.
item->add (NULL)
break
case Iris::Listitem::SET_CAP & REQUEST_MASK:
2009-12-30 15:00:37 +02:00
// Set linked capability.
item->target.clone (0, c->arg, c->copy[1])
break
default:
dpanic (0, "invalid listitem operation")
reply_num (Iris::ERR_INVALID_OPERATION)
2009-12-30 15:00:37 +02:00
return
reply_num (0)
2009-09-06 12:04:09 +03:00
static void kill_reply (kReceiver *r):
kCapRef cap = r->refs
while cap.valid ():
kCapability *c = cap.deref ()
cap = c->sibling_next
if (unsigned)c->target == (CAPTYPE_RECEIVER | Iris::Receiver::REPLY):
2009-09-06 12:04:09 +03:00
c->invalidate ()
static void kernel_invoke (unsigned target, Iris::Num protected_data, kCapability::Context *c):
2009-05-25 01:31:35 +03:00
// Kernel calling convention:
// data[0].l is the request.
2009-10-10 02:31:10 +03:00
// reply is the reply capability, or (for call capabilities) the target to call.
2009-05-25 01:31:35 +03:00
// other parameters' meanings depend on the operation.
if target == (CAPTYPE_RECEIVER | Iris::Receiver::CALL) || target == (CAPTYPE_RECEIVER | Iris::Receiver::CALL_ASYNC):
2009-10-10 02:31:10 +03:00
// This is a call capability. reply is the capability to call.
kReceiver *owner = (kReceiver *)protected_data.l
owner->protected_only = target == (CAPTYPE_RECEIVER | Iris::Receiver::CALL)
2009-08-24 22:02:35 +03:00
if must_wait:
old_current->wait ()
2009-09-06 12:04:09 +03:00
if !reply_target:
2010-01-24 22:34:24 +02:00
if (c->reply.index & ~CAP_COPY) != CAP_NONE:
kdebug ("target index: ")
kdebug_num (c->reply.index)
kdebug ("\n")
dpanic (0x54635675, "no target to call")
return
2009-09-06 12:04:09 +03:00
if ((unsigned)reply_target & ~KERNEL_MASK) != 0:
// This is a user-implemented object. Create a real reply capability.
2009-09-06 12:04:09 +03:00
kReceiver *call_target = reply_target
c->reply = kCapRef (&reply_caps, 0)
c->reply.set ((kReceiver *)(CAPTYPE_RECEIVER | Iris::Receiver::REPLY), protected_data, kCapRef (), &((kReceiver *)protected_data.l)->refs)
2009-09-06 12:04:09 +03:00
c->copy[0] = true
call_target->send_message (reply_protected, c)
c->reply->invalidate ()
else if (unsigned)reply_target == (CAPTYPE_RECEIVER | Iris::Receiver::REPLY):
// Reply capability: destroy all before invoke.
2009-09-06 12:04:09 +03:00
kReceiver *r = (kReceiver *)reply_protected.l
kill_reply (r)
r->send_message (r->reply_protected_data, c)
else:
// Kernel call: don't create actual capablities.
2009-09-06 12:04:09 +03:00
kCapRef call_target = c->reply
c->reply.reset ()
reply_target = (kReceiver *)protected_data.l
reply_protected = reply_target->reply_protected_data
2009-09-06 12:04:09 +03:00
kernel_invoke ((unsigned)call_target->target, call_target->protected_data, c)
2009-07-20 01:23:45 +03:00
return
2009-08-24 22:02:35 +03:00
if must_wait:
old_current->wait ()
if target == (CAPTYPE_RECEIVER | Iris::Receiver::REPLY):
2009-05-29 00:35:27 +03:00
// This is a reply capability.
2009-09-06 12:04:09 +03:00
kReceiver *r = (kReceiver *)protected_data.l
kill_reply (r)
2009-06-10 23:54:12 +03:00
r->send_message (r->reply_protected_data, c)
2009-07-20 01:23:45 +03:00
return
2009-08-24 22:02:35 +03:00
if !target:
return
unsigned cmd
if (target & REQUEST_MASK) == CAP_MASTER:
if c->data[0].l & CAP_MASTER_CREATE:
2009-09-06 12:04:09 +03:00
reply_cap (target | (c->data[0].l & REQUEST_MASK), protected_data, &((kObject *)protected_data.l)->refs)
return
cmd = c->data[0].l
c->data[0].l = 0
else:
2009-09-07 00:34:50 +03:00
cmd = target
cmd &= REQUEST_MASK
2009-05-25 01:31:35 +03:00
switch target & CAPTYPE_MASK:
case CAPTYPE_RECEIVER:
2009-09-06 12:04:09 +03:00
receiver_invoke (cmd, target, protected_data, c)
2009-05-25 01:31:35 +03:00
break
case CAPTYPE_MEMORY:
2009-09-06 12:04:09 +03:00
memory_invoke (cmd, target, protected_data, c)
2009-05-25 01:31:35 +03:00
break
case CAPTYPE_THREAD:
2009-09-06 12:04:09 +03:00
thread_invoke (cmd, target, protected_data, c)
2009-05-25 01:31:35 +03:00
break
case CAPTYPE_PAGE:
2009-09-06 12:04:09 +03:00
page_invoke (cmd, target, protected_data, c)
2009-05-25 01:31:35 +03:00
break
case CAPTYPE_CAPS:
2009-09-06 12:04:09 +03:00
caps_invoke (cmd, target, protected_data, c)
2009-05-25 01:31:35 +03:00
break
2009-12-30 15:00:37 +02:00
case CAPTYPE_LIST:
list_invoke (cmd, target, protected_data, c)
break
case CAPTYPE_LISTITEM:
listitem_invoke (cmd, target, protected_data, c)
break
2009-05-25 01:31:35 +03:00
default:
panic (0x99337744, "invalid capability type invoked")
2009-07-24 15:25:53 +03:00
return
2009-07-20 01:23:45 +03:00
return
2009-05-25 01:31:35 +03:00
void invoke (kReceiverP target, Iris::Num protected_data, kCapability::Context *c):
2010-01-24 22:34:24 +02:00
if dbg_code.l && old_current->id != 1:
log_message ("invoke", (unsigned)target, protected_data.l, c)
2009-05-27 19:33:05 +03:00
if (unsigned)target & ~KERNEL_MASK:
// This is not a kernel capability: send a message to the receiver.
2009-08-24 22:02:35 +03:00
if must_wait:
old_current->wait ()
2010-01-24 22:34:24 +02:00
//else
// log_message ("user invoke", (unsigned)target, protected_data.l, c)
2009-09-06 12:04:09 +03:00
target->send_message (protected_data, c)
2009-07-20 01:23:45 +03:00
return
2009-05-25 01:31:35 +03:00
// This is a kernel capability. Use a function to allow optimized call capabilities.
2010-01-24 22:34:24 +02:00
//if !must_wait && old_current->id == ~0
// log_message ("kernel invoke", (unsigned)target, protected_data.l, c)
2009-09-06 12:04:09 +03:00
context = c
if c->reply.valid ():
reply_target = c->reply->target
reply_protected = c->reply->protected_data
else:
2009-09-06 12:04:09 +03:00
reply_target = NULL
reply_protected.l = 0
2009-09-06 12:04:09 +03:00
kernel_invoke ((unsigned)target, protected_data, c)