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, &system_utsname, sizeof (*name)))
218 * Compacrapability ...
220 asmlinkage int sys_olduname(struct oldold_utsname * name)
226 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
229 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
230 error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
231 error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
232 error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
233 error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
234 error -= __put_user(0,name->release+__OLD_UTS_LEN);
235 error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
236 error -= __put_user(0,name->version+__OLD_UTS_LEN);
237 error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
238 error = __put_user(0,name->machine+__OLD_UTS_LEN);
239 error = error ? -EFAULT : 0;
244 asmlinkage int _sys_sysmips(int cmd, long arg1, int arg2, int arg3)
251 char nodename[__NEW_UTS_LEN + 1];
253 if (!capable(CAP_SYS_ADMIN))
256 name = (char *) arg1;
258 len = strncpy_from_user(nodename, name, __NEW_UTS_LEN);
262 down_write(&uts_sem);
263 strncpy(system_utsname.nodename, nodename, len);
264 nodename[__NEW_UTS_LEN] = '\0';
265 strlcpy(system_utsname.nodename, nodename,
266 sizeof(system_utsname.nodename));
271 case MIPS_ATOMIC_SET:
272 printk(KERN_CRIT "How did I get here?\n");
276 tmp = current->thread.mflags & ~3;
277 current->thread.mflags = tmp | (arg1 & 3);
292 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
294 * This is really horribly ugly.
296 asmlinkage int sys_ipc (uint call, int first, int second,
297 unsigned long third, void *ptr, long fifth)
301 version = call >> 16; /* hack for backward compatibility */
306 return sys_semtimedop (first, (struct sembuf *)ptr, second,
309 return sys_semtimedop (first, (struct sembuf *)ptr, second,
310 (const struct timespec __user *)fifth);
312 return sys_semget (first, second, third);
317 if (get_user(fourth.__pad, (void **) ptr))
319 return sys_semctl (first, second, third, fourth);
323 return sys_msgsnd (first, (struct msgbuf *) ptr,
328 struct ipc_kludge tmp;
332 if (copy_from_user(&tmp,
333 (struct ipc_kludge *) ptr,
336 return sys_msgrcv (first, tmp.msgp, second,
340 return sys_msgrcv (first,
341 (struct msgbuf *) ptr,
342 second, fifth, third);
345 return sys_msgget ((key_t) first, second);
347 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
353 ret = do_shmat (first, (char *) ptr, second, &raddr);
356 return put_user (raddr, (ulong *) third);
358 case 1: /* iBCS2 emulator entry point */
359 if (!segment_eq(get_fs(), get_ds()))
361 return do_shmat (first, (char *) ptr, second, (ulong *) third);
364 return sys_shmdt ((char *)ptr);
366 return sys_shmget (first, second, third);
368 return sys_shmctl (first, second,
369 (struct shmid_ds *) ptr);
376 * Native ABI that is O32 or N64 version
378 asmlinkage long sys_shmat(int shmid, char __user *shmaddr,
379 int shmflg, unsigned long *addr)
384 err = do_shmat(shmid, shmaddr, shmflg, &raddr);
388 return put_user(raddr, addr);
392 * No implemented yet ...
394 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
400 * If we ever come here the user sp is bad. Zap the process right away.
401 * Due to the bad stack signaling wouldn't work.
403 asmlinkage void bad_stack(void)