Skip to content

Commit 57b2235

Browse files
committed
Fix jit
1 parent cd74a77 commit 57b2235

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

ext/opcache/jit/tls/zend_jit_tls_darwin.c

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

2727
TSRMLS_CACHE_EXTERN();
2828

29+
struct tlv_descriptor {
30+
void *(*thunk)(struct tlv_descriptor *);
31+
uintptr_t key;
32+
uintptr_t offset;
33+
};
34+
2935
zend_result zend_jit_resolve_tsrm_ls_cache_offsets(
3036
size_t *tcb_offset,
3137
size_t *module_index,
@@ -37,46 +43,50 @@ zend_result zend_jit_resolve_tsrm_ls_cache_offsets(
3743
}
3844

3945
#if defined(__x86_64__)
40-
size_t *ti;
46+
const struct tlv_descriptor *desc;
47+
4148
__asm__ __volatile__(
42-
"leaq __tsrm_ls_cache(%%rip),%0"
43-
: "=r" (ti));
44-
*module_offset = ti[2];
45-
*module_index = ti[1] * 8;
49+
"leaq ___tsrm_ls_cache@TLVP(%%rip), %0\n\t"
50+
"movq (%0), %0\n\t"
51+
: "=&r"(desc)
52+
:
53+
: "memory"
54+
);
4655

47-
return SUCCESS;
48-
#endif
56+
*module_index = (size_t)(desc->key * sizeof(void *));
57+
*module_offset = (size_t)desc->offset;
4958

59+
return SUCCESS;
60+
#else
5061
return FAILURE;
62+
#endif
5163
}
5264

53-
/* Used for testing */
5465
void *zend_jit_tsrm_ls_cache_address(
5566
size_t tcb_offset,
5667
size_t module_index,
5768
size_t module_offset
5869
) {
59-
60-
#if defined(__x86_64__)
70+
#if defined(__APPLE__) && defined(__x86_64__)
6171
if (tcb_offset) {
6272
char *addr;
6373
__asm__ __volatile__(
64-
"movq %%gs:(%1), %0\n"
65-
: "=r" (addr)
66-
: "r" (tcb_offset)
74+
"movq %%gs:(%1), %0\n\t"
75+
: "=r"(addr)
76+
: "r"(tcb_offset)
6777
);
6878
return addr;
6979
}
80+
7081
if (module_index != (size_t)-1 && module_offset != (size_t)-1) {
7182
char *base;
7283
__asm__ __volatile__(
73-
"movq %%gs:(%1), %0\n"
74-
: "=r" (base)
75-
: "r" (module_index)
84+
"movq %%gs:(%1), %0\n\t"
85+
: "=r"(base)
86+
: "r"(module_index)
7687
);
7788
return base + module_offset;
7889
}
7990
#endif
80-
8191
return NULL;
8292
}

0 commit comments

Comments
 (0)