Add generic sys_old_mmap()
[safe/jmp/linux-2.6] / arch / arm / kernel / sys_arm.c
1 /*
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/ipc.h>
29 #include <linux/uaccess.h>
30
31 #if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT)
32 /*
33  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
34  *
35  * This is really horribly ugly.
36  */
37 asmlinkage int sys_ipc(uint call, int first, int second, int third,
38                        void __user *ptr, long fifth)
39 {
40         int version, ret;
41
42         version = call >> 16; /* hack for backward compatibility */
43         call &= 0xffff;
44
45         switch (call) {
46         case SEMOP:
47                 return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
48         case SEMTIMEDOP:
49                 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
50                                         (const struct timespec __user *)fifth);
51
52         case SEMGET:
53                 return sys_semget (first, second, third);
54         case SEMCTL: {
55                 union semun fourth;
56                 if (!ptr)
57                         return -EINVAL;
58                 if (get_user(fourth.__pad, (void __user * __user *) ptr))
59                         return -EFAULT;
60                 return sys_semctl (first, second, third, fourth);
61         }
62
63         case MSGSND:
64                 return sys_msgsnd(first, (struct msgbuf __user *) ptr, 
65                                   second, third);
66         case MSGRCV:
67                 switch (version) {
68                 case 0: {
69                         struct ipc_kludge tmp;
70                         if (!ptr)
71                                 return -EINVAL;
72                         if (copy_from_user(&tmp,(struct ipc_kludge __user *)ptr,
73                                            sizeof (tmp)))
74                                 return -EFAULT;
75                         return sys_msgrcv (first, tmp.msgp, second,
76                                            tmp.msgtyp, third);
77                 }
78                 default:
79                         return sys_msgrcv (first,
80                                            (struct msgbuf __user *) ptr,
81                                            second, fifth, third);
82                 }
83         case MSGGET:
84                 return sys_msgget ((key_t) first, second);
85         case MSGCTL:
86                 return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
87
88         case SHMAT:
89                 switch (version) {
90                 default: {
91                         ulong raddr;
92                         ret = do_shmat(first, (char __user *)ptr, second, &raddr);
93                         if (ret)
94                                 return ret;
95                         return put_user(raddr, (ulong __user *)third);
96                 }
97                 case 1: /* Of course, we don't support iBCS2! */
98                         return -EINVAL;
99                 }
100         case SHMDT: 
101                 return sys_shmdt ((char __user *)ptr);
102         case SHMGET:
103                 return sys_shmget (first, second, third);
104         case SHMCTL:
105                 return sys_shmctl (first, second,
106                                    (struct shmid_ds __user *) ptr);
107         default:
108                 return -ENOSYS;
109         }
110 }
111 #endif
112
113 /* Fork a new task - this creates a new program thread.
114  * This is called indirectly via a small wrapper
115  */
116 asmlinkage int sys_fork(struct pt_regs *regs)
117 {
118 #ifdef CONFIG_MMU
119         return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
120 #else
121         /* can not support in nommu mode */
122         return(-EINVAL);
123 #endif
124 }
125
126 /* Clone a task - this clones the calling program thread.
127  * This is called indirectly via a small wrapper
128  */
129 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
130                          int __user *parent_tidptr, int tls_val,
131                          int __user *child_tidptr, struct pt_regs *regs)
132 {
133         if (!newsp)
134                 newsp = regs->ARM_sp;
135
136         return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
137 }
138
139 asmlinkage int sys_vfork(struct pt_regs *regs)
140 {
141         return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
142 }
143
144 /* sys_execve() executes a new program.
145  * This is called indirectly via a small wrapper
146  */
147 asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv,
148                           char __user * __user *envp, struct pt_regs *regs)
149 {
150         int error;
151         char * filename;
152
153         filename = getname(filenamei);
154         error = PTR_ERR(filename);
155         if (IS_ERR(filename))
156                 goto out;
157         error = do_execve(filename, argv, envp, regs);
158         putname(filename);
159 out:
160         return error;
161 }
162
163 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
164 {
165         struct pt_regs regs;
166         int ret;
167
168         memset(&regs, 0, sizeof(struct pt_regs));
169         ret = do_execve((char *)filename, (char __user * __user *)argv,
170                         (char __user * __user *)envp, &regs);
171         if (ret < 0)
172                 goto out;
173
174         /*
175          * Save argc to the register structure for userspace.
176          */
177         regs.ARM_r0 = ret;
178
179         /*
180          * We were successful.  We won't be returning to our caller, but
181          * instead to user space by manipulating the kernel stack.
182          */
183         asm(    "add    r0, %0, %1\n\t"
184                 "mov    r1, %2\n\t"
185                 "mov    r2, %3\n\t"
186                 "bl     memmove\n\t"    /* copy regs to top of stack */
187                 "mov    r8, #0\n\t"     /* not a syscall */
188                 "mov    r9, %0\n\t"     /* thread structure */
189                 "mov    sp, r0\n\t"     /* reposition stack pointer */
190                 "b      ret_to_user"
191                 :
192                 : "r" (current_thread_info()),
193                   "Ir" (THREAD_START_SP - sizeof(regs)),
194                   "r" (&regs),
195                   "Ir" (sizeof(regs))
196                 : "r0", "r1", "r2", "r3", "ip", "lr", "memory");
197
198  out:
199         return ret;
200 }
201 EXPORT_SYMBOL(kernel_execve);
202
203 /*
204  * Since loff_t is a 64 bit type we avoid a lot of ABI hassle
205  * with a different argument ordering.
206  */
207 asmlinkage long sys_arm_fadvise64_64(int fd, int advice,
208                                      loff_t offset, loff_t len)
209 {
210         return sys_fadvise64_64(fd, offset, len, advice);
211 }