diff options
author | 2017-01-18 09:23:12 +0000 | |
---|---|---|
committer | 2017-02-14 14:04:33 +0000 | |
commit | c069a30d42aefd902c20e8bc09dfad1683f07ded (patch) | |
tree | 8bbf72bea7ea5d243b57f8e0ab64b687a9f60e4b /runtime/utils.h | |
parent | 3f38398380b80d1ded078ebed1211b7e4f51460f (diff) |
ART: invoke-custom support
Adds invoke-custom instruction to the interpreter.
Bug: 33191717,30550796
Test: art/test/run-test --host 952
Change-Id: I3b754128649a8b3a00ade79ba2518d0e377f3a1e
Diffstat (limited to 'runtime/utils.h')
-rw-r--r-- | runtime/utils.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/runtime/utils.h b/runtime/utils.h index 67438b5881..96e5bfa8ec 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -301,6 +301,30 @@ constexpr PointerSize ConvertToPointerSize(T any) { } } +// Returns a type cast pointer if object pointed to is within the provided bounds. +// Otherwise returns nullptr. +template <typename T> +inline static T BoundsCheckedCast(const void* pointer, + const void* lower, + const void* upper) { + const uint8_t* bound_begin = static_cast<const uint8_t*>(lower); + const uint8_t* bound_end = static_cast<const uint8_t*>(upper); + DCHECK(bound_begin <= bound_end); + + T result = reinterpret_cast<T>(pointer); + const uint8_t* begin = static_cast<const uint8_t*>(pointer); + const uint8_t* end = begin + sizeof(*result); + if (begin < bound_begin || end > bound_end || begin > end) { + return nullptr; + } + return result; +} + +template <typename T, size_t size> +constexpr size_t ArrayCount(const T (&)[size]) { + return size; +} + } // namespace art #endif // ART_RUNTIME_UTILS_H_ |