pandora: defconfig: update
[pandora-kernel.git] / arch / sparc / kernel / sys_sparc_64.c
1 /* linux/arch/sparc64/kernel/sys_sparc.c
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/fs.h>
12 #include <linux/file.h>
13 #include <linux/mm.h>
14 #include <linux/sem.h>
15 #include <linux/msg.h>
16 #include <linux/shm.h>
17 #include <linux/stat.h>
18 #include <linux/mman.h>
19 #include <linux/utsname.h>
20 #include <linux/smp.h>
21 #include <linux/slab.h>
22 #include <linux/syscalls.h>
23 #include <linux/ipc.h>
24 #include <linux/personality.h>
25 #include <linux/random.h>
26 #include <linux/export.h>
27
28 #include <asm/uaccess.h>
29 #include <asm/utrap.h>
30 #include <asm/unistd.h>
31
32 #include "entry.h"
33 #include "systbls.h"
34
35 /* #define DEBUG_UNIMP_SYSCALL */
36
37 asmlinkage unsigned long sys_getpagesize(void)
38 {
39         return PAGE_SIZE;
40 }
41
42 #define VA_EXCLUDE_START (0x0000080000000000UL - (1UL << 32UL))
43 #define VA_EXCLUDE_END   (0xfffff80000000000UL + (1UL << 32UL))
44
45 /* Does addr --> addr+len fall within 4GB of the VA-space hole or
46  * overflow past the end of the 64-bit address space?
47  */
48 static inline int invalid_64bit_range(unsigned long addr, unsigned long len)
49 {
50         unsigned long va_exclude_start, va_exclude_end;
51
52         va_exclude_start = VA_EXCLUDE_START;
53         va_exclude_end   = VA_EXCLUDE_END;
54
55         if (unlikely(len >= va_exclude_start))
56                 return 1;
57
58         if (unlikely((addr + len) < addr))
59                 return 1;
60
61         if (unlikely((addr >= va_exclude_start && addr < va_exclude_end) ||
62                      ((addr + len) >= va_exclude_start &&
63                       (addr + len) < va_exclude_end)))
64                 return 1;
65
66         return 0;
67 }
68
69 /* Does start,end straddle the VA-space hole?  */
70 static inline int straddles_64bit_va_hole(unsigned long start, unsigned long end)
71 {
72         unsigned long va_exclude_start, va_exclude_end;
73
74         va_exclude_start = VA_EXCLUDE_START;
75         va_exclude_end   = VA_EXCLUDE_END;
76
77         if (likely(start < va_exclude_start && end < va_exclude_start))
78                 return 0;
79
80         if (likely(start >= va_exclude_end && end >= va_exclude_end))
81                 return 0;
82
83         return 1;
84 }
85
86 /* These functions differ from the default implementations in
87  * mm/mmap.c in two ways:
88  *
89  * 1) For file backed MAP_SHARED mmap()'s we D-cache color align,
90  *    for fixed such mappings we just validate what the user gave us.
91  * 2) For 64-bit tasks we avoid mapping anything within 4GB of
92  *    the spitfire/niagara VA-hole.
93  */
94
95 static inline unsigned long COLOUR_ALIGN(unsigned long addr,
96                                          unsigned long pgoff)
97 {
98         unsigned long base = (addr+SHMLBA-1)&~(SHMLBA-1);
99         unsigned long off = (pgoff<<PAGE_SHIFT) & (SHMLBA-1);
100
101         return base + off;
102 }
103
104 static inline unsigned long COLOUR_ALIGN_DOWN(unsigned long addr,
105                                               unsigned long pgoff)
106 {
107         unsigned long base = addr & ~(SHMLBA-1);
108         unsigned long off = (pgoff<<PAGE_SHIFT) & (SHMLBA-1);
109
110         if (base + off <= addr)
111                 return base + off;
112         return base - off;
113 }
114
115 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
116 {
117         struct mm_struct *mm = current->mm;
118         struct vm_area_struct * vma;
119         unsigned long task_size = TASK_SIZE;
120         unsigned long start_addr, vm_start;
121         int do_color_align;
122
123         if (flags & MAP_FIXED) {
124                 /* We do not accept a shared mapping if it would violate
125                  * cache aliasing constraints.
126                  */
127                 if ((flags & MAP_SHARED) &&
128                     ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
129                         return -EINVAL;
130                 return addr;
131         }
132
133         if (test_thread_flag(TIF_32BIT))
134                 task_size = STACK_TOP32;
135         if (unlikely(len > task_size || len >= VA_EXCLUDE_START))
136                 return -ENOMEM;
137
138         do_color_align = 0;
139         if (filp || (flags & MAP_SHARED))
140                 do_color_align = 1;
141
142         if (addr) {
143                 if (do_color_align)
144                         addr = COLOUR_ALIGN(addr, pgoff);
145                 else
146                         addr = PAGE_ALIGN(addr);
147
148                 vma = find_vma(mm, addr);
149                 if (task_size - len >= addr &&
150                     (!vma || addr + len <= vm_start_gap(vma)))
151                         return addr;
152         }
153
154         if (len > mm->cached_hole_size) {
155                 start_addr = addr = mm->free_area_cache;
156         } else {
157                 start_addr = addr = TASK_UNMAPPED_BASE;
158                 mm->cached_hole_size = 0;
159         }
160
161         task_size -= len;
162
163 full_search:
164         if (do_color_align)
165                 addr = COLOUR_ALIGN(addr, pgoff);
166         else
167                 addr = PAGE_ALIGN(addr);
168
169         for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
170                 /* At this point:  (!vma || addr < vma->vm_end). */
171                 if (addr < VA_EXCLUDE_START &&
172                     (addr + len) >= VA_EXCLUDE_START) {
173                         addr = VA_EXCLUDE_END;
174                         vma = find_vma(mm, VA_EXCLUDE_END);
175                 }
176                 if (unlikely(task_size < addr)) {
177                         if (start_addr != TASK_UNMAPPED_BASE) {
178                                 start_addr = addr = TASK_UNMAPPED_BASE;
179                                 mm->cached_hole_size = 0;
180                                 goto full_search;
181                         }
182                         return -ENOMEM;
183                 }
184                 if (vma)
185                         vm_start = vm_start_gap(vma);
186                 if (likely(!vma || addr + len <= vm_start)) {
187                         /*
188                          * Remember the place where we stopped the search:
189                          */
190                         mm->free_area_cache = addr + len;
191                         return addr;
192                 }
193                 if (addr + mm->cached_hole_size < vm_start)
194                         mm->cached_hole_size = vm_start - addr;
195
196                 addr = vma->vm_end;
197                 if (do_color_align)
198                         addr = COLOUR_ALIGN(addr, pgoff);
199         }
200 }
201
202 unsigned long
203 arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
204                           const unsigned long len, const unsigned long pgoff,
205                           const unsigned long flags)
206 {
207         struct vm_area_struct *vma;
208         struct mm_struct *mm = current->mm;
209         unsigned long task_size = STACK_TOP32;
210         unsigned long addr = addr0, vm_start;
211         int do_color_align;
212
213         /* This should only ever run for 32-bit processes.  */
214         BUG_ON(!test_thread_flag(TIF_32BIT));
215
216         if (flags & MAP_FIXED) {
217                 /* We do not accept a shared mapping if it would violate
218                  * cache aliasing constraints.
219                  */
220                 if ((flags & MAP_SHARED) &&
221                     ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
222                         return -EINVAL;
223                 return addr;
224         }
225
226         if (unlikely(len > task_size))
227                 return -ENOMEM;
228
229         do_color_align = 0;
230         if (filp || (flags & MAP_SHARED))
231                 do_color_align = 1;
232
233         /* requesting a specific address */
234         if (addr) {
235                 if (do_color_align)
236                         addr = COLOUR_ALIGN(addr, pgoff);
237                 else
238                         addr = PAGE_ALIGN(addr);
239
240                 vma = find_vma(mm, addr);
241                 if (task_size - len >= addr &&
242                     (!vma || addr + len <= vm_start_gap(vma)))
243                         return addr;
244         }
245
246         /* check if free_area_cache is useful for us */
247         if (len <= mm->cached_hole_size) {
248                 mm->cached_hole_size = 0;
249                 mm->free_area_cache = mm->mmap_base;
250         }
251
252         /* either no address requested or can't fit in requested address hole */
253         addr = mm->free_area_cache;
254         if (do_color_align) {
255                 unsigned long base = COLOUR_ALIGN_DOWN(addr-len, pgoff);
256
257                 addr = base + len;
258         }
259
260         /* make sure it can fit in the remaining address space */
261         if (likely(addr > len)) {
262                 vma = find_vma(mm, addr-len);
263                 if (!vma || addr <= vm_start_gap(vma)) {
264                         /* remember the address as a hint for next time */
265                         return (mm->free_area_cache = addr-len);
266                 }
267         }
268
269         if (unlikely(mm->mmap_base < len))
270                 goto bottomup;
271
272         addr = mm->mmap_base-len;
273         if (do_color_align)
274                 addr = COLOUR_ALIGN_DOWN(addr, pgoff);
275
276         do {
277                 /*
278                  * Lookup failure means no vma is above this address,
279                  * else if new region fits below vma->vm_start,
280                  * return with success:
281                  */
282                 vma = find_vma(mm, addr);
283                 if (vma)
284                         vm_start = vm_start_gap(vma);
285                 if (likely(!vma || addr + len <= vm_start)) {
286                         /* remember the address as a hint for next time */
287                         return (mm->free_area_cache = addr);
288                 }
289
290                 /* remember the largest hole we saw so far */
291                 if (addr + mm->cached_hole_size < vm_start)
292                         mm->cached_hole_size = vm_start - addr;
293
294                 /* try just below the current vma->vm_start */
295                 addr = vm_start - len;
296                 if (do_color_align)
297                         addr = COLOUR_ALIGN_DOWN(addr, pgoff);
298         } while (likely(len < vm_start));
299
300 bottomup:
301         /*
302          * A failed mmap() very likely causes application failure,
303          * so fall back to the bottom-up function here. This scenario
304          * can happen with large stack limits and large mmap()
305          * allocations.
306          */
307         mm->cached_hole_size = ~0UL;
308         mm->free_area_cache = TASK_UNMAPPED_BASE;
309         addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
310         /*
311          * Restore the topdown base:
312          */
313         mm->free_area_cache = mm->mmap_base;
314         mm->cached_hole_size = ~0UL;
315
316         return addr;
317 }
318
319 /* Try to align mapping such that we align it as much as possible. */
320 unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags)
321 {
322         unsigned long align_goal, addr = -ENOMEM;
323         unsigned long (*get_area)(struct file *, unsigned long,
324                                   unsigned long, unsigned long, unsigned long);
325
326         get_area = current->mm->get_unmapped_area;
327
328         if (flags & MAP_FIXED) {
329                 /* Ok, don't mess with it. */
330                 return get_area(NULL, orig_addr, len, pgoff, flags);
331         }
332         flags &= ~MAP_SHARED;
333
334         align_goal = PAGE_SIZE;
335         if (len >= (4UL * 1024 * 1024))
336                 align_goal = (4UL * 1024 * 1024);
337         else if (len >= (512UL * 1024))
338                 align_goal = (512UL * 1024);
339         else if (len >= (64UL * 1024))
340                 align_goal = (64UL * 1024);
341
342         do {
343                 addr = get_area(NULL, orig_addr, len + (align_goal - PAGE_SIZE), pgoff, flags);
344                 if (!(addr & ~PAGE_MASK)) {
345                         addr = (addr + (align_goal - 1UL)) & ~(align_goal - 1UL);
346                         break;
347                 }
348
349                 if (align_goal == (4UL * 1024 * 1024))
350                         align_goal = (512UL * 1024);
351                 else if (align_goal == (512UL * 1024))
352                         align_goal = (64UL * 1024);
353                 else
354                         align_goal = PAGE_SIZE;
355         } while ((addr & ~PAGE_MASK) && align_goal > PAGE_SIZE);
356
357         /* Mapping is smaller than 64K or larger areas could not
358          * be obtained.
359          */
360         if (addr & ~PAGE_MASK)
361                 addr = get_area(NULL, orig_addr, len, pgoff, flags);
362
363         return addr;
364 }
365 EXPORT_SYMBOL(get_fb_unmapped_area);
366
367 /* Essentially the same as PowerPC.  */
368 static unsigned long mmap_rnd(void)
369 {
370         unsigned long rnd = 0UL;
371
372         if (current->flags & PF_RANDOMIZE) {
373                 unsigned long val = get_random_int();
374                 if (test_thread_flag(TIF_32BIT))
375                         rnd = (val % (1UL << (23UL-PAGE_SHIFT)));
376                 else
377                         rnd = (val % (1UL << (30UL-PAGE_SHIFT)));
378         }
379         return rnd << PAGE_SHIFT;
380 }
381
382 void arch_pick_mmap_layout(struct mm_struct *mm)
383 {
384         unsigned long random_factor = mmap_rnd();
385         unsigned long gap;
386
387         /*
388          * Fall back to the standard layout if the personality
389          * bit is set, or if the expected stack growth is unlimited:
390          */
391         gap = rlimit(RLIMIT_STACK);
392         if (!test_thread_flag(TIF_32BIT) ||
393             (current->personality & ADDR_COMPAT_LAYOUT) ||
394             gap == RLIM_INFINITY ||
395             sysctl_legacy_va_layout) {
396                 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
397                 mm->get_unmapped_area = arch_get_unmapped_area;
398                 mm->unmap_area = arch_unmap_area;
399         } else {
400                 /* We know it's 32-bit */
401                 unsigned long task_size = STACK_TOP32;
402
403                 if (gap < 128 * 1024 * 1024)
404                         gap = 128 * 1024 * 1024;
405                 if (gap > (task_size / 6 * 5))
406                         gap = (task_size / 6 * 5);
407
408                 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
409                 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
410                 mm->unmap_area = arch_unmap_area_topdown;
411         }
412 }
413
414 /*
415  * sys_pipe() is the normal C calling standard for creating
416  * a pipe. It's not the way unix traditionally does this, though.
417  */
418 SYSCALL_DEFINE1(sparc_pipe_real, struct pt_regs *, regs)
419 {
420         int fd[2];
421         int error;
422
423         error = do_pipe_flags(fd, 0);
424         if (error)
425                 goto out;
426         regs->u_regs[UREG_I1] = fd[1];
427         error = fd[0];
428 out:
429         return error;
430 }
431
432 /*
433  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
434  *
435  * This is really horribly ugly.
436  */
437
438 SYSCALL_DEFINE6(sparc_ipc, unsigned int, call, int, first, unsigned long, second,
439                 unsigned long, third, void __user *, ptr, long, fifth)
440 {
441         long err;
442
443         /* No need for backward compatibility. We can start fresh... */
444         if (call <= SEMCTL) {
445                 switch (call) {
446                 case SEMOP:
447                         err = sys_semtimedop(first, ptr,
448                                              (unsigned)second, NULL);
449                         goto out;
450                 case SEMTIMEDOP:
451                         err = sys_semtimedop(first, ptr, (unsigned)second,
452                                 (const struct timespec __user *)
453                                              (unsigned long) fifth);
454                         goto out;
455                 case SEMGET:
456                         err = sys_semget(first, (int)second, (int)third);
457                         goto out;
458                 case SEMCTL: {
459                         err = sys_semctl(first, second,
460                                          (int)third | IPC_64,
461                                          (union semun) ptr);
462                         goto out;
463                 }
464                 default:
465                         err = -ENOSYS;
466                         goto out;
467                 }
468         }
469         if (call <= MSGCTL) {
470                 switch (call) {
471                 case MSGSND:
472                         err = sys_msgsnd(first, ptr, (size_t)second,
473                                          (int)third);
474                         goto out;
475                 case MSGRCV:
476                         err = sys_msgrcv(first, ptr, (size_t)second, fifth,
477                                          (int)third);
478                         goto out;
479                 case MSGGET:
480                         err = sys_msgget((key_t)first, (int)second);
481                         goto out;
482                 case MSGCTL:
483                         err = sys_msgctl(first, (int)second | IPC_64, ptr);
484                         goto out;
485                 default:
486                         err = -ENOSYS;
487                         goto out;
488                 }
489         }
490         if (call <= SHMCTL) {
491                 switch (call) {
492                 case SHMAT: {
493                         ulong raddr;
494                         err = do_shmat(first, ptr, (int)second, &raddr);
495                         if (!err) {
496                                 if (put_user(raddr,
497                                              (ulong __user *) third))
498                                         err = -EFAULT;
499                         }
500                         goto out;
501                 }
502                 case SHMDT:
503                         err = sys_shmdt(ptr);
504                         goto out;
505                 case SHMGET:
506                         err = sys_shmget(first, (size_t)second, (int)third);
507                         goto out;
508                 case SHMCTL:
509                         err = sys_shmctl(first, (int)second | IPC_64, ptr);
510                         goto out;
511                 default:
512                         err = -ENOSYS;
513                         goto out;
514                 }
515         } else {
516                 err = -ENOSYS;
517         }
518 out:
519         return err;
520 }
521
522 SYSCALL_DEFINE1(sparc64_personality, unsigned long, personality)
523 {
524         long ret;
525
526         if (personality(current->personality) == PER_LINUX32 &&
527             personality(personality) == PER_LINUX)
528                 personality |= PER_LINUX32;
529         ret = sys_personality(personality);
530         if (personality(ret) == PER_LINUX32)
531                 ret &= ~PER_LINUX32;
532
533         return ret;
534 }
535
536 int sparc_mmap_check(unsigned long addr, unsigned long len)
537 {
538         if (test_thread_flag(TIF_32BIT)) {
539                 if (len >= STACK_TOP32)
540                         return -EINVAL;
541
542                 if (addr > STACK_TOP32 - len)
543                         return -EINVAL;
544         } else {
545                 if (len >= VA_EXCLUDE_START)
546                         return -EINVAL;
547
548                 if (invalid_64bit_range(addr, len))
549                         return -EINVAL;
550         }
551
552         return 0;
553 }
554
555 /* Linux version of mmap */
556 SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
557                 unsigned long, prot, unsigned long, flags, unsigned long, fd,
558                 unsigned long, off)
559 {
560         unsigned long retval = -EINVAL;
561
562         if ((off + PAGE_ALIGN(len)) < off)
563                 goto out;
564         if (off & ~PAGE_MASK)
565                 goto out;
566         retval = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
567 out:
568         return retval;
569 }
570
571 SYSCALL_DEFINE2(64_munmap, unsigned long, addr, size_t, len)
572 {
573         long ret;
574
575         if (invalid_64bit_range(addr, len))
576                 return -EINVAL;
577
578         down_write(&current->mm->mmap_sem);
579         ret = do_munmap(current->mm, addr, len);
580         up_write(&current->mm->mmap_sem);
581         return ret;
582 }
583
584 extern unsigned long do_mremap(unsigned long addr,
585         unsigned long old_len, unsigned long new_len,
586         unsigned long flags, unsigned long new_addr);
587                 
588 SYSCALL_DEFINE5(64_mremap, unsigned long, addr, unsigned long, old_len,
589                 unsigned long, new_len, unsigned long, flags,
590                 unsigned long, new_addr)
591 {
592         unsigned long ret = -EINVAL;
593
594         if (test_thread_flag(TIF_32BIT))
595                 goto out;
596
597         down_write(&current->mm->mmap_sem);
598         ret = do_mremap(addr, old_len, new_len, flags, new_addr);
599         up_write(&current->mm->mmap_sem);
600 out:
601         return ret;       
602 }
603
604 /* we come to here via sys_nis_syscall so it can setup the regs argument */
605 asmlinkage unsigned long c_sys_nis_syscall(struct pt_regs *regs)
606 {
607         static int count;
608         
609         /* Don't make the system unusable, if someone goes stuck */
610         if (count++ > 5)
611                 return -ENOSYS;
612
613         printk ("Unimplemented SPARC system call %ld\n",regs->u_regs[1]);
614 #ifdef DEBUG_UNIMP_SYSCALL      
615         show_regs (regs);
616 #endif
617
618         return -ENOSYS;
619 }
620
621 /* #define DEBUG_SPARC_BREAKPOINT */
622
623 asmlinkage void sparc_breakpoint(struct pt_regs *regs)
624 {
625         siginfo_t info;
626
627         if (test_thread_flag(TIF_32BIT)) {
628                 regs->tpc &= 0xffffffff;
629                 regs->tnpc &= 0xffffffff;
630         }
631 #ifdef DEBUG_SPARC_BREAKPOINT
632         printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n", regs->tpc, regs->tnpc);
633 #endif
634         info.si_signo = SIGTRAP;
635         info.si_errno = 0;
636         info.si_code = TRAP_BRKPT;
637         info.si_addr = (void __user *)regs->tpc;
638         info.si_trapno = 0;
639         force_sig_info(SIGTRAP, &info, current);
640 #ifdef DEBUG_SPARC_BREAKPOINT
641         printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n", regs->tpc, regs->tnpc);
642 #endif
643 }
644
645 extern void check_pending(int signum);
646
647 SYSCALL_DEFINE2(getdomainname, char __user *, name, int, len)
648 {
649         int nlen, err;
650
651         if (len < 0)
652                 return -EINVAL;
653
654         down_read(&uts_sem);
655         
656         nlen = strlen(utsname()->domainname) + 1;
657         err = -EINVAL;
658         if (nlen > len)
659                 goto out;
660
661         err = -EFAULT;
662         if (!copy_to_user(name, utsname()->domainname, nlen))
663                 err = 0;
664
665 out:
666         up_read(&uts_sem);
667         return err;
668 }
669
670 SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
671                 utrap_handler_t, new_p, utrap_handler_t, new_d,
672                 utrap_handler_t __user *, old_p,
673                 utrap_handler_t __user *, old_d)
674 {
675         if (type < UT_INSTRUCTION_EXCEPTION || type > UT_TRAP_INSTRUCTION_31)
676                 return -EINVAL;
677         if (new_p == (utrap_handler_t)(long)UTH_NOCHANGE) {
678                 if (old_p) {
679                         if (!current_thread_info()->utraps) {
680                                 if (put_user(NULL, old_p))
681                                         return -EFAULT;
682                         } else {
683                                 if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
684                                         return -EFAULT;
685                         }
686                 }
687                 if (old_d) {
688                         if (put_user(NULL, old_d))
689                                 return -EFAULT;
690                 }
691                 return 0;
692         }
693         if (!current_thread_info()->utraps) {
694                 current_thread_info()->utraps =
695                         kzalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long), GFP_KERNEL);
696                 if (!current_thread_info()->utraps)
697                         return -ENOMEM;
698                 current_thread_info()->utraps[0] = 1;
699         } else {
700                 if ((utrap_handler_t)current_thread_info()->utraps[type] != new_p &&
701                     current_thread_info()->utraps[0] > 1) {
702                         unsigned long *p = current_thread_info()->utraps;
703
704                         current_thread_info()->utraps =
705                                 kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long),
706                                         GFP_KERNEL);
707                         if (!current_thread_info()->utraps) {
708                                 current_thread_info()->utraps = p;
709                                 return -ENOMEM;
710                         }
711                         p[0]--;
712                         current_thread_info()->utraps[0] = 1;
713                         memcpy(current_thread_info()->utraps+1, p+1,
714                                UT_TRAP_INSTRUCTION_31*sizeof(long));
715                 }
716         }
717         if (old_p) {
718                 if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
719                         return -EFAULT;
720         }
721         if (old_d) {
722                 if (put_user(NULL, old_d))
723                         return -EFAULT;
724         }
725         current_thread_info()->utraps[type] = (long)new_p;
726
727         return 0;
728 }
729
730 asmlinkage long sparc_memory_ordering(unsigned long model,
731                                       struct pt_regs *regs)
732 {
733         if (model >= 3)
734                 return -EINVAL;
735         regs->tstate = (regs->tstate & ~TSTATE_MM) | (model << 14);
736         return 0;
737 }
738
739 SYSCALL_DEFINE5(rt_sigaction, int, sig, const struct sigaction __user *, act,
740                 struct sigaction __user *, oact, void __user *, restorer,
741                 size_t, sigsetsize)
742 {
743         struct k_sigaction new_ka, old_ka;
744         int ret;
745
746         /* XXX: Don't preclude handling different sized sigset_t's.  */
747         if (sigsetsize != sizeof(sigset_t))
748                 return -EINVAL;
749
750         if (act) {
751                 new_ka.ka_restorer = restorer;
752                 if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
753                         return -EFAULT;
754         }
755
756         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
757
758         if (!ret && oact) {
759                 if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
760                         return -EFAULT;
761         }
762
763         return ret;
764 }
765
766 /*
767  * Do a system call from kernel instead of calling sys_execve so we
768  * end up with proper pt_regs.
769  */
770 int kernel_execve(const char *filename,
771                   const char *const argv[],
772                   const char *const envp[])
773 {
774         long __res;
775         register long __g1 __asm__ ("g1") = __NR_execve;
776         register long __o0 __asm__ ("o0") = (long)(filename);
777         register long __o1 __asm__ ("o1") = (long)(argv);
778         register long __o2 __asm__ ("o2") = (long)(envp);
779         asm volatile ("t 0x6d\n\t"
780                       "sub %%g0, %%o0, %0\n\t"
781                       "movcc %%xcc, %%o0, %0\n\t"
782                       : "=r" (__res), "=&r" (__o0)
783                       : "1" (__o0), "r" (__o1), "r" (__o2), "r" (__g1)
784                       : "cc");
785         return __res;
786 }