Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux Debian Mips系统调用unistd.h是否丢失?_Linux_Assembly_Debian_Mips - Fatal编程技术网

Linux Debian Mips系统调用unistd.h是否丢失?

Linux Debian Mips系统调用unistd.h是否丢失?,linux,assembly,debian,mips,Linux,Assembly,Debian,Mips,我正在使用qemu运行Debian Squeeze mips体系结构,只是想弄清楚我可以在$v0中执行哪些系统调用。我找到了这个。虽然本页确实告诉我write命令使用4。我做了以下工作: #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); 我正在使用安装Debian Squence 是的,它使用mips作为系统架构: uname -a Linux debian 2.6.32-5-4kc

我正在使用qemu运行Debian Squeeze mips体系结构,只是想弄清楚我可以在$v0中执行哪些系统调用。我找到了这个。虽然本页确实告诉我write命令使用4。我做了以下工作:

#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t count); 
我正在使用安装Debian Squence

是的,它使用mips作为系统架构:

uname -a
Linux debian 2.6.32-5-4kc-malta #1 Sat Feb 16 12:43:42 UTC 2013 mips GNU/Linux 
--test.asm--

现在我使用“as”进行组装,使用“ld”进行链接

as -march=mips32 -o test.o test.asm
ld -o test.out test.o
chmod +x test.out
./test.out
不幸的是,这会导致错误:
非法指令

我编译了下面的c程序来确定write函数使用了什么偏移量,以及它的参数以进行双重检查

--写--

write的手册页说明了以下内容:

#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t count); 
此示例在Mars和Spim中运行良好,但使用一个参数而不是3个:

--示例.asm--

由于我使用test.asm获得了非法指令,这意味着我必须指向无效指令。尽管系统调用代码与之前的观察结果相同。是不正确的,尽管它是mips体系结构的unistd.h文件,我们在查看手册页时确认了该文件的写入和所需的参数。因此,现在我尝试使用trace,认为$v0之前指向了错误的指令,并使用
0x2abbcbe0
找到了指令指针。也许这会奏效?让我们试试看

在strace中,-i选项在系统调用时打印指令指针

所以我编辑了asm文件

--test.asm--

再次运行组装和链接过程:

as -march=mips32 -o test.o test.asm
ld -o test.out test.o
chmod +x test.out
./test.out
不幸的是,这会再次导致错误:
非法指令

我还反转了$a寄存器,认为我是反向操作的,我运行了多次strace,并确认指令指针中的值没有改变,这表明aslr实际上已被禁用。我在/usr/include/中查找了unistd.h文件,但它与开头介绍的网站中的文件完全不同。有趣的是,这个结构在spim和Mars中工作得非常完美,这两个系统都使用li$v0,4模拟了它们的打印/写入系统调用。我知道Mars和Spim使用他们自己的模拟系统调用。我以为斯特拉斯会帮我找到它们,但这似乎行不通

在哪里可以找到$v0的正确值?我觉得我已经把谷歌逼到了毫无意义的地步

也许我弄乱了asm文件及其语法

让我们尝试一些更简单的方法,只需运行exit:

.global __start
.text
        __start:
        li $v0, 1
        li $a0, 0
        syscall
装配连杆并运行

as -march=mips32 -o test.o test.asm
ld -o test.out test.o
chmod +x test.out
./test.out
Illegal Instruction
也在没有
-march=mips32

as -o test.o test.asm
ld -o test.out test.o
chmod +x test.out
./test.out
Illegal Instruction
这应该是最容易执行的事情


我在这里不知所措,伙计们,请帮助。

如果您愿意使用Linux系统调用,那么在MIPS平台(马耳他)上,您可以找到系统调用的列表。在这个架构上,Linux映射从4000开始的系统调用。正在使用的ABI是MIPS o32。下面是该文件的一个片段。请注意,您可以在系统中的
/usr/include/asm/unistd.h
中找到该文件的副本:

#define __NR_Linux          4000
#define __NR_exit           (__NR_Linux +   1)
#define __NR_write          (__NR_Linux +   4)
#define __NR_exit_group     (__NR_Linux + 246)
以下代码应打印
Hello World
,然后退出:

    .text
    .globl  __start
__start:
    li $v0, 4004
    li $a0, 1
    la $a1, out_string
    li $a2, 12
    syscall
    li $v0, 4001
    la $a0, 1
    syscall

.data
    out_string: .asciiz "Hello World\n"
\uuuu NR\u exit\u组(4246)是在Linux中定义的,在一个主要方面不同于正常的
退出(4001):

此系统调用相当于退出(2),只是它不仅终止调用线程,而且终止调用进程的线程组中的所有线程


$v0
应该包含系统调用号,而不是某个地址。因此,4看起来是正确的-当然比0x2abbcbe0更正确。你的程序永远不会正常退出,这是不好的。您应该使用
exit
syscall(根据您链接的页面,syscall编号为1)。运行qemu时,您使用的是哪种mips体系结构?我使用的是Debian的哪个端口(Debian mips或Debian mipsel),我猜第一次观察到的是这个。在您最初的
test.asm
中,它给出了一条非法指令,我注意到您实际上并没有在最后退出并允许您的程序以代码的形式执行
Hello World\n
?我可以看出这导致了一个非法的指令。在syscall输出字符串之后,如果您使用
li$v0,1
然后
la$a0,0
然后
syscall
退出操作系统,会发生什么情况?我做了以下操作,使程序仅根据您概述的指令退出:li$v0,1然后li$a0,0和syscall。然而,这仍然只是返回“非法指令”。我完全同意你的观点,你在这里给出的退出代码是正确的。它仍然在说“非法指令”似乎很奇怪,这确实和qemu仿真有关吗?这太完美了。感谢您指出在哪里可以找到unistd.h文件。这确实很有帮助。现在我可以轻松地继续学习mips了。是的,4246是exit_组(0),我通过对_exit函数lol的反汇编进行黑客攻击获得了它。非常感谢!是的,我在后面加上了4246,因为我注意到你自己也碰到过它。祝你好运我意识到现在我误读了分解,是的,4001出现在那里。
.global __start
.text
        __start:
        li $v0, 1
        li $a0, 0
        syscall
as -march=mips32 -o test.o test.asm
ld -o test.out test.o
chmod +x test.out
./test.out
Illegal Instruction
as -o test.o test.asm
ld -o test.out test.o
chmod +x test.out
./test.out
Illegal Instruction
#define __NR_Linux          4000
#define __NR_exit           (__NR_Linux +   1)
#define __NR_write          (__NR_Linux +   4)
#define __NR_exit_group     (__NR_Linux + 246)
    .text
    .globl  __start
__start:
    li $v0, 4004
    li $a0, 1
    la $a1, out_string
    li $a2, 12
    syscall
    li $v0, 4001
    la $a0, 1
    syscall

.data
    out_string: .asciiz "Hello World\n"