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 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
19 #include <linux/elf-em.h>
20 #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
21 #define __AUDIT_ARCH_LE 0x40000000
23 #ifndef CONFIG_AUDITSYSCALL
24 #define sysexit_audit int_ret_from_sys_call
25 #define sysretl_audit int_ret_from_sys_call
28 #define IA32_NR_syscalls ((ia32_syscall_end - ia32_sys_call_table)/8)
30 .macro IA32_ARG_FIXUP noebp=0
38 movl %edx,%edx /* zero extension */
51 * Reload arg registers from stack in case ptrace changed them.
52 * We don't reload %eax because syscall_trace_enter() returned
53 * the value it wants us to use in the table lookup.
55 .macro LOAD_ARGS32 offset
56 movl \offset(%rsp),%r11d
57 movl \offset+8(%rsp),%r10d
58 movl \offset+16(%rsp),%r9d
59 movl \offset+24(%rsp),%r8d
60 movl \offset+40(%rsp),%ecx
61 movl \offset+48(%rsp),%edx
62 movl \offset+56(%rsp),%esi
63 movl \offset+64(%rsp),%edi
66 .macro CFI_STARTPROC32 simple
78 #ifdef CONFIG_PARAVIRT
79 ENTRY(native_usergs_sysret32)
82 ENDPROC(native_usergs_sysret32)
84 ENTRY(native_irq_enable_sysexit)
88 ENDPROC(native_irq_enable_sysexit)
92 * 32bit SYSENTER instruction entry.
95 * %eax System call number.
106 * This is purely a fast path. For anything complicated we use the int 0x80
107 * path below. Set up a complete hardware stack frame to share code
108 * with the int 0x80 path.
110 ENTRY(ia32_sysenter_target)
111 CFI_STARTPROC32 simple
116 movq %gs:pda_kernelstack, %rsp
117 addq $(PDA_STACKOFFSET),%rsp
119 * No need to follow this irqs on/off section: the syscall
120 * disabled irqs, here we enable it straight after entry:
122 ENABLE_INTERRUPTS(CLBR_NONE)
123 movl %ebp,%ebp /* zero extension */
125 CFI_ADJUST_CFA_OFFSET 8
126 /*CFI_REL_OFFSET ss,0*/
128 CFI_ADJUST_CFA_OFFSET 8
131 CFI_ADJUST_CFA_OFFSET 8
132 /*CFI_REL_OFFSET rflags,0*/
133 movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
136 CFI_ADJUST_CFA_OFFSET 8
137 /*CFI_REL_OFFSET cs,0*/
140 CFI_ADJUST_CFA_OFFSET 8
143 CFI_ADJUST_CFA_OFFSET 8
146 /* no need to do an access_ok check here because rbp has been
147 32bit zero extended */
149 .section __ex_table,"a"
152 GET_THREAD_INFO(%r10)
153 orl $TS_COMPAT,TI_status(%r10)
154 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
156 jnz sysenter_tracesys
157 cmpl $(IA32_NR_syscalls-1),%eax
162 call *ia32_sys_call_table(,%rax,8)
163 movq %rax,RAX-ARGOFFSET(%rsp)
164 GET_THREAD_INFO(%r10)
165 DISABLE_INTERRUPTS(CLBR_NONE)
167 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
169 sysexit_from_sys_call:
170 andl $~TS_COMPAT,TI_status(%r10)
171 /* clear IF, that popfq doesn't enable interrupts early */
172 andl $~0x200,EFLAGS-R11(%rsp)
173 movl RIP-R11(%rsp),%edx /* User %eip */
175 RESTORE_ARGS 1,24,1,1,1,1
177 CFI_ADJUST_CFA_OFFSET -8
178 /*CFI_RESTORE rflags*/
179 popq %rcx /* User %esp */
180 CFI_ADJUST_CFA_OFFSET -8
183 ENABLE_INTERRUPTS_SYSEXIT32
185 #ifdef CONFIG_AUDITSYSCALL
186 .macro auditsys_entry_common
187 movl %esi,%r9d /* 6th arg: 4th syscall arg */
188 movl %edx,%r8d /* 5th arg: 3rd syscall arg */
189 /* (already in %ecx) 4th arg: 2nd syscall arg */
190 movl %ebx,%edx /* 3rd arg: 1st syscall arg */
191 movl %eax,%esi /* 2nd arg: syscall number */
192 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
193 call audit_syscall_entry
194 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
195 cmpl $(IA32_NR_syscalls-1),%eax
197 movl %ebx,%edi /* reload 1st syscall arg */
198 movl RCX-ARGOFFSET(%rsp),%esi /* reload 2nd syscall arg */
199 movl RDX-ARGOFFSET(%rsp),%edx /* reload 3rd syscall arg */
200 movl RSI-ARGOFFSET(%rsp),%ecx /* reload 4th syscall arg */
201 movl RDI-ARGOFFSET(%rsp),%r8d /* reload 5th syscall arg */
204 .macro auditsys_exit exit
205 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
206 jnz int_ret_from_sys_call
209 movl %eax,%esi /* second arg, syscall return value */
210 cmpl $0,%eax /* is it < 0? */
211 setl %al /* 1 if so, 0 if not */
212 movzbl %al,%edi /* zero-extend that into %edi */
213 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
214 call audit_syscall_exit
215 GET_THREAD_INFO(%r10)
216 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
217 movl RBP-ARGOFFSET(%rsp),%ebp /* reload user register value */
218 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
221 testl %edi,TI_flags(%r10)
228 auditsys_entry_common
229 movl %ebp,%r9d /* reload 6th syscall arg */
230 jmp sysenter_dispatch
233 auditsys_exit sysexit_from_sys_call
238 #ifdef CONFIG_AUDITSYSCALL
239 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
245 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
246 movq %rsp,%rdi /* &pt_regs -> arg1 */
247 call syscall_trace_enter
248 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
251 cmpl $(IA32_NR_syscalls-1),%eax
252 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
255 ENDPROC(ia32_sysenter_target)
258 * 32bit SYSCALL instruction entry.
261 * %eax System call number.
267 * %ebp Arg2 [note: not saved in the stack frame, should not be touched]
273 * This is purely a fast path. For anything complicated we use the int 0x80
274 * path below. Set up a complete hardware stack frame to share code
275 * with the int 0x80 path.
277 ENTRY(ia32_cstar_target)
278 CFI_STARTPROC32 simple
280 CFI_DEF_CFA rsp,PDA_STACKOFFSET
282 /*CFI_REGISTER rflags,r11*/
286 movq %gs:pda_kernelstack,%rsp
288 * No need to follow this irqs on/off section: the syscall
289 * disabled irqs and here we enable it straight after entry:
291 ENABLE_INTERRUPTS(CLBR_NONE)
293 movl %eax,%eax /* zero extension */
294 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
295 movq %rcx,RIP-ARGOFFSET(%rsp)
296 CFI_REL_OFFSET rip,RIP-ARGOFFSET
297 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */
299 movq $__USER32_CS,CS-ARGOFFSET(%rsp)
300 movq $__USER32_DS,SS-ARGOFFSET(%rsp)
301 movq %r11,EFLAGS-ARGOFFSET(%rsp)
302 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
303 movq %r8,RSP-ARGOFFSET(%rsp)
304 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
305 /* no need to do an access_ok check here because r8 has been
306 32bit zero extended */
307 /* hardware stack frame is complete now */
309 .section __ex_table,"a"
312 GET_THREAD_INFO(%r10)
313 orl $TS_COMPAT,TI_status(%r10)
314 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
318 cmpl $IA32_NR_syscalls-1,%eax
322 call *ia32_sys_call_table(,%rax,8)
323 movq %rax,RAX-ARGOFFSET(%rsp)
324 GET_THREAD_INFO(%r10)
325 DISABLE_INTERRUPTS(CLBR_NONE)
327 testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
329 sysretl_from_sys_call:
330 andl $~TS_COMPAT,TI_status(%r10)
331 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
332 movl RIP-ARGOFFSET(%rsp),%ecx
334 movl EFLAGS-ARGOFFSET(%rsp),%r11d
335 /*CFI_REGISTER rflags,r11*/
337 movl RSP-ARGOFFSET(%rsp),%esp
341 #ifdef CONFIG_AUDITSYSCALL
344 movl %r9d,R9-ARGOFFSET(%rsp) /* register to be clobbered by call */
345 auditsys_entry_common
346 movl R9-ARGOFFSET(%rsp),%r9d /* reload 6th syscall arg */
350 auditsys_exit sysretl_from_sys_call
354 #ifdef CONFIG_AUDITSYSCALL
355 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
362 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
363 movq %rsp,%rdi /* &pt_regs -> arg1 */
364 call syscall_trace_enter
365 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
368 movl RSP-ARGOFFSET(%rsp), %r8d
369 cmpl $(IA32_NR_syscalls-1),%eax
370 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
372 END(ia32_cstar_target)
380 * Emulated IA32 system calls via int 0x80.
383 * %eax System call number.
389 * %ebp Arg6 [note: not saved in the stack frame, should not be touched]
392 * Uses the same stack frame as the x86-64 version.
393 * All registers except %eax must be saved (but ptrace may violate that)
394 * Arguments are zero extended. For system calls that want sign extension and
395 * take long arguments a wrapper is needed. Most calls can just be called
397 * Assumes it is only called from user space and entered with interrupts off.
401 CFI_STARTPROC32 simple
403 CFI_DEF_CFA rsp,SS+8-RIP
404 /*CFI_REL_OFFSET ss,SS-RIP*/
405 CFI_REL_OFFSET rsp,RSP-RIP
406 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
407 /*CFI_REL_OFFSET cs,CS-RIP*/
408 CFI_REL_OFFSET rip,RIP-RIP
409 PARAVIRT_ADJUST_EXCEPTION_FRAME
412 * No need to follow this irqs on/off section: the syscall
413 * disabled irqs and here we enable it straight after entry:
415 ENABLE_INTERRUPTS(CLBR_NONE)
418 CFI_ADJUST_CFA_OFFSET 8
420 /* note the registers are not zero extended to the sf.
421 this could be a problem. */
423 GET_THREAD_INFO(%r10)
424 orl $TS_COMPAT,TI_status(%r10)
425 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
428 cmpl $(IA32_NR_syscalls-1),%eax
429 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
431 call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
433 movq %rax,RAX-ARGOFFSET(%rsp)
434 jmp int_ret_from_sys_call
439 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
440 movq %rsp,%rdi /* &pt_regs -> arg1 */
441 call syscall_trace_enter
442 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
448 movq $0,ORIG_RAX-ARGOFFSET(%rsp)
449 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
450 jmp int_ret_from_sys_call
457 .macro PTREGSCALL label, func, arg
460 leaq \func(%rip),%rax
461 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
462 jmp ia32_ptregs_common
467 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
468 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
469 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
470 PTREGSCALL stub32_execve, sys32_execve, %rcx
471 PTREGSCALL stub32_fork, sys_fork, %rdi
472 PTREGSCALL stub32_clone, sys32_clone, %rdx
473 PTREGSCALL stub32_vfork, sys_vfork, %rdi
474 PTREGSCALL stub32_iopl, sys_iopl, %rsi
476 ENTRY(ia32_ptregs_common)
479 CFI_STARTPROC32 simple
481 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
482 CFI_REL_OFFSET rax,RAX-ARGOFFSET
483 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
484 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
485 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
486 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
487 CFI_REL_OFFSET rip,RIP-ARGOFFSET
488 /* CFI_REL_OFFSET cs,CS-ARGOFFSET*/
489 /* CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
490 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
491 /* CFI_REL_OFFSET ss,SS-ARGOFFSET*/
495 jmp ia32_sysret /* misbalances the return cache */
497 END(ia32_ptregs_common)
502 .quad sys_restart_syscall
507 .quad compat_sys_open /* 5 */
512 .quad sys_unlink /* 10 */
515 .quad compat_sys_time
517 .quad sys_chmod /* 15 */
519 .quad quiet_ni_syscall /* old break syscall holder */
522 .quad sys_getpid /* 20 */
523 .quad compat_sys_mount /* mount */
524 .quad sys_oldumount /* old_umount */
527 .quad compat_sys_stime /* stime */ /* 25 */
528 .quad compat_sys_ptrace /* ptrace */
530 .quad sys_fstat /* (old)fstat */
532 .quad compat_sys_utime /* 30 */
533 .quad quiet_ni_syscall /* old stty syscall holder */
534 .quad quiet_ni_syscall /* old gtty syscall holder */
537 .quad quiet_ni_syscall /* 35 */ /* old ftime syscall holder */
542 .quad sys_rmdir /* 40 */
545 .quad compat_sys_times
546 .quad quiet_ni_syscall /* old prof syscall holder */
547 .quad sys_brk /* 45 */
552 .quad sys_getegid16 /* 50 */
554 .quad sys_umount /* new_umount */
555 .quad quiet_ni_syscall /* old lock syscall holder */
556 .quad compat_sys_ioctl
557 .quad compat_sys_fcntl64 /* 55 */
558 .quad quiet_ni_syscall /* old mpx syscall holder */
560 .quad quiet_ni_syscall /* old ulimit syscall holder */
562 .quad sys_umask /* 60 */
567 .quad sys_getpgrp /* 65 */
569 .quad sys32_sigaction
572 .quad sys_setreuid16 /* 70 */
574 .quad sys32_sigsuspend
575 .quad compat_sys_sigpending
576 .quad sys_sethostname
577 .quad compat_sys_setrlimit /* 75 */
578 .quad compat_sys_old_getrlimit /* old_getrlimit */
579 .quad compat_sys_getrusage
580 .quad sys32_gettimeofday
581 .quad sys32_settimeofday
582 .quad sys_getgroups16 /* 80 */
583 .quad sys_setgroups16
584 .quad sys32_old_select
587 .quad sys_readlink /* 85 */
591 .quad compat_sys_old_readdir
592 .quad sys32_mmap /* 90 */
597 .quad sys_fchown16 /* 95 */
598 .quad sys_getpriority
599 .quad sys_setpriority
600 .quad quiet_ni_syscall /* old profil syscall holder */
601 .quad compat_sys_statfs
602 .quad compat_sys_fstatfs /* 100 */
604 .quad compat_sys_socketcall
606 .quad compat_sys_setitimer
607 .quad compat_sys_getitimer /* 105 */
608 .quad compat_sys_newstat
609 .quad compat_sys_newlstat
610 .quad compat_sys_newfstat
612 .quad stub32_iopl /* 110 */
614 .quad quiet_ni_syscall /* old "idle" system call */
615 .quad sys32_vm86_warning /* vm86old */
616 .quad compat_sys_wait4
617 .quad sys_swapoff /* 115 */
618 .quad compat_sys_sysinfo
621 .quad stub32_sigreturn
622 .quad stub32_clone /* 120 */
623 .quad sys_setdomainname
626 .quad compat_sys_adjtimex
627 .quad sys32_mprotect /* 125 */
628 .quad compat_sys_sigprocmask
629 .quad quiet_ni_syscall /* create_module */
630 .quad sys_init_module
631 .quad sys_delete_module
632 .quad quiet_ni_syscall /* 130 get_kernel_syms */
636 .quad quiet_ni_syscall /* bdflush */
637 .quad sys_sysfs /* 135 */
638 .quad sys_personality
639 .quad quiet_ni_syscall /* for afs_syscall */
642 .quad sys_llseek /* 140 */
643 .quad compat_sys_getdents
644 .quad compat_sys_select
647 .quad compat_sys_readv /* 145 */
648 .quad compat_sys_writev
651 .quad sys32_sysctl /* sysctl */
652 .quad sys_mlock /* 150 */
656 .quad sys_sched_setparam
657 .quad sys_sched_getparam /* 155 */
658 .quad sys_sched_setscheduler
659 .quad sys_sched_getscheduler
660 .quad sys_sched_yield
661 .quad sys_sched_get_priority_max
662 .quad sys_sched_get_priority_min /* 160 */
663 .quad sys32_sched_rr_get_interval
664 .quad compat_sys_nanosleep
666 .quad sys_setresuid16
667 .quad sys_getresuid16 /* 165 */
668 .quad sys32_vm86_warning /* vm86 */
669 .quad quiet_ni_syscall /* query_module */
671 .quad compat_sys_nfsservctl
672 .quad sys_setresgid16 /* 170 */
673 .quad sys_getresgid16
675 .quad stub32_rt_sigreturn
676 .quad sys32_rt_sigaction
677 .quad sys32_rt_sigprocmask /* 175 */
678 .quad sys32_rt_sigpending
679 .quad compat_sys_rt_sigtimedwait
680 .quad sys32_rt_sigqueueinfo
681 .quad sys_rt_sigsuspend
682 .quad sys32_pread /* 180 */
688 .quad stub32_sigaltstack
690 .quad quiet_ni_syscall /* streams1 */
691 .quad quiet_ni_syscall /* streams2 */
692 .quad stub32_vfork /* 190 */
693 .quad compat_sys_getrlimit
695 .quad sys32_truncate64
696 .quad sys32_ftruncate64
697 .quad sys32_stat64 /* 195 */
702 .quad sys_getgid /* 200 */
707 .quad sys_getgroups /* 205 */
712 .quad sys_setresgid /* 210 */
717 .quad sys_setfsuid /* 215 */
722 .quad compat_sys_getdents64 /* 220 getdents64 */
723 .quad compat_sys_fcntl64
724 .quad quiet_ni_syscall /* tux */
725 .quad quiet_ni_syscall /* security */
727 .quad sys32_readahead /* 225 */
732 .quad sys_lgetxattr /* 230 */
737 .quad sys_removexattr /* 235 */
738 .quad sys_lremovexattr
739 .quad sys_fremovexattr
742 .quad compat_sys_futex /* 240 */
743 .quad compat_sys_sched_setaffinity
744 .quad compat_sys_sched_getaffinity
745 .quad sys_set_thread_area
746 .quad sys_get_thread_area
747 .quad compat_sys_io_setup /* 245 */
749 .quad compat_sys_io_getevents
750 .quad compat_sys_io_submit
752 .quad sys32_fadvise64 /* 250 */
753 .quad quiet_ni_syscall /* free_huge_pages */
755 .quad sys32_lookup_dcookie
756 .quad sys_epoll_create
757 .quad sys_epoll_ctl /* 255 */
759 .quad sys_remap_file_pages
760 .quad sys_set_tid_address
761 .quad compat_sys_timer_create
762 .quad compat_sys_timer_settime /* 260 */
763 .quad compat_sys_timer_gettime
764 .quad sys_timer_getoverrun
765 .quad sys_timer_delete
766 .quad compat_sys_clock_settime
767 .quad compat_sys_clock_gettime /* 265 */
768 .quad compat_sys_clock_getres
769 .quad compat_sys_clock_nanosleep
770 .quad compat_sys_statfs64
771 .quad compat_sys_fstatfs64
772 .quad sys_tgkill /* 270 */
773 .quad compat_sys_utimes
774 .quad sys32_fadvise64_64
775 .quad quiet_ni_syscall /* sys_vserver */
777 .quad compat_sys_get_mempolicy /* 275 */
778 .quad sys_set_mempolicy
779 .quad compat_sys_mq_open
781 .quad compat_sys_mq_timedsend
782 .quad compat_sys_mq_timedreceive /* 280 */
783 .quad compat_sys_mq_notify
784 .quad compat_sys_mq_getsetattr
785 .quad compat_sys_kexec_load /* reserved for kexec */
786 .quad compat_sys_waitid
787 .quad quiet_ni_syscall /* 285: sys_altroot */
789 .quad sys_request_key
792 .quad sys_ioprio_get /* 290 */
793 .quad sys_inotify_init
794 .quad sys_inotify_add_watch
795 .quad sys_inotify_rm_watch
796 .quad sys_migrate_pages
797 .quad compat_sys_openat /* 295 */
801 .quad compat_sys_futimesat
802 .quad sys32_fstatat /* 300 */
807 .quad sys_readlinkat /* 305 */
810 .quad compat_sys_pselect6
811 .quad compat_sys_ppoll
812 .quad sys_unshare /* 310 */
813 .quad compat_sys_set_robust_list
814 .quad compat_sys_get_robust_list
816 .quad sys32_sync_file_range
817 .quad sys_tee /* 315 */
818 .quad compat_sys_vmsplice
819 .quad compat_sys_move_pages
821 .quad sys_epoll_pwait
822 .quad compat_sys_utimensat /* 320 */
823 .quad compat_sys_signalfd
824 .quad sys_timerfd_create
826 .quad sys32_fallocate
827 .quad compat_sys_timerfd_settime /* 325 */
828 .quad compat_sys_timerfd_gettime
829 .quad compat_sys_signalfd4
831 .quad sys_epoll_create2
832 .quad sys_dup3 /* 330 */