This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / m32r / kernel / sys_m32r.c
1 /*
2  * linux/arch/m32r/kernel/sys_m32r.c
3  *
4  * This file contains various random system calls that
5  * have a non-standard calling sequence on the Linux/M32R platform.
6  *
7  * Taken from i386 version.
8  */
9
10 #include <linux/config.h>
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14 #include <linux/smp.h>
15 #include <linux/smp_lock.h>
16 #include <linux/sem.h>
17 #include <linux/msg.h>
18 #include <linux/shm.h>
19 #include <linux/stat.h>
20 #include <linux/syscalls.h>
21 #include <linux/mman.h>
22 #include <linux/file.h>
23 #include <linux/utsname.h>
24
25 #include <asm/uaccess.h>
26 #include <asm/cachectl.h>
27 #include <asm/cacheflush.h>
28 #include <asm/ipc.h>
29
30 /*
31  * sys_tas() - test-and-set
32  * linuxthreads testing version
33  */
34 #ifndef CONFIG_SMP
35 asmlinkage int sys_tas(int *addr)
36 {
37         int oldval;
38         unsigned long flags;
39
40         if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
41                 return -EFAULT;
42         local_irq_save(flags);
43         oldval = *addr;
44         *addr = 1;
45         local_irq_restore(flags);
46         return oldval;
47 }
48 #else /* CONFIG_SMP */
49 #include <linux/spinlock.h>
50
51 static spinlock_t tas_lock = SPIN_LOCK_UNLOCKED;
52
53 asmlinkage int sys_tas(int *addr)
54 {
55         int oldval;
56
57         if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
58                 return -EFAULT;
59
60         spin_lock(&tas_lock);
61         oldval = *addr;
62         *addr = 1;
63         spin_unlock(&tas_lock);
64
65         return oldval;
66 }
67 #endif /* CONFIG_SMP */
68
69 /*
70  * sys_pipe() is the normal C calling standard for creating
71  * a pipe. It's not the way Unix traditionally does this, though.
72  */
73 asmlinkage int
74 sys_pipe(unsigned long r0, unsigned long r1, unsigned long r2,
75         unsigned long r3, unsigned long r4, unsigned long r5,
76         unsigned long r6, struct pt_regs regs)
77 {
78         int fd[2];
79         int error;
80
81         error = do_pipe(fd);
82         if (!error) {
83                 if (copy_to_user((void *)r0, (void *)fd, 2*sizeof(int)))
84                         error = -EFAULT;
85         }
86         return error;
87 }
88
89 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
90         unsigned long prot, unsigned long flags,
91         unsigned long fd, unsigned long pgoff)
92 {
93         int error = -EBADF;
94         struct file *file = NULL;
95
96         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
97         if (!(flags & MAP_ANONYMOUS)) {
98                 file = fget(fd);
99                 if (!file)
100                         goto out;
101         }
102
103         down_write(&current->mm->mmap_sem);
104         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
105         up_write(&current->mm->mmap_sem);
106
107         if (file)
108                 fput(file);
109 out:
110         return error;
111 }
112
113 /*
114  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
115  *
116  * This is really horribly ugly.
117  */
118 asmlinkage int sys_ipc(uint call, int first, int second,
119                        int third, void __user *ptr, long fifth)
120 {
121         int version, ret;
122
123         version = call >> 16; /* hack for backward compatibility */
124         call &= 0xffff;
125
126         switch (call) {
127         case SEMOP:
128                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
129                                       second, NULL);
130         case SEMTIMEDOP:
131                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
132                                       second, (const struct timespec __user *)fifth);
133         case SEMGET:
134                 return sys_semget (first, second, third);
135         case SEMCTL: {
136                 union semun fourth;
137                 if (!ptr)
138                         return -EINVAL;
139                 if (get_user(fourth.__pad, (void __user * __user *) ptr))
140                         return -EFAULT;
141                 return sys_semctl (first, second, third, fourth);
142                 }
143
144         case MSGSND:
145                 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
146                                    second, third);
147         case MSGRCV:
148                 switch (version) {
149                 case 0: {
150                         struct ipc_kludge tmp;
151                         if (!ptr)
152                                 return -EINVAL;
153
154                         if (copy_from_user(&tmp,
155                                            (struct ipc_kludge __user *) ptr,
156                                            sizeof (tmp)))
157                                 return -EFAULT;
158                         return sys_msgrcv (first, tmp.msgp, second,
159                                            tmp.msgtyp, third);
160                         }
161                 default:
162                         return sys_msgrcv (first,
163                                            (struct msgbuf __user *) ptr,
164                                            second, fifth, third);
165                 }
166         case MSGGET:
167                 return sys_msgget ((key_t) first, second);
168         case MSGCTL:
169                 return sys_msgctl (first, second,
170                                    (struct msqid_ds __user *) ptr);
171         case SHMAT: {
172                 ulong raddr;
173
174                 if ((ret = verify_area(VERIFY_WRITE, (ulong __user *) third,
175                                       sizeof(ulong))))
176                         return ret;
177                 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
178                 if (ret)
179                         return ret;
180                 return put_user (raddr, (ulong __user *) third);
181                 }
182         case SHMDT:
183                 return sys_shmdt ((char __user *)ptr);
184         case SHMGET:
185                 return sys_shmget (first, second, third);
186         case SHMCTL:
187                 return sys_shmctl (first, second,
188                                    (struct shmid_ds __user *) ptr);
189         default:
190                 return -ENOSYS;
191         }
192 }
193
194 asmlinkage int sys_uname(struct old_utsname * name)
195 {
196         int err;
197         if (!name)
198                 return -EFAULT;
199         down_read(&uts_sem);
200         err=copy_to_user(name, &system_utsname, sizeof (*name));
201         up_read(&uts_sem);
202         return err?-EFAULT:0;
203 }
204
205 asmlinkage int sys_cacheflush(void *addr, int bytes, int cache)
206 {
207         /* This should flush more selectivly ...  */
208         _flush_cache_all();
209         return 0;
210 }
211
212 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
213 {
214         /* Not implemented yet. */
215         return -ENOSYS;
216 }
217