Skip to content

Commit

Permalink
Added dependencies | Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bperkovic15 committed Jan 5, 2024
1 parent 3649e4e commit 0427844
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 26 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/gh-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: Build & Test on Ubuntu, macOS, and Windows

on:
push:
branches: [ "main" ]
branches: [ "master" ]
pull_request:
branches: [ "main" ]
branches: [ "master" ]

jobs:
build:
Expand Down Expand Up @@ -93,8 +93,8 @@ jobs:
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: >
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} &&
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --target vm_unit_tests
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} # &&
# cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --target vm_unit_tests
- name: Test
Expand Down
60 changes: 48 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ cmake_minimum_required( VERSION 3.27.0 )

project( vm )

# TODO: Fully implement

###################
##### Target ######
###################

file(GLOB_RECURSE vm_sources "${PROJECT_SOURCE_DIR}/include/*")
set(CMAKE_CXX_STANDARD 23)

# TODO: Use psiha/build cmake utils?

file( GLOB_RECURSE vm_sources "${PROJECT_SOURCE_DIR}/include/*" )
add_library( vm STATIC ${vm_sources} )
target_include_directories( vm PUBLIC "${PROJECT_SOURCE_DIR}/include/" )
target_compile_features( vm PRIVATE cxx_std_23 )

###################
###### Deps #######
Expand All @@ -24,24 +27,57 @@ file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
EXPECTED_HASH SHA256=cc155ce02e7945e7b8967ddfaff0b050e958a723ef7aad3766d368940cb15494
)
set(CPM_SOURCE_CACHE "${CMAKE_CURRENT_BINARY_DIR}/deps") # Using this ensures shallow clones
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)

# Add and link packages

# Add packages

CPMAddPackage("gh:boostorg/static_assert#boost-1.84.0") # Boost::core dependency
CPMAddPackage("gh:boostorg/throw_exception#boost-1.84.0") # Boost::core dependency
CPMAddPackage("gh:boostorg/config#boost-1.84.0") # Boost::core dependency
CPMAddPackage("gh:boostorg/io#boost-1.84.0") # Boost::utility dependency
CPMAddPackage("gh:boostorg/type_traits#boost-1.84.0") # Boost::utility dependency
CPMAddPackage("gh:boostorg/predef#boost-1.84.0") # Boost::winapi dependency
CPMAddPackage("gh:boostorg/assert#boost-1.84.0")
CPMAddPackage("gh:boostorg/core#boost-1.84.0")
CPMAddPackage("gh:boostorg/preprocessor#boost-1.84.0")
CPMAddPackage("gh:boostorg/winapi#boost-1.84.0")
CPMAddPackage("gh:boostorg/utility#boost-1.84.0")

CPMAddPackage("gh:psiha/config_ex#master")
CPMAddPackage("gh:psiha/std_fix#master")
CPMAddPackage("gh:psiha/err#master")
CPMAddPackage("gh:psiha/build#master")
target_include_directories( vm PRIVATE "${build_SOURCE_DIR}/include" )

CPMAddPackage("gh:boostorg/boost#boost-1.84.0")
target_link_libraries( vm PRIVATE Boost::boost )
CPMAddPackage("gh:google/[email protected]")

# Link & include

target_link_libraries( vm PRIVATE
Boost::core
Boost::assert
Boost::preprocessor
Boost::winapi
Boost::utility
)

target_include_directories( vm PRIVATE
"${assert_SOURCE_DIR}/include"
"${core_SOURCE_DIR}/include"
"${preprocessor_SOURCE_DIR}/include"
"${winapi_SOURCE_DIR}/include"
"${utility_SOURCE_DIR}/include"
"${config_ex_SOURCE_DIR}/include"
"${std_fix_SOURCE_DIR}/include"
"${err_SOURCE_DIR}/include"
"${build_SOURCE_DIR}/include"
)

###################
##### Testing #####
###################

enable_testing()

# GOOGLE TEST
CPMAddPackage("gh:google/[email protected]")

# ADDING TESTS
add_subdirectory(${PROJECT_SOURCE_DIR}/test)
add_subdirectory("${PROJECT_SOURCE_DIR}/test")
9 changes: 7 additions & 2 deletions include/psi/vm/allocation/impl/allocation.posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
/// For more information, see http://www.boost.org
///
////////////////////////////////////////////////////////////////////////////////

#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))

//------------------------------------------------------------------------------
#include "allocation.impl.hpp"
#include "psi/vm/align.hpp"
Expand Down Expand Up @@ -61,13 +64,13 @@ void * mmap( void * const target_address, std::size_t const size, int const prot
}


void * allocate( std::size_t & size ) noexcept
void * allocate( std::size_t const & size ) noexcept
{
size = __builtin_align_up( size, reserve_granularity );
return mmap( nullptr, size, PROT_READ | PROT_WRITE, /*TODO rethink*/ MAP_NORESERVE );
}

