master
h 47 lines 1.22 KB
Raw
1 /*
2 * Get user helper pc for memory unwinding.
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6 #ifndef ACCEL_TCG_HELPER_RETADDR_H
7 #define ACCEL_TCG_HELPER_RETADDR_H
8
9 #ifndef CONFIG_TCG
10 #error Can only include this header with TCG
11 #endif
12
13 /*
14 * For user-only, helpers that use guest to host address translation
15 * must protect the actual host memory access by recording 'retaddr'
16 * for the signal handler. This is required for a race condition in
17 * which another thread unmaps the page between a probe and the
18 * actual access.
19 */
20 #ifdef CONFIG_USER_ONLY
21 extern __thread uintptr_t helper_retaddr;
22
23 static inline void set_helper_retaddr(uintptr_t ra)
24 {
25 helper_retaddr = ra;
26 /*
27 * Ensure that this write is visible to the SIGSEGV handler that
28 * may be invoked due to a subsequent invalid memory operation.
29 */
30 signal_barrier();
31 }
32
33 static inline void clear_helper_retaddr(void)
34 {
35 /*
36 * Ensure that previous memory operations have succeeded before
37 * removing the data visible to the signal handler.
38 */
39 signal_barrier();
40 helper_retaddr = 0;
41 }
42 #else
43 #define set_helper_retaddr(ra) do { } while (0)
44 #define clear_helper_retaddr() do { } while (0)
45 #endif
46
47 #endif /* ACCEL_TCG_HELPER_RETADDR_H */