提交 5d801298 编写于 作者: B Behdad Esfahbod

Add CrapPool

Common Regoin for Access Protection.  Like the NullPool, but writable.
上级 673b764d
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#ifndef HB_NO_VISIBILITY #ifndef HB_NO_VISIBILITY
const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
#endif #endif
void cbdt_callback (const uint8_t* data, unsigned int length, void cbdt_callback (const uint8_t* data, unsigned int length,
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#ifndef HB_NO_VISIBILITY #ifndef HB_NO_VISIBILITY
const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
#endif #endif
template <typename Type, int Bytes> struct LEInt; template <typename Type, int Bytes> struct LEInt;
......
...@@ -932,6 +932,7 @@ struct ArrayOf ...@@ -932,6 +932,7 @@ struct ArrayOf
} }
inline Type& operator [] (unsigned int i) inline Type& operator [] (unsigned int i)
{ {
if (unlikely (i >= len)) return Crap(Type);
return arrayZ[i]; return arrayZ[i];
} }
inline unsigned int get_size (void) const inline unsigned int get_size (void) const
...@@ -1040,6 +1041,11 @@ struct OffsetListOf : OffsetArrayOf<Type> ...@@ -1040,6 +1041,11 @@ struct OffsetListOf : OffsetArrayOf<Type>
if (unlikely (i >= this->len)) return Null(Type); if (unlikely (i >= this->len)) return Null(Type);
return this+this->arrayZ[i]; return this+this->arrayZ[i];
} }
inline const Type& operator [] (unsigned int i)
{
if (unlikely (i >= this->len)) return Crap(Type);
return this+this->arrayZ[i];
}
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ {
...@@ -1064,6 +1070,11 @@ struct HeadlessArrayOf ...@@ -1064,6 +1070,11 @@ struct HeadlessArrayOf
if (unlikely (i >= len || !i)) return Null(Type); if (unlikely (i >= len || !i)) return Null(Type);
return arrayZ[i-1]; return arrayZ[i-1];
} }
inline Type& operator [] (unsigned int i)
{
if (unlikely (i >= len || !i)) return Crap(Type);
return arrayZ[i-1];
}
inline unsigned int get_size (void) const inline unsigned int get_size (void) const
{ return len.static_size + (len ? len - 1 : 0) * Type::static_size; } { return len.static_size + (len ? len - 1 : 0) * Type::static_size; }
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#ifndef HB_NO_VISIBILITY #ifndef HB_NO_VISIBILITY
const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
#endif #endif
......
...@@ -529,7 +529,7 @@ _hb_ceil_to_4 (unsigned int v) ...@@ -529,7 +529,7 @@ _hb_ceil_to_4 (unsigned int v)
*/ */
/* /*
* Null objects * Static pools
*/ */
/* Global nul-content Null pool. Enlarge as necessary. */ /* Global nul-content Null pool. Enlarge as necessary. */
...@@ -547,7 +547,6 @@ const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] ...@@ -547,7 +547,6 @@ const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)]
= {} = {}
#endif #endif
; ;
/* Generic nul-content Null objects. */ /* Generic nul-content Null objects. */
template <typename Type> template <typename Type>
static inline const Type& Null (void) { static inline const Type& Null (void) {
...@@ -569,6 +568,28 @@ namespace Namespace { \ ...@@ -569,6 +568,28 @@ namespace Namespace { \
static_assert (Namespace::Type::min_size + 1 <= sizeof (_Null##Type), "Null pool too small. Enlarge.") static_assert (Namespace::Type::min_size + 1 <= sizeof (_Null##Type), "Null pool too small. Enlarge.")
/* Global writable pool. Enlarge as necessary. */
#ifdef HB_NO_VISIBILITY
static
#else
extern HB_INTERNAL
#endif
void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)]
#ifdef HB_NO_VISIBILITY
= {}
#endif
;
/* CRAP pool: Common Region for Access Protection. */
template <typename Type>
static inline Type& Crap (void) {
static_assert (sizeof (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE.");
Type *obj = reinterpret_cast<Type *> (_hb_CrapPool);
*obj = Null(Type);
return *obj;
}
#define Crap(Type) Crap<Type>()
/* arrays and maps */ /* arrays and maps */
...@@ -589,8 +610,18 @@ struct hb_vector_t ...@@ -589,8 +610,18 @@ struct hb_vector_t
arrayZ = static_array; arrayZ = static_array;
} }
inline Type& operator [] (unsigned int i) { return arrayZ[i]; } inline Type& operator [] (unsigned int i)
inline const Type& operator [] (unsigned int i) const { return arrayZ[i]; } {
if (unlikely (i >= len))
return Crap (Type);
return arrayZ[i];
}
inline const Type& operator [] (unsigned int i) const
{
if (unlikely (i >= len))
return Null (Type);
return arrayZ[i];
}
inline Type *push (void) inline Type *push (void)
{ {
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#if !defined(HB_NO_VISIBILITY) && !defined(HB_SUBSET_BUILTIN) #if !defined(HB_NO_VISIBILITY) && !defined(HB_SUBSET_BUILTIN)
const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
#endif #endif
......
...@@ -39,6 +39,7 @@ using namespace OT; ...@@ -39,6 +39,7 @@ using namespace OT;
#ifndef HB_NO_VISIBILITY #ifndef HB_NO_VISIBILITY
const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {}; const void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
#endif #endif
int int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册