Import 2.3.41pre2
[davej-history.git] / arch / sparc / kernel / sys_sparc.c
blobad449a435cf7018dbadb63411b7ec315ad86f105
1 /* $Id: sys_sparc.c,v 1.57 2000/01/21 11:38:42 jj Exp $
2 * linux/arch/sparc/kernel/sys_sparc.c
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/sparc
6 * platform.
7 */
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 #include <linux/sched.h>
12 #include <linux/config.h>
13 #include <linux/mm.h>
14 #include <linux/fs.h>
15 #include <linux/file.h>
16 #include <linux/sem.h>
17 #include <linux/msg.h>
18 #include <linux/shm.h>
19 #include <linux/stat.h>
20 #include <linux/mman.h>
21 #include <linux/utsname.h>
22 #include <linux/smp.h>
23 #include <linux/smp_lock.h>
25 #include <asm/uaccess.h>
26 #include <asm/ipc.h>
28 /* #define DEBUG_UNIMP_SYSCALL */
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.
33 asmlinkage unsigned long sys_getpagesize(void)
35 return PAGE_SIZE; /* Possibly older binaries want 8192 on sun4's? */
38 extern asmlinkage unsigned long sys_brk(unsigned long brk);
40 asmlinkage unsigned long sparc_brk(unsigned long brk)
42 if(ARCH_SUN4C_SUN4) {
43 if(brk >= 0x20000000 && brk < 0xe0000000)
44 return current->mm->brk;
46 return sys_brk(brk);
50 * sys_pipe() is the normal C calling standard for creating
51 * a pipe. It's not the way unix traditionally does this, though.
53 asmlinkage int sparc_pipe(struct pt_regs *regs)
55 int fd[2];
56 int error;
58 lock_kernel();
59 error = do_pipe(fd);
60 if (error)
61 goto out;
62 regs->u_regs[UREG_I1] = fd[1];
63 error = fd[0];
64 out:
65 unlock_kernel();
66 return error;
70 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
72 * This is really horribly ugly.
75 asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
77 int version, err;
79 lock_kernel();
80 version = call >> 16; /* hack for backward compatibility */
81 call &= 0xffff;
83 if (call <= SEMCTL)
84 switch (call) {
85 case SEMOP:
86 err = sys_semop (first, (struct sembuf *)ptr, second);
87 goto out;
88 case SEMGET:
89 err = sys_semget (first, second, third);
90 goto out;
91 case SEMCTL: {
92 union semun fourth;
93 err = -EINVAL;
94 if (!ptr)
95 goto out;
96 err = -EFAULT;
97 if(get_user(fourth.__pad, (void **)ptr))
98 goto out;
99 err = sys_semctl (first, second, third, fourth);
100 goto out;
102 default:
103 err = -EINVAL;
104 goto out;
106 if (call <= MSGCTL)
107 switch (call) {
108 case MSGSND:
109 err = sys_msgsnd (first, (struct msgbuf *) ptr,
110 second, third);
111 goto out;
112 case MSGRCV:
113 switch (version) {
114 case 0: {
115 struct ipc_kludge tmp;
116 err = -EINVAL;
117 if (!ptr)
118 goto out;
119 err = -EFAULT;
120 if(copy_from_user(&tmp,(struct ipc_kludge *) ptr, sizeof (tmp)))
121 goto out;
122 err = sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp, third);
123 goto out;
125 case 1: default:
126 err = sys_msgrcv (first, (struct msgbuf *) ptr, second, fifth, third);
127 goto out;
129 case MSGGET:
130 err = sys_msgget ((key_t) first, second);
131 goto out;
132 case MSGCTL:
133 err = sys_msgctl (first, second, (struct msqid_ds *) ptr);
134 goto out;
135 default:
136 err = -EINVAL;
137 goto out;
139 if (call <= SHMCTL)
140 switch (call) {
141 case SHMAT:
142 switch (version) {
143 case 0: default: {
144 ulong raddr;
145 err = sys_shmat (first, (char *) ptr, second, &raddr);
146 if (err)
147 goto out;
148 err = -EFAULT;
149 if(put_user (raddr, (ulong *) third))
150 goto out;
151 err = 0;
152 goto out;
154 case 1: /* iBCS2 emulator entry point */
155 err = sys_shmat (first, (char *) ptr, second, (ulong *) third);
156 goto out;
158 case SHMDT:
159 err = sys_shmdt ((char *)ptr);
160 goto out;
161 case SHMGET:
162 err = sys_shmget (first, second, third);
163 goto out;
164 case SHMCTL:
165 err = sys_shmctl (first, second, (struct shmid_ds *) ptr);
166 goto out;
167 default:
168 err = -EINVAL;
169 goto out;
171 else
172 err = -EINVAL;
173 out:
174 unlock_kernel();
175 return err;
178 /* Linux version of mmap */
179 static unsigned long do_mmap2(unsigned long addr, unsigned long len,
180 unsigned long prot, unsigned long flags, unsigned long fd,
181 unsigned long pgoff)
183 struct file * file = NULL;
184 unsigned long retval = -EBADF;
186 if (!(flags & MAP_ANONYMOUS)) {
187 file = fget(fd);
188 if (!file)
189 goto out;
192 down(&current->mm->mmap_sem);
193 lock_kernel();
194 retval = -ENOMEM;
195 len = PAGE_ALIGN(len);
196 if(!(flags & MAP_FIXED) &&
197 (!addr || (ARCH_SUN4C_SUN4 &&
198 (addr >= 0x20000000 && addr < 0xe0000000)))) {
199 addr = get_unmapped_area(0, len);
200 if(!addr)
201 goto out_putf;
202 if (ARCH_SUN4C_SUN4 &&
203 (addr >= 0x20000000 && addr < 0xe0000000)) {
204 retval = -EINVAL;
205 goto out_putf;
209 /* See asm-sparc/uaccess.h */
210 retval = -EINVAL;
211 if((len > (TASK_SIZE - PAGE_SIZE)) || (addr > (TASK_SIZE-len-PAGE_SIZE)))
212 goto out_putf;
214 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
215 retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
217 out_putf:
218 unlock_kernel();
219 up(&current->mm->mmap_sem);
220 if (file)
221 fput(file);
222 out:
223 return retval;
226 asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
227 unsigned long prot, unsigned long flags, unsigned long fd,
228 unsigned long pgoff)
230 /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
231 we have. */
232 return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT - 12));
235 asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
236 unsigned long prot, unsigned long flags, unsigned long fd,
237 unsigned long off)
239 return do_mmap2(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
242 /* we come to here via sys_nis_syscall so it can setup the regs argument */
243 asmlinkage unsigned long
244 c_sys_nis_syscall (struct pt_regs *regs)
246 static int count = 0;
248 if (count++ > 5) return -ENOSYS;
249 lock_kernel();
250 printk ("%s[%d]: Unimplemented SPARC system call %d\n", current->comm, current->pid, (int)regs->u_regs[1]);
251 #ifdef DEBUG_UNIMP_SYSCALL
252 show_regs (regs);
253 #endif
254 unlock_kernel();
255 return -ENOSYS;
258 /* #define DEBUG_SPARC_BREAKPOINT */
260 asmlinkage void
261 sparc_breakpoint (struct pt_regs *regs)
263 siginfo_t info;
265 lock_kernel();
266 #ifdef DEBUG_SPARC_BREAKPOINT
267 printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs->pc, regs->npc);
268 #endif
269 info.si_signo = SIGTRAP;
270 info.si_errno = 0;
271 info.si_code = TRAP_BRKPT;
272 info.si_addr = (void *)regs->pc;
273 info.si_trapno = 0;
274 force_sig_info(SIGTRAP, &info, current);
276 #ifdef DEBUG_SPARC_BREAKPOINT
277 printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs->pc, regs->npc);
278 #endif
279 unlock_kernel();
282 asmlinkage int
283 sparc_sigaction (int sig, const struct old_sigaction *act,
284 struct old_sigaction *oact)
286 struct k_sigaction new_ka, old_ka;
287 int ret;
289 if (sig < 0) {
290 current->thread.new_signal = 1;
291 sig = -sig;
294 if (act) {
295 unsigned long mask;
297 if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
298 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
299 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
300 return -EFAULT;
301 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
302 __get_user(mask, &act->sa_mask);
303 siginitset(&new_ka.sa.sa_mask, mask);
304 new_ka.ka_restorer = NULL;
307 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
309 if (!ret && oact) {
310 /* In the clone() case we could copy half consistant
311 * state to the user, however this could sleep and
312 * deadlock us if we held the signal lock on SMP. So for
313 * now I take the easy way out and do no locking.
315 if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
316 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
317 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
318 return -EFAULT;
319 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
320 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
323 return ret;
326 asmlinkage int
327 sys_rt_sigaction(int sig, const struct sigaction *act, struct sigaction *oact,
328 void *restorer, size_t sigsetsize)
330 struct k_sigaction new_ka, old_ka;
331 int ret;
333 /* XXX: Don't preclude handling different sized sigset_t's. */
334 if (sigsetsize != sizeof(sigset_t))
335 return -EINVAL;
337 /* All tasks which use RT signals (effectively) use
338 * new style signals.
340 current->thread.new_signal = 1;
342 if (act) {
343 new_ka.ka_restorer = restorer;
344 if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
345 return -EFAULT;
348 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
350 if (!ret && oact) {
351 if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
352 return -EFAULT;
355 return ret;
358 /* Just in case some old old binary calls this. */
359 asmlinkage int sys_pause(void)
361 current->state = TASK_INTERRUPTIBLE;
362 schedule();
363 return -ERESTARTNOHAND;
366 asmlinkage int sys_getdomainname(char *name, int len)
368 int nlen;
369 int err = -EFAULT;
371 down(&uts_sem);
373 nlen = strlen(system_utsname.domainname) + 1;
375 if (nlen < len)
376 len = nlen;
377 if(len > __NEW_UTS_LEN)
378 goto done;
379 if(copy_to_user(name, system_utsname.domainname, len))
380 goto done;
381 err = 0;
382 done:
383 up(&uts_sem);
384 return err;
388 #ifndef CONFIG_AP1000
389 /* only AP+ systems have sys_aplib */
390 asmlinkage int sys_aplib(void)
392 return -ENOSYS;
394 #endif