Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os_cpu/bsd_aarch64/vm/tcg-apple-jit.h
32285 views
/*1* Apple Silicon APRR functions for JIT handling2*3* Copyright (c) 2020 osy4*5* This library is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* This library is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with this library; if not, see <http://www.gnu.org/licenses/>.17*/1819/*20* Credits to: https://siguza.github.io/APRR/21* Reversed from /usr/lib/system/libsystem_pthread.dylib22*/2324#ifndef TCG_APPLE_JIT_H25#define TCG_APPLE_JIT_H2627#if defined(__aarch64__) && defined(__APPLE__)2829#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */30#define _COMM_PAGE_APRR_SUPPORT (_COMM_PAGE_START_ADDRESS + 0x10C)31#define _COMM_PAGE_APPR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x110)32#define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x118)3334static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)35{36/* Access shared kernel page at fixed memory location. */37uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;38return aprr_support > 0;39}4041/* write protect enable = write disable */42static __attribute__((__always_inline__)) void jit_write_protect(int enabled)43{44/* Access shared kernel page at fixed memory location. */45uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;46if (aprr_support == 0 || aprr_support > 3) {47return;48} else if (aprr_support == 1) {49__asm__ __volatile__ (50"mov x0, %0\n"51"ldr x0, [x0]\n"52"msr S3_4_c15_c2_7, x0\n"53"isb sy\n"54:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE55: _COMM_PAGE_APPR_WRITE_ENABLE)56: "memory", "x0"57);58} else {59__asm__ __volatile__ (60"mov x0, %0\n"61"ldr x0, [x0]\n"62"msr S3_6_c15_c1_5, x0\n"63"isb sy\n"64:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE65: _COMM_PAGE_APPR_WRITE_ENABLE)66: "memory", "x0"67);68}69}7071#else /* defined(__aarch64__) && defined(__APPLE__) */7273static __attribute__((__always_inline__)) bool jit_write_protect_supported(void)74{75return false;76}7778static __attribute__((__always_inline__)) void jit_write_protect(int enabled)79{80}8182#endif8384#endif /* define TCG_APPLE_JIT_H */858687