Skip to content

Commit 62c3f31

Browse files
committed
Fix jit on darwin x86_64
1 parent 0f04f27 commit 62c3f31

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

ext/opcache/jit/tls/zend_jit_tls_darwin.c

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626

2727
TSRMLS_CACHE_EXTERN();
2828

29+
typedef struct _tls_descriptor {
30+
void *(*thunk)(struct _tls_descriptor *);
31+
uintptr_t key;
32+
uintptr_t offset;
33+
} tls_descriptor;
34+
35+
#if defined(__x86_64__)
36+
static void *(*zend_jit_darwin_tlsdesc_thunk)(tls_descriptor *);
37+
static tls_descriptor *zend_jit_darwin_tlsdesc;
38+
#endif
39+
2940
zend_result zend_jit_resolve_tsrm_ls_cache_offsets(
3041
size_t *tcb_offset,
3142
size_t *module_index,
@@ -37,19 +48,39 @@ zend_result zend_jit_resolve_tsrm_ls_cache_offsets(
3748
}
3849

3950
#if defined(__x86_64__)
40-
size_t *ti;
51+
const tls_descriptor *tlsdesc_local;
4152
__asm__ __volatile__(
42-
"leaq __tsrm_ls_cache(%%rip),%0"
43-
: "=r" (ti));
44-
*module_offset = ti[2];
45-
*module_index = ti[1] * 8;
53+
"leaq __tsrm_ls_cache@TLVP(%%rip), %0\n\t"
54+
"movq (%0), %0"
55+
: "=&r" (tlsdesc_local)
56+
:
57+
: "memory"
58+
);
59+
60+
zend_jit_darwin_tlsdesc_thunk = tlsdesc_local->thunk;
61+
zend_jit_darwin_tlsdesc = (tls_descriptor *)tlsdesc_local;
62+
63+
*tcb_offset = 0;
64+
*module_index = (size_t)-1;
65+
*module_offset = (size_t)-1;
4666

4767
return SUCCESS;
4868
#endif
4969

5070
return FAILURE;
5171
}
5272

73+
ZEND_API void *zend_jit_tsrm_ls_cache_ptr(void)
74+
{
75+
#if defined(__x86_64__)
76+
return zend_jit_darwin_tlsdesc_thunk
77+
? zend_jit_darwin_tlsdesc_thunk(zend_jit_darwin_tlsdesc)
78+
: NULL;
79+
#else
80+
return NULL;
81+
#endif
82+
}
83+
5384
/* Used for testing */
5485
void *zend_jit_tsrm_ls_cache_address(
5586
size_t tcb_offset,
@@ -67,6 +98,11 @@ void *zend_jit_tsrm_ls_cache_address(
6798
);
6899
return addr;
69100
}
101+
if (module_index == (size_t)-1 && module_offset == (size_t)-1) {
102+
return zend_jit_darwin_tlsdesc_thunk
103+
? zend_jit_darwin_tlsdesc_thunk(zend_jit_darwin_tlsdesc)
104+
: NULL;
105+
}
70106
if (module_index != (size_t)-1 && module_offset != (size_t)-1) {
71107
char *base;
72108
__asm__ __volatile__(

0 commit comments

Comments
 (0)