全部博文(413)
分类: LINUX
2006-03-23 12:25:25
()
The following table lists the system calls for the Linux 2.2 kernel. It could also be thought of as an API for the interface between user space and kernel space. My motivation for making this table was to make programming in assembly language easier when using only system calls and not the C library (for more information on this topic, go to ). On the left are the numbers of the system calls. This number will be put in register %eax. On the right of the table are the types of values to be put into the remaining registers before calling the software interrupt 'int 0x80'. After each syscall, an integer is returned in %eax.
For convenience, the kernel source file where each system call is located is linked to in the column labelled "Source". In order to use the hyperlinks, you must first copy this page to your own machine because the links take you directly to the source code on your system. You must have the kernel source installed (or linked from) under '/usr/src/linux' for this to work.
%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 | dev_t | - | - | |
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 | dev_t | - | - | - | ||
63 | sys_dup2 | unsigned int | unsigned int | - | - | - | |
64 | sys_getppid | - | - | - | - | - | |
65 | sys_getpgrp | - | - | - | - | - | |
66 | sys_setsid | - | - | - | - | - | |
67 | sys_sigaction | int | const | - | - | ||
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 | 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 | - | - | - | - |
: this syscall takes six arguments, so it can't fit into the five registers %ebx - %edi; the last parameter (not shown) is of type 'long'. This syscall requires a special call method where a pointer is put in %ebx which points to an array containing the six arguments.
I will now explain exactly where in the kernel source that I got the information in the table above. I do this because 1) changes in the source are bound to happen, 2) you might be curious, or 3) I might've made an error.
For the numbers of the syscalls, look in for sys_call_table. The syscall numbers are offsets into that table. Several spots in the table are occupied by the syscall sys_ni_syscall. This is a placeholder that either replaces an obsolete syscall or reserves a spot for future syscalls.
Incidentally, the system calls are called from the function system_call in the same file; in particular, they are called with the assembly instruction 'call *SYMBOL_NAME(sys_call_table)(,%eax,4)'. The part '*SYMBOL_NAME(sys_call_table)' just gets replaced by a symbol name in sys_call_table. SYMBOL_NAME is a macro defined in , and it just replaces itself with its argument.
Here are the typedef declarations in the prototypes above:
: #ifdef __SMP__ typedef struct { volatile int counter; } atomic_t; #else typedef struct { int counter; } atomic_t; #endif |
|
:typedef char * __kernel_caddr_t; :typedef __kernel_caddr_t caddr_t; |
|
: typedef struct __user_cap_header_struct { version; int pid; } *cap_user_header_t; |
|
: typedef struct __user_cap_data_struct { effective; permitted; inheritable; } *cap_user_data_t; |
|
:typedef long __kernel_clock_t; :typedef __kernel_clock_t clock_t; |
|
dev_t |
:typedef unsigned short __kernel_dev_t; :typedef __kernel_dev_t dev_t; |
include/linux/posix_types.h #define __FD_SETSIZE 1024 #define __NFDBITS (8 * sizeof(unsigned long)) #define __FDSET_LONGS (__FD_SETSIZE/__NFDBITS) (==> __FDSET_LONGS == 32) typedef struct { unsigned long fds_bits [__FDSET_LONGS]; } __kernel_fd_set; :typedef __kernel_fd_set fd_set; |
|
:typedef unsigned short __kernel_gid_t; :typedef __kernel_gid_t gid_t; |
|
:typedef int __kernel_daddr_t; |
|
: typedef struct { int __val[2]; } __kernel_fsid_t; |
|
:typedef unsigned long __kernel_ino_t; |
|
:typedef unsigned int __kernel_size_t; | |
:typedef long long __kernel_loff_t; :typedef __kernel_loff_t loff_t; |
|
:typedef unsigned short __kernel_mode_t; :typedef __kernel_mode_t mode_t; |
|
:typedef long __kernel_off_t; :typedef __kernel_off_t off_t; | |
:typedef unsigned long old_sigset_t; | |
:typedef int __kernel_pid_t; :typedef __kernel_pid_t pid_t; |
|
:typedef void (*__sighandler_t)(int); | |
: #define SI_MAX_SIZE 128 #define SI_PAD_SIZE ((SI_MAX_SIZE/sizeof(int)) - 3) (==> SI_PAD_SIZE == 29) typedef struct siginfo { int si_signo; int si_errno; int si_code; union { int _pad[SI_PAD_SIZE]; /* kill() */ struct { _pid; /* sender's pid */ _uid; /* sender's uid */ } _kill; /* POSIX.1b timers */ struct { unsigned int _timer1; unsigned int _timer2; } _timer; /* POSIX.1b signals */ struct { _pid; /* sender's pid */ _uid; /* sender's uid */ sigval_t _sigval; } _rt; /* SIGCHLD */ struct { _pid; /* which child */ _uid; /* sender's uid */ int _status; /* exit code */ _utime; _stime; } _sigchld; /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ struct { void *_addr; /* faulting insn/memory ref. */ } _sigfault; /* SIGPOLL */ struct { int _band; /* POLL_IN, POLL_OUT, POLL_MSG */ int _fd; } _sigpoll; } _sifields; } siginfo_t; |
|
:typedef unsigned long sigset_t; | |
:typedef unsigned int __kernel_size_t; :typedef __kernel_size_t size_t; |
|
:typedef int __kernel_ssize_t; :typedef __kernel_ssize_t ssize_t; |
|
: typedef struct sigaltstack { void *ss_sp; int ss_flags; ss_size; } stack_t; |
|
:typedef long __kernel_suseconds_t; :typedef __kernel_suseconds_t suseconds_t; |
|
:typedef long __kernel_time_t;
:typedef __kernel_time_t time_t; |
|
:typedef unsigned short __kernel_uid_t; :typedef __kernel_uid_t uid_t; |
|
:typedef unsigned int uint; | |
:typedef unsigned int __u32; |
Here are the struct declarations for the table at the top:
: struct exception_table_entry { unsigned long insn, fixup; }; |
|
: struct iovec { void *iov_base; iov_len; }; |
|
: struct itimerval { it_interval; /* timer interval */ it_value; /* current value */ }; |
|
: struct kernel_sym { unsigned long value; char name[60]; }; |
|
: struct mmap_arg_struct { unsigned long addr; unsigned long len; unsigned long prot; unsigned long flags; unsigned long fd; unsigned long offset; }; |
|
: struct module { unsigned long size_of_struct; /* sizeof(module) */ *next; const char *name; unsigned long size; union { usecount; long pad; } uc; unsigned long flags; /* AUTOCLEAN et al */ unsigned nsyms; unsigned ndeps; *syms; *deps; *refs; int (*init)(void); void (*cleanup)(void); const *ex_table_start; const *ex_table_end; /* Members past this point are extensions to the basic module support and are optional. Use mod_opt_member() to examine them. */ const *persist_start; const *persist_end; int (*can_unload)(void); }; |
|
: struct module_persist; /* yes, it's empty */ |
|
: struct module_ref { *dep; /* "parent" pointer */ *ref; /* "child" pointer */ *next_ref; }; |
|
: struct module_symbol { unsigned long value; const char *name; }; |
|
: struct new_utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char domainname[65]; }; |
|
: struct __old_kernel_stat { unsigned short st_dev; unsigned short st_ino; unsigned short st_mode; unsigned short st_nlink; unsigned short st_uid; unsigned short st_gid; unsigned short st_rdev; unsigned long st_size; unsigned long st_atime; unsigned long st_mtime; unsigned long st_ctime; }; |
|
: struct oldold_utsname { char sysname[9]; char nodename[9]; char release[9]; char version[9]; char machine[9]; }; |
|
: struct old_sigaction { sa_handler; sa_mask; unsigned long sa_flags; void (*sa_restorer)(void); }; |
|
: struct old_utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; }; |
|
: struct pollfd { int fd; short events; short revents; }; |
|
: struct pt_regs { long ebx; long ecx; long edx; long esi; long edi; long ebp; long eax; int xds; int xes; long orig_eax; long eip; int xcs; long eflags; long esp; int xss; }; |
|
: struct revectored_struct { unsigned long __map[8]; }; |
|
: struct rlimit { long rlim_cur; long rlim_max; }; |
|
: struct rusage { ru_utime; /* user time used */ ru_stime; /* system time used */ long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral shared memory size */ long ru_idrss; /* integral unshared data size */ long ru_isrss; /* integral unshared stack size */ long ru_minflt; /* page reclaims */ long ru_majflt; /* page faults */ long ru_nswap; /* swaps */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_msgsnd; /* messages sent */ long ru_msgrcv; /* messages received */ long ru_nsignals; /* signals received */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary '' */ }; |
|
: struct sched_param { int sched_priority; }; |
|
: struct sel_arg_struct { unsigned long n; *inp, *outp, *exp; *tvp; }; |
|
: struct sigaction { sa_handler; unsigned long sa_flags; void (*sa_restorer)(void); sa_mask; /* mask last for extensibility */ }; |
|
: struct stat { unsigned short st_dev; unsigned short __pad1; unsigned long st_ino; unsigned short st_mode; unsigned short st_nlink; unsigned short st_uid; unsigned short st_gid; unsigned short st_rdev; unsigned short __pad2; unsigned long st_size; unsigned long st_blksize; unsigned long st_blocks; unsigned long st_atime; unsigned long __unused1; unsigned long st_mtime; unsigned long __unused2; unsigned long st_ctime; unsigned long __unused3; unsigned long __unused4; unsigned long __unused5; |
|
: struct statfs { long f_type; long f_bsize; long f_blocks; long f_bfree; long f_bavail; long f_files; long f_ffree; f_fsid; long f_namelen; long f_spare[6]; }; |
|
include/linux/sysctl.h struct __sysctl_args { int *name; int nlen; void *oldval; *oldlenp; void *newval; newlen; unsigned long __unused[4]; }; |
|
: struct sysinfo { long uptime; /* Seconds since boot */ unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ unsigned long totalram; /* Total usable main memory size */ unsigned long freeram; /* Available memory size */ unsigned long sharedram; /* Amount of shared memory */ unsigned long bufferram; /* Memory used by buffers */ unsigned long totalswap; /* Total swap space size */ unsigned long freeswap; /* swap space still available */ unsigned short procs; /* Number of current processes */ char _f[22]; /* Pads structure to 64 bytes */ }; |
|
: struct timex { unsigned int modes; /* mode selector */ long offset; /* time offset (usec) */ long freq; /* frequency offset (scaled ppm) */ long maxerror; /* maximum error (usec) */ long esterror; /* estimated error (usec) */ int status; /* clock command/status */ long constant; /* pll time constant */ long precision; /* clock precision (usec) (read only) */ long tolerance; /* clock frequency tolerance (ppm) * (read only) */ time; /* (read only) */ long tick; /* (modified) usecs between clock ticks */ long ppsfreq; /* pps frequency (scaled ppm) (ro) */ long jitter; /* pps jitter (us) (ro) */ int shift; /* interval duration (s) (shift) (ro) */ long stabil; /* pps stability (scaled ppm) (ro) */ long jitcnt; /* jitter limit exceeded (ro) */ long calcnt; /* calibration intervals (ro) */ long errcnt; /* calibration errors (ro) */ long stbcnt; /* stability limit exceeded (ro) */ int :32; int :32; int :32; int :32; int :32; int :32; int :32; int :32; int :32; int :32; int :32; int :32; }; |
|
: struct timespec { tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; |
|
: struct timeval { tv_sec; /* seconds */ tv_usec; /* microseconds */ }; |
|
: struct timezone { int tz_minuteswest; /* minutes west of Greenwich */ int tz_dsttime; /* type of dst correction */ }; |
|
include/linux/times.h struct tms { tms_utime; tms_stime; tms_cutime; tms_cstime; }; |
|
: struct ustat { f_tfree; f_tinode; char f_fname[6]; char f_fpack[6]; }; |
|
: struct utimbuf { actime; modtime; }; |
|
: struct vm86plus_info_struct { unsigned long force_return_for_pic:1; unsigned long vm86dbg_active:1; unsigned long vm86dbg_TFpendig:1; unsigned long unused:28; unsigned long is_vm86pus:1; unsigned char vm86dbg_intxxtab[32]; }; |
|
: struct vm86plus_struct { regs; unsigned long flags; unsigned long screen_bitmap; unsigned long cpu_type; int_revectored; int21_revectored; vm86plus; }; |
|
: struct vm86_regs { /* normal regs, with special meaning for the segment descriptors.. */ long ebx; long ecx; long edx; long esi; long edi; long ebp; long eax; long __null_ds; long __null_es; long __null_fs; long __null_gs; long orig_eax; long eip; unsigned short cs, __csh; long eflags; long esp; unsigned short ss, __ssh; /* these are specific to v86 mode: */ unsigned short es, __esh; unsigned short ds, __dsh; unsigned short fs, __fsh; unsigned short gs, __gsh; }; |
|
: struct vm86_struct { regs; unsigned long flags; unsigned long screen_bitmap; unsigned long cpu_type; int_revectored; int21_revectored; }; |