blob: df73914e81c8344feccac5df8d5791dcbe92ed60 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/lib/getuser.S
3 *
4 * Copyright (C) 2001 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Idea from x86 version, (C) Copyright 1998 Linus Torvalds
11 *
12 * These functions have a non-standard call interface to make them more
13 * efficient, especially as they return an error value in addition to
14 * the "real" return value.
15 *
16 * __get_user_X
17 *
18 * Inputs: r0 contains the address
Russell King84046632012-09-07 18:22:28 +010019 * r1 contains the address limit, which must be preserved
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * Outputs: r0 is the error code
Daniel Thompsone38361d2014-07-10 20:58:08 +010021 * r2, r3 contains the zero-extended value
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 * lr corrupted
23 *
Russell King4baa9922008-08-02 10:55:55 +010024 * No other registers must be altered. (see <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * for specific ASM register usage).
26 *
27 * Note that ADDR_LIMIT is either 0 or 0xc0000000.
28 * Note also that it is intended that __get_user_bad is not global.
29 */
Catalin Marinas93ed3972008-08-28 11:22:32 +010030#include <linux/linkage.h>
Russell King84046632012-09-07 18:22:28 +010031#include <asm/assembler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/errno.h>
Catalin Marinas247055a2010-09-13 16:03:21 +010033#include <asm/domain.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Catalin Marinas93ed3972008-08-28 11:22:32 +010035ENTRY(__get_user_1)
Russell King84046632012-09-07 18:22:28 +010036 check_uaccess r0, 1, r1, r2, __get_user_bad
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100371: TUSER(ldrb) r2, [r0]
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 mov r0, #0
Russell King6ebbf2c2014-06-30 16:29:12 +010039 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +010040ENDPROC(__get_user_1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Catalin Marinas93ed3972008-08-28 11:22:32 +010042ENTRY(__get_user_2)
Russell King84046632012-09-07 18:22:28 +010043 check_uaccess r0, 2, r1, r2, __get_user_bad
44#ifdef CONFIG_CPU_USE_DOMAINS
45rb .req ip
462: ldrbt r2, [r0], #1
473: ldrbt rb, [r0], #0
Catalin Marinas8b592782009-07-24 12:32:57 +010048#else
Russell King84046632012-09-07 18:22:28 +010049rb .req r0
502: ldrb r2, [r0]
513: ldrb rb, [r0, #1]
Catalin Marinas8b592782009-07-24 12:32:57 +010052#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#ifndef __ARMEB__
Russell King84046632012-09-07 18:22:28 +010054 orr r2, r2, rb, lsl #8
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#else
Russell King84046632012-09-07 18:22:28 +010056 orr r2, rb, r2, lsl #8
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#endif
58 mov r0, #0
Russell King6ebbf2c2014-06-30 16:29:12 +010059 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +010060ENDPROC(__get_user_2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Catalin Marinas93ed3972008-08-28 11:22:32 +010062ENTRY(__get_user_4)
Russell King84046632012-09-07 18:22:28 +010063 check_uaccess r0, 4, r1, r2, __get_user_bad
Catalin Marinas4e7682d2012-01-25 11:38:13 +0100644: TUSER(ldr) r2, [r0]
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 mov r0, #0
Russell King6ebbf2c2014-06-30 16:29:12 +010066 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +010067ENDPROC(__get_user_4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Daniel Thompsone38361d2014-07-10 20:58:08 +010069ENTRY(__get_user_8)
Kees Cook9e344042017-02-16 01:44:37 +010070 check_uaccess r0, 8, r1, r2, __get_user_bad8
Daniel Thompsone38361d2014-07-10 20:58:08 +010071#ifdef CONFIG_THUMB2_KERNEL
725: TUSER(ldr) r2, [r0]
736: TUSER(ldr) r3, [r0, #4]
74#else
755: TUSER(ldr) r2, [r0], #4
766: TUSER(ldr) r3, [r0]
77#endif
78 mov r0, #0
79 ret lr
80ENDPROC(__get_user_8)
81
82#ifdef __ARMEB__
Victor Kamenskyd9981382014-09-04 06:07:33 +010083ENTRY(__get_user_32t_8)
Daniel Thompsone38361d2014-07-10 20:58:08 +010084 check_uaccess r0, 8, r1, r2, __get_user_bad
85#ifdef CONFIG_CPU_USE_DOMAINS
86 add r0, r0, #4
877: ldrt r2, [r0]
88#else
897: ldr r2, [r0, #4]
90#endif
91 mov r0, #0
92 ret lr
Victor Kamenskyd9981382014-09-04 06:07:33 +010093ENDPROC(__get_user_32t_8)
94
95ENTRY(__get_user_64t_1)
96 check_uaccess r0, 1, r1, r2, __get_user_bad8
978: TUSER(ldrb) r3, [r0]
98 mov r0, #0
99 ret lr
100ENDPROC(__get_user_64t_1)
101
102ENTRY(__get_user_64t_2)
103 check_uaccess r0, 2, r1, r2, __get_user_bad8
104#ifdef CONFIG_CPU_USE_DOMAINS
105rb .req ip
1069: ldrbt r3, [r0], #1
10710: ldrbt rb, [r0], #0
108#else
109rb .req r0
1109: ldrb r3, [r0]
11110: ldrb rb, [r0, #1]
112#endif
113 orr r3, rb, r3, lsl #8
114 mov r0, #0
115 ret lr
116ENDPROC(__get_user_64t_2)
117
118ENTRY(__get_user_64t_4)
119 check_uaccess r0, 4, r1, r2, __get_user_bad8
12011: TUSER(ldr) r3, [r0]
121 mov r0, #0
122 ret lr
123ENDPROC(__get_user_64t_4)
Daniel Thompsone38361d2014-07-10 20:58:08 +0100124#endif
125
126__get_user_bad8:
127 mov r3, #0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128__get_user_bad:
129 mov r2, #0
130 mov r0, #-EFAULT
Russell King6ebbf2c2014-06-30 16:29:12 +0100131 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +0100132ENDPROC(__get_user_bad)
Daniel Thompsone38361d2014-07-10 20:58:08 +0100133ENDPROC(__get_user_bad8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Russell King42604152010-04-19 10:15:03 +0100135.pushsection __ex_table, "a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .long 1b, __get_user_bad
137 .long 2b, __get_user_bad
138 .long 3b, __get_user_bad
139 .long 4b, __get_user_bad
Daniel Thompsone38361d2014-07-10 20:58:08 +0100140 .long 5b, __get_user_bad8
141 .long 6b, __get_user_bad8
142#ifdef __ARMEB__
143 .long 7b, __get_user_bad
Victor Kamenskyd9981382014-09-04 06:07:33 +0100144 .long 8b, __get_user_bad8
145 .long 9b, __get_user_bad8
146 .long 10b, __get_user_bad8
147 .long 11b, __get_user_bad8
Daniel Thompsone38361d2014-07-10 20:58:08 +0100148#endif
Russell King42604152010-04-19 10:15:03 +0100149.popsection