在网上找了好一会儿才找到,自己整理一下,也方便以后查看。
参考网址:
http://zh.wikipedia.org/wiki/%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8
http://docs.cs.up.ac.za/programming/asm/derick_tut/syscalls.html
1.系统调用
在计算机中,系统调用(英语:system call),又称为系统呼叫,指运行在使用者空间的程序向操作系统内核请求需要更高权限运行的服务。 系统调用提供了用户程序与操作系统之间的接口。大多数系统交互式操作需求在内核态执行。如设备IO操作或者进程间通信。
Linux的系统调用通过int 80h实现,用系统调用号来区分入口函数。 操作系统实现系统调用的基本过程是:
应用程序调用库函数(API);
API将系统调用号存入EAX,然后通过中断调用使系统进入内核态;
内核中的中断处理函数根据系统调用号,调用对应的内核函数(系统调用);
系统调用完成相应功能,将返回值存入EAX,返回到中断处理函数;
中断处理函数返回到API中;
API将EAX返回给应用程序。
2.系统调用表(表格我整理成了excel下载,基于linux2.2的,不过应该都差不多)
寄存器eax存放调用号,剩下的几个寄存器存放参数。
以sys_write为例说明:
函数原型:
sys_write(unsigned int fd, const char * buf, size_t count)
下面是对于Linux汇编Helloworld的一些注释,可以对应系统调用表来看
[section .data]
strHello db "Hello, world!",0Ah
STRLEN equ $ - strHello
[section .text]
global _start
_start:
mov edx,STRLEN;对应参数count
mov ecx,strHello;对应参数buf
mov ebx,1;对应参数fd,fd = 1,在linux中对应于stdout,指的是显示屏
mov eax,4;系统调用号为4,sys_write
int 0x80
mov ebx,0;参数为0,exit(0)
mov eax,1;系统调用号为1,sys_exit
int 0x80
%eax | Name | Source | %ebx | %ecx | %edx | %esx | %edi |
1 | sys_exit | int | - | - | - | - | |
2 | sys_fork | - | - | - | - | ||
3 | sys_read | unsigned int | char * | - | - | ||
4 | sys_write | unsigned int | const char * | - | - | ||
5 | sys_open | const char * | int | int | - | - | |
6 | sys_close | unsigned int | - | - | - | - | |
7 | sys_waitpid | pid_t | unsigned int * | int | - | - | |
8 | sys_creat | const char * | int | - | - | - | |
9 | sys_link | const char * | const char * | - | - | - | |
10 | sys_unlink | const char * | - | - | - | - | |
11 | sys_execve | - | - | - | - | ||
12 | sys_chdir | const char * | - | - | - | - | |
13 | sys_time | int * | - | - | - | - | |
14 | sys_mknod | const char * | int | - | - | ||
15 | sys_chmod | const char * | - | - | - | ||
16 | sys_lchown | const char * | - | - | |||
18 | sys_stat | char * | - | - | - | ||
19 | sys_lseek | unsigned int | unsigned int | - | - | ||
20 | sys_getpid | - | - | - | - | - | |
21 | sys_mount | char * | char * | char * | - | - | |
22 | sys_oldumount | char * | - | - | - | - | |
23 | sys_setuid | - | - | - | - | ||
24 | sys_getuid | - | - | - | - | - | |
25 | sys_stime | int * | - | - | - | - | |
26 | sys_ptrace | long | long | long | long | - | |
27 | sys_alarm | unsigned int | - | - | - | - | |
28 | sys_fstat | unsigned int | - | - | - | ||
29 | sys_pause | - | - | - | - | - | |
30 | sys_utime | char * | - | - | - | ||
33 | sys_access | const char * | int | - | - | - | |
34 | sys_nice | int | - | - | - | - | |
36 | sys_sync | - | - | - | - | - | |
37 | sys_kill | int | int | - | - | - | |
38 | sys_rename | const char * | const char * | - | - | - | |
39 | sys_mkdir | const char * | int | - | - | - | |
40 | sys_rmdir | const char * | - | - | - | - | |
41 | sys_dup | unsigned int | - | - | - | - | |
42 | sys_pipe | unsigned long * | - | - | - | - | |
43 | sys_times | - | - | - | - | ||
45 | sys_brk | unsigned long | - | - | - | - | |
46 | sys_setgid | - | - | - | - | ||
47 | sys_getgid | - | - | - | - | - | |
48 | sys_signal | int | - | - | - | ||
49 | sys_geteuid | - | - | - | - | - | |
50 | sys_getegid | - | - | - | - | - | |
51 | sys_acct | const char * | - | - | - | - | |
52 | sys_umount | char * | int | - | - | - | |
54 | sys_ioctl | unsigned int | unsigned int | unsigned long | - | - | |
55 | sys_fcntl | unsigned int | unsigned int | unsigned long | - | - | |
57 | sys_setpgid | - | - | - | |||
59 | sys_olduname | - | - | - | - | ||
60 | sys_umask | int | - | - | - | - | |
61 | sys_chroot | const char * | - | - | - | - | |
62 | sys_ustat | - | - | - | |||
63 | sys_dup2 | unsigned int | unsigned int | - | - | - | |
64 | sys_getppid | - | - | - | - | - | |
65 | sys_getpgrp | - | - | - | - | - | |
66 | sys_setsid | - | - | - | - | - | |
67 | sys_sigaction | int | const struct old_sigaction * | - | - | ||
68 | sys_sgetmask | - | - | - | - | - | |
69 | sys_ssetmask | int | - | - | - | - | |
70 | sys_setreuid | - | - | - | |||
71 | sys_setregid | - | - | - | |||
72 | sys_sigsuspend | int | int | - | - | ||
73 | sys_sigpending | - | - | - | - | ||
74 | sys_sethostname | char * | int | - | - | - | |
75 | sys_setrlimit | unsigned int | - | - | - | ||
76 | sys_getrlimit | unsigned int | - | - | - | ||
77 | sys_getrusage | int | - | - | - | ||
78 | sys_gettimeofday | - | - | - | |||
79 | sys_settimeofday | - | - | - | |||
80 | sys_getgroups | int | - | - | - | ||
81 | sys_setgroups | int | - | - | - | ||
82 | old_select | - | - | - | - | ||
83 | sys_symlink | const char * | const char * | - | - | - | |
84 | sys_lstat | char * | - | - | - | ||
85 | sys_readlink | const char * | char * | int | - | - | |
86 | sys_uselib | const char * | - | - | - | - | |
87 | sys_swapon | const char * | int | - | - | - | |
88 | sys_reboot | int | int | int | void * | - | |
89 | old_readdir | unsigned int | void * | unsigned int | - | - | |
90 | old_mmap | - | - | - | - | ||
91 | sys_munmap | unsigned long | - | - | - | ||
92 | sys_truncate | const char * | unsigned long | - | - | - | |
93 | sys_ftruncate | unsigned int | unsigned long | - | - | - | |
94 | sys_fchmod | unsigned int | - | - | - | ||
95 | sys_fchown | unsigned int | - | - | |||
96 | sys_getpriority | int | int | - | - | - | |
97 | sys_setpriority | int | int | int | - | - | |
99 | sys_statfs | const char * | - | - | - | ||
100 | sys_fstatfs | unsigned int | - | - | - | ||
101 | sys_ioperm | unsigned long | unsigned long | int | - | - | |
102 | sys_socketcall | int | unsigned long * | - | - | - | |
103 | sys_syslog | int | char * | int | - | - | |
104 | sys_setitimer | int | - | - | |||
105 | sys_getitimer | int | - | - | - | ||
106 | sys_newstat | char * | - | - | - | ||
107 | sys_newlstat | char * | - | - | - | ||
108 | sys_newfstat | unsigned int | - | - | - | ||
109 | sys_uname | - | - | - | - | ||
110 | sys_iopl | unsigned long | - | - | - | - | |
111 | sys_vhangup | - | - | - | - | - | |
112 | sys_idle | - | - | - | - | - | |
113 | sys_vm86old | unsigned long | - | - | - | ||
114 | sys_wait4 | unsigned long * | int options | - | |||
115 | sys_swapoff | const char * | - | - | - | - | |
116 | sys_sysinfo | - | - | - | - | ||
117 | sys_ipc (*Note) | int | int | int | void * | ||
118 | sys_fsync | unsigned int | - | - | - | - | |
119 | sys_sigreturn | unsigned long | - | - | - | - | |
120 | sys_clone | - | - | - | - | ||
121 | sys_setdomainname | char * | int | - | - | - | |
122 | sys_newuname | - | - | - | - | ||
123 | sys_modify_ldt | int | void * | unsigned long | - | - | |
124 | sys_adjtimex | - | - | - | - | ||
125 | sys_mprotect | unsigned long | unsigned long | - | - | ||
126 | sys_sigprocmask | int | - | - | |||
127 | sys_create_module | const char * | - | - | - | ||
128 | sys_init_module | const char * | - | - | - | ||
129 | sys_delete_module | const char * | - | - | - | - | |
130 | sys_get_kernel_syms | - | - | - | - | ||
131 | sys_quotactl | int | const char * | int | - | ||
132 | sys_getpgid | - | - | - | - | ||
133 | sys_fchdir | unsigned int | - | - | - | - | |
134 | sys_bdflush | int | long | - | - | - | |
135 | sys_sysfs | int | unsigned long | unsigned long | - | - | |
136 | sys_personality | unsigned long | - | - | - | - | |
138 | sys_setfsuid | - | - | - | - | ||
139 | sys_setfsgid | - | - | - | - | ||
140 | sys_llseek | unsigned int | unsigned long | unsigned long | unsigned int | ||
141 | sys_getdents | unsigned int | void * | unsigned int | - | - | |
142 | sys_select | int | |||||
143 | sys_flock | unsigned int | unsigned int | - | - | - | |
144 | sys_msync | unsigned long | int | - | - | ||
145 | sys_readv | unsigned long | unsigned long | - | - | ||
146 | sys_writev | unsigned long | unsigned long | - | - | ||
147 | sys_getsid | - | - | - | - | ||
148 | sys_fdatasync | unsigned int | - | - | - | - | |
149 | sys_sysctl | - | - | - | - | ||
150 | sys_mlock | unsigned long | - | - | - | ||
151 | sys_munlock | unsigned long | - | - | - | ||
152 | sys_mlockall | int | - | - | - | - | |
153 | sys_munlockall | - | - | - | - | - | |
154 | sys_sched_setparam | - | - | - | |||
155 | sys_sched_getparam | - | - | - | |||
156 | sys_sched_setscheduler | int | - | - | |||
157 | sys_sched_getscheduler | - | - | - | - | ||
158 | sys_sched_yield | - | - | - | - | - | |
159 | sys_sched_get_priority_max | int | - | - | - | - | |
160 | sys_sched_get_priority_min | int | - | - | - | - | |
161 | sys_sched_rr_get_interval | - | - | - | |||
162 | sys_nanosleep | - | - | - | |||
163 | sys_mremap | unsigned long | unsigned long | unsigned long | unsigned long | - | |
164 | sys_setresuid | - | - | ||||
165 | sys_getresuid | - | - | ||||
166 | sys_vm86 | - | - | - | - | ||
167 | sys_query_module | const char * | int | char * | |||
168 | sys_poll | unsigned int | long | - | - | ||
169 | sys_nfsservctl | int | void * | void * | - | - | |
170 | sys_setresgid | - | - | ||||
171 | sys_getresgid | - | - | ||||
172 | sys_prctl | int | unsigned long | unsigned long | unsigned long | unsigned long | |
173 | sys_rt_sigreturn | unsigned long | - | - | - | - | |
174 | sys_rt_sigaction | int | - | ||||
175 | sys_rt_sigprocmask | int | - | ||||
176 | sys_rt_sigpending | - | - | - | |||
177 | sys_rt_sigtimedwait | - | |||||
178 | sys_rt_sigqueueinfo | int | int | - | - | ||
179 | sys_rt_sigsuspend | - | - | - | |||
180 | sys_pread | unsigned int | char * | - | |||
181 | sys_pwrite | unsigned int | const char * | - | |||
182 | sys_chown | const char * | - | - | |||
183 | sys_getcwd | char * | unsigned long | - | - | - | |
184 | sys_capget | - | - | - | |||
185 | sys_capset | - | - | - | |||
186 | sys_sigaltstack | - | - | - | |||
187 | sys_sendfile | int | int | - | |||
190 | sys_vfork | - | - | - | - |