blob: b3ec641b5cf8a1b8cf7cce2d932315e42235e03d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This file contains various random system calls that
12 * have a non-standard calling sequence on the Linux/arm
13 * platform.
14 */
15#include <linux/module.h>
16#include <linux/errno.h>
17#include <linux/sched.h>
18#include <linux/slab.h>
19#include <linux/mm.h>
20#include <linux/sem.h>
21#include <linux/msg.h>
22#include <linux/shm.h>
23#include <linux/stat.h>
24#include <linux/syscalls.h>
25#include <linux/mman.h>
26#include <linux/fs.h>
27#include <linux/file.h>
28#include <linux/utsname.h>
Adrian Bunkcba4fbb2007-10-16 23:29:24 -070029#include <linux/ipc.h>
Russell King33fa9b12008-09-06 11:35:55 +010030#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32extern unsigned long do_mremap(unsigned long addr, unsigned long old_len,
33 unsigned long new_len, unsigned long flags,
34 unsigned long new_addr);
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/* common code for old and new mmaps */
37inline long do_mmap2(
38 unsigned long addr, unsigned long len,
39 unsigned long prot, unsigned long flags,
40 unsigned long fd, unsigned long pgoff)
41{
42 int error = -EINVAL;
43 struct file * file = NULL;
44
45 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
46
Hugh Dickins6119be02005-04-19 13:29:21 -070047 if (flags & MAP_FIXED && addr < FIRST_USER_ADDRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 goto out;
49
50 error = -EBADF;
51 if (!(flags & MAP_ANONYMOUS)) {
52 file = fget(fd);
53 if (!file)
54 goto out;
55 }
56
57 down_write(&current->mm->mmap_sem);
58 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
59 up_write(&current->mm->mmap_sem);
60
61 if (file)
62 fput(file);
63out:
64 return error;
65}
66
67struct mmap_arg_struct {
68 unsigned long addr;
69 unsigned long len;
70 unsigned long prot;
71 unsigned long flags;
72 unsigned long fd;
73 unsigned long offset;
74};
75
76asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
77{
78 int error = -EFAULT;
79 struct mmap_arg_struct a;
80
81 if (copy_from_user(&a, arg, sizeof(a)))
82 goto out;
83
84 error = -EINVAL;
85 if (a.offset & ~PAGE_MASK)
86 goto out;
87
88 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
89out:
90 return error;
91}
92
93asmlinkage unsigned long
94sys_arm_mremap(unsigned long addr, unsigned long old_len,
95 unsigned long new_len, unsigned long flags,
96 unsigned long new_addr)
97{
98 unsigned long ret = -EINVAL;
99
Hugh Dickins6119be02005-04-19 13:29:21 -0700100 if (flags & MREMAP_FIXED && new_addr < FIRST_USER_ADDRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 goto out;
102
103 down_write(&current->mm->mmap_sem);
104 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
105 up_write(&current->mm->mmap_sem);
106
107out:
108 return ret;
109}
110
111/*
112 * Perform the select(nd, in, out, ex, tv) and mmap() system
113 * calls.
114 */
115
116struct sel_arg_struct {
117 unsigned long n;
118 fd_set __user *inp, *outp, *exp;
119 struct timeval __user *tvp;
120};
121
122asmlinkage int old_select(struct sel_arg_struct __user *arg)
123{
124 struct sel_arg_struct a;
125
126 if (copy_from_user(&a, arg, sizeof(a)))
127 return -EFAULT;
128 /* sys_select() does the appropriate kernel locking */
129 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
130}
131
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000132#if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/*
134 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
135 *
136 * This is really horribly ugly.
137 */
138asmlinkage int sys_ipc(uint call, int first, int second, int third,
139 void __user *ptr, long fifth)
140{
141 int version, ret;
142
143 version = call >> 16; /* hack for backward compatibility */
144 call &= 0xffff;
145
146 switch (call) {
147 case SEMOP:
148 return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
149 case SEMTIMEDOP:
150 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
151 (const struct timespec __user *)fifth);
152
153 case SEMGET:
154 return sys_semget (first, second, third);
155 case SEMCTL: {
156 union semun fourth;
157 if (!ptr)
158 return -EINVAL;
159 if (get_user(fourth.__pad, (void __user * __user *) ptr))
160 return -EFAULT;
161 return sys_semctl (first, second, third, fourth);
162 }
163
164 case MSGSND:
165 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
166 second, third);
167 case MSGRCV:
168 switch (version) {
169 case 0: {
170 struct ipc_kludge tmp;
171 if (!ptr)
172 return -EINVAL;
173 if (copy_from_user(&tmp,(struct ipc_kludge __user *)ptr,
174 sizeof (tmp)))
175 return -EFAULT;
176 return sys_msgrcv (first, tmp.msgp, second,
177 tmp.msgtyp, third);
178 }
179 default:
180 return sys_msgrcv (first,
181 (struct msgbuf __user *) ptr,
182 second, fifth, third);
183 }
184 case MSGGET:
185 return sys_msgget ((key_t) first, second);
186 case MSGCTL:
187 return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
188
189 case SHMAT:
190 switch (version) {
191 default: {
192 ulong raddr;
193 ret = do_shmat(first, (char __user *)ptr, second, &raddr);
194 if (ret)
195 return ret;
196 return put_user(raddr, (ulong __user *)third);
197 }
198 case 1: /* Of course, we don't support iBCS2! */
199 return -EINVAL;
200 }
201 case SHMDT:
202 return sys_shmdt ((char __user *)ptr);
203 case SHMGET:
204 return sys_shmget (first, second, third);
205 case SHMCTL:
206 return sys_shmctl (first, second,
207 (struct shmid_ds __user *) ptr);
208 default:
209 return -ENOSYS;
210 }
211}
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000212#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214/* Fork a new task - this creates a new program thread.
215 * This is called indirectly via a small wrapper
216 */
217asmlinkage int sys_fork(struct pt_regs *regs)
218{
Hyok S. Choif24284a2006-02-24 21:37:50 +0000219#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
Hyok S. Choif24284a2006-02-24 21:37:50 +0000221#else
222 /* can not support in nommu mode */
223 return(-EINVAL);
224#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
227/* Clone a task - this clones the calling program thread.
228 * This is called indirectly via a small wrapper
229 */
230asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
231 int __user *parent_tidptr, int tls_val,
232 int __user *child_tidptr, struct pt_regs *regs)
233{
234 if (!newsp)
235 newsp = regs->ARM_sp;
236
237 return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
238}
239
240asmlinkage int sys_vfork(struct pt_regs *regs)
241{
242 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
243}
244
245/* sys_execve() executes a new program.
246 * This is called indirectly via a small wrapper
247 */
248asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv,
249 char __user * __user *envp, struct pt_regs *regs)
250{
251 int error;
252 char * filename;
253
254 filename = getname(filenamei);
255 error = PTR_ERR(filename);
256 if (IS_ERR(filename))
257 goto out;
258 error = do_execve(filename, argv, envp, regs);
259 putname(filename);
260out:
261 return error;
262}
263
Arnd Bergmann3db03b42006-10-02 02:18:31 -0700264int kernel_execve(const char *filename, char *const argv[], char *const envp[])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
266 struct pt_regs regs;
267 int ret;
268
269 memset(&regs, 0, sizeof(struct pt_regs));
270 ret = do_execve((char *)filename, (char __user * __user *)argv,
271 (char __user * __user *)envp, &regs);
272 if (ret < 0)
273 goto out;
274
275 /*
276 * Save argc to the register structure for userspace.
277 */
278 regs.ARM_r0 = ret;
279
280 /*
281 * We were successful. We won't be returning to our caller, but
282 * instead to user space by manipulating the kernel stack.
283 */
284 asm( "add r0, %0, %1\n\t"
285 "mov r1, %2\n\t"
286 "mov r2, %3\n\t"
287 "bl memmove\n\t" /* copy regs to top of stack */
288 "mov r8, #0\n\t" /* not a syscall */
289 "mov r9, %0\n\t" /* thread structure */
290 "mov sp, r0\n\t" /* reposition stack pointer */
291 "b ret_to_user"
292 :
293 : "r" (current_thread_info()),
Russell King4f7a1812005-05-05 13:11:00 +0100294 "Ir" (THREAD_START_SP - sizeof(regs)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 "r" (&regs),
296 "Ir" (sizeof(regs))
Nicolas Pitrec2f48082005-10-04 23:17:53 +0100297 : "r0", "r1", "r2", "r3", "ip", "lr", "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 out:
300 return ret;
301}
Arnd Bergmann3db03b42006-10-02 02:18:31 -0700302EXPORT_SYMBOL(kernel_execve);
Nicolas Pitre68d91022005-09-01 12:37:13 +0100303
304/*
Simon Arlott6cbdc8c2007-05-11 20:40:30 +0100305 * Since loff_t is a 64 bit type we avoid a lot of ABI hassle
Nicolas Pitre68d91022005-09-01 12:37:13 +0100306 * with a different argument ordering.
307 */
308asmlinkage long sys_arm_fadvise64_64(int fd, int advice,
309 loff_t offset, loff_t len)
310{
311 return sys_fadvise64_64(fd, offset, len, advice);
312}