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 | * |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 19 | * Outputs: %[r|e]ax is error code (0 or -EFAULT) |
| 20 | * %[r|e]dx contains zero-extended value |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 21 | * %ecx contains the high half for 32-bit __get_user_8 |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 22 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * |
| 24 | * These functions should not modify any other registers, |
| 25 | * as they get called from within inline assembly. |
| 26 | */ |
| 27 | |
| 28 | #include <linux/linkage.h> |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 29 | #include <asm/dwarf2.h> |
Jeremy Fitzhardinge | 0341c14 | 2009-02-13 11:14:01 -0800 | [diff] [blame] | 30 | #include <asm/page_types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/errno.h> |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 32 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/thread_info.h> |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 34 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 35 | #include <asm/smap.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 |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 43 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 44 | 1: movzbl (%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 45 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 46 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 48 | CFI_ENDPROC |
| 49 | ENDPROC(__get_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 51 | ENTRY(__get_user_2) |
| 52 | CFI_STARTPROC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 53 | add $1,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 54 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 55 | GET_THREAD_INFO(%_ASM_DX) |
| 56 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 57 | jae bad_get_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 58 | ASM_STAC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 59 | 2: movzwl -1(%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 60 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 61 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 63 | CFI_ENDPROC |
| 64 | ENDPROC(__get_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 66 | ENTRY(__get_user_4) |
| 67 | CFI_STARTPROC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 68 | add $3,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 69 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 70 | GET_THREAD_INFO(%_ASM_DX) |
| 71 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 72 | jae bad_get_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 73 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 74 | 3: movl -3(%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 75 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 76 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 78 | CFI_ENDPROC |
| 79 | ENDPROC(__get_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 81 | ENTRY(__get_user_8) |
| 82 | CFI_STARTPROC |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_X86_64 |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 84 | add $7,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 85 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 86 | GET_THREAD_INFO(%_ASM_DX) |
| 87 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 88 | jae bad_get_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 89 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 90 | 4: movq -7(%_ASM_AX),%rdx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 91 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 92 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | ret |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 94 | #else |
| 95 | add $7,%_ASM_AX |
| 96 | jc bad_get_user_8 |
| 97 | GET_THREAD_INFO(%_ASM_DX) |
| 98 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
| 99 | jae bad_get_user_8 |
| 100 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 101 | 4: movl -7(%_ASM_AX),%edx |
| 102 | 5: movl -3(%_ASM_AX),%ecx |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 103 | xor %eax,%eax |
| 104 | ASM_CLAC |
| 105 | ret |
| 106 | #endif |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 107 | CFI_ENDPROC |
| 108 | ENDPROC(__get_user_8) |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | bad_get_user: |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 112 | CFI_STARTPROC |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 113 | xor %edx,%edx |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 114 | mov $(-EFAULT),%_ASM_AX |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 115 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 117 | CFI_ENDPROC |
| 118 | END(bad_get_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 120 | #ifdef CONFIG_X86_32 |
| 121 | bad_get_user_8: |
| 122 | CFI_STARTPROC |
| 123 | xor %edx,%edx |
| 124 | xor %ecx,%ecx |
| 125 | mov $(-EFAULT),%_ASM_AX |
| 126 | ASM_CLAC |
| 127 | ret |
| 128 | CFI_ENDPROC |
| 129 | END(bad_get_user_8) |
| 130 | #endif |
| 131 | |
H. Peter Anvin | 1a27bc0 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 132 | _ASM_EXTABLE(1b,bad_get_user) |
| 133 | _ASM_EXTABLE(2b,bad_get_user) |
| 134 | _ASM_EXTABLE(3b,bad_get_user) |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 135 | #ifdef CONFIG_X86_64 |
H. Peter Anvin | 1a27bc0 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 136 | _ASM_EXTABLE(4b,bad_get_user) |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 137 | #else |
| 138 | _ASM_EXTABLE(4b,bad_get_user_8) |
| 139 | _ASM_EXTABLE(5b,bad_get_user_8) |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 140 | #endif |