Merge with 2.4.0-test3-pre7.
[linux-2.6/linux-mips.git] / arch / mips / kernel / sysmips.c
blob7d34f2d8cce57ba973f906a91bc8b13bccaf6824
1 /*
2 * MIPS specific syscalls
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
8 * Copyright (C) 1995, 1996, 1997, 2000 by Ralf Baechle
9 */
10 #include <linux/errno.h>
11 #include <linux/linkage.h>
12 #include <linux/mm.h>
13 #include <linux/smp.h>
14 #include <linux/smp_lock.h>
15 #include <linux/sched.h>
16 #include <linux/string.h>
17 #include <linux/utsname.h>
19 #include <asm/cachectl.h>
20 #include <asm/pgalloc.h>
21 #include <asm/sysmips.h>
22 #include <asm/uaccess.h>
25 * How long a hostname can we get from user space?
26 * -EFAULT if invalid area or too long
27 * 0 if ok
28 * >0 EFAULT after xx bytes
30 static inline int
31 get_max_hostname(unsigned long address)
33 struct vm_area_struct * vma;
35 vma = find_vma(current->mm, address);
36 if (!vma || vma->vm_start > address || !(vma->vm_flags & VM_READ))
37 return -EFAULT;
38 address = vma->vm_end - address;
39 if (address > PAGE_SIZE)
40 return 0;
41 if (vma->vm_next && vma->vm_next->vm_start == vma->vm_end &&
42 (vma->vm_next->vm_flags & VM_READ))
43 return 0;
44 return address;
47 asmlinkage int
48 sys_sysmips(int cmd, int arg1, int arg2, int arg3)
50 int *p;
51 char *name;
52 int flags, tmp, len, retval, errno;
54 switch(cmd) {
55 case SETNAME: {
56 char nodename[__NEW_UTS_LEN + 1];
58 if (!capable(CAP_SYS_ADMIN))
59 return -EPERM;
61 name = (char *) arg1;
63 len = strncpy_from_user(nodename, name, sizeof(nodename));
64 if (len < 0)
65 return -EFAULT;
67 down_write(&uts_sem);
68 strncpy(system_utsname.nodename, name, len);
69 up_write(&uts_sem);
70 system_utsname.nodename[len] = '\0';
71 return 0;
74 case MIPS_ATOMIC_SET: {
75 /* This is broken in case of page faults and SMP ...
76 Risc/OS faults after maximum 20 tries with EAGAIN. */
77 unsigned int tmp;
79 p = (int *) arg1;
80 errno = verify_area(VERIFY_WRITE, p, sizeof(*p));
81 if (errno)
82 return errno;
83 errno = 0;
84 save_and_cli(flags);
85 errno |= __get_user(tmp, p);
86 errno |= __put_user(arg2, p);
87 restore_flags(flags);
89 if (errno)
90 return tmp;
92 return tmp; /* This is broken ... */
95 case MIPS_FIXADE:
96 tmp = current->thread.mflags & ~3;
97 current->thread.mflags = tmp | (arg1 & 3);
98 retval = 0;
99 goto out;
101 case FLUSH_CACHE:
102 flush_cache_all();
103 retval = 0;
104 goto out;
106 case MIPS_RDNVRAM:
107 retval = -EIO;
108 goto out;
110 default:
111 retval = -EINVAL;
112 goto out;
115 out:
116 return retval;
120 * No implemented yet ...
122 asmlinkage int
123 sys_cachectl(char *addr, int nbytes, int op)
125 return -ENOSYS;
128 asmlinkage int sys_pause(void)
130 current->state = TASK_INTERRUPTIBLE;
131 schedule();
132 return -ERESTARTNOHAND;