2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1995, 1996, 1997, 2000, 2001, 05 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 * Copyright (C) 2001 MIPS Technologies, Inc.
10 #include <linux/a.out.h>
11 #include <linux/capability.h>
12 #include <linux/errno.h>
13 #include <linux/linkage.h>
16 #include <linux/smp.h>
17 #include <linux/mman.h>
18 #include <linux/ptrace.h>
19 #include <linux/sched.h>
20 #include <linux/string.h>
21 #include <linux/syscalls.h>
22 #include <linux/file.h>
23 #include <linux/slab.h>
24 #include <linux/utsname.h>
25 #include <linux/unistd.h>
26 #include <linux/sem.h>
27 #include <linux/msg.h>
28 #include <linux/shm.h>
29 #include <linux/compiler.h>
30 #include <linux/module.h>
31 #include <linux/ipc.h>
33 #include <asm/branch.h>
34 #include <asm/cachectl.h>
35 #include <asm/cacheflush.h>
36 #include <asm/asm-offsets.h>
37 #include <asm/signal.h>
39 #include <asm/shmparam.h>
40 #include <asm/sysmips.h>
41 #include <asm/uaccess.h>
44 * For historic reasons the pipe(2) syscall on MIPS has an unusual calling
45 * convention. It returns results in registers $v0 / $v1 which means there
46 * is no need for it to do verify the validity of a userspace pointer
47 * argument. Historically that used to be expensive in Linux. These days
48 * the performance advantage is negligible.
50 asmlinkage int sysm_pipe(nabi_no_regargs volatile struct pt_regs regs)
55 error = do_pipe_flags(fd, 0);
66 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
68 EXPORT_SYMBOL(shm_align_mask);
70 #define COLOUR_ALIGN(addr,pgoff) \
71 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
72 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
74 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
75 unsigned long len, unsigned long pgoff, unsigned long flags)
77 struct vm_area_struct * vmm;
79 unsigned long task_size;
81 task_size = STACK_TOP;
86 if (flags & MAP_FIXED) {
87 /* Even MAP_FIXED mappings must reside within task_size. */
88 if (task_size - len < addr)
92 * We do not accept a shared mapping if it would violate
93 * cache aliasing constraints.
95 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
101 if (filp || (flags & MAP_SHARED))
105 addr = COLOUR_ALIGN(addr, pgoff);
107 addr = PAGE_ALIGN(addr);
108 vmm = find_vma(current->mm, addr);
109 if (task_size - len >= addr &&
110 (!vmm || addr + len <= vmm->vm_start))
113 addr = TASK_UNMAPPED_BASE;
115 addr = COLOUR_ALIGN(addr, pgoff);
117 addr = PAGE_ALIGN(addr);
119 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
120 /* At this point: (!vmm || addr < vmm->vm_end). */
121 if (task_size - len < addr)
123 if (!vmm || addr + len <= vmm->vm_start)
127 addr = COLOUR_ALIGN(addr, pgoff);
131 /* common code for old and new mmaps */
132 static inline unsigned long
133 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
134 unsigned long flags, unsigned long fd, unsigned long pgoff)
136 unsigned long error = -EBADF;
137 struct file * file = NULL;
139 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
140 if (!(flags & MAP_ANONYMOUS)) {
146 down_write(¤t->mm->mmap_sem);
147 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
148 up_write(¤t->mm->mmap_sem);
156 asmlinkage unsigned long
157 old_mmap(unsigned long addr, unsigned long len, int prot,
158 int flags, int fd, off_t offset)
160 unsigned long result;
163 if (offset & ~PAGE_MASK)
166 result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
172 asmlinkage unsigned long
173 sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
174 unsigned long flags, unsigned long fd, unsigned long pgoff)
176 if (pgoff & (~PAGE_MASK >> 12))
179 return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
182 save_static_function(sys_fork);
183 static int __used noinline
184 _sys_fork(nabi_no_regargs struct pt_regs regs)
186 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
189 save_static_function(sys_clone);
190 static int __used noinline
191 _sys_clone(nabi_no_regargs struct pt_regs regs)
193 unsigned long clone_flags;
195 int __user *parent_tidptr, *child_tidptr;
197 clone_flags = regs.regs[4];
198 newsp = regs.regs[5];
200 newsp = regs.regs[29];
201 parent_tidptr = (int __user *) regs.regs[6];
203 /* We need to fetch the fifth argument off the stack. */
205 if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
206 int __user *__user *usp = (int __user *__user *) regs.regs[29];
207 if (regs.regs[2] == __NR_syscall) {
208 if (get_user (child_tidptr, &usp[5]))
211 else if (get_user (child_tidptr, &usp[4]))
215 child_tidptr = (int __user *) regs.regs[8];
217 return do_fork(clone_flags, newsp, ®s, 0,
218 parent_tidptr, child_tidptr);
222 * sys_execve() executes a new program.
224 asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
229 filename = getname((char __user *) (long)regs.regs[4]);
230 error = PTR_ERR(filename);
231 if (IS_ERR(filename))
233 error = do_execve(filename, (char __user *__user *) (long)regs.regs[5],
234 (char __user *__user *) (long)regs.regs[6], ®s);
242 * Compacrapability ...
244 asmlinkage int sys_uname(struct old_utsname __user * name)
246 if (name && !copy_to_user(name, utsname(), sizeof (*name)))
252 * Compacrapability ...
254 asmlinkage int sys_olduname(struct oldold_utsname __user * name)
260 if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
263 error = __copy_to_user(&name->sysname, &utsname()->sysname,
265 error -= __put_user(0, name->sysname + __OLD_UTS_LEN);
266 error -= __copy_to_user(&name->nodename, &utsname()->nodename,
268 error -= __put_user(0, name->nodename + __OLD_UTS_LEN);
269 error -= __copy_to_user(&name->release, &utsname()->release,
271 error -= __put_user(0, name->release + __OLD_UTS_LEN);
272 error -= __copy_to_user(&name->version, &utsname()->version,
274 error -= __put_user(0, name->version + __OLD_UTS_LEN);
275 error -= __copy_to_user(&name->machine, &utsname()->machine,
277 error = __put_user(0, name->machine + __OLD_UTS_LEN);
278 error = error ? -EFAULT : 0;
283 asmlinkage int sys_set_thread_area(unsigned long addr)
285 struct thread_info *ti = task_thread_info(current);
288 if (cpu_has_userlocal)
289 write_c0_userlocal(addr);
294 asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
297 case MIPS_ATOMIC_SET:
298 printk(KERN_CRIT "How did I get here?\n");
306 set_thread_flag(TIF_FIXADE);
308 clear_thread_flag(TIF_FIXADE);
310 set_thread_flag(TIF_LOGADE);
312 clear_thread_flag(TIF_FIXADE);
325 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
327 * This is really horribly ugly.
329 asmlinkage int sys_ipc(unsigned int call, int first, int second,
330 unsigned long third, void __user *ptr, long fifth)
334 version = call >> 16; /* hack for backward compatibility */
339 return sys_semtimedop(first, (struct sembuf __user *)ptr,
342 return sys_semtimedop(first, (struct sembuf __user *)ptr,
344 (const struct timespec __user *)fifth);
346 return sys_semget(first, second, third);
351 if (get_user(fourth.__pad, (void __user *__user *) ptr))
353 return sys_semctl(first, second, third, fourth);
357 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
362 struct ipc_kludge tmp;
366 if (copy_from_user(&tmp,
367 (struct ipc_kludge __user *) ptr,
370 return sys_msgrcv(first, tmp.msgp, second,
374 return sys_msgrcv(first,
375 (struct msgbuf __user *) ptr,
376 second, fifth, third);
379 return sys_msgget((key_t) first, second);
381 return sys_msgctl(first, second,
382 (struct msqid_ds __user *) ptr);
388 ret = do_shmat(first, (char __user *) ptr, second,
392 return put_user(raddr, (unsigned long __user *) third);
394 case 1: /* iBCS2 emulator entry point */
395 if (!segment_eq(get_fs(), get_ds()))
397 return do_shmat(first, (char __user *) ptr, second,
398 (unsigned long *) third);
401 return sys_shmdt((char __user *)ptr);
403 return sys_shmget(first, second, third);
405 return sys_shmctl(first, second,
406 (struct shmid_ds __user *) ptr);
413 * No implemented yet ...
415 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
421 * If we ever come here the user sp is bad. Zap the process right away.
422 * Due to the bad stack signaling wouldn't work.
424 asmlinkage void bad_stack(void)
430 * Do a system call from kernel instead of calling sys_execve so we
431 * end up with proper pt_regs.
433 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
435 register unsigned long __a0 asm("$4") = (unsigned long) filename;
436 register unsigned long __a1 asm("$5") = (unsigned long) argv;
437 register unsigned long __a2 asm("$6") = (unsigned long) envp;
438 register unsigned long __a3 asm("$7");
441 __asm__ volatile (" \n"
443 " li $2, %5 # __NR_execve \n"
447 : "=&r" (__v0), "=r" (__a3)
448 : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
449 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",