diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-11-30 19:43:58 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2014-11-30 19:43:58 +0000 |
commit | 46e14d2b7323769500eb9cc7a8f717c4f9d188eb (patch) | |
tree | 0e8a16599ce3afb80f3d8ce476dc6439612b31f4 /lib/libc/arch/i386 | |
parent | 3bfb68f093e13e3a9bcf99e6eb14726d8b2eb7cb (diff) |
restructure libc/string + libc/arch/*/string coperation regarding
(potentially) MD versions (function dependent, not filename dependent)
split out memcpy/memmove/bcopy and strchr/index/strrchr/rindex
Bring back amd64 .S versions
And the final touch: switch all architectures temporarily to MI
memcpy.c, which contains syslog + abort for overlapping copies. A nice
harsh undefined behaviour. We will clean the entire userland of the
remaining issues in this catagory, then switch to the optimised memcpy
which skips the memmove check.
I tried to cut this change into pieces, but testing each sub-step on
every architecture is too time consuming and mindnumbing.
ok miod
Diffstat (limited to 'lib/libc/arch/i386')
-rw-r--r-- | lib/libc/arch/i386/string/Makefile.inc | 12 | ||||
-rw-r--r-- | lib/libc/arch/i386/string/bcopy.S | 26 | ||||
-rw-r--r-- | lib/libc/arch/i386/string/index.S | 26 | ||||
-rw-r--r-- | lib/libc/arch/i386/string/memcpy.S | 65 | ||||
-rw-r--r-- | lib/libc/arch/i386/string/memmove.S | 85 | ||||
-rw-r--r-- | lib/libc/arch/i386/string/rindex.S | 29 | ||||
-rw-r--r-- | lib/libc/arch/i386/string/strchr.S | 26 | ||||
-rw-r--r-- | lib/libc/arch/i386/string/strrchr.S | 29 |
8 files changed, 207 insertions, 91 deletions
diff --git a/lib/libc/arch/i386/string/Makefile.inc b/lib/libc/arch/i386/string/Makefile.inc index dc565194977..b0334f3399d 100644 --- a/lib/libc/arch/i386/string/Makefile.inc +++ b/lib/libc/arch/i386/string/Makefile.inc @@ -1,7 +1,9 @@ -# $OpenBSD: Makefile.inc,v 1.6 2012/09/04 03:10:42 okan Exp $ +# $OpenBSD: Makefile.inc,v 1.7 2014/11/30 19:43:56 deraadt Exp $ -SRCS+= bcmp.S bcopy.S bzero.S ffs.S index.S memchr.S memcmp.S memset.S \ - rindex.S strcat.S strcmp.S strcpy.S strcspn.c strlcpy.c strlen.c \ +SRCS+= bcopy.S memcpy.c memmove.S \ + strchr.S strrchr.S \ + bcmp.S bcopy.S bzero.S ffs.S memchr.S memcmp.S swab.S \ + memset.S strcat.S strcmp.S strcpy.S \ + strcspn.c strlen.c strlcat.c strlcpy.c \ strncat.c strncmp.S strncpy.c strpbrk.c strsep.c \ - strspn.c strstr.c swab.S -SRCS+= memcpy.S memmove.S strchr.S strrchr.S + strspn.c strstr.c diff --git a/lib/libc/arch/i386/string/bcopy.S b/lib/libc/arch/i386/string/bcopy.S index dde5ae111f4..bf3bcb1295c 100644 --- a/lib/libc/arch/i386/string/bcopy.S +++ b/lib/libc/arch/i386/string/bcopy.S @@ -1,4 +1,4 @@ -/* $OpenBSD: bcopy.S,v 1.5 2005/08/07 11:30:38 espie Exp $ */ +/* $OpenBSD: bcopy.S,v 1.6 2014/11/30 19:43:56 deraadt Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -33,30 +33,18 @@ #include <machine/asm.h> - /* - * (ov)bcopy (src,dst,cnt) - * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 - */ +/* + * bcopy(src, dst, cnt) + * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 + */ -#ifdef MEMCOPY -ENTRY(memcpy) -#else -#ifdef MEMMOVE -ENTRY(memmove) -#else ENTRY(bcopy) -#endif -#endif pushl %esi pushl %edi -#if defined(MEMCOPY) || defined(MEMMOVE) - movl 12(%esp),%edi - movl 16(%esp),%esi - movl %edi, %eax -#else + movl 12(%esp),%esi movl 16(%esp),%edi -#endif + movl 20(%esp),%ecx movl %ecx,%edx cmpl %esi,%edi /* potentially overlapping? */ diff --git a/lib/libc/arch/i386/string/index.S b/lib/libc/arch/i386/string/index.S deleted file mode 100644 index 7f83ef5b114..00000000000 --- a/lib/libc/arch/i386/string/index.S +++ /dev/null @@ -1,26 +0,0 @@ -/* $OpenBSD: index.S,v 1.4 2005/08/07 11:30:38 espie Exp $ */ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -#ifdef STRCHR -ENTRY(strchr) -#else -ENTRY(index) -#endif - movl 4(%esp),%eax - movb 8(%esp),%cl - .align 2,0x90 -L1: - movb (%eax),%dl - cmpb %dl,%cl /* found char??? */ - je L2 - incl %eax - testb %dl,%dl /* null terminator??? */ - jnz L1 - xorl %eax,%eax -L2: - ret diff --git a/lib/libc/arch/i386/string/memcpy.S b/lib/libc/arch/i386/string/memcpy.S index 95c8a838b95..9c846004e67 100644 --- a/lib/libc/arch/i386/string/memcpy.S +++ b/lib/libc/arch/i386/string/memcpy.S @@ -1,3 +1,62 @@ -/* $OpenBSD: memcpy.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */ -#define MEMCOPY -#include "bcopy.S" +/* $OpenBSD: memcpy.S,v 1.4 2014/11/30 19:43:56 deraadt Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from locore.s. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <machine/asm.h> + +/* + * memcpy(src, dst, cnt) + * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 + */ + +ENTRY(memcpy) + pushl %esi + pushl %edi + + movl 12(%esp),%edi + movl 16(%esp),%esi + movl %edi, %eax + + movl 20(%esp),%ecx + movl %ecx,%edx + + cld /* nope, copy forwards. */ + shrl $2,%ecx /* copy by words */ + rep + movsl + movl %edx,%ecx + andl $3,%ecx /* any bytes left? */ + rep + movsb + popl %edi + popl %esi + ret diff --git a/lib/libc/arch/i386/string/memmove.S b/lib/libc/arch/i386/string/memmove.S index c5bfd19b1d0..4859e3744fd 100644 --- a/lib/libc/arch/i386/string/memmove.S +++ b/lib/libc/arch/i386/string/memmove.S @@ -1,3 +1,82 @@ -/* $OpenBSD: memmove.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */ -#define MEMMOVE -#include "bcopy.S" +/* $OpenBSD: memmove.S,v 1.4 2014/11/30 19:43:56 deraadt Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from locore.s. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <machine/asm.h> + +/* + * memmove(src, dst, cnt) + * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 + */ + +ENTRY(memmove) + pushl %esi + pushl %edi + + movl 12(%esp),%edi + movl 16(%esp),%esi + movl %edi, %eax + + movl 20(%esp),%ecx + movl %ecx,%edx + cmpl %esi,%edi /* potentially overlapping? */ + jnb 1f + cld /* nope, copy forwards. */ + shrl $2,%ecx /* copy by words */ + rep + movsl + movl %edx,%ecx + andl $3,%ecx /* any bytes left? */ + rep + movsb + popl %edi + popl %esi + ret +1: + addl %ecx,%edi /* copy backwards. */ + addl %ecx,%esi + std + andl $3,%ecx /* any fractional bytes? */ + decl %edi + decl %esi + rep + movsb + movl %edx,%ecx + shrl $2,%ecx + subl $3,%esi + subl $3,%edi + rep + movsl + popl %edi + popl %esi + cld + ret diff --git a/lib/libc/arch/i386/string/rindex.S b/lib/libc/arch/i386/string/rindex.S deleted file mode 100644 index 0260d384ce2..00000000000 --- a/lib/libc/arch/i386/string/rindex.S +++ /dev/null @@ -1,29 +0,0 @@ -/* $OpenBSD: rindex.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */ -/* - * Written by J.T. Conklin <jtc@netbsd.org>. - * Public domain. - */ - -#include <machine/asm.h> - -#ifdef STRRCHR -ENTRY(strrchr) -#else -ENTRY(rindex) -#endif - pushl %ebx - movl 8(%esp),%edx - movb 12(%esp),%cl - xorl %eax,%eax /* init pointer to null */ - .align 2,0x90 -L1: - movb (%edx),%bl - cmpb %bl,%cl - jne L2 - movl %edx,%eax -L2: - incl %edx - testb %bl,%bl /* null terminator??? */ - jnz L1 - popl %ebx - ret diff --git a/lib/libc/arch/i386/string/strchr.S b/lib/libc/arch/i386/string/strchr.S index f76e593fcd0..453cdd6c281 100644 --- a/lib/libc/arch/i386/string/strchr.S +++ b/lib/libc/arch/i386/string/strchr.S @@ -1,3 +1,23 @@ -/* $OpenBSD: strchr.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */ -#define STRCHR -#include "index.S" +/* $OpenBSD: strchr.S,v 1.4 2014/11/30 19:43:56 deraadt Exp $ */ +/* + * Written by J.T. Conklin <jtc@netbsd.org>. + * Public domain. + */ + +#include <machine/asm.h> + +ALTENTRY(index) +ENTRY(strchr) + movl 4(%esp),%eax + movb 8(%esp),%cl + .align 2,0x90 +L1: + movb (%eax),%dl + cmpb %dl,%cl /* found char??? */ + je L2 + incl %eax + testb %dl,%dl /* null terminator??? */ + jnz L1 + xorl %eax,%eax +L2: + ret diff --git a/lib/libc/arch/i386/string/strrchr.S b/lib/libc/arch/i386/string/strrchr.S index 4ee153ff55f..ac6808fe797 100644 --- a/lib/libc/arch/i386/string/strrchr.S +++ b/lib/libc/arch/i386/string/strrchr.S @@ -1,3 +1,26 @@ -/* $OpenBSD: strrchr.S,v 1.3 2005/08/07 11:30:38 espie Exp $ */ -#define STRRCHR -#include "rindex.S" +/* $OpenBSD: strrchr.S,v 1.4 2014/11/30 19:43:56 deraadt Exp $ */ +/* + * Written by J.T. Conklin <jtc@netbsd.org>. + * Public domain. + */ + +#include <machine/asm.h> + +ALTENTRY(rindex) +ENTRY(strrchr) + pushl %ebx + movl 8(%esp),%edx + movb 12(%esp),%cl + xorl %eax,%eax /* init pointer to null */ + .align 2,0x90 +L1: + movb (%edx),%bl + cmpb %bl,%cl + jne L2 + movl %edx,%eax +L2: + incl %edx + testb %bl,%bl /* null terminator??? */ + jnz L1 + popl %ebx + ret |