Skip to content

Commit

Permalink
set tp offset for ppc64 back
Browse files Browse the repository at this point in the history
  • Loading branch information
palainp committed Feb 16, 2023
1 parent 36c9d02 commit 7d618d6
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions bindings/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ extern char _ltdata[], _ltbss[];
void* tp;
};

/* solo5_tls_tp_offset tells where we need to set the tp pointer next to
* the data block. It depends on the Variant, for Variant II it's at the end.
*/
#define _solo5_tls_tp_offset(x) (x + LTDATA + LTBSS)
#define _solo5_tls_data_offset(x) (x)

#define PPC64_TLS_OFFSET 0x7000

#elif defined(__aarch64__)
Expand All @@ -53,10 +47,6 @@ extern char _ltdata[], _ltbss[];
void* pad;
};

/* for Vairant I it's at the begining */
#define _solo5_tls_tp_offset(x) (x)
#define _solo5_tls_data_offset(x) (x + sizeof(struct tcb))

#else
#error Unsupported architecture
#endif
Expand All @@ -68,16 +58,41 @@ size_t solo5_tls_size()

uintptr_t solo5_tls_tp_offset(uintptr_t tls)
{
return _solo5_tls_tp_offset(tls);
uintptr_t tp;
#if defined(__powerpc64__)
tp = PPC64_TLS_OFFSET + tls;
#elif defined(__x86_64__)
tp = tls + LTDATA + LTBSS;
#elif defined(__aarch64__)
tp = tls;
#else
#error Unsupported architecture
#endif

return tp;
}

uintptr_t _solo5_tls_data_offset(uintptr_t tls)
{
uintptr_t data;
#if defined(__x86_64__) || defined(__powerpc64__)
data = tls;
#elif defined(__aarch64__)
data = data + sizeof(struct tcb);
#else
#error Unsupported architecture
#endif

return data;
}

solo5_result_t solo5_tls_init(uintptr_t tls)
{
if ((void*)tls == NULL) return SOLO5_R_EINVAL;

/* set tp at its proper place in the TLS block */
uintptr_t *tmp = (uintptr_t*)_solo5_tls_tp_offset(tls);
*tmp = _solo5_tls_tp_offset(tls);
uintptr_t *tmp = (uintptr_t*)solo5_tls_tp_offset(tls);
*tmp = *tmp;

/* copy the .tdata values */
memcpy((void*)_solo5_tls_data_offset(tls), TDATA, LTDATA);
Expand Down

0 comments on commit 7d618d6

Please sign in to comment.