Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion kernel/app/init-example/app/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand All @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions kernel/mythos/invocation/mythos/protocol/CapMap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace mythos {
enum Methods : uint8_t {
DERIVE,
REFERENCE,
MOVE,
DELETE,
REVOKE
};
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
37 changes: 12 additions & 25 deletions kernel/objects/capmap/objects/CapMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -86,7 +86,9 @@ namespace mythos {

optional<void> 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; i<cap_count(indexbits); i++) {
Expand Down Expand Up @@ -122,7 +124,7 @@ namespace mythos {

void CapMap::invoke(Tasklet* t, Cap self, IInvocation* msg)
{
/// @todo Monitor might not be neccessary for derive, reference, move
/// @todo Monitor might not be neccessary for derive, reference
monitor.request(t, [=](Tasklet* t){
Error err = Error::NOT_IMPLEMENTED;
switch (msg->getProtocol()) {
Expand Down Expand Up @@ -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<protocol::CapMap::Move>();
// 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<protocol::CapMap::Delete>();
Expand Down
1 change: 0 additions & 1 deletion kernel/objects/capmap/objects/CapMap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down
5 changes: 0 additions & 5 deletions kernel/runtime/kobject/runtime/CapMap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ namespace mythos {
return pr.invoke<protocol::CapMap::Reference>(_cap, src, srcDepth, dstCs, dst, dstDepth, req);
}

PortalFuture<void> move(PortalLock pr, CapPtr src, CapPtrDepth srcDepth,
CapPtr dstCs, CapPtr dst, CapPtrDepth dstDepth) {
return pr.invoke<protocol::CapMap::Move>(_cap, src, srcDepth, dstCs, dst, dstDepth);
}

PortalFuture<void> deleteCap(PortalLock pr, CapPtr src, CapPtrDepth srcDepth) {
return pr.invoke<protocol::CapMap::Delete>(_cap, src, srcDepth);
}
Expand Down
103 changes: 52 additions & 51 deletions kernel/runtime/process/runtime/process.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -142,7 +142,8 @@ class Process{

optional<CapPtr> 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();
Expand Down Expand Up @@ -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 ...");
Expand All @@ -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();
Expand Down