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 | * |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 16 | * Inputs: %rax contains the address. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/page.h> |
| 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> |
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) |
| 38 | CFI_STARTPROC |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 39 | GET_THREAD_INFO(%_ASM_DX) |
| 40 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | jae bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 42 | 1: movzb (%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 43 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 50 | add $1,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 51 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 52 | GET_THREAD_INFO(%_ASM_DX) |
| 53 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 54 | jae bad_get_user |
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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 63 | add $3,%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 64 | jc bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 65 | GET_THREAD_INFO(%_ASM_DX) |
| 66 | cmp TI_addr_limit(%_ASM_DX),%_ASM_AX |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 67 | jae bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 68 | 3: mov -3(%_ASM_AX),%edx |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 69 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 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 |
Glauber Costa | 9262875 | 2008-06-24 11:13:16 -0300 | [diff] [blame] | 80 | jae bad_get_user |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 81 | 4: movq -7(%_ASM_AX),%_ASM_DX |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 82 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Glauber Costa | ef8c1a2 | 2008-06-24 11:21:53 -0300 | [diff] [blame] | 89 | xor %edx,%edx |
Glauber Costa | 40faf46 | 2008-06-24 11:37:57 -0300 | [diff] [blame] | 90 | mov $(-EFAULT),%_ASM_AX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" |
Glauber Costa | 87e2f1e | 2008-06-24 12:02:44 -0300 | [diff] [blame^] | 96 | _ASM_PTR 1b,bad_get_user |
| 97 | _ASM_PTR 2b,bad_get_user |
| 98 | _ASM_PTR 3b,bad_get_user |
| 99 | _ASM_PTR 4b,bad_get_user |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | .previous |