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 */
166 movq $-ENOSYS,RAX(%rsp) /* really needed? */
167 movq %rsp,%rdi /* &pt_regs -> arg1 */
168 call syscall_trace_enter
169 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
174 ENDPROC(ia32_sysenter_target)
177 * 32bit SYSCALL instruction entry.
180 * %eax System call number.
186 * %ebp Arg2 [note: not saved in the stack frame, should not be touched]
192 * This is purely a fast path. For anything complicated we use the int 0x80
193 * path below. Set up a complete hardware stack frame to share code
194 * with the int 0x80 path.
196 ENTRY(ia32_cstar_target)
197 CFI_STARTPROC32 simple
199 CFI_DEF_CFA rsp,PDA_STACKOFFSET
201 /*CFI_REGISTER rflags,r11*/
205 movq %gs:pda_kernelstack,%rsp
207 * No need to follow this irqs on/off section: the syscall
208 * disabled irqs and here we enable it straight after entry:
212 movl %eax,%eax /* zero extension */
213 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
214 movq %rcx,RIP-ARGOFFSET(%rsp)
215 CFI_REL_OFFSET rip,RIP-ARGOFFSET
216 movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */
218 movq $__USER32_CS,CS-ARGOFFSET(%rsp)
219 movq $__USER32_DS,SS-ARGOFFSET(%rsp)
220 movq %r11,EFLAGS-ARGOFFSET(%rsp)
221 /*CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
222 movq %r8,RSP-ARGOFFSET(%rsp)
223 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
224 /* no need to do an access_ok check here because r8 has been
225 32bit zero extended */
226 /* hardware stack frame is complete now */
228 .section __ex_table,"a"
231 GET_THREAD_INFO(%r10)
232 orl $TS_COMPAT,threadinfo_status(%r10)
233 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
237 cmpl $IA32_NR_syscalls-1,%eax
240 call *ia32_sys_call_table(,%rax,8)
241 movq %rax,RAX-ARGOFFSET(%rsp)
242 GET_THREAD_INFO(%r10)
245 testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10)
246 jnz int_ret_from_sys_call
247 andl $~TS_COMPAT,threadinfo_status(%r10)
248 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
249 movl RIP-ARGOFFSET(%rsp),%ecx
251 movl EFLAGS-ARGOFFSET(%rsp),%r11d
252 /*CFI_REGISTER rflags,r11*/
254 movl RSP-ARGOFFSET(%rsp),%esp
265 movq $-ENOSYS,RAX(%rsp) /* really needed? */
266 movq %rsp,%rdi /* &pt_regs -> arg1 */
267 call syscall_trace_enter
268 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
271 movl RSP-ARGOFFSET(%rsp), %r8d
273 END(ia32_cstar_target)
281 * Emulated IA32 system calls via int 0x80.
284 * %eax System call number.
290 * %ebp Arg6 [note: not saved in the stack frame, should not be touched]
293 * Uses the same stack frame as the x86-64 version.
294 * All registers except %eax must be saved (but ptrace may violate that)
295 * Arguments are zero extended. For system calls that want sign extension and
296 * take long arguments a wrapper is needed. Most calls can just be called
298 * Assumes it is only called from user space and entered with interrupts off.
302 CFI_STARTPROC32 simple
304 CFI_DEF_CFA rsp,SS+8-RIP
305 /*CFI_REL_OFFSET ss,SS-RIP*/
306 CFI_REL_OFFSET rsp,RSP-RIP
307 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
308 /*CFI_REL_OFFSET cs,CS-RIP*/
309 CFI_REL_OFFSET rip,RIP-RIP
312 * No need to follow this irqs on/off section: the syscall
313 * disabled irqs and here we enable it straight after entry:
318 CFI_ADJUST_CFA_OFFSET 8
320 /* note the registers are not zero extended to the sf.
321 this could be a problem. */
323 GET_THREAD_INFO(%r10)
324 orl $TS_COMPAT,threadinfo_status(%r10)
325 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%r10)
328 cmpl $(IA32_NR_syscalls-1),%eax
331 call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
333 movq %rax,RAX-ARGOFFSET(%rsp)
334 jmp int_ret_from_sys_call
339 movq $-ENOSYS,RAX(%rsp) /* really needed? */
340 movq %rsp,%rdi /* &pt_regs -> arg1 */
341 call syscall_trace_enter
342 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
348 movq $0,ORIG_RAX-ARGOFFSET(%rsp)
349 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
350 jmp int_ret_from_sys_call
357 .macro PTREGSCALL label, func, arg
360 leaq \func(%rip),%rax
361 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
362 jmp ia32_ptregs_common
367 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi
368 PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi
369 PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx
370 PTREGSCALL stub32_sigsuspend, sys32_sigsuspend, %rcx
371 PTREGSCALL stub32_execve, sys32_execve, %rcx
372 PTREGSCALL stub32_fork, sys_fork, %rdi
373 PTREGSCALL stub32_clone, sys32_clone, %rdx
374 PTREGSCALL stub32_vfork, sys_vfork, %rdi
375 PTREGSCALL stub32_iopl, sys_iopl, %rsi
376 PTREGSCALL stub32_rt_sigsuspend, sys_rt_sigsuspend, %rdx
378 ENTRY(ia32_ptregs_common)
381 CFI_STARTPROC32 simple
383 CFI_DEF_CFA rsp,SS+8-ARGOFFSET
384 CFI_REL_OFFSET rax,RAX-ARGOFFSET
385 CFI_REL_OFFSET rcx,RCX-ARGOFFSET
386 CFI_REL_OFFSET rdx,RDX-ARGOFFSET
387 CFI_REL_OFFSET rsi,RSI-ARGOFFSET
388 CFI_REL_OFFSET rdi,RDI-ARGOFFSET
389 CFI_REL_OFFSET rip,RIP-ARGOFFSET
390 /* CFI_REL_OFFSET cs,CS-ARGOFFSET*/
391 /* CFI_REL_OFFSET rflags,EFLAGS-ARGOFFSET*/
392 CFI_REL_OFFSET rsp,RSP-ARGOFFSET
393 /* CFI_REL_OFFSET ss,SS-ARGOFFSET*/
397 jmp ia32_sysret /* misbalances the return cache */
399 END(ia32_ptregs_common)
404 .quad sys_restart_syscall
409 .quad compat_sys_open /* 5 */
414 .quad sys_unlink /* 10 */
417 .quad compat_sys_time
419 .quad sys_chmod /* 15 */
421 .quad quiet_ni_syscall /* old break syscall holder */
424 .quad sys_getpid /* 20 */
425 .quad compat_sys_mount /* mount */
426 .quad sys_oldumount /* old_umount */
429 .quad compat_sys_stime /* stime */ /* 25 */
430 .quad sys32_ptrace /* ptrace */
432 .quad sys_fstat /* (old)fstat */
434 .quad compat_sys_utime /* 30 */
435 .quad quiet_ni_syscall /* old stty syscall holder */
436 .quad quiet_ni_syscall /* old gtty syscall holder */
439 .quad quiet_ni_syscall /* 35 */ /* old ftime syscall holder */
444 .quad sys_rmdir /* 40 */
447 .quad compat_sys_times
448 .quad quiet_ni_syscall /* old prof syscall holder */
449 .quad sys_brk /* 45 */
454 .quad sys_getegid16 /* 50 */
456 .quad sys_umount /* new_umount */
457 .quad quiet_ni_syscall /* old lock syscall holder */
458 .quad compat_sys_ioctl
459 .quad compat_sys_fcntl64 /* 55 */
460 .quad quiet_ni_syscall /* old mpx syscall holder */
462 .quad quiet_ni_syscall /* old ulimit syscall holder */
464 .quad sys_umask /* 60 */
469 .quad sys_getpgrp /* 65 */
471 .quad sys32_sigaction
474 .quad sys_setreuid16 /* 70 */
476 .quad stub32_sigsuspend
477 .quad compat_sys_sigpending
478 .quad sys_sethostname
479 .quad compat_sys_setrlimit /* 75 */
480 .quad compat_sys_old_getrlimit /* old_getrlimit */
481 .quad compat_sys_getrusage
482 .quad sys32_gettimeofday
483 .quad sys32_settimeofday
484 .quad sys_getgroups16 /* 80 */
485 .quad sys_setgroups16
486 .quad sys32_old_select
489 .quad sys_readlink /* 85 */
493 .quad compat_sys_old_readdir
494 .quad sys32_mmap /* 90 */
499 .quad sys_fchown16 /* 95 */
500 .quad sys_getpriority
501 .quad sys_setpriority
502 .quad quiet_ni_syscall /* old profil syscall holder */
503 .quad compat_sys_statfs
504 .quad compat_sys_fstatfs /* 100 */
506 .quad compat_sys_socketcall
508 .quad compat_sys_setitimer
509 .quad compat_sys_getitimer /* 105 */
510 .quad compat_sys_newstat
511 .quad compat_sys_newlstat
512 .quad compat_sys_newfstat
514 .quad stub32_iopl /* 110 */
516 .quad quiet_ni_syscall /* old "idle" system call */
517 .quad sys32_vm86_warning /* vm86old */
518 .quad compat_sys_wait4
519 .quad sys_swapoff /* 115 */
520 .quad compat_sys_sysinfo
523 .quad stub32_sigreturn
524 .quad stub32_clone /* 120 */
525 .quad sys_setdomainname
528 .quad compat_sys_adjtimex
529 .quad sys32_mprotect /* 125 */
530 .quad compat_sys_sigprocmask
531 .quad quiet_ni_syscall /* create_module */
532 .quad sys_init_module
533 .quad sys_delete_module
534 .quad quiet_ni_syscall /* 130 get_kernel_syms */
538 .quad quiet_ni_syscall /* bdflush */
539 .quad sys_sysfs /* 135 */
540 .quad sys_personality
541 .quad quiet_ni_syscall /* for afs_syscall */
544 .quad sys_llseek /* 140 */
545 .quad compat_sys_getdents
546 .quad compat_sys_select
549 .quad compat_sys_readv /* 145 */
550 .quad compat_sys_writev
553 .quad sys32_sysctl /* sysctl */
554 .quad sys_mlock /* 150 */
558 .quad sys_sched_setparam
559 .quad sys_sched_getparam /* 155 */
560 .quad sys_sched_setscheduler
561 .quad sys_sched_getscheduler
562 .quad sys_sched_yield
563 .quad sys_sched_get_priority_max
564 .quad sys_sched_get_priority_min /* 160 */
565 .quad sys32_sched_rr_get_interval
566 .quad compat_sys_nanosleep
568 .quad sys_setresuid16
569 .quad sys_getresuid16 /* 165 */
570 .quad sys32_vm86_warning /* vm86 */
571 .quad quiet_ni_syscall /* query_module */
573 .quad compat_sys_nfsservctl
574 .quad sys_setresgid16 /* 170 */
575 .quad sys_getresgid16
577 .quad stub32_rt_sigreturn
578 .quad sys32_rt_sigaction
579 .quad sys32_rt_sigprocmask /* 175 */
580 .quad sys32_rt_sigpending
581 .quad compat_sys_rt_sigtimedwait
582 .quad sys32_rt_sigqueueinfo
583 .quad stub32_rt_sigsuspend
584 .quad sys32_pread /* 180 */
590 .quad stub32_sigaltstack
592 .quad quiet_ni_syscall /* streams1 */
593 .quad quiet_ni_syscall /* streams2 */
594 .quad stub32_vfork /* 190 */
595 .quad compat_sys_getrlimit
597 .quad sys32_truncate64
598 .quad sys32_ftruncate64
599 .quad sys32_stat64 /* 195 */
604 .quad sys_getgid /* 200 */
609 .quad sys_getgroups /* 205 */
614 .quad sys_setresgid /* 210 */
619 .quad sys_setfsuid /* 215 */
624 .quad compat_sys_getdents64 /* 220 getdents64 */
625 .quad compat_sys_fcntl64
626 .quad quiet_ni_syscall /* tux */
627 .quad quiet_ni_syscall /* security */
629 .quad sys32_readahead /* 225 */
634 .quad sys_lgetxattr /* 230 */
639 .quad sys_removexattr /* 235 */
640 .quad sys_lremovexattr
641 .quad sys_fremovexattr
644 .quad compat_sys_futex /* 240 */
645 .quad compat_sys_sched_setaffinity
646 .quad compat_sys_sched_getaffinity
647 .quad sys32_set_thread_area
648 .quad sys32_get_thread_area
649 .quad compat_sys_io_setup /* 245 */
651 .quad compat_sys_io_getevents
652 .quad compat_sys_io_submit
654 .quad sys32_fadvise64 /* 250 */
655 .quad quiet_ni_syscall /* free_huge_pages */
657 .quad sys32_lookup_dcookie
658 .quad sys_epoll_create
659 .quad sys_epoll_ctl /* 255 */
661 .quad sys_remap_file_pages
662 .quad sys_set_tid_address
663 .quad compat_sys_timer_create
664 .quad compat_sys_timer_settime /* 260 */
665 .quad compat_sys_timer_gettime
666 .quad sys_timer_getoverrun
667 .quad sys_timer_delete
668 .quad compat_sys_clock_settime
669 .quad compat_sys_clock_gettime /* 265 */
670 .quad compat_sys_clock_getres
671 .quad compat_sys_clock_nanosleep
672 .quad compat_sys_statfs64
673 .quad compat_sys_fstatfs64
674 .quad sys_tgkill /* 270 */
675 .quad compat_sys_utimes
676 .quad sys32_fadvise64_64
677 .quad quiet_ni_syscall /* sys_vserver */
679 .quad compat_sys_get_mempolicy /* 275 */
680 .quad sys_set_mempolicy
681 .quad compat_sys_mq_open
683 .quad compat_sys_mq_timedsend
684 .quad compat_sys_mq_timedreceive /* 280 */
685 .quad compat_sys_mq_notify
686 .quad compat_sys_mq_getsetattr
687 .quad compat_sys_kexec_load /* reserved for kexec */
688 .quad compat_sys_waitid
689 .quad quiet_ni_syscall /* 285: sys_altroot */
691 .quad sys_request_key
694 .quad sys_ioprio_get /* 290 */
695 .quad sys_inotify_init
696 .quad sys_inotify_add_watch
697 .quad sys_inotify_rm_watch
698 .quad sys_migrate_pages
699 .quad compat_sys_openat /* 295 */
703 .quad compat_sys_futimesat
704 .quad sys32_fstatat /* 300 */
709 .quad sys_readlinkat /* 305 */
712 .quad compat_sys_pselect6
713 .quad compat_sys_ppoll
714 .quad sys_unshare /* 310 */
715 .quad compat_sys_set_robust_list
716 .quad compat_sys_get_robust_list
718 .quad sys32_sync_file_range
719 .quad sys_tee /* 315 */
720 .quad compat_sys_vmsplice
721 .quad compat_sys_move_pages
723 .quad sys_epoll_pwait
724 .quad compat_sys_utimensat /* 320 */
725 .quad compat_sys_signalfd
726 .quad compat_sys_timerfd
728 .quad sys32_fallocate