Merge branch 'for-3.8' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm64 / kernel / sys_compat.c
1 /*
2 * Based on arch/arm/kernel/sys_arm.c
3 *
4 * Copyright (C) People who wrote linux/arch/i386/kernel/sys_i386.c
5 * Copyright (C) 1995, 1996 Russell King.
6 * Copyright (C) 2012 ARM Ltd.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <linux/compat.h>
22 #include <linux/personality.h>
23 #include <linux/sched.h>
24 #include <linux/slab.h>
25 #include <linux/syscalls.h>
26 #include <linux/uaccess.h>
27
28 #include <asm/cacheflush.h>
29 #include <asm/unistd32.h>
30
31 asmlinkage int compat_sys_fork(void)
32 {
33 return do_fork(SIGCHLD, 0, current_pt_regs(), 0, NULL, NULL);
34 }
35
36 asmlinkage int compat_sys_vfork(void)
37 {
38 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0,
39 current_pt_regs(), 0, NULL, NULL);
40 }
41
42 asmlinkage int compat_sys_sched_rr_get_interval(compat_pid_t pid,
43 struct compat_timespec __user *interval)
44 {
45 struct timespec t;
46 int ret;
47 mm_segment_t old_fs = get_fs();
48
49 set_fs(KERNEL_DS);
50 ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
51 set_fs(old_fs);
52 if (put_compat_timespec(&t, interval))
53 return -EFAULT;
54 return ret;
55 }
56
57 static inline void
58 do_compat_cache_op(unsigned long start, unsigned long end, int flags)
59 {
60 struct mm_struct *mm = current->active_mm;
61 struct vm_area_struct *vma;
62
63 if (end < start || flags)
64 return;
65
66 down_read(&mm->mmap_sem);
67 vma = find_vma(mm, start);
68 if (vma && vma->vm_start < end) {
69 if (start < vma->vm_start)
70 start = vma->vm_start;
71 if (end > vma->vm_end)
72 end = vma->vm_end;
73 up_read(&mm->mmap_sem);
74 __flush_cache_user_range(start & PAGE_MASK, PAGE_ALIGN(end));
75 return;
76 }
77 up_read(&mm->mmap_sem);
78 }
79
80 /*
81 * Handle all unrecognised system calls.
82 */
83 long compat_arm_syscall(struct pt_regs *regs)
84 {
85 unsigned int no = regs->regs[7];
86
87 switch (no) {
88 /*
89 * Flush a region from virtual address 'r0' to virtual address 'r1'
90 * _exclusive_. There is no alignment requirement on either address;
91 * user space does not need to know the hardware cache layout.
92 *
93 * r2 contains flags. It should ALWAYS be passed as ZERO until it
94 * is defined to be something else. For now we ignore it, but may
95 * the fires of hell burn in your belly if you break this rule. ;)
96 *
97 * (at a later date, we may want to allow this call to not flush
98 * various aspects of the cache. Passing '0' will guarantee that
99 * everything necessary gets flushed to maintain consistency in
100 * the specified region).
101 */
102 case __ARM_NR_compat_cacheflush:
103 do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
104 return 0;
105
106 case __ARM_NR_compat_set_tls:
107 current->thread.tp_value = regs->regs[0];
108 asm ("msr tpidrro_el0, %0" : : "r" (regs->regs[0]));
109 return 0;
110
111 default:
112 return -ENOSYS;
113 }
114 }