+
+/* Called by libthread_db. Returns a pointer to the thread local
+ storage (or its descriptor). */
+
+ps_err_e
+aarch64_ps_get_thread_area (const struct ps_prochandle *ph,
+ lwpid_t lwpid, int idx, void **base,
+ int is_64bit_p)
+{
+ struct iovec iovec;
+ uint64_t reg64;
+ uint32_t reg32;
+
+ if (is_64bit_p)
+ {
+ iovec.iov_base = ®64;
+ iovec.iov_len = sizeof (reg64);
+ }
+ else
+ {
+ iovec.iov_base = ®32;
+ iovec.iov_len = sizeof (reg32);
+ }
+
+ if (ptrace (PTRACE_GETREGSET, lwpid, NT_ARM_TLS, &iovec) != 0)
+ return PS_ERR;
+
+ /* IDX is the bias from the thread pointer to the beginning of the
+ thread descriptor. It has to be subtracted due to implementation
+ quirks in libthread_db. */
+ if (is_64bit_p)
+ *base = (void *) (reg64 - idx);
+ else
+ *base = (void *) (uintptr_t) (reg32 - idx);
+
+ return PS_OK;
+}