2013-10-10 79 views
2

到目前爲止,我只知道如何退出由GNU臂組件的程序。在linux下,怎麼做系統調用通過GNU ARM彙編

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

但還是有很多其他系統調用一樣的讀,寫,叉......我想,每個人都需要不同的服務數量,不同數量的寄存器作爲參數,並就如何使用寄存器不同的規則。我的問題是我可以從哪裏獲得關於爲他們每個人編寫程序集的信息。我搜索谷歌,但這個主題的信息較少。

+0

我會檢討'glibc'來源,他們一定有關於每個系統調用的信息。看看'syscall()'宏(''),也許吧。 –

+0

我認爲[](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/arch/arm/include/uapi/asm/unistd.h)給出系統調用號碼。你也可以看看[klibc](http://git.kernel.org/cgit/libs/klibc/klibc.git/tree/usr/klibc/arch/arm)。 –

回答

1

你可以像Android的仿生generate sys call stubs via some metadata and a script的方法或使用Bionic's directly

下面是仿生的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> 
+1

謝謝@auselen。 1年後,我終於明白你說的是什麼^ _ ^。 – wm8120