Page MenuHomeFreeBSD

Add <machine/tls.h> header to hold MD constants and helpers for TLS.
ClosedPublic

Authored by jhb on Dec 8 2021, 9:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Dec 9, 9:34 PM
Unknown Object (File)
Mon, Nov 25, 4:15 PM
Unknown Object (File)
Nov 18 2024, 1:44 PM
Unknown Object (File)
Nov 18 2024, 1:31 PM
Unknown Object (File)
Nov 18 2024, 11:46 AM
Unknown Object (File)
Nov 17 2024, 2:39 PM
Unknown Object (File)
Sep 28 2024, 7:52 AM
Unknown Object (File)
Sep 20 2024, 6:07 AM

Details

Summary

The header exports the following:

  • Definition of struct tcb.
  • Helpers to get/set the tcb for the current thread.
  • TLS_TCB_SIZE (size of TCB)
  • TLS_TCB_ALIGN (alignment of TCB)
  • TLS_VARIANT_I or TLS_VARIANT_II
  • TLS_DTV_OFFSET (bias of pointers in dtv[])
  • TLS_TP_OFFSET (bias of "thread pointer" relative to TCB)

Note that TLS_TP_OFFSET does not account for if the unbiased thread
pointer points to the start of the TCB (arm and x86) or the end of the
TCB (MIPS, PowerPC, and RISC-V).

Note also that for amd64, the struct tcb does not include the unused
tcb_spare field included in the current structure in libthr. libthr
does not use this field, and the existing calls in libc and rtld that
allocate a TCB for amd64 assume it is the size of 3 Elf_Addr's (and
thus do not allocate room for tcb_spare).

A <sys/_tls_variant_i.h> header is used by architectures using
Variant I TLS which uses a common struct tcb.

Sponsored by: The University of Cambridge, Google Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Dec 8 2021, 9:52 PM

Picking this review to comment on, but this applies to all commits in this series: I have runtime tested all of this on armv7, aarch64, amd64, i386, and riscv by running the /usr/tests/libexec/rtld-elf and /usr/tests/lib/libc tests (specifically including /usr/tests/lib/libc/tls tests). For mips and powerpc I have tested that universe builds, but I have not done runtime testing on those two platforms.

sys/amd64/include/tls.h
5

We do not add svn tags to new files anymore, I believe.

sys/x86/include/tls.h
69

Would be useful to comment it as /* i386 */

98

Also please add comment.

sys/x86/include/tls.h
50

This structure definition does not match one from the libthr/arch/amd64/include/pthread_md.h. OTOH I am not even sure if struct tcb layout is part of the ABI (I think not).

jhb marked 3 inline comments as done.Dec 9 2021, 12:42 AM
jhb added inline comments.
sys/x86/include/tls.h
50

So I think the one in libthr is wrong. It has an extra void * array that I think is trying to be a VLA but is never used. However, all the places that allocate the tcb currently (libc and libthr) currently use 'sizeof(Elf_Addr) * 3' which matches this size. At one point in this work I had kept it under an #if 0 with a comment. I probably should add a note in the commit log noting why it is different from the old one in libthr. Possibly should do that in the commit that changes libthr to use this header though?

sys/x86/include/tls.h
50

I think comments in both commits would be still affordable.

  • Address review feedback from @kib
This revision is now accepted and ready to land.Dec 9 2021, 1:00 AM
  • Narrow scope of #ifdef's in x86/tls.h as suggested by Jessica.
This revision now requires review to proceed.Dec 9 2021, 7:22 PM
This revision was not accepted when it landed; it landed in state Needs Review.Dec 9 2021, 9:25 PM
This revision was automatically updated to reflect the committed changes.