diff --git a/kernel/app/init-example/app/init.cc b/kernel/app/init-example/app/init.cc index e27c8497..4b81f6fc 100644 --- a/kernel/app/init-example/app/init.cc +++ b/kernel/app/init-example/app/init.cc @@ -517,6 +517,19 @@ void test_process(){ MLOG_INFO(mlog::app, "Test process finished"); } +void testCapMapDeletion(){ + MLOG_INFO(mlog::app, "Test CapMap deletion"); + + mythos::PortalLock pl(portal); + mythos::CapMap cs(capAlloc()); + + auto res = cs.create(pl, kmem, CapPtrDepth(12), CapPtrDepth(20), CapPtr(0)).wait(); + ASSERT(res); + + capAlloc.free(cs.cap(), pl); + MLOG_INFO(mlog::app, "Test CapMap deletion finished"); +} + int main() { char const str[] = "Hello world!"; @@ -535,8 +548,9 @@ int main() test_pthreads(); test_Rapl(); test_processor_allocator(); - test_process(); + //test_process(); //test_CgaScreen(); + testCapMapDeletion(); char const end[] = "bye, cruel world!"; mythos::syscall_debug(end, sizeof(end)-1); diff --git a/kernel/mythos/invocation/mythos/protocol/CapMap.hh b/kernel/mythos/invocation/mythos/protocol/CapMap.hh index c3fb1689..cb9867d7 100644 --- a/kernel/mythos/invocation/mythos/protocol/CapMap.hh +++ b/kernel/mythos/invocation/mythos/protocol/CapMap.hh @@ -37,7 +37,6 @@ namespace mythos { enum Methods : uint8_t { DERIVE, REFERENCE, - MOVE, DELETE, REVOKE }; @@ -90,16 +89,6 @@ namespace mythos { CapRequest request; }; - struct Move : public BinaryOp { - constexpr static uint16_t label = (proto<<8) + MOVE; - - Move(CapPtr src, uint8_t srcDepth, - CapPtr dstCS, CapPtr dst, uint8_t dstDepth) - : BinaryOp(label, getLength(this), src, srcDepth, dstCS, dst, dstDepth) - {} - - }; - struct Delete : public InvocationBase { constexpr static uint16_t label = (proto<<8) + DELETE; @@ -142,7 +131,6 @@ namespace mythos { switch(Methods(m)) { case REFERENCE: return obj->invokeReference(args...); case DERIVE: return obj->invokeDerive(args...); - case MOVE: return obj->invokeMove(args...); case DELETE: return obj->invokeDelete(args...); case REVOKE: return obj->invokeRevoke(args...); default: return Error::NOT_IMPLEMENTED; diff --git a/kernel/objects/capmap/objects/CapMap.cc b/kernel/objects/capmap/objects/CapMap.cc index 3615bd21..1b926f01 100644 --- a/kernel/objects/capmap/objects/CapMap.cc +++ b/kernel/objects/capmap/objects/CapMap.cc @@ -66,15 +66,15 @@ namespace mythos { CapMapFactory::factory(CapEntry* dstEntry, CapEntry* memEntry, Cap memCap, IAllocator* mem, CapPtrDepth indexbits, CapPtrDepth guardbits, CapPtr guard) { - auto obj = initial(memEntry, memCap, mem, indexbits, guardbits, guard); - if (!obj) RETHROW(obj); - auto& root = obj->getRoot(); - auto cap = root.cap(); - // Just a reference is stored in the target capability entry. - // The CapMap contains its original capability internally - // in order to resolve cyclic dependencies during deletion. - auto res = cap::inherit(root, cap, *dstEntry, cap.asReference()); - if (!res) RETHROW(res); // the object was deleted concurrently + auto ptr = mem->alloc(CapMap::size(indexbits), 64); + if (!ptr) RETHROW(ptr); + auto obj = new(*ptr) CapMap(mem, indexbits, guardbits, guard); + auto cap = Cap(obj).withData(CapMapData().writable(true)); + auto res = cap::inherit(*memEntry, memCap, *dstEntry, cap); + if (!res) { + mem->free(*ptr, CapMap::size(indexbits)); + RETHROW(res); + } return obj; } @@ -86,7 +86,9 @@ namespace mythos { optional CapMap::deleteCap(CapEntry&, Cap self, IDeleter& del) { + MLOG_INFO(mlog::cap, "CapMap::deleteCap"); if (self.isOriginal()) { + MLOG_DETAIL(mlog::cap, "delete original"); // delete all entries, leaves them in a locked state (allocated) // in order to prevent concurrent insertion of new caps. for (size_t i=0; igetProtocol()) { @@ -186,21 +188,6 @@ namespace mythos { return cap::reference(*srcRef->entry, *dstRef->entry, srcRef->entry->cap(), data.request).state(); } - Error CapMap::invokeMove(Tasklet*, Cap cap, IInvocation* msg) - { - auto data = msg->getMessage()->read(); - // retrieve dst cap entry - auto dstRef = lookupDst(cap, msg, data); - if (!dstRef) return dstRef.state(); - // retrieve source cap entry - auto srcRef = this->lookup(cap, data.srcPtr(), data.srcDepth, true); - if (!srcRef) return srcRef.state(); - // move - auto res = dstRef->entry->acquire(); - if (!res) { return res.state(); } - return srcRef->entry->moveTo(*dstRef->entry).state(); - } - Error CapMap::invokeDelete(Tasklet*, Cap cap, IInvocation* msg) { auto data = msg->getMessage()->read(); diff --git a/kernel/objects/capmap/objects/CapMap.hh b/kernel/objects/capmap/objects/CapMap.hh index 51b7a967..6bc3c757 100644 --- a/kernel/objects/capmap/objects/CapMap.hh +++ b/kernel/objects/capmap/objects/CapMap.hh @@ -75,7 +75,6 @@ public: // IKernelObject interface Error invokeReference(Tasklet*, Cap, IInvocation*); Error invokeDerive(Tasklet*, Cap, IInvocation*); - Error invokeMove(Tasklet*, Cap, IInvocation*); Error invokeDelete(Tasklet*, Cap, IInvocation*); Error invokeRevoke(Tasklet*, Cap, IInvocation*); Error getDebugInfo(Cap, IInvocation*); diff --git a/kernel/runtime/kobject/runtime/CapMap.hh b/kernel/runtime/kobject/runtime/CapMap.hh index 945e9edf..f93970c1 100644 --- a/kernel/runtime/kobject/runtime/CapMap.hh +++ b/kernel/runtime/kobject/runtime/CapMap.hh @@ -57,11 +57,6 @@ namespace mythos { return pr.invoke(_cap, src, srcDepth, dstCs, dst, dstDepth, req); } - PortalFuture move(PortalLock pr, CapPtr src, CapPtrDepth srcDepth, - CapPtr dstCs, CapPtr dst, CapPtrDepth dstDepth) { - return pr.invoke(_cap, src, srcDepth, dstCs, dst, dstDepth); - } - PortalFuture deleteCap(PortalLock pr, CapPtr src, CapPtrDepth srcDepth) { return pr.invoke(_cap, src, srcDepth); } diff --git a/kernel/runtime/process/runtime/process.hh b/kernel/runtime/process/runtime/process.hh index 77c9cd7d..76df41bf 100644 --- a/kernel/runtime/process/runtime/process.hh +++ b/kernel/runtime/process/runtime/process.hh @@ -128,10 +128,10 @@ class Process{ res = myAS.removeMap(pl, tmp_vaddr, 3).wait(); TEST(res); - MLOG_DETAIL(mlog::app, " move frame"); - res = myCS.move(pl, f.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(f.cap()); + //MLOG_DETAIL(mlog::app, " move frame"); + //res = myCS.move(pl, f.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(f.cap()); MLOG_DETAIL(mlog::app, " delete tables"); capAlloc.free(pm3, pl); @@ -142,7 +142,8 @@ class Process{ optional createProcess(PortalLock& pl){ MLOG_INFO(mlog::app, __func__); - + MLOG_ERROR(mlog::app, "process needs to be reworked!"); + return 0; /* create CapMap */ MLOG_DETAIL(mlog::app, "create CapMap ..."); auto res = cs.create(pl, kmem, CapPtrDepth(12), CapPtrDepth(20), CapPtr(0)).wait(); @@ -302,9 +303,9 @@ class Process{ .suspended(true) .invokeVia(pl).wait(); TEST(res); - MLOG_DETAIL(mlog::app, "move SC"); - res = myCS.move(pl, sc->cap, max_cap_depth, cs.cap(), sc->cap, max_cap_depth).wait(); - TEST(res); + //MLOG_DETAIL(mlog::app, "move SC"); + //res = myCS.move(pl, sc->cap, max_cap_depth, cs.cap(), sc->cap, max_cap_depth).wait(); + //TEST(res); /* create portal */ MLOG_DETAIL(mlog::app, "create Portal ..."); @@ -318,66 +319,66 @@ class Process{ TEST(res); MLOG_DETAIL(mlog::app, " move Portal"); - res = myCS.move(pl, port.cap(), max_cap_depth, cs.cap(), init::PORTAL, max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(port.cap()); + //res = myCS.move(pl, port.cap(), max_cap_depth, cs.cap(), init::PORTAL, max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(port.cap()); - MLOG_DETAIL(mlog::app, " move info frame"); - res = myCS.move(pl, infoFrame.cap(), max_cap_depth, cs.cap(), init::INFO_FRAME, max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(infoFrame.cap()); + //MLOG_DETAIL(mlog::app, " move info frame"); + //res = myCS.move(pl, infoFrame.cap(), max_cap_depth, cs.cap(), init::INFO_FRAME, max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(infoFrame.cap()); /* move tables */ MLOG_DETAIL(mlog::app, "move tables ..."); - res = myCS.move(pl, pm3.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm3.cap()); + //res = myCS.move(pl, pm3.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm3.cap()); - res = myCS.move(pl, pm2.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm2.cap()); + //res = myCS.move(pl, pm2.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm2.cap()); - res = myCS.move(pl, pm10.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm10.cap()); + //res = myCS.move(pl, pm10.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm10.cap()); - res = myCS.move(pl, pm11.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm11.cap()); + //res = myCS.move(pl, pm11.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm11.cap()); - res = myCS.move(pl, pm12.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm12.cap()); + //res = myCS.move(pl, pm12.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm12.cap()); - res = myCS.move(pl, pm13.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm13.cap()); + //res = myCS.move(pl, pm13.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm13.cap()); - res = myCS.move(pl, pm14.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm14.cap()); + //res = myCS.move(pl, pm14.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm14.cap()); - res = myCS.move(pl, pm15.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm15.cap()); + //res = myCS.move(pl, pm15.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm15.cap()); - res = myCS.move(pl, pm16.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm16.cap()); + //res = myCS.move(pl, pm16.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm16.cap()); - res = myCS.move(pl, pm17.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm17.cap()); + //res = myCS.move(pl, pm17.cap(), max_cap_depth, cs.cap(), pCapAlloc(), max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm17.cap()); - res = myCS.move(pl, pm4.cap(), max_cap_depth, cs.cap(), init::PML4, max_cap_depth).wait(); - TEST(res); - capAlloc.freeEmpty(pm4.cap()); + //res = myCS.move(pl, pm4.cap(), max_cap_depth, cs.cap(), init::PML4, max_cap_depth).wait(); + //TEST(res); + //capAlloc.freeEmpty(pm4.cap()); /* wake EC */ MLOG_DETAIL(mlog::app, "start process ..."); - MLOG_DETAIL(mlog::app, " move EC"); - res = myCS.move(pl, ec.cap(), max_cap_depth, cs.cap(), init::EC, max_cap_depth).wait(); - TEST(res); + //MLOG_DETAIL(mlog::app, " move EC"); + //res = myCS.move(pl, ec.cap(), max_cap_depth, cs.cap(), init::EC, max_cap_depth).wait(); + //TEST(res); MLOG_DETAIL(mlog::app, " create reference"); res = cs.reference(pl, init::EC, max_cap_depth, init::CSPACE, ec.cap(), max_cap_depth, 0).wait();