From c069a30d42aefd902c20e8bc09dfad1683f07ded Mon Sep 17 00:00:00 2001 From: Orion Hodson Date: Wed, 18 Jan 2017 09:23:12 +0000 Subject: ART: invoke-custom support Adds invoke-custom instruction to the interpreter. Bug: 33191717,30550796 Test: art/test/run-test --host 952 Change-Id: I3b754128649a8b3a00ade79ba2518d0e377f3a1e --- runtime/utils.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'runtime/utils.h') 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 +inline static T BoundsCheckedCast(const void* pointer, + const void* lower, + const void* upper) { + const uint8_t* bound_begin = static_cast(lower); + const uint8_t* bound_end = static_cast(upper); + DCHECK(bound_begin <= bound_end); + + T result = reinterpret_cast(pointer); + const uint8_t* begin = static_cast(pointer); + const uint8_t* end = begin + sizeof(*result); + if (begin < bound_begin || end > bound_end || begin > end) { + return nullptr; + } + return result; +} + +template +constexpr size_t ArrayCount(const T (&)[size]) { + return size; +} + } // namespace art #endif // ART_RUNTIME_UTILS_H_ -- cgit v1.2.3-59-g8ed1b