x86 Linux の 32bit と 64bit のシステムコールの違い
x86 Linux の 32bit と 64bit ではシステムコールの呼び出し方法と、 システムコール番号が異なります。システムコールの呼び出しは、 32bit では int 0x80 でソフトウェア割り込みを実行することでシステムコールを呼び出していますが、64bit では syscall 命令を実行します。
x86-64 の Linux でシステムコールを呼び出すには以下のようにします。rcx と r11 の内容は保存されません(破壊される)。
- rax にシステムコール番号を設定
- 必要ならば、第 1 引数 を rdi に設定
- 必要ならば、第 2 引数 を rsi に設定
- 必要ならば、第 3 引数 を rdx に設定
- 必要ならば、第 4 引数 を r10 に設定
- 必要ならば、第 5 引数 を r8 に設定
- 必要ならば、第 6 引数 を r9 に設定
- システムコール命令( syscall ) を実行
Linux のカーネルソースの arch/x86/include/asm/ 以下の unistd_32.h と unistd_64.h にはシステムコールの名称と番号の対応が定義 されています。32bit Linux と 64bit Linux のシステムコールの名称とシステムコール番号の対応表を以下に示します。
32 bit | 64 bit | ||
---|---|---|---|
x86_syscall | syscall# | x64_syscall | syscall# |
_llseek | 140 | - | - |
_newselect | 142 | - | - |
_sysctl | 149 | _sysctl | 156 |
- | - | accept | 43 |
- | - | accept4 | 288 |
access | 33 | access | 21 |
acct | 51 | acct | 163 |
add_key | 286 | add_key | 248 |
adjtimex | 124 | adjtimex | 159 |
afs_syscall | 137 | afs_syscall | 183 |
alarm | 27 | alarm | 37 |
- | - | arch_prctl | 158 |
- | - | bind | 49 |
bdflush | 134 | - | - |
break | 17 | - | - |
brk | 45 | brk | 12 |
capget | 184 | capget | 125 |
capset | 185 | capset | 126 |
chdir | 12 | chdir | 80 |
chmod | 15 | chmod | 90 |
chown | 182 | chown | 92 |
chown32 | 212 | - | - |
chroot | 61 | chroot | 161 |
clock_getres | 266 | clock_getres | 229 |
clock_gettime | 265 | clock_gettime | 228 |
clock_nanosleep | 267 | clock_nanosleep | 230 |
clock_settime | 264 | clock_settime | 227 |
clone | 120 | clone | 56 |
close | 6 | close | 3 |
- | - | connect | 42 |
creat | 8 | creat | 85 |
create_module | 127 | create_module | 174 |
delete_module | 129 | delete_module | 176 |
dup | 41 | dup | 32 |
dup2 | 63 | dup2 | 33 |
dup3 | 330 | dup3 | 292 |
epoll_create | 254 | epoll_create | 213 |
epoll_create1 | 329 | epoll_create1 | 291 |
epoll_ctl | 255 | epoll_ctl | 233 |
- | - | epoll_ctl_old | 214 |
epoll_pwait | 319 | epoll_pwait | 281 |
epoll_wait | 256 | epoll_wait | 232 |
- | - | epoll_wait_old | 215 |
eventfd | 323 | eventfd | 284 |
eventfd2 | 328 | eventfd2 | 290 |
execve | 11 | execve | 59 |
exit | 1 | exit | 60 |
exit_group | 252 | exit_group | 231 |
faccessat | 307 | faccessat | 269 |
fadvise64 | 250 | fadvise64 | 221 |
fadvise64_64 | 272 | - | - |
fallocate | 324 | fallocate | 285 |
fchdir | 133 | fchdir | 81 |
fchmod | 94 | fchmod | 91 |
fchmodat | 306 | fchmodat | 268 |
fchown | 95 | fchown | 93 |
fchown32 | 207 | - | - |
fchownat | 298 | fchownat | 260 |
fcntl | 55 | fcntl | 72 |
fcntl64 | 221 | - | - |
fdatasync | 148 | fdatasync | 75 |
fgetxattr | 231 | fgetxattr | 193 |
flistxattr | 234 | flistxattr | 196 |
flock | 143 | flock | 73 |
fork | 2 | fork | 57 |
fremovexattr | 237 | fremovexattr | 199 |
fsetxattr | 228 | fsetxattr | 190 |
fstat | 108 | fstat | 5 |
fstat64 | 197 | - | - |
fstatat64 | 300 | - | - |
fstatfs | 100 | fstatfs | 138 |
fstatfs64 | 269 | - | - |
fsync | 118 | fsync | 74 |
ftime | 35 | - | - |
ftruncate | 93 | ftruncate | 77 |
ftruncate64 | 194 | - | - |
futex | 240 | futex | 202 |
futimesat | 299 | futimesat | 261 |
get_kernel_syms | 130 | get_kernel_syms | 177 |
get_mempolicy | 275 | get_mempolicy | 239 |
get_robust_list | 312 | get_robust_list | 274 |
get_thread_area | 244 | get_thread_area | 211 |
getcpu | 318 | - | - |
getcwd | 183 | getcwd | 79 |
getdents | 141 | getdents | 78 |
getdents64 | 220 | getdents64 | 217 |
getegid | 50 | getegid | 108 |
getegid32 | 202 | - | - |
geteuid | 49 | geteuid | 107 |
geteuid32 | 201 | - | - |
getgid | 47 | getgid | 104 |
getgid32 | 200 | - | - |
getgroups | 80 | getgroups | 115 |
getgroups32 | 205 | - | - |
getitimer | 105 | getitimer | 36 |
- | - | getpeername | 52 |
getpgid | 132 | getpgid | 121 |
getpgrp | 65 | getpgrp | 111 |
getpid | 20 | getpid | 39 |
getpmsg | 188 | getpmsg | 181 |
getppid | 64 | getppid | 110 |
getpriority | 96 | getpriority | 140 |
getresgid | 171 | getresgid | 120 |
getresgid32 | 211 | - | - |
getresuid | 165 | getresuid | 118 |
getresuid32 | 209 | - | - |
- | - | getrlimit | 97 |
getrusage | 77 | getrusage | 98 |
getsid | 147 | getsid | 124 |
- | - | getsockname | 51 |
- | - | getsockopt | 55 |
gettid | 224 | gettid | 186 |
gettimeofday | 78 | gettimeofday | 96 |
getuid | 24 | getuid | 102 |
getuid32 | 199 | - | - |
getxattr | 229 | getxattr | 191 |
gtty | 32 | - | - |
idle | 112 | - | - |
init_module | 128 | init_module | 175 |
inotify_add_watch | 292 | inotify_add_watch | 254 |
inotify_init | 291 | inotify_init | 253 |
inotify_init1 | 332 | inotify_init1 | 294 |
inotify_rm_watch | 293 | inotify_rm_watch | 255 |
io_cancel | 249 | io_cancel | 210 |
io_destroy | 246 | io_destroy | 207 |
io_getevents | 247 | io_getevents | 208 |
io_setup | 245 | io_setup | 206 |
io_submit | 248 | io_submit | 209 |
ioctl | 54 | ioctl | 16 |
ioperm | 101 | ioperm | 173 |
iopl | 110 | iopl | 172 |
ioprio_get | 290 | ioprio_get | 252 |
ioprio_set | 289 | ioprio_set | 251 |
ipc | 117 | - | - |
kexec_load | 283 | kexec_load | 246 |
keyctl | 288 | keyctl | 250 |
kill | 37 | kill | 62 |
lchown | 16 | lchown | 94 |
lchown32 | 198 | lgetxattr | 192 |
lgetxattr | 230 | - | - |
link | 9 | link | 86 |
linkat | 303 | linkat | 265 |
- | - | listen | 50 |
listxattr | 232 | listxattr | 194 |
llistxattr | 233 | llistxattr | 195 |
lock | 53 | - | - |
lookup_dcookie | 253 | lookup_dcookie | 212 |
lremovexattr | 236 | lremovexattr | 198 |
lseek | 19 | lseek | 8 |
lsetxattr | 227 | lsetxattr | 189 |
lstat | 107 | lstat | 6 |
lstat64 | 196 | - | - |
madvise | 219 | madvise | 28 |
madvise1 | 219 | - | - |
mbind | 274 | mbind | 237 |
migrate_pages | 294 | migrate_pages | 256 |
mincore | 218 | mincore | 27 |
mkdir | 39 | mkdir | 83 |
mkdirat | 296 | mkdirat | 258 |
mknod | 14 | mknod | 133 |
mknodat | 297 | mknodat | 259 |
mlock | 150 | mlock | 149 |
mlockall | 152 | mlockall | 151 |
mmap | 90 | mmap | 9 |
mmap2 | 192 | - | - |
modify_ldt | 123 | modify_ldt | 154 |
mount | 21 | mount | 165 |
move_pages | 317 | move_pages | 279 |
mprotect | 125 | mprotect | 10 |
mpx | 56 | - | - |
mq_getsetattr | 282 | mq_getsetattr | 245 |
mq_notify | 281 | mq_notify | 244 |
mq_open | 277 | mq_open | 240 |
mq_timedreceive | 280 | mq_timedreceive | 243 |
mq_timedsend | 279 | mq_timedsend | 242 |
mq_unlink | 278 | mq_unlink | 241 |
mremap | 163 | mremap | 25 |
- | - | msgctl | 71 |
- | - | msgget | 68 |
- | - | msgrcv | 70 |
- | - | msgsnd | 69 |
msync | 144 | msync | 26 |
munlock | 151 | munlock | 150 |
munlockall | 153 | munlockall | 152 |
munmap | 91 | munmap | 11 |
- | - | nanosleep | 35 |
- | - | newfstatat | 262 |
nfsservctl | 169 | nfsservctl | 180 |
nice | 34 | - | - |
oldfstat | 28 | - | - |
oldlstat | 84 | - | - |
oldolduname | 59 | - | - |
oldstat | 18 | - | - |
olduname | 109 | - | - |
open | 5 | open | 2 |
openat | 295 | openat | 257 |
pause | 29 | pause | 34 |
personality | 136 | personality | 135 |
pipe | 42 | pipe | 22 |
pipe2 | 331 | pipe2 | 293 |
pivot_root | 217 | pivot_root | 155 |
poll | 168 | poll | 7 |
ppoll | 309 | ppoll | 271 |
prctl | 172 | prctl | 157 |
pread64 | 180 | pread64 | 17 |
prof | 44 | - | - |
profil | 98 | - | - |
pselect6 | 308 | pselect6 | 270 |
ptrace | 26 | ptrace | 101 |
putpmsg | 189 | putpmsg | 182 |
pwrite64 | 181 | pwrite64 | 18 |
query_module | 167 | query_module | 178 |
quotactl | 131 | quotactl | 179 |
read | 3 | read | 0 |
readahead | 225 | readahead | 187 |
readdir | 89 | - | - |
readlink | 85 | readlink | 89 |
readlinkat | 305 | readlinkat | 267 |
readv | 145 | readv | 19 |
reboot | 88 | reboot | 169 |
- | - | recvfrom | 45 |
- | - | recvmsg | 47 |
remap_file_pages | 257 | remap_file_pages | 216 |
removexattr | 235 | removexattr | 197 |
rename | 38 | rename | 82 |
renameat | 302 | renameat | 264 |
request_key | 287 | request_key | 249 |
restart_syscall | 0 | restart_syscall | 219 |
rmdir | 40 | rmdir | 84 |
rt_sigaction | 174 | rt_sigaction | 13 |
rt_sigpending | 176 | rt_sigpending | 127 |
rt_sigprocmask | 175 | rt_sigprocmask | 14 |
rt_sigqueueinfo | 178 | rt_sigqueueinfo | 129 |
rt_sigreturn | 173 | rt_sigreturn | 15 |
rt_sigsuspend | 179 | rt_sigsuspend | 130 |
rt_sigtimedwait | 177 | rt_sigtimedwait | 128 |
sched_get_priority_max | 159 | sched_get_priority_max | 146 |
sched_get_priority_min | 160 | sched_get_priority_min | 147 |
sched_getaffinity | 242 | sched_getaffinity | 204 |
sched_getparam | 155 | sched_getparam | 143 |
sched_getscheduler | 157 | sched_getscheduler | 145 |
sched_rr_get_interval | 161 | sched_rr_get_interval | 148 |
sched_setaffinity | 241 | sched_setaffinity | 203 |
sched_setparam | 154 | sched_setparam | 142 |
sched_setscheduler | 156 | sched_setscheduler | 144 |
sched_yield | 158 | sched_yield | 24 |
- | - | security | 185 |
select | 82 | select | 23 |
- | - | semctl | 66 |
- | - | semget | 64 |
- | - | semop | 65 |
- | - | semtimedop | 220 |
sendfile | 187 | sendfile | 40 |
sendfile64 | 239 | - | - |
- | - | sendmsg | 46 |
- | - | sendto | 44 |
set_mempolicy | 276 | set_mempolicy | 238 |
set_robust_list | 311 | set_robust_list | 273 |
set_thread_area | 243 | set_thread_area | 205 |
set_tid_address | 258 | set_tid_address | 218 |
setdomainname | 121 | setdomainname | 171 |
setfsgid | 139 | setfsgid | 123 |
setfsgid32 | 216 | - | - |
setfsuid | 138 | setfsuid | 122 |
setfsuid32 | 215 | - | - |
setgid | 46 | setgid | 106 |
setgid32 | 214 | - | - |
setgroups | 81 | setgroups | 116 |
setgroups32 | 206 | - | - |
sethostname | 74 | sethostname | 170 |
setitimer | 104 | setitimer | 38 |
setpgid | 57 | setpgid | 109 |
setpriority | 97 | setpriority | 141 |
setregid | 71 | setregid | 114 |
setregid32 | 204 | - | - |
setresgid | 170 | setresgid | 119 |
setresgid32 | 210 | - | - |
setresuid | 164 | setresuid | 117 |
setresuid32 | 208 | - | - |
setreuid | 70 | setreuid | 113 |
setreuid32 | 203 | - | - |
setrlimit | 75 | setrlimit | 160 |
setsid | 66 | setsid | 112 |
- | - | setsockopt | 54 |
settimeofday | 79 | settimeofday | 164 |
setuid | 23 | setuid | 105 |
setuid32 | 213 | - | - |
setxattr | 226 | setxattr | 188 |
sgetmask | 68 | - | - |
- | - | shmat | 30 |
- | - | shmctl | 31 |
- | - | shmdt | 67 |
- | - | shmget | 29 |
- | - | shutdown | 48 |
sigaction | 67 | - | - |
sigaltstack | 186 | sigaltstack | 131 |
signal | 48 | - | - |
signalfd | 321 | signalfd | 282 |
signalfd4 | 327 | signalfd4 | 289 |
sigpending | 73 | - | - |
sigprocmask | 126 | - | - |
sigreturn | 119 | - | - |
sigsuspend | 72 | - | - |
- | - | socket | 41 |
socketcall | 102 | - | - |
- | - | socketpair | 53 |
splice | 313 | splice | 275 |
ssetmask | 69 | - | - |
stat | 106 | stat | 4 |
stat64 | 195 | - | - |
statfs | 99 | statfs | 137 |
statfs64 | 268 | - | - |
stime | 25 | - | - |
stty | 31 | - | - |
swapoff | 115 | swapoff | 168 |
swapon | 87 | swapon | 167 |
symlink | 83 | symlink | 88 |
symlinkat | 304 | symlinkat | 266 |
sync | 36 | sync | 162 |
sync_file_range | 314 | sync_file_range | 277 |
sysfs | 135 | sysfs | 139 |
sysinfo | 116 | sysinfo | 99 |
syslog | 103 | syslog | 103 |
tee | 315 | tee | 276 |
tgkill | 270 | tgkill | 234 |
time | 13 | time | 201 |
timer_create | 259 | timer_create | 222 |
timer_delete | 263 | timer_delete | 226 |
timer_getoverrun | 262 | timer_getoverrun | 225 |
timer_gettime | 261 | timer_gettime | 224 |
timer_settime | 260 | timer_settime | 223 |
timerfd_create | 322 | timerfd_create | 283 |
timerfd_gettime | 326 | timerfd_gettime | 287 |
timerfd_settime | 325 | timerfd_settime | 286 |
times | 43 | times | 100 |
tkill | 238 | tkill | 200 |
truncate | 92 | truncate | 76 |
truncate64 | 193 | - | - |
- | - | tuxcall | 184 |
ugetrlimit | 191 | - | - |
ulimit | 58 | - | - |
umask | 60 | umask | 95 |
umount | 22 | - | - |
umount2 | 52 | umount2 | 166 |
uname | 122 | uname | 63 |
unlink | 10 | unlink | 87 |
unlinkat | 301 | unlinkat | 263 |
unshare | 310 | unshare | 272 |
uselib | 86 | uselib | 134 |
ustat | 62 | ustat | 136 |
utime | 30 | utime | 132 |
utimensat | 320 | utimensat | 280 |
utimes | 271 | utimes | 235 |
vfork | 190 | vfork | 58 |
vhangup | 111 | vhangup | 153 |
vm86 | 166 | - | - |
vm86old | 113 | - | - |
vmsplice | 316 | vmsplice | 278 |
vserver | 273 | vserver | 236 |
wait4 | 114 | wait4 | 61 |
waitid | 284 | waitid | 247 |
waitpid | 7 | - | - |
write | 4 | write | 1 |
writev | 146 | writev | 20 |