about summary refs log tree commit diff
path: root/sysdeps/i386
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/i386')
-rw-r--r--sysdeps/i386/bits/string.h2
-rw-r--r--sysdeps/i386/bp-asm.h18
-rw-r--r--sysdeps/i386/i486/bits/string.h4
-rw-r--r--sysdeps/i386/i686/strtok.S119
-rw-r--r--sysdeps/i386/memchr.S3
-rw-r--r--sysdeps/i386/strtok.S70
6 files changed, 132 insertions, 84 deletions
diff --git a/sysdeps/i386/bits/string.h b/sysdeps/i386/bits/string.h
index cf0285d847..eac8a36a22 100644
--- a/sysdeps/i386/bits/string.h
+++ b/sysdeps/i386/bits/string.h
@@ -28,7 +28,7 @@
 /* We only provide optimizations if the user selects them and if
    GNU CC is used.  */
 #if !defined __NO_STRING_INLINES && defined __USE_STRING_INLINES \
-    && defined __GNUC__ && __GNUC__ >= 2
+    && defined __GNUC__ && __GNUC__ >= 2 && !__BOUNDED_POINTERS__
 
 #ifndef __STRING_INLINE
 # ifdef __cplusplus
diff --git a/sysdeps/i386/bp-asm.h b/sysdeps/i386/bp-asm.h
index bde1f6a14a..f4e4226044 100644
--- a/sysdeps/i386/bp-asm.h
+++ b/sysdeps/i386/bp-asm.h
@@ -80,21 +80,21 @@
 
 /* Take bounds from BP_MEM and affix them to the pointer
    value in %eax, stuffing all into memory at RTN(%esp).
-   Use %ecx as a scratch register.  */
+   Use %edx as a scratch register.  */
 
 #   define RETURN_BOUNDED_POINTER(BP_MEM)	\
-	movl RTN(%esp), %ecx;			\
-	movl %eax, 0(%ecx);			\
+	movl RTN(%esp), %edx;			\
+	movl %eax, 0(%edx);			\
 	movl 4+BP_MEM, %eax;			\
-	movl %eax, 4(%ecx);			\
+	movl %eax, 4(%edx);			\
 	movl 8+BP_MEM, %eax;			\
-	movl %eax, 8(%ecx)
+	movl %eax, 8(%edx)
 
 #   define RETURN_NULL_BOUNDED_POINTER		\
-	movl RTN(%esp), %ecx;			\
-	movl %eax, 0(%ecx);			\
-	movl %eax, 4(%ecx);			\
-	movl %eax, 8(%ecx)
+	movl RTN(%esp), %edx;			\
+	movl %eax, 0(%edx);			\
+	movl %eax, 4(%edx);			\
+	movl %eax, 8(%edx)
 
 /* The caller of __errno_location is responsible for allocating space
    for the three-word BP return-value and passing pushing its address
diff --git a/sysdeps/i386/i486/bits/string.h b/sysdeps/i386/i486/bits/string.h
index 54e5ac4620..b60807286c 100644
--- a/sysdeps/i386/i486/bits/string.h
+++ b/sysdeps/i386/i486/bits/string.h
@@ -1,5 +1,5 @@
 /* Optimized, inlined string functions.  i486 version.
-   Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -28,7 +28,7 @@
 /* We only provide optimizations if the user selects them and if
    GNU CC is used.  */
 #if !defined __NO_STRING_INLINES && defined __USE_STRING_INLINES \
-    && defined __GNUC__ && __GNUC__ >= 2
+    && defined __GNUC__ && __GNUC__ >= 2 && !__BOUNDED_POINTERS__
 
 #ifndef __STRING_INLINE
 # ifdef __cplusplus
diff --git a/sysdeps/i386/i686/strtok.S b/sysdeps/i386/i686/strtok.S
index 96b3b5dc33..a982a4aa49 100644
--- a/sysdeps/i386/i686/strtok.S
+++ b/sysdeps/i386/i686/strtok.S
@@ -39,15 +39,39 @@
 
    We do a common implementation here.  */
 
-#ifndef USE_AS_STRTOK_R
+#ifdef USE_AS_STRTOK_R
+# define SAVE_PTR 0(%ecx)
+#else
 	.bss
 	.local save_ptr
 	ASM_TYPE_DIRECTIVE (save_ptr, @object)
 	.size save_ptr, 4
 save_ptr:
+# if __BOUNDED_POINTERS__
+	.space 12
+# else
 	.space 4
