import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / mips / kernel / sysmips.c
1 /*
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
4  * for more details.
5  *
6  * Copyright (C) 1995, 1996, 1997, 2000, 2001 by Ralf Baechle
7  * Copyright (C) 2001 MIPS Technologies, Inc.
8  */
9 #include <linux/errno.h>
10 #include <linux/linkage.h>
11 #include <linux/mm.h>
12 #include <linux/smp.h>
13 #include <linux/smp_lock.h>
14 #include <linux/sched.h>
15 #include <linux/string.h>
16 #include <linux/utsname.h>
17
18 #include <asm/cachectl.h>
19 #include <asm/pgalloc.h>
20 #include <asm/sysmips.h>
21 #include <asm/uaccess.h>
22
23 extern asmlinkage void syscall_trace(void);
24
25 /*
26  * How long a hostname can we get from user space?
27  *  -EFAULT if invalid area or too long
28  *  0 if ok
29  *  >0 EFAULT after xx bytes
30  */
31 static inline int
32 get_max_hostname(unsigned long address)
33 {
34         struct vm_area_struct * vma;
35
36         vma = find_vma(current->mm, address);
37         if (!vma || vma->vm_start > address || !(vma->vm_flags & VM_READ))
38                 return -EFAULT;
39         address = vma->vm_end - address;
40         if (address > PAGE_SIZE)
41                 return 0;
42         if (vma->vm_next && vma->vm_next->vm_start == vma->vm_end &&
43            (vma->vm_next->vm_flags & VM_READ))
44                 return 0;
45         return address;
46 }
47
48 asmlinkage int
49 _sys_sysmips(int cmd, int arg1, int arg2, int arg3)
50 {
51         char    *name;
52         int     tmp, len, retval;
53
54         switch(cmd) {
55         case SETNAME: {
56                 char nodename[__NEW_UTS_LEN + 1];
57
58                 if (!capable(CAP_SYS_ADMIN))
59                         return -EPERM;
60
61                 name = (char *) arg1;
62
63                 len = strncpy_from_user(nodename, name, sizeof(nodename));
64                 if (len < 0)
65                         return -EFAULT;
66
67                 down_write(&uts_sem);
68                 strncpy(system_utsname.nodename, nodename, len);
69                 system_utsname.nodename[len] = '\0';
70                 up_write(&uts_sem);
71                 return 0;
72         }
73
74         case MIPS_ATOMIC_SET:
75                 printk(KERN_CRIT "How did I get here?\n");
76                 retval = -EINVAL;
77                 goto out;
78
79         case MIPS_FIXADE:
80                 tmp = current->thread.mflags & ~3;
81                 current->thread.mflags = tmp | (arg1 & 3);
82                 retval = 0;
83                 goto out;
84
85         case FLUSH_CACHE:
86                 __flush_cache_all();
87                 retval = 0;
88                 goto out;
89
90         case MIPS_RDNVRAM:
91                 retval = -EIO;
92                 goto out;
93
94         default:
95                 retval = -EINVAL;
96                 goto out;
97         }
98
99 out:
100         return retval;
101 }
102
103 /*
104  * No implemented yet ...
105  */
106 asmlinkage int
107 sys_cachectl(char *addr, int nbytes, int op)
108 {
109         return -ENOSYS;
110 }
111
112 asmlinkage int sys_pause(void)
113 {
114         current->state = TASK_INTERRUPTIBLE;
115         schedule();
116         return -ERESTARTNOHAND;
117 }