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 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8 * Copyright (C) 2001 MIPS Technologies, Inc.
10 #include <linux/errno.h>
11 #include <linux/linkage.h>
13 #include <linux/smp.h>
14 #include <linux/smp_lock.h>
15 #include <linux/mman.h>
16 #include <linux/ptrace.h>
17 #include <linux/sched.h>
18 #include <linux/string.h>
19 #include <linux/syscalls.h>
20 #include <linux/file.h>
21 #include <linux/slab.h>
22 #include <linux/utsname.h>
23 #include <linux/unistd.h>
24 #include <linux/sem.h>
25 #include <linux/msg.h>
26 #include <linux/shm.h>
28 #include <asm/branch.h>
29 #include <asm/cachectl.h>
30 #include <asm/cacheflush.h>
32 #include <asm/offset.h>
33 #include <asm/signal.h>
35 #include <asm/shmparam.h>
36 #include <asm/sysmips.h>
37 #include <asm/uaccess.h>
39 asmlinkage int sys_pipe(nabi_no_regargs volatile struct pt_regs regs)
55 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
57 #define COLOUR_ALIGN(addr,pgoff) \
58 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
59 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
61 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
62 unsigned long len, unsigned long pgoff, unsigned long flags)
64 struct vm_area_struct * vmm;
66 unsigned long task_size;
69 task_size = TASK_SIZE;
71 task_size = (current->thread.mflags & MF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE;
74 if (flags & MAP_FIXED) {
76 * We do not accept a shared mapping if it would violate
77 * cache aliasing constraints.
79 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
87 if (filp || (flags & MAP_SHARED))
91 addr = COLOUR_ALIGN(addr, pgoff);
93 addr = PAGE_ALIGN(addr);
94 vmm = find_vma(current->mm, addr);
95 if (task_size - len >= addr &&
96 (!vmm || addr + len <= vmm->vm_start))
99 addr = TASK_UNMAPPED_BASE;
101 addr = COLOUR_ALIGN(addr, pgoff);
103 addr = PAGE_ALIGN(addr);
105 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
106 /* At this point: (!vmm || addr < vmm->vm_end). */
107 if (task_size - len < addr)
109 if (!vmm || addr + len <= vmm->vm_start)
113 addr = COLOUR_ALIGN(addr, pgoff);
117 /* common code for old and new mmaps */
119 do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
120 unsigned long flags, unsigned long fd, unsigned long pgoff)
122 unsigned long error = -EBADF;
123 struct file * file = NULL;
125 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
126 if (!(flags & MAP_ANONYMOUS)) {
132 down_write(¤t->mm->mmap_sem);
133 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
134 up_write(¤t->mm->mmap_sem);
142 asmlinkage unsigned long old_mmap(unsigned long addr, size_t len, int prot,
143 int flags, int fd, off_t offset)
145 unsigned long result;
148 if (offset & ~PAGE_MASK)
151 result = do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
158 sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
159 unsigned long flags, unsigned long fd, unsigned long pgoff)
161 return do_mmap2(addr, len, prot, flags, fd, pgoff);
164 save_static_function(sys_fork);
165 static_unused int _sys_fork(nabi_no_regargs struct pt_regs regs)
167 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
170 save_static_function(sys_clone);
171 static_unused int _sys_clone(nabi_no_regargs struct pt_regs regs)
173 unsigned long clone_flags;
175 int *parent_tidptr, *child_tidptr;
177 clone_flags = regs.regs[4];
178 newsp = regs.regs[5];
180 newsp = regs.regs[29];
181 parent_tidptr = (int *) regs.regs[6];
182 child_tidptr = (int *) regs.regs[7];
183 return do_fork(clone_flags & ~CLONE_IDLETASK, newsp, ®s, 0,
184 parent_tidptr, child_tidptr);
188 * sys_execve() executes a new program.
190 asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
195 filename = getname((char *) (long)regs.regs[4]);
196 error = PTR_ERR(filename);
197 if (IS_ERR(filename))
199 error = do_execve(filename, (char **) (long)regs.regs[5],
200 (char **) (long)regs.regs[6], ®s);
208 * Compacrapability ...
210 asmlinkage int sys_uname(struct old_utsname * name)
212 if (name && !copy_to_user(name, vx_new_utsname(), sizeof (*name)))
218 * Compacrapability ...
220 asmlinkage int sys_olduname(struct oldold_utsname * name)
223 struct new_utsname *ptr;
227 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
230 ptr = vx_new_utsname();
231 error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
232 error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
233 error -= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
234 error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
235 error -= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
236 error -= __put_user(0,name->release+__OLD_UTS_LEN);
237 error -= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
238 error -= __put_user(0,name->version+__OLD_UTS_LEN);
239 error -= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
240 error = __put_user(0,name->machine+__OLD_UTS_LEN);
241 error = error ? -EFAULT : 0;
246 asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
253 char nodename[__NEW_UTS_LEN + 1];
255 if (!capable(CAP_SYS_ADMIN))
258 name = (char *) arg1;
260 len = strncpy_from_user(nodename, name, __NEW_UTS_LEN);
264 down_write(&uts_sem);
265 strncpy(vx_new_uts(nodename), nodename, len);
266 nodename[__NEW_UTS_LEN] = '\0';
267 strlcpy(vx_new_uts(nodename), nodename,
268 sizeof(vx_new_uts(nodename)));
273 case MIPS_ATOMIC_SET:
274 printk(KERN_CRIT "How did I get here?\n");
278 tmp = current->thread.mflags & ~3;
279 current->thread.mflags = tmp | (arg1 & 3);
294 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
296 * This is really horribly ugly.
298 asmlinkage int sys_ipc (uint call, int first, int second,
299 unsigned long third, void *ptr, long fifth)
303 version = call >> 16; /* hack for backward compatibility */
308 return sys_semtimedop (first, (struct sembuf *)ptr, second,
311 return sys_semtimedop (first, (struct sembuf *)ptr, second,
312 (const struct timespec __user *)fifth);
314 return sys_semget (first, second, third);
319 if (get_user(fourth.__pad, (void **) ptr))
321 return sys_semctl (first, second, third, fourth);
325 return sys_msgsnd (first, (struct msgbuf *) ptr,
330 struct ipc_kludge tmp;
334 if (copy_from_user(&tmp,
335 (struct ipc_kludge *) ptr,
338 return sys_msgrcv (first, tmp.msgp, second,
342 return sys_msgrcv (first,
343 (struct msgbuf *) ptr,
344 second, fifth, third);
347 return sys_msgget ((key_t) first, second);
349 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
355 ret = do_shmat (first, (char *) ptr, second, &raddr);
358 return put_user (raddr, (ulong *) third);
360 case 1: /* iBCS2 emulator entry point */
361 if (!segment_eq(get_fs(), get_ds()))
363 return do_shmat (first, (char *) ptr, second, (ulong *) third);
366 return sys_shmdt ((char *)ptr);
368 return sys_shmget (first, second, third);
370 return sys_shmctl (first, second,
371 (struct shmid_ds *) ptr);
378 * Native ABI that is O32 or N64 version
380 asmlinkage long sys_shmat(int shmid, char __user *shmaddr,
381 int shmflg, unsigned long *addr)
386 err = do_shmat(shmid, shmaddr, shmflg, &raddr);
390 return put_user(raddr, addr);
394 * No implemented yet ...
396 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
402 * If we ever come here the user sp is bad. Zap the process right away.
403 * Due to the bad stack signaling wouldn't work.
405 asmlinkage void bad_stack(void)