]>
Commit | Line | Data |
---|---|---|
5526b7e4 | 1 | /* linux/arch/sparc/kernel/sys_sparc.c |
1da177e4 LT |
2 | * |
3 | * This file contains various random system calls that | |
4 | * have a non-standard calling sequence on the Linux/sparc | |
5 | * platform. | |
6 | */ | |
7 | ||
8 | #include <linux/errno.h> | |
9 | #include <linux/types.h> | |
10 | #include <linux/sched.h> | |
11 | #include <linux/mm.h> | |
12 | #include <linux/fs.h> | |
13 | #include <linux/file.h> | |
14 | #include <linux/sem.h> | |
15 | #include <linux/msg.h> | |
16 | #include <linux/shm.h> | |
17 | #include <linux/stat.h> | |
18 | #include <linux/syscalls.h> | |
19 | #include <linux/mman.h> | |
20 | #include <linux/utsname.h> | |
21 | #include <linux/smp.h> | |
22 | #include <linux/smp_lock.h> | |
cba4fbbf | 23 | #include <linux/ipc.h> |
1da177e4 LT |
24 | |
25 | #include <asm/uaccess.h> | |
fe74290d | 26 | #include <asm/unistd.h> |
1da177e4 LT |
27 | |
28 | /* #define DEBUG_UNIMP_SYSCALL */ | |
29 | ||
30 | /* XXX Make this per-binary type, this way we can detect the type of | |
31 | * XXX a binary. Every Sparc executable calls this very early on. | |
32 | */ | |
33 | asmlinkage unsigned long sys_getpagesize(void) | |
34 | { | |
35 | return PAGE_SIZE; /* Possibly older binaries want 8192 on sun4's? */ | |
36 | } | |
37 | ||
38 | #define COLOUR_ALIGN(addr) (((addr)+SHMLBA-1)&~(SHMLBA-1)) | |
39 | ||
40 | unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) | |
41 | { | |
42 | struct vm_area_struct * vmm; | |
43 | ||
44 | if (flags & MAP_FIXED) { | |
45 | /* We do not accept a shared mapping if it would violate | |
46 | * cache aliasing constraints. | |
47 | */ | |
48 | if ((flags & MAP_SHARED) && (addr & (SHMLBA - 1))) | |
49 | return -EINVAL; | |
50 | return addr; | |
51 | } | |
52 | ||
53 | /* See asm-sparc/uaccess.h */ | |
54 | if (len > TASK_SIZE - PAGE_SIZE) | |
55 | return -ENOMEM; | |
5110bd21 | 56 | if (ARCH_SUN4C && len > 0x20000000) |
1da177e4 LT |
57 | return -ENOMEM; |
58 | if (!addr) | |
59 | addr = TASK_UNMAPPED_BASE; | |
60 | ||
61 | if (flags & MAP_SHARED) | |
62 | addr = COLOUR_ALIGN(addr); | |
63 | else | |
64 | addr = PAGE_ALIGN(addr); | |
65 | ||
66 | for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) { | |
67 | /* At this point: (!vmm || addr < vmm->vm_end). */ | |
5110bd21 | 68 | if (ARCH_SUN4C && addr < 0xe0000000 && 0x20000000 - len < addr) { |
1da177e4 LT |
69 | addr = PAGE_OFFSET; |
70 | vmm = find_vma(current->mm, PAGE_OFFSET); | |
71 | } | |
72 | if (TASK_SIZE - PAGE_SIZE - len < addr) | |
73 | return -ENOMEM; | |
74 | if (!vmm || addr + len <= vmm->vm_start) | |
75 | return addr; | |
76 | addr = vmm->vm_end; | |
77 | if (flags & MAP_SHARED) | |
78 | addr = COLOUR_ALIGN(addr); | |
79 | } | |
80 | } | |
81 | ||
1da177e4 LT |
82 | /* |
83 | * sys_pipe() is the normal C calling standard for creating | |
84 | * a pipe. It's not the way unix traditionally does this, though. | |
85 | */ | |
86 | asmlinkage int sparc_pipe(struct pt_regs *regs) | |
87 | { | |
88 | int fd[2]; | |
89 | int error; | |
90 | ||
ed8cae8b | 91 | error = do_pipe_flags(fd, 0); |
1da177e4 LT |
92 | if (error) |
93 | goto out; | |
94 | regs->u_regs[UREG_I1] = fd[1]; | |
95 | error = fd[0]; | |
96 | out: | |
97 | return error; | |
98 | } | |
99 | ||
100 | /* | |
101 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. | |
102 | * | |
103 | * This is really horribly ugly. | |
104 | */ | |
105 | ||
106 | asmlinkage int sys_ipc (uint call, int first, int second, int third, void __user *ptr, long fifth) | |
107 | { | |
108 | int version, err; | |
109 | ||
110 | version = call >> 16; /* hack for backward compatibility */ | |
111 | call &= 0xffff; | |
112 | ||
113 | if (call <= SEMCTL) | |
114 | switch (call) { | |
115 | case SEMOP: | |
116 | err = sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL); | |
117 | goto out; | |
118 | case SEMTIMEDOP: | |
119 | err = sys_semtimedop (first, (struct sembuf __user *)ptr, second, (const struct timespec __user *) fifth); | |
120 | goto out; | |
121 | case SEMGET: | |
122 | err = sys_semget (first, second, third); | |
123 | goto out; | |
124 | case SEMCTL: { | |
125 | union semun fourth; | |
126 | err = -EINVAL; | |
127 | if (!ptr) | |
128 | goto out; | |
129 | err = -EFAULT; | |
130 | if (get_user(fourth.__pad, | |
131 | (void __user * __user *)ptr)) | |
132 | goto out; | |
133 | err = sys_semctl (first, second, third, fourth); | |
134 | goto out; | |
135 | } | |
136 | default: | |
137 | err = -ENOSYS; | |
138 | goto out; | |
139 | } | |
140 | if (call <= MSGCTL) | |
141 | switch (call) { | |
142 | case MSGSND: | |
143 | err = sys_msgsnd (first, (struct msgbuf __user *) ptr, | |
144 | second, third); | |
145 | goto out; | |
146 | case MSGRCV: | |
147 | switch (version) { | |
148 | case 0: { | |
149 | struct ipc_kludge tmp; | |
150 | err = -EINVAL; | |
151 | if (!ptr) | |
152 | goto out; | |
153 | err = -EFAULT; | |
154 | if (copy_from_user(&tmp, (struct ipc_kludge __user *) ptr, sizeof (tmp))) | |
155 | goto out; | |
156 | err = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, third); | |
157 | goto out; | |
158 | } | |
159 | case 1: default: | |
160 | err = sys_msgrcv (first, | |
161 | (struct msgbuf __user *) ptr, | |
162 | second, fifth, third); | |
163 | goto out; | |
164 | } | |
165 | case MSGGET: | |
166 | err = sys_msgget ((key_t) first, second); | |
167 | goto out; | |
168 | case MSGCTL: | |
169 | err = sys_msgctl (first, second, (struct msqid_ds __user *) ptr); | |
170 | goto out; | |
171 | default: | |
172 | err = -ENOSYS; | |
173 | goto out; | |
174 | } | |
175 | if (call <= SHMCTL) | |
176 | switch (call) { | |
177 | case SHMAT: | |
178 | switch (version) { | |
179 | case 0: default: { | |
180 | ulong raddr; | |
181 | err = do_shmat (first, (char __user *) ptr, second, &raddr); | |
182 | if (err) | |
183 | goto out; | |
184 | err = -EFAULT; | |
185 | if (put_user (raddr, (ulong __user *) third)) | |
186 | goto out; | |
187 | err = 0; | |
188 | goto out; | |
189 | } | |
190 | case 1: /* iBCS2 emulator entry point */ | |
191 | err = -EINVAL; | |
192 | goto out; | |
193 | } | |
194 | case SHMDT: | |
195 | err = sys_shmdt ((char __user *)ptr); | |
196 | goto out; | |
197 | case SHMGET: | |
198 | err = sys_shmget (first, second, third); | |
199 | goto out; | |
200 | case SHMCTL: | |
201 | err = sys_shmctl (first, second, (struct shmid_ds __user *) ptr); | |
202 | goto out; | |
203 | default: | |
204 | err = -ENOSYS; | |
205 | goto out; | |
206 | } | |
207 | else | |
208 | err = -ENOSYS; | |
209 | out: | |
210 | return err; | |
211 | } | |
212 | ||
94d149c3 | 213 | int sparc_mmap_check(unsigned long addr, unsigned long len) |
3a459756 | 214 | { |
5110bd21 | 215 | if (ARCH_SUN4C && |
3a459756 | 216 | (len > 0x20000000 || |
58163393 | 217 | (addr < 0xe0000000 && addr + len > 0x20000000))) |
3a459756 KK |
218 | return -EINVAL; |
219 | ||
220 | /* See asm-sparc/uaccess.h */ | |
221 | if (len > TASK_SIZE - PAGE_SIZE || addr + len > TASK_SIZE - PAGE_SIZE) | |
222 | return -EINVAL; | |
223 | ||
224 | return 0; | |
225 | } | |
226 | ||
1da177e4 | 227 | /* Linux version of mmap */ |
1da177e4 LT |
228 | |
229 | asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, | |
230 | unsigned long prot, unsigned long flags, unsigned long fd, | |
231 | unsigned long pgoff) | |
232 | { | |
233 | /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE | |
234 | we have. */ | |
f8b72560 AV |
235 | return sys_mmap_pgoff(addr, len, prot, flags, fd, |
236 | pgoff >> (PAGE_SHIFT - 12)); | |
1da177e4 LT |
237 | } |
238 | ||
239 | asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, | |
240 | unsigned long prot, unsigned long flags, unsigned long fd, | |
241 | unsigned long off) | |
242 | { | |
f8b72560 AV |
243 | /* no alignment check? */ |
244 | return sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); | |
1da177e4 LT |
245 | } |
246 | ||
247 | long sparc_remap_file_pages(unsigned long start, unsigned long size, | |
248 | unsigned long prot, unsigned long pgoff, | |
249 | unsigned long flags) | |
250 | { | |
251 | /* This works on an existing mmap so we don't need to validate | |
252 | * the range as that was done at the original mmap call. | |
253 | */ | |
254 | return sys_remap_file_pages(start, size, prot, | |
255 | (pgoff >> (PAGE_SHIFT - 12)), flags); | |
256 | } | |
257 | ||
1da177e4 LT |
258 | /* we come to here via sys_nis_syscall so it can setup the regs argument */ |
259 | asmlinkage unsigned long | |
260 | c_sys_nis_syscall (struct pt_regs *regs) | |
261 | { | |
262 | static int count = 0; | |
263 | ||
264 | if (count++ > 5) | |
265 | return -ENOSYS; | |
266 | printk ("%s[%d]: Unimplemented SPARC system call %d\n", | |
19c5870c | 267 | current->comm, task_pid_nr(current), (int)regs->u_regs[1]); |
1da177e4 LT |
268 | #ifdef DEBUG_UNIMP_SYSCALL |
269 | show_regs (regs); | |
270 | #endif | |
271 | return -ENOSYS; | |
272 | } | |
273 | ||
274 | /* #define DEBUG_SPARC_BREAKPOINT */ | |
275 | ||
276 | asmlinkage void | |
277 | sparc_breakpoint (struct pt_regs *regs) | |
278 | { | |
279 | siginfo_t info; | |
280 | ||
281 | lock_kernel(); | |
282 | #ifdef DEBUG_SPARC_BREAKPOINT | |
283 | printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs->pc, regs->npc); | |
284 | #endif | |
285 | info.si_signo = SIGTRAP; | |
286 | info.si_errno = 0; | |
287 | info.si_code = TRAP_BRKPT; | |
288 | info.si_addr = (void __user *)regs->pc; | |
289 | info.si_trapno = 0; | |
290 | force_sig_info(SIGTRAP, &info, current); | |
291 | ||
292 | #ifdef DEBUG_SPARC_BREAKPOINT | |
293 | printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs->pc, regs->npc); | |
294 | #endif | |
295 | unlock_kernel(); | |
296 | } | |
297 | ||
298 | asmlinkage int | |
299 | sparc_sigaction (int sig, const struct old_sigaction __user *act, | |
300 | struct old_sigaction __user *oact) | |
301 | { | |
302 | struct k_sigaction new_ka, old_ka; | |
303 | int ret; | |
304 | ||
5526b7e4 DM |
305 | WARN_ON_ONCE(sig >= 0); |
306 | sig = -sig; | |
1da177e4 LT |
307 | |
308 | if (act) { | |
309 | unsigned long mask; | |
310 | ||
311 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || | |
312 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || | |
313 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) | |
314 | return -EFAULT; | |
315 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); | |
316 | __get_user(mask, &act->sa_mask); | |
317 | siginitset(&new_ka.sa.sa_mask, mask); | |
318 | new_ka.ka_restorer = NULL; | |
319 | } | |
320 | ||
321 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | |
322 | ||
323 | if (!ret && oact) { | |
324 | /* In the clone() case we could copy half consistent | |
325 | * state to the user, however this could sleep and | |
326 | * deadlock us if we held the signal lock on SMP. So for | |
327 | * now I take the easy way out and do no locking. | |
328 | */ | |
329 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || | |
330 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || | |
331 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) | |
332 | return -EFAULT; | |
333 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); | |
334 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); | |
335 | } | |
336 | ||
337 | return ret; | |
338 | } | |
339 | ||
340 | asmlinkage long | |
341 | sys_rt_sigaction(int sig, | |
342 | const struct sigaction __user *act, | |
343 | struct sigaction __user *oact, | |
344 | void __user *restorer, | |
345 | size_t sigsetsize) | |
346 | { | |
347 | struct k_sigaction new_ka, old_ka; | |
348 | int ret; | |
349 | ||
350 | /* XXX: Don't preclude handling different sized sigset_t's. */ | |
351 | if (sigsetsize != sizeof(sigset_t)) | |
352 | return -EINVAL; | |
353 | ||
1da177e4 LT |
354 | if (act) { |
355 | new_ka.ka_restorer = restorer; | |
356 | if (copy_from_user(&new_ka.sa, act, sizeof(*act))) | |
357 | return -EFAULT; | |
358 | } | |
359 | ||
360 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | |
361 | ||
362 | if (!ret && oact) { | |
363 | if (copy_to_user(oact, &old_ka.sa, sizeof(*oact))) | |
364 | return -EFAULT; | |
365 | } | |
366 | ||
367 | return ret; | |
368 | } | |
369 | ||
370 | asmlinkage int sys_getdomainname(char __user *name, int len) | |
371 | { | |
8310a32c | 372 | int nlen, err; |
1da177e4 | 373 | |
b9c54f91 | 374 | if (len < 0) |
8310a32c DM |
375 | return -EINVAL; |
376 | ||
1da177e4 LT |
377 | down_read(&uts_sem); |
378 | ||
e9ff3990 | 379 | nlen = strlen(utsname()->domainname) + 1; |
b9c54f91 AW |
380 | err = -EINVAL; |
381 | if (nlen > len) | |
382 | goto out; | |
8310a32c DM |
383 | |
384 | err = -EFAULT; | |
e9ff3990 | 385 | if (!copy_to_user(name, utsname()->domainname, nlen)) |
8310a32c DM |
386 | err = 0; |
387 | ||
b9c54f91 | 388 | out: |
1da177e4 LT |
389 | up_read(&uts_sem); |
390 | return err; | |
391 | } | |
fe74290d AB |
392 | |
393 | /* | |
394 | * Do a system call from kernel instead of calling sys_execve so we | |
395 | * end up with proper pt_regs. | |
396 | */ | |
397 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]) | |
398 | { | |
399 | long __res; | |
400 | register long __g1 __asm__ ("g1") = __NR_execve; | |
401 | register long __o0 __asm__ ("o0") = (long)(filename); | |
402 | register long __o1 __asm__ ("o1") = (long)(argv); | |
403 | register long __o2 __asm__ ("o2") = (long)(envp); | |
404 | asm volatile ("t 0x10\n\t" | |
405 | "bcc 1f\n\t" | |
406 | "mov %%o0, %0\n\t" | |
407 | "sub %%g0, %%o0, %0\n\t" | |
408 | "1:\n\t" | |
409 | : "=r" (__res), "=&r" (__o0) | |
410 | : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1) | |
411 | : "cc"); | |
412 | return __res; | |
413 | } |