MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / arm / kernel / sys_arm.c
blob43a722bfcddefc63ec9357e6ba29f2ea9fe66c69
1 /*
2 * linux/arch/arm/kernel/sys_arm.c
4 * Copyright (C) People who wrote linux/arch/i386/kernel/sys_i386.c
5 * Copyright (C) 1995, 1996 Russell King.
6 * Copyright (C) 2003, 2004 Hyok S. Choi
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.
12 * This file contains various random system calls that
13 * have a non-standard calling sequence on the Linux/arm
14 * platform.
16 #include <linux/module.h>
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/slab.h>
20 #include <linux/mm.h>
21 #include <linux/sem.h>
22 #include <linux/msg.h>
23 #include <linux/shm.h>
24 #include <linux/stat.h>
25 #include <linux/syscalls.h>
26 #include <linux/mman.h>
27 #include <linux/fs.h>
28 #include <linux/file.h>
29 #include <linux/utsname.h>
31 #include <asm/uaccess.h>
32 #include <asm/ipc.h>
34 extern unsigned long do_mremap(unsigned long addr, unsigned long old_len,
35 unsigned long new_len, unsigned long flags,
36 unsigned long new_addr);
39 * sys_pipe() is the normal C calling standard for creating
40 * a pipe. It's not the way unix traditionally does this, though.
42 asmlinkage int sys_pipe(unsigned long __user *fildes)
44 int fd[2];
45 int error;
47 error = do_pipe(fd);
48 if (!error) {
49 if (copy_to_user(fildes, fd, 2*sizeof(int)))
50 error = -EFAULT;
52 return error;
55 /* common code for old and new mmaps */
56 inline long do_mmap2(
57 unsigned long addr, unsigned long len,
58 unsigned long prot, unsigned long flags,
59 unsigned long fd, unsigned long pgoff)
61 int error = -EINVAL;
62 struct file * file = NULL;
64 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
66 if (flags & MAP_FIXED && addr < FIRST_USER_ADDRESS)
67 goto out;
69 error = -EBADF;
70 if (!(flags & MAP_ANONYMOUS)) {
71 file = fget(fd);
72 if (!file)
73 goto out;
76 down_write(&current->mm->mmap_sem);
77 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
78 up_write(&current->mm->mmap_sem);
80 if (file)
81 fput(file);
82 out:
83 return error;
86 struct mmap_arg_struct {
87 unsigned long addr;
88 unsigned long len;
89 unsigned long prot;
90 unsigned long flags;
91 unsigned long fd;
92 unsigned long offset;
95 asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
97 int error = -EFAULT;
98 struct mmap_arg_struct a;
100 if (copy_from_user(&a, arg, sizeof(a)))
101 goto out;
103 error = -EINVAL;
104 if (a.offset & ~PAGE_MASK)
105 goto out;
107 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
108 out:
109 return error;
112 asmlinkage unsigned long
113 sys_arm_mremap(unsigned long addr, unsigned long old_len,
114 unsigned long new_len, unsigned long flags,
115 unsigned long new_addr)
117 unsigned long ret = -EINVAL;
118 #ifdef CONFIG_MMU
119 if (flags & MREMAP_FIXED && new_addr < FIRST_USER_ADDRESS)
120 goto out;
122 down_write(&current->mm->mmap_sem);
123 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
124 up_write(&current->mm->mmap_sem);
126 out:
127 #endif
128 return ret;
132 * Perform the select(nd, in, out, ex, tv) and mmap() system
133 * calls.
136 struct sel_arg_struct {
137 unsigned long n;
138 fd_set __user *inp, *outp, *exp;
139 struct timeval __user *tvp;
142 asmlinkage int old_select(struct sel_arg_struct __user *arg)
144 struct sel_arg_struct a;
146 if (copy_from_user(&a, arg, sizeof(a)))
147 return -EFAULT;
148 /* sys_select() does the appropriate kernel locking */
149 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
152 #if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT)
154 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
156 * This is really horribly ugly.
158 asmlinkage int sys_ipc(uint call, int first, int second, int third,
159 void __user *ptr, long fifth)
161 int version, ret;
163 version = call >> 16; /* hack for backward compatibility */
164 call &= 0xffff;
166 switch (call) {
167 case SEMOP:
168 return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
169 case SEMTIMEDOP:
170 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
171 (const struct timespec __user *)fifth);
173 case SEMGET:
174 return sys_semget (first, second, third);
175 case SEMCTL: {
176 union semun fourth;
177 if (!ptr)
178 return -EINVAL;
179 if (get_user(fourth.__pad, (void __user * __user *) ptr))
180 return -EFAULT;
181 return sys_semctl (first, second, third, fourth);
184 case MSGSND:
185 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
186 second, third);
187 case MSGRCV:
188 switch (version) {
189 case 0: {
190 struct ipc_kludge tmp;
191 if (!ptr)
192 return -EINVAL;
193 if (copy_from_user(&tmp,(struct ipc_kludge __user *)ptr,
194 sizeof (tmp)))
195 return -EFAULT;
196 return sys_msgrcv (first, tmp.msgp, second,
197 tmp.msgtyp, third);
199 default:
200 return sys_msgrcv (first,
201 (struct msgbuf __user *) ptr,
202 second, fifth, third);
204 case MSGGET:
205 return sys_msgget ((key_t) first, second);
206 case MSGCTL:
207 return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
209 case SHMAT:
210 switch (version) {
211 default: {
212 ulong raddr;
213 ret = do_shmat(first, (char __user *)ptr, second, &raddr);
214 if (ret)
215 return ret;
216 return put_user(raddr, (ulong __user *)third);
218 case 1: /* Of course, we don't support iBCS2! */
219 return -EINVAL;
221 case SHMDT:
222 return sys_shmdt ((char __user *)ptr);
223 case SHMGET:
224 return sys_shmget (first, second, third);
225 case SHMCTL:
226 return sys_shmctl (first, second,
227 (struct shmid_ds __user *) ptr);
228 default:
229 return -ENOSYS;
232 #endif
234 /* Fork a new task - this creates a new program thread.
235 * This is called indirectly via a small wrapper
237 asmlinkage int sys_fork(struct pt_regs *regs)
239 #ifdef CONFIG_MMU
240 return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
241 #else
242 /* can not support in nommu mode */
243 return(-EINVAL);
244 #endif
247 /* Clone a task - this clones the calling program thread.
248 * This is called indirectly via a small wrapper
250 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
251 int __user *parent_tidptr, int tls_val,
252 int __user *child_tidptr, struct pt_regs *regs)
254 if (!newsp)
255 newsp = regs->ARM_sp;
257 return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
260 asmlinkage int sys_vfork(struct pt_regs *regs)
262 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
265 /* sys_execve() executes a new program.
266 * This is called indirectly via a small wrapper
268 asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv,
269 char __user * __user *envp, struct pt_regs *regs)
271 int error;
272 char * filename;
274 filename = getname(filenamei);
275 error = PTR_ERR(filename);
276 if (IS_ERR(filename))
277 goto out;
278 error = do_execve(filename, argv, envp, regs);
279 putname(filename);
280 out:
281 return error;
284 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
286 struct pt_regs regs;
287 int ret;
289 memset(&regs, 0, sizeof(struct pt_regs));
290 ret = do_execve((char *)filename, (char __user * __user *)argv,
291 (char __user * __user *)envp, &regs);
292 if (ret < 0)
293 goto out;
296 * Save argc to the register structure for userspace.
298 regs.ARM_r0 = ret;
301 * We were successful. We won't be returning to our caller, but
302 * instead to user space by manipulating the kernel stack.
304 asm( "add r0, %0, %1\n\t"
305 "mov r1, %2\n\t"
306 "mov r2, %3\n\t"
307 "bl memmove\n\t" /* copy regs to top of stack */
308 "mov r8, #0\n\t" /* not a syscall */
309 "mov r9, %0\n\t" /* thread structure */
310 "mov sp, r0\n\t" /* reposition stack pointer */
311 "b ret_to_user"
313 : "r" (current_thread_info()),
314 "Ir" (THREAD_START_SP - sizeof(regs)),
315 "r" (&regs),
316 "Ir" (sizeof(regs))
317 : "r0", "r1", "r2", "r3", "ip", "lr", "memory");
319 out:
320 return ret;
322 EXPORT_SYMBOL(kernel_execve);
325 * Since loff_t is a 64 bit type we avoid a lot of ABI hastle
326 * with a different argument ordering.
328 asmlinkage long sys_arm_fadvise64_64(int fd, int advice,
329 loff_t offset, loff_t len)
331 return sys_fadvise64_64(fd, offset, len, advice);