Skip to content
Permalink
Browse files

Macros should require semi colons

  • Loading branch information
shravanrn committed Jul 20, 2019
1 parent 6e16ec0 commit 45da981e7b35d8b038260e1959f12fc27ed6ba5d
Showing with 50 additions and 46 deletions.
  1. +0 −5 .clang-format
  2. +21 −18 code/include/rlbox.hpp
  3. +4 −1 code/include/rlbox_helpers.hpp
  4. +19 −17 code/include/rlbox_range.hpp
  5. +6 −5 code/include/rlbox_wrapper_traits.hpp
@@ -115,11 +115,6 @@ Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
- BinaryOpValAndPtr
- BinaryOp
- UnaryOp
- rlbox_detail_forward_binop_to_base
- rlbox_generate_wrapper_check
TabWidth: 8
UseTab: Never
...
@@ -77,10 +77,11 @@ class tainted_base_impl
using T_Ret = decltype(ret); \
return tainted<T_Ret, T_Sbx>::internal_factory(ret); \
} \
}
} \
RLBOX_REQUIRE_SEMI_COLON

BinaryOpValAndPtr(+)
BinaryOpValAndPtr(-)
BinaryOpValAndPtr(+);
BinaryOpValAndPtr(-);

#undef BinaryOpValAndPtr

@@ -100,16 +101,17 @@ class tainted_base_impl
auto ret = raw opSymbol raw_rhs; \
using T_Ret = decltype(ret); \
return tainted<T_Ret, T_Sbx>::internal_factory(ret); \
}

BinaryOp(*)
BinaryOp(/)
BinaryOp(%)
BinaryOp(^)
BinaryOp(&)
BinaryOp(|)
BinaryOp(<<)
BinaryOp(>>)
} \
RLBOX_REQUIRE_SEMI_COLON

BinaryOp(*);
BinaryOp(/);
BinaryOp(%);
BinaryOp(^);
BinaryOp(&);
BinaryOp(|);
BinaryOp(<<);
BinaryOp(>>);

#undef BinaryOp

@@ -123,10 +125,11 @@ class tainted_base_impl
auto ret = opSymbol raw; \
using T_Ret = decltype(ret); \
return tainted<T_Ret, T_Sbx>::internal_factory(ret); \
}
} \
RLBOX_REQUIRE_SEMI_COLON

UnaryOp(-)
UnaryOp(~)
UnaryOp(-);
UnaryOp(~);

#undef UnaryOp

@@ -235,7 +238,7 @@ class tainted_base_impl
rlbox_detail_forward_to_const(operator->, T_Ret);
}

//The verifier should have the following signature for the given types
// The verifier should have the following signature for the given types
// If tainted type is simple such as int
// using T_Func = T_Ret(*)(int)
// If tainted type is a pointer to a simple type such as int*
@@ -777,7 +780,7 @@ class tainted_volatile : public tainted_base_impl<tainted_volatile, T, T_Sbx>
}

// Needed as the definition of unary & above shadows the base's binary &
rlbox_detail_forward_binop_to_base(&, T_ClassBase)
rlbox_detail_forward_binop_to_base(&, T_ClassBase);

template<typename T_RhsRef>
inline tainted_volatile<T, T_Sbx>& operator=(T_RhsRef&& val)
@@ -40,6 +40,8 @@ namespace detail {

#define RLBOX_UNUSED(...) (void)__VA_ARGS__

#define RLBOX_REQUIRE_SEMI_COLON static_assert(true)

#define if_constexpr_named(varName, ...) \
if constexpr (constexpr auto varName = __VA_ARGS__; varName)

@@ -61,7 +63,8 @@ namespace detail {
{ \
auto b = static_cast<__VA_ARGS__*>(this); \
return (*b)opSymbol rhs; \
}
} \
RLBOX_REQUIRE_SEMI_COLON

#define rlbox_detail_forward_to_const(func_name, result_type) \
using T_ConstClassPtr = std::add_pointer_t< \
@@ -9,22 +9,24 @@

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(RLBoxSandbox<T_Sbx>::is_in_same_sandbox(ptr_start, ptr_end),
"range has overflowed sandbox bounds");
}
// 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(
RLBoxSandbox<T_Sbx>::is_in_same_sandbox(ptr_start, ptr_end),
"range has overflowed sandbox bounds");
}

}
@@ -22,12 +22,13 @@ namespace rlbox::detail {
template<typename T> \
constexpr bool rlbox_is_##name##_v = \
decltype(detail_rlbox_is_##name::helper( \
std::declval<std::remove_cv_t<std::remove_reference_t<T>>*>()))::value;
std::declval<std::remove_cv_t<std::remove_reference_t<T>>*>()))::value; \
RLBOX_REQUIRE_SEMI_COLON

rlbox_generate_wrapper_check(tainted)
rlbox_generate_wrapper_check(tainted_volatile)
rlbox_generate_wrapper_check(sandbox_callback)
rlbox_generate_wrapper_check(sandbox_function)
rlbox_generate_wrapper_check(tainted);
rlbox_generate_wrapper_check(tainted_volatile);
rlbox_generate_wrapper_check(sandbox_callback);
rlbox_generate_wrapper_check(sandbox_function);

#undef rlbox_generate_wrapper_check

0 comments on commit 45da981

Please sign in to comment.
You can’t perform that action at this time.