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 - 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/sched.h>
17 #include <linux/string.h>
18 #include <linux/file.h>
19 #include <linux/utsname.h>
20 #include <linux/unistd.h>
21 #include <linux/sem.h>
22 #include <linux/msg.h>
23 #include <linux/shm.h>
24 #include <linux/slab.h>
26 #include <asm/cachectl.h>
27 #include <asm/offset.h>
28 #include <asm/pgalloc.h>
29 #include <asm/ptrace.h>
30 #include <asm/signal.h>
31 #include <asm/stackframe.h>
32 #include <asm/sysmips.h>
33 #include <asm/uaccess.h>
35 extern asmlinkage void syscall_trace(void);
37 asmlinkage int sys_pipe(abi64_no_regargs, struct pt_regs regs)
53 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
55 #define COLOUR_ALIGN(addr,pgoff) \
56 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
57 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
59 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
60 unsigned long len, unsigned long pgoff, unsigned long flags)
62 struct vm_area_struct * vmm;
65 if (flags & MAP_FIXED) {
67 * We do not accept a shared mapping if it would violate
68 * cache aliasing constraints.
70 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
78 if (filp || (flags & MAP_SHARED))
82 addr = COLOUR_ALIGN(addr, pgoff);
84 addr = PAGE_ALIGN(addr);
85 vmm = find_vma(current->mm, addr);
86 if (TASK_SIZE - len >= addr &&
87 (!vmm || addr + len <= vmm->vm_start))
90 addr = TASK_UNMAPPED_BASE;
92 addr = COLOUR_ALIGN(addr, pgoff);
94 addr = PAGE_ALIGN(addr);
96 for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
97 /* At this point: (!vmm || addr < vmm->vm_end). */
98 if (TASK_SIZE - len < addr)
100 if (!vmm || addr + len <= vmm->vm_start)
104 addr = COLOUR_ALIGN(addr, pgoff);
108 asmlinkage unsigned long
109 sys_mmap(unsigned long addr, size_t len, unsigned long prot,
110 unsigned long flags, unsigned long fd, off_t offset)
112 struct file * file = NULL;
116 if (offset & ~PAGE_MASK)
119 if (!(flags & MAP_ANONYMOUS)) {
125 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
127 down_write(¤t->mm->mmap_sem);
128 error = do_mmap(file, addr, len, prot, flags, offset);
129 up_write(¤t->mm->mmap_sem);
137 asmlinkage int sys_fork(abi64_no_regargs, struct pt_regs regs)
140 return do_fork(SIGCHLD, regs.regs[29], ®s, 0, NULL, NULL);
143 asmlinkage int sys_clone(abi64_no_regargs, struct pt_regs regs)
145 unsigned long clone_flags;
147 int *parent_tidptr, *child_tidptr;
150 clone_flags = regs.regs[4];
151 newsp = regs.regs[5];
153 newsp = regs.regs[29];
154 parent_tidptr = (int *) regs.regs[6];
155 child_tidptr = (int *) regs.regs[7];
156 return do_fork(clone_flags & ~CLONE_IDLETASK, newsp, ®s, 0,
157 parent_tidptr, child_tidptr);
161 * sys_execve() executes a new program.
163 asmlinkage int sys_execve(abi64_no_regargs, struct pt_regs regs)
168 filename = getname((char *) (long)regs.regs[4]);
169 error = PTR_ERR(filename);
170 if (IS_ERR(filename))
172 error = do_execve(filename, (char **) (long)regs.regs[5],
173 (char **) (long)regs.regs[6], ®s);
181 * Do the indirect syscall syscall.
183 * XXX This is borken.
185 asmlinkage int sys_syscall(abi64_no_regargs, struct pt_regs regs)
190 asmlinkage int sys_sysmips(int cmd, long arg1, int arg2, int arg3)
197 char nodename[__NEW_UTS_LEN + 1];
199 if (!capable(CAP_SYS_ADMIN))
202 name = (char *) arg1;
204 len = strncpy_from_user(nodename, name, __NEW_UTS_LEN);
208 down_write(&uts_sem);
209 strncpy(system_utsname.nodename, nodename, len);
210 nodename[__NEW_UTS_LEN] = '\0';
211 strlcpy(system_utsname.nodename, nodename,
212 sizeof(system_utsname.nodename));
217 case MIPS_ATOMIC_SET:
218 printk(KERN_CRIT "How did I get here?\n");
222 tmp = current->thread.mflags & ~3;
223 current->thread.mflags = tmp | (arg1 & 3);
238 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
240 * This is really horribly ugly.
242 asmlinkage int sys_ipc (uint call, int first, int second,
243 unsigned long third, void *ptr, long fifth)
247 version = call >> 16; /* hack for backward compatibility */
252 return sys_semop (first, (struct sembuf *)ptr, second);
254 return sys_semget (first, second, third);
259 if (get_user(fourth.__pad, (void **) ptr))
261 return sys_semctl (first, second, third, fourth);
265 return sys_msgsnd (first, (struct msgbuf *) ptr,
270 struct ipc_kludge tmp;
274 if (copy_from_user(&tmp,
275 (struct ipc_kludge *) ptr,
278 return sys_msgrcv (first, tmp.msgp, second,
282 return sys_msgrcv (first,
283 (struct msgbuf *) ptr,
284 second, fifth, third);
287 return sys_msgget ((key_t) first, second);
289 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
295 ret = sys_shmat (first, (char *) ptr, second, &raddr);
298 return put_user (raddr, (ulong *) third);
300 case 1: /* iBCS2 emulator entry point */
301 if (!segment_eq(get_fs(), get_ds()))
303 return sys_shmat (first, (char *) ptr, second, (ulong *) third);
306 return sys_shmdt ((char *)ptr);
308 return sys_shmget (first, second, third);
310 return sys_shmctl (first, second,
311 (struct shmid_ds *) ptr);
318 * No implemented yet ...
320 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
326 * If we ever come here the user sp is bad. Zap the process right away.
327 * Due to the bad stack signaling wouldn't work.
329 asmlinkage void bad_stack(void)