blob: cd5d716d289783cd5c0d853b461701822db96a63 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * __put_user functions.
3 *
4 * (C) Copyright 2005 Linus Torvalds
Glauber Costa5cbbc3b2008-06-24 17:40:14 -03005 * (C) Copyright 2005 Andi Kleen
6 * (C) Copyright 2008 Glauber Costa
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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 Beulich00e065e2007-05-02 19:27:05 +020013#include <linux/linkage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/thread_info.h>
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030015#include <asm/errno.h>
Glauber Costa2528de42008-06-24 17:36:31 -030016#include <asm/asm.h>
H. Peter Anvin63bcff22012-09-21 12:43:12 -070017#include <asm/smap.h>
Al Viro784d5692016-01-11 11:04:34 -050018#include <asm/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
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 Lutomirski13d4ea02016-07-14 13:22:57 -070033#define ENTER mov PER_CPU_VAR(current_task), %_ASM_BX
H. Peter Anvin63bcff22012-09-21 12:43:12 -070034#define EXIT ASM_CLAC ; \
Ingo Molnar131484c2015-05-28 12:21:47 +020035 ret
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37.text
Jan Beulich00e065e2007-05-02 19:27:05 +020038ENTRY(__put_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 ENTER
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070040 cmp TASK_addr_limit(%_ASM_BX),%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070042 ASM_STAC
Glauber Costa2528de42008-06-24 17:36:31 -0300431: movb %al,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030044 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020046ENDPROC(__put_user_1)
Al Viro784d5692016-01-11 11:04:34 -050047EXPORT_SYMBOL(__put_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Jan Beulich00e065e2007-05-02 19:27:05 +020049ENTRY(__put_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 ENTER
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070051 mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
Glauber Costa2528de42008-06-24 17:36:31 -030052 sub $1,%_ASM_BX
53 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070055 ASM_STAC
Glauber Costa2528de42008-06-24 17:36:31 -0300562: movw %ax,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030057 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020059ENDPROC(__put_user_2)
Al Viro784d5692016-01-11 11:04:34 -050060EXPORT_SYMBOL(__put_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Jan Beulich00e065e2007-05-02 19:27:05 +020062ENTRY(__put_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 ENTER
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070064 mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
Glauber Costa2528de42008-06-24 17:36:31 -030065 sub $3,%_ASM_BX
66 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070068 ASM_STAC
Glauber Costa2528de42008-06-24 17:36:31 -0300693: movl %eax,(%_ASM_CX)
Glauber Costaefea5052008-06-24 16:59:05 -030070 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020072ENDPROC(__put_user_4)
Al Viro784d5692016-01-11 11:04:34 -050073EXPORT_SYMBOL(__put_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Jan Beulich00e065e2007-05-02 19:27:05 +020075ENTRY(__put_user_8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 ENTER
Andy Lutomirski13d4ea02016-07-14 13:22:57 -070077 mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
Glauber Costa2528de42008-06-24 17:36:31 -030078 sub $7,%_ASM_BX
79 cmp %_ASM_BX,%_ASM_CX
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 jae bad_put_user
H. Peter Anvin63bcff22012-09-21 12:43:12 -070081 ASM_STAC
Glauber Costa5cbbc3b2008-06-24 17:40:14 -0300824: mov %_ASM_AX,(%_ASM_CX)
83#ifdef CONFIG_X86_32
Glauber Costa2528de42008-06-24 17:36:31 -0300845: movl %edx,4(%_ASM_CX)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030085#endif
Glauber Costaefea5052008-06-24 16:59:05 -030086 xor %eax,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020088ENDPROC(__put_user_8)
Al Viro784d5692016-01-11 11:04:34 -050089EXPORT_SYMBOL(__put_user_8)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91bad_put_user:
Glauber Costa5cbbc3b2008-06-24 17:40:14 -030092 movl $-EFAULT,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 EXIT
Jan Beulich00e065e2007-05-02 19:27:05 +020094END(bad_put_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
H. Peter Anvina53a96e2012-04-20 12:19:52 -070096 _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 Costa5cbbc3b2008-06-24 17:40:14 -0300100#ifdef CONFIG_X86_32
H. Peter Anvina53a96e2012-04-20 12:19:52 -0700101 _ASM_EXTABLE(5b,bad_put_user)
Glauber Costa5cbbc3b2008-06-24 17:40:14 -0300102#endif