- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用 qemu 运行 Debian Squeeze mips 架构,只是想弄清楚我可以放入 $v0 中执行的系统调用是什么。我找到了这个 webpage .尽管此页面确实告诉我写命令使用 4。我执行以下操作:
我正在使用 this image安装 Debian Squeeze。
是的,它使用 mips 作为系统架构:
uname -a
Linux debian 2.6.32-5-4kc-malta #1 Sat Feb 16 12:43:42 UTC 2013 mips GNU/Linux
--测试.asm--
.global __start
.text
__start:
li $v0, 4
li $a0, 1
la $a1, out_string
li $a2, 12
syscall
.data
out_string: .asciiz "Hello World\n"
现在我使用“as”进行组装,使用“ld”进行链接
as -march=mips32 -o test.o test.asm
ld -o test.out test.o
chmod +x test.out
./test.out
不幸的是,这会导致错误:Illegal Instruction
。
我编译了以下 c 程序以确定写入函数使用的偏移量及其参数以进行双重检查。
--写.c--
#include <stdio.h>
int main(int argc, char *argv[]){
printf("Hello World\n");
return 0;
}
运行 strace -i ./write.out
给出:
[2abbcbe0] write(1, "Hello World\n", 12Hello World)
write 的手册页说明如下:
#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t count);
我尝试使用 write 命令输出“Hello World”,它本身就可以正常工作。
这里描述了 write 函数的作用以及我是如何得出我编写 test.asm 的方式的:
fd 或 $a0 - 从打开调用中获得的文件描述符。它是一个整数值。也可以分别为标准输入、标准输出和标准错误给出值 0、1、2
buff 或 $a1 - 指向一个字符数组,可用于存储从 fd 指向的文件中获取的内容。
nbytes 或 $a2 - 指定要从字符数组写入 fd 指向的文件的字节数。
因此我们得出顺序:
#0x4 being what unistd.h for mips tells us the system call code is 4
$v0, 4
#Set first argument to the std output 1 for the file descriptor
$a0, 1
#Set the address for the string or buff
$a1, out_string
#Set nbytes or total bytes of the string
$a2, 12
这个例子在 Mars 和 Spim 中工作得很好,尽管只有一个参数而不是 3 个:
--example.asm--
.data
out_string: .asciiz "\nHello, World!\n"
.text
main:
li $v0, 4
la $a0, out_string
syscall
li $v0, 10
syscall
因为我在 test.asm 中得到了 Illegal Instruction
,这意味着我必须指向一个无效的指令。尽管之前观察到的系统调用代码 here .不正确,即使它是 mips 架构的 unistd.h 文件,我们确认查看写入的手册页及其参数。所以现在我尝试了 strace,认为 $v0 之前指向了错误的指令,并使用 0x2abbcbe0
找到了指令指针。也许这会奏效?让我们试试。
在 strace 中,-i 选项在系统调用时打印指令指针。
所以我编辑asm文件
--测试.asm--
.global __start
.text
__start:
li $v0, 0x2abbcbe0
li $a0, 1
la $a1, out_string
li $a2, 12
syscall
.data
out_string: .asciiz "Hello World\n"
再次运行组装和链接过程:
as -march=mips32 -o test.o test.asm
ld -o test.out test.o
chmod +x test.out
./test.out
不幸的是,这导致了错误:Illegal Instruction
again。
我还颠倒了 $a 寄存器,以为我是向后做的,我多次运行 strace 并确认指令指针中的值没有改变,这表明实际上禁用了 aslr。我在/usr/include/中查找了 unistd.h 文件,它看起来与开头显示的网站上的文件完全不同。有趣的是,这种结构在 spim 和 Mars 中都能完美运行,它们都使用 li $v0, 4 模拟它们的打印/写入系统调用。我知道 Mars 和 Spim 使用它们自己的模拟系统调用。以为 strace 会帮我找到它们,但这似乎行不通。
我在哪里可以找到 $v0 的正确值?我觉得我已经将 Google 搜索到了现在毫无意义的地方。
也许我弄乱了 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 平台(马耳他)上您可以找到系统调用列表 here .在此体系结构上,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"
__NR_exit_group
(4246) 在 Linux man pages 中定义并且在一个主要方面不同于普通的 exit
(4001):
This system call is equivalent to exit(2) except that it terminates not only the calling thread, but all threads in the calling process's thread group.
关于linux - Debian Mips 系统调用 unistd.h 丢失了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32062807/
我尝试在安装了多类型 MFC 库的 visual studio 2015 MFC 上运行以前编写的 MFC c++ 代码。 但是,我这里仍然有 12 个关于缺少函数的错误: IntelliSense:
我正在学习 OOP 并且有疑问。假设我有一个包含 ClassB.h 的文件 ClassA.h,并且在某些时候我的 ClassB.h 需要包含 ClassA .h。 这会产生一个错误,我想我明白为什么会
我开始使用 CUDA 进行编程,在一些示例中我找到了包含文件 cuda.h、cuda_runtime.h 和 cuda_runtime_api.h 包含在代码中。有人可以向我解释一下这些文件之间的区别
我有一些生成正则表达式的代码。那么下面的表达式实际上是: ^(?:\s*((exclude|include|hide|show|protect|risk|dir-merge|merge)),\s*((
我一直在查看一些源代码,以更好地了解我们使用的这款游戏的核心,并编写更可靠、更快速的插件。然后我发现了这段奇怪的代码...... public void setMaxH(double amount)
通常我们会使用标准类型作为 std::unordered_map 的键和值.但现在我需要自定义我自己的键和值类。 键类在block_cache_key.h 中定义如下: #ifndef BLOCK_C
例如,我想要两个头文件,它们可以依赖于另一个头文件中的函数。 //Header1.h file #include Header2.h void h1(){ //... func1(); } v
我正在研究来自 Sedgewick 的 Shell 排序 Algorithms in C part 1-4在第 172 页。 我使用 size (数组的长度),而不是 l和 r (开始和结束);所以我
我在 macOS BigSur 上通过 VMWare 使用 Ubuntu 20.04.2 LTS。我安装了最新版本的 tcl、tcl-dev、tk 和 tk-dev - 版本 8.6。我想编译 Arc
我用我的 glu 和 gl 头文件构建了一个 OpenGL 程序,默认包含在 windows 7 专业版中。现在,我买了一本描述 OpenGL 游戏开发的书。这本书的作者说,我必须在我的项目中包含 g
我想在 token 中保留特殊字符,同时仍对特殊字符进行 token 化。说我有话 "H&R Blocks" 我想将其标记为 "H", "R", "H&R", "Blocks" 我读了http://w
关于 hash 作为 trans 参数的另一个问题。在下面的代码中,简单地使用 hash 会给出不正确的结果,但是将其替换为 keys 和 values 会使其正确。怎么了? my @alph1 =
我已经编写了一个 C 程序,它获取屏幕像素的 RGB 值 (0-255),并知道其位置 (x,y)。它可以在 Linux 中运行,但是当我尝试在 Visual Studio (Windows) 中编译
我已经使用 Windows 7 专业版中默认包含的 glu 和 gl 头文件构建了一个 OpenGL 程序。现在,我买了一本描述 OpenGL 游戏开发的书。这本书的作者说,我必须将glew head
#include using namespace std; #include //#include int main() { initscr();
h:messages h:form 内的组件还显示与外部组件相关的消息。 如何限制它只显示与包含 h:form 内的组件相关的消息? 我不喜欢用单独的h:message来使我的代码膨胀。每个输入组件的
我下载了示例代码和 cpp 文件,其中包含 list.h、queue.h 和 vector.h 等头文件,如果我尝试构建,我会收到“ fatal error :没有这样的文件或目录编译终止”我想我应该
我有一个编译成功的桌面项目,但是在我向项目添加新配置以支持 Windows Mobile 平台后,我收到以下错误: error C2146: syntax error : missing ';' be
有很多关于这个错误的帖子,但我无法解决它,我希望你能拿出解决方案。我在 Ubuntu 机器上。 ~/graphmap2$ 在这个文件夹中,我下载了 zlib。可以看图 经过一番谷歌搜索后,我还注意到没
是否可以在 Visual C++ 中使用以下 header : 图.h dos.h bios.h 最佳答案 据我所知,无法在 Visual C++ 中使用它, 与此同时,我希望您关注 Open Wat
我是一名优秀的程序员,十分优秀!