Messages in this thread Patch in this message | | | Date | Tue, 14 Sep 1999 15:19:39 +1000 | From | Paul Mackerras <> | Subject | Re: 2.2.13pre5/6/7 strnlen for PPC |
| |
Andreas Tobler <toa@pop.agri.ch> wrote:
> A little exploration showed me, that in alpha, i386 and sparc some > updates concerning the strnlen_user were done. > Is the PPC part already done? I got some problems when I saw the
I have done a strnlen_user and sent the patch to Alan. In the meantime, here's the patch to implement strnlen_user.
Paul.
diff -urN official/arch/ppc/kernel/ppc_ksyms.c linux/arch/ppc/kernel/ppc_ksyms.c --- official/arch/ppc/kernel/ppc_ksyms.c Mon Sep 13 10:56:11 1999 +++ linux/arch/ppc/kernel/ppc_ksyms.c Mon Sep 13 10:54:48 1999 @@ -121,7 +121,7 @@ EXPORT_SYMBOL(__copy_tofrom_user); EXPORT_SYMBOL(__clear_user); EXPORT_SYMBOL(__strncpy_from_user); -EXPORT_SYMBOL(strlen_user); +EXPORT_SYMBOL(__strnlen_user); /* EXPORT_SYMBOL(inb); diff -urN official/arch/ppc/lib/string.S linux/arch/ppc/lib/string.S --- official/arch/ppc/lib/string.S Thu Apr 29 16:43:58 1999 +++ linux/arch/ppc/lib/string.S Mon Sep 13 10:56:54 1999 @@ -380,16 +380,26 @@ .long 1b,99b .text - .globl strlen_user -strlen_user: - addi r4,r3,-1 -1: lbzu r0,1(r4) +/* r3 = str, r4 = len (> 0), r5 = top (highest addr + 1) */ + .globl __strnlen_user +__strnlen_user: + subf r6,r3,r5 /* top - str */ + addi r7,r3,-1 + cmplw 0,r4,r6 + bge 0f + mr r6,r4 +0: mtctr r6 /* ctr = min(len, top - str) */ +1: lbzu r0,1(r7) /* get next byte */ cmpwi 0,r0,0 - bne 1b - subf r3,r3,r4 - addi r3,r3,1 + bdnzf 2,1b /* loop if --ctr != 0 && byte != 0 */ + addi r7,r7,1 + subf r3,r3,r7 /* number of bytes we have looked at */ + beqlr /* return if we found a 0 byte */ + cmpw 0,r3,r4 /* did we look at all len bytes? */ + blt 99f /* if not, must have hit top */ + addi r3,r4,1 /* return len + 1 to indicate no null found */ blr -99: li r3,0 +99: li r3,0 /* bad address, return 0 */ blr .section __ex_table,"a" .align 2 diff -urN official/include/asm-ppc/uaccess.h linux/include/asm-ppc/uaccess.h --- official/include/asm-ppc/uaccess.h Wed Mar 24 10:20:25 1999 +++ linux/include/asm-ppc/uaccess.h Mon Sep 13 11:09:23 1999 @@ -259,7 +259,24 @@ * Return 0 for error */ -extern long strlen_user(const char *); +extern int __strnlen_user(const char *str, long len, unsigned long top); + +/* + * Returns the length of the string at str (including the null byte), + * or 0 if we hit a page we can't access, + * or something > len if we didn't find a null byte. + * + * The `top' parameter to __strnlen_user is to make sure that + * we can never overflow from the user area into kernel space. + * It is 1 + the highest address the task can access. + */ +extern __inline__ int strnlen_user(const char *str, long len) +{ + unsigned long top = __kernel_ok? 0: TASK_SIZE; + return __strnlen_user(str, len, top); +} + +#define strlen_user(str) strnlen_user((str), 0x7ffffffe) #endif /* __ASSEMBLY__ */ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |