1 From 3956f39e58f0d29487057b523cd68bbd24efc844 Mon Sep 17 00:00:00 2001
2 From: Aurelien Larcher <aurelien.larcher@gmail.com>
3 Date: Thu, 11 Jun 2020 13:24:30 +0200
4 Subject: [PATCH 18/25] 18-obmalloc-adi.patch
7 Objects/obmalloc.c | 35 ++++++++++++++++++++++++++++++++++-
8 1 file changed, 34 insertions(+), 1 deletion(-)
10 diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
11 index 9408855383..225052df17 100644
12 --- a/Objects/obmalloc.c
13 +++ b/Objects/obmalloc.c
14 @@ -1350,6 +1350,39 @@ obmalloc controls. Since this test is needed at every entry point, it's
15 extremely desirable that it be this fast.
20 + * Py_ADDRESS_IN_RANGE needs to access memory that might be arbitrarily
21 + * tagged by an ADI aware allocator. The use of a nonfaulting load
22 + * guarantees that the read will succeed.
26 +/* Studio can use built-in nonfaulting load instruction for vis.h */
28 +#define POOL_INDEX(x) __vis_ldswa_ASI_PNF((void*)x)
30 +#else /* __SUNPRO_C */
32 + * GCC doesn't have similar instruction built-in, but it can use
33 + * following assembly code to do the same.
36 +static inline int vis_ldswa_ASI_PNF(void *arg);
38 +int vis_ldswa_ASI_PNF(void *arg) {
40 + __asm__ ("ldswa [%1]0x82,%0" : "=r" (res) : "r" (arg));
43 +#define POOL_INDEX(x) vis_ldswa_ASI_PNF((void*)x)
45 +#endif /* __SUNPRO_C */
46 +#else /* __sparcv9 */
47 +#define POOL_INDEX(x) (*(x))
48 +#endif /* __sparcv9 */
51 static bool _Py_NO_SANITIZE_ADDRESS
52 _Py_NO_SANITIZE_THREAD
53 _Py_NO_SANITIZE_MEMORY
54 @@ -1360,7 +1393,7 @@ address_in_range(void *p, poolp pool)
55 // another thread may be concurrently modifying the value without holding
56 // the GIL. The following dance forces the compiler to read pool->arenaindex
58 - uint arenaindex = *((volatile uint *)&pool->arenaindex);
59 + uint arenaindex = (uint)POOL_INDEX((volatile uint *)&pool->arenaindex);
60 return arenaindex < maxarenas &&
61 (uintptr_t)p - arenas[arenaindex].address < ARENA_SIZE &&
62 arenas[arenaindex].address != 0;