예제 #1
0
#define GSL_THROW_ON_CONTRACT_VIOLATION
#define NO_INFO 1
#include <common.cxx>
#include <iostream>
#include <kernel/memmap.hpp>

CASE ("Using the fixed memory range class")
{
    GIVEN ("A fixed memory range over raw sequence of bytes")
    {
      // A dynamically allocated "raw pool" of bytes
      // @note : In the kernel memory map these would be physical ranges
      char* seq = const_cast<char*>("Spans provide a safer way to access memory");
      Fixed_memory_range range(reinterpret_cast<uintptr_t>(seq + 16),
                                 reinterpret_cast<uintptr_t>(seq + 20), "Demo range",
                               "A range inside a local pool");

      auto seq_start = seq + 16;
      auto seq_end = seq + 20;
      EXPECT(range.size() == seq_end - seq_start + 1);
      EXPECT(std::string(range.name()) == std::string("Demo range"));

      THEN("You can iterate safely over that range, and not out of bounds"){
        for (auto i : range)
          EXPECT(i);

        auto i = range.begin();
        for (; i != range.end(); i++)
          EXPECT(*i);
예제 #2
0
 bool overlaps(const Fixed_memory_range& other) const {
   // Other range overlaps with my range
   return in_range(other.addr_start()) or in_range(other.addr_end())
     // Or my range is inside other range
     or (other.in_range(addr_start()) and other.in_range(addr_end()));
 }
예제 #3
0
bool Fixed_memory_range::overlaps(const Fixed_memory_range& other) const noexcept {
  return (in_range(other.addr_start()) or in_range(other.addr_end()))   //< Other range overlaps with my range
      or (other.in_range(addr_start()) and other.in_range(addr_end())); //< My range is inside other range
}