nasm系统调用Linux [英] nasm system calls Linux

查看:120
本文介绍了nasm系统调用Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对汇编中的Linux x86系统调用有疑问.

I have got a question about linux x86 system calls in assembly.

当我在Linux上使用nasm创建新的汇编程序时,我想知道执行特定任务(例如读取文件,编写输出或简单退出)必须使用的系统调用. ).我知道一些系统调用,因为我已经阅读了一些有关Internet的示例(例如eax = 0,ebx = 1 int 0x80 exit(返回值为1)),但仅此而已...我怎么知道是否还有其他退出系统调用的参数?还是要进行另一个系统调用?我正在寻找一个说明哪些系统调用具有哪些参数要在哪些寄存器中传递的文档.

When I am creating a new assembly program with nasm on linux, I'd like to know which system calls I have to use for doing a specific task (for example reading a file, writing output, or simple exiting...). I know some syscall because I've read them on some examples taken around internet (such as eax=0, ebx=1 int 0x80 exit with return value of 1), but nothing more... How could I know if there are other arguments for exit syscall? Or for another syscall? I'm looking for a docs that explain which syscalls have which arguments to pass in which registers.

我已经阅读了有关退出功能等的手册页,但没有向我解释我在问什么.

I've read the man page about exit function etc. but it didn't explain to me what I'm asking.

希望我足够清楚

谢谢!

推荐答案

Wiki(我刚刚再次对其进行了更新:)具有指向系统调用ABI的链接(每个调用的编号,放置参数的位置,要运行的指令以及将破坏哪些寄存器的链接)返回).手册页中没有对此进行记录,因为它是特定于体系结构的.二进制常量相同:不必在每种体系结构上都相同.

The x86 wiki (which I just updated again :) has links to the system call ABI (what the numbers are for every call, where to put the params, what instruction to run, and which registers will clobbered on return). This is not documented in the man page because it's architecture-specific. Same for binary constants: they don't have to be the same on every architecture.

grep -r O_APPEND /usr/include为您的目标体系结构以递归方式搜索.h文件.

grep -r O_APPEND /usr/include for your target architecture to recursively search the .h files.

更好的方法是进行设置,以便可以在asm源中使用符号常量,以提高可读性并避免出错的风险.

Even better is to set things up so you can use the symbolic constants in your asm source, for readability and to avoid the risk of errors.

在处理.S文件时,gcc实际上确实使用了C预处理器,但包括大多数C头文件也将为您提供一些C原型.

The gcc actually does use the C Preprocessor when processing .S files, but including most C header files will also get you some C prototypes.

或使用sed等将#define转换为NASM宏.也许将一些#include<>行输入到C预处理器,并使其仅打印出宏定义.

Or convert the #defines to NASM macros with sed or something. Maybe feed some #include<> lines to the C preprocessor and have it print out just the macro definitions.

printf '#include <%s>\n' unistd.h sys/stat.h   |
gcc -dD -E - |
sed -ne 's/^#define \([A-Za-z_0-9]*\) \(.\)/\1\tequ \2/p'

这会将每个非空的#define转换为NASM symbol equ value.当我尝试在其上运行NASM时,生成的文件有很多error: expression syntax error行,但是从中手动选择一些有效行可能会起作用.

That turns every non-empty #define into a NASM symbol equ value. The resulting file has many lines of error: expression syntax error when I tried to run NASM on it, but manually selecting some valid lines from that may work.

一些常量是通过多个步骤定义的,例如#define S_IRGRP (S_IRUSR >> 3).转换为NASM equ符号定义时,这可能会起作用,也可能不会起作用.

Some constants are defined in multiple steps, e.g. #define S_IRGRP (S_IRUSR >> 3). This might or might not work when converted to NASM equ symbol definitions.

还要注意,在C 0666中,它是一个八进制常量.在NASM中,您需要0o666666o.前导0并不特殊.否则,用于十六进制和十进制常数的NASM语法与C兼容.

Also note that in C 0666, is an octal constant. In NASM, you need either 0o666 or 666o; a leading 0 is not special. Otherwise, NASM syntax for hex and decimal constants is compatible with C.

这篇关于nasm系统调用Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