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/config.h>
11 #include <linux/a.out.h>
12 #include <linux/capability.h>
13 #include <linux/errno.h>
14 #include <linux/linkage.h>
16 #include <linux/smp.h>
17 #include <linux/smp_lock.h>
18 #include <linux/mman.h>
19 #include <linux/ptrace.h>
20 #include <linux/sched.h>
21 #include <linux/string.h>
22 #include <linux/syscalls.h>
23 #include <linux/file.h>
24 #include <linux/slab.h>
25 #include <linux/utsname.h>
26 #include <linux/unistd.h>
27 #include <linux/sem.h>
28 #include <linux/msg.h>
29 #include <linux/shm.h>
30 #include <linux/compiler.h>
31 #include <linux/module.h>
33 #include <asm/branch.h>
34 #include <asm/cachectl.h>
35 #include <asm/cacheflush.h>
37 #include <asm/asm-offsets.h>
38 #include <asm/signal.h>
40 #include <asm/shmparam.h>
41 #include <asm/sysmips.h>
42 #include <asm/uaccess.h>
44 asmlinkage int sys_pipe(nabi_no_regargs volatile struct pt_regs regs)
60 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
62 EXPORT_SYMBOL(shm_align_mask);
64 #define COLOUR_ALIGN(addr,pgoff) \
65 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
66 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
68 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
69 unsigned long len, unsigned long pgoff, unsigned long flags)
71 struct vm_area_struct * vmm;
73 unsigned long task_size;
75 task_size = STACK_TOP;
77 if (flags & MAP_FIXED) {
79 * We do not accept a shared mapping if it would violate
80 * cache aliasing constraints.
82 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
90 if (filp || (flags & MAP_SHARED))
94 addr = COLOUR_ALIGN(addr, pgoff);
96 addr = PAGE_ALIGN(addr);
97 vmm = find_vma(current->mm, addr);
98 if (task_size - len >= addr &&
99 (!vmm || addr + len <= vmm->vm_start))
102 addr = TASK_UNMAPPED_BASE;
104 addr = COLOUR_ALIGN(addr, pgoff);
106 addr = PAGE_ALIGN(addr);
108 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
109 /* At this point: (!vmm || addr < vmm->vm_end). */
110 if (task_size - len < addr)
112 if (!vmm || addr + len <= vmm->vm_start)
116 addr = COLOUR_ALIGN(addr, pgoff);
120 /* common code for old and new mmaps */
121 static inline unsigned long
122 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
123 unsigned long flags, unsigned long fd, unsigned long pgoff)
125 unsigned long error = -EBADF;
126 struct file * file = NULL;
128 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
129 if (!(flags & MAP_ANONYMOUS)) {
135 down_write(¤t->mm->mmap_sem);
136 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
137 up_write(¤t->mm->mmap_sem);
145 asmlinkage unsigned long
146 old_mmap(unsigned long addr, unsigned long len, int prot,
147 int flags, int fd, off_t offset)
149 unsigned long result;
152 if (offset & ~PAGE_MASK)
155 result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
161 asmlinkage unsigned long
162 sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
163 unsigned long flags, unsigned long fd, unsigned long pgoff)
165 if (pgoff & (~PAGE_MASK >> 12))
168 return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT-12));
171 save_static_function(sys_fork);
172 __attribute_used__ noinline static int
173 _sys_fork(nabi_no_regargs struct pt_regs regs)
175 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
178 save_static_function(sys_clone);
179 __attribute_used__ noinline static int
180 _sys_clone(nabi_no_regargs struct pt_regs regs)
182 unsigned long clone_flags;
184 int __user *parent_tidptr, *child_tidptr;
186 clone_flags = regs.regs[4];
187 newsp = regs.regs[5];
189 newsp = regs.regs[29];
190 parent_tidptr = (int __user *) regs.regs[6];
192 /* We need to fetch the fifth argument off the stack. */
194 if (clone_flags & (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)) {
195 int __user *__user *usp = (int __user *__user *) regs.regs[29];
196 if (regs.regs[2] == __NR_syscall) {
197 if (get_user (child_tidptr, &usp[5]))
200 else if (get_user (child_tidptr, &usp[4]))
204 child_tidptr = (int __user *) regs.regs[8];
206 return do_fork(clone_flags, newsp, ®s, 0,
207 parent_tidptr, child_tidptr);
211 * sys_execve() executes a new program.
213 asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
218 filename = getname((char __user *) (long)regs.regs[4]);
219 error = PTR_ERR(filename);
220 if (IS_ERR(filename))
222 error = do_execve(filename, (char __user *__user *) (long)regs.regs[5],
223 (char __user *__user *) (long)regs.regs[6], ®s);
231 * Compacrapability ...
233 asmlinkage int sys_uname(struct old_utsname __user * name)
235 if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
241 * Compacrapability ...
243 asmlinkage int sys_olduname(struct oldold_utsname __user * name)
249 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
252 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
253 error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
254 error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
255 error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
256 error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
257 error -= __put_user(0,name->release+__OLD_UTS_LEN);
258 error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
259 error -= __put_user(0,name->version+__OLD_UTS_LEN);
260 error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
261 error = __put_user(0,name->machine+__OLD_UTS_LEN);
262 error = error ? -EFAULT : 0;
267 void sys_set_thread_area(unsigned long addr)
269 struct thread_info *ti = task_thread_info(current);
273 /* If some future MIPS implementation has this register in hardware,
274 * we will need to update it here (and in context switches). */
277 asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
282 case MIPS_ATOMIC_SET:
283 printk(KERN_CRIT "How did I get here?\n");
287 tmp = current->thread.mflags & ~3;
288 current->thread.mflags = tmp | (arg1 & 3);
300 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
302 * This is really horribly ugly.
304 asmlinkage int sys_ipc (uint call, int first, int second,
305 unsigned long third, void __user *ptr, long fifth)
309 version = call >> 16; /* hack for backward compatibility */
314 return sys_semtimedop (first, (struct sembuf __user *)ptr,
317 return sys_semtimedop (first, (struct sembuf __user *)ptr,
319 (const struct timespec __user *)fifth);
321 return sys_semget (first, second, third);
326 if (get_user(fourth.__pad, (void __user *__user *) ptr))
328 return sys_semctl (first, second, third, fourth);
332 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
337 struct ipc_kludge tmp;
341 if (copy_from_user(&tmp,
342 (struct ipc_kludge __user *) ptr,
345 return sys_msgrcv (first, tmp.msgp, second,
349 return sys_msgrcv (first,
350 (struct msgbuf __user *) ptr,
351 second, fifth, third);
354 return sys_msgget ((key_t) first, second);
356 return sys_msgctl (first, second,
357 (struct msqid_ds __user *) ptr);
363 ret = do_shmat (first, (char __user *) ptr, second,
367 return put_user (raddr, (ulong __user *) third);
369 case 1: /* iBCS2 emulator entry point */
370 if (!segment_eq(get_fs(), get_ds()))
372 return do_shmat (first, (char __user *) ptr, second,
376 return sys_shmdt ((char __user *)ptr);
378 return sys_shmget (first, second, third);
380 return sys_shmctl (first, second,
381 (struct shmid_ds __user *) ptr);
388 * No implemented yet ...
390 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
396 * If we ever come here the user sp is bad. Zap the process right away.
397 * Due to the bad stack signaling wouldn't work.
399 asmlinkage void bad_stack(void)