+# endif
 
-#define FUNCTION BP_SYM (strtok)
+# ifdef PIC
+#  define SAVE_PTR save_ptr@GOTOFF(%ebx)
+# else
+#  define SAVE_PTR save_ptr
+# endif
+
+# define FUNCTION strtok
+#endif
+
+#if !defined USE_AS_STRTOK_R && defined PIC
+# define PARMS	LINKAGE+256+4	/* space for table and saved PIC register */
+#else
+# define PARMS	LINKAGE+256	/* space for table */
+#endif
+#define RTN	PARMS
+#define STR	RTN+RTN_SIZE
+#define DELIM	STR+PTR_SIZE
+#ifdef USE_AS_STRTOK_R
+# define SAVE	DELIM+PTR_SIZE
 #endif
 
 	.text
@@ -57,12 +81,6 @@ save_ptr:
 	ret
 #endif
 
-#define PARMS	LINKAGE		/* no space for saved regs */
-#define RTN	PARMS
-#define STR	RTN+RTN_SIZE
-#define DELIM	STR+PTR_SIZE
-#define SAVE	DELIM+PTR_SIZE
-
 ENTRY (BP_SYM (FUNCTION))
 	ENTER
 
@@ -89,36 +107,39 @@ ENTRY (BP_SYM (FUNCTION))
 	/* Note: %ecx = 0 !!! */
 	movl %edx, %edi
 
-#if !defined USE_AS_STRTOK_R && defined PIC
-	movl 264(%esp), %edx		/* Get start of string.  */
-#else
-	movl 260(%esp), %edx		/* Get start of string.  */
-#endif
+	movl STR(%esp), %edx		/* Get start of string.  */
 
 #ifdef USE_AS_STRTOK_R
 	/* The value is stored in the third argument.  */
-	movl 268(%esp), %eax
+	movl SAVE(%esp), %eax
 	movl (%eax), %eax
 #else
 	/* The value is in the local variable defined above.  But
 	   we have to take care for PIC code.  */
-# ifndef PIC
-	movl save_ptr, %eax
-# else
-	movl save_ptr@GOTOFF(%ebx), %eax
-# endif
+	movl SAVE_PTR, %eax
 #endif
 
 	/* If the pointer is NULL we have to use the stored value of
 	   the last run.  */
 	cmpl $0, %edx
 	cmove %eax, %edx
-
-#if !defined USE_AS_STRTOK_R && defined PIC
-	movl 268(%esp), %eax		/* Get start of delimiter set.  */
-#else
-	movl 264(%esp), %eax		/* Get start of delimiter set.  */
+#if __BOUNDED_POINTERS__
+# ifdef USE_AS_STRTOK_R
+	movl SAVE(%esp), %ecx	/* borrow %ecx for a moment */
+# endif
+	je L(0)
+	/* Save bounds of incoming non-NULL STR into save area.  */
+	movl 4+STR(%esp), %eax
+	movl %eax, 4+SAVE_PTR
+	movl 8+STR(%esp), %eax
+	movl %eax, 8+SAVE_PTR
+L(0):	CHECK_BOUNDS_LOW (%edx, SAVE_PTR)
+# ifdef USE_AS_STRTOK_R
+	xorl %ecx, %ecx		/* restore %ecx to zero */
+# endif
 #endif
+	movl DELIM(%esp), %eax		/* Get start of delimiter set.  */
+	CHECK_BOUNDS_LOW (%eax, DELIM(%esp))
 
 /* For understanding the following code remember that %ecx == 0 now.
    Although all the following instruction only modify %cl we always
@@ -126,17 +147,17 @@ ENTRY (BP_SYM (FUNCTION))
 
 L(2):	movb (%eax), %cl	/* get byte from stopset */
 	testb %cl, %cl		/* is NUL char? */
-	jz L(1)			/* yes => start compare loop */
+	jz L(1_1)		/* yes => start compare loop */
 	movb %cl, (%esp,%ecx)	/* set corresponding byte in stopset table */
 
 	movb 1(%eax), %cl	/* get byte from stopset */
 	testb $0xff, %cl	/* is NUL char? */
-	jz L(1)			/* yes => start compare loop */
+	jz L(1_2)		/* yes => start compare loop */
 	movb %cl, (%esp,%ecx)	/* set corresponding byte in stopset table */
 
 	movb 2(%eax), %cl	/* get byte from stopset */
 	testb $0xff, %cl	/* is NUL char? */
