Skip to content

Commit

Permalink
CMake option ENKITS_SANITIZE and sanitizer fixes (#127)
Browse files Browse the repository at this point in the history
 - Fixes #125
  • Loading branch information
erincatto committed Apr 26, 2024
1 parent dc795fd commit 03e6a2c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v3

- name: Configure static library
run: cmake -S . -B build-static
run: cmake -S . -B build-static -D ENKITS_SANITIZE=ON
- name: Build static library
run: cmake --build build-static --parallel
- name: Test static library
Expand All @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v3

- name: Configure static library
run: cmake -S . -B build-static
run: cmake -S . -B build-static -D ENKITS_SANITIZE=ON
- name: Build static library
run: cmake --build build-static --parallel
- name: Test static library
Expand All @@ -71,7 +71,7 @@ jobs:
- uses: actions/checkout@v3

- name: Configure static library
run: cmake -S . -B build-static
run: cmake -S . -B build-static -D ENKITS_SANITIZE=ON
- name: Build static library
run: cmake --build build-static --parallel
- name: Test static library
Expand All @@ -93,8 +93,13 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup MSVC dev command prompt
uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64

- name: Configure static library
run: cmake -S . -B build-static -G "Visual Studio 17 2022"
run: cmake -S . -B build-static -G "Visual Studio 17 2022" -D ENKITS_SANITIZE=ON
- name: Build static library
run: cmake --build build-static --parallel
- name: Test static library
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ option( ENKITS_BUILD_C_INTERFACE "Build C interface" ON )
option( ENKITS_BUILD_EXAMPLES "Build example applications" ON )
option( ENKITS_BUILD_SHARED "Build shared library" OFF )
option( ENKITS_INSTALL "Generate installation target" OFF )
option( ENKITS_SANITIZE "Build with sanitizers" OFF)

set( ENKITS_TASK_PRIORITIES_NUM "3" CACHE STRING "Number of task priorities, 1-5, 0 for defined by defaults in source" )

Expand All @@ -36,6 +37,17 @@ endif()

list( APPEND ENKITS_SRC ${ENKITS_HEADERS} )

if(ENKITS_SANITIZE)
if(MSVC)
add_compile_options(/fsanitize=address)
add_link_options(/INCREMENTAL:NO)
else()
# add_compile_options(-fsanitize=thread -fno-omit-frame-pointer)
add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined)
add_link_options(-fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined)
endif()
endif()

if( ENKITS_BUILD_SHARED )
add_library( enkiTS SHARED ${ENKITS_SRC} )
target_compile_definitions( enkiTS PRIVATE ENKITS_BUILD_DLL=1 )
Expand Down
20 changes: 10 additions & 10 deletions src/TaskScheduler_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ ENKITS_API uint32_t enkiGetNumFirstExternalTaskThread()

