diff --git a/.github/workflows/capable-workflow.yml b/.github/workflows/capable-workflow.yml new file mode 100644 index 000000000..d39851710 --- /dev/null +++ b/.github/workflows/capable-workflow.yml @@ -0,0 +1,115 @@ +name: snmalloc CI for Morello at The Capable Hub + +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + inputs: + bootenv_label: + description: "Morello host environment" + type: string + required: true + default: "benchmark" + + runqueue_label: + description: "Morello runner queue (production or test scripts?)" + required: true + type: choice + options: + - "msr-morello" + - "msr-morello-test" + +jobs: + # UNIX-like, but with some needed TLC for the moment, so not folded in to the main unixlike CI. + # Morello can't easily self-host since it mixes purecap and hybrid build tools. + # We point cmake at the LLVM Clang frontend explicitly lest it pick up the more magic wrappers. + morello: + strategy: + matrix: + # Build each combination of OS and release/debug variants + os: [ "morello" ] + build-type: [ Release, Debug ] + caps: [ Hybrid, Purecap ] + include: + - os: "morello" + caps: Hybrid + dependencies: >- + cmake ninja-build + cmake-flags: > + -DCMAKE_CXX_COMPILER=/root/llvm-cheri/install/bin/clang++ + -DCMAKE_C_COMPILER=/root/llvm-cheri/install/bin/clang + -DCMAKE_CXX_FLAGS='-march=morello -Xclang -morello-vararg=new' + -DCMAKE_C_FLAGS='-march=morello -Xclang -morello-vararg=new' + - os: "morello" + caps: Purecap + dependencies: >- + cmake ninja-build + cmake-flags: > + -DCMAKE_ASM_COMPILER_TARGET=aarch64-unknown-linux-musl_purecap + -DCMAKE_C_COMPILER_TARGET=aarch64-unknown-linux-musl_purecap + -DCMAKE_CXX_COMPILER_TARGET=aarch64-unknown-linux-musl_purecap + -DCMAKE_CXX_COMPILER=/root/llvm-cheri/install/bin/clang++ + -DCMAKE_C_COMPILER=/root/llvm-cheri/install/bin/clang + -DCMAKE_CXX_FLAGS='-march=morello -mabi=purecap -Xclang -morello-vararg=new' + -DCMAKE_C_FLAGS='-march=morello -mabi=purecap -Xclang -morello-vararg=new' + # Don't abort runners if a single one fails + fail-fast: false + # Morello needs special handling to get picked up by our self-hosted runners + # When/if we do integrate this back into the unixlike matrix above, we could + # say something like:: + # runs-on: >- + # ${{ (matrix.os == 'morello' && fromJSON('["self-hosted", "msr-morello", "benchmark"]')) + # || matrix.os }} + # to dispatch dynamically. + runs-on: self-hosted + # runs-on: the-capable-hub-aws-ci + env: + BUILD_DIR: ${{github.workspace}}/volatile/${{ github.job }} + container: + image: capablehub/cheri-ca-llvm:19-riscv64-latest + steps: + - uses: actions/checkout@v2 + - name: Log environment details + run: | + uname -a + mount + - name: Configure CMake + run: | + # ${{github.workspace}}/build + apt-get update + apt-get -yy install ${{ matrix.dependencies }} + ls -l /root + cmake --version + which clang + ls -l `which clang` + clang --version + which clang++ + ls -l `which clang++` + clang++ --version + mkdir -p ./build + + cmake \ + -B ./build \ + -DCMAKE_BUILD_TYPE=${{matrix.build-type}} \ + -G Ninja ${{ matrix.cmake-flags }} \ + ${{ matrix.extra-cmake-flags }} + # Build with a nice ninja status line + - name: Build + working-directory: ./build + run: | + NINJA_STATUS="%p [%f:%s/%t] %o/s, %es" ninja + - name: Test file size of binaries is sane + working-directory: ./build + run: | + ls -l func-first_operation-fast ; [ $(ls -l func-first_operation-fast | awk '{ print $5}') -lt 10000000 ] + # If the tests are enabled for this job, run them + - name: Test + if: ${{ matrix.build-only != 'yes' }} + working-directory: ${{github.workspace}}/build + run: | + ctest --output-on-failure -j 4 -C ${{ matrix.build-type }} --timeout 400 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 237e5a749..1890fd68e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,11 +8,11 @@ concurrency: # Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - branches: [ main ] - pull_request: - branches: [ main, snmalloc1 ] + # # Triggers the workflow on push or pull request events but only for the master branch + # push: + # branches: [ main ] + # pull_request: + # branches: [ main, snmalloc1 ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/.github/workflows/morello.yml b/.github/workflows/morello.yml index 68cebc407..d81166273 100644 --- a/.github/workflows/morello.yml +++ b/.github/workflows/morello.yml @@ -1,11 +1,11 @@ name: snmalloc CI for Morello on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [ main ] - pull_request: - branches: [ main ] + # # Triggers the workflow on push or pull request events but only for the main branch + # push: + # branches: [ main ] + # pull_request: + # branches: [ main ] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/.github/workflows/reusable-cmake-build.yml b/.github/workflows/reusable-cmake-build.yml index fe83359b7..83da6f3af 100644 --- a/.github/workflows/reusable-cmake-build.yml +++ b/.github/workflows/reusable-cmake-build.yml @@ -1,66 +1,66 @@ name: Reusable CMake Build -on: - workflow_call: - inputs: - os: - required: true - type: string - description: 'Runner OS (e.g., ubuntu-24.04, macos-14, windows-2022)' - build-type: - required: true - type: string - description: 'CMake build type (Release, Debug)' - cmake-config: - required: false - type: string - default: '-G Ninja' - description: 'CMake configuration options (-G, -A, -T, compiler flags)' - extra-cmake-flags: - required: false - type: string - default: '' - description: 'Additional CMake flags for the project' - dependencies: - required: false - type: string - default: '' - description: 'Command to install dependencies' - build-only: - required: false - type: boolean - default: false - description: 'Skip tests if true' - self-host: - required: false - type: boolean - default: false - description: 'Run self-hosting test' - check-binary-size: - required: false - type: boolean - default: true - description: 'Check binary size is reasonable' - test-exclude-pattern: - required: false - type: string - default: '' - description: 'Regex pattern for tests to exclude' - test-extra-args: - required: false - type: string - default: '' - description: 'Extra arguments for ctest' - use-msbuild: - required: false - type: boolean - default: false - description: 'Use MSBuild instead of Ninja for building' - timeout-minutes: - required: false - type: number - default: 30 - description: 'Job timeout in minutes' +# on: +# workflow_call: +# inputs: +# os: +# required: true +# type: string +# description: 'Runner OS (e.g., ubuntu-24.04, macos-14, windows-2022)' +# build-type: +# required: true +# type: string +# description: 'CMake build type (Release, Debug)' +# cmake-config: +# required: false +# type: string +# default: '-G Ninja' +# description: 'CMake configuration options (-G, -A, -T, compiler flags)' +# extra-cmake-flags: +# required: false +# type: string +# default: '' +# description: 'Additional CMake flags for the project' +# dependencies: +# required: false +# type: string +# default: '' +# description: 'Command to install dependencies' +# build-only: +# required: false +# type: boolean +# default: false +# description: 'Skip tests if true' +# self-host: +# required: false +# type: boolean +# default: false +# description: 'Run self-hosting test' +# check-binary-size: +# required: false +# type: boolean +# default: true +# description: 'Check binary size is reasonable' +# test-exclude-pattern: +# required: false +# type: string +# default: '' +# description: 'Regex pattern for tests to exclude' +# test-extra-args: +# required: false +# type: string +# default: '' +# description: 'Extra arguments for ctest' +# use-msbuild: +# required: false +# type: boolean +# default: false +# description: 'Use MSBuild instead of Ninja for building' +# timeout-minutes: +# required: false +# type: number +# default: 30 +# description: 'Job timeout in minutes' jobs: build: diff --git a/.github/workflows/reusable-vm-build.yml b/.github/workflows/reusable-vm-build.yml index bc4e2e1a8..76f36ab76 100644 --- a/.github/workflows/reusable-vm-build.yml +++ b/.github/workflows/reusable-vm-build.yml @@ -1,39 +1,39 @@ name: Reusable VM Build -on: - workflow_call: - inputs: - vm-type: - required: true - type: string - description: 'VM type (freebsd, netbsd, openbsd)' - vm-version: - required: true - type: string - description: 'VM version' - build-type: - required: true - type: string - description: 'CMake build type' - dependencies: - required: true - type: string - description: 'Commands to install dependencies' - cmake-flags: - required: false - type: string - default: '' - description: 'Additional CMake flags' - host-os: - required: false - type: string - default: 'ubuntu-22.04' - description: 'Host runner OS' - timeout-minutes: - required: false - type: number - default: 25 - description: 'Job timeout in minutes' +# on: +# workflow_call: +# inputs: +# vm-type: +# required: true +# type: string +# description: 'VM type (freebsd, netbsd, openbsd)' +# vm-version: +# required: true +# type: string +# description: 'VM version' +# build-type: +# required: true +# type: string +# description: 'CMake build type' +# dependencies: +# required: true +# type: string +# description: 'Commands to install dependencies' +# cmake-flags: +# required: false +# type: string +# default: '' +# description: 'Additional CMake flags' +# host-os: +# required: false +# type: string +# default: 'ubuntu-22.04' +# description: 'Host runner OS' +# timeout-minutes: +# required: false +# type: number +# default: 25 +# description: 'Job timeout in minutes' jobs: build: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index cb070f78b..1d43c695a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -7,10 +7,10 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} on: - push: - branches: [ main ] - pull_request: - branches: [ main ] + # push: + # branches: [ main ] + # pull_request: + # branches: [ main ] workflow_dispatch: diff --git a/src/snmalloc/global/threadalloc.h b/src/snmalloc/global/threadalloc.h index d037995e5..37dfd61cc 100644 --- a/src/snmalloc/global/threadalloc.h +++ b/src/snmalloc/global/threadalloc.h @@ -26,6 +26,7 @@ # error At most one out of method of thread teardown can be specified. # endif # define SNMALLOC_THREAD_TEARDOWN_DEFINED +# define __cxa_thread_atexit_impl __cxa_thread_atexit extern "C" int __cxa_thread_atexit_impl(void(func)(void*), void*, void*); extern "C" void* __dso_handle; #endif diff --git a/src/snmalloc/pal/pal_linux.h b/src/snmalloc/pal/pal_linux.h index 251aaf321..500e53cd6 100644 --- a/src/snmalloc/pal/pal_linux.h +++ b/src/snmalloc/pal/pal_linux.h @@ -19,6 +19,13 @@ # include # endif +# if defined(__CHERI_PURE_CAPABILITY__) //&& defined(__MORELLO__) +# include +# if !defined(CHERI_PERM_SW_VMEM) +# define CHERI_PERM_SW_VMEM CHERI_PERM_CHERIABI_VMMAP +# endif +# endif + # include namespace snmalloc @@ -161,6 +168,33 @@ namespace snmalloc madvise(p, size, MADV_DONTDUMP); } +# if defined(__CHERI_PURE_CAPABILITY__) + static_assert( + aal_supports, + "CHERI purecap support requires StrictProvenance AAL"); + + /** + * On CheriBSD, exporting a pointer means stripping it of the authority to + * manage the address space it references by clearing the SW_VMEM + * permission bit (Which sounds appropriate on Linux, too). + */ + template + static SNMALLOC_FAST_PATH CapPtr> + capptr_to_user_address_control(CapPtr p) + { + if constexpr (Aal::aal_cheri_features & Aal::AndPermsTrapsUntagged) + { + if (p == nullptr) + { + return nullptr; + } + } + return CapPtr>::unsafe_from( + __builtin_cheri_perms_and( + p.unsafe_ptr(), ~static_cast(CHERI_PERM_SW_VMEM))); + } +# endif + static uint64_t get_entropy64() { KeepErrno k; @@ -179,7 +213,7 @@ namespace snmalloc char buffer[sizeof(uint64_t)]; }; - ssize_t ret; + intptr_t ret; // give a try to SYS_getrandom # ifdef SYS_getrandom @@ -203,7 +237,10 @@ namespace snmalloc // 2. `GRND_NONBLOCK` bit is set. Since we are reading from // `urandom`, this means if the entropy pool is // not initialised, we will get a EAGAIN. - ret = syscall(SYS_getrandom, current, length, GRND_NONBLOCK); + ret = syscall(SYS_getrandom, + current, + length, + GRND_NONBLOCK); // check whether are interrupt by a signal if (SNMALLOC_UNLIKELY(ret < 0)) { diff --git a/src/test/func/cheri/cheri.cc b/src/test/func/cheri/cheri.cc index 1928dbbd5..b56aa6b7a 100644 --- a/src/test/func/cheri/cheri.cc +++ b/src/test/func/cheri/cheri.cc @@ -10,7 +10,12 @@ int main() // # define SNMALLOC_TRACING +# if defined(__FreeBSD__) # include +# else +# include +# endif + # include # include @@ -130,10 +135,10 @@ int main() */ message("Grab Alloc from pool for inspection"); { - static_assert( - std::is_same_v>); + static_assert(std::is_same_v&>); - auto* ca = AllocPool::acquire(); + auto* ca = AllocPool::acquire(); SNMALLOC_CHECK(cap_len_is(ca, sizeof(*ca))); SNMALLOC_CHECK(cap_vmem_perm_is(ca, false)); diff --git a/src/test/func/memory/memory.cc b/src/test/func/memory/memory.cc index 7c181a24a..195a33391 100644 --- a/src/test/func/memory/memory.cc +++ b/src/test/func/memory/memory.cc @@ -29,7 +29,10 @@ # ifdef __OpenBSD__ using rlim64_t = rlim_t; +# elif defined(__linux__) +using rlim64_t = size_t; # endif + #else using rlim64_t = size_t; #endif