diff options
author | vnugent <public@vaughnnugent.com> | 2024-04-20 11:10:30 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2024-04-20 11:10:30 -0400 |
commit | 8c4a45e384accf92b1b6d748530e8d46f7de40d6 (patch) | |
tree | e0cb1664982934c6d87002864d50642f1d0b0645 /lib | |
parent | 42ff77080d10b0fc9fecbbc46141e8e23a1d066a (diff) |
refactor: Overhaul C libraries and fix builds
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Net.Compression/vnlib_compress/CMakeLists.txt | 464 | ||||
-rw-r--r-- | lib/Net.Compression/vnlib_compress/Taskfile.yaml | 57 | ||||
-rw-r--r-- | lib/Net.Compression/vnlib_compress/compression.h | 16 | ||||
-rw-r--r-- | lib/Net.Compression/vnlib_compress/feature_brotli.c | 6 | ||||
-rw-r--r-- | lib/Net.Compression/vnlib_compress/util.h | 56 | ||||
-rw-r--r-- | lib/Utils.Memory/NativeHeapApi/src/NativeHeapApi.h | 160 | ||||
-rw-r--r-- | lib/Utils.Memory/vnlib_mimalloc/CMakeLists.txt | 151 | ||||
-rw-r--r-- | lib/Utils.Memory/vnlib_mimalloc/NativeHeapApi.h | 160 | ||||
-rw-r--r-- | lib/Utils.Memory/vnlib_mimalloc/Taskfile.yaml | 23 | ||||
-rw-r--r-- | lib/Utils.Memory/vnlib_rpmalloc/CMakeLists.txt | 130 | ||||
-rw-r--r-- | lib/Utils.Memory/vnlib_rpmalloc/NativeHeapApi.h | 160 | ||||
-rw-r--r-- | lib/Utils.Memory/vnlib_rpmalloc/Taskfile.yaml | 11 | ||||
-rw-r--r-- | lib/Utils.Memory/vnlib_rpmalloc/vnlib_rpmalloc.vcxitems | 1 |
13 files changed, 566 insertions, 829 deletions
diff --git a/lib/Net.Compression/vnlib_compress/CMakeLists.txt b/lib/Net.Compression/vnlib_compress/CMakeLists.txt index f963c41..c3eb723 100644 --- a/lib/Net.Compression/vnlib_compress/CMakeLists.txt +++ b/lib/Net.Compression/vnlib_compress/CMakeLists.txt @@ -1,95 +1,181 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.10) project(vnlib_compress C) - -#export header files to the main project -file(GLOB COMP_HEADERS *.h) - -#Add indepednent source files to the project -set(VNLIB_COMPRESS_SOURCES compression.c) +set(CMAKE_PROJECT_NAME "vnlib_compress") #set options for enable botli and zlib option(ENABLE_BROTLI "Enable brotli compression" ON) option(ENABLE_ZLIB "Enable zlib compression" ON) option(ENABLE_RPMALLOC "Enable local source code vnlib_rpmalloc memory allocator" OFF) +option(COMPRESS_BUILD_SHARED "Produces a shared library instead of a static library" ON) +option(USE_STATIC_RUNTIME "Use the static runtime library" OFF) +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The build configuration type") + +string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) +message(STATUS "Build type is '${build_type}'") -set(THIRD_PARTY_DIR ./third-party) +#export all header files to the main project +file(GLOB COMP_HEADERS *.h) +set(VNLIB_COMPRESS_SOURCES + compression.c +) + +include(FetchContent) + +############################### +# +# DOWNLOAD DEPENDENCIES +# +############################### -#add feature specific source files to the project if(ENABLE_BROTLI) + + message(STATUS "Downloading brotli compression as a local dependency") + + set(BROTLI_BUNDLED_MODE OFF) #explicitly set bundled mode to off + set(BROTLI_EMSCRIPTEN OFF) #disable emscripten support + set(BUILD_SHARED_LIBS OFF) #disable shared library building, as only static is needed + + FetchContent_Declare( + lib_brotli + GIT_REPOSITORY https://github.com/google/brotli.git + GIT_TAG 1b3a5ccb6e7b9384b741437532f4dae0730c61f2 + GIT_PROGRESS TRUE + ) + + FetchContent_GetProperties(lib_brotli) + FetchContent_MakeAvailable(lib_brotli) + + #add include directories for brotli + include_directories(${lib_brotli_SOURCE_DIR}/c/include) + + #add the brotli source files to the project list(APPEND VNLIB_COMPRESS_SOURCES feature_brotli.c) - #define the brotli feature macro to enable zlib support - add_definitions(-DVNLIB_COMPRESSOR_BROTLI_ENABLED) + add_compile_definitions(VNLIB_COMPRESSOR_BROTLI_ENABLED) endif() if(ENABLE_ZLIB) + + #by default the cloudlfare fork should build a static lib. It will be large + message(STATUS "Downloading ZLIB as a local dependency") + + set(SKIP_INSTALL_ALL ON) #do not install zlib files + + #add zlib source files to the project + FetchContent_Declare( + lib_cf_zlib + GIT_REPOSITORY https://github.com/cloudflare/zlib.git + GIT_TAG 92530568d2c128b4432467b76a3b54d93d6350bd + GIT_PROGRESS TRUE + ) + + #Get project properties + FetchContent_GetProperties(lib_cf_zlib) + FetchContent_MakeAvailable(lib_cf_zlib) + + #add include directories for zlib + include_directories(${lib_cf_zlib_SOURCE_DIR}) + + #enable the feature code for zlib and add the source files list(APPEND VNLIB_COMPRESS_SOURCES feature_zlib.c) - #define the zlib feature macro to enable zlib support - add_definitions(-DVNLIB_COMPRESSOR_ZLIB_ENABLED) + add_compile_definitions(VNLIB_COMPRESSOR_ZLIB_ENABLED) endif() -#create my shared library -add_library(${CMAKE_PROJECT_NAME} SHARED ${VNLIB_COMPRESS_SOURCES} ${COMP_HEADERS}) -#also create static library -add_library(${CMAKE_PROJECT_NAME}_static STATIC ${VNLIB_COMPRESS_SOURCES} ${COMP_HEADERS}) +#Add support for rpmalloc memmory allocator +if(ENABLE_RPMALLOC) -#if on unix lib will be appended, so we can adjust -if(UNIX) - set_target_properties(${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_NAME}_static PROPERTIES OUTPUT_NAME vn_compress) + #enable greedy mode for rpmalloc + set(ENABLE_GREEDY ON) + + add_subdirectory( + ../../Utils.Memory/vnlib_rpmalloc/ + ${CMAKE_CURRENT_BINARY_DIR}/vnlib_rpmalloc/ + ) + + add_compile_definitions(VNLIB_CUSTOM_MALLOC_ENABLE) endif() #Setup the compiler options -set(CMAKE_C_STANDARD 90) set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) #enable position independent code (for shared libraries with exports) + +############################### +# +# CONFIGURE LIBRARY BUILD +# +############################### + +if(COMPRESS_BUILD_SHARED) + set(TARGET_NAME ${CMAKE_PROJECT_NAME}) + add_library(${TARGET_NAME} SHARED ${VNLIB_COMPRESS_SOURCES} ${COMP_HEADERS}) +else() + set(TARGET_NAME ${CMAKE_PROJECT_NAME}_static) + add_library(${TARGET_NAME} STATIC ${VNLIB_COMPRESS_SOURCES} ${COMP_HEADERS}) +endif() -#enable position independent code (for shared libraries with exports) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +target_compile_features(${TARGET_NAME} PRIVATE c_std_90) #force compiler to use c90 standard for library + +#if on unix lib will be appended, so we can adjust +if(UNIX) + set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME vn_compress) +endif() #since were buildiing in tree, set the export defintiions -add_definitions(-DVNLIB_EXPORTING) +target_compile_definitions(${TARGET_NAME} PRIVATE VNLIB_EXPORTING) + +if(ENABLE_BROTLI) + #link the encoder-only library to the main project + target_link_libraries(${TARGET_NAME} PRIVATE brotlienc) +endif() + +if(ENABLE_ZLIB) + #workaround cloudlfare fork bug. SSE is always enabled with x64 on Windows + if(MSVC) + target_compile_definitions(zlib PRIVATE HAS_SSE42 PRIVATE HAS_SSE2) + endif() + + target_link_libraries(${TARGET_NAME} PRIVATE zlib) +endif() -message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'") +#link rpmalloc to the main project +if(ENABLE_RPMALLOC) + target_link_libraries(${TARGET_NAME} PRIVATE vnlib_rpmalloc_static) + add_dependencies(${TARGET_NAME} vnlib_rpmalloc_static) -#include checks for zlib and brotli -include(CheckTypeSize) -include(CheckFunctionExists) -include(CheckIncludeFile) -include(CheckCCompilerFlag) -enable_testing() + #Include the nativeheap api header + target_include_directories(${TARGET_NAME} PRIVATE ../../Utils.Memory/vnlib_rpmalloc/) +endif() #setup flags for windows compilation if(MSVC) - - #global windows cl flags - add_compile_options( + target_compile_options( + ${TARGET_NAME} + PRIVATE + /Qspectre /sdl /TC /GS - - $<$<CONFIG:Debug>:/FC> - $<$<CONFIG:Debug>:/showIncludes> - ) - #only target our project - target_compile_options( - ${CMAKE_PROJECT_NAME} - PRIVATE + #disable warnings for struct padding and spectre mitigation when WX is enabled + $<$<CONFIG:Debug>:/wd5045> + $<$<CONFIG:Debug>:/wd4820> #for debug configs $<$<CONFIG:Debug>:/options:strict> - #disable warnings for struct padding and spectre mitigation wuen WX is enabled - $<$<CONFIG:Debug>:/wd5045> - $<$<CONFIG:Debug>:/wd4820> + $<$<CONFIG:Debug>:/FC> #full path in diagnostics $<$<CONFIG:Debug>:/Wall> - $<$<CONFIG:Debug>:/WX> #warnings as errors (only for our project) - $<$<CONFIG:Debug>:/Zi> - $<$<CONFIG:Debug>:/Zo> + $<$<CONFIG:Debug>:/WX> #warnings as errors (only for our project) + $<$<CONFIG:Debug>:/Zi> #enable debug info + $<$<CONFIG:Debug>:/showIncludes> ) #set build macros - add_compile_definitions( + target_compile_definitions( + ${TARGET_NAME} + PRIVATE + $<$<CONFIG:DEBUG>:DEBUG> $<$<CONFIG:RELEASE>:RELEASE> ) @@ -97,215 +183,33 @@ if(MSVC) #configure gcc flags elseif(CMAKE_COMPILER_IS_GNUCC) - add_compile_options( - -Wextra - -fstack-protector - - $<$<CONFIG:Debug>:-g> - $<$<CONFIG:Debug>:-Og> - $<$<CONFIG:Debug>:-Wall> - $<$<CONFIG:Debug>:-Werror> - ) - - #only target our project - target_compile_options( - ${CMAKE_PROJECT_NAME} + target_compile_options( + ${TARGET_NAME} PRIVATE - $<$<CONFIG:Debug>:-Wall> - $<$<CONFIG:Debug>:-pedantic> - ) -endif() - -#check for brotli encoding only feature enablement -if(ENABLE_BROTLI) - - #macros for brotli - set(BROTLI_DEFINITIONS) - - set(LIBM_LIBRARY) - check_function_exists(log2 LOG2_RES) - - if(NOT LOG2_RES) - - set(orig_req_libs "${CMAKE_REQUIRED_LIBRARIES}") - set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};m") - - check_function_exists(log2 LOG2_LIBM_RES) - - if(LOG2_LIBM_RES) - set(LIBM_LIBRARY "m") - list(APPEND BROTLI_DEFINITIONS -DBROTLI_HAVE_LOG2=1) - else() - list(APPEND BROTLI_DEFINITIONS -DBROTLI_HAVE_LOG2=0) - endif() - - set(CMAKE_REQUIRED_LIBRARIES "${orig_req_libs}") - unset(LOG2_LIBM_RES) - unset(orig_req_libs) - else() - list(APPEND BROTLI_DEFINITIONS -DBROTLI_HAVE_LOG2=1) - endif() - unset(LOG2_RES) - - #target definitions from brotli cmakelists - if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - list(APPEND BROTLI_DEFINITIONS -DOS_LINUX) - elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") - list(APPEND BROTLI_DEFINITIONS -DOS_FREEBSD) - elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - list(APPEND BROTLI_DEFINITIONS -DOS_MACOSX) - set(CMAKE_MACOS_RPATH TRUE) - endif() - - #add the include directory for brotli so we can include the header files - include_directories(${THIRD_PARTY_DIR}/brotli/c/include) - - #get common sources - file(GLOB BROTLI_SOURCES ${THIRD_PARTY_DIR}/brotli/c/common/*.c) - - #we need to add the brotli encoder source files to the project - file(GLOB BROTLI_ENC_SOURCES ${THIRD_PARTY_DIR}/brotli/c/enc/*.c) - - #add brotli as a static library to link later - add_library(lib_brotli STATIC ${BROTLI_SOURCES} ${BROTLI_ENC_SOURCES}) - - target_link_libraries(${CMAKE_PROJECT_NAME} lib_brotli) - - #add the definitions to the brotli project only - target_compile_definitions(lib_brotli PRIVATE ${BROTLI_DEFINITIONS}) - -endif() - -#check for zlib feature enablement, supports madler and cloudflare forks -if(ENABLE_ZLIB) - - #add the include directory for zlib so we can include the header files - include_directories(${THIRD_PARTY_DIR}/zlib) - - set(ZLIB_DEFINITIONS) - set(Z_C_FLAGS) - - #we only need to add the zlib deflate source files to the project - set(ZLIB_SOURCES - ${THIRD_PARTY_DIR}/zlib/deflate.c - ${THIRD_PARTY_DIR}/zlib/adler32.c - ${THIRD_PARTY_DIR}/zlib/crc32.c - ${THIRD_PARTY_DIR}/zlib/zutil.c - ${THIRD_PARTY_DIR}/zlib/trees.c + -Wextra + -fstack-protector ) - - check_type_size(off64_t OFF64_T) - check_function_exists(fseeko HAVE_FSEEKO) - - if(HAVE_OFF64_T) - list(APPEND ZLIB_DEFINITIONS -D_LARGEFILE64_SOURCE=1) - endif() - #add fseeko if we have it - if(NOT HAVE_FSEEKO) - list(APPEND ZLIB_DEFINITIONS -DNO_FSEEKO) - endif() - - if(MSVC) - - set(CMAKE_DEBUG_POSTFIX "d") - - list(APPEND ZLIB_DEFINITIONS - -D_CRT_SECURE_NO_DEPRECATE - -D_CRT_NONSTDC_NO_DEPRECATE + #enable debug compiler options + if(build_type STREQUAL "debug") + target_compile_options( + ${TARGET_NAME} + PRIVATE + + -g #enable debugger info + -Og #disable optimizations + -Wall #enable all warnings + -Werror #treat warnings as errors + -pedantic #enable pedantic mode ) - - #NOTE - #During CI a pre-compiled library will be built. - #We cannot depend on users having the the same instructions as the build machine - #So some optimizations are disabled for the pre-compiled library - - if(NOT CI_PRECOMPILE) - - #setup avx compiler support on Windows - check_c_compiler_flag(/arch:AVX HAS_AVX) - if (HAS_AVX) - list(APPEND Z_C_FLAGS /arch:AVX) - list(APPEND ZLIB_DEFINITIONS -DHAS_AVX) - endif() - - endif() - - #All x64 machines have SSE2, so we can use it as - #and the Windows compiler will automatically use it - #so we only need to set the definition - list(APPEND Z_C_FLAGS /arch:SSE2) - list(APPEND ZLIB_DEFINITIONS -DHAS_SSE2 -DHAS_SSE42) - - elseif(UNIX) - - #for cloudflare intrinsic detections - check_c_compiler_flag(-march=armv8-a+crc ARM_CRC) - check_c_compiler_flag(-msse2 HAS_SSE2) - check_c_compiler_flag(-mssse3 HAS_SSSE3) - check_c_compiler_flag(-msse4.2 HAS_SSE42) - check_c_compiler_flag(-mpclmul HAS_PCLMUL) - - if(ARM_CRC) - list(APPEND Z_C_FLAGS -march=armv8-a+crc) - - if(EXISTS "{THIRD_PARTY_DIR}/zlib/adler32_simd.c") - list(APPEND ZLIB_DEFINITIONS -DADLER32_SIMD_NEON) - list(APPEND ZLIB_SOURCES ${THIRD_PARTY_DIR}/zlib/adler32_simd.c) - endif() - - else() - if(HAS_SSE2) - list(APPEND Z_C_FLAGS -msse2) - list(APPEND ZLIB_DEFINITIONS -DHAS_SSE2) - #excluding inflate specific optimizations - endif() - if(HAS_SSSE3) - list(APPEND Z_C_FLAGS -mssse3) - - #add cloudflare intrinsic optimizations, may not be present if using non-cloudflare fork - if(EXISTS "${THIRD_PARTY_DIR}/zlib/adler32_simd.c") - list(APPEND ZLIB_DEFINITIONS -DHAS_SSSE3 -DADLER32_SIMD_SSSE3) - list(APPEND ZLIB_SOURCES ${THIRD_PARTY_DIR}/zlib/adler32_simd.c) - endif() - - endif() - if(HAS_SSE42) - list(APPEND Z_C_FLAGS -msse4.2) - list(APPEND ZLIB_DEFINITIONS -DHAS_SSE42) - endif() - if(HAS_PCLMUL) - list(APPEND Z_C_FLAGS -mpclmul) - - #add cloudflare intrinsic optimizations for PCMLONGMUL crc32, may not be present if using non-cloudflare fork - if(EXISTS "${THIRD_PARTY_DIR}/zlib/crc32_simd.c") - list(APPEND ZLIB_DEFINITIONS -DHAS_PCLMUL) - list(APPEND ZLIB_SOURCES ${THIRD_PARTY_DIR}/zlib/crc32_simd.c) - endif() - - endif() - endif() - endif() - - - - #add zlib as a library to link later - add_library(lib_deflate STATIC ${ZLIB_SOURCES}) + target_compile_definitions(${TARGET_NAME} PRIVATE DEBUG) - if(MSVC) - #allways targeting x64 machines - set_target_properties(lib_deflate PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64") endif() - #add the definitions to the zlib project only - target_compile_definitions(lib_deflate PRIVATE ${ZLIB_DEFINITIONS}) - - #only target zlib project with compiler flags - target_compile_options(lib_deflate PRIVATE ${Z_C_FLAGS}) - - target_link_libraries(${CMAKE_PROJECT_NAME} lib_deflate) +else() + message(FATAL_ERROR "Unsupported compiler, sorry. Submit an issue for your platform and I'll work on it :)") endif() if(NATIVE_HEAP_LIB_PATH) @@ -314,63 +218,7 @@ if(NATIVE_HEAP_LIB_PATH) include_directories(${NATIVE_HEAP_INCLUDES}) #If manual heap linking is enabled, we need to link the native heap library - target_link_libraries(${CMAKE_PROJECT_NAME} ${NATIVE_HEAP_LIB_PATH}) - - #Disable rpmalloc if we are linking a custom native heap - set(ENABLE_RPMALLOC OFF) - - #add defintion to enable custom malloc heap overrides - target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE VNLIB_CUSTOM_MALLOC_ENABLE) - -endif() - -#Add support for rpmalloc memmory allocator -if(ENABLE_RPMALLOC) - - #Include the nativeheap api header - include_directories(../../Utils.Memory/NativeHeapApi/src) - - if(MSVC) + target_link_libraries(${TARGET_NAME} PRIVATE ${NATIVE_HEAP_LIB_PATH}) + target_compile_definitions(${TARGET_NAME} PRIVATE VNLIB_CUSTOM_MALLOC_ENABLE) #configure src - #find the rpmalloc static library for windows builds - find_library(VNLIB_RPMALLOC_DEBUG_LIB - NAMES vnlib_rpmalloc_static - PATHS ../../Utils.Memory/vnlib_rpmalloc/build/Debug - ) - - find_library(VNLIB_RPMALLOC_RELEASE_LIB - NAMES vnlib_rpmalloc_static - PATHS ../../Utils.Memory/vnlib_rpmalloc/build/Release - ) - - #target static libraries for all configs - target_link_libraries(${CMAKE_PROJECT_NAME} - $<$<CONFIG:Debug>:${VNLIB_RPMALLOC_DEBUG_LIB}> - #set release for all release configs - $<$<CONFIG:MinSizeRel>:${VNLIB_RPMALLOC_RELEASE_LIB}> - $<$<CONFIG:RelWithDepInfo>:${VNLIB_RPMALLOC_RELEASE_LIB}> - $<$<CONFIG:Release>:${VNLIB_RPMALLOC_RELEASE_LIB}> - ) - - elseif(UNIX) - - #find the rpmalloc library for unix builds - find_library(VNLIB_RPMALLOC_LIB - NAMES libvn_rpmalloc - PATHS ../../Utils.Memory/vnlib_rpmalloc/build - ) - - #add the rpmalloc library to the project - target_link_libraries(${CMAKE_PROJECT_NAME} ${VNLIB_RPMALLOC_LIB}) - - else() - - #failure - message(FATAL_ERROR "Unsupported platform configuration for rpmalloc") - - endif() - - #add defintion to enable custom malloc heap overrides - target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE VNLIB_CUSTOM_MALLOC_ENABLE) - -endif() +endif()
\ No newline at end of file diff --git a/lib/Net.Compression/vnlib_compress/Taskfile.yaml b/lib/Net.Compression/vnlib_compress/Taskfile.yaml index fff756d..4ddc464 100644 --- a/lib/Net.Compression/vnlib_compress/Taskfile.yaml +++ b/lib/Net.Compression/vnlib_compress/Taskfile.yaml @@ -9,50 +9,21 @@ version: '3' vars: - THIRD_PARTY_DIR: './third-party' PROJECT_NAME: 'vnlib_compress' - ZLIB_GIT_REPO: 'https://github.com/cloudflare/zlib.git' - BROTLI_GIT_REPO: 'https://github.com/google/brotli.git' tasks: default: cmds: - - cmd: echo "Building vnlib_compress" + - cmd: echo "Building {{.PROJECT_NAME}}" silent: true - - #make third-party dir before cloning libs - - cmd: powershell -Command "mkdir '{{.THIRD_PARTY_DIR}}' -Force" - platforms: [windows] - ignore_error: true - - cmd: mkdir -p '{{.THIRD_PARTY_DIR}}' - platforms: [linux, darwin] - ignore_error: true - - - task: zlib - - task: brotli - - #invoke cmake for build - - cmake -B./build {{.CMAKE_ARGS}} - - #build for platform - - cmake --build build/ --config Release - + - cmake -Bbuild/ -DCMAKE_BUILD_TYPE=Release {{.CMAKE_ARGS}} + - cmake --build build/ --config Release #called by ci pipline to build the winx64 project build: cmds: - #make third-party dir before cloning libs - - cmd: powershell -Command "mkdir '{{.THIRD_PARTY_DIR}}' -Force" - platforms: [windows] - ignore_error: true - - cmd: mkdir -p '{{.THIRD_PARTY_DIR}}' - platforms: [linux, darwin] - ignore_error: true - - task: zlib - - task: brotli - #the CI pipline may have issues reading modules if the third-party dir is not cleaned every time a build runs, only an issue after build - defer: { task: clean-third-party } @@ -85,31 +56,15 @@ tasks: clean: ignore_error: true cmds: - - for: [ bin/, build/, third-party/ ] + - for: [ bin/, build/ ] cmd: powershell Remove-Item -Recurse '{{.ITEM}}' -Force - - #update or install the cloudflare fork of zlib library - zlib: - internal: true - status: - - cd {{.THIRD_PARTY_DIR}} && git clone {{.ZLIB_GIT_REPO}} - cmds: - - cd {{.THIRD_PARTY_DIR}}/zlib && git pull - - #update or install the google brotli library - brotli: - internal: true - status: - - cd {{.THIRD_PARTY_DIR}} && git clone {{.BROTLI_GIT_REPO}} - cmds: - - cd {{.THIRD_PARTY_DIR}}/brotli && git pull clean-third-party: internal: false ignore_error: true cmds: - - cmd: powershell rm -Recurse -Force '{{.THIRD_PARTY_DIR}}' + - cmd: powershell rm -Recurse -Force 'build/_deps/' platforms: [windows] - - cmd: rm -rf {{.THIRD_PARTY_DIR}} + - cmd: rm -rf 'build/_deps/' platforms: [linux, darwin]
\ No newline at end of file diff --git a/lib/Net.Compression/vnlib_compress/compression.h b/lib/Net.Compression/vnlib_compress/compression.h index a6a6104..3d03145 100644 --- a/lib/Net.Compression/vnlib_compress/compression.h +++ b/lib/Net.Compression/vnlib_compress/compression.h @@ -44,31 +44,31 @@ #define _IS_WINDOWS #endif -//Set api export calling convention (allow used to override) +/*Set api export calling convention(allow used to override)*/ #ifndef VNLIB_COMPRESS_CC #ifdef _IS_WINDOWS - //STD for importing to other languages such as .NET + /*STD for importing to other languages such as.NET*/ #define VNLIB_COMPRESS_CC __stdcall #else #define VNLIB_COMPRESS_CC #endif -#endif // !VNLIB_CC +#endif /* !VNLIB_CC */ -#ifndef VNLIB_COMPRESS_EXPORT //Allow users to disable the export/impoty macro if using source code directly +#ifndef VNLIB_COMPRESS_EXPORT /*Allow users to disable the export/impoty macro if using source code directly*/ #ifdef VNLIB_COMPRESS_EXPORTING #ifdef _IS_WINDOWS #define VNLIB_COMPRESS_EXPORT __declspec(dllexport) #else #define VNLIB_COMPRESS_EXPORT __attribute__((visibility("default"))) - #endif // IS_WINDOWS + #endif /* IS_WINDOWS */ #else #ifdef _IS_WINDOWS #define VNLIB_COMPRESS_EXPORT __declspec(dllimport) #else #define VNLIB_COMPRESS_EXPORT - #endif // IS_WINDOWS - #endif // !VNLIB_EXPORTING -#endif // !VNLIB_EXPORT + #endif /* IS_WINDOWS */ + #endif /* !VNLIB_EXPORTING */ +#endif /* !VNLIB_EXPORT */ #ifndef _In_ #define _In_ diff --git a/lib/Net.Compression/vnlib_compress/feature_brotli.c b/lib/Net.Compression/vnlib_compress/feature_brotli.c index d5ba141..361c61a 100644 --- a/lib/Net.Compression/vnlib_compress/feature_brotli.c +++ b/lib/Net.Compression/vnlib_compress/feature_brotli.c @@ -223,14 +223,14 @@ int BrCompressBlock(const CompressorState* state, CompressionOperation* operatio int64_t BrGetCompressedSize(const CompressorState* state, uint64_t length, int32_t flush) { - (void)flush; + size_t size; + + (void)sizeof(flush); /* * When the flush flag is set, the caller is requesting the * entire size of the compressed data, which can include metadata */ - size_t size; - validateCompState(state) if (length <= 0) diff --git a/lib/Net.Compression/vnlib_compress/util.h b/lib/Net.Compression/vnlib_compress/util.h index c29de4b..292e3bf 100644 --- a/lib/Net.Compression/vnlib_compress/util.h +++ b/lib/Net.Compression/vnlib_compress/util.h @@ -30,6 +30,8 @@ * will be enabled when heapapi.h is included. */ #ifdef VNLIB_CUSTOM_MALLOC_ENABLE + /* Since static linking ie snabled, heapapi must have extern symbol not dllimport */ + #define VNLIB_HEAP_API extern #include <NativeHeapApi.h> #endif @@ -37,32 +39,28 @@ #define IS_WINDOWS #endif -/* If not Windows, define inline */ -#ifndef IS_WINDOWS - #ifndef inline - #define inline __inline__ - #endif // !inline -#endif // !IS_WINDOWS - -/* If not Windows, define inline */ -#ifndef IS_WINDOWS - #ifndef inline - #define inline __inline__ - #endif // !inline -#endif // !IS_WINDOWS - -//NULL +#if defined(IS_WINDOWS) || defined(inline) || defined(__clang__) + #define _cp_fn_inline inline +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 allows usage of inline keyword */ + #define _cp_fn_inline inline +#elif defined(__GNUC__) || defined(__GNUG__) + #define _cp_fn_inline __inline__ +#else + #define _cp_fn_inline + #pragma message("Warning: No inline keyword defined for this compiler") +#endif + #ifndef NULL #define NULL ((void*)0) -#endif // !NULL +#endif /* !NULL */ #ifndef TRUE #define TRUE 1 -#endif // !TRUE +#endif /* !TRUE */ #ifndef FALSE #define FALSE 0 -#endif // !FALSE +#endif /* !FALSE */ /* * Add debug runtime assertions @@ -76,6 +74,9 @@ #define CHECK_NULL_PTR(ptr) if(!ptr) return ERR_INVALID_PTR; #ifdef NATIVE_HEAP_API /* Defined in the NativeHeapApi */ + + #include <stddef.h> + /* * Add overrides for malloc, calloc, and free that use * the nativeheap api to allocate memory @@ -84,23 +85,32 @@ * api consistency. */ - static inline void* vnmalloc(size_t num, size_t size) + static _cp_fn_inline void* vnmalloc(size_t num, size_t size) { return heapAlloc(heapGetSharedHeapHandle(), num, size, FALSE); } - static inline void* vncalloc(size_t num, size_t size) + static _cp_fn_inline void* vncalloc(size_t num, size_t size) { return heapAlloc(heapGetSharedHeapHandle(), num, size, TRUE); } - static inline void vnfree(void* ptr) + static _cp_fn_inline void vnfree(void* ptr) { + #ifdef DEBUG + ERRNO result; result = heapFree(heapGetSharedHeapHandle(), ptr); - //track failed free results + /* track failed free results */ assert(result > 0); + + #else + + heapFree(heapGetSharedHeapHandle(), ptr); + + #endif + } #else @@ -125,6 +135,6 @@ */ #define vncalloc(num, size) calloc(num, size) -#endif // NATIVE_HEAP_API +#endif /* NATIVE_HEAP_API */ #endif /* !UTIL_H_ */
\ No newline at end of file diff --git a/lib/Utils.Memory/NativeHeapApi/src/NativeHeapApi.h b/lib/Utils.Memory/NativeHeapApi/src/NativeHeapApi.h index 6a994b2..1738d19 100644 --- a/lib/Utils.Memory/NativeHeapApi/src/NativeHeapApi.h +++ b/lib/Utils.Memory/NativeHeapApi/src/NativeHeapApi.h @@ -5,13 +5,13 @@ * Package: NativeHeapApi * File: NativeHeapApi.h * -* This library is free software; you can redistribute it and/or +* This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License -* as published by the Free Software Foundation; either version 2.1 -* of the License, or (at your option) any later version. +* as published by the Free Software Foundation; either version 2.1 +* of the License, or (at your option) any later version. * -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * @@ -30,78 +30,60 @@ #define _P_IS_WINDOWS #endif -//Set api export calling convention (allow used to override) +/* Set api export calling convention (allow used to override) */ #ifndef VNLIB_CC #ifdef _P_IS_WINDOWS - //STD for importing to other languages such as .NET - #define VNLIB_CC __stdcall + /* STD for importing to other languages such as.NET */ + #define VNLIB_CC __stdcall #else #define VNLIB_CC #endif -#endif // !NC_CC +#endif /* !VNLIB_CC */ -#ifndef VNLIB_EXPORT //Allow users to disable the export/impoty macro if using source code directly +#ifndef VNLIB_HEAP_API /* Allow users to disable the export/impoty macro if using source code directly */ #ifdef VNLIB_EXPORTING #ifdef _P_IS_WINDOWS #define VNLIB_HEAP_API __declspec(dllexport) #else #define VNLIB_HEAP_API __attribute__((visibility("default"))) - #endif // _NC_IS_WINDOWS + #endif /* _P_IS_WINDOWS */ #else #ifdef _P_IS_WINDOWS #define VNLIB_HEAP_API __declspec(dllimport) #else #define VNLIB_HEAP_API - #endif // _P_IS_WINDOWS - #endif // !VNLIB_EXPORTING -#endif // !VNLIB_EXPORT + #endif /* _P_IS_WINDOWS */ + #endif /* !VNLIB_EXPORTING */ +#endif /* !VNLIB_EXPORT */ -/// <summary> -/// Internal heap creation flags passed to the creation method by the library loader -/// </summary> +/* Internal heap creation flags passed to the creation method by the library loader */ typedef enum HeapCreationFlags { - /// <summary> - /// Default/no flags - /// </summary> + /* Default/no flags */ HEAP_CREATION_NO_FLAGS, - /// <summary> - /// Specifies that all allocations be zeroed before returning to caller - /// </summary> + /* Specifies that all allocations be zeroed before returning to caller */ HEAP_CREATION_GLOBAL_ZERO = 0x01, - /// <summary> - /// Specifies that the heap should use internal locking, aka its not thread safe - /// and needs to be made thread safe - /// </summary> + /* Specifies that the heap should use internal locking, aka its not thread safe + and needs to be made thread safe */ HEAP_CREATION_SERIALZE_ENABLED = 0x02, - /// <summary> - /// Specifies that the requested heap will be a shared heap for the process/library - /// </summary> + /* Specifies that the requested heap will be a shared heap for the process/library */ HEAP_CREATION_IS_SHARED = 0x04, - /// <summary> - /// Specifies that the heap will support block reallocation - /// </summary> - HEAP_CREATION_SUPPORTS_REALLOC = 0x08, + /* Specifies that the heap will support block reallocation */ + HEAP_CREATION_SUPPORTS_REALLOC = 0x08 } HeapCreationFlags; #ifdef _P_IS_WINDOWS - typedef void* LPVOID; -#endif // !WIN32 +typedef void* LPVOID; +#endif /* !WIN32 */ -/// <summary> -/// The vnlib ERRNO type, integer/process dependent, -/// internally represented as a pointer -/// </summary> +/* The vnlib ERRNO type, integer/process dependent, +internally represented as a pointer */ typedef void* ERRNO; -/// <summary> -/// A pointer to a heap structure that was stored during heap creation -/// </summary> +/* A pointer to a heap structure that was stored during heap creation */ typedef void* HeapHandle; -/// <summary> -/// A structure for heap initialization -/// </summary> +/* A structure for heap initialization */ typedef struct UnmanagedHeapDescriptor { HeapHandle HeapPointer; @@ -109,56 +91,60 @@ typedef struct UnmanagedHeapDescriptor HeapCreationFlags CreationFlags; } UnmanagedHeapDescriptor; -/// <summary> -/// Gets the shared heap handle for the process/library -/// </summary> -/// <returns>A pointer to the shared heap</returns> +/* Gets the shared heap handle for the process/library +Returns: A pointer to the shared heap +*/ VNLIB_HEAP_API HeapHandle VNLIB_CC heapGetSharedHeapHandle(void); -/// <summary> -/// The heap creation method. You must set the flags->HeapPointer = your heap -/// structure -/// </summary> -/// <param name="flags">Creation flags passed by the caller to create the heap. This structure will be initialized, and may be modified</param> -/// <returns>A boolean value that indicates the result of the operation</returns> +/* The heap creation method. You must set the flags->HeapPointer = your heap +structure. +Parameters: + flags - Creation flags passed by the caller to create the heap. This structure will be initialized, and may be modified +Returns: A boolean value that indicates the result of the operation +*/ VNLIB_HEAP_API ERRNO VNLIB_CC heapCreate(UnmanagedHeapDescriptor* flags); -/// <summary> -/// Destroys a previously created heap -/// </summary> -/// <param name="heap">The pointer to your custom heap structure from heap creation</param> +/* Destroys a previously created heap +Parameters: + heap - The pointer to your custom heap structure from heap creation +*/ VNLIB_HEAP_API ERRNO VNLIB_CC heapDestroy(HeapHandle heap); -/// <summary> -/// Allocates a block from the desired heap and returns a pointer -/// to the block. Optionally zeros the block before returning -/// </summary> -/// <param name="heap">A pointer to your heap structure</param> -/// <param name="elements">The number of elements to allocate</param> -/// <param name="alignment">The alignment (or size) of each element in bytes</param> -/// <param name="zero">A flag to zero the block before returning the block</param> -/// <returns>A pointer to the allocated block</returns> +/* Allocates a block from the desired heap and returns a pointer +to the block. Optionally zeros the block before returning + +Parameters: + heap - A pointer to your heap structure + elements - The number of elements to allocate + alignment - The alignment (or size) of each element in bytes + zero - A flag to zero the block before returning the block + +Returns: A pointer to the allocated block +*/ VNLIB_HEAP_API void* VNLIB_CC heapAlloc(HeapHandle heap, uint64_t elements, uint64_t alignment, int zero); -/// <summary> -/// Reallocates a block on the desired heap and returns a pointer to the new block. If reallocation -/// is not supported, you should only return 0 and leave the block unmodified. The data in the valid -/// size of the block MUST remain unmodified. -/// </summary> -/// <param name="heap">A pointer to your heap structure</param> -/// <param name="block">A pointer to the block to reallocate</param> -/// <param name="elements">The new size of the block, in elements</param> -/// <param name="alignment">The element size or block alignment</param> -/// <param name="zero">A flag to zero the block (or the new size) before returning.</param> -/// <returns>A pointer to the reallocated block, or zero if the operation failed or is not supported</returns> +/* Reallocates a block on the desired heap and returns a pointer to the new block. If reallocation +is not supported, you should only return 0 and leave the block unmodified. The data in the valid +size of the block MUST remain unmodified. + +Parameters: + heap - A pointer to your heap structure + block - A pointer to the block to reallocate + elements - The new size of the block, in elements + alignment - The element size or block alignment + zero - A flag to zero the block (or the new size) before returning. + +Returns: A pointer to the reallocated block, or zero if the operation failed or is not supported +*/ VNLIB_HEAP_API void* VNLIB_CC heapRealloc(HeapHandle heap, void* block, uint64_t elements, uint64_t alignment, int zero); -/// <summary> -/// Frees a previously allocated block on the desired heap. -/// </summary> -/// <param name="heap">A pointer to your heap structure</param> -/// <param name="block">A pointer to the block to free</param> -/// <returns>A value that indicates the result of the operation, nonzero if success, 0 if a failure occurred </returns> +/* Frees a previously allocated block on the desired heap. +Parameters: + heap - A pointer to your heap structure + block - A pointer to the block to free + +Returns: A value that indicates the result of the operation, nonzero if success, 0 if a failure occurred +*/ VNLIB_HEAP_API ERRNO VNLIB_CC heapFree(HeapHandle heap, void* block); -#endif // !NATIVE_HEAP_API
\ No newline at end of file +#endif /* !NATIVE_HEAP_API */ diff --git a/lib/Utils.Memory/vnlib_mimalloc/CMakeLists.txt b/lib/Utils.Memory/vnlib_mimalloc/CMakeLists.txt index f1ef4b9..4a2a946 100644 --- a/lib/Utils.Memory/vnlib_mimalloc/CMakeLists.txt +++ b/lib/Utils.Memory/vnlib_mimalloc/CMakeLists.txt @@ -1,6 +1,18 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.10) project(vnlib_mimalloc C) +set(CMAKE_PROJECT_NAME "vnlib_mimalloc") + +option(ENABLE_GREEDY "Enable greedy allocator configuration" ON) +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The build configuration type") + +#Setup the compiler options +set(CMAKE_C_STANDARD 11) #c11 is required for mimalloc static assertions +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) #enable position independent code (for shared libraries with exports) + +string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) +message(STATUS "Build type is '${build_type}'") #export header files to the main project file(GLOB HEADERS *.h) @@ -8,12 +20,8 @@ file(GLOB HEADERS *.h) #Add indepednent source files to the project file(GLOB VNLIB_MIMALLOC_SOURCES *.c) -#set options for greedy allocator defaults -option(ENABLE_GREEDY "Enable greedy allocator configuration" ON) - #create my shared library add_library(${CMAKE_PROJECT_NAME} SHARED ${VNLIB_MIMALLOC_SOURCES} ${HEADERS}) -#also create static library add_library(${CMAKE_PROJECT_NAME}_static STATIC ${VNLIB_MIMALLOC_SOURCES} ${HEADERS}) #if on unix lib will be appended, so we can adjust @@ -21,42 +29,22 @@ if(UNIX) set_target_properties(${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_NAME}_static PROPERTIES OUTPUT_NAME vn_mimalloc) endif() -#Setup the compiler options -set(CMAKE_C_STANDARD 90) -set(CMAKE_C_STANDARD_REQUIRED ON) - -#enable position independent code (for shared libraries with exports) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'") - -#if debug -add_compile_definitions($<$<CONFIG:Debug>:DEBUG>) - -if(ENABLE_GREEDY) - add_compile_definitions(VNLIB_MIMALLOC_GREEDY) -endif() - #setup flags for windows compilation if(MSVC) - - #global windows cl flags - add_compile_options( - /Qspectre - /sdl - /TC - /GS - /machine:x64 - - $<$<CONFIG:Debug>:/FC> - $<$<CONFIG:Debug>:/showIncludes> - ) + + #if debug + target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:DEBUG>) #only target our project target_compile_options( ${CMAKE_PROJECT_NAME} PRIVATE + /Qspectre + /sdl + /TC + /GS + #disable warnings for struct padding and spectre mitigation wuen WX is enabled $<$<CONFIG:Debug>:/wd5045> $<$<CONFIG:Debug>:/wd4820> @@ -69,10 +57,15 @@ if(MSVC) $<$<CONFIG:Debug>:/WX> #warnings as errors (only for our project) $<$<CONFIG:Debug>:/Zi> $<$<CONFIG:Debug>:/Zo> + $<$<CONFIG:Debug>:/FC> + $<$<CONFIG:Debug>:/showIncludes> ) #set build macros - add_compile_definitions( + target_compile_definitions( + ${CMAKE_PROJECT_NAME} + PRIVATE + $<$<CONFIG:DEBUG>:DEBUG> $<$<CONFIG:RELEASE>:RELEASE> ) @@ -80,65 +73,55 @@ if(MSVC) #configure gcc flags elseif(CMAKE_COMPILER_IS_GNUCC) - add_compile_options( - -Wextra - -fstack-protector - - $<$<CONFIG:Debug>:-g> - $<$<CONFIG:Debug>:-Og> - $<$<CONFIG:Debug>:-Wall> - $<$<CONFIG:Debug>:-Werror> - ) - - #only target our project - target_compile_options( + target_compile_options( ${CMAKE_PROJECT_NAME} PRIVATE - $<$<CONFIG:Debug>:-Wall> - $<$<CONFIG:Debug>:-pedantic> - ) -endif() - -#include mimalloc headers -include_directories(vendor/include) - -if(MSVC) - - #find the mimalloc static library for windows builds - find_library(VNLIB_MIMALLOC_DEBUG_LIB - NAMES mimalloc-static - PATHS vendor/build/Debug - ) - - find_library(VNLIB_MIMALLOC_RELEASE_LIB - NAMES mimalloc-static - PATHS vendor/build/Release + -Wextra + -fstack-protector ) - #target static libraries for all configs - target_link_libraries(${CMAKE_PROJECT_NAME} - $<$<CONFIG:Debug>:${VNLIB_MIMALLOC_DEBUG_LIB}> - #set release for all release configs - $<$<CONFIG:MinSizeRel>:${VNLIB_MIMALLOC_RELEASE_LIB}> - $<$<CONFIG:RelWithDepInfo>:${VNLIB_MIMALLOC_RELEASE_LIB}> - $<$<CONFIG:Release>:${VNLIB_MIMALLOC_RELEASE_LIB}> - ) + #enable debug compiler options + if(build_type STREQUAL "debug") + target_compile_options( + ${CMAKE_PROJECT_NAME} + PRIVATE -elseif(UNIX) + -g #enable debugger info + -Og #disable optimizations + -Wall #enable all warnings + -Werror #treat warnings as errors + -pedantic #enable pedantic mode + ) - #find the mimalloc library for unix builds - find_library(VNLIB_MIMALLOC_LIB - NAMES mimalloc - PATHS vendor/build - ) + target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE DEBUG) - #add the mimalloc library to the project - target_link_libraries(${CMAKE_PROJECT_NAME} ${VNLIB_MIMALLOC_LIB}) + endif() else() + message(FATAL_ERROR "Unsupported compiler, sorry. Submit an issue for your platform and I'll work on it :)") +endif() - #failure - message(FATAL_ERROR "Unsupported platform configuration for mimalloc library") -endif()
\ No newline at end of file +#include mimalloc headers +include_directories(vendor/include) + +################################## +# # +# Include mimalloc library # +# # +################################## + +set(MI_BUILD_TESTS OFF) +set(MI_BUILD_STATIC ON) +set(MI_BUILD_SHARED OFF) +set(MI_OVERRIDE OFF) +set(MI_WIN_REDIRECT OFF) + +add_subdirectory( + ${CMAKE_CURRENT_SOURCE_DIR}/vendor + ${CMAKE_CURRENT_BINARY_DIR}/mimalloc +) + +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE mimalloc-static) +target_link_libraries(${CMAKE_PROJECT_NAME}_static PRIVATE mimalloc-static) diff --git a/lib/Utils.Memory/vnlib_mimalloc/NativeHeapApi.h b/lib/Utils.Memory/vnlib_mimalloc/NativeHeapApi.h index 6a994b2..1738d19 100644 --- a/lib/Utils.Memory/vnlib_mimalloc/NativeHeapApi.h +++ b/lib/Utils.Memory/vnlib_mimalloc/NativeHeapApi.h @@ -5,13 +5,13 @@ * Package: NativeHeapApi * File: NativeHeapApi.h * -* This library is free software; you can redistribute it and/or +* This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License -* as published by the Free Software Foundation; either version 2.1 -* of the License, or (at your option) any later version. +* as published by the Free Software Foundation; either version 2.1 +* of the License, or (at your option) any later version. * -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * @@ -30,78 +30,60 @@ #define _P_IS_WINDOWS #endif -//Set api export calling convention (allow used to override) +/* Set api export calling convention (allow used to override) */ #ifndef VNLIB_CC #ifdef _P_IS_WINDOWS - //STD for importing to other languages such as .NET - #define VNLIB_CC __stdcall + /* STD for importing to other languages such as.NET */ + #define VNLIB_CC __stdcall #else #define VNLIB_CC #endif -#endif // !NC_CC +#endif /* !VNLIB_CC */ -#ifndef VNLIB_EXPORT //Allow users to disable the export/impoty macro if using source code directly +#ifndef VNLIB_HEAP_API /* Allow users to disable the export/impoty macro if using source code directly */ #ifdef VNLIB_EXPORTING #ifdef _P_IS_WINDOWS #define VNLIB_HEAP_API __declspec(dllexport) #else #define VNLIB_HEAP_API __attribute__((visibility("default"))) - #endif // _NC_IS_WINDOWS + #endif /* _P_IS_WINDOWS */ #else #ifdef _P_IS_WINDOWS #define VNLIB_HEAP_API __declspec(dllimport) #else #define VNLIB_HEAP_API - #endif // _P_IS_WINDOWS - #endif // !VNLIB_EXPORTING -#endif // !VNLIB_EXPORT + #endif /* _P_IS_WINDOWS */ + #endif /* !VNLIB_EXPORTING */ +#endif /* !VNLIB_EXPORT */ -/// <summary> -/// Internal heap creation flags passed to the creation method by the library loader -/// </summary> +/* Internal heap creation flags passed to the creation method by the library loader */ typedef enum HeapCreationFlags { - /// <summary> - /// Default/no flags - /// </summary> + /* Default/no flags */ HEAP_CREATION_NO_FLAGS, - /// <summary> - /// Specifies that all allocations be zeroed before returning to caller - /// </summary> + /* Specifies that all allocations be zeroed before returning to caller */ HEAP_CREATION_GLOBAL_ZERO = 0x01, - /// <summary> - /// Specifies that the heap should use internal locking, aka its not thread safe - /// and needs to be made thread safe - /// </summary> + /* Specifies that the heap should use internal locking, aka its not thread safe + and needs to be made thread safe */ HEAP_CREATION_SERIALZE_ENABLED = 0x02, - /// <summary> - /// Specifies that the requested heap will be a shared heap for the process/library - /// </summary> + /* Specifies that the requested heap will be a shared heap for the process/library */ HEAP_CREATION_IS_SHARED = 0x04, - /// <summary> - /// Specifies that the heap will support block reallocation - /// </summary> - HEAP_CREATION_SUPPORTS_REALLOC = 0x08, + /* Specifies that the heap will support block reallocation */ + HEAP_CREATION_SUPPORTS_REALLOC = 0x08 } HeapCreationFlags; #ifdef _P_IS_WINDOWS - typedef void* LPVOID; -#endif // !WIN32 +typedef void* LPVOID; +#endif /* !WIN32 */ -/// <summary> -/// The vnlib ERRNO type, integer/process dependent, -/// internally represented as a pointer -/// </summary> +/* The vnlib ERRNO type, integer/process dependent, +internally represented as a pointer */ typedef void* ERRNO; -/// <summary> -/// A pointer to a heap structure that was stored during heap creation -/// </summary> +/* A pointer to a heap structure that was stored during heap creation */ typedef void* HeapHandle; -/// <summary> -/// A structure for heap initialization -/// </summary> +/* A structure for heap initialization */ typedef struct UnmanagedHeapDescriptor { HeapHandle HeapPointer; @@ -109,56 +91,60 @@ typedef struct UnmanagedHeapDescriptor HeapCreationFlags CreationFlags; } UnmanagedHeapDescriptor; -/// <summary> -/// Gets the shared heap handle for the process/library -/// </summary> -/// <returns>A pointer to the shared heap</returns> +/* Gets the shared heap handle for the process/library +Returns: A pointer to the shared heap +*/ VNLIB_HEAP_API HeapHandle VNLIB_CC heapGetSharedHeapHandle(void); -/// <summary> -/// The heap creation method. You must set the flags->HeapPointer = your heap -/// structure -/// </summary> -/// <param name="flags">Creation flags passed by the caller to create the heap. This structure will be initialized, and may be modified</param> -/// <returns>A boolean value that indicates the result of the operation</returns> +/* The heap creation method. You must set the flags->HeapPointer = your heap +structure. +Parameters: + flags - Creation flags passed by the caller to create the heap. This structure will be initialized, and may be modified +Returns: A boolean value that indicates the result of the operation +*/ VNLIB_HEAP_API ERRNO VNLIB_CC heapCreate(UnmanagedHeapDescriptor* flags); -/// <summary> -/// Destroys a previously created heap -/// </summary> -/// <param name="heap">The pointer to your custom heap structure from heap creation</param> +/* Destroys a previously created heap +Parameters: + heap - The pointer to your custom heap structure from heap creation +*/ VNLIB_HEAP_API ERRNO VNLIB_CC heapDestroy(HeapHandle heap); -/// <summary> -/// Allocates a block from the desired heap and returns a pointer -/// to the block. Optionally zeros the block before returning -/// </summary> -/// <param name="heap">A pointer to your heap structure</param> -/// <param name="elements">The number of elements to allocate</param> -/// <param name="alignment">The alignment (or size) of each element in bytes</param> -/// <param name="zero">A flag to zero the block before returning the block</param> -/// <returns>A pointer to the allocated block</returns> +/* Allocates a block from the desired heap and returns a pointer +to the block. Optionally zeros the block before returning + +Parameters: + heap - A pointer to your heap structure + elements - The number of elements to allocate + alignment - The alignment (or size) of each element in bytes + zero - A flag to zero the block before returning the block + +Returns: A pointer to the allocated block +*/ VNLIB_HEAP_API void* VNLIB_CC heapAlloc(HeapHandle heap, uint64_t elements, uint64_t alignment, int zero); -/// <summary> -/// Reallocates a block on the desired heap and returns a pointer to the new block. If reallocation -/// is not supported, you should only return 0 and leave the block unmodified. The data in the valid -/// size of the block MUST remain unmodified. -/// </summary> -/// <param name="heap">A pointer to your heap structure</param> -/// <param name="block">A pointer to the block to reallocate</param> -/// <param name="elements">The new size of the block, in elements</param> -/// <param name="alignment">The element size or block alignment</param> -/// <param name="zero">A flag to zero the block (or the new size) before returning.</param> -/// <returns>A pointer to the reallocated block, or zero if the operation failed or is not supported</returns> +/* Reallocates a block on the desired heap and returns a pointer to the new block. If reallocation +is not supported, you should only return 0 and leave the block unmodified. The data in the valid +size of the block MUST remain unmodified. + +Parameters: + heap - A pointer to your heap structure + block - A pointer to the block to reallocate + elements - The new size of the block, in elements + alignment - The element size or block alignment + zero - A flag to zero the block (or the new size) before returning. + +Returns: A pointer to the reallocated block, or zero if the operation failed or is not supported +*/ VNLIB_HEAP_API void* VNLIB_CC heapRealloc(HeapHandle heap, void* block, uint64_t elements, uint64_t alignment, int zero); -/// <summary> -/// Frees a previously allocated block on the desired heap. -/// </summary> -/// <param name="heap">A pointer to your heap structure</param> -/// <param name="block">A pointer to the block to free</param> -/// <returns>A value that indicates the result of the operation, nonzero if success, 0 if a failure occurred </returns> +/* Frees a previously allocated block on the desired heap. +Parameters: + heap - A pointer to your heap structure + block - A pointer to the block to free + +Returns: A value that indicates the result of the operation, nonzero if success, 0 if a failure occurred +*/ VNLIB_HEAP_API ERRNO VNLIB_CC heapFree(HeapHandle heap, void* block); -#endif // !NATIVE_HEAP_API
\ No newline at end of file +#endif /* !NATIVE_HEAP_API */ diff --git a/lib/Utils.Memory/vnlib_mimalloc/Taskfile.yaml b/lib/Utils.Memory/vnlib_mimalloc/Taskfile.yaml index e9e9153..acf8851 100644 --- a/lib/Utils.Memory/vnlib_mimalloc/Taskfile.yaml +++ b/lib/Utils.Memory/vnlib_mimalloc/Taskfile.yaml @@ -17,20 +17,16 @@ tasks: default: desc: "Builds the entire project from source code without using the VNBuild build system for target machines" cmds: - #build with defaults - - task: build - - cmd: echo "Your vnlib_mimalloc dll file can be found in '{{.USER_WORKING_DIR}}/build'" + #init cmake build with greedy enabled + - cmake -Bbuild/ -DCMAKE_BUILD_TYPE=Release -DENABLE_GREEDY=1 {{.CMAKE_ARGS}} + - cmake --build build/ --config Release + - cmd: echo "Your vnlib_mimalloc library file can be found in '{{.USER_WORKING_DIR}}/build'" silent: true build: - cmds: - #build the mimalloc library first - - cd vendor/ && cmake -B./build -DMI_BUILD_STATIC=1 {{.MIMALLOC_CMAKE_ARGS}} -DMI_BUILD_TESTS=0 -DMI_OVERRIDE=0 -DMI_WIN_REDIRECT=0 - - cd vendor/ && cmake --build build/ --config Debug - - cd vendor/ && cmake --build build/ --config Release - + cmds: #build our library - - cmake -B./build -DENABLE_GREEDY=1 {{.CMAKE_ARGS}} + - cmake -B./build -DENABLE_GREEDY=1 {{.CMAKE_ARGS}} - cmake --build build/ --config Debug - cmake --build build/ --config Release @@ -80,9 +76,8 @@ tasks: clean: ignore_error: true - cmds: - - cmd: powershell -Command "Remove-Item -Recurse './bin'" - - cmd: powershell -Command "Remove-Item -Recurse './build'" - - cmd: powershell -Command "Remove-Item -Recurse '../mimalloc/build'" + cmds: + - for: [ bin/, build/ ] + cmd: powershell Remove-Item -Recurse '{{.ITEM}}' -Force
\ No newline at end of file diff --git a/lib/Utils.Memory/vnlib_rpmalloc/CMakeLists.txt b/lib/Utils.Memory/vnlib_rpmalloc/CMakeLists.txt index 5e04d03..706050c 100644 --- a/lib/Utils.Memory/vnlib_rpmalloc/CMakeLists.txt +++ b/lib/Utils.Memory/vnlib_rpmalloc/CMakeLists.txt @@ -1,6 +1,18 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.10) project(vnlib_rpmalloc C) +set(CMAKE_PROJECT_NAME "vnlib_rpmalloc") + +option(ENABLE_GREEDY "Enable greedy allocator configuration" ON) +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The build configuration type") + +#Setup the compiler options +set(CMAKE_C_STANDARD 11) #c11 is required for rpmalloc static assertions +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) #enable position independent code (for shared libraries with exports) + +string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) +message(STATUS "Build type is '${build_type}'") #export header files to the main project file(GLOB HEADERS *.h) @@ -14,12 +26,8 @@ set(VNLIB_RPMALLOC_SOURCES #add rpmalloc includes, there will only be one library include_directories(vendor) -#set options for greedy allocator defaults -option(ENABLE_GREEDY "Enable greedy allocator configuration" ON) - -#create my shared library +#create shared/static libs add_library(${CMAKE_PROJECT_NAME} SHARED ${VNLIB_RPMALLOC_SOURCES} ${HEADERS}) -#also create static library add_library(${CMAKE_PROJECT_NAME}_static STATIC ${VNLIB_RPMALLOC_SOURCES} ${HEADERS}) #if on unix lib will be appended, so we can adjust @@ -27,43 +35,17 @@ if(UNIX) set_target_properties(${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_NAME}_static PROPERTIES OUTPUT_NAME vn_rpmalloc) endif() -#Setup the compiler options -set(CMAKE_C_STANDARD 90) -set(CMAKE_C_STANDARD_REQUIRED ON) - -#enable position independent code (for shared libraries with exports) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'") - -#if debug -add_compile_definitions($<$<CONFIG:Debug>:DEBUG>) - -if(ENABLE_GREEDY) - add_compile_definitions(VNLIB_RPMALLOC_GREEDY) -endif() #setup flags for windows compilation if(MSVC) - - #global windows cl flags + add_compile_options( /Qspectre /sdl /TC /GS - /machine:x64 - - $<$<CONFIG:Debug>:/FC> - $<$<CONFIG:Debug>:/showIncludes> - ) - #only target our project - target_compile_options( - ${CMAKE_PROJECT_NAME} - PRIVATE - - #disable warnings for struct padding and spectre mitigation wuen WX is enabled + #disable warnings for struct padding and spectre mitigation when WX is enabled $<$<CONFIG:Debug>:/wd5045> $<$<CONFIG:Debug>:/wd4820> $<$<CONFIG:Debug>:/wd4574> @@ -72,13 +54,14 @@ if(MSVC) $<$<CONFIG:Debug>:/options:strict> #disable warnings for struct padding and spectre mitigation wuen WX is enabled $<$<CONFIG:Debug>:/Wall> - $<$<CONFIG:Debug>:/WX> #warnings as errors (only for our project) - $<$<CONFIG:Debug>:/Zi> - $<$<CONFIG:Debug>:/Zo> + $<$<CONFIG:Debug>:/WX> #warnings as errors (only for our project) + $<$<CONFIG:Debug>:/Zi> #enable debug info + $<$<CONFIG:Debug>:/Zo> + $<$<CONFIG:Debug>:/FC> #full path in diagnostics + $<$<CONFIG:Debug>:/showIncludes> ) - #set build macros - add_compile_definitions( + add_compile_definitions( $<$<CONFIG:DEBUG>:DEBUG> $<$<CONFIG:RELEASE>:RELEASE> ) @@ -89,52 +72,57 @@ elseif(CMAKE_COMPILER_IS_GNUCC) add_compile_options( -Wextra -fstack-protector - - $<$<CONFIG:Debug>:-g> - $<$<CONFIG:Debug>:-Og> - $<$<CONFIG:Debug>:-Wall> - $<$<CONFIG:Debug>:-Werror> ) - #only target our project - target_compile_options( - ${CMAKE_PROJECT_NAME} - PRIVATE - $<$<CONFIG:Debug>:-Wall> - $<$<CONFIG:Debug>:-pedantic> - ) + #enable debug compiler options + if(build_type STREQUAL "debug") + add_compile_options( + -g #enable debugger info + -Og #disable optimizations + -Wall #enable all warnings + -Werror #treat warnings as errors + -pedantic #enable pedantic mode + ) + endif() +else() + message(FATAL_ERROR "Unsupported compiler, sorry. Submit an issue for your platform and I'll work on it :)") endif() #enable required features -add_definitions(-DRPMALLOC_FIRST_CLASS_HEAPS=1) -add_definitions(-DENABLE_ADAPTIVE_THREAD_CACHE=1) +add_compile_definitions( + RPMALLOC_FIRST_CLASS_HEAPS=1 + ENABLE_ADAPTIVE_THREAD_CACHE=1 -#add some debugging/tracing for debug mode -add_compile_definitions($<$<CONFIG:Debug>:ENABLE_VALIDATE_ARGS=1>) -add_compile_definitions($<$<CONFIG:Debug>:ENABLE_ASSERTS=1>) + #add some debugging/tracing for debug mode + $<$<CONFIG:Debug>:ENABLE_TRACE=1> + $<$<CONFIG:Debug>:ENABLE_VALIDATE_ARGS=1> +) if(ENABLE_GREEDY) -#if greedy is enabled, add greedy options -add_definitions(-DENABLE_UNLIMITED_CACHE=1) -add_definitions(-DENABLE_UNLIMITED_GLOBAL_CACHE=1) -add_definitions(-DENABLE_UNLIMITED_THREAD_CACHE=1) + add_compile_definitions( + #if greedy is enabled, add greedy options + ENABLE_UNLIMITED_CACHE=1 + ENABLE_UNLIMITED_GLOBAL_CACHE=1 + ENABLE_UNLIMITED_THREAD_CACHE=1 -#On by default but we otherwise disable global cache to really reduce commited size -add_definitions(-DENABLE_GLOBAL_CACHE=1) -add_definitions(-DENABLE_UNLIMITED_GLOBAL_CACHE=1) + #On by default but we otherwise disable global cache to really reduce commited size + ENABLE_GLOBAL_CACHE=1 + ENABLE_UNLIMITED_GLOBAL_CACHE=1 + ) else() -#disable greedy definitions -add_definitions(-DENABLE_UNLIMITED_CACHE 0) -add_definitions(-DENABLE_UNLIMITED_GLOBAL_CACHE=0) -add_definitions(-DENABLE_UNLIMITED_THREAD_CACHE=0) -add_definitions(-DENABLE_GLOBAL_CACHE=0) + add_compile_definitions( + #disable greedy definitions + ENABLE_UNLIMITED_CACHE=0 + ENABLE_UNLIMITED_GLOBAL_CACHE=0 + ENABLE_UNLIMITED_THREAD_CACHE=0 + ENABLE_GLOBAL_CACHE=0 -#also disable unlimited global cache to release spans to OS -add_definitions(-DENABLE_UNLIMITED_GLOBAL_CACHE=0) + #also disable unlimited global cache to release spans to OS + ENABLE_UNLIMITED_GLOBAL_CACHE=0 + ) endif() - diff --git a/lib/Utils.Memory/vnlib_rpmalloc/NativeHeapApi.h b/lib/Utils.Memory/vnlib_rpmalloc/NativeHeapApi.h index 6a994b2..1738d19 100644 --- a/lib/Utils.Memory/vnlib_rpmalloc/NativeHeapApi.h +++ b/lib/Utils.Memory/vnlib_rpmalloc/NativeHeapApi.h @@ -5,13 +5,13 @@ * Package: NativeHeapApi * File: NativeHeapApi.h * -* This library is free software; you can redistribute it and/or +* This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License -* as published by the Free Software Foundation; either version 2.1 -* of the License, or (at your option) any later version. +* as published by the Free Software Foundation; either version 2.1 +* of the License, or (at your option) any later version. * -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * @@ -30,78 +30,60 @@ #define _P_IS_WINDOWS #endif -//Set api export calling convention (allow used to override) +/* Set api export calling convention (allow used to override) */ #ifndef VNLIB_CC #ifdef _P_IS_WINDOWS - //STD for importing to other languages such as .NET - #define VNLIB_CC __stdcall + /* STD for importing to other languages such as.NET */ + #define VNLIB_CC __stdcall #else #define VNLIB_CC #endif -#endif // !NC_CC +#endif /* !VNLIB_CC */ -#ifndef VNLIB_EXPORT //Allow users to disable the export/impoty macro if using source code directly +#ifndef VNLIB_HEAP_API /* Allow users to disable the export/impoty macro if using source code directly */ #ifdef VNLIB_EXPORTING #ifdef _P_IS_WINDOWS #define VNLIB_HEAP_API __declspec(dllexport) #else #define VNLIB_HEAP_API __attribute__((visibility("default"))) - #endif // _NC_IS_WINDOWS + #endif /* _P_IS_WINDOWS */ #else #ifdef _P_IS_WINDOWS #define VNLIB_HEAP_API __declspec(dllimport) #else #define VNLIB_HEAP_API - #endif // _P_IS_WINDOWS - #endif // !VNLIB_EXPORTING -#endif // !VNLIB_EXPORT + #endif /* _P_IS_WINDOWS */ + #endif /* !VNLIB_EXPORTING */ +#endif /* !VNLIB_EXPORT */ -/// <summary> -/// Internal heap creation flags passed to the creation method by the library loader -/// </summary> +/* Internal heap creation flags passed to the creation method by the library loader */ typedef enum HeapCreationFlags { - /// <summary> - /// Default/no flags - /// </summary> + /* Default/no flags */ HEAP_CREATION_NO_FLAGS, - /// <summary> - /// Specifies that all allocations be zeroed before returning to caller - /// </summary> + /* Specifies that all allocations be zeroed before returning to caller */ HEAP_CREATION_GLOBAL_ZERO = 0x01, - /// <summary> - /// Specifies that the heap should use internal locking, aka its not thread safe - /// and needs to be made thread safe - /// </summary> + /* Specifies that the heap should use internal locking, aka its not thread safe + and needs to be made thread safe */ HEAP_CREATION_SERIALZE_ENABLED = 0x02, - /// <summary> - /// Specifies that the requested heap will be a shared heap for the process/library - /// </summary> + /* Specifies that the requested heap will be a shared heap for the process/library */ HEAP_CREATION_IS_SHARED = 0x04, - /// <summary> - /// Specifies that the heap will support block reallocation - /// </summary> - HEAP_CREATION_SUPPORTS_REALLOC = 0x08, + /* Specifies that the heap will support block reallocation */ + HEAP_CREATION_SUPPORTS_REALLOC = 0x08 } HeapCreationFlags; #ifdef _P_IS_WINDOWS - typedef void* LPVOID; -#endif // !WIN32 +typedef void* LPVOID; +#endif /* !WIN32 */ -/// <summary> -/// The vnlib ERRNO type, integer/process dependent, -/// internally represented as a pointer -/// </summary> +/* The vnlib ERRNO type, integer/process dependent, +internally represented as a pointer */ typedef void* ERRNO; -/// <summary> -/// A pointer to a heap structure that was stored during heap creation -/// </summary> +/* A pointer to a heap structure that was stored during heap creation */ typedef void* HeapHandle; -/// <summary> -/// A structure for heap initialization -/// </summary> +/* A structure for heap initialization */ typedef struct UnmanagedHeapDescriptor { HeapHandle HeapPointer; @@ -109,56 +91,60 @@ typedef struct UnmanagedHeapDescriptor HeapCreationFlags CreationFlags; } UnmanagedHeapDescriptor; -/// <summary> -/// Gets the shared heap handle for the process/library -/// </summary> -/// <returns>A pointer to the shared heap</returns> +/* Gets the shared heap handle for the process/library +Returns: A pointer to the shared heap +*/ VNLIB_HEAP_API HeapHandle VNLIB_CC heapGetSharedHeapHandle(void); -/// <summary> -/// The heap creation method. You must set the flags->HeapPointer = your heap -/// structure -/// </summary> -/// <param name="flags">Creation flags passed by the caller to create the heap. This structure will be initialized, and may be modified</param> -/// <returns>A boolean value that indicates the result of the operation</returns> +/* The heap creation method. You must set the flags->HeapPointer = your heap +structure. +Parameters: + flags - Creation flags passed by the caller to create the heap. This structure will be initialized, and may be modified +Returns: A boolean value that indicates the result of the operation +*/ VNLIB_HEAP_API ERRNO VNLIB_CC heapCreate(UnmanagedHeapDescriptor* flags); -/// <summary> -/// Destroys a previously created heap -/// </summary> -/// <param name="heap">The pointer to your custom heap structure from heap creation</param> +/* Destroys a previously created heap +Parameters: + heap - The pointer to your custom heap structure from heap creation +*/ VNLIB_HEAP_API ERRNO VNLIB_CC heapDestroy(HeapHandle heap); -/// <summary> -/// Allocates a block from the desired heap and returns a pointer -/// to the block. Optionally zeros the block before returning -/// </summary> -/// <param name="heap">A pointer to your heap structure</param> -/// <param name="elements">The number of elements to allocate</param> -/// <param name="alignment">The alignment (or size) of each element in bytes</param> -/// <param name="zero">A flag to zero the block before returning the block</param> -/// <returns>A pointer to the allocated block</returns> +/* Allocates a block from the desired heap and returns a pointer +to the block. Optionally zeros the block before returning + +Parameters: + heap - A pointer to your heap structure + elements - The number of elements to allocate + alignment - The alignment (or size) of each element in bytes + zero - A flag to zero the block before returning the block + +Returns: A pointer to the allocated block +*/ VNLIB_HEAP_API void* VNLIB_CC heapAlloc(HeapHandle heap, uint64_t elements, uint64_t alignment, int zero); -/// <summary> -/// Reallocates a block on the desired heap and returns a pointer to the new block. If reallocation -/// is not supported, you should only return 0 and leave the block unmodified. The data in the valid -/// size of the block MUST remain unmodified. -/// </summary> -/// <param name="heap">A pointer to your heap structure</param> -/// <param name="block">A pointer to the block to reallocate</param> -/// <param name="elements">The new size of the block, in elements</param> -/// <param name="alignment">The element size or block alignment</param> -/// <param name="zero">A flag to zero the block (or the new size) before returning.</param> -/// <returns>A pointer to the reallocated block, or zero if the operation failed or is not supported</returns> +/* Reallocates a block on the desired heap and returns a pointer to the new block. If reallocation +is not supported, you should only return 0 and leave the block unmodified. The data in the valid +size of the block MUST remain unmodified. + +Parameters: + heap - A pointer to your heap structure + block - A pointer to the block to reallocate + elements - The new size of the block, in elements + alignment - The element size or block alignment + zero - A flag to zero the block (or the new size) before returning. + +Returns: A pointer to the reallocated block, or zero if the operation failed or is not supported +*/ VNLIB_HEAP_API void* VNLIB_CC heapRealloc(HeapHandle heap, void* block, uint64_t elements, uint64_t alignment, int zero); -/// <summary> -/// Frees a previously allocated block on the desired heap. -/// </summary> -/// <param name="heap">A pointer to your heap structure</param> -/// <param name="block">A pointer to the block to free</param> -/// <returns>A value that indicates the result of the operation, nonzero if success, 0 if a failure occurred </returns> +/* Frees a previously allocated block on the desired heap. +Parameters: + heap - A pointer to your heap structure + block - A pointer to the block to free + +Returns: A value that indicates the result of the operation, nonzero if success, 0 if a failure occurred +*/ VNLIB_HEAP_API ERRNO VNLIB_CC heapFree(HeapHandle heap, void* block); -#endif // !NATIVE_HEAP_API
\ No newline at end of file +#endif /* !NATIVE_HEAP_API */ diff --git a/lib/Utils.Memory/vnlib_rpmalloc/Taskfile.yaml b/lib/Utils.Memory/vnlib_rpmalloc/Taskfile.yaml index b327913..40bdc7c 100644 --- a/lib/Utils.Memory/vnlib_rpmalloc/Taskfile.yaml +++ b/lib/Utils.Memory/vnlib_rpmalloc/Taskfile.yaml @@ -16,9 +16,9 @@ tasks: default: desc: "Builds the entire project from source code without using the VNBuild build system for target machines" cmds: - #build with defaults + #build with defaults #init cmake build with greedy enabled - - cmake -Bbuild/ -DCMAKE_BUILD_TYPE=Release -DENABLE_GREEDY=1 + - cmake -Bbuild/ -DCMAKE_BUILD_TYPE=Release -DENABLE_GREEDY=1 {{.CMAKE_ARGS}} - cmake --build build/ --config Release - cmd: echo "Your vnlib_rpmalloc library file can be found in '{{.USER_WORKING_DIR}}/build'" silent: true @@ -77,9 +77,8 @@ tasks: cmds: - powershell -Command "tar --exclude build/* --exclude bin/* --exclude vendor/build/* -czf 'bin/src.tgz' ." - clean: ignore_error: true - cmds: - - cmd: powershell -Command "Remove-Item -Recurse 'bin/'" - - cmd: powershell -Command "Remove-Item -Recurse 'build/'"
\ No newline at end of file + cmds: + - for: [ bin/, build/ ] + cmd: powershell Remove-Item -Recurse '{{.ITEM}}' -Force
\ No newline at end of file diff --git a/lib/Utils.Memory/vnlib_rpmalloc/vnlib_rpmalloc.vcxitems b/lib/Utils.Memory/vnlib_rpmalloc/vnlib_rpmalloc.vcxitems index eeda4c8..44fef45 100644 --- a/lib/Utils.Memory/vnlib_rpmalloc/vnlib_rpmalloc.vcxitems +++ b/lib/Utils.Memory/vnlib_rpmalloc/vnlib_rpmalloc.vcxitems @@ -27,6 +27,7 @@ <None Include="$(MSBuildThisFileDirectory)Taskfile.yaml" /> </ItemGroup> <ItemGroup> + <ClInclude Include="$(MSBuildThisFileDirectory)NativeHeapApi.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)vendor\rpmalloc.h" /> </ItemGroup> </Project>
\ No newline at end of file |