在linux下,如何通过GNU ARM程序集进行系统调用 [英] In linux, how to do system calls through GNU ARM assembly

查看:20
本文介绍了在linux下,如何通过GNU ARM程序集进行系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我只知道如何通过 gnu arm assembly 退出程序.

Till now, I only know how to exit a program by gnu arm assembly.

#exit(0)
mov r0, #0    # return code
mov r7, #1    # supervisor service number
svc           # call supervisor service

但是还有很多其他的系统调用,比如读、写、分叉……我想它们中的每一个都需要不同的服务编号、不同数量的寄存器作为参数以及关于如何使用寄存器的不同规则.我的问题是在哪里可以获得有关为每个人编写程序集的信息.我在谷歌上搜索过,但关于这个主题的信息较少.

But there are still many other syscalls like read, write, fork... I suppose that each of them will require different service number, different numbers of registers as arguments and different rules on how to use registers. My question is where I can get information on writing assembly for each of them. I searched google but the information is less on this topic.

推荐答案

你可以采用像 Android 的 Bionic 和 通过一些元数据和脚本生成系统调用存根 或使用 仿生的直接.

You can take an approach like Android's Bionic and generate sys call stubs via some metadata and a script or use Bionic's directly.

以下来自 Bionic 的 libc/SYSCALLS.TXT

Below is from Bionic's libc/SYSCALLS.TXT

# this file is used to list all the syscalls that will be supported by
# the Bionic C library. It is used to automatically generate the syscall
# stubs, the list of syscall constants (__NR_xxxx) and the content of <linux/_unistd.h>
#
# each non comment line has the following format:
#
# return_type    func_name[:syscall_name[:call_id]]([parameter_list])  (syscall_number|"stub")
#
# note that:
#      - syscall_name correspond to the name of the syscall, which may differ from
#        the exported function name (example: the exit syscall is implemented by the _exit()
#        function, which is not the same as the standard C exit() function which calls it)
#        The call_id parameter, given that func_name and syscall_name have
#        been provided, allows the user to specify dispatch style syscalls.
#        For example, socket() syscall on i386 actually becomes:
#          socketcall(__NR_socket, 1, *(rest of args on stack)).
#
#      - each parameter type is assumed to be stored on 32 bits, there is no plan to support
#        64-bit architectures at the moment
#
#      - it there is "stub" instead of a syscall number, the tool will not generate any
#        assembler template for the syscall; it's up to the bionic implementation to provide
#        a relevant C stub
#
#      - additionally, if the syscall number is different amoung ARM, and x86, MIPS use:
#        return_type funcname[:syscall_name](parameters) arm_number,x86_number,mips_number
#
# the file is processed by a python script named gensyscalls.py
#

# process management
void    _exit:exit_group (int)      248,252,246
void    _exit_thread:exit (int)     1
pid_t   __fork:fork (void)           2

<skipped rest of the file>

这篇关于在linux下,如何通过GNU ARM程序集进行系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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