1 : /*
2 : * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 :
8 : #ifndef NATIVE_CLIENT_SRC_INCLUDE_CONCURRENCY_OPS_H_
9 : #define NATIVE_CLIENT_SRC_INCLUDE_CONCURRENCY_OPS_H_ 1
10 :
11 :
12 : #include "native_client/src/include/nacl_base.h"
13 : #include "native_client/src/include/portability.h"
14 :
15 : #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86
16 :
17 0 : static INLINE void NaClWriteMemoryBarrier() {
18 : #if NACL_WINDOWS
19 : /* Inline assembly is not available in x86-64 MSVC. Use built-in. */
20 : _mm_sfence();
21 : #else
22 0 : __asm__ __volatile__("sfence");
23 : #endif
24 0 : }
25 :
26 : #elif NACL_ARCH(NACL_BUILD_ARCH) == NACL_arm
27 :
28 : static INLINE void NaClWriteMemoryBarrier() {
29 : /* Note that this depends on ARMv7. */
30 : __asm__ __volatile__("dsb");
31 :
32 : /*
33 : * We could support ARMv6 by instead using:
34 : * __asm__ __volatile__("mcr p15, 0, %0, c7, c10, 5"
35 : * : : "r" (0) : "memory");
36 : */
37 : }
38 :
39 : #else
40 :
41 : #error "Define for other architectures"
42 :
43 : #endif
44 :
45 :
46 0 : static INLINE void NaClClearInstructionCache(void *start, void *end) {
47 : #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86
48 : /*
49 : * Clearing the icache explicitly is not necessary on x86. We could
50 : * call gcc's __builtin___clear_cache() on x86, where it is a no-op,
51 : * except that it is not available in Mac OS X's old version of gcc.
52 : */
53 : UNREFERENCED_PARAMETER(start);
54 : UNREFERENCED_PARAMETER(end);
55 : #elif defined(__GNUC__)
56 : __builtin___clear_cache(start, end);
57 : #else
58 : /*
59 : * Give an error in case we ever target a non-gcc compiler for ARM
60 : * or for some other architecture that we might support in the
61 : * future.
62 : */
63 : # error "Don't know how to clear the icache on this architecture"
64 : #endif
65 0 : }
66 :
67 :
68 : #endif /* NATIVE_CLIENT_SRC_INCLUDE_CONCURRENCY_OPS_H_ */
|