]> Pileus Git - ~andy/linux/blob - arch/mips/lib/strncpy_user.S
Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus
[~andy/linux] / arch / mips / lib / strncpy_user.S
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1996, 1999 by Ralf Baechle
7  * Copyright (C) 2011 MIPS Technologies, Inc.
8  */
9 #include <linux/errno.h>
10 #include <asm/asm.h>
11 #include <asm/asm-offsets.h>
12 #include <asm/regdef.h>
13
14 #define EX(insn,reg,addr,handler)                       \
15 9:      insn    reg, addr;                              \
16         .section __ex_table,"a";                        \
17         PTR     9b, handler;                            \
18         .previous
19
20 /*
21  * Returns: -EFAULT if exception before terminator, N if the entire
22  * buffer filled, else strlen.
23  */
24
25 /*
26  * Ugly special case have to check: we might get passed a user space
27  * pointer which wraps into the kernel space.  We don't deal with that.  If
28  * it happens at most some bytes of the exceptions handlers will be copied.
29  */
30
31 LEAF(__strncpy_from_user_asm)
32         LONG_L          v0, TI_ADDR_LIMIT($28)  # pointer ok?
33         and             v0, a1
34         bnez            v0, .Lfault
35
36 FEXPORT(__strncpy_from_user_nocheck_asm)
37         .set            noreorder
38         move            t0, zero
39         move            v1, a1
40 1:      EX(lbu, v0, (v1), .Lfault)
41         PTR_ADDIU       v1, 1
42         R10KCBARRIER(0(ra))
43         beqz            v0, 2f
44          sb             v0, (a0)
45         PTR_ADDIU       t0, 1
46         bne             t0, a2, 1b
47          PTR_ADDIU      a0, 1
48 2:      PTR_ADDU        v0, a1, t0
49         xor             v0, a1
50         bltz            v0, .Lfault
51          nop
52         jr              ra                      # return n
53          move           v0, t0
54         END(__strncpy_from_user_asm)
55
56 .Lfault: jr             ra
57           li            v0, -EFAULT
58
59         .section        __ex_table,"a"
60         PTR             1b, .Lfault
61         .previous