1 /* $Id: sys_sparc.c,v 1.67 2000/11/30 08:37:31 anton 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
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 #include <linux/sched.h>
14 #include <linux/file.h>
15 #include <linux/sem.h>
16 #include <linux/msg.h>
17 #include <linux/shm.h>
18 #include <linux/stat.h>
19 #include <linux/mman.h>
20 #include <linux/utsname.h>
21 #include <linux/smp.h>
22 #include <linux/smp_lock.h>
24 #include <asm/uaccess.h>
27 /* #define DEBUG_UNIMP_SYSCALL */
29 /* XXX Make this per-binary type, this way we can detect the type of
30 * XXX a binary. Every Sparc executable calls this very early on.
32 asmlinkage
unsigned long sys_getpagesize(void)
34 return PAGE_SIZE
; /* Possibly older binaries want 8192 on sun4's? */
37 #define COLOUR_ALIGN(addr) (((addr)+SHMLBA-1)&~(SHMLBA-1))
39 unsigned long get_unmapped_area(unsigned long addr
, unsigned long len
)
41 struct vm_area_struct
* vmm
;
43 /* See asm-sparc/uaccess.h */
44 if (len
> TASK_SIZE
- PAGE_SIZE
)
46 if (ARCH_SUN4C_SUN4
&& len
> 0x20000000)
49 addr
= TASK_UNMAPPED_BASE
;
51 if (current
->thread
.flags
& SPARC_FLAG_MMAPSHARED
)
52 addr
= COLOUR_ALIGN(addr
);
54 addr
= PAGE_ALIGN(addr
);
56 for (vmm
= find_vma(current
->mm
, addr
); ; vmm
= vmm
->vm_next
) {
57 /* At this point: (!vmm || addr < vmm->vm_end). */
58 if (ARCH_SUN4C_SUN4
&& addr
< 0xe0000000 && 0x20000000 - len
< addr
) {
60 vmm
= find_vma(current
->mm
, PAGE_OFFSET
);
62 if (TASK_SIZE
- PAGE_SIZE
- len
< addr
)
64 if (!vmm
|| addr
+ len
<= vmm
->vm_start
)
67 if (current
->thread
.flags
& SPARC_FLAG_MMAPSHARED
)
68 addr
= COLOUR_ALIGN(addr
);
72 extern asmlinkage
unsigned long sys_brk(unsigned long brk
);
74 asmlinkage
unsigned long sparc_brk(unsigned long brk
)
77 if ((brk
& 0xe0000000) != (current
->mm
->brk
& 0xe0000000))
78 return current
->mm
->brk
;
84 * sys_pipe() is the normal C calling standard for creating
85 * a pipe. It's not the way unix traditionally does this, though.
87 asmlinkage
int sparc_pipe(struct pt_regs
*regs
)
95 regs
->u_regs
[UREG_I1
] = fd
[1];
102 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
104 * This is really horribly ugly.
107 asmlinkage
int sys_ipc (uint call
, int first
, int second
, int third
, void *ptr
, long fifth
)
111 version
= call
>> 16; /* hack for backward compatibility */
117 err
= sys_semop (first
, (struct sembuf
*)ptr
, second
);
120 err
= sys_semget (first
, second
, third
);
128 if(get_user(fourth
.__pad
, (void **)ptr
))
130 err
= sys_semctl (first
, second
, third
, fourth
);
140 err
= sys_msgsnd (first
, (struct msgbuf
*) ptr
,
146 struct ipc_kludge tmp
;
151 if(copy_from_user(&tmp
,(struct ipc_kludge
*) ptr
, sizeof (tmp
)))
153 err
= sys_msgrcv (first
, tmp
.msgp
, second
, tmp
.msgtyp
, third
);
157 err
= sys_msgrcv (first
, (struct msgbuf
*) ptr
, second
, fifth
, third
);
161 err
= sys_msgget ((key_t
) first
, second
);
164 err
= sys_msgctl (first
, second
, (struct msqid_ds
*) ptr
);
176 err
= sys_shmat (first
, (char *) ptr
, second
, &raddr
);
180 if(put_user (raddr
, (ulong
*) third
))
185 case 1: /* iBCS2 emulator entry point */
186 err
= sys_shmat (first
, (char *) ptr
, second
, (ulong
*) third
);
190 err
= sys_shmdt ((char *)ptr
);
193 err
= sys_shmget (first
, second
, third
);
196 err
= sys_shmctl (first
, second
, (struct shmid_ds
*) ptr
);
208 /* Linux version of mmap */
209 static unsigned long do_mmap2(unsigned long addr
, unsigned long len
,
210 unsigned long prot
, unsigned long flags
, unsigned long fd
,
213 struct file
* file
= NULL
;
214 unsigned long retval
= -EBADF
;
216 if (!(flags
& MAP_ANONYMOUS
)) {
223 len
= PAGE_ALIGN(len
);
224 if (ARCH_SUN4C_SUN4
&&
226 ((flags
& MAP_FIXED
) &&
227 addr
< 0xe0000000 && addr
+ len
> 0x20000000)))
230 /* See asm-sparc/uaccess.h */
231 if (len
> TASK_SIZE
- PAGE_SIZE
|| addr
+ len
> TASK_SIZE
- PAGE_SIZE
)
234 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
236 if (flags
& MAP_SHARED
)
237 current
->thread
.flags
|= SPARC_FLAG_MMAPSHARED
;
239 down(¤t
->mm
->mmap_sem
);
240 retval
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
241 up(¤t
->mm
->mmap_sem
);
243 current
->thread
.flags
&= ~(SPARC_FLAG_MMAPSHARED
);
252 asmlinkage
unsigned long sys_mmap2(unsigned long addr
, unsigned long len
,
253 unsigned long prot
, unsigned long flags
, unsigned long fd
,
256 /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
258 return do_mmap2(addr
, len
, prot
, flags
, fd
, pgoff
>> (PAGE_SHIFT
- 12));
261 asmlinkage
unsigned long sys_mmap(unsigned long addr
, unsigned long len
,
262 unsigned long prot
, unsigned long flags
, unsigned long fd
,
265 return do_mmap2(addr
, len
, prot
, flags
, fd
, off
>> PAGE_SHIFT
);
268 extern unsigned long do_mremap(unsigned long addr
,
269 unsigned long old_len
, unsigned long new_len
,
270 unsigned long flags
, unsigned long new_addr
);
272 asmlinkage
unsigned long sparc_mremap(unsigned long addr
,
273 unsigned long old_len
, unsigned long new_len
,
274 unsigned long flags
, unsigned long new_addr
)
276 struct vm_area_struct
*vma
;
277 unsigned long ret
= -EINVAL
;
278 if (ARCH_SUN4C_SUN4
) {
279 if (old_len
> 0x20000000 || new_len
> 0x20000000)
281 if (addr
< 0xe0000000 && addr
+ old_len
> 0x20000000)
284 if (old_len
> TASK_SIZE
- PAGE_SIZE
||
285 new_len
> TASK_SIZE
- PAGE_SIZE
)
287 down(¤t
->mm
->mmap_sem
);
288 vma
= find_vma(current
->mm
, addr
);
289 if (vma
&& (vma
->vm_flags
& VM_SHARED
))
290 current
->thread
.flags
|= SPARC_FLAG_MMAPSHARED
;
291 if (flags
& MREMAP_FIXED
) {
292 if (ARCH_SUN4C_SUN4
&&
293 new_addr
< 0xe0000000 &&
294 new_addr
+ new_len
> 0x20000000)
296 if (new_addr
+ new_len
> TASK_SIZE
- PAGE_SIZE
)
298 } else if ((ARCH_SUN4C_SUN4
&& addr
< 0xe0000000 &&
299 addr
+ new_len
> 0x20000000) ||
300 addr
+ new_len
> TASK_SIZE
- PAGE_SIZE
) {
302 if (!(flags
& MREMAP_MAYMOVE
))
304 new_addr
= get_unmapped_area (addr
, new_len
);
307 flags
|= MREMAP_FIXED
;
309 ret
= do_mremap(addr
, old_len
, new_len
, flags
, new_addr
);
311 current
->thread
.flags
&= ~(SPARC_FLAG_MMAPSHARED
);
312 up(¤t
->mm
->mmap_sem
);
317 /* we come to here via sys_nis_syscall so it can setup the regs argument */
318 asmlinkage
unsigned long
319 c_sys_nis_syscall (struct pt_regs
*regs
)
321 static int count
= 0;
323 if (count
++ > 5) return -ENOSYS
;
324 printk ("%s[%d]: Unimplemented SPARC system call %d\n", current
->comm
, current
->pid
, (int)regs
->u_regs
[1]);
325 #ifdef DEBUG_UNIMP_SYSCALL
331 /* #define DEBUG_SPARC_BREAKPOINT */
334 sparc_breakpoint (struct pt_regs
*regs
)
339 #ifdef DEBUG_SPARC_BREAKPOINT
340 printk ("TRAP: Entering kernel PC=%x, nPC=%x\n", regs
->pc
, regs
->npc
);
342 info
.si_signo
= SIGTRAP
;
344 info
.si_code
= TRAP_BRKPT
;
345 info
.si_addr
= (void *)regs
->pc
;
347 force_sig_info(SIGTRAP
, &info
, current
);
349 #ifdef DEBUG_SPARC_BREAKPOINT
350 printk ("TRAP: Returning to space: PC=%x nPC=%x\n", regs
->pc
, regs
->npc
);
356 sparc_sigaction (int sig
, const struct old_sigaction
*act
,
357 struct old_sigaction
*oact
)
359 struct k_sigaction new_ka
, old_ka
;
363 current
->thread
.new_signal
= 1;
370 if (verify_area(VERIFY_READ
, act
, sizeof(*act
)) ||
371 __get_user(new_ka
.sa
.sa_handler
, &act
->sa_handler
) ||
372 __get_user(new_ka
.sa
.sa_restorer
, &act
->sa_restorer
))
374 __get_user(new_ka
.sa
.sa_flags
, &act
->sa_flags
);
375 __get_user(mask
, &act
->sa_mask
);
376 siginitset(&new_ka
.sa
.sa_mask
, mask
);
377 new_ka
.ka_restorer
= NULL
;
380 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
383 /* In the clone() case we could copy half consistant
384 * state to the user, however this could sleep and
385 * deadlock us if we held the signal lock on SMP. So for
386 * now I take the easy way out and do no locking.
388 if (verify_area(VERIFY_WRITE
, oact
, sizeof(*oact
)) ||
389 __put_user(old_ka
.sa
.sa_handler
, &oact
->sa_handler
) ||
390 __put_user(old_ka
.sa
.sa_restorer
, &oact
->sa_restorer
))
392 __put_user(old_ka
.sa
.sa_flags
, &oact
->sa_flags
);
393 __put_user(old_ka
.sa
.sa_mask
.sig
[0], &oact
->sa_mask
);
400 sys_rt_sigaction(int sig
, const struct sigaction
*act
, struct sigaction
*oact
,
401 void *restorer
, size_t sigsetsize
)
403 struct k_sigaction new_ka
, old_ka
;
406 /* XXX: Don't preclude handling different sized sigset_t's. */
407 if (sigsetsize
!= sizeof(sigset_t
))
410 /* All tasks which use RT signals (effectively) use
413 current
->thread
.new_signal
= 1;
416 new_ka
.ka_restorer
= restorer
;
417 if (copy_from_user(&new_ka
.sa
, act
, sizeof(*act
)))
421 ret
= do_sigaction(sig
, act
? &new_ka
: NULL
, oact
? &old_ka
: NULL
);
424 if (copy_to_user(oact
, &old_ka
.sa
, sizeof(*oact
)))
431 /* Just in case some old old binary calls this. */
432 asmlinkage
int sys_pause(void)
434 current
->state
= TASK_INTERRUPTIBLE
;
436 return -ERESTARTNOHAND
;
439 asmlinkage
int sys_getdomainname(char *name
, int len
)
446 nlen
= strlen(system_utsname
.domainname
) + 1;
450 if(len
> __NEW_UTS_LEN
)
452 if(copy_to_user(name
, system_utsname
.domainname
, len
))