1 2 #pragma once 3 // IWYU pragma: private, include "rlbox.hpp" 4 // IWYU pragma: friend "rlbox_.*\.hpp" 5 6 #include <cstdint> 7 8 #include "rlbox_types.hpp" 9 10 namespace rlbox::detail { 11 12 // Checks that a given range is either entirely in a sandbox or entirely 13 // outside 14 template<typename T_Sbx> check_range_doesnt_cross_app_sbx_boundary(const void * ptr,size_t size)15inline void check_range_doesnt_cross_app_sbx_boundary(const void* ptr, 16 size_t size) 17 { 18 auto ptr_start_val = reinterpret_cast<uintptr_t>(ptr); 19 detail::dynamic_check( 20 ptr_start_val, 21 "Performing memory operation memset/memcpy on a null pointer"); 22 auto ptr_end_val = ptr_start_val + size - 1; 23 24 auto ptr_start = reinterpret_cast<void*>(ptr_start_val); 25 auto ptr_end = reinterpret_cast<void*>(ptr_end_val); 26 27 detail::dynamic_check( 28 rlbox_sandbox<T_Sbx>::is_in_same_sandbox(ptr_start, ptr_end), 29 "range has overflowed sandbox bounds"); 30 } 31 32 }