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 | addq $1,%rax |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame^] | 51 | jc bad_get_user |
| 52 | GET_THREAD_INFO(%rdx) |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame] | 53 | cmpq threadinfo_addr_limit(%rdx),%rax |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame^] | 54 | jae bad_get_user |
| 55 | 2: movzwl -1(%rax),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | xorl %eax,%eax |
| 57 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 58 | CFI_ENDPROC |
| 59 | ENDPROC(__get_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 61 | ENTRY(__get_user_4) |
| 62 | CFI_STARTPROC |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame] | 63 | addq $3,%rax |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame^] | 64 | jc bad_get_user |
| 65 | GET_THREAD_INFO(%rdx) |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame] | 66 | cmpq threadinfo_addr_limit(%rdx),%rax |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame^] | 67 | jae bad_get_user |
| 68 | 3: movl -3(%rax),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | xorl %eax,%eax |
| 70 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 71 | CFI_ENDPROC |
| 72 | ENDPROC(__get_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 74 | ENTRY(__get_user_8) |
| 75 | CFI_STARTPROC |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame] | 76 | addq $7,%rax |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame^] | 77 | jc bad_get_user |
| 78 | GET_THREAD_INFO(%rdx) |
Glauber Costa | edf1016 | 2008-06-13 16:35:52 -0300 | [diff] [blame] | 79 | cmpq threadinfo_addr_limit(%rdx),%rax |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame^] | 80 | jae bad_get_user |
| 81 | 4: movq -7(%rax),%rdx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | xorl %eax,%eax |
| 83 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 84 | CFI_ENDPROC |
| 85 | ENDPROC(__get_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | bad_get_user: |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 88 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | xorl %edx,%edx |
| 90 | movq $(-EFAULT),%rax |
| 91 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 92 | CFI_ENDPROC |
| 93 | END(bad_get_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | .section __ex_table,"a" |
| 96 | .quad 1b,bad_get_user |
| 97 | .quad 2b,bad_get_user |
| 98 | .quad 3b,bad_get_user |
| 99 | .quad 4b,bad_get_user |
| 100 | .previous |