软件中断后全局变量被破坏

时间:2016-06-26 15:10:23

标签: linux assembly system-calls

我目前正在学校学习x86汇编语言,所以我可以问一个愚蠢的问题(尽管我没有发现任何有用的东西)。

我在主文件的 data 部分中声明了一些全局变量,然后我有第二个文件,其中有两个函数使用这些全局变量。

.section .data
  .globl file_desc
  .globl init
  .globl reset
  .globl rpm

  file_desc: .long
  init: .int
  reset: .int
  rpm: .long

在_start部分,我调用 sys_open 系统调用来获取文件描述符,并将其保存在 file_desc 变量中。 然后我在另一个文件中调用一个函数:

read_init:
    # read the INIT and convert it
    movl $SYS_READ, %eax
    movl file_desc, %ebx
    leal init, %ecx
    movl $1, %edx
    int $0x80

    cmp $0, %eax        # check for EOF
    jle eof
    jmp get_init

eof:
    movl $47, init      # we make the init to -1 xD

get_init:
    subb $48, init      # get the real value of INIT

    # skip 1 byte
    movl $SYS_SEEK, %eax
    movl file_desc, %ebx
    movl $1, %ecx
    movl $1, %edx
    int $0x80

    ret

问题是,当我到达 sys_lseek 系统调用时,file_desc已被修改!我使用GDB进行调试以查看它,并且在调用read syscall之后,该值不一样。

理论上它不应该修改它,那么我的程序到底是什么?

0 个答案:

没有答案
相关问题