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/capability.h>
11 #include <linux/errno.h>
12 #include <linux/linkage.h>
15 #include <linux/smp.h>
16 #include <linux/mman.h>
17 #include <linux/ptrace.h>
18 #include <linux/sched.h>
19 #include <linux/string.h>
20 #include <linux/syscalls.h>
21 #include <linux/file.h>
22 #include <linux/slab.h>
23 #include <linux/utsname.h>
24 #include <linux/unistd.h>
25 #include <linux/sem.h>
26 #include <linux/msg.h>
27 #include <linux/shm.h>
28 #include <linux/compiler.h>
29 #include <linux/module.h>
30 #include <linux/ipc.h>
32 #include <asm/branch.h>
33 #include <asm/cachectl.h>
34 #include <asm/cacheflush.h>
35 #include <asm/asm-offsets.h>
36 #include <asm/signal.h>
38 #include <asm/shmparam.h>
39 #include <asm/sysmips.h>
40 #include <asm/uaccess.h>
43 * For historic reasons the pipe(2) syscall on MIPS has an unusual calling
44 * convention. It returns results in registers $v0 / $v1 which means there
45 * is no need for it to do verify the validity of a userspace pointer
46 * argument. Historically that used to be expensive in Linux. These days
47 * the performance advantage is negligible.
49 asmlinkage int sysm_pipe(nabi_no_regargs volatile struct pt_regs regs)
54 error = do_pipe_flags(fd, 0);
65 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
67 EXPORT_SYMBOL(shm_align_mask);
69 #define COLOUR_ALIGN(addr,pgoff) \
70 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
71 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
73 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
74 unsigned long len, unsigned long pgoff, unsigned long flags)
76 struct vm_area_struct * vmm;
78 unsigned long task_size;
80 task_size = STACK_TOP;
85 if (flags & MAP_FIXED) {
86 /* Even MAP_FIXED mappings must reside within task_size. */
87 if (task_size - len < addr)
91 * We do not accept a shared mapping if it would violate
92 * cache aliasing constraints.
94 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
100 if (filp || (flags & MAP_SHARED))
104 addr = COLOUR_ALIGN(addr, pgoff);
106 addr = PAGE_ALIGN(addr);
107 vmm = find_vma(current->mm, addr);
108 if (task_size - len >= addr &&
109 (!vmm || addr + len <= vmm->vm_start))
112 addr = TASK_UNMAPPED_BASE;
114 addr = COLOUR_ALIGN(addr, pgoff);
116 addr = PAGE_ALIGN(addr);
118 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
119 /* At this point: (!vmm || addr < vmm->vm_end). */
120 if (task_size - len < addr)
122 if (!vmm || addr + len <= vmm->vm_start)
126 addr = COLOUR_ALIGN(addr, pgoff);
130 /* common code for old and new mmaps */
131 static inline unsigned long
132 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
133 unsigned long flags, unsigned long fd, unsigned long pgoff)
135 unsigned long error = -EBADF;
136 struct file * file = NULL;
138 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
139 if (!(flags & MAP_ANONYMOUS)) {
145 down_write(¤t->mm->mmap_sem);
146 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
147 up_write(¤t->mm->mmap_sem);
155 asmlinkage unsigned long
156 old_mmap(unsigned long addr, unsigned long len, int prot,
157 int flags, int fd, off_t offset)
159 unsigned long result;
162 if (offset & ~PAGE_MASK)
165 result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
171 asmlinkage unsigned long
172 sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
173 unsigned long flags, unsigned long fd, unsigned long pgoff)
175 if (pgoff & (~PAGE_MASK >> 12))
178 return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
181 save_static_function(sys_fork);
182 static int __used noinline
183 _sys_fork(nabi_no_regargs struct pt_regs regs)
185 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
188 save_static_function(sys_clone);
189 static int __used noinline
190 _sys_clone(nabi_no_regargs struct pt_regs regs)
192 unsigned long clone_flags;
194 int __user *parent_tidptr, *child_tidptr;
196 clone_flags = regs.regs[4];
197 newsp = regs.regs[5];
199 newsp = regs.regs[29];
200 parent_tidptr = (int __user *) regs.regs[6];
202 /* We need to fetch the fifth argument off the stack. */
204 if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
205 int __user *__user *usp = (int __user *__user *) regs.regs[29];
206 if (regs.regs[2] == __NR_syscall) {
207 if (get_user (child_tidptr, &usp[5]))
210 else if (get_user (child_tidptr, &usp[4]))
214 child_tidptr = (int __user *) regs.regs[8];
216 return do_fork(clone_flags, newsp, ®s, 0,
217 parent_tidptr, child_tidptr);
221 * sys_execve() executes a new program.
223 asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
228 filename = getname((char __user *) (long)regs.regs[4]);
229 error = PTR_ERR(filename);
230 if (IS_ERR(filename))
232 error = do_execve(filename, (char __user *__user *) (long)regs.regs[5],
233 (char __user *__user *) (long)regs.regs[6], ®s);
241 * Compacrapability ...
243 asmlinkage int sys_uname(struct old_utsname __user * name)
245 if (name && !copy_to_user(name, utsname(), sizeof (*name)))
251 * Compacrapability ...
253 asmlinkage int sys_olduname(struct oldold_utsname __user * name)
259 if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
262 error = __copy_to_user(&name->sysname, &utsname()->sysname,
264 error -= __put_user(0, name->sysname + __OLD_UTS_LEN);
265 error -= __copy_to_user(&name->nodename, &utsname()->nodename,
267 error -= __put_user(0, name->nodename + __OLD_UTS_LEN);
268 error -= __copy_to_user(&name->release, &utsname()->release,
270 error -= __put_user(0, name->release + __OLD_UTS_LEN);
271 error -= __copy_to_user(&name->version, &utsname()->version,
273 error -= __put_user(0, name->version + __OLD_UTS_LEN);
274 error -= __copy_to_user(&name->machine, &utsname()->machine,
276 error = __put_user(0, name->machine + __OLD_UTS_LEN);
277 error = error ? -EFAULT : 0;
282 asmlinkage int sys_set_thread_area(unsigned long addr)
284 struct thread_info *ti = task_thread_info(current);
287 if (cpu_has_userlocal)
288 write_c0_userlocal(addr);
293 asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
296 case MIPS_ATOMIC_SET:
297 printk(KERN_CRIT "How did I get here?\n");
305 set_thread_flag(TIF_FIXADE);
307 clear_thread_flag(TIF_FIXADE);
309 set_thread_flag(TIF_LOGADE);
311 clear_thread_flag(TIF_FIXADE);
324 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
326 * This is really horribly ugly.
328 asmlinkage int sys_ipc(unsigned int call, int first, int second,
329 unsigned long third, void __user *ptr, long fifth)
333 version = call >> 16; /* hack for backward compatibility */
338 return sys_semtimedop(first, (struct sembuf __user *)ptr,
341 return sys_semtimedop(first, (struct sembuf __user *)ptr,
343 (const struct timespec __user *)fifth);
345 return sys_semget(first, second, third);
350 if (get_user(fourth.__pad, (void __user *__user *) ptr))
352 return sys_semctl(first, second, third, fourth);
356 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
361 struct ipc_kludge tmp;
365 if (copy_from_user(&tmp,
366 (struct ipc_kludge __user *) ptr,
369 return sys_msgrcv(first, tmp.msgp, second,
373 return sys_msgrcv(first,
374 (struct msgbuf __user *) ptr,
375 second, fifth, third);
378 return sys_msgget((key_t) first, second);
380 return sys_msgctl(first, second,
381 (struct msqid_ds __user *) ptr);
387 ret = do_shmat(first, (char __user *) ptr, second,
391 return put_user(raddr, (unsigned long __user *) third);
393 case 1: /* iBCS2 emulator entry point */
394 if (!segment_eq(get_fs(), get_ds()))
396 return do_shmat(first, (char __user *) ptr, second,
397 (unsigned long *) third);
400 return sys_shmdt((char __user *)ptr);
402 return sys_shmget(first, second, third);
404 return sys_shmctl(first, second,
405 (struct shmid_ds __user *) ptr);
412 * No implemented yet ...
414 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
420 * If we ever come here the user sp is bad. Zap the process right away.
421 * Due to the bad stack signaling wouldn't work.
423 asmlinkage void bad_stack(void)
429 * Do a system call from kernel instead of calling sys_execve so we
430 * end up with proper pt_regs.
432 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
434 register unsigned long __a0 asm("$4") = (unsigned long) filename;
435 register unsigned long __a1 asm("$5") = (unsigned long) argv;
436 register unsigned long __a2 asm("$6") = (unsigned long) envp;
437 register unsigned long __a3 asm("$7");
440 __asm__ volatile (" \n"
442 " li $2, %5 # __NR_execve \n"
446 : "=&r" (__v0), "=r" (__a3)
447 : "r" (__a0), "r" (__a1), "r" (__a2), "i" (__NR_execve)
448 : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",