2 * Compatibility mode system call entry point for x86-64.
4 * Copyright 2000-2002 Andi Kleen, SuSE Labs.
7 #include <asm/dwarf2.h>
8 #include <asm/calling.h>
9 #include <asm/asm-offsets.h>
10 #include <asm/current.h>
11 #include <asm/errno.h>
12 #include <asm/ia32_unistd.h>
13 #include <asm/thread_info.h>
14 #include <asm/segment.h>
15 #include <asm/irqflags.h>
16 #include <linux/linkage.h>
18 #define IA32_NR_syscalls ((ia32_syscall_end - ia32_sys_call_table)/8)
20 .macro IA32_ARG_FIXUP noebp=0
28 movl %edx,%edx /* zero extension */
40 .macro LOAD_ARGS32 offset
41 movl \offset(%rsp),%r11d
42 movl \offset+8(%rsp),%r10d
43 movl \offset+16(%rsp),%r9d
44 movl \offset+24(%rsp),%r8d
45 movl \offset+40(%rsp),%ecx
46 movl \offset+48(%rsp),%edx
47 movl \offset+56(%rsp),%esi
48 movl \offset+64(%rsp),%edi
49 movl \offset+72(%rsp),%eax
52 .macro CFI_STARTPROC32 simple
65 * 32bit SYSENTER instruction entry.
68 * %eax System call number.
79 * This is purely a fast path. For anything complicated we use the int 0x80
80 * path below. Set up a complete hardware stack frame to share code
81 * with the int 0x80 path.
83 ENTRY(ia32_sysenter_target)
84 CFI_STARTPROC32 simple
89 movq %gs:pda_kernelstack, %rsp
90 addq $(PDA_STACKOFFSET),%rsp
92 * No need to follow this irqs on/off section: the syscall
93 * disabled irqs, here we enable it straight after entry:
96 movl %ebp,%ebp /* zero extension */
98 CFI_ADJUST_CFA_OFFSET 8
99 /*CFI_REL_OFFSET ss,0*/
101 CFI_ADJUST_CFA_OFFSET 8
104 CFI_ADJUST_CFA_OFFSET 8
105 /*CFI_REL_OFFSET rflags,0*/
106 movl 8*3-THREAD_SIZE+threadinfo_sysenter_return(%rsp), %r10d
109 CFI_ADJUST_CFA_OFFSET 8
110 /*CFI_REL_OFFSET cs,0*/
113 CFI_ADJUST_CFA_OFFSET 8
116 CFI_ADJUST_CFA_OFFSET 8
119 /* no need to do an access_ok check here because rbp has been
120 32bit zero extended */
122 .section __ex_table,"a"
125 GET_THREAD_INFO(%r10)
126 orl $TS_COMPAT,threadinfo_status(%r10)
127 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
129 jnz sysenter_tracesys
131 cmpl $(IA32_NR_syscalls-1),%eax
134 call *ia32_sys_call_table(,%rax,8)
135 movq %rax,RAX-ARGOFFSET(%rsp)
136 GET_THREAD_INFO(%r10)
139 testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
140 jnz int_ret_from_sys_call
141 andl $~TS_COMPAT,threadinfo_status(%r10)
142 /* clear IF, that popfq doesn't enable interrupts early */
143 andl $~0x200,EFLAGS-R11(%rsp)
144 movl RIP-R11(%rsp),%edx /* User %eip */
146 RESTORE_ARGS 1,24,1,1,1,1
148 CFI_ADJUST_CFA_OFFSET -8
149 /*CFI_RESTORE rflags*/
150 popq %rcx /* User %esp */
151 CFI_ADJUST_CFA_OFFSET -8
155 sti /* sti only takes effect after the next instruction */
165 movq $-ENOSYS,RAX(%rsp) /* really needed? */
166 movq %rsp,%rdi /* &pt_regs -> arg1 */
167 call syscall_trace_enter
168 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
173 ENDPROC(ia32_sysenter_target)
176 * 32bit SYSCALL instruction entry.
179 * %eax System call number.
185 * %ebp Arg2 [note: not saved in the stack frame, should not be touched]
191 * This is purely a fast path. For anything complicated we use the int 0x80
192 * path below. Set up a complete hardware stack frame to share code
193 * with the int 0x80 path.
195 ENTRY(ia32_cstar_target)
196 CFI_STARTPROC32 simple
198 CFI_DEF_CFA rsp,PDA_STACKOFFSET
200 /*CFI_REGISTER rflags,r11*/
204 movq %gs:pda_kernelstack,%rsp
206 * No need to follow this irqs on/off section: the syscall
207 * disabled irqs and here we enable it straight after entry:
211 movl %eax,%eax /* zero extension */
212 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
213 movq %rcx,RIP-ARGOFFSET(%rsp)
214 CFI_REL_OFFSET rip,RIP-ARGOFFSET
215 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */
217 movq $__USER32_CS,CS-ARGOFFSET(%rsp)
218 movq $__USER32_DS,SS-ARGOFFSET(%rsp)
219 movq %r11,EFLAGS-ARGOFFSET(%rsp)
220 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
221 movq %r8,RSP-ARGOFFSET(%rsp)
222 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
223 /* no need to do an access_ok check here because r8 has been
224 32bit zero extended */
225 /* hardware stack frame is complete now */
227 .section __ex_table,"a"
230 GET_THREAD_INFO(%r10)
231 orl $TS_COMPAT,threadinfo_status(%r10)
232 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
236 cmpl $IA32_NR_syscalls-1,%eax
239 call *ia32_sys_call_table(,%rax,8)
240 movq %rax,RAX-ARGOFFSET(%rsp)
241 GET_THREAD_INFO(%r10)
244 testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
245 jnz int_ret_from_sys_call
246 andl $~TS_COMPAT,threadinfo_status(%r10)
247 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
248 movl RIP-ARGOFFSET(%rsp),%ecx
250 movl EFLAGS-ARGOFFSET(%rsp),%r11d
251 /*CFI_REGISTER rflags,r11*/
253 movl RSP-ARGOFFSET(%rsp),%esp
264 movq $-ENOSYS,RAX(%rsp) /* really needed? */
265 movq %rsp,%rdi /* &pt_regs -> arg1 */
266 call syscall_trace_enter
267 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
270 movl RSP-ARGOFFSET(%rsp), %r8d
272 END(ia32_cstar_target)
280 * Emulated IA32 system calls via int 0x80.
283 * %eax System call number.
289 * %ebp Arg6 [note: not saved in the stack frame, should not be touched]
292 * Uses the same stack frame as the x86-64 version.
293 * All registers except %eax must be saved (but ptrace may violate that)
294 * Arguments are zero extended. For system calls that want sign extension and
295 * take long arguments a wrapper is needed. Most calls can just be called
297 * Assumes it is only called from user space and entered with interrupts off.
301 CFI_STARTPROC32 simple
303 CFI_DEF_CFA rsp,SS+8-RIP
304 /*CFI_REL_OFFSET ss,SS-RIP*/
305 CFI_REL_OFFSET rsp,RSP-RIP
306 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
307 /*CFI_REL_OFFSET cs,CS-RIP*/
308 CFI_REL_OFFSET rip,RIP-RIP
311 * No need to follow this irqs on/off section: the syscall
312 * disabled irqs and here we enable it straight after entry:
317 CFI_ADJUST_CFA_OFFSET 8
319 /* note the registers are not zero extended to the sf.
320 this could be a problem. */
322 GET_THREAD_INFO(%r10)
323 orl $TS_COMPAT,threadinfo_status(%r10)
324 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
327 cmpl $(IA32_NR_syscalls-1),%eax
330 call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
332 movq %rax,RAX-ARGOFFSET(%rsp)
333 jmp int_ret_from_sys_call
338 movq $-ENOSYS,RAX(%rsp) /* really needed? */
339 movq %rsp,%rdi /* &pt_regs -> arg1 */
340 call syscall_trace_enter
341 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
347 movq $0,ORIG_RAX-ARGOFFSET(%rsp)
348 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
349 jmp int_ret_from_sys_call
356 .macro PTREGSCALL label, func, arg
359 leaq \func(%rip),%rax
360 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
361 jmp ia32_ptregs_common
366 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
367 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
368 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
369 PTREGSCALL stub32_sigsuspend, sys32_sigsuspend, %rcx
370 PTREGSCALL stub32_execve, sys32_execve, %rcx
371 PTREGSCALL stub32_fork, sys_fork, %rdi
372 PTREGSCALL stub32_clone, sys32_clone, %rdx
373 PTREGSCALL stub32_vfork, sys_vfork, %rdi
374 PTREGSCALL stub32_iopl, sys_iopl, %rsi
375 PTREGSCALL stub32_rt_sigsuspend, sys_rt_sigsuspend, %rdx
377 ENTRY(ia32_ptregs_common)
380 CFI_STARTPROC32 simple
382 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
383 CFI_REL_OFFSET rax,RAX-ARGOFFSET
384 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
385 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
386 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
387 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
388 CFI_REL_OFFSET rip,RIP-ARGOFFSET
389 /* CFI_REL_OFFSET cs,CS-ARGOFFSET*/
390 /* CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
391 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
392 /* CFI_REL_OFFSET ss,SS-ARGOFFSET*/
396 jmp ia32_sysret /* misbalances the return cache */
398 END(ia32_ptregs_common)
403 .quad sys_restart_syscall
408 .quad compat_sys_open /* 5 */
413 .quad sys_unlink /* 10 */
416 .quad compat_sys_time
418 .quad sys_chmod /* 15 */
420 .quad quiet_ni_syscall /* old break syscall holder */
423 .quad sys_getpid /* 20 */
424 .quad compat_sys_mount /* mount */
425 .quad sys_oldumount /* old_umount */
428 .quad compat_sys_stime /* stime */ /* 25 */
429 .quad sys32_ptrace /* ptrace */
431 .quad sys_fstat /* (old)fstat */
433 .quad compat_sys_utime /* 30 */
434 .quad quiet_ni_syscall /* old stty syscall holder */
435 .quad quiet_ni_syscall /* old gtty syscall holder */
438 .quad quiet_ni_syscall /* 35 */ /* old ftime syscall holder */
443 .quad sys_rmdir /* 40 */
446 .quad compat_sys_times
447 .quad quiet_ni_syscall /* old prof syscall holder */
448 .quad sys_brk /* 45 */
453 .quad sys_getegid16 /* 50 */
455 .quad sys_umount /* new_umount */
456 .quad quiet_ni_syscall /* old lock syscall holder */
457 .quad compat_sys_ioctl
458 .quad compat_sys_fcntl64 /* 55 */
459 .quad quiet_ni_syscall /* old mpx syscall holder */
461 .quad quiet_ni_syscall /* old ulimit syscall holder */
463 .quad sys_umask /* 60 */
468 .quad sys_getpgrp /* 65 */
470 .quad sys32_sigaction
473 .quad sys_setreuid16 /* 70 */
475 .quad stub32_sigsuspend
476 .quad compat_sys_sigpending
477 .quad sys_sethostname
478 .quad compat_sys_setrlimit /* 75 */
479 .quad compat_sys_old_getrlimit /* old_getrlimit */
480 .quad compat_sys_getrusage
481 .quad sys32_gettimeofday
482 .quad sys32_settimeofday
483 .quad sys_getgroups16 /* 80 */
484 .quad sys_setgroups16
485 .quad sys32_old_select
488 .quad sys_readlink /* 85 */
492 .quad compat_sys_old_readdir
493 .quad sys32_mmap /* 90 */
498 .quad sys_fchown16 /* 95 */
499 .quad sys_getpriority
500 .quad sys_setpriority
501 .quad quiet_ni_syscall /* old profil syscall holder */
502 .quad compat_sys_statfs
503 .quad compat_sys_fstatfs /* 100 */
505 .quad compat_sys_socketcall
507 .quad compat_sys_setitimer
508 .quad compat_sys_getitimer /* 105 */
509 .quad compat_sys_newstat
510 .quad compat_sys_newlstat
511 .quad compat_sys_newfstat
513 .quad stub32_iopl /* 110 */
515 .quad quiet_ni_syscall /* old "idle" system call */
516 .quad sys32_vm86_warning /* vm86old */
517 .quad compat_sys_wait4
518 .quad sys_swapoff /* 115 */
519 .quad compat_sys_sysinfo
522 .quad stub32_sigreturn
523 .quad stub32_clone /* 120 */
524 .quad sys_setdomainname
527 .quad compat_sys_adjtimex
528 .quad sys32_mprotect /* 125 */
529 .quad compat_sys_sigprocmask
530 .quad quiet_ni_syscall /* create_module */
531 .quad sys_init_module
532 .quad sys_delete_module
533 .quad quiet_ni_syscall /* 130 get_kernel_syms */
537 .quad quiet_ni_syscall /* bdflush */
538 .quad sys_sysfs /* 135 */
539 .quad sys_personality
540 .quad quiet_ni_syscall /* for afs_syscall */
543 .quad sys_llseek /* 140 */
544 .quad compat_sys_getdents
545 .quad compat_sys_select
548 .quad compat_sys_readv /* 145 */
549 .quad compat_sys_writev
552 .quad sys32_sysctl /* sysctl */
553 .quad sys_mlock /* 150 */
557 .quad sys_sched_setparam
558 .quad sys_sched_getparam /* 155 */
559 .quad sys_sched_setscheduler
560 .quad sys_sched_getscheduler
561 .quad sys_sched_yield
562 .quad sys_sched_get_priority_max
563 .quad sys_sched_get_priority_min /* 160 */
564 .quad sys32_sched_rr_get_interval
565 .quad compat_sys_nanosleep
567 .quad sys_setresuid16
568 .quad sys_getresuid16 /* 165 */
569 .quad sys32_vm86_warning /* vm86 */
570 .quad quiet_ni_syscall /* query_module */
572 .quad compat_sys_nfsservctl
573 .quad sys_setresgid16 /* 170 */
574 .quad sys_getresgid16
576 .quad stub32_rt_sigreturn
577 .quad sys32_rt_sigaction
578 .quad sys32_rt_sigprocmask /* 175 */
579 .quad sys32_rt_sigpending
580 .quad compat_sys_rt_sigtimedwait
581 .quad sys32_rt_sigqueueinfo
582 .quad stub32_rt_sigsuspend
583 .quad sys32_pread /* 180 */
589 .quad stub32_sigaltstack
591 .quad quiet_ni_syscall /* streams1 */
592 .quad quiet_ni_syscall /* streams2 */
593 .quad stub32_vfork /* 190 */
594 .quad compat_sys_getrlimit
596 .quad sys32_truncate64
597 .quad sys32_ftruncate64
598 .quad sys32_stat64 /* 195 */
603 .quad sys_getgid /* 200 */
608 .quad sys_getgroups /* 205 */
613 .quad sys_setresgid /* 210 */
618 .quad sys_setfsuid /* 215 */
623 .quad compat_sys_getdents64 /* 220 getdents64 */
624 .quad compat_sys_fcntl64
625 .quad quiet_ni_syscall /* tux */
626 .quad quiet_ni_syscall /* security */
628 .quad sys32_readahead /* 225 */
633 .quad sys_lgetxattr /* 230 */
638 .quad sys_removexattr /* 235 */
639 .quad sys_lremovexattr
640 .quad sys_fremovexattr
643 .quad compat_sys_futex /* 240 */
644 .quad compat_sys_sched_setaffinity
645 .quad compat_sys_sched_getaffinity
646 .quad sys_set_thread_area
647 .quad sys_get_thread_area
648 .quad compat_sys_io_setup /* 245 */
650 .quad compat_sys_io_getevents
651 .quad compat_sys_io_submit
653 .quad sys32_fadvise64 /* 250 */
654 .quad quiet_ni_syscall /* free_huge_pages */
656 .quad sys32_lookup_dcookie
657 .quad sys_epoll_create
658 .quad sys_epoll_ctl /* 255 */
660 .quad sys_remap_file_pages
661 .quad sys_set_tid_address
662 .quad compat_sys_timer_create
663 .quad compat_sys_timer_settime /* 260 */
664 .quad compat_sys_timer_gettime
665 .quad sys_timer_getoverrun
666 .quad sys_timer_delete
667 .quad compat_sys_clock_settime
668 .quad compat_sys_clock_gettime /* 265 */
669 .quad compat_sys_clock_getres
670 .quad compat_sys_clock_nanosleep
671 .quad compat_sys_statfs64
672 .quad compat_sys_fstatfs64
673 .quad sys_tgkill /* 270 */
674 .quad compat_sys_utimes
675 .quad sys32_fadvise64_64
676 .quad quiet_ni_syscall /* sys_vserver */
678 .quad compat_sys_get_mempolicy /* 275 */
679 .quad sys_set_mempolicy
680 .quad compat_sys_mq_open
682 .quad compat_sys_mq_timedsend
683 .quad compat_sys_mq_timedreceive /* 280 */
684 .quad compat_sys_mq_notify
685 .quad compat_sys_mq_getsetattr
686 .quad compat_sys_kexec_load /* reserved for kexec */
687 .quad compat_sys_waitid
688 .quad quiet_ni_syscall /* 285: sys_altroot */
690 .quad sys_request_key
693 .quad sys_ioprio_get /* 290 */
694 .quad sys_inotify_init
695 .quad sys_inotify_add_watch
696 .quad sys_inotify_rm_watch
697 .quad sys_migrate_pages
698 .quad compat_sys_openat /* 295 */
702 .quad compat_sys_futimesat
703 .quad sys32_fstatat /* 300 */
708 .quad sys_readlinkat /* 305 */
711 .quad compat_sys_pselect6
712 .quad compat_sys_ppoll
713 .quad sys_unshare /* 310 */
714 .quad compat_sys_set_robust_list
715 .quad compat_sys_get_robust_list
717 .quad sys32_sync_file_range
718 .quad sys_tee /* 315 */
719 .quad compat_sys_vmsplice
720 .quad compat_sys_move_pages
722 .quad sys_epoll_pwait
723 .quad compat_sys_utimensat /* 320 */
724 .quad compat_sys_signalfd
725 .quad sys_timerfd_create
727 .quad sys32_fallocate
728 .quad compat_sys_timerfd_settime /* 325 */
729 .quad compat_sys_timerfd_gettime