Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * __get_user functions. |
| 3 | * |
| 4 | * (C) Copyright 1998 Linus Torvalds |
| 5 | * (C) Copyright 2005 Andi Kleen |
| 6 | * |
| 7 | * These functions have a non-standard call interface |
| 8 | * to make them more efficient, especially as they |
| 9 | * return an error value in addition to the "real" |
| 10 | * return value. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * __get_user_X |
| 15 | * |
| 16 | * Inputs: %rcx contains the address. |
| 17 | * The register is modified, but all changes are undone |
| 18 | * before returning because the C code doesn't know about it. |
| 19 | * |
| 20 | * Outputs: %rax is error code (0 or -EFAULT) |
| 21 | * %rdx contains zero-extended value |
| 22 | * |
| 23 | * %r8 is destroyed. |
| 24 | * |
| 25 | * These functions should not modify any other registers, |
| 26 | * as they get called from within inline assembly. |
| 27 | */ |
| 28 | |
| 29 | #include <linux/linkage.h> |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 30 | #include <asm/dwarf2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/page.h> |
| 32 | #include <asm/errno.h> |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 33 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/thread_info.h> |
| 35 | |
| 36 | .text |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 37 | ENTRY(__get_user_1) |
| 38 | CFI_STARTPROC |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 39 | GET_THREAD_INFO(%rdx) |
| 40 | cmpq threadinfo_addr_limit(%rdx),%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | jae bad_get_user |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 42 | 1: movzb (%rax),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | xorl %eax,%eax |
| 44 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 45 | CFI_ENDPROC |
| 46 | ENDPROC(__get_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 48 | ENTRY(__get_user_2) |
| 49 | CFI_STARTPROC |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 50 | GET_THREAD_INFO(%rdx) |
| 51 | addq $1,%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | jc 20f |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 53 | cmpq threadinfo_addr_limit(%rdx),%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | jae 20f |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 55 | decq %rax |
| 56 | 2: movzwl (%rax),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | xorl %eax,%eax |
| 58 | ret |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 59 | 20: decq %rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | jmp bad_get_user |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 61 | CFI_ENDPROC |
| 62 | ENDPROC(__get_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 64 | ENTRY(__get_user_4) |
| 65 | CFI_STARTPROC |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 66 | GET_THREAD_INFO(%rdx) |
| 67 | addq $3,%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | jc 30f |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 69 | cmpq threadinfo_addr_limit(%rdx),%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | jae 30f |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 71 | subq $3,%rax |
| 72 | 3: movl (%rax),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | xorl %eax,%eax |
| 74 | ret |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 75 | 30: subq $3,%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | jmp bad_get_user |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 77 | CFI_ENDPROC |
| 78 | ENDPROC(__get_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 80 | ENTRY(__get_user_8) |
| 81 | CFI_STARTPROC |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 82 | GET_THREAD_INFO(%rdx) |
| 83 | addq $7,%rax |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 84 | jc 40f |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 85 | cmpq threadinfo_addr_limit(%rdx),%rax |
Alexander Nyberg | 3a6fd75 | 2005-04-21 07:59:51 -0700 | [diff] [blame] | 86 | jae 40f |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 87 | subq $7,%rax |
| 88 | 4: movq (%rax),%rdx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | xorl %eax,%eax |
| 90 | ret |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame^] | 91 | 40: subq $7,%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | jmp bad_get_user |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 93 | CFI_ENDPROC |
| 94 | ENDPROC(__get_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | bad_get_user: |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 97 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | xorl %edx,%edx |
| 99 | movq $(-EFAULT),%rax |
| 100 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 101 | CFI_ENDPROC |
| 102 | END(bad_get_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | .section __ex_table,"a" |
| 105 | .quad 1b,bad_get_user |
| 106 | .quad 2b,bad_get_user |
| 107 | .quad 3b,bad_get_user |
| 108 | .quad 4b,bad_get_user |
| 109 | .previous |