-	jz L(1)			/* yes => start compare loop */
+	jz L(1_3)		/* yes => start compare loop */
 	movb %cl, (%esp,%ecx)	/* set corresponding byte in stopset table */
 
 	movb 3(%eax), %cl	/* get byte from stopset */
@@ -145,7 +166,16 @@ L(2):	movb (%eax), %cl	/* get byte from stopset */
 	testb $0xff, %cl	/* is NUL char? */
 	jnz L(2)		/* no => process next dword from stopset */
 
-L(1):	leal -4(%edx), %eax	/* prepare loop */
+#if __BOUNDED_POINTERS__
+	jmp L(1_0)		/* pointer is correct for bounds check */
+L(1_3):	incl %eax		/* adjust pointer for bounds check */
+L(1_2):	incl %eax		/* ditto */
+L(1_1):	incl %eax		/* ditto */
+L(1_0):	CHECK_BOUNDS_HIGH (%eax, DELIM(%esp), jbe)
+#else
+L(1_3):; L(1_2):; L(1_1):	/* fall through */
+#endif
+	leal -4(%edx), %eax	/* prepare loop */
 
 	/* We use a neat trick for the following loop.  Normally we would
 	   have to test for two termination conditions
@@ -204,10 +234,7 @@ L(7):	addl $4, %edx		/* adjust pointer for full loop round */
 L(10):	incl %edx
 L(9):	incl %edx
 
-L(8):	/* Remove the stopset table.  */
-	addl $256, %esp
-
-	cmpl %eax, %edx
+L(8):	cmpl %eax, %edx
 	je L(returnNULL)	/* There was no token anymore.  */
 
 	movb $0, (%edx)		/* Terminate string.  */
@@ -217,22 +244,26 @@ L(8):	/* Remove the stopset table.  */
 	leal 1(%edx), %ecx
 	cmovne %ecx, %edx
 
-L(return):
 	/* Store the pointer to the next character.  */
-#ifdef USE_AS_STRTOK_R
-	movl 12(%esp), %ecx
-	movl %edx, (%ecx)
-#else
-# ifndef PIC
-	movl %edx, save_ptr
-# else
-	movl %edx, save_ptr@GOTOFF(%ebx)
-	popl %ebx
+# ifdef USE_AS_STRTOK_R
+	movl SAVE(%esp), %ecx
 # endif
+	movl %edx, SAVE_PTR
+	CHECK_BOUNDS_HIGH (%edx, SAVE_PTR, jb)
+	RETURN_BOUNDED_POINTER (SAVE_PTR)
+
+L(epilogue):
+	/* Remove the stopset table.  */
+	addl $256, %esp
+#if !defined USE_AS_STRTOK_R && defined PIC
+	popl %ebx
 #endif
-	ret
+	LEAVE
+	RET_PTR
 
 L(returnNULL):
 	xorl %eax, %eax
-	jmp L(return)
+	RETURN_NULL_BOUNDED_POINTER
+	jmp L(epilogue)
+
 END (BP_SYM (FUNCTION))
diff --git a/sysdeps/i386/memchr.S b/sysdeps/i386/memchr.S
index 098e413cba..d01a31c855 100644
--- a/sysdeps/i386/memchr.S
+++ b/sysdeps/i386/memchr.S
@@ -328,3 +328,6 @@ L(pop):	popl %edi		/* pop saved registers */
 END (BP_SYM (__memchr))
 
 weak_alias (BP_SYM (__memchr), BP_SYM (memchr))
+#if !__BOUNDED_POINTERS__
+weak_alias (__memchr, __ubp_memchr)
+#endif
diff --git a/sysdeps/i386/strtok.S b/sysdeps/i386/strtok.S
index 47924b2237..ff8980a924 100644
--- a/sysdeps/i386/strtok.S
+++ b/sysdeps/i386/strtok.S
@@ -39,15 +39,27 @@
 
    We do a common implementation here.  */
 
-#ifndef USE_AS_STRTOK_R
+#ifdef USE_AS_STRTOK_R
+# define SAVE_PTR 0(%ecx)
+#else
 	.bss
 	.local save_ptr
 	ASM_TYPE_DIRECTIVE (save_ptr, @object)
 	.size save_ptr, 4
 save_ptr:
+# if __BOUNDED_POINTERS__
+	.space 12
+# else
 	.space 4
