From what I've found so far the "gs" register points to a thread-specific area of data (TSD). Memory of the size of one pointer can be allocated in this area by using pthread_key_create and be written to using pthread_setspecific.
After looking at apple's tsd.h there also seem to be some entries of the same size (pointer-sized) predefined at the beginning of the TSD memory area, namely __TSD_THREAD_SELF, __TSD_ERRNO, __TSD_MIG_REPLY and __TSD_SEMAPHORE_CACHE.
So now my questions are:
(since OSX binaries use mach-o, dyld seems to be involved in this as well somehow)
This is defined in the libpthread subcomponent . In particular, look at the struct _pthread
in internal.h . The tsd
field is the array of thread-specific data that gsbase points to. The first _INTERNAL_POSIX_THREAD_KEYS_MAX
(currently 256) elements are reserved to Apple. The remaining _EXTERNAL_POSIX_THREAD_KEYS_MAX
(currently 512 on macOS) elements are for callers of pthread_key_create()
.
The internal slots are reserved for various system library/framework and C library purposes. Some of the reservations are documented in tsd_private.h .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.