X-Git-Url: http://git.buserror.net/cgi-bin/gitweb.cgi?p=polintos%2Fscott%2Fpriv.git;a=blobdiff_plain;f=kernel%2Forb%2Finvoke.cc;h=8d4f3eb96370a03fab278e4edbd06eb29b49e9bb;hp=b2e5de80bb05d3a9304dd158e95529abe64ac915;hb=1ac390fe1e18444008857b056c947710be9621a8;hpb=77bf9a95a836b14a243953e1fbd28c7c1106c59a diff --git a/kernel/orb/invoke.cc b/kernel/orb/invoke.cc index b2e5de8..8d4f3eb 100644 --- a/kernel/orb/invoke.cc +++ b/kernel/orb/invoke.cc @@ -1,6 +1,6 @@ // orb/invoke.cc -- Method Invocation // -// This software is copyright (c) 2006 Scott Wood . +// This software is copyright (c) 2007 Scott Wood . // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors or contributors be held liable for any damages @@ -16,12 +16,21 @@ #include #include #include +#include +#include +#include +#include + #include + +#include #include using System::RunTime::ParamInfoBlock; +typedef ParamInfoBlock::Segment Segment; using namespace ORB; using Threads::Thread; +using Util::round_up; namespace ORB { static CallFrame *new_frame(Thread *thread) @@ -41,24 +50,179 @@ namespace ORB { return &hdr->frames[0]; } - return &hdr->frames[thread->orbstack_top += 1]; + return &hdr->frames[++thread->orbstack_top]; } -} + + Object *IDSpace::lookup(ID id) + { + // FIXME: refcounting + ObjTableEntry *ote = table.lookup(id); + if (!ote || !ote->hdr.Valid) + return NULL; + + if (ote->hdr.Pointer) + return ote->ptr.object; -extern "C" void invoke_method(ulong objid, ulong methid, - ParamInfoBlock *user_pib, ulong ret_pc) -{ - ParamInfoBlock pib = Arch::copyin(user_pib); - CallFrame *frame = new_frame(curthread); + return &ote->obj; + } + + ObjectHdr *IDSpace::get_local(Object *obj) + { + if (&obj->aspace->idspace == this) + return obj; - frame->object = objid; - frame->method = methid; - frame->caller_user_pib = user_pib; - frame->ret_pc = ret_pc; + Lock::AutoSpinLock autolock(lock); + ObjectPtr *ptr = *rmap.find(obj); + if (ptr) + return ptr; + + int id = alloc.alloc(); + ptr = &table.lookup(id, true)->ptr; + + ptr->id = id; + ptr->flags = 0; + ptr->Valid = 1; + ptr->Pointer = 1; + ptr->object = obj; + + rmap.add(obj, ptr); + return ptr; + } + + Object *IDSpace::newobj(Mem::ProcAddrSpace *aspace) + { + Lock::AutoSpinLock autolock(lock); + int id = alloc.alloc(); + Object *obj = &table.lookup(id, true)->obj; + + obj->id = id; + obj->flags = 0; + obj->Valid = 1; + obj->aspace = aspace; + + return obj; + } - printf("invoke_method: frame %p object %lx method %lx pib %p ret %lx\n", - frame, frame->object, frame->method, frame->caller_user_pib, - frame->ret_pc); + static void copy_data(u8 *dest, u8 *vaddr, size_t bufsize, + ParamInfoBlock *dpib, ParamInfoBlock *spib, + u32 fmask, u32 flags) + { + size_t copied = 0; + for (uint i = 0; i < spib->num_segments; i++) { + if ((spib->segments[i].flags & fmask) != flags) + continue; + + size_t len = round_up(spib->segments[i].len, 3); + + if (len + copied > bufsize || len + copied < copied) + throw_idl(InvalidArgument, 0, countarray("copy_data: bad size")); + + dpib->segments[i].ptr = vaddr; + dpib->segments[i].len = len; + dpib->segments[i].reserved = 0; + Arch::copyin(spib->segments[i].ptr, dest, len); + + copied += len; + dest += len; + vaddr += len; + } + } + + typedef void (*KernEntry)(ParamInfoBlock *pib); + + struct KernObject : public Object { + KernEntry entry; + }; + + typedef Util::RadixTree KIDTable; + KIDTable *kernobjs; + void copy_ids_to_kern(ParamInfoBlock *dpib, ParamInfoBlock *spib, + IDSpace *ids) + { + dpib->objlist_len = spib->objlist_len; + + for (uint i = 0; i < spib->objlist_len; i++) { + Object *obj = ids->lookup(spib->objlist[i]); + + if (!obj) + throw_idl(InvalidReference, i, nullarray); + + dpib->objlist[i] = reinterpret_cast(obj); + } + } + + void invoke_method(ParamInfoBlock *user_pib, uintptr_t &stack) + { + printf("invoke_method: pib %p\n", user_pib); + + ParamInfoBlock pib = Arch::copyin(user_pib); + printf("objlist len %lu\n", pib.objlist_len); + + if (pib.objlist_len == 0) + throw_idl(InvalidArgument, 0, countarray("no objects")); + + // FIXME: declare constants somewhere + if (pib.num_segments > 64) + throw_idl(InvalidArgument, 0, countarray("too many segments")); + if (pib.objlist_len > 4096) + throw_idl(InvalidArgument, 0, countarray("too many objects")); + + printf("&pib.objlist[0] %p\n", &pib.objlist[0]); + + IDSpace *ids = &curthread->aspace->idspace; + ID objid = Arch::copyin(&pib.objlist[0]); + Object *obj = ids->lookup(objid); + + if (!obj) { + printf("no obj %d\n", objid); + throw_idl(InvalidReference, 0, nullarray); + } + + printf("obj %p\n", obj); + + if (obj->aspace == Arch::init_thread->aspace) { + KernObject *ko = static_cast(obj); + int datalen = round_up(pib.buffer_size, 8); + int buflen = datalen + pib.objlist_len * sizeof(void *); + int piboff = datalen; + buflen += sizeof(ParamInfoBlock); + buflen += pib.num_segments * sizeof(ParamInfoBlock::Segment); + + u8 *args = new(orbmm) u8[buflen]; + u8 *copy = new(orbmm) u8[pib.copy_size]; + ParamInfoBlock *dpib = reinterpret_cast + (args + piboff); + dpib->objlist = reinterpret_cast(args + datalen); + + copy_ids_to_kern(dpib, &pib, ids); + copy_data(args, args, pib.buffer_size, dpib, &pib, ~0U, Segment::In); + copy_data(copy, copy, pib.copy_size, dpib, &pib, ~0U, + Segment::In | Segment::Copy); + + ko->entry(dpib); + + // FIXME: Copy return data + return; + } + + CallFrame *frame = new_frame(curthread); + frame->caller_user_pib = user_pib; + frame->ret_stack = stack; + + printf("invoke_method: frame %p pib %p ret_stack %lx obj %p\n", + frame, frame->caller_user_pib, + frame->ret_stack, obj); + } + + uintptr_t return_from_method(uintptr_t &exptr, size_t &exlen) + { + return 0; + } + + void init() + { + kernobjs = new KIDTable; + } }