Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os_cpu/bsd_aarch64/vm/tcg-apple-jit.h
32285 views
1
/*
2
* Apple Silicon APRR functions for JIT handling
3
*
4
* Copyright (c) 2020 osy
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
/*
21
* Credits to: https://siguza.github.io/APRR/
22
* Reversed from /usr/lib/system/libsystem_pthread.dylib
23
*/
24
25
#ifndef TCG_APPLE_JIT_H
26
#define TCG_APPLE_JIT_H
27
28
#if defined(__aarch64__) && defined(__APPLE__)
29
30
#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */
31
#define _COMM_PAGE_APRR_SUPPORT (_COMM_PAGE_START_ADDRESS + 0x10C)
32
#define _COMM_PAGE_APPR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x110)
33
#define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x118)
34
35
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
36
{
37
/* Access shared kernel page at fixed memory location. */
38
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
39
return aprr_support > 0;
40
}
41
42
/* write protect enable = write disable */
43
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
44
{
45
/* Access shared kernel page at fixed memory location. */
46
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
47
if (aprr_support == 0 || aprr_support > 3) {
48
return;
49
} else if (aprr_support == 1) {
50
__asm__ __volatile__ (
51
"mov x0, %0\n"
52
"ldr x0, [x0]\n"
53
"msr S3_4_c15_c2_7, x0\n"
54
"isb sy\n"
55
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
56
: _COMM_PAGE_APPR_WRITE_ENABLE)
57
: "memory", "x0"
58
);
59
} else {
60
__asm__ __volatile__ (
61
"mov x0, %0\n"
62
"ldr x0, [x0]\n"
63
"msr S3_6_c15_c1_5, x0\n"
64
"isb sy\n"
65
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE
66
: _COMM_PAGE_APPR_WRITE_ENABLE)
67
: "memory", "x0"
68
);
69
}
70
}
71
72
#else /* defined(__aarch64__) && defined(__APPLE__) */
73
74
static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)
75
{
76
return false;
77
}
78
79
static __attribute__((__always_inline__)) void jit_write_protect(int enabled)
80
{
81
}
82
83
#endif
84
85
#endif /* define TCG_APPLE_JIT_H */
86
87