From 413265ef50bdd95a1d5b60213ef4ed08489cc778 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Thu, 27 Jan 2022 14:06:29 +0000 Subject: [PATCH 01/20] Add tests folder --- tests/simple.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/simple.c diff --git a/tests/simple.c b/tests/simple.c new file mode 100644 index 0000000..e69de29 From d01072153d59749cc0834397674b32ed26379187 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Thu, 27 Jan 2022 14:08:31 +0000 Subject: [PATCH 02/20] Add src folder --- src/manager.S | 62 +++++++++++++++++++++++++++++++++++ src/switcher.S | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 src/manager.S create mode 100644 src/switcher.S diff --git a/src/manager.S b/src/manager.S new file mode 100644 index 0000000..1845a6f --- /dev/null +++ b/src/manager.S @@ -0,0 +1,62 @@ +// Variables +.global comps_addr +.global switcher_caps + +// Functions +.global init_compartments +.global add_compartment +.global del_compartment + +/** + * Sets up memory for compartments + * + * @param c0 Start address of switcher memory region + * @param c1 Address of `switch_compartment` + */ +.type init_compartments, "function" +init_compartments: + // Derive DDC + cvtp c0, x0 + scbnds c0, c0, #32 + + // Store DDC + str c0, =comps_addr + + // Derive PCC + cvtp c1, x1 + mov x2, #320 // TODO dynamic value + scbndse c1, c1, x2 + + // Store PCC + str c1, =comps_addr+16 + + ret + +/** + * Function to add information for a compartment + * + * @param c0 Start address + * @param c1 Function address + */ +.type add_compartment, "function" +add_compartment: + // Derive compartment PCC + + // Derive compartment DDC + + // Update DDC + ldr c0, =comps_addr + gclen x1, c0 + add x1, x1, #32 + scbndse c0, c0, x1 + str c0, =comps_addr + + ret + +/** + * Function to delete an existing compartment data + * + * @param c0 ID of compartment to be deleted + */ +.type del_compartment, "function" +del_compartment: diff --git a/src/switcher.S b/src/switcher.S new file mode 100644 index 0000000..20b3aaf --- /dev/null +++ b/src/switcher.S @@ -0,0 +1,88 @@ +.global switcher_entry +.global switch_compartment + +/** + * Entry point from user code to switcher function + * + * @param c0 DDC of switcher, containing compartment information + */ +.type switcher_entry, "function" +switcher_entry: + mov c29, c0 + mov x0, #0 + cvtp clr, lr + b switch_compartment + ret clr + +/** Code to perform actual switch + * + * @param x0 ID (in `comps` array) of compartment to switch to + */ +.type switch_compartment, "function" +switch_compartment: + // Store entering compartment's DDC, and move to memory containing + // compartment info + mrs c2, DDC + mov x10, x0 + + // Expect switcher DDC in c29 + msr DDC, c29 + + // Get compartment to switch to data + mov x11, #COMP_SIZE + mul x10, x10, x11 + + // Load PCC, including function we are jumping to within compartment + add x11, x10, #COMP_OFFSET_PCC + ldr c0, [x29, x11] + + // Load DDC + add x11, x10, #COMP_OFFSET_DDC + ldr c1, [x29, x11] + + // Setup SP + mov x12, sp + add x11, x10, #COMP_OFFSET_STK_ADDR + ldr x11, [x29, x11] + mov sp, x11 + + // Install compartment DDC + msr DDC, c1 + + // Save old DDC (c2), old SP (x12), old CLR (clr) on stack + stp c2, clr, [sp, #-48]! + str x12, [sp, #32] + + // Stack layout at this point: + // + // `stack + size` -> ________________________ + // sp + 40 -> [ ] ^ + // sp + 32 -> [ old SP ] | + // sp + 24 -> [ old CLR (hi64) ] | + // sp + 16 -> [ old CLR (lo64) ] | + // sp + 8 -> [ old DDC (high 64) ] | DDC bounds + // sp + 0 -> [ old DDC (low 64) ] | + // : : + // `stack` -> ________________________v + + // Clean all registers, except register used to call function within + // compartment we are transitioning to + bl clean+4 + + // Jump to the function within the compartment we are switching to (this + // also sets PCC) + blr c0 + + // Clean capabilities left in the return value. + mov w0, w0 + bl clean + + // Restore the caller's context and compartment. + ldp c10, clr, [sp] + ldr x12, [sp, #32] + msr DDC, c10 + mov x10, #0 + mov sp, x12 + + ret clr + From 1e6c40c37b04ed6d5131f79e5f7d860bbf6ec591 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Thu, 27 Jan 2022 14:40:07 +0000 Subject: [PATCH 03/20] Add build files --- src/CMakeLists.txt | 6 ++++++ tests/CMakeLists.txt | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 src/CMakeLists.txt create mode 100644 tests/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..be97c07 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ +set(BUILD_SHARED_LIBS ON) + +add_library(morello-compartments SHARED + ${SRC_DIR}/manager.S + ${SRC_DIR}/switcher.S + ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..af415c7 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(simple + simple.c) + +add_test(NAME simple COMMAND simple ) From ba64db26aba3e813720e828338b31d10318a0315 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Thu, 27 Jan 2022 14:40:39 +0000 Subject: [PATCH 04/20] Add missing content --- .gitignore | 3 +++ CMakeLists.txt | 24 ++++++++++++++++++++++++ tests/simple.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b9c214 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build/ + +**/*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..584c439 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.16) +project(CheriMorelloCompartments) + +set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include) +set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) +set(TEST_DIR ${CMAKE_SOURCE_DIR}/tests) + +# Setup +include_directories("${INCLUDE_DIR}") + +find_package(Clang REQUIRED) +find_package(LLVM REQUIRED CONFIG) + +# Building +add_subdirectory(${SRC_DIR}) + +# Testing +if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) +endif() + +if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) + add_subdirectory(${TEST_DIR}) +endif() diff --git a/tests/simple.c b/tests/simple.c index e69de29..24d7485 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -0,0 +1,28 @@ +#include "cheriintrin.h" + +/******************************************************************************* + * Globals and constants + ******************************************************************************/ + +const size_t switcher_mem_max_size; + +/******************************************************************************* + * Extern functions + ******************************************************************************/ + +extern int switch_compartment(); +extern void init_compartments(uint8_t*, uintptr_t); + +/******************************************************************************* + * Main + ******************************************************************************/ + +int +main() +{ + uint8_t* switcher_start = malloc(switcher_mem_max_size); + uintptr_t switch_comp_addr = &switch_compartment; + + init_compartments(switcher_start, switch_comp_addr); + return 0; +} From 7cf8d8f1d0835b7337de4e6b158089c21b4037bc Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Fri, 28 Jan 2022 13:19:50 +0000 Subject: [PATCH 05/20] Add cmake languages specifier --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 584c439..d73a9a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(CheriMorelloCompartments) +project(CheriMorelloCompartments LANGUAGES C ASM) set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include) set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) From f079c7817a04b231de0aaf71c2720d727dc41d85 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Fri, 28 Jan 2022 14:02:57 +0000 Subject: [PATCH 06/20] Update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 9b9c214..2bb8ac8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ build/ **/*.swp + +build.sh From 29ea84c16d61c3458488a49bbba19fa6be616e6f Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Fri, 28 Jan 2022 14:09:30 +0000 Subject: [PATCH 07/20] Fixes * add includes to `simple.c` * fix casting in `simple.c` * link `simple.c` against built library --- tests/CMakeLists.txt | 2 ++ tests/simple.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index af415c7..47f5d62 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,6 @@ add_executable(simple simple.c) +target_link_libraries(simple morello-compartments) + add_test(NAME simple COMMAND simple ) diff --git a/tests/simple.c b/tests/simple.c index 24d7485..4c20a17 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -1,3 +1,6 @@ +#include "stdint.h" +#include "stdlib.h" + #include "cheriintrin.h" /******************************************************************************* @@ -21,7 +24,7 @@ int main() { uint8_t* switcher_start = malloc(switcher_mem_max_size); - uintptr_t switch_comp_addr = &switch_compartment; + uintptr_t switch_comp_addr = (uintptr_t) switch_compartment; init_compartments(switcher_start, switch_comp_addr); return 0; From 97dc135ce0d574e5b9769b937d9dc78faafb666f Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Fri, 28 Jan 2022 15:55:24 +0000 Subject: [PATCH 08/20] Infrastructure * .gitignore update for local files * update library building parameters --- .gitignore | 1 + src/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2bb8ac8..8972cb6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ **/*.swp build.sh +up.sh diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be97c07..43cb217 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ set(BUILD_SHARED_LIBS ON) -add_library(morello-compartments SHARED +add_library(morello-compartments STATIC ${SRC_DIR}/manager.S ${SRC_DIR}/switcher.S ) From 0ff640e1a76d5a097acc1776c27039ec608246cc Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Fri, 28 Jan 2022 15:56:01 +0000 Subject: [PATCH 09/20] Add header and fixes * fix some standin code in `manager.S` * add common header file to contain macros for offsets in the compartments holding area --- include/comps_offsets.h | 4 ++++ src/manager.S | 27 +++++++++++++++++++++------ src/switcher.S | 2 ++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 include/comps_offsets.h diff --git a/include/comps_offsets.h b/include/comps_offsets.h new file mode 100644 index 0000000..a8f4965 --- /dev/null +++ b/include/comps_offsets.h @@ -0,0 +1,4 @@ +#define COMP_SIZE 48 +#define COMP_OFFSET_PCC 0 +#define COMP_OFFSET_DDC 16 +#define COMP_OFFSET_STK_ADDR 32 diff --git a/src/manager.S b/src/manager.S index 1845a6f..4b8532b 100644 --- a/src/manager.S +++ b/src/manager.S @@ -1,5 +1,8 @@ +#include "comps_offsets.h" + // Variables .global comps_addr +.global comps_cnt .global switcher_caps // Functions @@ -15,12 +18,16 @@ */ .type init_compartments, "function" init_compartments: + // Get address to store at + adr x3, switcher_caps + // Derive DDC cvtp c0, x0 - scbnds c0, c0, #32 + scbnds c0, c0, #32 // Store DDC - str c0, =comps_addr + str c0, [x3] + add x3, x3, #16 // Derive PCC cvtp c1, x1 @@ -28,7 +35,7 @@ init_compartments: scbndse c1, c1, x2 // Store PCC - str c1, =comps_addr+16 + str c1, [x3] ret @@ -44,12 +51,20 @@ add_compartment: // Derive compartment DDC - // Update DDC - ldr c0, =comps_addr + // Increment counter + adr x2, comps_cnt + ldr x3, [x2] + add x3, x3, #1 + str x3, [x2] + + + // Update switcher DDC + adr x2, switcher_caps + ldr c0, [x2] gclen x1, c0 add x1, x1, #32 scbndse c0, c0, x1 - str c0, =comps_addr + str c0, [x2] ret diff --git a/src/switcher.S b/src/switcher.S index 20b3aaf..4779b1f 100644 --- a/src/switcher.S +++ b/src/switcher.S @@ -1,3 +1,5 @@ +#include "comps_offsets.h" + .global switcher_entry .global switch_compartment From f67d3db978b21db11b0a51b3f493db4b30ab16d9 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Fri, 28 Jan 2022 16:16:35 +0000 Subject: [PATCH 10/20] Various additions * add `clean` function to `switcher.S` * define global variables in `manager.S` * initialize addresses on heap for variables from `manager.S` in `simple.c` * simple static asserts for compartment value offsets in `simple.c` --- src/CMakeLists.txt | 2 -- src/manager.S | 11 ++++++++++- src/switcher.S | 41 +++++++++++++++++++++++++++++++++++++++++ tests/simple.c | 13 +++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 43cb217..f14286d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,3 @@ -set(BUILD_SHARED_LIBS ON) - add_library(morello-compartments STATIC ${SRC_DIR}/manager.S ${SRC_DIR}/switcher.S diff --git a/src/manager.S b/src/manager.S index 4b8532b..882ad6f 100644 --- a/src/manager.S +++ b/src/manager.S @@ -1,8 +1,17 @@ +.data + +comps_cnt: .int 0 +comps_addr: .long 0x0 +switcher_caps: .long 0x0 + +.text +.balign 4 + #include "comps_offsets.h" // Variables -.global comps_addr .global comps_cnt +.global comps_addr .global switcher_caps // Functions diff --git a/src/switcher.S b/src/switcher.S index 4779b1f..22cbdcd 100644 --- a/src/switcher.S +++ b/src/switcher.S @@ -1,5 +1,8 @@ #include "comps_offsets.h" +.text +.balign 4 + .global switcher_entry .global switch_compartment @@ -88,3 +91,41 @@ switch_compartment: ret clr +clean: + mov x0, #0 + mov x1, #0 + mov x2, #0 + mov x3, #0 + mov x4, #0 + mov x5, #0 + mov x6, #0 + mov x7, #0 + mov x8, #0 + mov x9, #0 + mov x10, #0 + mov x11, #0 + mov x12, #0 + mov x13, #0 + mov x14, #0 + mov x15, #0 + mov x16, #0 + mov x17, #0 + // x18 is the "platform register" (for some platforms). If so, it needs to + // be preserved, but here we assume that only the lower 64 bits are + // required. + mov x18, x18 + // x19-x29 are callee-saved, but only the lower 64 bits. + mov x19, x19 + mov x20, x20 + mov x21, x21 + mov x22, x22 + mov x23, x23 + mov x24, x24 + mov x25, x25 + mov x26, x26 + mov x27, x27 + mov x28, x28 + mov x29, x29 // FP + // We need LR (x30) to return. The call to this helper already cleaned it. + // Don't replace SP; this needs special handling by the caller anyway. + ret diff --git a/tests/simple.c b/tests/simple.c index 4c20a17..b1139d4 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -1,8 +1,15 @@ +#include "assert.h" #include "stdint.h" #include "stdlib.h" #include "cheriintrin.h" +#include "comps_offsets.h" + +static_assert(COMP_SIZE == sizeof(void* __capability) * 3, "Invalid `COMP_SIZE` provided"); +static_assert(COMP_OFFSET_DDC == sizeof(void* __capability) * 1, "Invalid `COMP_OFFSET_DDC` provided."); +static_assert(COMP_OFFSET_STK_ADDR == sizeof(void* __capability) * 2, "Invalid `COMP_OFFSET_STK_LEN` provided."); + /******************************************************************************* * Globals and constants ******************************************************************************/ @@ -16,6 +23,9 @@ const size_t switcher_mem_max_size; extern int switch_compartment(); extern void init_compartments(uint8_t*, uintptr_t); +extern void* comps_addr; +extern void* switcher_caps; + /******************************************************************************* * Main ******************************************************************************/ @@ -23,6 +33,9 @@ extern void init_compartments(uint8_t*, uintptr_t); int main() { + switcher_caps = malloc(sizeof(void* __capability) * 2); + comps_addr = malloc(COMP_SIZE * 10); + uint8_t* switcher_start = malloc(switcher_mem_max_size); uintptr_t switch_comp_addr = (uintptr_t) switch_compartment; From f6f6b6a7009382ab3ec72fcad01272f8df7559f3 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Mon, 31 Jan 2022 16:24:33 +0000 Subject: [PATCH 11/20] Testing infrastructure and small fix * Fix type of asm global variables for alignment --- src/manager.S | 6 +++--- tests/CMakeLists.txt | 3 ++- tests/run_test.sh | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/run_test.sh diff --git a/src/manager.S b/src/manager.S index 882ad6f..2d710e5 100644 --- a/src/manager.S +++ b/src/manager.S @@ -1,8 +1,8 @@ .data -comps_cnt: .int 0 -comps_addr: .long 0x0 -switcher_caps: .long 0x0 +comps_cnt: .dword 0 +comps_addr: .dword +switcher_caps: .dword .text .balign 4 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 47f5d62..49ba2dc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,4 +3,5 @@ add_executable(simple target_link_libraries(simple morello-compartments) -add_test(NAME simple COMMAND simple ) +add_test(NAME simple + COMMAND ${CMAKE_SOURCE_DIR}/tests/run_test.sh $) diff --git a/tests/run_test.sh b/tests/run_test.sh new file mode 100644 index 0000000..1a774df --- /dev/null +++ b/tests/run_test.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -x +set -e + +if [ $# -ne 1 ] +then + echo "Expected one parameter: path to executable." + exit 1 +fi + +CHERIBSD_PORT=10086 +CHERIBSD_USER=root +CHERIBSD_HOST=localhost + +scp -P $CHERIBSD_PORT $1 $CHERIBSD_USER@$CHERIBSD_HOST: +ssh -p $CHERIBSD_PORT $CHERIBSD_USER@$CHERIBSD_HOST -t ./$(basename $1) From 2d6913c7bcdc34165f3e9013ada02e7e038ea4d7 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Tue, 1 Feb 2022 15:13:39 +0000 Subject: [PATCH 12/20] Updates * add wrapper to save `clr` when coming from C into `asm` * fix some constants in `simple.c` referring to memory region sizes * more work on `initialize_compartments()` --- src/manager.S | 37 +++++++++++++++++++++++++++---------- tests/simple.c | 11 +++++++---- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/manager.S b/src/manager.S index 2d710e5..8c8911b 100644 --- a/src/manager.S +++ b/src/manager.S @@ -15,10 +15,32 @@ switcher_caps: .dword .global switcher_caps // Functions +.global asm_call_wrapper .global init_compartments .global add_compartment .global del_compartment +/** + * Wrapper to store/restore state when coming from C + * + * @param x0 ASM function to call + * @param x1-x6 parameters to pass to function in c0 + */ +.type asm_call_wrapper, "function" +asm_call_wrapper: + // Save `x0` so we can temporarily use it + cvtp c0, x0 + str c0, [sp] + + // Derive `clr` (in case asm function does something weird with `PCC`) + cvtp c0, lr + swp c0, c0, [sp] + sub sp, sp, #16 + + blr c0 + ldr clr, [sp] + ret clr + /** * Sets up memory for compartments * @@ -27,24 +49,19 @@ switcher_caps: .dword */ .type init_compartments, "function" init_compartments: - // Get address to store at - adr x3, switcher_caps // Derive DDC cvtp c0, x0 - scbnds c0, c0, #32 - - // Store DDC - str c0, [x3] - add x3, x3, #16 + scbnds c0, c0, x1 // Derive PCC - cvtp c1, x1 + cvtp c1, x2 mov x2, #320 // TODO dynamic value scbndse c1, c1, x2 - // Store PCC - str c1, [x3] + // Store (DDC, PCC) at `[switcher_caps]` + ldr x3, switcher_caps + stp c0, c1, [x3] ret diff --git a/tests/simple.c b/tests/simple.c index b1139d4..ebcd41b 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -14,14 +14,16 @@ static_assert(COMP_OFFSET_STK_ADDR == sizeof(void* __capability) * 2, "Invalid ` * Globals and constants ******************************************************************************/ -const size_t switcher_mem_max_size; +const size_t max_comp_cnt = 2; +const size_t switcher_mem_max_size = max_comp_cnt * COMP_SIZE; /******************************************************************************* * Extern functions ******************************************************************************/ +extern void asm_call_wrapper(void*, ...); +extern void init_compartments(uint8_t*, size_t, uintptr_t); extern int switch_compartment(); -extern void init_compartments(uint8_t*, uintptr_t); extern void* comps_addr; extern void* switcher_caps; @@ -34,11 +36,12 @@ int main() { switcher_caps = malloc(sizeof(void* __capability) * 2); - comps_addr = malloc(COMP_SIZE * 10); + comps_addr = malloc(COMP_SIZE * max_comp_cnt); uint8_t* switcher_start = malloc(switcher_mem_max_size); uintptr_t switch_comp_addr = (uintptr_t) switch_compartment; - init_compartments(switcher_start, switch_comp_addr); + asm_call_wrapper(init_compartments, + switcher_start, switcher_mem_max_size, switch_comp_addr); return 0; } From a053b09f96a9874a76f8f5ca5d1395de88c48942 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Thu, 3 Feb 2022 11:11:26 +0000 Subject: [PATCH 13/20] Fixes and updates * Change registers used by `init_compartments` to include match the wrapper * Fix sp address loading in wrapper --- src/manager.S | 19 ++++++++++--------- tests/{simple.c => simple_init.c} | 0 2 files changed, 10 insertions(+), 9 deletions(-) rename tests/{simple.c => simple_init.c} (100%) diff --git a/src/manager.S b/src/manager.S index 8c8911b..efbccd7 100644 --- a/src/manager.S +++ b/src/manager.S @@ -38,30 +38,31 @@ asm_call_wrapper: sub sp, sp, #16 blr c0 - ldr clr, [sp] + ldr clr, [sp, #16]! ret clr /** * Sets up memory for compartments * * @param c0 Start address of switcher memory region - * @param c1 Address of `switch_compartment` + * @param c1 Size of switcher memory region + * @param c2 Address of `switch_compartment` */ .type init_compartments, "function" init_compartments: // Derive DDC - cvtp c0, x0 - scbnds c0, c0, x1 + cvtp c1, x1 + scbnds c1, c1, x2 // Derive PCC - cvtp c1, x2 - mov x2, #320 // TODO dynamic value - scbndse c1, c1, x2 + cvtp c2, x3 + mov x3, #320 // TODO dynamic value + scbndse c2, c2, x3 // Store (DDC, PCC) at `[switcher_caps]` - ldr x3, switcher_caps - stp c0, c1, [x3] + ldr x4, switcher_caps + stp c1, c2, [x4] ret diff --git a/tests/simple.c b/tests/simple_init.c similarity index 100% rename from tests/simple.c rename to tests/simple_init.c From c9b387fb8b68941a344ec7b2cc5c1c48d61c8302 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Tue, 8 Feb 2022 12:27:01 +0000 Subject: [PATCH 14/20] Various updates * further work on (now old) `add_compartment` function * initialize `.data` variables in `manager.S` * make use of `asm_call_wrapper` in tests * add generic function to add tests in cmake --- src/manager.S | 37 +++++++++++++++++-------- tests/CMakeLists.txt | 15 ++++++---- tests/run_test.sh | 0 tests/simple_add.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ tests/simple_init.c | 2 ++ 5 files changed, 102 insertions(+), 18 deletions(-) mode change 100644 => 100755 tests/run_test.sh create mode 100644 tests/simple_add.c diff --git a/src/manager.S b/src/manager.S index efbccd7..d7c35bd 100644 --- a/src/manager.S +++ b/src/manager.S @@ -1,8 +1,8 @@ .data comps_cnt: .dword 0 -comps_addr: .dword -switcher_caps: .dword +comps_addr: .dword 0 +switcher_caps: .dword 0 .text .balign 4 @@ -44,9 +44,9 @@ asm_call_wrapper: /** * Sets up memory for compartments * - * @param c0 Start address of switcher memory region - * @param c1 Size of switcher memory region - * @param c2 Address of `switch_compartment` + * @param c1 Start address of switcher memory region + * @param c2 Size of switcher memory region + * @param c3 Address of `switch_compartment` */ .type init_compartments, "function" init_compartments: @@ -69,21 +69,34 @@ init_compartments: /** * Function to add information for a compartment * - * @param c0 Start address - * @param c1 Function address + * @param c1 Start address + * @param c2 Size of memory region + * @param c3 Function address */ .type add_compartment, "function" add_compartment: + // Derive compartment PCC + cvtp c3, x3 + mov x4, #320 // TODO dynamic value + scbndse c3, c3, x4 // Derive compartment DDC + cvtp c1, x1 + scbnds c2, c1, x2 - // Increment counter - adr x2, comps_cnt - ldr x3, [x2] - add x3, x3, #1 - str x3, [x2] + // Store new PCC and DDC + ldr x0, comps_addr + ldr x1, comps_cnt + mov x3, #COMP_SIZE + madd x0, x1, x2, x0 + stp c3, c2, [x0] + // Increment counter + adr x3, comps_cnt + ldr x4, [x3] + add x4, x4, #1 + str x4, [x3] // Update switcher DDC adr x2, switcher_caps diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 49ba2dc..17bc8e6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,10 @@ -add_executable(simple - simple.c) +function(new_proj_test test_name) + add_executable(${test_name} + ${test_name}.c) + target_link_libraries(${test_name} morello-compartments) + add_test(NAME ${test_name} + COMMAND ${CMAKE_SOURCE_DIR}/tests/run_test.sh $) +endfunction() -target_link_libraries(simple morello-compartments) - -add_test(NAME simple - COMMAND ${CMAKE_SOURCE_DIR}/tests/run_test.sh $) +new_proj_test(simple_init) +new_proj_test(simple_add) diff --git a/tests/run_test.sh b/tests/run_test.sh old mode 100644 new mode 100755 diff --git a/tests/simple_add.c b/tests/simple_add.c new file mode 100644 index 0000000..83118b6 --- /dev/null +++ b/tests/simple_add.c @@ -0,0 +1,66 @@ +#include "assert.h" +#include "stdint.h" +#include "stdlib.h" + +#include "cheriintrin.h" + +#include "comps_offsets.h" + +static_assert(COMP_SIZE == sizeof(void* __capability) * 3, "Invalid `COMP_SIZE` provided"); +static_assert(COMP_OFFSET_DDC == sizeof(void* __capability) * 1, "Invalid `COMP_OFFSET_DDC` provided."); +static_assert(COMP_OFFSET_STK_ADDR == sizeof(void* __capability) * 2, "Invalid `COMP_OFFSET_STK_LEN` provided."); + +/******************************************************************************* + * Globals and constants + ******************************************************************************/ + +const size_t max_comp_cnt = 2; +const size_t switcher_mem_max_size = max_comp_cnt * COMP_SIZE; + +/******************************************************************************* + * Extern functions + ******************************************************************************/ + +extern void asm_call_wrapper(void*, ...); +extern void init_compartments(void*, size_t, void*); +extern void add_compartment(void*, size_t, void*); +extern int switch_compartment(); + +extern void* comps_addr; +extern void* switcher_caps; + +/******************************************************************************* + * Main + ******************************************************************************/ + +int comp_f_fn(); + +int +main() +{ + switcher_caps = malloc(sizeof(void* __capability) * 2); + comps_addr = malloc(COMP_SIZE * max_comp_cnt); + + void* switcher_start = malloc(switcher_mem_max_size); + void* switch_comp_addr = switch_compartment; + + asm_call_wrapper(init_compartments, + switcher_start, switcher_mem_max_size, switch_comp_addr); + + const size_t comp_f_size = 1000; + uintptr_t comp_f_start = (uintptr_t) malloc(comp_f_size); + asm_call_wrapper(add_compartment, + comp_f_start, comp_f_size, comp_f_fn); + + return 0; +} + +/******************************************************************************* + * Compartments + ******************************************************************************/ + +int +comp_f_fn() +{ + return 42; +} diff --git a/tests/simple_init.c b/tests/simple_init.c index ebcd41b..f9a00d3 100644 --- a/tests/simple_init.c +++ b/tests/simple_init.c @@ -41,6 +41,8 @@ main() uint8_t* switcher_start = malloc(switcher_mem_max_size); uintptr_t switch_comp_addr = (uintptr_t) switch_compartment; + // init_compartments(); + asm_call_wrapper(init_compartments, switcher_start, switcher_mem_max_size, switch_comp_addr); return 0; From 05782d1baebc2e0fab0f1b584184c302bb47f650 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Tue, 8 Feb 2022 14:43:32 +0000 Subject: [PATCH 15/20] Update `init_compartments` As discussed, we move towards a more abstract model, including memory management in the assembly layer. This updates the initialiation function to not require any user input, and setup memory appropriately, for future use. --- src/manager.S | 57 ++++++++++++++++++++++++++++++++------------- src/switcher.S | 3 +++ tests/simple_init.c | 21 ++++++----------- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/manager.S b/src/manager.S index d7c35bd..f803069 100644 --- a/src/manager.S +++ b/src/manager.S @@ -44,25 +44,50 @@ asm_call_wrapper: /** * Sets up memory for compartments * - * @param c1 Start address of switcher memory region - * @param c2 Size of switcher memory region - * @param c3 Address of `switch_compartment` + * Initializes required memory for compartments. This involves allocating a + * memory region for use by switcher code, to contain required capabilities, + * and deriving appropriate PCC/DDC values containing the executable switcher + * code, and the aforementioned memory region, respectively. */ .type init_compartments, "function" init_compartments: - - // Derive DDC - cvtp c1, x1 - scbnds c1, c1, x2 - - // Derive PCC - cvtp c2, x3 - mov x3, #320 // TODO dynamic value - scbndse c2, c2, x3 - - // Store (DDC, PCC) at `[switcher_caps]` - ldr x4, switcher_caps - stp c1, c2, [x4] + // Save `lr` + mov x6, lr + + // Allocate memory for switcher + mov x0, xzr // address + mov x1, #128 // length + mov w2, #3 // prot == PROT_READ | PROT_WRITE + mov w3, #4098 // flags == MAP_PRIVATE | MAP_ANONYMOUS + mov w4, #-1 // fd + mov w5, wzr // offset + bl mmap + + // Restore `lr` + mov lr, x6 + + // Save pointer to new allocated memory in `switcher_caps` + adr x2, switcher_caps + str x0, [x2] + + // Derive DDC for switcher + cvtp c2, x0 + scbnds c2, c2, x1 + + // Derive PCC for `switch_compartments` and friends + adr x3, switcher_entry + adr x4, switch_compartment_end + sub x4, x4, x3 + cvtp c3, x3 + scbndse c3, c3, x4 + + // Store (DDC, PCC) at `switcher_caps` + ldr x1, switcher_caps + stp c2, c3, [x1], #32 + + // Save start address for compartment capabilities in `comps_addr` + adr x2, comps_addr + str x1, [x2] ret diff --git a/src/switcher.S b/src/switcher.S index 22cbdcd..7a83c6f 100644 --- a/src/switcher.S +++ b/src/switcher.S @@ -5,6 +5,7 @@ .global switcher_entry .global switch_compartment +.global switch_compartment_end /** * Entry point from user code to switcher function @@ -129,3 +130,5 @@ clean: // We need LR (x30) to return. The call to this helper already cleaned it. // Don't replace SP; this needs special handling by the caller anyway. ret + +switch_compartment_end: diff --git a/tests/simple_init.c b/tests/simple_init.c index f9a00d3..843eabb 100644 --- a/tests/simple_init.c +++ b/tests/simple_init.c @@ -1,6 +1,7 @@ -#include "assert.h" -#include "stdint.h" -#include "stdlib.h" +#include +#include +#include +#include #include "cheriintrin.h" @@ -21,8 +22,7 @@ const size_t switcher_mem_max_size = max_comp_cnt * COMP_SIZE; * Extern functions ******************************************************************************/ -extern void asm_call_wrapper(void*, ...); -extern void init_compartments(uint8_t*, size_t, uintptr_t); +extern void* init_compartments(); extern int switch_compartment(); extern void* comps_addr; @@ -35,15 +35,8 @@ extern void* switcher_caps; int main() { - switcher_caps = malloc(sizeof(void* __capability) * 2); - comps_addr = malloc(COMP_SIZE * max_comp_cnt); + void* inner_addr = init_compartments(); + assert(switcher_caps != MAP_FAILED); - uint8_t* switcher_start = malloc(switcher_mem_max_size); - uintptr_t switch_comp_addr = (uintptr_t) switch_compartment; - - // init_compartments(); - - asm_call_wrapper(init_compartments, - switcher_start, switcher_mem_max_size, switch_comp_addr); return 0; } From b4cefc3d7a3c8c823f842f48a2a52e985532aa34 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Tue, 8 Feb 2022 15:05:55 +0000 Subject: [PATCH 16/20] Polish * clean-up `simple_init.c` * derive dynamic length for switcher memory region --- include/comps_offsets.h | 2 ++ src/manager.S | 9 ++++++++- tests/simple_init.c | 10 ---------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/comps_offsets.h b/include/comps_offsets.h index a8f4965..16c1ee1 100644 --- a/include/comps_offsets.h +++ b/include/comps_offsets.h @@ -2,3 +2,5 @@ #define COMP_OFFSET_PCC 0 #define COMP_OFFSET_DDC 16 #define COMP_OFFSET_STK_ADDR 32 + +#define MAX_COMP_COUNT 2 diff --git a/src/manager.S b/src/manager.S index f803069..c3bed7c 100644 --- a/src/manager.S +++ b/src/manager.S @@ -54,9 +54,16 @@ init_compartments: // Save `lr` mov x6, lr + // Compute size of required memory, equivalent to `length` parameter of + // `mmap` + mov x0, #COMP_SIZE + mov x1, #MAX_COMP_COUNT + mov x2, #32 // size of the 2 switcher capabilities + madd x1, x0, x1, x2 + // Allocate memory for switcher mov x0, xzr // address - mov x1, #128 // length + // length - already stored in `x1` mov w2, #3 // prot == PROT_READ | PROT_WRITE mov w3, #4098 // flags == MAP_PRIVATE | MAP_ANONYMOUS mov w4, #-1 // fd diff --git a/tests/simple_init.c b/tests/simple_init.c index 843eabb..d343fea 100644 --- a/tests/simple_init.c +++ b/tests/simple_init.c @@ -11,21 +11,11 @@ static_assert(COMP_SIZE == sizeof(void* __capability) * 3, "Invalid `COMP_SIZE` static_assert(COMP_OFFSET_DDC == sizeof(void* __capability) * 1, "Invalid `COMP_OFFSET_DDC` provided."); static_assert(COMP_OFFSET_STK_ADDR == sizeof(void* __capability) * 2, "Invalid `COMP_OFFSET_STK_LEN` provided."); -/******************************************************************************* - * Globals and constants - ******************************************************************************/ - -const size_t max_comp_cnt = 2; -const size_t switcher_mem_max_size = max_comp_cnt * COMP_SIZE; - /******************************************************************************* * Extern functions ******************************************************************************/ extern void* init_compartments(); -extern int switch_compartment(); - -extern void* comps_addr; extern void* switcher_caps; /******************************************************************************* From 1e2604d4503800aa88d47ef9cf1249e1dd9f1645 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Wed, 9 Feb 2022 12:11:38 +0000 Subject: [PATCH 17/20] Fix * Save needed registers on stack before calling `mmap` in `init_compartments`l, to ensure they are available after the call. --- src/manager.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/manager.S b/src/manager.S index c3bed7c..df3e044 100644 --- a/src/manager.S +++ b/src/manager.S @@ -51,9 +51,6 @@ asm_call_wrapper: */ .type init_compartments, "function" init_compartments: - // Save `lr` - mov x6, lr - // Compute size of required memory, equivalent to `length` parameter of // `mmap` mov x0, #COMP_SIZE @@ -61,6 +58,9 @@ init_compartments: mov x2, #32 // size of the 2 switcher capabilities madd x1, x0, x1, x2 + // Store length and `lr` on stack, as we'll need them later + stp x1, lr, [sp, #-16]! + // Allocate memory for switcher mov x0, xzr // address // length - already stored in `x1` @@ -70,8 +70,8 @@ init_compartments: mov w5, wzr // offset bl mmap - // Restore `lr` - mov lr, x6 + // Restore length and `lr` + ldp x1, lr, [sp], #16 // Save pointer to new allocated memory in `switcher_caps` adr x2, switcher_caps From aa89a67e90af4bb664c6441609c7526531170d79 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Wed, 9 Feb 2022 12:51:47 +0000 Subject: [PATCH 18/20] Add checks to `simple_init` --- src/manager.S | 2 ++ tests/simple_init.c | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/manager.S b/src/manager.S index df3e044..5eb6b19 100644 --- a/src/manager.S +++ b/src/manager.S @@ -48,6 +48,8 @@ asm_call_wrapper: * memory region for use by switcher code, to contain required capabilities, * and deriving appropriate PCC/DDC values containing the executable switcher * code, and the aforementioned memory region, respectively. + * + * @return Pointer to newly allocated memory region */ .type init_compartments, "function" init_compartments: diff --git a/tests/simple_init.c b/tests/simple_init.c index d343fea..a07f5f8 100644 --- a/tests/simple_init.c +++ b/tests/simple_init.c @@ -16,7 +16,10 @@ static_assert(COMP_OFFSET_STK_ADDR == sizeof(void* __capability) * 2, "Invalid ` ******************************************************************************/ extern void* init_compartments(); -extern void* switcher_caps; +extern void* __capability * switcher_caps; + +extern void switcher_entry(); +extern void switch_compartment_end(); /******************************************************************************* * Main @@ -26,7 +29,20 @@ int main() { void* inner_addr = init_compartments(); - assert(switcher_caps != MAP_FAILED); + + assert(inner_addr != MAP_FAILED); + assert(switcher_caps == inner_addr); + + void* __capability switcher_ddc = switcher_caps[0]; + assert(cheri_is_valid(switcher_ddc)); + assert(cheri_length_get(switcher_ddc) == + COMP_SIZE * MAX_COMP_COUNT + 2 * sizeof(void* __capability)); + + void* __capability switcher_pcc = switcher_caps[1]; + assert(cheri_is_valid(switcher_pcc)); + assert(cheri_address_get(switcher_pcc) == (unsigned long) switcher_entry); + assert(cheri_address_get(switcher_pcc) + cheri_length_get(switcher_pcc) == + (unsigned long) switch_compartment_end); return 0; } From 96a72ee6eec2df7bf431e48c6b3fec445960dfd8 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Wed, 9 Feb 2022 13:59:22 +0000 Subject: [PATCH 19/20] Finalize `simple_add` test --- src/manager.S | 86 ++++++++++++++++++++++++++++------------------ tests/simple_add.c | 45 ++++++++++-------------- 2 files changed, 71 insertions(+), 60 deletions(-) diff --git a/src/manager.S b/src/manager.S index 5eb6b19..f44baa0 100644 --- a/src/manager.S +++ b/src/manager.S @@ -103,44 +103,62 @@ init_compartments: /** * Function to add information for a compartment * - * @param c1 Start address - * @param c2 Size of memory region - * @param c3 Function address + * @param x0 Compartment memory size + * @param x1 Compartment executable function + * + * @return Pointer to newly allocated memory region */ .type add_compartment, "function" add_compartment: + // Store inputs and `lr` so we can call `mmap` + stp x0, x1, [sp, #-32]! + str lr, [sp, #16] + mov x1, x0 + + // Allocate memory for new compartment + mov x0, xzr // address + // length - already stored in `x1` + mov w2, #3 // prot == PROT_READ | PROT_WRITE + mov w3, #4098 // flags == MAP_PRIVATE | MAP_ANONYMOUS + mov w4, #-1 // fd + mov w5, wzr // offset + bl mmap + + // Restore memory size and function address + ldp x1, x2, [sp], #32 + ldr lr, [sp, #-16] - // Derive compartment PCC - cvtp c3, x3 - mov x4, #320 // TODO dynamic value - scbndse c3, c3, x4 - - // Derive compartment DDC - cvtp c1, x1 - scbnds c2, c1, x2 - - // Store new PCC and DDC - ldr x0, comps_addr - ldr x1, comps_cnt - mov x3, #COMP_SIZE - madd x0, x1, x2, x0 - stp c3, c2, [x0] - - // Increment counter - adr x3, comps_cnt - ldr x4, [x3] - add x4, x4, #1 - str x4, [x3] - - // Update switcher DDC - adr x2, switcher_caps - ldr c0, [x2] - gclen x1, c0 - add x1, x1, #32 - scbndse c0, c0, x1 - str c0, [x2] - - ret + // Derive compartment DDC + cvtp c0, x0 + scbnds c0, c0, x1 + + // Derive compartment PCC + cvtp c1, x2 + mov x2, #320 // TODO dynamic value + scbndse c1, c1, x2 + + // Store new PCC and DDC + ldr x2, comps_addr + ldr x3, comps_cnt + mov x4, #COMP_SIZE + madd x2, x3, x4, x2 + stp c0, c1, [x2] + + // Increment counter + adr x3, comps_cnt + ldr x4, [x3] + add x4, x4, #1 + str x4, [x3] + + // Update switcher DDC + //adr x2, switcher_caps + //ldr c0, [x2] + //gclen x1, c0 + //add x1, x1, #32 + //scbndse c0, c0, x1 + //str c0, [x2] + + ret /** * Function to delete an existing compartment data diff --git a/tests/simple_add.c b/tests/simple_add.c index 83118b6..82d0044 100644 --- a/tests/simple_add.c +++ b/tests/simple_add.c @@ -1,6 +1,7 @@ -#include "assert.h" -#include "stdint.h" -#include "stdlib.h" +#include +#include +#include +#include #include "cheriintrin.h" @@ -10,24 +11,15 @@ static_assert(COMP_SIZE == sizeof(void* __capability) * 3, "Invalid `COMP_SIZE` static_assert(COMP_OFFSET_DDC == sizeof(void* __capability) * 1, "Invalid `COMP_OFFSET_DDC` provided."); static_assert(COMP_OFFSET_STK_ADDR == sizeof(void* __capability) * 2, "Invalid `COMP_OFFSET_STK_LEN` provided."); -/******************************************************************************* - * Globals and constants - ******************************************************************************/ - -const size_t max_comp_cnt = 2; -const size_t switcher_mem_max_size = max_comp_cnt * COMP_SIZE; - /******************************************************************************* * Extern functions ******************************************************************************/ -extern void asm_call_wrapper(void*, ...); -extern void init_compartments(void*, size_t, void*); -extern void add_compartment(void*, size_t, void*); -extern int switch_compartment(); +extern void* __capability * comps_addr; +extern size_t comps_cnt; -extern void* comps_addr; -extern void* switcher_caps; +extern void* init_compartments(); +extern void* add_compartment(size_t, void*); /******************************************************************************* * Main @@ -38,19 +30,20 @@ int comp_f_fn(); int main() { - switcher_caps = malloc(sizeof(void* __capability) * 2); - comps_addr = malloc(COMP_SIZE * max_comp_cnt); + init_compartments(); + + size_t comp_size = 2000; + assert(add_compartment(comp_size, comp_f_fn) != MAP_FAILED); - void* switcher_start = malloc(switcher_mem_max_size); - void* switch_comp_addr = switch_compartment; + assert(comps_cnt == 1); - asm_call_wrapper(init_compartments, - switcher_start, switcher_mem_max_size, switch_comp_addr); + void* __capability comp_ddc = comps_addr[0]; + assert(cheri_is_valid(comp_ddc)); + assert(cheri_length_get(comp_ddc) == comp_size); - const size_t comp_f_size = 1000; - uintptr_t comp_f_start = (uintptr_t) malloc(comp_f_size); - asm_call_wrapper(add_compartment, - comp_f_start, comp_f_size, comp_f_fn); + void* __capability comp_pcc = comps_addr[1]; + assert(cheri_is_valid(comp_pcc)); + assert(cheri_address_get(comp_pcc) == (unsigned long) comp_f_fn); return 0; } From 2c4d2c5debe7749c48e96ed687cba520c13baf58 Mon Sep 17 00:00:00 2001 From: Andrei Lascu Date: Wed, 9 Feb 2022 15:58:49 +0000 Subject: [PATCH 20/20] First try at bors --- .buildbot.sh | 28 ++++++++++++++++++++++++++++ bors.toml | 10 ++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .buildbot.sh create mode 100644 bors.toml diff --git a/.buildbot.sh b/.buildbot.sh new file mode 100644 index 0000000..a8a26c6 --- /dev/null +++ b/.buildbot.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +export CC=/home/cheriworker/cheri/output/morello-sdk/bin/clang +export CFLAGS="--config cheribsd-morello-hybrid.cfg" +export ASMFLAGS="--config cheribsd-morello-hybrid.cfg" + +build_dir="$(pwd)/build" +src_dir="$(pwd)/" + +# Build project locally +cmake \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=DEBUG \ + -DLLVM_DIR=/home/cheriworker/cheri/output/morello-sdk/lib/cmake/llvm \ + -DClang_DIR=/home/cheriworker/cheri/output/morello-sdk/lib/cmake/clang \ + -B $build_dir \ + -S $src_dir +cmake --build $build_dir + +# Spawn CHERI QEMU instance +NETDEV="user,id=net0,hostfwd=tcp::10086-:22" +$HOME/cheri/output/morello-sdk/bin/qemu-system-morello -M virt,gic-version=3 -cpu morello -m 2048 -nographic -bios edk2-aarch64-code.fd -drive if=none,file=$HOME/cheri/output/cheribsd-morello-hybrid.img,id=drv,format=raw -device virtio-blk-device,drive=drv -device virtio-net-device,netdev=net0 -netdev $NETDEV -device virtio-rng-pci + +# Execute tests via CMake +cd $build_dir +ctest diff --git a/bors.toml b/bors.toml new file mode 100644 index 0000000..db1bdaa --- /dev/null +++ b/bors.toml @@ -0,0 +1,10 @@ +# Sourced from +# https://github.com/capablevms/cheri-examples/blob/master/bors.toml +status = ["buildbot/capablevms-test-script"] + +timeout_sec = 600 # 10 minutes + +# Have bors delete auto-merged branches +delete_merged_branches = true + +cut_body_after = ""