mirror of
https://github.com/Bareflank/hypervisor
synced 2026-08-17 06:23:04 -04:00
Fix issue with IOCTL interfaces
This commit is contained in:
parent
2472495b61
commit
137b29b7ec
3 changed files with 57 additions and 9 deletions
|
|
@ -52,6 +52,8 @@ macro(hypervisor_add_integration NAME HEADERS)
|
|||
${NAME}.cpp
|
||||
)
|
||||
|
||||
target_compile_options(integration_${NAME} PRIVATE -Wframe-larger-than=4294967295)
|
||||
|
||||
set_property(SOURCE ${NAME} APPEND PROPERTY OBJECT_DEPENDS ${${HEADERS}})
|
||||
|
||||
target_link_libraries(integration_${NAME} PRIVATE
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include <bsl/convert.hpp>
|
||||
#include <bsl/debug.hpp>
|
||||
#include <bsl/discard.hpp>
|
||||
#include <bsl/exchange.hpp>
|
||||
#include <bsl/expects.hpp>
|
||||
#include <bsl/safe_integral.hpp>
|
||||
#include <bsl/string_view.hpp>
|
||||
|
|
@ -55,6 +56,11 @@ namespace lib
|
|||
bsl::safe_i32 m_hndl{IOCTL_INVALID_HNDL};
|
||||
|
||||
public:
|
||||
/// <!-- description -->
|
||||
/// @brief Default constructor
|
||||
///
|
||||
constexpr ioctl() noexcept = default;
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Creates a lib::ioctl that can be used to communicate
|
||||
/// with a device driver through an IOCTL interface.
|
||||
|
|
@ -83,10 +89,12 @@ namespace lib
|
|||
///
|
||||
explicit constexpr ioctl(bsl::safe_i32 const hndl) noexcept
|
||||
{
|
||||
bsl::expects(IOCTL_INVALID_HNDL != hndl);
|
||||
bsl::expects(hndl.is_pos());
|
||||
|
||||
m_hndl = hndl;
|
||||
if (hndl.is_neg()) {
|
||||
m_hndl = IOCTL_INVALID_HNDL;
|
||||
}
|
||||
else {
|
||||
m_hndl = hndl;
|
||||
}
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
|
|
@ -111,7 +119,9 @@ namespace lib
|
|||
/// <!-- inputs/outputs -->
|
||||
/// @param mut_o the object being moved
|
||||
///
|
||||
constexpr ioctl(ioctl &&mut_o) noexcept = delete;
|
||||
constexpr ioctl(ioctl &&mut_o) noexcept
|
||||
: m_hndl{bsl::exchange(mut_o.m_hndl, IOCTL_INVALID_HNDL)}
|
||||
{}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief copy assignment
|
||||
|
|
@ -129,7 +139,22 @@ namespace lib
|
|||
/// @param mut_o the object being moved
|
||||
/// @return a reference to *this
|
||||
///
|
||||
[[maybe_unused]] constexpr auto operator=(ioctl &&mut_o) &noexcept -> ioctl & = delete;
|
||||
[[maybe_unused]] constexpr auto
|
||||
operator=(ioctl &&mut_o) &noexcept -> ioctl &
|
||||
{
|
||||
/// NOTE:
|
||||
/// - For now we do not use the swap technique that AUTOSAR wants
|
||||
/// you to use because we actually need an exchange since we
|
||||
/// are implementing something closer to a unique_ptr.
|
||||
///
|
||||
|
||||
if (this == &mut_o) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
m_hndl = bsl::exchange(mut_o.m_hndl, IOCTL_INVALID_HNDL);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Closes the IOCTL
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
|
||||
// clang-format on
|
||||
|
||||
#include <bsl/exchange.hpp>
|
||||
#include <bsl/debug.hpp>
|
||||
#include <bsl/move.hpp>
|
||||
#include <bsl/safe_integral.hpp>
|
||||
|
|
@ -59,6 +60,11 @@ namespace lib
|
|||
HANDLE m_hndl{};
|
||||
|
||||
public:
|
||||
/// <!-- description -->
|
||||
/// @brief Default constructor
|
||||
///
|
||||
constexpr ioctl() noexcept = default;
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Creates a lib::ioctl that can be used to communicate
|
||||
/// with a device driver through an IOCTL interface.
|
||||
|
|
@ -156,7 +162,6 @@ namespace lib
|
|||
///
|
||||
explicit constexpr ioctl(HANDLE const hndl) noexcept
|
||||
{
|
||||
bsl::expects(nullptr != hndl);
|
||||
m_hndl = hndl;
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +186,8 @@ namespace lib
|
|||
/// <!-- inputs/outputs -->
|
||||
/// @param mut_o the object being moved
|
||||
///
|
||||
constexpr ioctl(ioctl &&mut_o) noexcept = delete;
|
||||
constexpr ioctl(ioctl &&mut_o) noexcept : m_hndl{bsl::exchange(mut_o.m_hndl, nullptr)}
|
||||
{}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief copy assignment
|
||||
|
|
@ -199,7 +205,22 @@ namespace lib
|
|||
/// @param mut_o the object being moved
|
||||
/// @return a reference to *this
|
||||
///
|
||||
[[maybe_unused]] constexpr auto operator=(ioctl &&mut_o) &noexcept -> ioctl & = delete;
|
||||
[[maybe_unused]] constexpr auto
|
||||
operator=(ioctl &&mut_o) &noexcept -> ioctl &
|
||||
{
|
||||
/// NOTE:
|
||||
/// - For now we do not use the swap technique that AUTOSAR wants
|
||||
/// you to use because we actually need an exchange since we
|
||||
/// are implementing something closer to a unique_ptr.
|
||||
///
|
||||
|
||||
if (this == &mut_o) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
m_hndl = bsl::exchange(mut_o.m_hndl, IOCTL_INVALID_HNDL);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// <!-- description -->
|
||||
/// @brief Closes the IOCTL
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue