X-Git-Url: http://git.buserror.net/cgi-bin/gitweb.cgi?p=polintos%2Fscott%2Fpriv.git;a=blobdiff_plain;f=kernel%2Forb%2Finvoke.cc;fp=kernel%2Forb%2Finvoke.cc;h=8d4f3eb96370a03fab278e4edbd06eb29b49e9bb;hp=ffcd8372318c4e8f581fc490602c73b750c4993b;hb=1ac390fe1e18444008857b056c947710be9621a8;hpb=6e64b28821757af60447c790ae52a91831a9d4f0 diff --git a/kernel/orb/invoke.cc b/kernel/orb/invoke.cc index ffcd837..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 @@ -17,14 +17,20 @@ #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) @@ -46,59 +52,177 @@ namespace ORB { 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; - ObjectHdr *IDSpace::get_local_hdr(Object *obj) + return &ote->obj; + } + + ObjectHdr *IDSpace::get_local(Object *obj) { - ObjectHdr *hdr = *rmap.lookup(obj->id); - if (hdr) - return hdr; + if (&obj->aspace->idspace == this) + return obj; + + Lock::AutoSpinLock autolock(lock); + ObjectPtr *ptr = *rmap.find(obj); + if (ptr) + return ptr; int id = alloc.alloc(); - ObjectPtr *ptr = &table.lookup(id, true)->ptr; + ptr = &table.lookup(id, true)->ptr; ptr->id = id; ptr->flags = 0; + ptr->Valid = 1; ptr->Pointer = 1; ptr->object = obj; - *rmap.lookup(id, true) = ptr; + rmap.add(obj, ptr); return ptr; } - Object *IDSpace::newobj(Mem::ProcAddrSpace *aspace, uintptr_t entry) + 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; - obj->entry = entry; return obj; } + + 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); - CallFrame *frame = new_frame(curthread); + 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); + } -// if (pib->objlist_len == 0) + 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; + } -// frame->object = objid; + CallFrame *frame = new_frame(curthread); frame->caller_user_pib = user_pib; -// frame->ret_pc = ret_pc; + frame->ret_stack = stack; - printf("invoke_method: frame %p pib %p ret %lx\n", + printf("invoke_method: frame %p pib %p ret_stack %lx obj %p\n", frame, frame->caller_user_pib, - frame->ret_pc); - - + frame->ret_stack, obj); } uintptr_t return_from_method(uintptr_t &exptr, size_t &exlen) { return 0; } + + void init() + { + kernobjs = new KIDTable; + } }