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