diff --git a/CMakeLists.txt b/CMakeLists.txt index 74d8582..d174ec7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,10 @@ macro(warnings_high) endif() endmacro() +macro(oe_simulate target) + target_compile_definitions(${target} PRIVATE IS_REALLY_ADDRESS_SPACE_CONSTRAINED) +endmacro() + macro(clangformat_targets) # The clang-format tool is installed under a variety of different names. Try # to find a sensible one. Only look for versions 9 explicitly - we don't @@ -244,6 +248,9 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY) add_shim(snmallocshim SHARED ${SHARED_FILES}) add_shim(snmallocshim-1mib SHARED ${SHARED_FILES}) target_compile_definitions(snmallocshim-1mib PRIVATE IS_ADDRESS_SPACE_CONSTRAINED) + # Build a shim with some settings from oe. + add_shim(snmallocshim-oe SHARED ${SHARED_FILES}) + oe_simulate(snmallocshim-oe) endif() if(SNMALLOC_RUST_SUPPORT) @@ -260,7 +267,7 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY) foreach(TEST_CATEGORY ${TEST_CATEGORIES}) subdirlist(TESTS ${TESTDIR}/${TEST_CATEGORY}) foreach(TEST ${TESTS}) - foreach(SUPER_SLAB_SIZE 1;16) + foreach(SUPER_SLAB_SIZE 1;16;oe) unset(SRC) aux_source_directory(${TESTDIR}/${TEST_CATEGORY}/${TEST} SRC) set(TESTNAME "${TEST_CATEGORY}-${TEST}-${SUPER_SLAB_SIZE}") @@ -269,6 +276,9 @@ if(NOT DEFINED SNMALLOC_ONLY_HEADER_LIBRARY) if (${SUPER_SLAB_SIZE} EQUAL 1) target_compile_definitions(${TESTNAME} PRIVATE IS_ADDRESS_SPACE_CONSTRAINED) endif() + if (${SUPER_SLAB_SIZE} EQUAL oe) + oe_simulate(${TESTNAME}) + endif() target_link_libraries(${TESTNAME} snmalloc_lib) if (${TEST} MATCHES "release-.*") message(STATUS "Adding test: ${TESTNAME} only for release configs") diff --git a/src/mem/allocconfig.h b/src/mem/allocconfig.h index 9704b94..ae6240b 100644 --- a/src/mem/allocconfig.h +++ b/src/mem/allocconfig.h @@ -50,6 +50,15 @@ namespace snmalloc #endif ; + // Specifies even smaller slab and super slab sizes for open enclave. + static constexpr size_t REALLY_ADDRESS_SPACE_CONSTRAINED = +#ifdef IS_REALLY_ADDRESS_SPACE_CONSTRAINED + true +#else + false +#endif + ; + static constexpr size_t RESERVE_MULTIPLE = #ifdef USE_RESERVE_MULTIPLE USE_RESERVE_MULTIPLE @@ -100,14 +109,17 @@ namespace snmalloc static constexpr size_t MIN_ALLOC_BITS = bits::ctz_const(MIN_ALLOC_SIZE); // Slabs are 64 KiB unless constrained to 16 KiB. - static constexpr size_t SLAB_BITS = ADDRESS_SPACE_CONSTRAINED ? 14 : 16; + static constexpr size_t SLAB_BITS = REALLY_ADDRESS_SPACE_CONSTRAINED ? + 13 : + (ADDRESS_SPACE_CONSTRAINED ? 14 : 16); static constexpr size_t SLAB_SIZE = 1 << SLAB_BITS; static constexpr size_t SLAB_MASK = ~(SLAB_SIZE - 1); // Superslabs are composed of this many slabs. Slab offsets are encoded as // a byte, so the maximum count is 256. This must be a power of two to // allow fast masking to find a superslab start address. - static constexpr size_t SLAB_COUNT_BITS = ADDRESS_SPACE_CONSTRAINED ? 6 : 8; + static constexpr size_t SLAB_COUNT_BITS = + REALLY_ADDRESS_SPACE_CONSTRAINED ? 5 : (ADDRESS_SPACE_CONSTRAINED ? 6 : 8); static constexpr size_t SLAB_COUNT = 1 << SLAB_COUNT_BITS; static constexpr size_t SUPERSLAB_SIZE = SLAB_SIZE * SLAB_COUNT; static constexpr size_t SUPERSLAB_MASK = ~(SUPERSLAB_SIZE - 1); diff --git a/src/test/func/two_alloc_types/alloc2.cc b/src/test/func/two_alloc_types/alloc2.cc index 5338054..67be116 100644 --- a/src/test/func/two_alloc_types/alloc2.cc +++ b/src/test/func/two_alloc_types/alloc2.cc @@ -1,4 +1,7 @@ -#undef IS_ADDRESS_SPACE_CONSTRAINED +// Remove parameters feed from test harness +#undef ADDRESS_SPACE_CONSTRAINED +#undef REALLY_ADDRESS_SPACE_CONSTRAINED + #define SNMALLOC_NAME_MANGLE(a) host_##a #define NO_BOOTSTRAP_ALLOCATOR #define SNMALLOC_EXPOSE_PAGEMAP