加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 什么是汇编中的%gs

发布时间:2020-12-13 19:43:39 所属栏目:Linux 来源:网络整理
导读:void return_input (void){ char array[30]; gets (array); printf("%sn",array); } 在gcc中编译之后,此函数将转换为以下程序集代码: push %ebpmov %esp,%ebpsub $0x28,%espmov %gs:0x14,%eaxmov %eax,-0x4(%ebp)xor %eax,%eaxlea -0x22(%ebp),(%esp)call
void return_input (void)
{ 
   char array[30]; 

   gets (array); 
   printf("%sn",array); 
}

在gcc中编译之后,此函数将转换为以下程序集代码:

push   %ebp
mov    %esp,%ebp
sub    $0x28,%esp
mov    %gs:0x14,%eax
mov    %eax,-0x4(%ebp)
xor    %eax,%eax
lea    -0x22(%ebp),(%esp)
call   0x8048374 
lea    -0x22(%ebp),(%esp)
call   0x80483a4 
mov    -0x4(%ebp),%eax
xor    %gs:0x14,%eax
je     0x80484ac 
call   0x8048394 
leave  
ret  

我不明白两行:

mov    %gs:0x14,%eax

什么是%gs,这两行究竟是什么呢?

这是编译命令:

cc -c -mpreferred-stack-boundary=2 -ggdb file.c

解决方法

GS是一个段寄存器,其在linux中的使用可以在 here上读取(它基本上用于每个进程数据).
mov    %gs:0x14,%eax

该代码用于验证堆栈没有爆炸或已被证实,使用存储在GS 0x14中的金丝雀值,参见this.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读