如何在Linux下使用AMD64的FS / GS寄存器? [英] How are the fs/gs registers used in Linux AMD64?

查看:791
本文介绍了如何在Linux下使用AMD64的FS / GS寄存器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在x86-64架构,两个寄存器有一个特殊的目的:FS和GS。在linux 2.6 * FS的寄存器似乎被用来存储线程​​局部信息。

On the x86-64 architecture, two registers have a special purpose: FS and GS. In linux 2.6.*, the FS register seem to be used to store thread-local information.


  • 这是否正确?

  • 什么是存储在FS:0?是否有描述该内容的任何的C结构?

  • 什么是再运用GS?

推荐答案

在X86-64还有的 3项TLS 中,通过入店他们两个的FS和GS ,FS是由glibc的内部使用(在IA32明显的FS所使用的葡萄酒和GS通过的glibc )。

In x86-64 there are 3 TLS entries, two of them accesible via FS and GS, FS is used internally by glibc (in IA32 apparently FS is used by Wine and GS by glibc).

的Glibc使其TLS入口点 结构的pthread 包含线程的一些内部结构。 glibc的通常是指结构的pthread 变量 PD ,presumably为的 pthread的描述符

Glibc makes its TLS entry point to a struct pthread that contains some internal structures for threading. Glibc usually refers to a struct pthread variable as pd, presumably for pthread descriptor.

在x86-64的,结构的pthread 开始以<一个href=\"http://fxr.watson.org/fxr/source/nptl/sysdeps/x86_64/tls.h?v=GLIBC27;im=excerpts#L45\"><$c$c>tcbhead_t (这取决于系统的架构,见宏<一个href=\"http://fxr.watson.org/fxr/ident?v=GLIBC27;im=excerpts;i=TLS_DTV_AT_TP\"><$c$c>TLS_DTV_AT_TP和<一个href=\"http://fxr.watson.org/fxr/ident?v=GLIBC27;im=excerpts;i=TLS_TCB_AT_TP\"><$c$c>TLS_TCB_AT_TP).这个线程控制块报头,AFAIU,含有即使当存在一个线程所需要的一些领域。该DTV是动态线程矢量,并包含)的指针为TLS块经由的dlopen加载的DSO(< 。/ code>之前或TCB后有在(程序)加载时间链接的可执行文件和数字存储示波器静态TLS块的TCB和DTV解释pretty井的Ulrich Drepper的TLS文件(寻找在第3章的图)。

On x86-64, struct pthread starts with a tcbhead_t (this depends on the architecture, see the macros TLS_DTV_AT_TP and TLS_TCB_AT_TP). This Thread Control Block Header, AFAIU, contains some fields that are needed even when there is a single thread. The DTV is the Dynamic Thread Vector, and contains pointers to TLS blocks for DSOs loaded via dlopen(). Before or after the TCB there is a static TLS block for the executable and DSOs linked at (program's) load time. The TCB and DTV are explained pretty well in Ulrich Drepper's TLS document (look for the diagrams in chapter 3).

这篇关于如何在Linux下使用AMD64的FS / GS寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