1214152Sed/* ===-- clear_cache.c - Implement __clear_cache ---------------------------===
2214152Sed *
3214152Sed *                     The LLVM Compiler Infrastructure
4214152Sed *
5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open
6222656Sed * Source Licenses. See LICENSE.TXT for details.
7214152Sed *
8214152Sed * ===----------------------------------------------------------------------===
9214152Sed */
10214152Sed
11215125Sed#include "int_lib.h"
12214152Sed
13214152Sed#if __APPLE__
14214152Sed  #include <libkern/OSCacheControl.h>
15214152Sed#endif
16214152Sed
17214152Sed/*
18214152Sed * The compiler generates calls to __clear_cache() when creating
19214152Sed * trampoline functions on the stack for use with nested functions.
20214152Sed * It is expected to invalidate the instruction cache for the
21214152Sed * specified range.
22214152Sed */
23214152Sed
24214152Sedvoid __clear_cache(void* start, void* end)
25214152Sed{
26214152Sed#if __i386__ || __x86_64__
27214152Sed/*
28214152Sed * Intel processors have a unified instruction and data cache
29214152Sed * so there is nothing to do
30214152Sed */
31214152Sed#else
32214152Sed    #if __APPLE__
33214152Sed        /* On Darwin, sys_icache_invalidate() provides this functionality */
34214152Sed        sys_icache_invalidate(start, end-start);
35214152Sed    #else
36214152Sed        compilerrt_abort();
37214152Sed    #endif
38214152Sed#endif
39214152Sed}
40214152Sed
41