blob: 5d08ab4ac757672dc23314645942e2103852f870 [file] [log] [blame]
Alexandre Ramesb78f1392016-07-01 14:22:22 +01001// Copyright 2015, VIXL authors
Pierre Langlois88c46b82016-06-02 18:15:32 +01002// 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
Pierre Langlois78973f22016-08-10 14:35:56 +010029extern "C" {
Pierre Langlois88c46b82016-06-02 18:15:32 +010030#include <sys/mman.h>
Pierre Langlois78973f22016-08-10 14:35:56 +010031}
Pierre Langlois88c46b82016-06-02 18:15:32 +010032
33#include "globals-vixl.h"
Alexandre Ramesd3832962016-07-04 15:03:43 +010034#include "aarch64/cpu-aarch64.h"
Pierre Langlois88c46b82016-06-02 18:15:32 +010035
36namespace vixl {
37
Alexandre Rames2b5d5612016-07-25 14:14:22 +010038// BSD uses `MAP_ANON` instead of the Linux `MAP_ANONYMOUS`. The `MAP_ANONYMOUS`
39// alias should generally be available, but is not always, so define it manually
40// if necessary.
41#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
42#define MAP_ANONYMOUS MAP_ANON
43#endif
44
Pierre Langlois88c46b82016-06-02 18:15:32 +010045
Alex Gilday31dd2ae2016-07-05 16:34:41 +010046void ExecuteMemory(byte* buffer, size_t size, int offset) {
Pierre Langlois88c46b82016-06-02 18:15:32 +010047 void (*test_function)(void);
48
Alex Gilday31dd2ae2016-07-05 16:34:41 +010049 VIXL_ASSERT((offset >= 0) && (static_cast<size_t>(offset) < size));
50 VIXL_STATIC_ASSERT(sizeof(buffer) == sizeof(test_function));
Pierre Langlois88c46b82016-06-02 18:15:32 +010051 VIXL_STATIC_ASSERT(sizeof(uintptr_t) == sizeof(test_function));
Alex Gilday31dd2ae2016-07-05 16:34:41 +010052 uintptr_t entry_point = reinterpret_cast<uintptr_t>(buffer);
Pierre Langlois88c46b82016-06-02 18:15:32 +010053 entry_point += offset;
54 memcpy(&test_function, &entry_point, sizeof(test_function));
55
Alex Gilday31dd2ae2016-07-05 16:34:41 +010056 USE(size);
57
Pierre Langloisdd63b6b2016-12-19 13:22:33 +000058#if defined(__aarch64__) && defined(VIXL_INCLUDE_TARGET_AARCH64)
Alex Gilday31dd2ae2016-07-05 16:34:41 +010059 aarch64::CPU::EnsureIAndDCacheCoherency(buffer, size);
Rodolph Perfetta9a9331f2016-12-09 22:05:48 +000060#elif defined(__arm__) && \
Pierre Langloisbde2e4b2017-01-24 17:41:26 +000061 (defined(VIXL_INCLUDE_TARGET_A32) || defined(VIXL_INCLUDE_TARGET_T32))
Pierre Langlois88c46b82016-06-02 18:15:32 +010062 // TODO: Do not use __builtin___clear_cache and instead implement
63 // `CPU::EnsureIAndDCacheCoherency` for aarch32.
Alex Gilday31dd2ae2016-07-05 16:34:41 +010064 __builtin___clear_cache(buffer, reinterpret_cast<char*>(buffer) + size);
Pierre Langlois88c46b82016-06-02 18:15:32 +010065#endif
66 test_function();
67}
68
69} // namespace vixl