blob: fdd33163366918e3d5407e21059b7fbae5ac7ca5 [file] [log] [blame]
Edward O'Callaghan4856eef2009-08-05 04:02:56 +00001/* ===-- clear_cache.c - Implement __clear_cache ---------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant5b791f62010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan4856eef2009-08-05 04:02:56 +00007 *
8 * ===----------------------------------------------------------------------===
9 */
Daniel Dunbarfd089992009-06-26 16:47:03 +000010
Daniel Dunbarfd089992009-06-26 16:47:03 +000011#if __APPLE__
12 #include <libkern/OSCacheControl.h>
13#endif
14
Edward O'Callaghan4856eef2009-08-05 04:02:56 +000015/*
16 * The compiler generates calls to __clear_cache() when creating
17 * trampoline functions on the stack for use with nested functions.
18 * It is expected to invalidate the instruction cache for the
19 * specified range.
20 */
21
Daniel Dunbarfd089992009-06-26 16:47:03 +000022void __clear_cache(void* start, void* end)
23{
24#if __i386__ || __x86_64__
Edward O'Callaghan4856eef2009-08-05 04:02:56 +000025/*
26 * Intel processors have a unified instruction and data cache
27 * so there is nothing to do
28 */
Daniel Dunbarfd089992009-06-26 16:47:03 +000029#else
30 #if __APPLE__
Edward O'Callaghan4856eef2009-08-05 04:02:56 +000031 /* On Darwin, sys_icache_invalidate() provides this functionality */
Daniel Dunbarfd089992009-06-26 16:47:03 +000032 sys_icache_invalidate(start, end-start);
33 #else
Daniel Dunbarf2870082010-03-31 17:00:45 +000034 compilerrt_abort();
Daniel Dunbarfd089992009-06-26 16:47:03 +000035 #endif
36#endif
37}
38