linux – 什么是汇编中的%gs

前端之家收集整理的这篇文章主要介绍了linux – 什么是汇编中的%gs前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
void return_input (void)
{ 
   char array[30]; 

   gets (array); 
   printf("%s\n",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.

原文链接:https://www.f2er.com/linux/393583.html

猜你在找的Linux相关文章