enkiTaskSet* enkiCreateTaskSet( enkiTaskScheduler* pETS_, enkiTaskExecuteRange taskFunc_ )
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;
enkiTaskSet* pTask = (enkiTaskSet*)customAllocator.alloc(
alignof(enkiTaskSet), sizeof(enkiTaskSet), customAllocator.userData, ENKI_FILE_AND_LINE );
new(pTask) enkiTaskSet( taskFunc_ );
Expand All @@ -216,7 +216,7 @@ enkiTaskSet* enkiCreateTaskSet( enkiTaskScheduler* pETS_, enkiTaskExecuteRange t

void enkiDeleteTaskSet( enkiTaskScheduler* pETS_, enkiTaskSet* pTaskSet_ )
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;

pTaskSet_->~enkiTaskSet();
customAllocator.free( pTaskSet_, sizeof(enkiTaskSet), customAllocator.userData, ENKI_FILE_AND_LINE );
Expand Down Expand Up @@ -300,7 +300,7 @@ int enkiIsTaskSetComplete( enkiTaskScheduler* pETS_, enkiTaskSet* pTaskSet_ )

enkiPinnedTask* enkiCreatePinnedTask(enkiTaskScheduler* pETS_, enkiPinnedTaskExecute taskFunc_, uint32_t threadNum_)
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;
enkiPinnedTask* pTask = (enkiPinnedTask*)customAllocator.alloc(
alignof(enkiPinnedTask), sizeof(enkiPinnedTask), customAllocator.userData, ENKI_FILE_AND_LINE );
new(pTask) enkiPinnedTask( taskFunc_, threadNum_ );
Expand All @@ -309,7 +309,7 @@ enkiPinnedTask* enkiCreatePinnedTask(enkiTaskScheduler* pETS_, enkiPinnedTaskExe

void enkiDeletePinnedTask( enkiTaskScheduler* pETS_, enkiPinnedTask* pPinnedTask_ )
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;

pPinnedTask_->~enkiPinnedTask();
customAllocator.free( pPinnedTask_, sizeof(enkiPinnedTask), customAllocator.userData, ENKI_FILE_AND_LINE );
Expand Down Expand Up @@ -443,7 +443,7 @@ enkiCompletable* enkiGetCompletableFromCompletionAction( enkiCompletionAction* p

enkiCompletable* enkiCreateCompletable( enkiTaskScheduler* pETS_ )
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;
enkiCompletable* pTask = (enkiCompletable*)customAllocator.alloc(
alignof(enkiCompletable), sizeof(enkiCompletable), customAllocator.userData, ENKI_FILE_AND_LINE );
new(pTask) enkiCompletable();
Expand All @@ -452,7 +452,7 @@ enkiCompletable* enkiCreateCompletable( enkiTaskScheduler* pETS_ )

void enkiDeleteCompletable( enkiTaskScheduler* pETS_, enkiCompletable* pCompletable_ )
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;

pCompletable_->~enkiCompletable();
customAllocator.free( pCompletable_, sizeof(enkiCompletable), customAllocator.userData, ENKI_FILE_AND_LINE );
Expand All @@ -470,7 +470,7 @@ void enkiWaitForCompletablePriority( enkiTaskScheduler* pETS_, enkiCompletable*

enkiDependency* enkiCreateDependency( enkiTaskScheduler* pETS_ )
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;
enkiDependency* pDep = (enkiDependency*)customAllocator.alloc(
alignof(enkiDependency), sizeof(enkiDependency), customAllocator.userData, ENKI_FILE_AND_LINE );
new(pDep) enkiDependency();
Expand All @@ -479,7 +479,7 @@ enkiDependency* enkiCreateDependency( enkiTaskScheduler* pETS_ )

void enkiDeleteDependency( enkiTaskScheduler* pETS_, enkiDependency* pDependency_ )
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;

pDependency_->~enkiDependency();
customAllocator.free( pDependency_, sizeof(enkiDependency), customAllocator.userData, ENKI_FILE_AND_LINE );
Expand All @@ -492,7 +492,7 @@ void enkiSetDependency( enkiDependency* pDependency_, enkiCompletable* pDependen

enkiCompletionAction* enkiCreateCompletionAction( enkiTaskScheduler* pETS_, enkiCompletionFunction completionFunctionPreComplete_, enkiCompletionFunction completionFunctionPostComplete_ )
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;
enkiCompletionAction* pCA = (enkiCompletionAction*)customAllocator.alloc(
alignof(enkiCompletionAction), sizeof(enkiCompletionAction), customAllocator.userData, ENKI_FILE_AND_LINE );
new(pCA) enkiCompletionAction();
Expand All @@ -503,7 +503,7 @@ enkiCompletionAction* enkiCreateCompletionAction( enkiTaskScheduler* pETS_, enki

void enkiDeleteCompletionAction( enkiTaskScheduler* pETS_, enkiCompletionAction* pCompletionAction_ )
{
const CustomAllocator& customAllocator = pETS_->GetConfig().customAllocator;
CustomAllocator customAllocator = pETS_->GetConfig().customAllocator;

pCompletionAction_->~enkiCompletionAction();
customAllocator.free( pCompletionAction_, sizeof(enkiCompletionAction), customAllocator.userData, ENKI_FILE_AND_LINE );
Expand Down

0 comments on commit 03e6a2c

Please sign in to comment.