[vm/ios] Don't use __clear_cache on iOS, it's not always available.

Change-Id: Ia80b543587b3dc265c4a4d97befff73d915ad2be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110560
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Samir Jindel <sjindel@google.com>
This commit is contained in:
Samir Jindel 2019-08-01 14:14:39 +00:00 committed by commit-bot@chromium.org
parent 7825801189
commit 0ea0409401
2 changed files with 26 additions and 6 deletions

View file

@ -15,6 +15,10 @@
#include "vm/object.h"
#include "vm/simulator.h"
#if defined(HOST_OS_IOS)
#include <libkern/OSCacheControl.h>
#endif
#if !defined(TARGET_HOST_MISMATCH)
#include <sys/syscall.h> /* NOLINT */
#include <unistd.h> /* NOLINT */
@ -91,7 +95,9 @@ DEFINE_FLAG(bool, sim_use_hardfp, true, "Use the hardfp ABI.");
#endif
void CPU::FlushICache(uword start, uword size) {
#if !defined(TARGET_HOST_MISMATCH) && HOST_ARCH_ARM
#if defined(DART_PRECOMPILED_RUNTIME)
UNREACHABLE();
#elif !defined(TARGET_HOST_MISMATCH) && HOST_ARCH_ARM
// Nothing to do. Flushing no instructions.
if (size == 0) {
return;
@ -102,8 +108,12 @@ void CPU::FlushICache(uword start, uword size) {
//
// https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/caches-and-self-modifying-code
//
// On iOS we can use ::__clear_cache from Clang.
#if (defined(__linux__) && !defined(ANDROID)) || defined(TARGET_OS_IOS)
// On iOS we use sys_icache_invalidate from Darwin. See:
//
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/sys_icache_invalidate.3.html
#if defined(HOST_OS_IOS)
sys_icache_invalidate(reinterpret_cast<void*>(start), size);
#elif defined(__linux__) && !defined(ANDROID)
extern void __clear_cache(char*, char*);
char* beg = reinterpret_cast<char*>(start);
char* end = reinterpret_cast<char*>(start + size);

View file

@ -20,10 +20,16 @@
#include <unistd.h>
#endif
#if defined(HOST_OS_IOS)
#include <libkern/OSCacheControl.h>
#endif
namespace dart {
void CPU::FlushICache(uword start, uword size) {
#if !defined(USING_SIMULATOR)
#if defined(DART_PRECOMPILED_RUNTIME)
UNREACHABLE();
#elif !defined(USING_SIMULATOR)
// Nothing to do. Flushing no instructions.
if (size == 0) {
return;
@ -33,8 +39,12 @@ void CPU::FlushICache(uword start, uword size) {
//
// https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/caches-and-self-modifying-code
//
// On iOS we can use ::__clear_cache from Clang.
#if defined(HOST_OS_ANDROID) || defined(HOST_OS_LINUX) || defined(HOST_OS_IOS)
// On iOS we use sys_icache_invalidate from Darwin. See:
//
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/sys_icache_invalidate.3.html
#if defined(HOST_OS_IOS)
sys_icache_invalidate(reinterpret_cast<void*>(start), size);
#elif defined(HOST_OS_ANDROID) || defined(HOST_OS_LINUX)
extern void __clear_cache(char*, char*);
char* beg = reinterpret_cast<char*>(start);
char* end = reinterpret_cast<char*>(start + size);