Merge ../linus
[deliverable/linux.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 if (!oldval)
45 *addr = 1;
46 local_irq_restore(flags);
47 return oldval;
48 }
49 #else /* CONFIG_SMP */
50 #include <linux/spinlock.h>
51
52 static DEFINE_SPINLOCK(tas_lock);
53
54 asmlinkage int sys_tas(int *addr)
55 {
56 int oldval;
57
58 if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
59 return -EFAULT;
60
61 _raw_spin_lock(&tas_lock);
62 oldval = *addr;
63 if (!oldval)
64 *addr = 1;
65 _raw_spin_unlock(&tas_lock);
66
67 return oldval;
68 }
69 #endif /* CONFIG_SMP */
70
71 /*
72 * sys_pipe() is the normal C calling standard for creating
73 * a pipe. It's not the way Unix traditionally does this, though.
74 */
75 asmlinkage int
76 sys_pipe(unsigned long r0, unsigned long r1, unsigned long r2,
77 unsigned long r3, unsigned long r4, unsigned long r5,
78 unsigned long r6, struct pt_regs regs)
79 {
80 int fd[2];
81 int error;
82
83 error = do_pipe(fd);
84 if (!error) {
85 if (copy_to_user((void *)r0, (void *)fd, 2*sizeof(int)))
86 error = -EFAULT;
87 }
88 return error;
89 }
90
91 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
92 unsigned long prot, unsigned long flags,
93 unsigned long fd, unsigned long pgoff)
94 {
95 int error = -EBADF;
96 struct file *file = NULL;
97
98 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
99 if (!(flags & MAP_ANONYMOUS)) {
100 file = fget(fd);
101 if (!file)
102 goto out;
103 }
104
105 down_write(&current->mm->mmap_sem);
106 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
107 up_write(&current->mm->mmap_sem);
108
109 if (file)
110 fput(file);
111 out:
112 return error;
113 }
114
115 /*
116 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
117 *
118 * This is really horribly ugly.
119 */
120 asmlinkage int sys_ipc(uint call, int first, int second,
121 int third, void __user *ptr, long fifth)
122 {
123 int version, ret;
124
125 version = call >> 16; /* hack for backward compatibility */
126 call &= 0xffff;
127
128 switch (call) {
129 case SEMOP:
130 return sys_semtimedop(first, (struct sembuf __user *)ptr,
131 second, NULL);
132 case SEMTIMEDOP:
133 return sys_semtimedop(first, (struct sembuf __user *)ptr,
134 second, (const struct timespec __user *)fifth);
135 case SEMGET:
136 return sys_semget (first, second, third);
137 case SEMCTL: {
138 union semun fourth;
139 if (!ptr)
140 return -EINVAL;
141 if (get_user(fourth.__pad, (void __user * __user *) ptr))
142 return -EFAULT;
143 return sys_semctl (first, second, third, fourth);
144 }
145
146 case MSGSND:
147 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
148 second, third);
149 case MSGRCV:
150 switch (version) {
151 case 0: {
152 struct ipc_kludge tmp;
153 if (!ptr)
154 return -EINVAL;
155
156 if (copy_from_user(&tmp,
157 (struct ipc_kludge __user *) ptr,
158 sizeof (tmp)))
159 return -EFAULT;
160 return sys_msgrcv (first, tmp.msgp, second,
161 tmp.msgtyp, third);
162 }
163 default:
164 return sys_msgrcv (first,
165 (struct msgbuf __user *) ptr,
166 second, fifth, third);
167 }
168 case MSGGET:
169 return sys_msgget ((key_t) first, second);
170 case MSGCTL:
171 return sys_msgctl (first, second,
172 (struct msqid_ds __user *) ptr);
173 case SHMAT: {
174 ulong raddr;
175
176 if (!access_ok(VERIFY_WRITE, (ulong __user *) third,
177 sizeof(ulong)))
178 return -EFAULT;
179 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
180 if (ret)
181 return ret;
182 return put_user (raddr, (ulong __user *) third);
183 }
184 case SHMDT:
185 return sys_shmdt ((char __user *)ptr);
186 case SHMGET:
187 return sys_shmget (first, second, third);
188 case SHMCTL:
189 return sys_shmctl (first, second,
190 (struct shmid_ds __user *) ptr);
191 default:
192 return -ENOSYS;
193 }
194 }
195
196 asmlinkage int sys_uname(struct old_utsname * name)
197 {
198 int err;
199 if (!name)
200 return -EFAULT;
201 down_read(&uts_sem);
202 err=copy_to_user(name, &system_utsname, sizeof (*name));
203 up_read(&uts_sem);
204 return err?-EFAULT:0;
205 }
206
207 asmlinkage int sys_cacheflush(void *addr, int bytes, int cache)
208 {
209 /* This should flush more selectivly ... */
210 _flush_cache_all();
211 return 0;
212 }
213
214 asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
215 {
216 /* Not implemented yet. */
217 return -ENOSYS;
218 }
219
This page took 0.037026 seconds and 6 git commands to generate.