void * reserve( std::size_t & size ) noexcept
void * reserve( std::size_t const & size ) noexcept
{
size = __builtin_align_up( size, reserve_granularity );
return mmap( nullptr, size, PROT_NONE, /*TODO rethink*/ MAP_NORESERVE );
Expand Down Expand Up @@ -137,3 +140,5 @@ bool allocate_fixed( void * const address, std::size_t const size, allocation_ty
//------------------------------------------------------------------------------
} // namespace psi
//------------------------------------------------------------------------------

#endif
7 changes: 7 additions & 0 deletions include/psi/vm/allocation/impl/allocation.win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
/// For more information, see http://www.boost.org
///
////////////////////////////////////////////////////////////////////////////////

#ifdef WIN32

//------------------------------------------------------------------------------
#include "allocation.impl.hpp"
#include "psi/vm/detail/nt.hpp"
Expand All @@ -20,6 +23,7 @@
#include <algorithm> // for std::min

#include <windows.h>
#undef min // Make std::min not broken
//------------------------------------------------------------------------------
namespace psi
{
Expand Down Expand Up @@ -192,3 +196,6 @@ bool allocate_fixed( void * const address, std::size_t const size, allocation_ty
//------------------------------------------------------------------------------
} // namespace psi
//------------------------------------------------------------------------------


#endif
19 changes: 11 additions & 8 deletions include/psi/vm/allocation/impl/remap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
#include "allocation.impl.hpp"
#include "psi/vm/align.hpp"

#include <cstddef>

#include <boost/assert.hpp>
#include <boost/config_ex.hpp>
Expand Down Expand Up @@ -49,10 +52,10 @@ expand_result expand
BOOST_ASSUME( current_size < required_size_for_end_expansion );
BOOST_ASSUME( current_size >= used_capacity );

BOOST_ASSUME( is_aligned( address , reserve_granularity ) );
BOOST_ASSUME( is_aligned( current_size , reserve_granularity ) );
BOOST_ASSUME( is_aligned( required_size_for_end_expansion , reserve_granularity ) );
BOOST_ASSUME( is_aligned( required_size_for_front_expansion, reserve_granularity ) );
BOOST_ASSUME( is_aligned( reinterpret_cast<uintptr_t>(address) , reserve_granularity ) );
BOOST_ASSUME( is_aligned( current_size , reserve_granularity ) );
BOOST_ASSUME( is_aligned( required_size_for_end_expansion , reserve_granularity ) );
BOOST_ASSUME( is_aligned( required_size_for_front_expansion , reserve_granularity ) );

BOOST_ASSUME( ( alloc_type == allocation_type::commit ) || !used_capacity );

Expand Down Expand Up @@ -91,7 +94,7 @@ expand_result expand
BOOST_ASSERT_MSG( false, "mremap failed but an appending mmap succeeded!?" ); // behaviour investigation
# endif
BOOST_ASSUME( current_size + additional_end_size == required_size_for_end_expansion );
return { address, required_size_for_end_expansion, expand_result::back_extended };
return { address, required_size_for_end_expansion, expand_result::method::back_extended };
}
}

Expand All @@ -104,21 +107,21 @@ expand_result expand
if ( allocate_fixed( pre_address, additional_front_size, allocation_type::commit ) ) // avoid having a non-committed range before a committed range
{
BOOST_VERIFY( current_size + additional_front_size == required_size_for_front_expansion );
return { static_cast< std::byte * >( pre_address ), required_size_for_front_expansion, expand_result::FrontExtended };
return { static_cast< std::byte * >( pre_address ), /*required_size_for_front_expansion,*/ expand_result::method::front_extended };
}
}

if ( realloc_type == reallocation_type::moveable )
{
// Everything else failed: fallback to the classic allocate new->copy->free old dance.
auto const requested_size{ required_size_for_end_expansion }; //...mrmlj...TODO respect front-expand-only requests
auto requested_size{ required_size_for_end_expansion }; //...mrmlj...TODO respect front-expand-only requests
auto const new_location { allocate( requested_size ) };
if ( new_location )
{
BOOST_ASSUME( requested_size == required_size_for_end_expansion );
std::memcpy( new_location, address, used_capacity );
free( address, current_size );
return { static_cast< std::byte * >( new_location ), required_size_for_end_expansion, expand_result::moved };
return { static_cast< std::byte * >( new_location ), /*required_size_for_end_expansion,*/ expand_result::method::moved };
}
}

Expand Down
2 changes: 2 additions & 0 deletions include/psi/vm/mappable_objects/file/win32/file.inl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <boost/assert.hpp>
#include <psi/err/win32.hpp>

#undef max
//------------------------------------------------------------------------------
namespace psi
{
Expand Down

0 comments on commit 0427844

Please sign in to comment.