Alexandre Rames | b78f139 | 2016-07-01 14:22:22 +0100 | [diff] [blame] | 1 | // Copyright 2015, VIXL authors |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are met: |
| 6 | // |
| 7 | // * Redistributions of source code must retain the above copyright notice, |
| 8 | // this list of conditions and the following disclaimer. |
| 9 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer in the documentation |
| 11 | // and/or other materials provided with the distribution. |
| 12 | // * Neither the name of ARM Limited nor the names of its contributors may be |
| 13 | // used to endorse or promote products derived from this software without |
| 14 | // specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND |
| 17 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 20 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | |
| 27 | #include "test-utils.h" |
| 28 | |
Jacob Bramley | 4893432 | 2019-02-04 18:27:53 +0000 | [diff] [blame] | 29 | #include <string.h> |
| 30 | |
Pierre Langlois | 78973f2 | 2016-08-10 14:35:56 +0100 | [diff] [blame] | 31 | extern "C" { |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 32 | #include <sys/mman.h> |
Pierre Langlois | 78973f2 | 2016-08-10 14:35:56 +0100 | [diff] [blame] | 33 | } |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 34 | |
| 35 | #include "globals-vixl.h" |
Jacob Bramley | 4893432 | 2019-02-04 18:27:53 +0000 | [diff] [blame] | 36 | |
| 37 | #ifdef VIXL_INCLUDE_TARGET_AARCH64 |
Alexandre Rames | d383296 | 2016-07-04 15:03:43 +0100 | [diff] [blame] | 38 | #include "aarch64/cpu-aarch64.h" |
Jacob Bramley | 4893432 | 2019-02-04 18:27:53 +0000 | [diff] [blame] | 39 | #endif |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 40 | |
| 41 | namespace vixl { |
| 42 | |
Alexandre Rames | 2b5d561 | 2016-07-25 14:14:22 +0100 | [diff] [blame] | 43 | // BSD uses `MAP_ANON` instead of the Linux `MAP_ANONYMOUS`. The `MAP_ANONYMOUS` |
| 44 | // alias should generally be available, but is not always, so define it manually |
| 45 | // if necessary. |
| 46 | #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) |
| 47 | #define MAP_ANONYMOUS MAP_ANON |
| 48 | #endif |
| 49 | |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 50 | |
Jacob Bramley | 4893432 | 2019-02-04 18:27:53 +0000 | [diff] [blame] | 51 | void ExecuteMemory(byte* buffer, size_t size, int byte_offset) { |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 52 | void (*test_function)(void); |
| 53 | |
Jacob Bramley | 4893432 | 2019-02-04 18:27:53 +0000 | [diff] [blame] | 54 | VIXL_ASSERT((byte_offset >= 0) && (static_cast<size_t>(byte_offset) < size)); |
Alex Gilday | 31dd2ae | 2016-07-05 16:34:41 +0100 | [diff] [blame] | 55 | VIXL_STATIC_ASSERT(sizeof(buffer) == sizeof(test_function)); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 56 | VIXL_STATIC_ASSERT(sizeof(uintptr_t) == sizeof(test_function)); |
Alex Gilday | 31dd2ae | 2016-07-05 16:34:41 +0100 | [diff] [blame] | 57 | uintptr_t entry_point = reinterpret_cast<uintptr_t>(buffer); |
Jacob Bramley | 4893432 | 2019-02-04 18:27:53 +0000 | [diff] [blame] | 58 | entry_point += byte_offset; |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 59 | memcpy(&test_function, &entry_point, sizeof(test_function)); |
| 60 | |
Alex Gilday | 31dd2ae | 2016-07-05 16:34:41 +0100 | [diff] [blame] | 61 | USE(size); |
| 62 | |
Pierre Langlois | dd63b6b | 2016-12-19 13:22:33 +0000 | [diff] [blame] | 63 | #if defined(__aarch64__) && defined(VIXL_INCLUDE_TARGET_AARCH64) |
Alex Gilday | 31dd2ae | 2016-07-05 16:34:41 +0100 | [diff] [blame] | 64 | aarch64::CPU::EnsureIAndDCacheCoherency(buffer, size); |
Rodolph Perfetta | 9a9331f | 2016-12-09 22:05:48 +0000 | [diff] [blame] | 65 | #elif defined(__arm__) && \ |
Pierre Langlois | bde2e4b | 2017-01-24 17:41:26 +0000 | [diff] [blame] | 66 | (defined(VIXL_INCLUDE_TARGET_A32) || defined(VIXL_INCLUDE_TARGET_T32)) |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 67 | // TODO: Do not use __builtin___clear_cache and instead implement |
| 68 | // `CPU::EnsureIAndDCacheCoherency` for aarch32. |
Alex Gilday | 31dd2ae | 2016-07-05 16:34:41 +0100 | [diff] [blame] | 69 | __builtin___clear_cache(buffer, reinterpret_cast<char*>(buffer) + size); |
Jacob Bramley | 4893432 | 2019-02-04 18:27:53 +0000 | [diff] [blame] | 70 | #else |
| 71 | // This helper requires a native (non-Simulator) environment. |
| 72 | VIXL_ABORT_WITH_MSG("Cannot ExecuteMemory(...): unsupported platform."); |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 73 | #endif |
| 74 | test_function(); |
| 75 | } |
| 76 | |
| 77 | } // namespace vixl |