mirror of
https://github.com/Bareflank/hypervisor
synced 2026-08-17 06:23:04 -04:00
windows cross compilation support
This commit is contained in:
parent
9304ef0b39
commit
d87a954890
15 changed files with 827 additions and 418 deletions
401
.clang-tidy
401
.clang-tidy
|
|
@ -47,402 +47,5 @@ Checks:
|
|||
WarningsAsErrors: '*'
|
||||
HeaderFilterRegex: '.*'
|
||||
AnalyzeTemporaryDtors: false
|
||||
FormatStyle: none
|
||||
CheckOptions:
|
||||
- key: bsl-using-decl-scope.HeaderFileExtensions
|
||||
value: ';h;hh;hpp;hxx'
|
||||
- key: bugprone-argument-comment.CommentBoolLiterals
|
||||
value: '0'
|
||||
- key: bugprone-argument-comment.CommentCharacterLiterals
|
||||
value: '0'
|
||||
- key: bugprone-argument-comment.CommentFloatLiterals
|
||||
value: '0'
|
||||
- key: bugprone-argument-comment.CommentIntegerLiterals
|
||||
value: '0'
|
||||
- key: bugprone-argument-comment.CommentNullPtrs
|
||||
value: '0'
|
||||
- key: bugprone-argument-comment.CommentStringLiterals
|
||||
value: '0'
|
||||
- key: bugprone-argument-comment.CommentUserDefinedLiterals
|
||||
value: '0'
|
||||
- key: bugprone-argument-comment.IgnoreSingleArgument
|
||||
value: '0'
|
||||
- key: bugprone-argument-comment.StrictMode
|
||||
value: '0'
|
||||
- key: bugprone-assert-side-effect.AssertMacros
|
||||
value: assert
|
||||
- key: bugprone-assert-side-effect.CheckFunctionCalls
|
||||
value: '0'
|
||||
- key: bugprone-dangling-handle.HandleClasses
|
||||
value: 'std::basic_string_view;std::experimental::basic_string_view'
|
||||
- key: bugprone-dynamic-static-initializers.HeaderFileExtensions
|
||||
value: ';h;hh;hpp;hxx'
|
||||
- key: bugprone-exception-escape.FunctionsThatShouldNotThrow
|
||||
value: ''
|
||||
- key: bugprone-exception-escape.IgnoredExceptions
|
||||
value: ''
|
||||
- key: bugprone-misplaced-widening-cast.CheckImplicitCasts
|
||||
value: '0'
|
||||
- key: bugprone-not-null-terminated-result.WantToUseSafeFunctions
|
||||
value: '1'
|
||||
- key: bugprone-reserved-identifier.AllowedIdentifiers
|
||||
value: ''
|
||||
- key: bugprone-reserved-identifier.Invert
|
||||
value: '0'
|
||||
- key: bugprone-signed-char-misuse.CharTypdefsToIgnore
|
||||
value: ''
|
||||
- key: bugprone-sizeof-expression.WarnOnSizeOfCompareToConstant
|
||||
value: '1'
|
||||
- key: bugprone-sizeof-expression.WarnOnSizeOfConstant
|
||||
value: '1'
|
||||
- key: bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression
|
||||
value: '0'
|
||||
- key: bugprone-sizeof-expression.WarnOnSizeOfThis
|
||||
value: '1'
|
||||
- key: bugprone-string-constructor.LargeLengthThreshold
|
||||
value: '8388608'
|
||||
- key: bugprone-string-constructor.WarnOnLargeLength
|
||||
value: '1'
|
||||
- key: bugprone-suspicious-enum-usage.StrictMode
|
||||
value: '0'
|
||||
- key: bugprone-suspicious-include.HeaderFileExtensions
|
||||
value: ';h;hh;hpp;hxx'
|
||||
- key: bugprone-suspicious-include.ImplementationFileExtensions
|
||||
value: 'c;cc;cpp;cxx'
|
||||
- key: bugprone-suspicious-missing-comma.MaxConcatenatedTokens
|
||||
value: '5'
|
||||
- key: bugprone-suspicious-missing-comma.RatioThreshold
|
||||
value: '0.200000'
|
||||
- key: bugprone-suspicious-missing-comma.SizeThreshold
|
||||
value: '5'
|
||||
- key: bugprone-suspicious-string-compare.StringCompareLikeFunctions
|
||||
value: ''
|
||||
- key: bugprone-suspicious-string-compare.WarnOnImplicitComparison
|
||||
value: '1'
|
||||
- key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison
|
||||
value: '0'
|
||||
- key: bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit
|
||||
value: '16'
|
||||
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
|
||||
value: '1'
|
||||
- key: bugprone-unused-return-value.CheckedFunctions
|
||||
value: '::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty'
|
||||
- key: cert-dcl16-c.IgnoreMacros
|
||||
value: '1'
|
||||
- key: cert-dcl16-c.NewSuffixes
|
||||
value: 'L;LL;LU;LLU'
|
||||
- key: cert-dcl37-c.AllowedIdentifiers
|
||||
value: ''
|
||||
- key: cert-dcl37-c.Invert
|
||||
value: '0'
|
||||
- key: cert-dcl51-cpp.AllowedIdentifiers
|
||||
value: ''
|
||||
- key: cert-dcl51-cpp.Invert
|
||||
value: '0'
|
||||
- key: cert-dcl59-cpp.HeaderFileExtensions
|
||||
value: ';h;hh;hpp;hxx'
|
||||
- key: cert-err09-cpp.CheckThrowTemporaries
|
||||
value: '1'
|
||||
- key: cert-err61-cpp.CheckThrowTemporaries
|
||||
value: '1'
|
||||
- key: cert-msc32-c.DisallowedSeedTypes
|
||||
value: 'time_t,std::time_t'
|
||||
- key: cert-msc51-cpp.DisallowedSeedTypes
|
||||
value: 'time_t,std::time_t'
|
||||
- key: cert-oop11-cpp.IncludeStyle
|
||||
value: llvm
|
||||
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
|
||||
value: '0'
|
||||
- key: cert-oop57-cpp.MemCmpNames
|
||||
value: ''
|
||||
- key: cert-oop57-cpp.MemCpyNames
|
||||
value: ''
|
||||
- key: cert-oop57-cpp.MemSetNames
|
||||
value: ''
|
||||
- key: cppcoreguidelines-avoid-magic-numbers.IgnoredFloatingPointValues
|
||||
value: '0;1'
|
||||
- key: cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues
|
||||
value: '0;1'
|
||||
- key: cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal
|
||||
value: '0'
|
||||
- key: cppcoreguidelines-explicit-virtual-functions.FinalSpelling
|
||||
value: final
|
||||
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
|
||||
value: '1'
|
||||
- key: cppcoreguidelines-explicit-virtual-functions.OverrideSpelling
|
||||
value: override
|
||||
- key: cppcoreguidelines-macro-usage.AllowedRegexp
|
||||
value: ''
|
||||
- key: cppcoreguidelines-macro-usage.CheckCapsOnly
|
||||
value: '0'
|
||||
- key: cppcoreguidelines-macro-usage.IgnoreCommandLineMacros
|
||||
value: '1'
|
||||
- key: cppcoreguidelines-no-malloc.Allocations
|
||||
value: '::malloc;::calloc'
|
||||
- key: cppcoreguidelines-no-malloc.Deallocations
|
||||
value: '::free'
|
||||
- key: cppcoreguidelines-no-malloc.Reallocations
|
||||
value: '::realloc'
|
||||
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
|
||||
value: '1'
|
||||
- key: cppcoreguidelines-owning-memory.LegacyResourceConsumers
|
||||
value: '::free;::realloc;::freopen;::fclose'
|
||||
- key: cppcoreguidelines-owning-memory.LegacyResourceProducers
|
||||
value: '::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile'
|
||||
- key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader
|
||||
value: ''
|
||||
- key: cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle
|
||||
value: '0'
|
||||
- key: cppcoreguidelines-pro-type-member-init.IgnoreArrays
|
||||
value: '0'
|
||||
- key: cppcoreguidelines-pro-type-member-init.UseAssignment
|
||||
value: '0'
|
||||
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions
|
||||
value: '0'
|
||||
- key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted
|
||||
value: '0'
|
||||
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
|
||||
value: '0'
|
||||
- key: google-readability-braces-around-statements.ShortStatementLines
|
||||
value: '1'
|
||||
- key: google-readability-function-size.StatementThreshold
|
||||
value: '800'
|
||||
- key: google-readability-namespace-comments.ShortNamespaceLines
|
||||
value: '10'
|
||||
- key: google-readability-namespace-comments.SpacesBeforeComments
|
||||
value: '2'
|
||||
- key: hicpp-braces-around-statements.ShortStatementLines
|
||||
value: '0'
|
||||
- key: hicpp-function-size.BranchThreshold
|
||||
value: '4294967295'
|
||||
- key: hicpp-function-size.LineThreshold
|
||||
value: '4294967295'
|
||||
- key: hicpp-function-size.NestingThreshold
|
||||
value: '4294967295'
|
||||
- key: hicpp-function-size.ParameterThreshold
|
||||
value: '4294967295'
|
||||
- key: hicpp-function-size.StatementThreshold
|
||||
value: '800'
|
||||
- key: hicpp-function-size.VariableThreshold
|
||||
value: '4294967295'
|
||||
- key: hicpp-member-init.IgnoreArrays
|
||||
value: '0'
|
||||
- key: hicpp-member-init.UseAssignment
|
||||
value: '0'
|
||||
- key: hicpp-move-const-arg.CheckTriviallyCopyableMove
|
||||
value: '1'
|
||||
- key: hicpp-multiway-paths-covered.WarnOnMissingElse
|
||||
value: '0'
|
||||
- key: hicpp-named-parameter.IgnoreFailedSplit
|
||||
value: '0'
|
||||
- key: hicpp-named-parameter.IgnoreMainLikeFunctions
|
||||
value: '0'
|
||||
- key: hicpp-no-malloc.Allocations
|
||||
value: '::malloc;::calloc'
|
||||
- key: hicpp-no-malloc.Deallocations
|
||||
value: '::free'
|
||||
- key: hicpp-no-malloc.Reallocations
|
||||
value: '::realloc'
|
||||
- key: hicpp-signed-bitwise.IgnorePositiveIntegerLiterals
|
||||
value: '0'
|
||||
- key: hicpp-special-member-functions.AllowMissingMoveFunctions
|
||||
value: '0'
|
||||
- key: hicpp-special-member-functions.AllowMissingMoveFunctionsWhenCopyIsDeleted
|
||||
value: '0'
|
||||
- key: hicpp-special-member-functions.AllowSoleDefaultDtor
|
||||
value: '0'
|
||||
- key: hicpp-uppercase-literal-suffix.IgnoreMacros
|
||||
value: '1'
|
||||
- key: hicpp-uppercase-literal-suffix.NewSuffixes
|
||||
value: ''
|
||||
- key: hicpp-use-auto.MinTypeNameLength
|
||||
value: '5'
|
||||
- key: hicpp-use-auto.RemoveStars
|
||||
value: '0'
|
||||
- key: hicpp-use-emplace.ContainersWithPushBack
|
||||
value: '::std::vector;::std::list;::std::deque'
|
||||
- key: hicpp-use-emplace.SmartPointers
|
||||
value: '::std::shared_ptr;::std::unique_ptr;::std::auto_ptr;::std::weak_ptr'
|
||||
- key: hicpp-use-emplace.TupleMakeFunctions
|
||||
value: '::std::make_pair;::std::make_tuple'
|
||||
- key: hicpp-use-emplace.TupleTypes
|
||||
value: '::std::pair;::std::tuple'
|
||||
- key: hicpp-use-equals-default.IgnoreMacros
|
||||
value: '1'
|
||||
- key: hicpp-use-equals-delete.IgnoreMacros
|
||||
value: '1'
|
||||
- key: hicpp-use-noexcept.ReplacementString
|
||||
value: ''
|
||||
- key: hicpp-use-noexcept.UseNoexceptFalse
|
||||
value: '1'
|
||||
- key: hicpp-use-nullptr.NullMacros
|
||||
value: ''
|
||||
- key: hicpp-use-override.AllowOverrideAndFinal
|
||||
value: '0'
|
||||
- key: hicpp-use-override.FinalSpelling
|
||||
value: final
|
||||
- key: hicpp-use-override.IgnoreDestructors
|
||||
value: '0'
|
||||
- key: hicpp-use-override.OverrideSpelling
|
||||
value: override
|
||||
- key: llvm-qualified-auto.AddConstToQualified
|
||||
value: '0'
|
||||
- key: misc-definitions-in-headers.HeaderFileExtensions
|
||||
value: ';h;hh;hpp;hxx'
|
||||
- key: misc-definitions-in-headers.UseHeaderFileExtension
|
||||
value: '1'
|
||||
- key: misc-throw-by-value-catch-by-reference.CheckThrowTemporaries
|
||||
value: '1'
|
||||
- key: misc-unused-parameters.StrictMode
|
||||
value: '0'
|
||||
- key: modernize-loop-convert.MaxCopySize
|
||||
value: '16'
|
||||
- key: modernize-loop-convert.MinConfidence
|
||||
value: reasonable
|
||||
- key: modernize-loop-convert.NamingStyle
|
||||
value: CamelCase
|
||||
- key: modernize-make-shared.IgnoreMacros
|
||||
value: '1'
|
||||
- key: modernize-make-shared.IncludeStyle
|
||||
value: llvm
|
||||
- key: modernize-make-shared.MakeSmartPtrFunction
|
||||
value: 'std::make_shared'
|
||||
- key: modernize-make-shared.MakeSmartPtrFunctionHeader
|
||||
value: memory
|
||||
- key: modernize-make-unique.IgnoreMacros
|
||||
value: '1'
|
||||
- key: modernize-make-unique.IncludeStyle
|
||||
value: llvm
|
||||
- key: modernize-make-unique.MakeSmartPtrFunction
|
||||
value: 'std::make_unique'
|
||||
- key: modernize-make-unique.MakeSmartPtrFunctionHeader
|
||||
value: memory
|
||||
- key: modernize-pass-by-value.IncludeStyle
|
||||
value: llvm
|
||||
- key: modernize-pass-by-value.ValuesOnly
|
||||
value: '0'
|
||||
- key: modernize-raw-string-literal.ReplaceShorterLiterals
|
||||
value: '0'
|
||||
- key: modernize-replace-auto-ptr.IncludeStyle
|
||||
value: llvm
|
||||
- key: modernize-replace-random-shuffle.IncludeStyle
|
||||
value: llvm
|
||||
- key: modernize-use-auto.MinTypeNameLength
|
||||
value: '5'
|
||||
- key: modernize-use-auto.RemoveStars
|
||||
value: '0'
|
||||
- key: modernize-use-default-member-init.IgnoreMacros
|
||||
value: '1'
|
||||
- key: modernize-use-default-member-init.UseAssignment
|
||||
value: '0'
|
||||
- key: modernize-use-emplace.ContainersWithPushBack
|
||||
value: '::std::vector;::std::list;::std::deque'
|
||||
- key: modernize-use-emplace.SmartPointers
|
||||
value: '::std::shared_ptr;::std::unique_ptr;::std::auto_ptr;::std::weak_ptr'
|
||||
- key: modernize-use-emplace.TupleMakeFunctions
|
||||
value: '::std::make_pair;::std::make_tuple'
|
||||
- key: modernize-use-emplace.TupleTypes
|
||||
value: '::std::pair;::std::tuple'
|
||||
- key: modernize-use-equals-default.IgnoreMacros
|
||||
value: '1'
|
||||
- key: modernize-use-equals-delete.IgnoreMacros
|
||||
value: '1'
|
||||
- key: modernize-use-nodiscard.ReplacementString
|
||||
value: '[[nodiscard]]'
|
||||
- key: modernize-use-noexcept.ReplacementString
|
||||
value: ''
|
||||
- key: modernize-use-noexcept.UseNoexceptFalse
|
||||
value: '1'
|
||||
- key: modernize-use-nullptr.NullMacros
|
||||
value: 'NULL'
|
||||
- key: modernize-use-override.AllowOverrideAndFinal
|
||||
value: '0'
|
||||
- key: modernize-use-override.FinalSpelling
|
||||
value: final
|
||||
- key: modernize-use-override.IgnoreDestructors
|
||||
value: '0'
|
||||
- key: modernize-use-override.OverrideSpelling
|
||||
value: override
|
||||
- key: modernize-use-transparent-functors.SafeMode
|
||||
value: '0'
|
||||
- key: modernize-use-using.IgnoreMacros
|
||||
value: '1'
|
||||
- key: performance-faster-string-find.StringLikeClasses
|
||||
value: 'std::basic_string'
|
||||
- key: performance-for-range-copy.AllowedTypes
|
||||
value: ''
|
||||
- key: performance-for-range-copy.WarnOnAllAutoCopies
|
||||
value: '0'
|
||||
- key: performance-inefficient-string-concatenation.StrictMode
|
||||
value: '0'
|
||||
- key: performance-inefficient-vector-operation.EnableProto
|
||||
value: '0'
|
||||
- key: performance-inefficient-vector-operation.VectorLikeClasses
|
||||
value: '::std::vector'
|
||||
- key: performance-move-const-arg.CheckTriviallyCopyableMove
|
||||
value: '1'
|
||||
- key: performance-move-constructor-init.IncludeStyle
|
||||
value: llvm
|
||||
- key: performance-no-automatic-move.AllowedTypes
|
||||
value: ''
|
||||
- key: performance-type-promotion-in-math-fn.IncludeStyle
|
||||
value: llvm
|
||||
- key: performance-unnecessary-copy-initialization.AllowedTypes
|
||||
value: ''
|
||||
- key: performance-unnecessary-value-param.AllowedTypes
|
||||
value: ''
|
||||
- key: performance-unnecessary-value-param.IncludeStyle
|
||||
value: llvm
|
||||
- key: readability-braces-around-statements.ShortStatementLines
|
||||
value: '0'
|
||||
- key: readability-else-after-return.WarnOnUnfixable
|
||||
value: '1'
|
||||
- key: readability-function-size.BranchThreshold
|
||||
value: '4294967295'
|
||||
- key: readability-function-size.LineThreshold
|
||||
value: '4294967295'
|
||||
- key: readability-function-size.NestingThreshold
|
||||
value: '4294967295'
|
||||
- key: readability-function-size.ParameterThreshold
|
||||
value: '4294967295'
|
||||
- key: readability-function-size.StatementThreshold
|
||||
value: '800'
|
||||
- key: readability-function-size.VariableThreshold
|
||||
value: '4294967295'
|
||||
- key: readability-identifier-naming.IgnoreFailedSplit
|
||||
value: '0'
|
||||
- key: readability-identifier-naming.IgnoreMainLikeFunctions
|
||||
value: '0'
|
||||
- key: readability-implicit-bool-conversion.AllowIntegerConditions
|
||||
value: '0'
|
||||
- key: readability-implicit-bool-conversion.AllowPointerConditions
|
||||
value: '0'
|
||||
- key: readability-inconsistent-declaration-parameter-name.IgnoreMacros
|
||||
value: '1'
|
||||
- key: readability-inconsistent-declaration-parameter-name.Strict
|
||||
value: '0'
|
||||
- key: readability-magic-numbers.IgnoredFloatingPointValues
|
||||
value: '0;1'
|
||||
- key: readability-magic-numbers.IgnoredIntegerValues
|
||||
value: '0;1'
|
||||
- key: readability-qualified-auto.AddConstToQualified
|
||||
value: '1'
|
||||
- key: readability-redundant-member-init.IgnoreBaseInCopyConstructors
|
||||
value: '0'
|
||||
- key: readability-redundant-smartptr-get.IgnoreMacros
|
||||
value: '1'
|
||||
- key: readability-redundant-string-init.StringNames
|
||||
value: '::std::basic_string'
|
||||
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
|
||||
value: '0'
|
||||
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
|
||||
value: '0'
|
||||
- key: readability-simplify-subscript-expr.Types
|
||||
value: '::std::basic_string;::std::basic_string_view;::std::vector;::std::array'
|
||||
- key: readability-static-accessed-through-instance.NameSpecifierNestingThreshold
|
||||
value: '3'
|
||||
- key: readability-uppercase-literal-suffix.IgnoreMacros
|
||||
value: '1'
|
||||
- key: readability-uppercase-literal-suffix.NewSuffixes
|
||||
value: ''
|
||||
...
|
||||
FormatStyle: none
|
||||
UseColor: true
|
||||
|
|
|
|||
|
|
@ -24,20 +24,15 @@ project(hypervisor CXX)
|
|||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cmake/init_build.cmake)
|
||||
|
||||
if(HYPERVISOR_BUILD_LOADER)
|
||||
add_subdirectory(loader)
|
||||
endif()
|
||||
if(NOT WIN32)
|
||||
if(HYPERVISOR_BUILD_LOADER)
|
||||
add_subdirectory(loader)
|
||||
endif()
|
||||
|
||||
if(HYPERVISOR_BUILD_VMMCTL)
|
||||
add_subdirectory(vmmctl)
|
||||
if(HYPERVISOR_BUILD_VMMCTL)
|
||||
add_subdirectory(vmmctl)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
hypervisor_add_mk_cross_compile(cmake/mk_cross_compile)
|
||||
hypervisor_add_ext_cross_compile(cmake/ext_cross_compile)
|
||||
|
||||
if(NOT DEFINED FIRST_TIME)
|
||||
message(STATUS "${BF_COLOR_YLW}-----------------------------------------${BF_COLOR_RST}")
|
||||
message(STATUS "run '${BF_COLOR_MAG}make info${BF_COLOR_RST}' for configuration details")
|
||||
message(STATUS "${BF_COLOR_YLW}-----------------------------------------${BF_COLOR_RST}")
|
||||
set(FIRST_TIME ON)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -27,11 +27,16 @@ option(HYPERVISOR_BUILD_VMMCTL "Turns on/off building the vmmctl" ON)
|
|||
if (NOT DEFINED HYPERVISOR_TARGET_ARCH)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
execute_process(
|
||||
COMMAND bash "-c" "lscpu | grep 'Vendor ID' | awk '{ print $3 }'"
|
||||
COMMAND ${CMAKE_CURRENT_LIST_DIR}/../../utils/linux/get_target_arch
|
||||
OUTPUT_VARIABLE HYPERVISOR_DEFAULT_TARGET_ARCH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_CURRENT_LIST_DIR}/../../utils/windows/get_target_arch
|
||||
OUTPUT_VARIABLE HYPERVISOR_DEFAULT_TARGET_ARCH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
|
@ -39,6 +44,18 @@ else()
|
|||
set(HYPERVISOR_DEFAULT_TARGET_ARCH ${HYPERVISOR_TARGET_ARCH})
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED HYPERVISOR_CXX_LINKER)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(HYPERVISOR_DEFAULT_CXX_LINKER "ld.lld")
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(HYPERVISOR_DEFAULT_CXX_LINKER "ld.lld")
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
else()
|
||||
set(HYPERVISOR_DEFAULT_CXX_LINKER ${HYPERVISOR_CXX_LINKER})
|
||||
endif()
|
||||
|
||||
bf_add_config(
|
||||
CONFIG_NAME HYPERVISOR_TARGET_ARCH
|
||||
CONFIG_TYPE STRING
|
||||
|
|
@ -50,7 +67,7 @@ bf_add_config(
|
|||
bf_add_config(
|
||||
CONFIG_NAME HYPERVISOR_CXX_LINKER
|
||||
CONFIG_TYPE STRING
|
||||
DEFAULT_VAL "ld.lld"
|
||||
DEFAULT_VAL ${HYPERVISOR_DEFAULT_CXX_LINKER}
|
||||
DESCRIPTION "Define the linker to use for cross-compiling. Does not effect native linking"
|
||||
SKIP_VALIDATION
|
||||
)
|
||||
|
|
|
|||
|
|
@ -33,5 +33,3 @@ if(NOT bsl_POPULATED)
|
|||
FetchContent_Populate(bsl)
|
||||
add_subdirectory(${bsl_SOURCE_DIR} ${bsl_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
message(STATUS "Found BSL: ${bsl_SOURCE_DIR}")
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ macro(hypervisor_add_info)
|
|||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_command(TARGET info
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "${BF_COLOR_YLW} BSL ${BF_COLOR_CYN}${bsl_SOURCE_DIR}${BF_COLOR_RST}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
if(HYPERVISOR_BUILD_LOADER)
|
||||
add_custom_command(TARGET info
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "${BF_COLOR_YLW} HYPERVISOR_BUILD_LOADER ${BF_COLOR_GRN}enabled${BF_COLOR_RST}"
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ string(CONCAT HYPERVISOR_EXT_CXX_FLAGS
|
|||
"-mno-aes "
|
||||
"-mno-sse4a "
|
||||
"-mcmodel=large "
|
||||
"-std=c++20 "
|
||||
)
|
||||
|
||||
string(CONCAT HYPERVISOR_EXT_LINK_FLAGS
|
||||
|
|
@ -55,3 +56,24 @@ set(CMAKE_CXX_COMPILE_OBJECT
|
|||
set(CMAKE_CXX_LINK_EXECUTABLE
|
||||
"${HYPERVISOR_CXX_LINKER} ${HYPERVISOR_EXT_LINK_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Hack For Windows
|
||||
################################################################################
|
||||
|
||||
# For some reason, CMake on Windows is adding extra stuff to the compiler
|
||||
# includes and flags. The following fixes this issue by telling CMake not
|
||||
# to configure the compiler. We need to add C++20 to the command above
|
||||
# to make this work.
|
||||
# https://gitlab.kitware.com/cmake/cmake/-/issues/21789
|
||||
|
||||
# set(__COMPILER_CLANG 1)
|
||||
|
||||
# macro(__compiler_clang lang)
|
||||
# endmacro()
|
||||
|
||||
# macro(__compiler_clang_cxx_standards lang)
|
||||
# endmacro()
|
||||
|
||||
# macro(__compiler_check_default_language_standard lang)
|
||||
# endmacro()
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ string(CONCAT HYPERVISOR_MK_CXX_FLAGS
|
|||
"-mno-aes "
|
||||
"-mno-sse4a "
|
||||
"-mcmodel=large "
|
||||
"-std=c++20 "
|
||||
)
|
||||
|
||||
string(CONCAT HYPERVISOR_MK_LINK_FLAGS
|
||||
|
|
@ -55,3 +56,24 @@ set(CMAKE_CXX_COMPILE_OBJECT
|
|||
set(CMAKE_CXX_LINK_EXECUTABLE
|
||||
"${HYPERVISOR_CXX_LINKER} ${HYPERVISOR_MK_LINK_FLAGS} <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>"
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# Hack For Windows
|
||||
################################################################################
|
||||
|
||||
# For some reason, CMake on Windows is adding extra stuff to the compiler
|
||||
# includes and flags. The following fixes this issue by telling CMake not
|
||||
# to configure the compiler. We need to add C++20 to the command above
|
||||
# to make this work.
|
||||
# https://gitlab.kitware.com/cmake/cmake/-/issues/21789
|
||||
|
||||
set(__COMPILER_CLANG 1)
|
||||
|
||||
macro(__compiler_clang lang)
|
||||
endmacro()
|
||||
|
||||
macro(__compiler_clang_cxx_standards lang)
|
||||
endmacro()
|
||||
|
||||
macro(__compiler_check_default_language_standard lang)
|
||||
endmacro()
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ namespace loader
|
|||
{
|
||||
namespace details
|
||||
{
|
||||
/// @brief the size of reserved #0 in the state_save_t
|
||||
constexpr bsl::safe_uintmax PAD_SIZE{bsl::to_umax(0x6)};
|
||||
/// @brief the size of reserved #0 in the state_save_t
|
||||
constexpr bsl::safe_uintmax RESERVED0_SIZE{bsl::to_umax(0xB)};
|
||||
/// @brief the size of reserved #1 in the state_save_t
|
||||
|
|
@ -133,13 +135,13 @@ namespace loader
|
|||
global_descriptor_table_register_t gdtr;
|
||||
|
||||
/// @brief added padding for alignment (0x0AA)
|
||||
uint8_t pad1[0x6];
|
||||
bsl::details::carray<bsl::uint8, details::PAD_SIZE.get()> pad1;
|
||||
|
||||
/// @brief stores the value of the IDTR (0x0B0)
|
||||
interrupt_descriptor_table_register_t idtr;
|
||||
|
||||
/// @brief added padding for alignment (0x0BA)
|
||||
uint8_t pad2[0x6];
|
||||
bsl::details::carray<bsl::uint8, details::PAD_SIZE.get()> pad2;
|
||||
|
||||
/// @brief stores the value of the ES segment selector (0x0C0)
|
||||
bsl::uint16 es_selector;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,29 @@
|
|||
/**
|
||||
* @copyright
|
||||
* Copyright (C) 2020 Assured Information Security, Inc.
|
||||
*
|
||||
* @copyright
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* @copyright
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* @copyright
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
.code64
|
||||
.intel_syntax noprefix
|
||||
|
||||
|
|
@ -16,6 +42,6 @@ loop:
|
|||
dec rdi
|
||||
cmp rdi, 0
|
||||
jne loop
|
||||
|
||||
|
||||
pop rbx
|
||||
ret
|
||||
|
|
|
|||
43
utils/get_target_arch.c
Normal file
43
utils/get_target_arch.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* @copyright
|
||||
* Copyright (C) 2020 Assured Information Security, Inc.
|
||||
*
|
||||
* @copyright
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* @copyright
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* @copyright
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
uint32_t get_vendor(void);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (get_vendor() == 0x68747541) {
|
||||
printf("AuthenticAMD");
|
||||
}
|
||||
else {
|
||||
printf("GenuineIntel");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
39
utils/get_target_arch_get_vendor.S
Normal file
39
utils/get_target_arch_get_vendor.S
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* @copyright
|
||||
* Copyright (C) 2020 Assured Information Security, Inc.
|
||||
*
|
||||
* @copyright
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* @copyright
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* @copyright
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
.code64
|
||||
.intel_syntax noprefix
|
||||
|
||||
.globl get_vendor
|
||||
get_vendor:
|
||||
push rbx
|
||||
|
||||
mov rax, 0x0
|
||||
cpuid
|
||||
mov rax, rbx
|
||||
|
||||
pop rbx
|
||||
ret
|
||||
BIN
utils/linux/get_target_arch
Executable file
BIN
utils/linux/get_target_arch
Executable file
Binary file not shown.
BIN
utils/windows/get_target_arch
Normal file
BIN
utils/windows/get_target_arch
Normal file
Binary file not shown.
314
vmmctl/src/windows/ifmap.hpp
Normal file
314
vmmctl/src/windows/ifmap.hpp
Normal file
|
|
@ -0,0 +1,314 @@
|
|||
/// @copyright
|
||||
/// Copyright (C) 2020 Assured Information Security, Inc.
|
||||
///
|
||||
/// @copyright
|
||||
/// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
/// of this software and associated documentation files (the "Software"), to deal
|
||||
/// in the Software without restriction, including without limitation the rights
|
||||
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
/// copies of the Software, and to permit persons to whom the Software is
|
||||
/// furnished to do so, subject to the following conditions:
|
||||
///
|
||||
/// @copyright
|
||||
/// The above copyright notice and this permission notice shall be included in
|
||||
/// all copies or substantial portions of the Software.
|
||||
///
|
||||
/// @copyright
|
||||
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
/// SOFTWARE.
|
||||
|
||||
#ifndef BSL_DETAILS_IFMAP_WINDOWS_HPP
|
||||
#define BSL_DETAILS_IFMAP_WINDOWS_HPP
|
||||
|
||||
#include "../../../byte.hpp"
|
||||
#include "../../../convert.hpp"
|
||||
#include "../../../cstdint.hpp"
|
||||
#include "../../../debug.hpp"
|
||||
#include "../../../discard.hpp"
|
||||
#include "../../../move.hpp"
|
||||
#include "../../../safe_integral.hpp"
|
||||
#include "../../../span.hpp"
|
||||
#include "../../../string_view.hpp"
|
||||
#include "../../../swap.hpp"
|
||||
#include "../../../touch.hpp"
|
||||
|
||||
#include <Windows.h>
|
||||
#undef max
|
||||
#undef min
|
||||
|
||||
namespace bsl
|
||||
{
|
||||
/// @class bsl::ifmap
|
||||
///
|
||||
/// <!-- description -->
|
||||
/// @brief Maps a file as read-only, and returns a pointer to the file
|
||||
/// via data() as well as the size of the mapped file via size().
|
||||
/// @include example_ifmap_overview.hpp
|
||||
///
|
||||
class ifmap final
|
||||
{
|
||||
/// @brief stores a handle to the mapped file.
|
||||
HANDLE m_file{};
|
||||
/// @brief stores a handle to the mapped file.
|
||||
HANDLE m_view{};
|
||||
/// @brief stores a view of the file that is mapped.
|
||||
span<byte const> m_data{};
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Swaps *this with other
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param lhs the left hand side of the exchange
|
||||
/// @param rhs the right hand side of the exchange
|
||||
///
|
||||
static constexpr void
|
||||
private_swap(ifmap &lhs, ifmap &rhs) noexcept
|
||||
{
|
||||
bsl::swap(lhs.m_file, rhs.m_file);
|
||||
bsl::swap(lhs.m_view, rhs.m_view);
|
||||
bsl::swap(lhs.m_data, rhs.m_data);
|
||||
}
|
||||
|
||||
public:
|
||||
/// @brief alias for: void
|
||||
using value_type = void;
|
||||
/// @brief alias for: safe_uintmax
|
||||
using size_type = safe_uintmax;
|
||||
/// @brief alias for: safe_uintmax
|
||||
using difference_type = safe_uintmax;
|
||||
/// @brief alias for: void *
|
||||
using pointer_type = void *;
|
||||
/// @brief alias for: void const *
|
||||
using const_pointer_type = void const *;
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Creates a default ifmap that has not yet been mapped.
|
||||
/// @include ifmap/example_ifmap_default_constructor.hpp
|
||||
///
|
||||
ifmap() noexcept = default;
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Creates a bsl::ifmap given a the filename and path of
|
||||
/// the file to map as read-only.
|
||||
/// @include ifmap/example_ifmap_constructor.hpp
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param filename the filename and path of the file to map
|
||||
///
|
||||
explicit ifmap(string_view const &filename) noexcept
|
||||
{
|
||||
m_file = CreateFileA(
|
||||
filename.data(),
|
||||
GENERIC_READ,
|
||||
0,
|
||||
nullptr,
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
nullptr);
|
||||
|
||||
m_view = CreateFileMappingA(m_file, nullptr, PAGE_READONLY, 0, 0, nullptr);
|
||||
if (nullptr == m_view) {
|
||||
bsl::alert() << "failed to open read-only file: " // --
|
||||
<< filename // --
|
||||
<< bsl::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD high{};
|
||||
DWORD size{GetFileSize(m_file, &high)};
|
||||
if (INVALID_FILE_SIZE == size) {
|
||||
bsl::alert() << "failed to get the size of the read-only file: " // --
|
||||
<< filename // --
|
||||
<< bsl::endl;
|
||||
|
||||
bsl::discard(CloseHandle(m_view));
|
||||
bsl::discard(CloseHandle(m_file));
|
||||
m_file = nullptr;
|
||||
m_view = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
pointer_type const ptr{MapViewOfFile(m_view, FILE_MAP_READ, 0, 0, 0)};
|
||||
if (nullptr == ptr) {
|
||||
bsl::alert() << "failed to map read-only file: " // --
|
||||
<< filename // --
|
||||
<< bsl::endl;
|
||||
|
||||
bsl::discard(CloseHandle(m_view));
|
||||
bsl::discard(CloseHandle(m_file));
|
||||
m_file = nullptr;
|
||||
m_view = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
m_data = {
|
||||
static_cast<bsl::byte const *>(ptr),
|
||||
(to_umax(high) << to_umax(32)) | to_umax(size)};
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Destructor unmaps a previously mapped file.
|
||||
///
|
||||
~ifmap() noexcept = default;
|
||||
// {
|
||||
// if (nullptr != m_file) {
|
||||
// bsl::discard(UnmapViewOfFile(m_data.data()));
|
||||
// bsl::discard(CloseHandle(m_view));
|
||||
// bsl::discard(CloseHandle(m_file));
|
||||
// m_file = nullptr;
|
||||
// m_view = nullptr;
|
||||
// }
|
||||
// else {
|
||||
// bsl::touch();
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief copy constructor
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param o the object being copied
|
||||
///
|
||||
constexpr ifmap(ifmap const &o) noexcept = delete;
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief move constructor
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param o the object being moved
|
||||
///
|
||||
constexpr ifmap(ifmap &&o) noexcept
|
||||
: m_file{bsl::move(o.m_file)}, m_view{bsl::move(o.m_view)}, m_data{bsl::move(o.m_data)}
|
||||
{
|
||||
o.m_file = nullptr;
|
||||
o.m_view = nullptr;
|
||||
o.m_data = {};
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief copy assignment
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param o the object being copied
|
||||
/// @return a reference to *this
|
||||
///
|
||||
[[maybe_unused]] constexpr auto operator=(ifmap const &o) &noexcept -> ifmap & = delete;
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief move assignment
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param o the object being moved
|
||||
/// @return a reference to *this
|
||||
///
|
||||
[[maybe_unused]] auto
|
||||
operator=(ifmap &&o) &noexcept -> ifmap &
|
||||
{
|
||||
ifmap tmp{bsl::move(o)};
|
||||
this->private_swap(*this, tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Returns a span to the read-only mapped file.
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @return Returns a span to the read-only mapped file.
|
||||
///
|
||||
[[nodiscard]] constexpr auto
|
||||
view() const noexcept -> bsl::span<byte const>
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Returns a pointer to the read-only mapped file.
|
||||
/// @include ifmap/example_ifmap_data.hpp
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @return Returns a pointer to the read-only mapped file.
|
||||
///
|
||||
[[nodiscard]] constexpr auto
|
||||
data() const noexcept -> const_pointer_type
|
||||
{
|
||||
return m_data.data();
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Returns true if the file failed to be mapped, false
|
||||
/// otherwise.
|
||||
/// @include ifmap/example_ifmap_empty.hpp
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @return Returns true if the file failed to be mapped, false
|
||||
/// otherwise.
|
||||
///
|
||||
[[nodiscard]] constexpr auto
|
||||
empty() const noexcept -> bool
|
||||
{
|
||||
return m_data.empty();
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Returns !empty()
|
||||
/// @include ifmap/example_ifmap_operator_bool.hpp
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @return Returns !empty()
|
||||
///
|
||||
[[nodiscard]] constexpr explicit operator bool() const noexcept
|
||||
{
|
||||
return !this->empty();
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Returns the number of bytes in the file being
|
||||
/// mapped.
|
||||
/// @include ifmap/example_ifmap_size.hpp
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @return Returns the number of bytes in the file being
|
||||
/// mapped.
|
||||
///
|
||||
[[nodiscard]] constexpr auto
|
||||
size() const noexcept -> size_type
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Returns the max number of bytes the BSL supports.
|
||||
/// @include ifmap/example_ifmap_max_size.hpp
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @return Returns the max number of bytes the BSL supports.
|
||||
///
|
||||
[[nodiscard]] static constexpr auto
|
||||
max_size() noexcept -> size_type
|
||||
{
|
||||
return to_umax(size_type::max());
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Returns the number of bytes in the file being
|
||||
/// mapped.
|
||||
/// @include ifmap/example_ifmap_size_bytes.hpp
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @return Returns the number of bytes in the file being
|
||||
/// mapped.
|
||||
///
|
||||
[[nodiscard]] constexpr auto
|
||||
size_bytes() const noexcept -> size_type
|
||||
{
|
||||
return m_data.size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
323
vmmctl/src/windows/ioctl.hpp
Normal file
323
vmmctl/src/windows/ioctl.hpp
Normal file
|
|
@ -0,0 +1,323 @@
|
|||
/// @copyright
|
||||
/// Copyright (C) 2020 Assured Information Security, Inc.
|
||||
///
|
||||
/// @copyright
|
||||
/// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
/// of this software and associated documentation files (the "Software"), to deal
|
||||
/// in the Software without restriction, including without limitation the rights
|
||||
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
/// copies of the Software, and to permit persons to whom the Software is
|
||||
/// furnished to do so, subject to the following conditions:
|
||||
///
|
||||
/// @copyright
|
||||
/// The above copyright notice and this permission notice shall be included in
|
||||
/// all copies or substantial portions of the Software.
|
||||
///
|
||||
/// @copyright
|
||||
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
/// SOFTWARE.
|
||||
|
||||
#ifndef BSL_DETAILS_IOCTL_WINDOWS_HPP
|
||||
#define BSL_DETAILS_IOCTL_WINDOWS_HPP
|
||||
|
||||
#include "../../../debug.hpp"
|
||||
#include "../../../move.hpp"
|
||||
#include "../../../safe_integral.hpp"
|
||||
#include "../../../swap.hpp"
|
||||
|
||||
#include <SetupAPI.h>
|
||||
#include <Windows.h>
|
||||
#undef max
|
||||
#undef min
|
||||
|
||||
namespace bsl
|
||||
{
|
||||
/// @class bsl::ioctl
|
||||
///
|
||||
/// <!-- description -->
|
||||
/// @brief Executes IOCTL commands to a driver.
|
||||
///
|
||||
class ioctl final
|
||||
{
|
||||
/// @brief stores a handle to the device driver.
|
||||
HANDLE m_hndl{};
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Swaps *this with other
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param lhs the left hand side of the exchange
|
||||
/// @param rhs the right hand side of the exchange
|
||||
///
|
||||
static constexpr auto
|
||||
private_swap(ioctl &lhs, ioctl &rhs) noexcept -> void
|
||||
{
|
||||
bsl::swap(lhs.m_hndl, rhs.m_hndl);
|
||||
}
|
||||
|
||||
public:
|
||||
/// <!-- description -->
|
||||
/// @brief Creates a bsl::ioctl that can be used to communicate
|
||||
/// with a device driver through an IOCTL interface.
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param name the name of the device driver to IOCTL.
|
||||
///
|
||||
template<typename GUID>
|
||||
explicit ioctl(GUID name) noexcept
|
||||
{
|
||||
BOOL ret{};
|
||||
DWORD size{};
|
||||
HANDLE info{};
|
||||
SP_INTERFACE_DEVICE_DETAIL_DATA *dev_data{};
|
||||
|
||||
SP_DEVINFO_DATA dev_info{};
|
||||
dev_info.cbSize = sizeof(SP_DEVINFO_DATA);
|
||||
|
||||
SP_INTERFACE_DEVICE_DATA if_info{};
|
||||
if_info.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
|
||||
|
||||
info = SetupDiGetClassDevs(&name, 0, 0, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
|
||||
if (INVALID_HANDLE_VALUE == info) {
|
||||
bsl::error() << "SetupDiGetClassDevs failed\n";
|
||||
return;
|
||||
}
|
||||
|
||||
ret = SetupDiEnumDeviceInfo(info, 0, &dev_info);
|
||||
if (ret == FALSE) {
|
||||
bsl::error() << "SetupDiEnumDeviceInfo failed\n";
|
||||
bsl::discard(CloseHandle(info));
|
||||
return;
|
||||
}
|
||||
|
||||
ret = SetupDiEnumDeviceInterfaces(info, &dev_info, &(name), 0, &if_info);
|
||||
if (ret == FALSE) {
|
||||
bsl::error() << "SetupDiEnumDeviceInterfaces failed\n";
|
||||
bsl::discard(CloseHandle(info));
|
||||
return;
|
||||
}
|
||||
|
||||
ret = SetupDiGetDeviceInterfaceDetail(info, &if_info, nullptr, 0, &size, nullptr);
|
||||
if (ret == FALSE) {
|
||||
bsl::error() << "SetupDiGetDeviceInterfaceDetail failed\n";
|
||||
bsl::discard(CloseHandle(info));
|
||||
return;
|
||||
}
|
||||
|
||||
dev_data = static_cast<SP_INTERFACE_DEVICE_DETAIL_DATA *>(malloc(size));
|
||||
if (nullptr == dev_data) {
|
||||
bsl::error() << "malloc failed in ioctl\n";
|
||||
bsl::discard(CloseHandle(info));
|
||||
return;
|
||||
}
|
||||
|
||||
dev_data->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
|
||||
|
||||
ret = SetupDiGetDeviceInterfaceDetail(info, &if_info, dev_data, size, nullptr, nullptr);
|
||||
if (ret == FALSE) {
|
||||
bsl::error() << "SetupDiGetDeviceInterfaceDetail failed\n";
|
||||
free(dev_data);
|
||||
bsl::discard(CloseHandle(info));
|
||||
return;
|
||||
}
|
||||
|
||||
m_hndl = CreateFile(
|
||||
dev_data->DevicePath,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
nullptr,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
nullptr);
|
||||
|
||||
free(dev_data);
|
||||
bsl::discard(CloseHandle(info));
|
||||
|
||||
if (nullptr == m_hndl) {
|
||||
bsl::error() << "ioctl CreateFile failed\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Destructor
|
||||
///
|
||||
~ioctl() noexcept
|
||||
{
|
||||
if (nullptr != m_hndl) {
|
||||
bsl::discard(CloseHandle(m_hndl));
|
||||
}
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief copy constructor
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param o the object being copied
|
||||
///
|
||||
constexpr ioctl(ioctl const &o) noexcept = delete;
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief move constructor
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param o the object being moved
|
||||
///
|
||||
constexpr ioctl(ioctl &&o) noexcept : m_hndl{bsl::move(o.m_hndl)}
|
||||
{
|
||||
o.m_hndl = nullptr;
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief copy assignment
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param o the object being copied
|
||||
/// @return a reference to *this
|
||||
///
|
||||
[[maybe_unused]] constexpr auto operator=(ioctl const &o) &noexcept -> ioctl & = delete;
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief move assignment
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @param o the object being moved
|
||||
/// @return a reference to *this
|
||||
///
|
||||
[[maybe_unused]] auto
|
||||
operator=(ioctl &&o) &noexcept -> ioctl &
|
||||
{
|
||||
ioctl tmp{bsl::move(o)};
|
||||
this->private_swap(*this, tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Sends a request to the driver without read or writing
|
||||
/// data.
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @tparam REQUEST the type of request
|
||||
/// @param req the request
|
||||
/// @return Returns true if the IOCTL succeeded, false otherwise.
|
||||
///
|
||||
template<typename REQUEST>
|
||||
[[nodiscard]] constexpr auto
|
||||
send(bsl::safe_integral<REQUEST> const &req) const noexcept -> bool
|
||||
{
|
||||
if (nullptr == m_hndl) {
|
||||
bsl::error() << "failed to send, ioctl not properly initialized\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD bytes{};
|
||||
if (!DeviceIoControl(m_hndl, req.get(), nullptr, 0, nullptr, 0, &bytes, nullptr)) {
|
||||
bsl::error() << "DeviceIoControl failed\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Reads data from the device driver
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @tparam REQUEST the type of request
|
||||
/// @param req the request
|
||||
/// @param data a pointer to read data to
|
||||
/// @param size the size of the buffer being read to
|
||||
/// @return Returns true if the IOCTL succeeded, false otherwise.
|
||||
///
|
||||
template<typename REQUEST>
|
||||
[[nodiscard]] constexpr auto
|
||||
read(bsl::safe_integral<REQUEST> const &req, void *const data, safe_uintmax const &size)
|
||||
const noexcept -> bool
|
||||
{
|
||||
if (nullptr == m_hndl) {
|
||||
bsl::error() << "failed to read, ioctl not properly initialized\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD bytes{};
|
||||
if (!DeviceIoControl(m_hndl, req.get(), nullptr, 0, data, size, &bytes, nullptr)) {
|
||||
bsl::error() << "DeviceIoControl failed\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Writes data to the device driver
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @tparam REQUEST the type of request
|
||||
/// @param req the request
|
||||
/// @param data a pointer to write data from
|
||||
/// @param size the size of the buffer being written from
|
||||
/// @return Returns true if the IOCTL succeeded, false otherwise.
|
||||
///
|
||||
template<typename REQUEST>
|
||||
[[nodiscard]] constexpr auto
|
||||
write(
|
||||
bsl::safe_integral<REQUEST> const &req,
|
||||
void const *const data,
|
||||
safe_uintmax const &size) const noexcept -> bool
|
||||
{
|
||||
void *const ptr{const_cast<void *>(data)};
|
||||
;
|
||||
|
||||
if (nullptr == m_hndl) {
|
||||
bsl::error() << "failed to write, ioctl not properly initialized\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD bytes{};
|
||||
if (!DeviceIoControl(m_hndl, req.get(), ptr, size, nullptr, 0, &bytes, nullptr)) {
|
||||
bsl::error() << "DeviceIoControl failed\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Reads/writes data from/to the device driver
|
||||
///
|
||||
/// <!-- inputs/outputs -->
|
||||
/// @tparam REQUEST the type of request
|
||||
/// @param req the request
|
||||
/// @param data a pointer to read/write data to/from
|
||||
/// @param size the size of the buffer being read/written to/from
|
||||
/// @return Returns true if the IOCTL succeeded, false otherwise.
|
||||
///
|
||||
template<typename REQUEST>
|
||||
[[nodiscard]] constexpr auto
|
||||
read_write(
|
||||
bsl::safe_integral<REQUEST> const &req,
|
||||
void *const data,
|
||||
safe_uintmax const &size) const noexcept -> bool
|
||||
{
|
||||
if (nullptr == m_hndl) {
|
||||
bsl::error() << "failed to read/write, ioctl not properly initialized\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD bytes{};
|
||||
if (!DeviceIoControl(m_hndl, req.get(), data, size, data, size, &bytes, nullptr)) {
|
||||
bsl::error() << "DeviceIoControl failed\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue