无法通过 0x80 打开 Linux 中的文件
Can't open file in Linux via 0x80
我正在尝试在 GAS 中实现一个简单的测试程序,该程序打开一个文件,向其中写入一些文本并退出。但是,'open' 的系统调用不断返回“-14”("EFAULT - bad address" 如果我理解正确的话)。程序代码如下:
.intel_syntax noprefix
.section .data
textoutput:
.asciz "Hello world!"
pstr_end:
.set lentext, pstr_end - textoutput
filetoopen:
.asciz "/tmp/tsttxt"
.section .text
.globl main
.func main
main:
mov eax, 5 # open
mov ebx, filetoopen # filname
mov ecx, 2 # flags: read and write
mov edx, 0700 # mode
int 0x80
mov ebx, eax # <<< !!! eax here contains -14
mov eax, 4
mov ecx, textoutput
mov edx, lentext
int 0x80
mov eax, 1
mov ebx, 0
int 0x80
问题似乎与 filetoopen
字符串有关(open
的联机帮助页说 EFAULT 表示 pathname points outside your accessible address space
。)是否在程序的代码?导致此错误的原因是什么?
谢谢。
在英特尔语法中你需要使用mov ebx, offset filetoopen
。
如果您查看组装后的实际指令,您会发现这是一个内存负载:
80483e1: 8b 1d 2d 96 04 08 mov ebx,DWORD PTR ds:0x804962d
那当然是错的,你需要这里的地址。这也适用于此模式的其他两次出现。
我正在尝试在 GAS 中实现一个简单的测试程序,该程序打开一个文件,向其中写入一些文本并退出。但是,'open' 的系统调用不断返回“-14”("EFAULT - bad address" 如果我理解正确的话)。程序代码如下:
.intel_syntax noprefix
.section .data
textoutput:
.asciz "Hello world!"
pstr_end:
.set lentext, pstr_end - textoutput
filetoopen:
.asciz "/tmp/tsttxt"
.section .text
.globl main
.func main
main:
mov eax, 5 # open
mov ebx, filetoopen # filname
mov ecx, 2 # flags: read and write
mov edx, 0700 # mode
int 0x80
mov ebx, eax # <<< !!! eax here contains -14
mov eax, 4
mov ecx, textoutput
mov edx, lentext
int 0x80
mov eax, 1
mov ebx, 0
int 0x80
问题似乎与 filetoopen
字符串有关(open
的联机帮助页说 EFAULT 表示 pathname points outside your accessible address space
。)是否在程序的代码?导致此错误的原因是什么?
谢谢。
在英特尔语法中你需要使用mov ebx, offset filetoopen
。
如果您查看组装后的实际指令,您会发现这是一个内存负载:
80483e1: 8b 1d 2d 96 04 08 mov ebx,DWORD PTR ds:0x804962d
那当然是错的,你需要这里的地址。这也适用于此模式的其他两次出现。