blob: 3b897444a9bd48e1b9cdd54d19f9dc80cdd8e516 [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>
Adrian Bunkcba4fbb2007-10-16 23:29:24 -070028#include <linux/ipc.h>
Russell King33fa9b12008-09-06 11:35:55 +010029#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031/* common code for old and new mmaps */
32inline long do_mmap2(
33 unsigned long addr, unsigned long len,
34 unsigned long prot, unsigned long flags,
35 unsigned long fd, unsigned long pgoff)
36{
37 int error = -EINVAL;
38 struct file * file = NULL;
39
40 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 error = -EBADF;
43 if (!(flags & MAP_ANONYMOUS)) {
44 file = fget(fd);
45 if (!file)
46 goto out;
47 }
48
49 down_write(&current->mm->mmap_sem);
50 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
51 up_write(&current->mm->mmap_sem);
52
53 if (file)
54 fput(file);
55out:
56 return error;
57}
58
59struct mmap_arg_struct {
60 unsigned long addr;
61 unsigned long len;
62 unsigned long prot;
63 unsigned long flags;
64 unsigned long fd;
65 unsigned long offset;
66};
67
68asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
69{
70 int error = -EFAULT;
71 struct mmap_arg_struct a;
72
73 if (copy_from_user(&a, arg, sizeof(a)))
74 goto out;
75
76 error = -EINVAL;
77 if (a.offset & ~PAGE_MASK)
78 goto out;
79
80 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
81out:
82 return error;
83}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/*
86 * Perform the select(nd, in, out, ex, tv) and mmap() system
87 * calls.
88 */
89
90struct sel_arg_struct {
91 unsigned long n;
92 fd_set __user *inp, *outp, *exp;
93 struct timeval __user *tvp;
94};
95
96asmlinkage int old_select(struct sel_arg_struct __user *arg)
97{
98 struct sel_arg_struct a;
99
100 if (copy_from_user(&a, arg, sizeof(a)))
101 return -EFAULT;
102 /* sys_select() does the appropriate kernel locking */
103 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
104}
105
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000106#if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/*
108 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
109 *
110 * This is really horribly ugly.
111 */
112asmlinkage int sys_ipc(uint call, int first, int second, int third,
113 void __user *ptr, long fifth)
114{
115 int version, ret;
116
117 version = call >> 16; /* hack for backward compatibility */
118 call &= 0xffff;
119
120 switch (call) {
121 case SEMOP:
122 return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
123 case SEMTIMEDOP:
124 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
125 (const struct timespec __user *)fifth);
126
127 case SEMGET:
128 return sys_semget (first, second, third);
129 case SEMCTL: {
130 union semun fourth;
131 if (!ptr)
132 return -EINVAL;
133 if (get_user(fourth.__pad, (void __user * __user *) ptr))
134 return -EFAULT;
135 return sys_semctl (first, second, third, fourth);
136 }
137
138 case MSGSND:
139 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
140 second, third);
141 case MSGRCV:
142 switch (version) {
143 case 0: {
144 struct ipc_kludge tmp;
145 if (!ptr)
146 return -EINVAL;
147 if (copy_from_user(&tmp,(struct ipc_kludge __user *)ptr,
148 sizeof (tmp)))
149 return -EFAULT;
150 return sys_msgrcv (first, tmp.msgp, second,
151 tmp.msgtyp, third);
152 }
153 default:
154 return sys_msgrcv (first,
155 (struct msgbuf __user *) ptr,
156 second, fifth, third);
157 }
158 case MSGGET:
159 return sys_msgget ((key_t) first, second);
160 case MSGCTL:
161 return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
162
163 case SHMAT:
164 switch (version) {
165 default: {
166 ulong raddr;
167 ret = do_shmat(first, (char __user *)ptr, second, &raddr);
168 if (ret)
169 return ret;
170 return put_user(raddr, (ulong __user *)third);
171 }
172 case 1: /* Of course, we don't support iBCS2! */
173 return -EINVAL;
174 }
175 case SHMDT:
176 return sys_shmdt ((char __user *)ptr);
177 case SHMGET:
178 return sys_shmget (first, second, third);
179 case SHMCTL:
180 return sys_shmctl (first, second,
181 (struct shmid_ds __user *) ptr);
182 default:
183 return -ENOSYS;
184 }
185}
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000186#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/* Fork a new task - this creates a new program thread.
189 * This is called indirectly via a small wrapper
190 */
191asmlinkage int sys_fork(struct pt_regs *regs)
192{
Hyok S. Choif24284a2006-02-24 21:37:50 +0000193#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
Hyok S. Choif24284a2006-02-24 21:37:50 +0000195#else
196 /* can not support in nommu mode */
197 return(-EINVAL);
198#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199}
200
201/* Clone a task - this clones the calling program thread.
202 * This is called indirectly via a small wrapper
203 */
204asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
205 int __user *parent_tidptr, int tls_val,
206 int __user *child_tidptr, struct pt_regs *regs)
207{
208 if (!newsp)
209 newsp = regs->ARM_sp;
210
211 return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
212}
213
214asmlinkage int sys_vfork(struct pt_regs *regs)
215{
216 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
217}
218
219/* sys_execve() executes a new program.
220 * This is called indirectly via a small wrapper
221 */
222asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv,
223 char __user * __user *envp, struct pt_regs *regs)
224{
225 int error;
226 char * filename;
227
228 filename = getname(filenamei);
229 error = PTR_ERR(filename);
230 if (IS_ERR(filename))
231 goto out;
232 error = do_execve(filename, argv, envp, regs);
233 putname(filename);
234out:
235 return error;
236}
237
Arnd Bergmann3db03b42006-10-02 02:18:31 -0700238int kernel_execve(const char *filename, char *const argv[], char *const envp[])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
240 struct pt_regs regs;
241 int ret;
242
243 memset(&regs, 0, sizeof(struct pt_regs));
244 ret = do_execve((char *)filename, (char __user * __user *)argv,
245 (char __user * __user *)envp, &regs);
246 if (ret < 0)
247 goto out;
248
249 /*
250 * Save argc to the register structure for userspace.
251 */
252 regs.ARM_r0 = ret;
253
254 /*
255 * We were successful. We won't be returning to our caller, but
256 * instead to user space by manipulating the kernel stack.
257 */
258 asm( "add r0, %0, %1\n\t"
259 "mov r1, %2\n\t"
260 "mov r2, %3\n\t"
261 "bl memmove\n\t" /* copy regs to top of stack */
262 "mov r8, #0\n\t" /* not a syscall */
263 "mov r9, %0\n\t" /* thread structure */
264 "mov sp, r0\n\t" /* reposition stack pointer */
265 "b ret_to_user"
266 :
267 : "r" (current_thread_info()),
Russell King4f7a1812005-05-05 13:11:00 +0100268 "Ir" (THREAD_START_SP - sizeof(regs)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 "r" (&regs),
270 "Ir" (sizeof(regs))
Nicolas Pitrec2f48082005-10-04 23:17:53 +0100271 : "r0", "r1", "r2", "r3", "ip", "lr", "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273 out:
274 return ret;
275}
Arnd Bergmann3db03b42006-10-02 02:18:31 -0700276EXPORT_SYMBOL(kernel_execve);
Nicolas Pitre68d91022005-09-01 12:37:13 +0100277
278/*
Simon Arlott6cbdc8c2007-05-11 20:40:30 +0100279 * Since loff_t is a 64 bit type we avoid a lot of ABI hassle
Nicolas Pitre68d91022005-09-01 12:37:13 +0100280 * with a different argument ordering.
281 */
282asmlinkage long sys_arm_fadvise64_64(int fd, int advice,
283 loff_t offset, loff_t len)
284{
285 return sys_fadvise64_64(fd, offset, len, advice);
286}