TLS for MacOS 64-bit
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 (closed) 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 (closed) 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 (closed), 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.