2 * linux/arch/arm26/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 Ian Molton.
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
16 #include <linux/module.h>
17 #include <linux/errno.h>
18 #include <linux/sched.h>
19 #include <linux/slab.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>
28 #include <linux/file.h>
29 #include <linux/utsname.h>
31 #include <asm/uaccess.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 * fildes)
49 if (copy_to_user(fildes, fd, 2*sizeof(int)))
55 /* common code for old and new mmaps */
57 unsigned long addr, unsigned long len,
58 unsigned long prot, unsigned long flags,
59 unsigned long fd, unsigned long pgoff)
62 struct file * file = NULL;
64 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
67 * If we are doing a fixed mapping, and address < PAGE_SIZE,
70 if (flags & MAP_FIXED && addr < PAGE_SIZE && vectors_base() == 0)
74 if (!(flags & MAP_ANONYMOUS)) {
80 down_write(¤t->mm->mmap_sem);
81 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
82 up_write(¤t->mm->mmap_sem);
90 struct mmap_arg_struct {
99 asmlinkage int old_mmap(struct mmap_arg_struct *arg)
102 struct mmap_arg_struct a;
104 if (copy_from_user(&a, arg, sizeof(a)))
108 if (a.offset & ~PAGE_MASK)
111 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
116 asmlinkage unsigned long
117 sys_arm_mremap(unsigned long addr, unsigned long old_len,
118 unsigned long new_len, unsigned long flags,
119 unsigned long new_addr)
121 unsigned long ret = -EINVAL;
124 * If we are doing a fixed mapping, and address < PAGE_SIZE,
127 if (flags & MREMAP_FIXED && new_addr < PAGE_SIZE &&
131 down_write(¤t->mm->mmap_sem);
132 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
133 up_write(¤t->mm->mmap_sem);
140 * Perform the select(nd, in, out, ex, tv) and mmap() system
144 struct sel_arg_struct {
146 fd_set *inp, *outp, *exp;
150 asmlinkage int old_select(struct sel_arg_struct *arg)
152 struct sel_arg_struct a;
154 if (copy_from_user(&a, arg, sizeof(a)))
156 /* sys_select() does the appropriate kernel locking */
157 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
161 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
163 * This is really horribly ugly.
165 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
169 version = call >> 16; /* hack for backward compatibility */
174 return sys_semop (first, (struct sembuf *)ptr, second);
176 return sys_semget (first, second, third);
181 if (get_user(fourth.__pad, (void **) ptr))
183 return sys_semctl (first, second, third, fourth);
187 return sys_msgsnd (first, (struct msgbuf *) ptr,
192 struct ipc_kludge tmp;
195 if (copy_from_user(&tmp,(struct ipc_kludge *) ptr,
198 return sys_msgrcv (first, tmp.msgp, second,
202 return sys_msgrcv (first,
203 (struct msgbuf *) ptr,
204 second, fifth, third);
207 return sys_msgget ((key_t) first, second);
209 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
215 ret = do_shmat (first, (char *) ptr, second, &raddr);
218 return put_user (raddr, (ulong *) third);
220 case 1: /* iBCS2 emulator entry point */
221 if (!segment_eq(get_fs(), get_ds()))
223 return do_shmat (first, (char *) ptr,
224 second, (ulong *) third);
227 return sys_shmdt ((char *)ptr);
229 return sys_shmget (first, second, third);
231 return sys_shmctl (first, second,
232 (struct shmid_ds *) ptr);
238 /* Fork a new task - this creates a new program thread.
239 * This is called indirectly via a small wrapper
241 asmlinkage int sys_fork(struct pt_regs *regs)
243 return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
246 /* Clone a task - this clones the calling program thread.
247 * This is called indirectly via a small wrapper
249 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, struct pt_regs *regs)
252 * We don't support SETTID / CLEARTID (FIXME!!! (nicked from arm32))
254 if (clone_flags & (CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID))
258 newsp = regs->ARM_sp;
260 return do_fork(clone_flags, newsp, regs, 0, NULL, NULL);
263 asmlinkage int sys_vfork(struct pt_regs *regs)
265 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
268 /* sys_execve() executes a new program.
269 * This is called indirectly via a small wrapper
271 asmlinkage int sys_execve(char *filenamei, char **argv, char **envp, struct pt_regs *regs)
276 filename = getname(filenamei);
277 error = PTR_ERR(filename);
278 if (IS_ERR(filename))
280 error = do_execve(filename, argv, envp, regs);
286 /* FIXME - see if this is correct for arm26 */
287 long execve(const char *filename, char **argv, char **envp)
291 memset(®s, 0, sizeof(struct pt_regs));
292 ret = do_execve((char *)filename, (char __user * __user *)argv, (char __user * __user *)envp, ®s);
297 * Save argc to the register structure for userspace.
302 * We were successful. We won't be returning to our caller, but
303 * instead to user space by manipulating the kernel stack.
305 asm( "add r0, %0, %1\n\t"
308 "bl memmove\n\t" /* copy regs to top of stack */
309 "mov r8, #0\n\t" /* not a syscall */
310 "mov r9, %0\n\t" /* thread structure */
311 "mov sp, r0\n\t" /* reposition stack pointer */
314 : "r" (current_thread_info()),
315 "Ir" (THREAD_SIZE - 8 - sizeof(regs)),
318 : "r0", "r1", "r2", "r3", "ip", "memory");
324 EXPORT_SYMBOL(execve);