vserver 1.9.5.x5
[linux-2.6.git] / arch / sparc64 / kernel / sys_sparc.c
1 /* $Id: sys_sparc.c,v 1.57 2002/02/09 19:49:30 davem Exp $
2  * linux/arch/sparc64/kernel/sys_sparc.c
3  *
4  * This file contains various random system calls that
5  * have a non-standard calling sequence on the Linux/sparc
6  * platform.
7  */
8
9 #include <linux/config.h>
10 #include <linux/errno.h>
11 #include <linux/types.h>
12 #include <linux/sched.h>
13 #include <linux/fs.h>
14 #include <linux/file.h>
15 #include <linux/mm.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>
24 #include <linux/slab.h>
25 #include <linux/syscalls.h>
26 #include <linux/ipc.h>
27 #include <linux/personality.h>
28 #include <linux/vs_cvirt.h>
29
30 #include <asm/uaccess.h>
31 #include <asm/ipc.h>
32 #include <asm/utrap.h>
33 #include <asm/perfctr.h>
34
35 /* #define DEBUG_UNIMP_SYSCALL */
36
37 /* XXX Make this per-binary type, this way we can detect the type of
38  * XXX a binary.  Every Sparc executable calls this very early on.
39  */
40 asmlinkage unsigned long sys_getpagesize(void)
41 {
42         return PAGE_SIZE;
43 }
44
45 #define COLOUR_ALIGN(addr,pgoff)                \
46         ((((addr)+SHMLBA-1)&~(SHMLBA-1)) +      \
47          (((pgoff)<<PAGE_SHIFT) & (SHMLBA-1)))
48
49 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
50 {
51         struct mm_struct *mm = current->mm;
52         struct vm_area_struct * vma;
53         unsigned long task_size = TASK_SIZE;
54         unsigned long start_addr;
55         int do_color_align;
56
57         if (flags & MAP_FIXED) {
58                 /* We do not accept a shared mapping if it would violate
59                  * cache aliasing constraints.
60                  */
61                 if ((flags & MAP_SHARED) &&
62                     ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
63                         return -EINVAL;
64                 return addr;
65         }
66
67         if (test_thread_flag(TIF_32BIT))
68                 task_size = 0xf0000000UL;
69         if (len > task_size || len > -PAGE_OFFSET)
70                 return -ENOMEM;
71
72         do_color_align = 0;
73         if (filp || (flags & MAP_SHARED))
74                 do_color_align = 1;
75
76         if (addr) {
77                 if (do_color_align)
78                         addr = COLOUR_ALIGN(addr, pgoff);
79                 else
80                         addr = PAGE_ALIGN(addr);
81
82                 vma = find_vma(mm, addr);
83                 if (task_size - len >= addr &&
84                     (!vma || addr + len <= vma->vm_start))
85                         return addr;
86         }
87
88         start_addr = addr = mm->free_area_cache;
89
90         task_size -= len;
91
92 full_search:
93         if (do_color_align)
94                 addr = COLOUR_ALIGN(addr, pgoff);
95         else
96                 addr = PAGE_ALIGN(addr);
97
98         for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
99                 /* At this point:  (!vma || addr < vma->vm_end). */
100                 if (addr < PAGE_OFFSET && -PAGE_OFFSET - len < addr) {
101                         addr = PAGE_OFFSET;
102                         vma = find_vma(mm, PAGE_OFFSET);
103                 }
104                 if (task_size < addr) {
105                         if (start_addr != TASK_UNMAPPED_BASE) {
106                                 start_addr = addr = TASK_UNMAPPED_BASE;
107                                 goto full_search;
108                         }
109                         return -ENOMEM;
110                 }
111                 if (!vma || addr + len <= vma->vm_start) {
112                         /*
113                          * Remember the place where we stopped the search:
114                          */
115                         mm->free_area_cache = addr + len;
116                         return addr;
117                 }
118                 addr = vma->vm_end;
119                 if (do_color_align)
120                         addr = COLOUR_ALIGN(addr, pgoff);
121         }
122 }
123
124 /* Try to align mapping such that we align it as much as possible. */
125 unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, unsigned long len, unsigned long pgoff, unsigned long flags)
126 {
127         unsigned long align_goal, addr = -ENOMEM;
128
129         if (flags & MAP_FIXED) {
130                 /* Ok, don't mess with it. */
131                 return get_unmapped_area(NULL, addr, len, pgoff, flags);
132         }
133         flags &= ~MAP_SHARED;
134
135         align_goal = PAGE_SIZE;
136         if (len >= (4UL * 1024 * 1024))
137                 align_goal = (4UL * 1024 * 1024);
138         else if (len >= (512UL * 1024))
139                 align_goal = (512UL * 1024);
140         else if (len >= (64UL * 1024))
141                 align_goal = (64UL * 1024);
142
143         do {
144                 addr = get_unmapped_area(NULL, orig_addr, len + (align_goal - PAGE_SIZE), pgoff, flags);
145                 if (!(addr & ~PAGE_MASK)) {
146                         addr = (addr + (align_goal - 1UL)) & ~(align_goal - 1UL);
147                         break;
148                 }
149
150                 if (align_goal == (4UL * 1024 * 1024))
151                         align_goal = (512UL * 1024);
152                 else if (align_goal == (512UL * 1024))
153                         align_goal = (64UL * 1024);
154                 else
155                         align_goal = PAGE_SIZE;
156         } while ((addr & ~PAGE_MASK) && align_goal > PAGE_SIZE);
157
158         /* Mapping is smaller than 64K or larger areas could not
159          * be obtained.
160          */
161         if (addr & ~PAGE_MASK)
162                 addr = get_unmapped_area(NULL, orig_addr, len, pgoff, flags);
163
164         return addr;
165 }
166
167 asmlinkage unsigned long sparc_brk(unsigned long brk)
168 {
169         /* People could try to be nasty and use ta 0x6d in 32bit programs */
170         if (test_thread_flag(TIF_32BIT) &&
171             brk >= 0xf0000000UL)
172                 return current->mm->brk;
173
174         if ((current->mm->brk & PAGE_OFFSET) != (brk & PAGE_OFFSET))
175                 return current->mm->brk;
176         return sys_brk(brk);
177 }
178                                                                 
179 /*
180  * sys_pipe() is the normal C calling standard for creating
181  * a pipe. It's not the way unix traditionally does this, though.
182  */
183 asmlinkage long sparc_pipe(struct pt_regs *regs)
184 {
185         int fd[2];
186         int error;
187
188         error = do_pipe(fd);
189         if (error)
190                 goto out;
191         regs->u_regs[UREG_I1] = fd[1];
192         error = fd[0];
193 out:
194         return error;
195 }
196
197 /*
198  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
199  *
200  * This is really horribly ugly.
201  */
202
203 asmlinkage long sys_ipc(unsigned int call, int first, unsigned long second,
204                         unsigned long third, void __user *ptr, long fifth)
205 {
206         int err;
207
208         /* No need for backward compatibility. We can start fresh... */
209         if (call <= SEMCTL) {
210                 switch (call) {
211                 case SEMOP:
212                         err = sys_semtimedop(first, ptr,
213                                              (unsigned)second, NULL);
214                         goto out;
215                 case SEMTIMEDOP:
216                         err = sys_semtimedop(first, ptr, (unsigned)second,
217                                 (const struct timespec __user *) fifth);
218                         goto out;
219                 case SEMGET:
220                         err = sys_semget(first, (int)second, (int)third);
221                         goto out;
222                 case SEMCTL: {
223                         union semun fourth;
224                         err = -EINVAL;
225                         if (!ptr)
226                                 goto out;
227                         err = -EFAULT;
228                         if (get_user(fourth.__pad,
229                                      (void __user * __user *) ptr))
230                                 goto out;
231                         err = sys_semctl(first, (int)second | IPC_64,
232                                          (int)third, fourth);
233                         goto out;
234                 }
235                 default:
236                         err = -ENOSYS;
237                         goto out;
238                 };
239         }
240         if (call <= MSGCTL) {
241                 switch (call) {
242                 case MSGSND:
243                         err = sys_msgsnd(first, ptr, (size_t)second,
244                                          (int)third);
245                         goto out;
246                 case MSGRCV:
247                         err = sys_msgrcv(first, ptr, (size_t)second, fifth,
248                                          (int)third);
249                         goto out;
250                 case MSGGET:
251                         err = sys_msgget((key_t)first, (int)second);
252                         goto out;
253                 case MSGCTL:
254                         err = sys_msgctl(first, (int)second | IPC_64, ptr);
255                         goto out;
256                 default:
257                         err = -ENOSYS;
258                         goto out;
259                 };
260         }
261         if (call <= SHMCTL) {
262                 switch (call) {
263                 case SHMAT: {
264                         ulong raddr;
265                         err = do_shmat(first, ptr, (int)second, &raddr);
266                         if (!err) {
267                                 if (put_user(raddr,
268                                              (ulong __user *) third))
269                                         err = -EFAULT;
270                         }
271                         goto out;
272                 }
273                 case SHMDT:
274                         err = sys_shmdt(ptr);
275                         goto out;
276                 case SHMGET:
277                         err = sys_shmget(first, (size_t)second, (int)third);
278                         goto out;
279                 case SHMCTL:
280                         err = sys_shmctl(first, (int)second | IPC_64, ptr);
281                         goto out;
282                 default:
283                         err = -ENOSYS;
284                         goto out;
285                 };
286         } else {
287                 err = -ENOSYS;
288         }
289 out:
290         return err;
291 }
292
293 asmlinkage long sparc64_newuname(struct new_utsname __user *name)
294 {
295         int ret = sys_newuname(name);
296         
297         if (current->personality == PER_LINUX32 && !ret) {
298                 ret = (copy_to_user(name->machine, "sparc\0\0", 8)
299                        ? -EFAULT : 0);
300         }
301         return ret;
302 }
303
304 asmlinkage long sparc64_personality(unsigned long personality)
305 {
306         int ret;
307
308         if (current->personality == PER_LINUX32 &&
309             personality == PER_LINUX)
310                 personality = PER_LINUX32;
311         ret = sys_personality(personality);
312         if (ret == PER_LINUX32)
313                 ret = PER_LINUX;
314
315         return ret;
316 }
317
318 /* Linux version of mmap */
319 asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
320         unsigned long prot, unsigned long flags, unsigned long fd,
321         unsigned long off)
322 {
323         struct file * file = NULL;
324         unsigned long retval = -EBADF;
325
326         if (!(flags & MAP_ANONYMOUS)) {
327                 file = fget(fd);
328                 if (!file)
329                         goto out;
330         }
331         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
332         len = PAGE_ALIGN(len);
333         retval = -EINVAL;
334
335         if (test_thread_flag(TIF_32BIT)) {
336                 if (len > 0xf0000000UL ||
337                     ((flags & MAP_FIXED) && addr > 0xf0000000UL - len))
338                         goto out_putf;
339         } else {
340                 if (len > -PAGE_OFFSET ||
341                     ((flags & MAP_FIXED) &&
342                      addr < PAGE_OFFSET && addr + len > -PAGE_OFFSET))
343                         goto out_putf;
344         }
345
346         down_write(&current->mm->mmap_sem);
347         retval = do_mmap(file, addr, len, prot, flags, off);
348         up_write(&current->mm->mmap_sem);
349
350 out_putf:
351         if (file)
352                 fput(file);
353 out:
354         return retval;
355 }
356
357 asmlinkage long sys64_munmap(unsigned long addr, size_t len)
358 {
359         long ret;
360
361         if (len > -PAGE_OFFSET ||
362             (addr < PAGE_OFFSET && addr + len > -PAGE_OFFSET))
363                 return -EINVAL;
364         down_write(&current->mm->mmap_sem);
365         ret = do_munmap(current->mm, addr, len);
366         up_write(&current->mm->mmap_sem);
367         return ret;
368 }
369
370 extern unsigned long do_mremap(unsigned long addr,
371         unsigned long old_len, unsigned long new_len,
372         unsigned long flags, unsigned long new_addr);
373                 
374 asmlinkage unsigned long sys64_mremap(unsigned long addr,
375         unsigned long old_len, unsigned long new_len,
376         unsigned long flags, unsigned long new_addr)
377 {
378         struct vm_area_struct *vma;
379         unsigned long ret = -EINVAL;
380         if (test_thread_flag(TIF_32BIT))
381                 goto out;
382         if (old_len > -PAGE_OFFSET || new_len > -PAGE_OFFSET)
383                 goto out;
384         if (addr < PAGE_OFFSET && addr + old_len > -PAGE_OFFSET)
385                 goto out;
386         down_write(&current->mm->mmap_sem);
387         if (flags & MREMAP_FIXED) {
388                 if (new_addr < PAGE_OFFSET &&
389                     new_addr + new_len > -PAGE_OFFSET)
390                         goto out_sem;
391         } else if (addr < PAGE_OFFSET && addr + new_len > -PAGE_OFFSET) {
392                 unsigned long map_flags = 0;
393                 struct file *file = NULL;
394
395                 ret = -ENOMEM;
396                 if (!(flags & MREMAP_MAYMOVE))
397                         goto out_sem;
398
399                 vma = find_vma(current->mm, addr);
400                 if (vma) {
401                         if (vma->vm_flags & VM_SHARED)
402                                 map_flags |= MAP_SHARED;
403                         file = vma->vm_file;
404                 }
405
406                 /* MREMAP_FIXED checked above. */
407                 new_addr = get_unmapped_area(file, addr, new_len,
408                                     vma ? vma->vm_pgoff : 0,
409                                     map_flags);
410                 ret = new_addr;
411                 if (new_addr & ~PAGE_MASK)
412                         goto out_sem;
413                 flags |= MREMAP_FIXED;
414         }
415         ret = do_mremap(addr, old_len, new_len, flags, new_addr);
416 out_sem:
417         up_write(&current->mm->mmap_sem);
418 out:
419         return ret;       
420 }
421
422 /* we come to here via sys_nis_syscall so it can setup the regs argument */
423 asmlinkage unsigned long c_sys_nis_syscall(struct pt_regs *regs)
424 {
425         static int count;
426         
427         /* Don't make the system unusable, if someone goes stuck */
428         if (count++ > 5)
429                 return -ENOSYS;
430
431         printk ("Unimplemented SPARC system call %ld\n",regs->u_regs[1]);
432 #ifdef DEBUG_UNIMP_SYSCALL      
433         show_regs (regs);
434 #endif
435
436         return -ENOSYS;
437 }
438
439 /* #define DEBUG_SPARC_BREAKPOINT */
440
441 asmlinkage void sparc_breakpoint(struct pt_regs *regs)
442 {
443         siginfo_t info;
444
445         if (test_thread_flag(TIF_32BIT)) {
446                 regs->tpc &= 0xffffffff;
447                 regs->tnpc &= 0xffffffff;
448         }
449 #ifdef DEBUG_SPARC_BREAKPOINT
450         printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n", regs->tpc, regs->tnpc);
451 #endif
452         info.si_signo = SIGTRAP;
453         info.si_errno = 0;
454         info.si_code = TRAP_BRKPT;
455         info.si_addr = (void __user *)regs->tpc;
456         info.si_trapno = 0;
457         force_sig_info(SIGTRAP, &info, current);
458 #ifdef DEBUG_SPARC_BREAKPOINT
459         printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n", regs->tpc, regs->tnpc);
460 #endif
461 }
462
463 extern void check_pending(int signum);
464
465 asmlinkage long sys_getdomainname(char __user *name, int len)
466 {
467         int nlen;
468         int err = -EFAULT;
469
470         down_read(&uts_sem);
471         
472         nlen = strlen(vx_new_uts(domainname)) + 1;
473
474         if (nlen < len)
475                 len = nlen;
476         if (len > __NEW_UTS_LEN)
477                 goto done;
478         if (copy_to_user(name, vx_new_uts(domainname), len))
479                 goto done;
480         err = 0;
481 done:
482         up_read(&uts_sem);
483         return err;
484 }
485
486 asmlinkage long solaris_syscall(struct pt_regs *regs)
487 {
488         static int count;
489
490         regs->tpc = regs->tnpc;
491         regs->tnpc += 4;
492         if (test_thread_flag(TIF_32BIT)) {
493                 regs->tpc &= 0xffffffff;
494                 regs->tnpc &= 0xffffffff;
495         }
496         if (++count <= 5) {
497                 printk ("For Solaris binary emulation you need solaris module loaded\n");
498                 show_regs (regs);
499         }
500         send_sig(SIGSEGV, current, 1);
501
502         return -ENOSYS;
503 }
504
505 #ifndef CONFIG_SUNOS_EMUL
506 asmlinkage long sunos_syscall(struct pt_regs *regs)
507 {
508         static int count;
509
510         regs->tpc = regs->tnpc;
511         regs->tnpc += 4;
512         if (test_thread_flag(TIF_32BIT)) {
513                 regs->tpc &= 0xffffffff;
514                 regs->tnpc &= 0xffffffff;
515         }
516         if (++count <= 20)
517                 printk ("SunOS binary emulation not compiled in\n");
518         force_sig(SIGSEGV, current);
519
520         return -ENOSYS;
521 }
522 #endif
523
524 asmlinkage long sys_utrap_install(utrap_entry_t type,
525                                   utrap_handler_t new_p,
526                                   utrap_handler_t new_d,
527                                   utrap_handler_t __user *old_p,
528                                   utrap_handler_t __user *old_d)
529 {
530         if (type < UT_INSTRUCTION_EXCEPTION || type > UT_TRAP_INSTRUCTION_31)
531                 return -EINVAL;
532         if (new_p == (utrap_handler_t)(long)UTH_NOCHANGE) {
533                 if (old_p) {
534                         if (!current_thread_info()->utraps) {
535                                 if (put_user(NULL, old_p))
536                                         return -EFAULT;
537                         } else {
538                                 if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
539                                         return -EFAULT;
540                         }
541                 }
542                 if (old_d) {
543                         if (put_user(NULL, old_d))
544                                 return -EFAULT;
545                 }
546                 return 0;
547         }
548         if (!current_thread_info()->utraps) {
549                 current_thread_info()->utraps =
550                         kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long), GFP_KERNEL);
551                 if (!current_thread_info()->utraps)
552                         return -ENOMEM;
553                 current_thread_info()->utraps[0] = 1;
554                 memset(current_thread_info()->utraps+1, 0,
555                        UT_TRAP_INSTRUCTION_31*sizeof(long));
556         } else {
557                 if ((utrap_handler_t)current_thread_info()->utraps[type] != new_p &&
558                     current_thread_info()->utraps[0] > 1) {
559                         long *p = current_thread_info()->utraps;
560
561                         current_thread_info()->utraps =
562                                 kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long),
563                                         GFP_KERNEL);
564                         if (!current_thread_info()->utraps) {
565                                 current_thread_info()->utraps = p;
566                                 return -ENOMEM;
567                         }
568                         p[0]--;
569                         current_thread_info()->utraps[0] = 1;
570                         memcpy(current_thread_info()->utraps+1, p+1,
571                                UT_TRAP_INSTRUCTION_31*sizeof(long));
572                 }
573         }
574         if (old_p) {
575                 if (put_user((utrap_handler_t)(current_thread_info()->utraps[type]), old_p))
576                         return -EFAULT;
577         }
578         if (old_d) {
579                 if (put_user(NULL, old_d))
580                         return -EFAULT;
581         }
582         current_thread_info()->utraps[type] = (long)new_p;
583
584         return 0;
585 }
586
587 long sparc_memory_ordering(unsigned long model, struct pt_regs *regs)
588 {
589         if (model >= 3)
590                 return -EINVAL;
591         regs->tstate = (regs->tstate & ~TSTATE_MM) | (model << 14);
592         return 0;
593 }
594
595 asmlinkage long sys_rt_sigaction(int sig,
596                                  const struct sigaction __user *act,
597                                  struct sigaction __user *oact,
598                                  void __user *restorer,
599                                  size_t sigsetsize)
600 {
601         struct k_sigaction new_ka, old_ka;
602         int ret;
603
604         /* XXX: Don't preclude handling different sized sigset_t's.  */
605         if (sigsetsize != sizeof(sigset_t))
606                 return -EINVAL;
607
608         if (act) {
609                 new_ka.ka_restorer = restorer;
610                 if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
611                         return -EFAULT;
612         }
613
614         ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
615
616         if (!ret && oact) {
617                 if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
618                         return -EFAULT;
619         }
620
621         return ret;
622 }
623
624 /* Invoked by rtrap code to update performance counters in
625  * user space.
626  */
627 asmlinkage void update_perfctrs(void)
628 {
629         unsigned long pic, tmp;
630
631         read_pic(pic);
632         tmp = (current_thread_info()->kernel_cntd0 += (unsigned int)pic);
633         __put_user(tmp, current_thread_info()->user_cntd0);
634         tmp = (current_thread_info()->kernel_cntd1 += (pic >> 32));
635         __put_user(tmp, current_thread_info()->user_cntd1);
636         reset_pic();
637 }
638
639 asmlinkage long sys_perfctr(int opcode, unsigned long arg0, unsigned long arg1, unsigned long arg2)
640 {
641         int err = 0;
642
643         switch(opcode) {
644         case PERFCTR_ON:
645                 current_thread_info()->pcr_reg = arg2;
646                 current_thread_info()->user_cntd0 = (u64 __user *) arg0;
647                 current_thread_info()->user_cntd1 = (u64 __user *) arg1;
648                 current_thread_info()->kernel_cntd0 =
649                         current_thread_info()->kernel_cntd1 = 0;
650                 write_pcr(arg2);
651                 reset_pic();
652                 set_thread_flag(TIF_PERFCTR);
653                 break;
654
655         case PERFCTR_OFF:
656                 err = -EINVAL;
657                 if (test_thread_flag(TIF_PERFCTR)) {
658                         current_thread_info()->user_cntd0 =
659                                 current_thread_info()->user_cntd1 = NULL;
660                         current_thread_info()->pcr_reg = 0;
661                         write_pcr(0);
662                         clear_thread_flag(TIF_PERFCTR);
663                         err = 0;
664                 }
665                 break;
666
667         case PERFCTR_READ: {
668                 unsigned long pic, tmp;
669
670                 if (!test_thread_flag(TIF_PERFCTR)) {
671                         err = -EINVAL;
672                         break;
673                 }
674                 read_pic(pic);
675                 tmp = (current_thread_info()->kernel_cntd0 += (unsigned int)pic);
676                 err |= __put_user(tmp, current_thread_info()->user_cntd0);
677                 tmp = (current_thread_info()->kernel_cntd1 += (pic >> 32));
678                 err |= __put_user(tmp, current_thread_info()->user_cntd1);
679                 reset_pic();
680                 break;
681         }
682
683         case PERFCTR_CLRPIC:
684                 if (!test_thread_flag(TIF_PERFCTR)) {
685                         err = -EINVAL;
686                         break;
687                 }
688                 current_thread_info()->kernel_cntd0 =
689                         current_thread_info()->kernel_cntd1 = 0;
690                 reset_pic();
691                 break;
692
693         case PERFCTR_SETPCR: {
694                 u64 __user *user_pcr = (u64 __user *)arg0;
695
696                 if (!test_thread_flag(TIF_PERFCTR)) {
697                         err = -EINVAL;
698                         break;
699                 }
700                 err |= __get_user(current_thread_info()->pcr_reg, user_pcr);
701                 write_pcr(current_thread_info()->pcr_reg);
702                 current_thread_info()->kernel_cntd0 =
703                         current_thread_info()->kernel_cntd1 = 0;
704                 reset_pic();
705                 break;
706         }
707
708         case PERFCTR_GETPCR: {
709                 u64 __user *user_pcr = (u64 __user *)arg0;
710
711                 if (!test_thread_flag(TIF_PERFCTR)) {
712                         err = -EINVAL;
713                         break;
714                 }
715                 err |= __put_user(current_thread_info()->pcr_reg, user_pcr);
716                 break;
717         }
718
719         default:
720                 err = -EINVAL;
721                 break;
722         };
723         return err;
724 }