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> |
Jeremy Fitzhardinge | 0341c14 | 2009-02-13 11:14:01 -0800 | [diff] [blame] | 29 | #include <asm/page_types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/errno.h> |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 31 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/thread_info.h> |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 33 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 34 | #include <asm/smap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | .text |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 37 | ENTRY(__get_user_1) |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 38 | GET_THREAD_INFO(%_ASM_DX) |
| 39 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | jae bad_get_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 41 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 42 | 1: movzbl (%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 43 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 44 | ASM_CLAC |
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 | 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) |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 49 | add $1,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 50 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 51 | GET_THREAD_INFO(%_ASM_DX) |
| 52 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 53 | jae bad_get_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 54 | ASM_STAC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 55 | 2: movzwl -1(%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 56 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 57 | ASM_CLAC |
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 | 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) |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 62 | add $3,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 63 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 64 | GET_THREAD_INFO(%_ASM_DX) |
| 65 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 66 | jae bad_get_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 67 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 68 | 3: movl -3(%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 69 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 70 | ASM_CLAC |
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 | 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) |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 75 | #ifdef CONFIG_X86_64 |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 76 | add $7,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 77 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 78 | GET_THREAD_INFO(%_ASM_DX) |
| 79 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 80 | jae bad_get_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 81 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 82 | 4: movq -7(%_ASM_AX),%rdx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 83 | xor %eax,%eax |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 84 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | ret |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 86 | #else |
| 87 | add $7,%_ASM_AX |
| 88 | jc bad_get_user_8 |
| 89 | GET_THREAD_INFO(%_ASM_DX) |
| 90 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
| 91 | jae bad_get_user_8 |
| 92 | ASM_STAC |
H. Peter Anvin | 1664016 | 2013-02-11 23:14:48 -0800 | [diff] [blame] | 93 | 4: movl -7(%_ASM_AX),%edx |
| 94 | 5: movl -3(%_ASM_AX),%ecx |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 95 | xor %eax,%eax |
| 96 | ASM_CLAC |
| 97 | ret |
| 98 | #endif |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 99 | ENDPROC(__get_user_8) |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | bad_get_user: |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 103 | xor %edx,%edx |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 104 | mov $(-EFAULT),%_ASM_AX |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 105 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | ret |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 107 | END(bad_get_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 109 | #ifdef CONFIG_X86_32 |
| 110 | bad_get_user_8: |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 111 | xor %edx,%edx |
| 112 | xor %ecx,%ecx |
| 113 | mov $(-EFAULT),%_ASM_AX |
| 114 | ASM_CLAC |
| 115 | ret |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 116 | END(bad_get_user_8) |
| 117 | #endif |
| 118 | |
H. Peter Anvin | 1a27bc0 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 119 | _ASM_EXTABLE(1b,bad_get_user) |
| 120 | _ASM_EXTABLE(2b,bad_get_user) |
| 121 | _ASM_EXTABLE(3b,bad_get_user) |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 122 | #ifdef CONFIG_X86_64 |
H. Peter Anvin | 1a27bc0 | 2012-04-20 12:19:51 -0700 | [diff] [blame] | 123 | _ASM_EXTABLE(4b,bad_get_user) |
Ville Syrjälä | 96477b4 | 2012-12-12 13:34:03 +0200 | [diff] [blame] | 124 | #else |
| 125 | _ASM_EXTABLE(4b,bad_get_user_8) |
| 126 | _ASM_EXTABLE(5b,bad_get_user_8) |
Glauber Costa | 6c2d458 | 2008-06-24 12:05:11 -0300 | [diff] [blame] | 127 | #endif |