Skip to content

Commit

Permalink
tests.extra/regress-double_ref_shared
Browse files Browse the repository at this point in the history
  • Loading branch information
nwf committed Feb 21, 2025
1 parent 4e67064 commit 092a41b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests.extra/regress-double_ref_shared/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This exhibits one compartment with two compilatioon units that each reference a
shared object with different permissions. Because of the differing permissions,
two import entries should be created.
13 changes: 13 additions & 0 deletions tests.extra/regress-double_ref_shared/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <compartment-macros.h>

struct Foo
{
int bar;
};

void top1();
void top2();

int __cheri_compartment("top") entry();
17 changes: 17 additions & 0 deletions tests.extra/regress-double_ref_shared/top1.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "common.h"

void top1()
{
auto ref1 =
SHARED_OBJECT_WITH_PERMISSIONS(struct Foo, foo, true, true, false, false);

ref1->bar = 1;
}

int entry()
{
top1();
top2();

return 0;
}
13 changes: 13 additions & 0 deletions tests.extra/regress-double_ref_shared/top2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "common.h"

#include <debug.hh>

using Debug = ConditionalDebug<true, "top2">;

void top2()
{
auto ref2 = SHARED_OBJECT_WITH_PERMISSIONS(
struct Foo, foo, true, false, false, false);

Debug::log("ref2: {}", ref2->bar);
}
31 changes: 31 additions & 0 deletions tests.extra/regress-double_ref_shared/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
set_project("CHERIoT Scheduler IRQ Exception PoC")
sdkdir = "../../sdk"
includes(sdkdir)
set_toolchains("cheriot-clang")

option("board")
set_default("sail")

compartment("top")
add_files("top1.cc")
add_files("top2.cc")

on_load(function(target)
target:values_set("shared_objects", { foo = 4 }, {expand = false})
end)

firmware("top_compartment")
add_deps("freestanding", "debug")
add_deps("top")
on_load(function(target)
target:values_set("board", "$(board)")
target:values_set("threads", {
{
compartment = "top",
priority = 1,
entry_point = "entry",
stack_size = 0x200,
trusted_stack_frames = 1
}
}, {expand = false})
end)

0 comments on commit 092a41b

Please sign in to comment.