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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/thread_info.h> |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 15 | #include <asm/errno.h> |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 16 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 17 | #include <asm/smap.h> |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 18 | #include <asm/export.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 | |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 33 | #define ENTER mov PER_CPU_VAR(current_task), %_ASM_BX |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 34 | #define EXIT ASM_CLAC ; \ |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 35 | ret |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | .text |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 38 | ENTRY(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | ENTER |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 40 | cmp TASK_addr_limit(%_ASM_BX),%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 42 | ASM_STAC |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 43 | 1: movb %al,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 44 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 46 | ENDPROC(__put_user_1) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 47 | EXPORT_SYMBOL(__put_user_1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 49 | ENTRY(__put_user_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | ENTER |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 51 | mov TASK_addr_limit(%_ASM_BX),%_ASM_BX |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 52 | sub $1,%_ASM_BX |
| 53 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 55 | ASM_STAC |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 56 | 2: movw %ax,(%_ASM_CX) |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 57 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 59 | ENDPROC(__put_user_2) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 60 | EXPORT_SYMBOL(__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 |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 64 | mov TASK_addr_limit(%_ASM_BX),%_ASM_BX |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 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) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 73 | EXPORT_SYMBOL(__put_user_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 75 | ENTRY(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | ENTER |
Andy Lutomirski | 13d4ea0 | 2016-07-14 13:22:57 -0700 | [diff] [blame] | 77 | mov TASK_addr_limit(%_ASM_BX),%_ASM_BX |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 78 | sub $7,%_ASM_BX |
| 79 | cmp %_ASM_BX,%_ASM_CX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | jae bad_put_user |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 81 | ASM_STAC |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 82 | 4: mov %_ASM_AX,(%_ASM_CX) |
| 83 | #ifdef CONFIG_X86_32 |
Glauber Costa | 2528de4 | 2008-06-24 17:36:31 -0300 | [diff] [blame] | 84 | 5: movl %edx,4(%_ASM_CX) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 85 | #endif |
Glauber Costa | efea505 | 2008-06-24 16:59:05 -0300 | [diff] [blame] | 86 | xor %eax,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 88 | ENDPROC(__put_user_8) |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 89 | EXPORT_SYMBOL(__put_user_8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | bad_put_user: |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 92 | movl $-EFAULT,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | EXIT |
Jan Beulich | 00e065e | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 94 | END(bad_put_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
H. Peter Anvin | a53a96e | 2012-04-20 12:19:52 -0700 | [diff] [blame] | 96 | _ASM_EXTABLE(1b,bad_put_user) |
| 97 | _ASM_EXTABLE(2b,bad_put_user) |
| 98 | _ASM_EXTABLE(3b,bad_put_user) |
| 99 | _ASM_EXTABLE(4b,bad_put_user) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 100 | #ifdef CONFIG_X86_32 |
H. Peter Anvin | a53a96e | 2012-04-20 12:19:52 -0700 | [diff] [blame] | 101 | _ASM_EXTABLE(5b,bad_put_user) |
Glauber Costa | 5cbbc3b | 2008-06-24 17:40:14 -0300 | [diff] [blame] | 102 | #endif |