arm64: 32-bit (compat) applications support
[deliverable/linux.git] / arch / arm64 / kernel / sys_compat.c
CommitLineData
3dd681d9
WD
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#define __SYSCALL_COMPAT
22
23#include <linux/compat.h>
24#include <linux/personality.h>
25#include <linux/sched.h>
26#include <linux/slab.h>
27#include <linux/syscalls.h>
28#include <linux/uaccess.h>
29
30#include <asm/cacheflush.h>
31#include <asm/unistd.h>
32
33asmlinkage int compat_sys_fork(struct pt_regs *regs)
34{
35 return do_fork(SIGCHLD, regs->compat_sp, regs, 0, NULL, NULL);
36}
37
38asmlinkage int compat_sys_clone(unsigned long clone_flags, unsigned long newsp,
39 int __user *parent_tidptr, int tls_val,
40 int __user *child_tidptr, struct pt_regs *regs)
41{
42 if (!newsp)
43 newsp = regs->compat_sp;
44
45 return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
46}
47
48asmlinkage int compat_sys_vfork(struct pt_regs *regs)
49{
50 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->compat_sp,
51 regs, 0, NULL, NULL);
52}
53
54asmlinkage int compat_sys_execve(const char __user *filenamei,
55 compat_uptr_t argv, compat_uptr_t envp,
56 struct pt_regs *regs)
57{
58 int error;
59 char * filename;
60
61 filename = getname(filenamei);
62 error = PTR_ERR(filename);
63 if (IS_ERR(filename))
64 goto out;
65 error = compat_do_execve(filename, compat_ptr(argv), compat_ptr(envp),
66 regs);
67 putname(filename);
68out:
69 return error;
70}
71
72asmlinkage int compat_sys_sched_rr_get_interval(compat_pid_t pid,
73 struct compat_timespec __user *interval)
74{
75 struct timespec t;
76 int ret;
77 mm_segment_t old_fs = get_fs();
78
79 set_fs(KERNEL_DS);
80 ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
81 set_fs(old_fs);
82 if (put_compat_timespec(&t, interval))
83 return -EFAULT;
84 return ret;
85}
86
87asmlinkage int compat_sys_sendfile(int out_fd, int in_fd,
88 compat_off_t __user *offset, s32 count)
89{
90 mm_segment_t old_fs = get_fs();
91 int ret;
92 off_t of;
93
94 if (offset && get_user(of, offset))
95 return -EFAULT;
96
97 set_fs(KERNEL_DS);
98 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
99 count);
100 set_fs(old_fs);
101
102 if (offset && put_user(of, offset))
103 return -EFAULT;
104 return ret;
105}
106
107static inline void
108do_compat_cache_op(unsigned long start, unsigned long end, int flags)
109{
110 struct mm_struct *mm = current->active_mm;
111 struct vm_area_struct *vma;
112
113 if (end < start || flags)
114 return;
115
116 down_read(&mm->mmap_sem);
117 vma = find_vma(mm, start);
118 if (vma && vma->vm_start < end) {
119 if (start < vma->vm_start)
120 start = vma->vm_start;
121 if (end > vma->vm_end)
122 end = vma->vm_end;
123 up_read(&mm->mmap_sem);
124 __flush_cache_user_range(start & PAGE_MASK, PAGE_ALIGN(end));
125 return;
126 }
127 up_read(&mm->mmap_sem);
128}
129
130/*
131 * Handle all unrecognised system calls.
132 */
133long compat_arm_syscall(struct pt_regs *regs)
134{
135 unsigned int no = regs->regs[7];
136
137 switch (no) {
138 /*
139 * Flush a region from virtual address 'r0' to virtual address 'r1'
140 * _exclusive_. There is no alignment requirement on either address;
141 * user space does not need to know the hardware cache layout.
142 *
143 * r2 contains flags. It should ALWAYS be passed as ZERO until it
144 * is defined to be something else. For now we ignore it, but may
145 * the fires of hell burn in your belly if you break this rule. ;)
146 *
147 * (at a later date, we may want to allow this call to not flush
148 * various aspects of the cache. Passing '0' will guarantee that
149 * everything necessary gets flushed to maintain consistency in
150 * the specified region).
151 */
152 case __ARM_NR_compat_cacheflush:
153 do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
154 return 0;
155
156 case __ARM_NR_compat_set_tls:
157 current->thread.tp_value = regs->regs[0];
158 asm ("msr tpidrro_el0, %0" : : "r" (regs->regs[0]));
159 return 0;
160
161 default:
162 return -ENOSYS;
163 }
164}
This page took 0.029128 seconds and 5 git commands to generate.