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/vsyscall32.h>
16 #include <asm/irqflags.h>
17 #include <linux/linkage.h>
19 #define IA32_NR_syscalls ((ia32_syscall_end - ia32_sys_call_table)/8)
21 .macro IA32_ARG_FIXUP noebp=0
29 movl %edx,%edx /* zero extension */
41 .macro LOAD_ARGS32 offset
42 movl \offset(%rsp),%r11d
43 movl \offset+8(%rsp),%r10d
44 movl \offset+16(%rsp),%r9d
45 movl \offset+24(%rsp),%r8d
46 movl \offset+40(%rsp),%ecx
47 movl \offset+48(%rsp),%edx
48 movl \offset+56(%rsp),%esi
49 movl \offset+64(%rsp),%edi
50 movl \offset+72(%rsp),%eax
53 .macro CFI_STARTPROC32 simple
66 * 32bit SYSENTER instruction entry.
69 * %eax System call number.
80 * This is purely a fast path. For anything complicated we use the int 0x80
81 * path below. Set up a complete hardware stack frame to share code
82 * with the int 0x80 path.
84 ENTRY(ia32_sysenter_target)
85 CFI_STARTPROC32 simple
90 movq %gs:pda_kernelstack, %rsp
91 addq $(PDA_STACKOFFSET),%rsp
93 * No need to follow this irqs on/off section: the syscall
94 * disabled irqs, here we enable it straight after entry:
97 movl %ebp,%ebp /* zero extension */
99 CFI_ADJUST_CFA_OFFSET 8
100 /*CFI_REL_OFFSET ss,0*/
102 CFI_ADJUST_CFA_OFFSET 8
105 CFI_ADJUST_CFA_OFFSET 8
106 /*CFI_REL_OFFSET rflags,0*/
107 movl $VSYSCALL32_SYSEXIT, %r10d
110 CFI_ADJUST_CFA_OFFSET 8
111 /*CFI_REL_OFFSET cs,0*/
114 CFI_ADJUST_CFA_OFFSET 8
117 CFI_ADJUST_CFA_OFFSET 8
120 /* no need to do an access_ok check here because rbp has been
121 32bit zero extended */
123 .section __ex_table,"a"
126 GET_THREAD_INFO(%r10)
127 orl $TS_COMPAT,threadinfo_status(%r10)
128 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
130 jnz sysenter_tracesys
132 cmpl $(IA32_NR_syscalls-1),%eax
135 call *ia32_sys_call_table(,%rax,8)
136 movq %rax,RAX-ARGOFFSET(%rsp)
137 GET_THREAD_INFO(%r10)
140 testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
141 jnz int_ret_from_sys_call
142 andl $~TS_COMPAT,threadinfo_status(%r10)
143 /* clear IF, that popfq doesn't enable interrupts early */
144 andl $~0x200,EFLAGS-R11(%rsp)
145 RESTORE_ARGS 1,24,1,1,1,1
147 CFI_ADJUST_CFA_OFFSET -8
148 /*CFI_RESTORE rflags*/
149 popq %rcx /* User %esp */
150 CFI_ADJUST_CFA_OFFSET -8
152 movl $VSYSCALL32_SYSEXIT,%edx /* User %eip */
156 sti /* sti only takes effect after the next instruction */
164 movq $-ENOSYS,RAX(%rsp) /* really needed? */
165 movq %rsp,%rdi /* &pt_regs -> arg1 */
166 call syscall_trace_enter
167 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
170 /* no need to do an access_ok check here because rbp has been
171 32bit zero extended */
173 .section __ex_table,"a"
178 ENDPROC(ia32_sysenter_target)
181 * 32bit SYSCALL instruction entry.
184 * %eax System call number.
190 * %ebp Arg2 [note: not saved in the stack frame, should not be touched]
196 * This is purely a fast path. For anything complicated we use the int 0x80
197 * path below. Set up a complete hardware stack frame to share code
198 * with the int 0x80 path.
200 ENTRY(ia32_cstar_target)
201 CFI_STARTPROC32 simple
203 CFI_DEF_CFA rsp,PDA_STACKOFFSET
205 /*CFI_REGISTER rflags,r11*/
209 movq %gs:pda_kernelstack,%rsp
211 * No need to follow this irqs on/off section: the syscall
212 * disabled irqs and here we enable it straight after entry:
216 movl %eax,%eax /* zero extension */
217 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
218 movq %rcx,RIP-ARGOFFSET(%rsp)
219 CFI_REL_OFFSET rip,RIP-ARGOFFSET
220 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */
222 movq $__USER32_CS,CS-ARGOFFSET(%rsp)
223 movq $__USER32_DS,SS-ARGOFFSET(%rsp)
224 movq %r11,EFLAGS-ARGOFFSET(%rsp)
225 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
226 movq %r8,RSP-ARGOFFSET(%rsp)
227 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
228 /* no need to do an access_ok check here because r8 has been
229 32bit zero extended */
230 /* hardware stack frame is complete now */
232 .section __ex_table,"a"
235 GET_THREAD_INFO(%r10)
236 orl $TS_COMPAT,threadinfo_status(%r10)
237 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
241 cmpl $IA32_NR_syscalls-1,%eax
244 call *ia32_sys_call_table(,%rax,8)
245 movq %rax,RAX-ARGOFFSET(%rsp)
246 GET_THREAD_INFO(%r10)
249 testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
250 jnz int_ret_from_sys_call
251 andl $~TS_COMPAT,threadinfo_status(%r10)
252 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
253 movl RIP-ARGOFFSET(%rsp),%ecx
255 movl EFLAGS-ARGOFFSET(%rsp),%r11d
256 /*CFI_REGISTER rflags,r11*/
258 movl RSP-ARGOFFSET(%rsp),%esp
267 movq $-ENOSYS,RAX(%rsp) /* really needed? */
268 movq %rsp,%rdi /* &pt_regs -> arg1 */
269 call syscall_trace_enter
270 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
272 movl RSP-ARGOFFSET(%rsp), %r8d
273 /* no need to do an access_ok check here because r8 has been
274 32bit zero extended */
276 .section __ex_table,"a"
280 END(ia32_cstar_target)
288 * Emulated IA32 system calls via int 0x80.
291 * %eax System call number.
297 * %ebp Arg6 [note: not saved in the stack frame, should not be touched]
300 * Uses the same stack frame as the x86-64 version.
301 * All registers except %eax must be saved (but ptrace may violate that)
302 * Arguments are zero extended. For system calls that want sign extension and
303 * take long arguments a wrapper is needed. Most calls can just be called
305 * Assumes it is only called from user space and entered with interrupts off.
309 CFI_STARTPROC32 simple
311 CFI_DEF_CFA rsp,SS+8-RIP
312 /*CFI_REL_OFFSET ss,SS-RIP*/
313 CFI_REL_OFFSET rsp,RSP-RIP
314 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
315 /*CFI_REL_OFFSET cs,CS-RIP*/
316 CFI_REL_OFFSET rip,RIP-RIP
319 * No need to follow this irqs on/off section: the syscall
320 * disabled irqs and here we enable it straight after entry:
325 CFI_ADJUST_CFA_OFFSET 8
327 /* note the registers are not zero extended to the sf.
328 this could be a problem. */
330 GET_THREAD_INFO(%r10)
331 orl $TS_COMPAT,threadinfo_status(%r10)
332 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
335 cmpl $(IA32_NR_syscalls-1),%eax
338 call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
340 movq %rax,RAX-ARGOFFSET(%rsp)
341 jmp int_ret_from_sys_call
346 movq $-ENOSYS,RAX(%rsp) /* really needed? */
347 movq %rsp,%rdi /* &pt_regs -> arg1 */
348 call syscall_trace_enter
349 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
355 movq $0,ORIG_RAX-ARGOFFSET(%rsp)
356 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
357 jmp int_ret_from_sys_call
364 .macro PTREGSCALL label, func, arg
367 leaq \func(%rip),%rax
368 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
369 jmp ia32_ptregs_common
374 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
375 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
376 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
377 PTREGSCALL stub32_sigsuspend, sys32_sigsuspend, %rcx
378 PTREGSCALL stub32_execve, sys32_execve, %rcx
379 PTREGSCALL stub32_fork, sys_fork, %rdi
380 PTREGSCALL stub32_clone, sys32_clone, %rdx
381 PTREGSCALL stub32_vfork, sys_vfork, %rdi
382 PTREGSCALL stub32_iopl, sys_iopl, %rsi
383 PTREGSCALL stub32_rt_sigsuspend, sys_rt_sigsuspend, %rdx
385 ENTRY(ia32_ptregs_common)
388 CFI_STARTPROC32 simple
390 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
391 CFI_REL_OFFSET rax,RAX-ARGOFFSET
392 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
393 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
394 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
395 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
396 CFI_REL_OFFSET rip,RIP-ARGOFFSET
397 /* CFI_REL_OFFSET cs,CS-ARGOFFSET*/
398 /* CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
399 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
400 /* CFI_REL_OFFSET ss,SS-ARGOFFSET*/
404 jmp ia32_sysret /* misbalances the return cache */
406 END(ia32_ptregs_common)
411 .quad sys_restart_syscall
416 .quad compat_sys_open /* 5 */
421 .quad sys_unlink /* 10 */
424 .quad compat_sys_time
426 .quad sys_chmod /* 15 */
428 .quad quiet_ni_syscall /* old break syscall holder */
431 .quad sys_getpid /* 20 */
432 .quad compat_sys_mount /* mount */
433 .quad sys_oldumount /* old_umount */
436 .quad compat_sys_stime /* stime */ /* 25 */
437 .quad sys32_ptrace /* ptrace */
439 .quad sys_fstat /* (old)fstat */
441 .quad compat_sys_utime /* 30 */
442 .quad quiet_ni_syscall /* old stty syscall holder */
443 .quad quiet_ni_syscall /* old gtty syscall holder */
446 .quad quiet_ni_syscall /* 35 */ /* old ftime syscall holder */
451 .quad sys_rmdir /* 40 */
454 .quad compat_sys_times
455 .quad quiet_ni_syscall /* old prof syscall holder */
456 .quad sys_brk /* 45 */
461 .quad sys_getegid16 /* 50 */
463 .quad sys_umount /* new_umount */
464 .quad quiet_ni_syscall /* old lock syscall holder */
465 .quad compat_sys_ioctl
466 .quad compat_sys_fcntl64 /* 55 */
467 .quad quiet_ni_syscall /* old mpx syscall holder */
469 .quad quiet_ni_syscall /* old ulimit syscall holder */
471 .quad sys_umask /* 60 */
476 .quad sys_getpgrp /* 65 */
478 .quad sys32_sigaction
481 .quad sys_setreuid16 /* 70 */
483 .quad stub32_sigsuspend
484 .quad compat_sys_sigpending
485 .quad sys_sethostname
486 .quad compat_sys_setrlimit /* 75 */
487 .quad compat_sys_old_getrlimit /* old_getrlimit */
488 .quad compat_sys_getrusage
489 .quad sys32_gettimeofday
490 .quad sys32_settimeofday
491 .quad sys_getgroups16 /* 80 */
492 .quad sys_setgroups16
493 .quad sys32_old_select
496 .quad sys_readlink /* 85 */
500 .quad compat_sys_old_readdir
501 .quad sys32_mmap /* 90 */
506 .quad sys_fchown16 /* 95 */
507 .quad sys_getpriority
508 .quad sys_setpriority
509 .quad quiet_ni_syscall /* old profil syscall holder */
510 .quad compat_sys_statfs
511 .quad compat_sys_fstatfs /* 100 */
513 .quad compat_sys_socketcall
515 .quad compat_sys_setitimer
516 .quad compat_sys_getitimer /* 105 */
517 .quad compat_sys_newstat
518 .quad compat_sys_newlstat
519 .quad compat_sys_newfstat
521 .quad stub32_iopl /* 110 */
523 .quad quiet_ni_syscall /* old "idle" system call */
524 .quad sys32_vm86_warning /* vm86old */
525 .quad compat_sys_wait4
526 .quad sys_swapoff /* 115 */
527 .quad compat_sys_sysinfo
530 .quad stub32_sigreturn
531 .quad stub32_clone /* 120 */
532 .quad sys_setdomainname
535 .quad compat_sys_adjtimex
536 .quad sys32_mprotect /* 125 */
537 .quad compat_sys_sigprocmask
538 .quad quiet_ni_syscall /* create_module */
539 .quad sys_init_module
540 .quad sys_delete_module
541 .quad quiet_ni_syscall /* 130 get_kernel_syms */
545 .quad quiet_ni_syscall /* bdflush */
546 .quad sys_sysfs /* 135 */
547 .quad sys_personality
548 .quad quiet_ni_syscall /* for afs_syscall */
551 .quad sys_llseek /* 140 */
552 .quad compat_sys_getdents
553 .quad compat_sys_select
556 .quad compat_sys_readv /* 145 */
557 .quad compat_sys_writev
560 .quad sys32_sysctl /* sysctl */
561 .quad sys_mlock /* 150 */
565 .quad sys_sched_setparam
566 .quad sys_sched_getparam /* 155 */
567 .quad sys_sched_setscheduler
568 .quad sys_sched_getscheduler
569 .quad sys_sched_yield
570 .quad sys_sched_get_priority_max
571 .quad sys_sched_get_priority_min /* 160 */
572 .quad sys32_sched_rr_get_interval
573 .quad compat_sys_nanosleep
575 .quad sys_setresuid16
576 .quad sys_getresuid16 /* 165 */
577 .quad sys32_vm86_warning /* vm86 */
578 .quad quiet_ni_syscall /* query_module */
580 .quad compat_sys_nfsservctl
581 .quad sys_setresgid16 /* 170 */
582 .quad sys_getresgid16
584 .quad stub32_rt_sigreturn
585 .quad sys32_rt_sigaction
586 .quad sys32_rt_sigprocmask /* 175 */
587 .quad sys32_rt_sigpending
588 .quad compat_sys_rt_sigtimedwait
589 .quad sys32_rt_sigqueueinfo
590 .quad stub32_rt_sigsuspend
591 .quad sys32_pread /* 180 */
597 .quad stub32_sigaltstack
599 .quad quiet_ni_syscall /* streams1 */
600 .quad quiet_ni_syscall /* streams2 */
601 .quad stub32_vfork /* 190 */
602 .quad compat_sys_getrlimit
604 .quad sys32_truncate64
605 .quad sys32_ftruncate64
606 .quad sys32_stat64 /* 195 */
611 .quad sys_getgid /* 200 */
616 .quad sys_getgroups /* 205 */
621 .quad sys_setresgid /* 210 */
626 .quad sys_setfsuid /* 215 */
631 .quad compat_sys_getdents64 /* 220 getdents64 */
632 .quad compat_sys_fcntl64
633 .quad quiet_ni_syscall /* tux */
634 .quad quiet_ni_syscall /* security */
636 .quad sys32_readahead /* 225 */
641 .quad sys_lgetxattr /* 230 */
646 .quad sys_removexattr /* 235 */
647 .quad sys_lremovexattr
648 .quad sys_fremovexattr
651 .quad compat_sys_futex /* 240 */
652 .quad compat_sys_sched_setaffinity
653 .quad compat_sys_sched_getaffinity
654 .quad sys32_set_thread_area
655 .quad sys32_get_thread_area
656 .quad compat_sys_io_setup /* 245 */
658 .quad compat_sys_io_getevents
659 .quad compat_sys_io_submit
661 .quad sys32_fadvise64 /* 250 */
662 .quad quiet_ni_syscall /* free_huge_pages */
664 .quad sys32_lookup_dcookie
665 .quad sys_epoll_create
666 .quad sys_epoll_ctl /* 255 */
668 .quad sys_remap_file_pages
669 .quad sys_set_tid_address
670 .quad compat_sys_timer_create
671 .quad compat_sys_timer_settime /* 260 */
672 .quad compat_sys_timer_gettime
673 .quad sys_timer_getoverrun
674 .quad sys_timer_delete
675 .quad compat_sys_clock_settime
676 .quad compat_sys_clock_gettime /* 265 */
677 .quad compat_sys_clock_getres
678 .quad compat_sys_clock_nanosleep
679 .quad compat_sys_statfs64
680 .quad compat_sys_fstatfs64
681 .quad sys_tgkill /* 270 */
682 .quad compat_sys_utimes
683 .quad sys32_fadvise64_64
684 .quad quiet_ni_syscall /* sys_vserver */
686 .quad compat_sys_get_mempolicy /* 275 */
687 .quad sys_set_mempolicy
688 .quad compat_sys_mq_open
690 .quad compat_sys_mq_timedsend
691 .quad compat_sys_mq_timedreceive /* 280 */
692 .quad compat_sys_mq_notify
693 .quad compat_sys_mq_getsetattr
694 .quad compat_sys_kexec_load /* reserved for kexec */
695 .quad compat_sys_waitid
696 .quad quiet_ni_syscall /* 285: sys_altroot */
698 .quad sys_request_key
701 .quad sys_ioprio_get /* 290 */
702 .quad sys_inotify_init
703 .quad sys_inotify_add_watch
704 .quad sys_inotify_rm_watch
705 .quad sys_migrate_pages
706 .quad compat_sys_openat /* 295 */
710 .quad compat_sys_futimesat
711 .quad sys32_fstatat /* 300 */
716 .quad sys_readlinkat /* 305 */
719 .quad compat_sys_pselect6
720 .quad compat_sys_ppoll
721 .quad sys_unshare /* 310 */
722 .quad compat_sys_set_robust_list
723 .quad compat_sys_get_robust_list
725 .quad sys32_sync_file_range
726 .quad sys_tee /* 315 */
727 .quad compat_sys_vmsplice
728 .quad compat_sys_move_pages
730 .quad sys_epoll_pwait
731 .quad compat_sys_utimensat /* 320 */
732 .quad compat_sys_signalfd
733 .quad compat_sys_timerfd
735 .quad sys32_fallocate