- pre5:
[davej-history.git] / arch / arm / kernel / sys_arm.c
blobfb15b3d972de375c8bbb4c49b77b283a7b28a0c9
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 *
7 * This file contains various random system calls that
8 * have a non-standard calling sequence on the Linux/arm
9 * platform.
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/malloc.h>
15 #include <linux/mm.h>
16 #include <linux/sem.h>
17 #include <linux/msg.h>
18 #include <linux/shm.h>
19 #include <linux/stat.h>
20 #include <linux/mman.h>
21 #include <linux/fs.h>
22 #include <linux/file.h>
23 #include <linux/utsname.h>
25 #include <asm/uaccess.h>
26 #include <asm/ipc.h>
29 * Constant strings used in inlined functions in header files
33 * sys_pipe() is the normal C calling standard for creating
34 * a pipe. It's not the way unix traditionally does this, though.
36 asmlinkage int sys_pipe(unsigned long * fildes)
38 int fd[2];
39 int error;
41 error = do_pipe(fd);
42 if (!error) {
43 if (copy_to_user(fildes, fd, 2*sizeof(int)))
44 error = -EFAULT;
46 return error;
49 /* common code for old and new mmaps */
50 inline long do_mmap2(
51 unsigned long addr, unsigned long len,
52 unsigned long prot, unsigned long flags,
53 unsigned long fd, unsigned long pgoff)
55 int error = -EBADF;
56 struct file * file = NULL;
58 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
59 if (!(flags & MAP_ANONYMOUS)) {
60 file = fget(fd);
61 if (!file)
62 goto out;
65 down(&current->mm->mmap_sem);
66 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
67 up(&current->mm->mmap_sem);
69 if (file)
70 fput(file);
71 out:
72 return error;
75 struct mmap_arg_struct {
76 unsigned long addr;
77 unsigned long len;
78 unsigned long prot;
79 unsigned long flags;
80 unsigned long fd;
81 unsigned long offset;
84 asmlinkage int old_mmap(struct mmap_arg_struct *arg)
86 int error = -EFAULT;
87 struct mmap_arg_struct a;
89 if (copy_from_user(&a, arg, sizeof(a)))
90 goto out;;
92 error = -EINVAL;
93 if (a.offset & ~PAGE_MASK)
94 goto out;
96 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
97 out:
98 return error;
102 * Perform the select(nd, in, out, ex, tv) and mmap() system
103 * calls.
105 extern asmlinkage int sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
107 struct sel_arg_struct {
108 unsigned long n;
109 fd_set *inp, *outp, *exp;
110 struct timeval *tvp;
113 asmlinkage int old_select(struct sel_arg_struct *arg)
115 struct sel_arg_struct a;
117 if (copy_from_user(&a, arg, sizeof(a)))
118 return -EFAULT;
119 /* sys_select() does the appropriate kernel locking */
120 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
124 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
126 * This is really horribly ugly.
128 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
130 int version, ret;
132 version = call >> 16; /* hack for backward compatibility */
133 call &= 0xffff;
135 switch (call) {
136 case SEMOP:
137 return sys_semop (first, (struct sembuf *)ptr, second);
138 case SEMGET:
139 return sys_semget (first, second, third);
140 case SEMCTL: {
141 union semun fourth;
142 if (!ptr)
143 return -EINVAL;
144 if (get_user(fourth.__pad, (void **) ptr))
145 return -EFAULT;
146 return sys_semctl (first, second, third, fourth);
149 case MSGSND:
150 return sys_msgsnd (first, (struct msgbuf *) ptr,
151 second, third);
152 case MSGRCV:
153 switch (version) {
154 case 0: {
155 struct ipc_kludge tmp;
156 if (!ptr)
157 return -EINVAL;
158 if (copy_from_user(&tmp,(struct ipc_kludge *) ptr,
159 sizeof (tmp)))
160 return -EFAULT;
161 return sys_msgrcv (first, tmp.msgp, second,
162 tmp.msgtyp, third);
164 default:
165 return sys_msgrcv (first,
166 (struct msgbuf *) ptr,
167 second, fifth, third);
169 case MSGGET:
170 return sys_msgget ((key_t) first, second);
171 case MSGCTL:
172 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
174 case SHMAT:
175 switch (version) {
176 default: {
177 ulong raddr;
178 ret = sys_shmat (first, (char *) ptr, second, &raddr);
179 if (ret)
180 return ret;
181 return put_user (raddr, (ulong *) third);
183 case 1: /* iBCS2 emulator entry point */
184 if (!segment_eq(get_fs(), get_ds()))
185 return -EINVAL;
186 return sys_shmat (first, (char *) ptr,
187 second, (ulong *) third);
189 case SHMDT:
190 return sys_shmdt ((char *)ptr);
191 case SHMGET:
192 return sys_shmget (first, second, third);
193 case SHMCTL:
194 return sys_shmctl (first, second,
195 (struct shmid_ds *) ptr);
196 default:
197 return -EINVAL;
201 /* Fork a new task - this creates a new program thread.
202 * This is called indirectly via a small wrapper
204 asmlinkage int sys_fork(struct pt_regs *regs)
206 return do_fork(SIGCHLD, regs->ARM_sp, regs, 0);
209 /* Clone a task - this clones the calling program thread.
210 * This is called indirectly via a small wrapper
212 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, struct pt_regs *regs)
214 if (!newsp)
215 newsp = regs->ARM_sp;
216 return do_fork(clone_flags, newsp, regs, 0);
219 asmlinkage int sys_vfork(struct pt_regs *regs)
221 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0);
224 /* sys_execve() executes a new program.
225 * This is called indirectly via a small wrapper
227 asmlinkage int sys_execve(char *filenamei, char **argv, char **envp, struct pt_regs *regs)
229 int error;
230 char * filename;
232 filename = getname(filenamei);
233 error = PTR_ERR(filename);
234 if (IS_ERR(filename))
235 goto out;
236 error = do_execve(filename, argv, envp, regs);
237 putname(filename);
238 out:
239 return error;
242 asmlinkage int sys_pause(void)
244 current->state = TASK_INTERRUPTIBLE;
245 schedule();
246 return -ERESTARTNOHAND;