+# endif
+
+# ifdef PIC
+#  define SAVE_PTR save_ptr@GOTOFF(%ebx)
+# else
+#  define SAVE_PTR save_ptr
+# endif
 
-#define FUNCTION strtok
+# define FUNCTION strtok
 #endif
 
 #define PARMS	LINKAGE		/* no space for saved regs */
@@ -62,10 +74,9 @@ ENTRY (BP_SYM (FUNCTION))
 
 	movl STR(%esp), %edx
 	movl DELIM(%esp), %eax
-	CHECK_BOUNDS_LOW (%edx, STR(%esp))
 	CHECK_BOUNDS_LOW (%eax, DELIM(%esp))
 
-#if !defined (USE_AS_STRTOK_R) && defined (PIC)
+#if !defined USE_AS_STRTOK_R && defined PIC
 	pushl %ebx			/* Save PIC register.  */
 	call L(here)
 L(here):
@@ -76,7 +87,22 @@ L(here):
 	/* If the pointer is NULL we have to use the stored value of
 	   the last run.  */
 	cmpl $0, %edx
-	jne L(0)
+#if __BOUNDED_POINTERS__
+	movl SAVE(%esp), %ecx
+	je L(0)
+	/* Save bounds of incoming non-NULL STR into save area.  */
+	movl 4+STR(%esp), %eax
+	movl %eax, 4+SAVE_PTR
+	movl 8+STR(%esp), %eax
+	movl %eax, 8+SAVE_PTR
+	CHECK_BOUNDS_LOW (%edx, SAVE_PTR)
+	jmp L(1)
+L(0):	movl SAVE_PTR, %edx
+	CHECK_BOUNDS_LOW (%edx, SAVE_PTR)
+	jmp L(1)
+#else
+	jne L(1)
+#endif
 
 #ifdef USE_AS_STRTOK_R
 	/* The value is stored in the third argument.  */
@@ -85,14 +111,10 @@ L(here):
 #else
 	/* The value is in the local variable defined above.  But
 	   we have to take care for PIC code.  */
-# ifndef PIC
-	movl save_ptr, %edx
-# else
-	movl save_ptr@GOTOFF(%ebx), %edx
-# endif
+	movl SAVE_PTR, %edx
 #endif
 
-L(0):
+L(1):
 	/* First we create a table with flags for all possible characters.
 	   For the ASCII (7bit/8bit) or ISO-8859-X character sets which are
 	   supported by the C string functions we have 256 characters.
@@ -195,7 +217,7 @@ L(2):	movb (%eax), %cl	/* get byte from stopset */
 L(1_3):	incl %eax		/* adjust pointer for bounds check */
 L(1_2):	incl %eax		/* ditto */
 L(1_1):	incl %eax		/* ditto */
-L(1_0):	CHECK_BOUNDS_HIGH (%eax, DELIM(%esp), jb)
+L(1_0):	CHECK_BOUNDS_HIGH (%eax, DELIM(%esp), jbe)
 #else
 L(1_3):; L(1_2):; L(1_1):	/* fall through */
 #endif
@@ -273,25 +295,17 @@ L(8):	/* Remove the stopset table.  */
 	incl %edx
 L(11):
 
-L(return):
 	/* Store the pointer to the next character.  */
 #ifdef USE_AS_STRTOK_R
 	movl SAVE(%esp), %ecx
-	movl %edx, (%ecx)
-#else
-# ifndef PIC
-	movl %edx, save_ptr
-# else
-	movl %edx, save_ptr@GOTOFF(%ebx)
-	popl %ebx
-# endif
 #endif
-#if __BOUNDED_POINTERS__
-	testl %eax, %eax
-	jz L(ret)
-	CHECK_BOUNDS_HIGH (%eax, STR(%esp), jb)
-	RETURN_BOUNDED_POINTER (STR(%esp))
-L(ret):
+	movl %edx, SAVE_PTR
+	CHECK_BOUNDS_HIGH (%edx, SAVE_PTR, jb)
+	RETURN_BOUNDED_POINTER (SAVE_PTR)
+
+L(epilogue):
+#if !defined USE_AS_STRTOK_R && defined PIC
+	popl %ebx
 #endif
 	LEAVE
 	RET_PTR
@@ -299,6 +313,6 @@ L(ret):
 L(returnNULL):
 	xorl %eax, %eax
 	RETURN_NULL_BOUNDED_POINTER
-	jmp L(return)
+	jmp L(epilogue)
 
 END (BP_SYM (FUNCTION))