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.
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.
11 * This file contains various random system calls that
12 * have a non-standard calling sequence on the Linux/arm
15 #include <linux/module.h>
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/slab.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>
27 #include <linux/file.h>
28 #include <linux/utsname.h>
29 #include <linux/ipc.h>
30 #include <linux/uaccess.h>
32 extern unsigned long do_mremap(unsigned long addr, unsigned long old_len,
33 unsigned long new_len, unsigned long flags,
34 unsigned long new_addr);
36 /* common code for old and new mmaps */
38 unsigned long addr, unsigned long len,
39 unsigned long prot, unsigned long flags,
40 unsigned long fd, unsigned long pgoff)
43 struct file * file = NULL;
45 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
47 if (flags & MAP_FIXED && addr < FIRST_USER_ADDRESS)
51 if (!(flags & MAP_ANONYMOUS)) {
57 down_write(¤t->mm->mmap_sem);
58 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
59 up_write(¤t->mm->mmap_sem);
67 struct mmap_arg_struct {
76 asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
79 struct mmap_arg_struct a;
81 if (copy_from_user(&a, arg, sizeof(a)))
85 if (a.offset & ~PAGE_MASK)
88 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
93 asmlinkage unsigned long
94 sys_arm_mremap(unsigned long addr, unsigned long old_len,
95 unsigned long new_len, unsigned long flags,
96 unsigned long new_addr)
98 unsigned long ret = -EINVAL;
100 if (flags & MREMAP_FIXED && new_addr < FIRST_USER_ADDRESS)
103 down_write(¤t->mm->mmap_sem);
104 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
105 up_write(¤t->mm->mmap_sem);
112 * Perform the select(nd, in, out, ex, tv) and mmap() system
116 struct sel_arg_struct {
118 fd_set __user *inp, *outp, *exp;
119 struct timeval __user *tvp;
122 asmlinkage int old_select(struct sel_arg_struct __user *arg)
124 struct sel_arg_struct a;
126 if (copy_from_user(&a, arg, sizeof(a)))
128 /* sys_select() does the appropriate kernel locking */
129 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
132 #if !defined(CONFIG_AEABI) || defined(CONFIG_OABI_COMPAT)
134 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
136 * This is really horribly ugly.
138 asmlinkage int sys_ipc(uint call, int first, int second, int third,
139 void __user *ptr, long fifth)
143 version = call >> 16; /* hack for backward compatibility */
148 return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
150 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
151 (const struct timespec __user *)fifth);
154 return sys_semget (first, second, third);
159 if (get_user(fourth.__pad, (void __user * __user *) ptr))
161 return sys_semctl (first, second, third, fourth);
165 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
170 struct ipc_kludge tmp;
173 if (copy_from_user(&tmp,(struct ipc_kludge __user *)ptr,
176 return sys_msgrcv (first, tmp.msgp, second,
180 return sys_msgrcv (first,
181 (struct msgbuf __user *) ptr,
182 second, fifth, third);
185 return sys_msgget ((key_t) first, second);
187 return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
193 ret = do_shmat(first, (char __user *)ptr, second, &raddr);
196 return put_user(raddr, (ulong __user *)third);
198 case 1: /* Of course, we don't support iBCS2! */
202 return sys_shmdt ((char __user *)ptr);
204 return sys_shmget (first, second, third);
206 return sys_shmctl (first, second,
207 (struct shmid_ds __user *) ptr);
214 /* Fork a new task - this creates a new program thread.
215 * This is called indirectly via a small wrapper
217 asmlinkage int sys_fork(struct pt_regs *regs)
220 return do_fork(SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
222 /* can not support in nommu mode */
227 /* Clone a task - this clones the calling program thread.
228 * This is called indirectly via a small wrapper
230 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
231 int __user *parent_tidptr, int tls_val,
232 int __user *child_tidptr, struct pt_regs *regs)
235 newsp = regs->ARM_sp;
237 return do_fork(clone_flags, newsp, regs, 0, parent_tidptr, child_tidptr);
240 asmlinkage int sys_vfork(struct pt_regs *regs)
242 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->ARM_sp, regs, 0, NULL, NULL);
245 /* sys_execve() executes a new program.
246 * This is called indirectly via a small wrapper
248 asmlinkage int sys_execve(char __user *filenamei, char __user * __user *argv,
249 char __user * __user *envp, struct pt_regs *regs)
254 filename = getname(filenamei);
255 error = PTR_ERR(filename);
256 if (IS_ERR(filename))
258 error = do_execve(filename, argv, envp, regs);
264 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
269 memset(®s, 0, sizeof(struct pt_regs));
270 ret = do_execve((char *)filename, (char __user * __user *)argv,
271 (char __user * __user *)envp, ®s);
276 * Save argc to the register structure for userspace.
281 * We were successful. We won't be returning to our caller, but
282 * instead to user space by manipulating the kernel stack.
284 asm( "add r0, %0, %1\n\t"
287 "bl memmove\n\t" /* copy regs to top of stack */
288 "mov r8, #0\n\t" /* not a syscall */
289 "mov r9, %0\n\t" /* thread structure */
290 "mov sp, r0\n\t" /* reposition stack pointer */
293 : "r" (current_thread_info()),
294 "Ir" (THREAD_START_SP - sizeof(regs)),
297 : "r0", "r1", "r2", "r3", "ip", "lr", "memory");
302 EXPORT_SYMBOL(kernel_execve);
305 * Since loff_t is a 64 bit type we avoid a lot of ABI hassle
306 * with a different argument ordering.
308 asmlinkage long sys_arm_fadvise64_64(int fd, int advice,
309 loff_t offset, loff_t len)
311 return sys_fadvise64_64(fd, offset, len, advice);