DynamoRIO / DynamoRIO/dynamorio

TLS for MacOS 64-bit

Open
#1,568 7 comments 0 reactions 0 assignees View on GitHub
OpSys-OSX Type-Feature
Dominant language
C
Stars
3.2k
Forks
629
Avg merge
2d 18h
Merged PRs (30d)
30

Description

Split from #58 as this may have some overlap with ARM work. I'm going to paste my notes here:

*\* TODO 64-bit: can only set gs, not fs, and can't read gs

For 64-bit: thread_fast_set_cthread_self64 which sets MSR_IA32_KERNEL_GS_BASE.
May not be a way to set MSR for FS: no reference to MSR_IA32_KERNEL_FS_BASE in
xnu sources.

**\* TODO option #1 for DR: is there some free padding space in TLS mmap?

Maybe beyond pthread data structs, since stack beyond that is page-aligned?

**\* TODO option #2 for DR: early injection and use privlib w/ larger mmap + app mangling?

Add extra page to TLS mmap, maybe to the left so out of way (16-bit offs
will still reach).

We'd need to mangle the app's references even w/o priv loader.

**\* TODO option #3 for DR: like Windows, can we steal some slots from app's TLS?

Like Windows, request official TLS slots like app would and take ~20 (and
ensure directly addressable)?

**\* TODO for priv libs, have to mangle app's refs

If go w/ option #2, have to do so even w/o priv libs.

**\* TODO how read current gs?
**\* TODO on Ivybridge+, use OP_wrfsbase or OP_wrgsbase?!
**\* TODO steal register? later update: leverage ARM code?
Though this only helps for the code cache and our gencode: in our C code
we need a separate TLS mechanism.

Contributor guide

Open the contributing guide

Research direction

Start with the notes in this issue and the related ARM work in #58, then inspect the referenced xnu entry point thread_fast_set_cthread_self64 and the MSR and OP_wrfsbase/OP_wrgsbase questions. Determine which TLS approach is viable for macOS 64-bit, including the separate C-code mechanism; done means the platform has a defined, working TLS strategy.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, macos
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.