Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * __put_user functions. |
| 3 | * |
| 4 | * (C) Copyright 2005 Linus Torvalds |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 5 | * (C) Copyright 2005 Andi Kleen |
| 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 | */ |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 13 | #include <linux/linkage.h> |
| 14 | #include <asm/dwarf2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/thread_info.h> |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 16 | #include <asm/errno.h> |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 17 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 18 | #include <asm/smap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | |
| 21 | /* |
| 22 | * __put_user_X |
| 23 | * |
| 24 | * Inputs: %eax[:%edx] contains the data |
| 25 | * %ecx contains the address |
| 26 | * |
| 27 | * Outputs: %eax is error code (0 or -EFAULT) |
| 28 | * |
| 29 | * These functions should not modify any other registers, |
| 30 | * as they get called from within inline assembly. |
| 31 | */ |
| 32 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 33 | #define ENTER CFI_STARTPROC ; \ |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 34 | GET_THREAD_INFO(%_ASM_BX) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 35 | #define EXIT ASM_CLAC ; \ |
| 36 | ret ; \ |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 37 | CFI_ENDPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | .text |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 40 | ENTRY(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | ENTER |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 42 | cmp TI_addr_limit(%_ASM_BX),%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 44 | ASM_STAC |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 45 | 1: movb %al,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 46 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 48 | ENDPROC(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 50 | ENTRY(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | ENTER |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 52 | mov TI_addr_limit(%_ASM_BX),%_ASM_BX |
| 53 | sub $1,%_ASM_BX |
| 54 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 56 | ASM_STAC |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 57 | 2: movw %ax,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 58 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 60 | ENDPROC(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 62 | ENTRY(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | ENTER |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 64 | mov TI_addr_limit(%_ASM_BX),%_ASM_BX |
| 65 | sub $3,%_ASM_BX |
| 66 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 68 | ASM_STAC |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 69 | 3: movl %eax,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 70 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 72 | ENDPROC(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 74 | ENTRY(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | ENTER |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 76 | mov TI_addr_limit(%_ASM_BX),%_ASM_BX |
| 77 | sub $7,%_ASM_BX |
| 78 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 80 | ASM_STAC |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 81 | 4: mov %_ASM_AX,(%_ASM_CX) |
| 82 | #ifdef CONFIG_X86_32 |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 83 | 5: movl %edx,4(%_ASM_CX) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 84 | #endif |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 85 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 87 | ENDPROC(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | bad_put_user: |
Glauber Costa | 268cf04 | 2008-06-24 12:40:55 -0300 | [diff] [blame] | 90 | CFI_STARTPROC |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 91 | movl $-EFAULT,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 93 | END(bad_put_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
H. Peter Anvin | a53a96e | 2012-04-20 12:19:52 -0700 | [diff] [blame] | 95 | _ASM_EXTABLE(1b,bad_put_user) |
| 96 | _ASM_EXTABLE(2b,bad_put_user) |
| 97 | _ASM_EXTABLE(3b,bad_put_user) |
| 98 | _ASM_EXTABLE(4b,bad_put_user) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 99 | #ifdef CONFIG_X86_32 |
H. Peter Anvin | a53a96e | 2012-04-20 12:19:52 -0700 | [diff] [blame] | 100 | _ASM_EXTABLE(5b,bad_put_user) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 101 | #endif |