Chinaunix首页 | 论坛 | 博客
  • 博客访问: 458036
  • 博文数量: 134
  • 博客积分: 3056
  • 博客等级: 中校
  • 技术积分: 1150
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-14 15:53
文章分类
文章存档

2013年(1)

2010年(133)

我的朋友

分类: LINUX

2010-06-03 19:25:14

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, links go from the "Name" column to the man page for most of the system calls. Links to the kernel source file where each system call is located are linked to in the column labelled "Source". (You can also a version of this page which has links directly to the source that is installed on your system.) Links to definitions are provided for the parameters that are typedefs or structs.

%eax Name Source %ebx %ecx %edx %esx %edi
1 int - - - -
2 - - - -
3 unsigned int char * - -
4 unsigned int const char * - -
5 const char * int int - -
6 unsigned int - - - -
7 pid_t unsigned int * int - -
8 const char * int - - -
9 const char * const char * - - -
10 const char * - - - -
11 - - - -
12 const char * - - - -
13 int * - - - -
14 const char * int dev_t - -
15 const char * - - -
16 const char * - -
18 char * - - -
19 unsigned int unsigned int - -
20 - - - - -
21 char * char * char * - -
22 sys_oldumount char * - - - -
23 - - - -
24 - - - - -
25 int * - - - -
26 long long long long -
27 unsigned int - - - -
28 unsigned int - - -
29 - - - - -
30 char * - - -
33 const char * int - - -
34 int - - - -
36 - - - - -
37 int int - - -
38 const char * const char * - - -
39 const char * int - - -
40 const char * - - - -
41 unsigned int - - - -
42 unsigned long * - - - -
43 - - - -
45 unsigned long - - - -
46 - - - -
47 - - - - -
48 int - - -
49 - - - - -
50 - - - - -
51 const char * - - - -
52 char * int - - -
54 unsigned int unsigned int unsigned long - -
55 unsigned int unsigned int unsigned long - -
57 - - -
59 - - - -
60 int - - - -
61 const char * - - - -
62 dev_t - - -
63 unsigned int unsigned int - - -
64 - - - - -
65 - - - - -
66 - - - - -
67 int const - -
68 - - - - -
69 int - - - -
70 - - -
71 - - -
72 int int - -
73 - - - -
74 char * int - - -
75 unsigned int - - -
76 unsigned int - - -
77 int - - -
78 - - -
79 - - -
80 int - - -
81 int - - -
82 old_select - - - -
83 const char * const char * - - -
84 char * - - -
85 const char * char * int - -
86 const char * - - - -
87 const char * int - - -
88 int int int void * -
89 old_readdir unsigned int void * unsigned int - -
90 old_mmap - - - -
91 unsigned long - - -
92 const char * unsigned long - - -
93 unsigned int unsigned long - - -
94 unsigned int - - -
95 unsigned int - -
96 int int - - -
97 int int int - -
99 const char * - - -
100 unsigned int - - -
101 unsigned long unsigned long int - -
102 int unsigned long * - - -
103 int char * int - -
104 int - -
105 int - - -
106 sys_newstat char * - - -
107 sys_newlstat char * - - -
108 sys_newfstat unsigned int - - -
109 - - - -
110 unsigned long - - - -
111 - - - - -
112 - - - - -
113 unsigned long - - -
114 unsigned long * int options -
115 const char * - - - -
116 - - - -
117 sys_ipc int int int void *
118 unsigned int - - - -
119 unsigned long - - - -
120 - - - -
121 char * int - - -
122 sys_newuname - - - -
123 int void * unsigned long - -
124 - - - -
125 unsigned long unsigned long - -
126 int - -
127 const char * - - -
128 const char * - - -
129 const char * - - - -
130 - - - -
131 int const char * int -
132 - - - -
133 unsigned int - - - -
134 int long - - -
135 int unsigned long unsigned long - -
136 unsigned long - - - -
138 - - - -
139 - - - -
140 unsigned int unsigned long unsigned long unsigned int
141 unsigned int void * unsigned int - -
142 int
143 unsigned int unsigned int - - -
144 unsigned long int - -
145 unsigned long unsigned long - -
146 unsigned long unsigned long - -
147 - - - -
148 unsigned int - - - -
149 - - - -
150 unsigned long - - -
151 unsigned long - - -
152 int - - - -
153 - - - - -
154 - - -
155 - - -
156 int - -
157 - - - -
158 - - - - -
159 int - - - -
160 int - - - -
161 - - -
162 - - -
163 unsigned long unsigned long unsigned long unsigned long -
164 - -
165 - -
166 - - - -
167 const char * int char *
168 unsigned int long - -
169 int void * void * - -
170 - -
171 - -
172 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 unsigned int char * -
181 unsigned int const char * -
182 const char * - -
183 sys_getcwd char * unsigned long - - -
184 - - -
185 - - -
186 - - -
187 int int -
190 - - - -

: 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.

System Call Numbers

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.

Typedefs

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;

 

Structs

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;
};
阅读(734) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~