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 |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 6 | * (C) Copyright 2008 Glauber Costa |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * These functions have a non-standard call interface |
| 9 | * to make them more efficient, especially as they |
| 10 | * return an error value in addition to the "real" |
| 11 | * return value. |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * __get_user_X |
| 16 | * |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 17 | * Inputs: %[r|e]ax contains the address. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * The register is modified, but all changes are undone |
| 19 | * before returning because the C code doesn't know about it. |
| 20 | * |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 21 | * Outputs: %[r|e]ax is error code (0 or -EFAULT) |
| 22 | * %[r|e]dx contains zero-extended value |
| 23 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Jeremy Fitzhardinge | 0341c14 | 2009-02-13 11:14:01 -0800 | [diff] [blame] | 31 | #include <asm/page_types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 35 | #include <asm/asm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | .text |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 38 | ENTRY(__get_user_1) |
| 39 | CFI_STARTPROC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 40 | GET_THREAD_INFO(%_ASM_DX) |
| 41 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | jae bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 43 | 1: movzb (%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 44 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 46 | CFI_ENDPROC |
| 47 | ENDPROC(__get_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 49 | ENTRY(__get_user_2) |
| 50 | CFI_STARTPROC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 51 | add $1,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 52 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 53 | GET_THREAD_INFO(%_ASM_DX) |
| 54 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 55 | jae bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 56 | 2: movzwl -1(%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 57 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 59 | CFI_ENDPROC |
| 60 | ENDPROC(__get_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 62 | ENTRY(__get_user_4) |
| 63 | CFI_STARTPROC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 64 | add $3,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 65 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 66 | GET_THREAD_INFO(%_ASM_DX) |
| 67 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 68 | jae bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 69 | 3: mov -3(%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 70 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 72 | CFI_ENDPROC |
| 73 | ENDPROC(__get_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 75 | #ifdef CONFIG_X86_64 |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 76 | ENTRY(__get_user_8) |
| 77 | CFI_STARTPROC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 78 | add $7,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 79 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 80 | GET_THREAD_INFO(%_ASM_DX) |
| 81 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 82 | jae bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 83 | 4: movq -7(%_ASM_AX),%_ASM_DX |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 84 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 86 | CFI_ENDPROC |
| 87 | ENDPROC(__get_user_8) |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 88 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | bad_get_user: |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 91 | CFI_STARTPROC |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 92 | xor %edx,%edx |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 93 | mov $(-EFAULT),%_ASM_AX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 95 | CFI_ENDPROC |
| 96 | END(bad_get_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
H. Peter Anvin | 1a27bc0 | 2012-04-20 12:19:51 -0700 | [diff] [blame^] | 98 | _ASM_EXTABLE(1b,bad_get_user) |
| 99 | _ASM_EXTABLE(2b,bad_get_user) |
| 100 | _ASM_EXTABLE(3b,bad_get_user) |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 101 | #ifdef CONFIG_X86_64 |
H. Peter Anvin | 1a27bc0 | 2012-04-20 12:19:51 -0700 | [diff] [blame^] | 102 | _ASM_EXTABLE(4b,bad_get_user) |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 103 | #endif |