MCPcopy Create free account
hub / github.com/Bareflank/hypervisor / get_callback

Function get_callback

kernel/src/dispatch_syscall_helpers.hpp:565–601  ·  view source on GitHub ↗

<!-- description --> @brief Given an input register, returns a callback address on success, or bsl::safe_umx::failure() on failure. <!-- inputs/outputs --> @param reg the register to get the vmid from. @return Given an input register, returns a callback address on success, or bsl::safe_umx::failure() on failure.

Source from the content-addressed store, hash-verified

563 /// success, or bsl::safe_umx::failure() on failure.
564 ///
565 [[nodiscard]] constexpr auto
566 // NOLINTNEXTLINE(bsl-non-safe-integral-types-are-forbidden)
567 get_callback(bsl::uint64 const reg) noexcept -> bsl::safe_umx
568 {
569 constexpr auto min_addr{HYPERVISOR_EXT_CODE_ADDR};
570 constexpr auto max_addr{(min_addr + HYPERVISOR_EXT_CODE_SIZE).checked()};
571
572 /// NOTE:
573 /// - There is no way to know if the provided address actually points
574 /// to a function that performs the action that is supposed to be
575 /// handled, but we can at least ensure the address is in the
576 /// right range as a sanity check.
577 ///
578
579 auto const addr{bsl::to_umx(reg)};
580 if (bsl::unlikely(addr < min_addr)) {
581 bsl::error() << "the provided callback address " // --
582 << bsl::hex(addr) // --
583 << " is out of range" // --
584 << bsl::endl // --
585 << bsl::here(); // --
586
587 return bsl::safe_umx::failure();
588 }
589
590 if (bsl::unlikely(addr >= max_addr)) {
591 bsl::error() << "the provided callback address " // --
592 << bsl::hex(addr) // --
593 << " is out of range" // --
594 << bsl::endl // --
595 << bsl::here(); // --
596
597 return bsl::safe_umx::failure();
598 }
599
600 return addr;
601 }
602
603 /// <!-- description -->
604 /// @brief Given an input register, returns a ppid if the provided

Calls

no outgoing calls

Tested by

no test coverage detected