为什么我不能使用int 0x80从指向堆栈存储器的指针进行sys_write? [英] Why can't I sys_write from a pointer to stack memory, using int 0x80?
本文介绍了为什么我不能使用int 0x80从指向堆栈存储器的指针进行sys_write?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
; NASM
push 30 ; '0'
mov rax, 4 ; write
mov rbx, 1 ; stdout
mov rcx, rsp ; ptr to character on stack
mov rdx, 1 ; length of string = 1
int 80h
上面的代码不会将任何内容输出到stdout.当我为section .data
中的字符提供ptr时,它会起作用.我在做什么错了?
The code above does not print anything to stdout. It works when i give it a ptr to a character in section .data
. What am i doing wrong?
推荐答案
amd64
使用与int 0x80
不同的方法进行系统调用,尽管该方法可能仍适用于已安装的32位库等.而在
amd64
uses a different method for system calls than int 0x80
, although that might still work with 32-bit libraries installed, etc. Whereas on x86
one would do:
mov eax, SYSCALL_NUMBER
mov ebx, param1
mov ecx, param2
mov edx, param3
int 0x80
在amd64
上的
可以这样做:
on amd64
one would instead do this:
mov rax, SYSCALL_NUMBER_64 ; different from the x86 equivalent, usually
mov rdi, param1
mov rsi, param2
mov rdx, param3
syscall
对于您想做的事情,请考虑以下示例:
For what you want to do, consider the following example:
bits 64
global _start
section .text
_start:
push 0x0a424242
mov rdx, 04h
lea rsi, [rsp]
call write
call exit
exit:
mov rax, 60 ; exit()
xor rdi, rdi ; errno
syscall
write:
mov rax, 1 ; write()
mov rdi, 1 ; stdout
syscall
ret
这篇关于为什么我不能使用int 0x80从指向堆栈存储器的指针进行sys_write?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文