RLBox
rlbox_wrapper_traits.hpp
1 #pragma once
2 // IWYU pragma: private, include "rlbox.hpp"
3 // IWYU pragma: friend "rlbox_.*\.hpp"
4 
5 #include <type_traits>
6 
7 #include "rlbox_types.hpp"
8 
9 namespace rlbox::detail {
10 
11 #define rlbox_generate_wrapper_check(name) \
12  namespace detail_rlbox_is_##name \
13  { \
14  template<typename T> \
15  struct unwrapper : std::false_type \
16  {}; \
17  \
18  template<typename T, typename T_Sbx> \
19  struct unwrapper<name<T, T_Sbx>> : std::true_type \
20  {}; \
21  } \
22  \
23  template<typename T> \
24  constexpr bool rlbox_is_##name##_v = \
25  detail_rlbox_is_##name::unwrapper<T>::value; \
26  RLBOX_REQUIRE_SEMI_COLON
27 
28 rlbox_generate_wrapper_check(tainted);
29 rlbox_generate_wrapper_check(tainted_volatile);
30 rlbox_generate_wrapper_check(tainted_opaque);
31 rlbox_generate_wrapper_check(sandbox_callback);
32 
33 #undef rlbox_generate_wrapper_check
34 
35 namespace detail_rlbox_is_tainted_boolean_hint {
36  template<typename T>
37  struct unwrapper : std::false_type
38  {};
39 
40  template<>
41  struct unwrapper<tainted_boolean_hint> : std::true_type
42  {};
43 }
44 
45 template<typename T>
46 constexpr bool rlbox_is_tainted_boolean_hint_v =
48 
49 template<typename T>
50 constexpr bool rlbox_is_tainted_or_vol_v =
51  rlbox_is_tainted_v<T> || rlbox_is_tainted_volatile_v<T>;
52 
53 template<typename T>
54 constexpr bool rlbox_is_tainted_or_opaque_v =
55  rlbox_is_tainted_v<T> || rlbox_is_tainted_opaque_v<T>;
56 
57 // tainted_hint is NOT considered a wrapper type... This carries no particular
58 // significant and is just a convention choice
59 template<typename T>
60 constexpr bool rlbox_is_wrapper_v =
61  rlbox_is_tainted_v<T> || rlbox_is_tainted_volatile_v<T> ||
62  rlbox_is_tainted_opaque_v<T> || rlbox_is_sandbox_callback_v<T>;
63 
64 namespace detail_rlbox_remove_wrapper {
65  template<typename T>
66  struct unwrapper
67  {
68  using type = T;
69  using type_sbx = void;
70  };
71 
72  template<typename T, typename T_Sbx>
73  struct unwrapper<tainted<T, T_Sbx>>
74  {
75  using type = T;
76  using type_sbx = T_Sbx;
77  };
78 
79  template<typename T, typename T_Sbx>
80  struct unwrapper<tainted_volatile<T, T_Sbx>>
81  {
82  using type = T;
83  using type_sbx = T_Sbx;
84  };
85 
86  template<typename T, typename T_Sbx>
87  struct unwrapper<tainted_opaque<T, T_Sbx>>
88  {
89  using type = T;
90  using type_sbx = T_Sbx;
91  };
92 
93  template<typename T, typename T_Sbx>
94  struct unwrapper<sandbox_callback<T, T_Sbx>>
95  {
96  using type = T;
97  using type_sbx = T_Sbx;
98  };
99 }
100 
101 template<typename T>
102 using rlbox_remove_wrapper_t =
103  typename detail_rlbox_remove_wrapper::unwrapper<T>::type;
104 
105 template<typename T>
106 using rlbox_get_wrapper_sandbox_t =
107  typename detail_rlbox_remove_wrapper::unwrapper<T>::type_sbx;
108 
109 template<typename T, typename T_Sbx>
110 using rlbox_tainted_opaque_to_tainted_t =
111  std::conditional_t<rlbox_is_tainted_opaque_v<T>,
113  T>;
114 
115 // https://stackoverflow.com/questions/34974844/check-if-a-type-is-from-a-particular-namespace
116 namespace detail_is_member_of_rlbox_detail {
117  template<typename T, typename = void>
118  struct is_member_of_rlbox_detail_helper : std::false_type
119  {};
120 
121  template<typename T>
123  T,
124  decltype(struct_is_member_of_rlbox_detail(std::declval<T>()))>
125  : std::true_type
126  {};
127 }
128 
129 template<typename T>
130 void struct_is_member_of_rlbox_detail(T&&);
131 
132 template<typename T>
133 constexpr auto is_member_of_rlbox_detail =
135 
136 // https://stackoverflow.com/questions/9644477/how-to-check-whether-a-class-has-specified-nested-class-definition-or-typedef-in
137 namespace detail_has_member_using_can_grant_deny_access {
138  template<class T, class Enable = void>
139  struct has_member_using_can_grant_deny_access : std::false_type
140  {};
141 
142  template<class T>
144  T,
145  std::void_t<typename T::can_grant_deny_access>> : std::true_type
146  {};
147 }
148 
149 template<class T>
150 constexpr bool has_member_using_can_grant_deny_access_v =
151  detail_has_member_using_can_grant_deny_access::
152  has_member_using_can_grant_deny_access<T>::value;
153 
154 }
Definition: rlbox_policy_types.hpp:37
Tainted boolean value that serves as a "hint" and not a definite answer. Comparisons with a tainted_v...
Definition: rlbox_types.hpp:34
Definition: rlbox_types.hpp:9
Tainted volatile values are like tainted values but still point to sandbox memory....
Definition: rlbox.hpp:1101
Definition: rlbox_types.hpp:22
Definition: rlbox_wrapper_traits.hpp:67