summaryrefslogtreecommitdiffstats
path: root/third_party/rlbox/include/rlbox_range.hpp
blob: 3dafcbd024c976920bced318dd609585d82ef27e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once
// IWYU pragma: private, include "rlbox.hpp"
// IWYU pragma: friend "rlbox_.*\.hpp"

#include <cstdint>

#include "rlbox_types.hpp"

namespace rlbox::detail {

// Checks that a given range is either entirely in a sandbox or entirely
// outside
template<typename T_Sbx>
inline void check_range_doesnt_cross_app_sbx_boundary(const void* ptr,
                                                      size_t size)
{
  auto ptr_start_val = reinterpret_cast<uintptr_t>(ptr);
  detail::dynamic_check(
    ptr_start_val,
    "Performing memory operation memset/memcpy on a null pointer");
  auto ptr_end_val = ptr_start_val + size - 1;

  auto ptr_start = reinterpret_cast<void*>(ptr_start_val);
  auto ptr_end = reinterpret_cast<void*>(ptr_end_val);

  detail::dynamic_check(
    rlbox_sandbox<T_Sbx>::is_in_same_sandbox(ptr_start, ptr_end),
    "range has overflowed sandbox bounds");
}

}