This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: __memchr & bp-checks.h cleanups


No build regressions.  No binary changes for non-BP (only the expected
symbol-table changes).

OK?

2000-07-16  Greg McGary  <greg@mcgary.org>

	* sysdeps/generic/bp-checks.h: Use unbounded __memchr
	rather than non-existent __ubp_memchr.
	(CHECK_STRINGopt, CHECK_FCNTL, BOUNDED_N, BOUNDED_1): New macros.
	(_CHECK_STRING, _CHECK_N): New macros.
	(CHECK_STRING, CHECK_N, CHECK_Nopt): Rewrite in terms of _CHECK_*.
	(CHECK_IOCTL): Move inside `#if !__ASSEMBLER__'.
	* sysdeps/alpha/memchr.S: Change strong name to "__memchr".
	Add weak alias "memchr".
	* sysdeps/generic/memchr.c: Likewise.
	* sysdeps/i386/memchr.S: Likewise.
	* sysdeps/ia64/memchr.S: Likewise.
	* sysdeps/m68k/memchr.S: Likewise.
	* sysdeps/sparc/sparc32/memchr.S: Likewise.
	* sysdeps/sparc/sparc64/memchr.S: Likewise.
	* sysdeps/vax/memchr.s: Likewise.


Index: sysdeps/generic/bp-checks.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/generic/bp-checks.h,v
retrieving revision 1.2
diff -u -p -B -w -r1.2 bp-checks.h
--- bp-checks.h	2000/07/07 02:19:04	1.2
+++ bp-checks.h	2000/07/17 00:14:04
@@ -27,9 +27,8 @@
 
 #  if __BOUNDED_POINTERS__
 
-/* GKM FIXME: when gcc is ready, add real bounds checks */
 #   define BOUNDS_VIOLATED (__builtin_trap (), 0)
-extern int __ubp_memchr (const char *__unbounded, int, unsigned);
+extern int __memchr (const char *__unbounded, int, unsigned);
 
 /* Verify that pointer's value >= low.  Return pointer value.  */
 #   define CHECK_BOUNDS_LOW(ARG)				\
@@ -41,36 +40,64 @@ extern int __ubp_memchr (const char *__u
   (((__ptrvalue (ARG) > __ptrhigh (ARG)) && BOUNDS_VIOLATED),	\
    __ptrvalue (ARG))
 
-/* Check bounds of a pointer seated to a single object.  */
-#   define CHECK_1(ARG) CHECK_N ((ARG), 1)
-
-/* Same as CHECK_1, but tolerate ARG == NULL.  */
-#   define CHECK_1opt(ARG) CHECK_Nopt ((ARG), 1)
-
-/* Check bounds of a pointer seated to an array of N objects.  */
-#   define CHECK_N(ARG, N)				\
-  (((__ptrvalue (ARG) < __ptrlow (ARG)			\
+#  define _CHECK_N(ARG, N, COND)			\
+  (((COND)						\
+    && (__ptrvalue (ARG) < __ptrlow (ARG)		\
      || __ptrvalue (ARG) + (N) > __ptrhigh (ARG))	\
-    && BOUNDS_VIOLATED), __ptrvalue (ARG))
+    && BOUNDS_VIOLATED),				\
+   __ptrvalue (ARG))
 
-/* Same as CHECK_N, but tolerate ARG == NULL.  */
-#   define CHECK_Nopt(ARG, N)				\
-  (((__ptrvalue (ARG)					\
+#  define _CHECK_STRING(ARG, COND)				\
+  (((COND)							\
      && (__ptrvalue (ARG) < __ptrlow (ARG)		\
-	 || __ptrvalue (ARG) + (N) > __ptrhigh (ARG)))	\
-    && BOUNDS_VIOLATED), __ptrvalue (ARG))
-
-/* Check for NUL-terminator within string's bounds.  */
-#   define CHECK_STRING(ARG)					\
-  (((__ptrvalue (ARG) < __ptrlow (ARG)				\
-     || !__ubp_memchr (__ptrvalue (ARG), '\0',			\
+	|| !__memchr (__ptrvalue (ARG), '\0',			\
 		       (__ptrhigh (ARG) - __ptrvalue (ARG))))	\
      && BOUNDS_VIOLATED),					\
    __ptrvalue (ARG))
 
+/* Check bounds of a pointer seated to an array of N objects.  */
+#  define CHECK_N(ARG, N) _CHECK_N ((ARG), (N), 1)
+/* Same as CHECK_N, but tolerate ARG == NULL.  */
+#  define CHECK_Nopt(ARG, N) _CHECK_N ((ARG), (N), __ptrvalue (ARG))
+
+/* Check bounds of a pointer seated to a single object.  */
+#  define CHECK_1(ARG) CHECK_N ((ARG), 1)
+/* Same as CHECK_1, but tolerate ARG == NULL.  */
+#  define CHECK_1opt(ARG) CHECK_Nopt ((ARG), 1)
+
+/* Check for NUL-terminator within string's bounds.  */
+#  define CHECK_STRING(ARG) _CHECK_STRING ((ARG), 1)
+/* Same as CHECK_STRING, but tolerate ARG == NULL.  */
+#  define CHECK_STRINGopt(ARG) _CHECK_STRING ((ARG), __ptrvalue (ARG))
+
+/* Check bounds of signal syscall args with type sigset_t.  */
 #   define CHECK_SIGSET(SET) CHECK_N ((SET), _NSIG / (8 * sizeof *(SET)))
+/* Same as CHECK_SIGSET, but tolerate SET == NULL.  */
 #   define CHECK_SIGSETopt(SET) CHECK_Nopt ((SET), _NSIG / (8 * sizeof *(SET)))
 
+#  if defined (_IOC_SIZESHIFT) && defined (_IOC_SIZEBITS)
+/* Extract the size of the ioctl data and check its bounds.  */
+#   define CHECK_IOCTL(ARG, CMD)					\
+  CHECK_N ((const char *) (ARG),					\
+	   (((CMD) >> _IOC_SIZESHIFT) & ((1 << _IOC_SIZEBITS) - 1)))
+#  else
+/* We don't know the size of the ioctl data, so the best we can do
+   is check that the first byte is within bounds.  */
+#   define CHECK_IOCTL(ARG, CMD) CHECK_1 ((const char *) ARG)
+#  endif
+
+/* Check bounds of `struct flock *' for the locking fcntl commands.  */
+#  define CHECK_FCNTL(ARG, CMD)					\
+  (((CMD) == F_GETLK || (CMD) == F_SETLK || (CMD) == F_SETLKW)	\
+   ? CHECK_1 ((struct flock *) ARG) : (unsigned long) (ARG))
+
+/* Return a bounded pointer with value PTR that satisfies CHECK_N (PTR, N).  */
+#  define BOUNDED_N(PTR, N) 				\
+  ({ __typeof (*(PTR)) *__bounded _p_;			\
+     __ptrvalue _p_ = __ptrlow _p_ = __ptrvalue (PTR);	\
+     __ptrhigh _p_ = __ptrvalue _p_ + (N);		\
+     _p_; })
+
 #  else /* !__BOUNDED_POINTERS__ */
 
 /* Do nothing if not compiling with -fbounded-pointers.  */
@@ -85,18 +112,13 @@ extern int __ubp_memchr (const char *__u
 #   define CHECK_STRING(ARG) (ARG)
 #   define CHECK_SIGSET(SET) (SET)
 #   define CHECK_SIGSETopt(SET) (SET)
+#  define CHECK_IOCTL(ARG, CMD) (ARG)
+#  define CHECK_FCNTL(ARG, CMD) (ARG)
+#  define BOUNDED_N(PTR, N) (PTR)
 
 #  endif /* !__BOUNDED_POINTERS__ */
-
-#  if defined (_IOC_SIZESHIFT) && defined (_IOC_SIZEBITS)
 
-/* Extract the size of the ioctl parameter argument and check its bounds.  */
-#   define CHECK_IOCTL(ARG, CMD) \
-  CHECK_N ((ARG), (((CMD) >> _IOC_SIZESHIFT) & ((1 << _IOC_SIZEBITS) - 1)))
-
-#  else
-#   define CHECK_IOCTL(ARG, CMD) __ptrvalue (ARG)
-#  endif
+# define BOUNDED_1(PTR) BOUNDED_N (PTR, 1)
 
 # endif /* !__ASSEMBLER__ */
 
Index: sysdeps/alpha/memchr.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/alpha/memchr.S,v
retrieving revision 1.7
diff -u -p -r1.7 memchr.S
--- memchr.S	1999/05/18 08:55:49	1.7
+++ memchr.S	2000/07/17 00:04:35
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by David Mosberger (davidm@cs.arizona.edu).
 
@@ -37,7 +37,7 @@ For correctness consider that:
         .set noreorder
         .set noat
 
-ENTRY(memchr)
+ENTRY(__memchr)
 #ifdef PROF
 	ldgp	gp, 0(pv)
 	lda	AT, _mcount
@@ -167,4 +167,6 @@ $not_found:
 	mov	zero, v0	#-e0	:
 	ret			# .. e1 :
 
-        END(memchr)
+        END(__memchr)
+
+weak_alias (__stpcpy, stpcpy)
Index: sysdeps/generic/memchr.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/generic/memchr.c,v
retrieving revision 1.15
diff -u -p -r1.15 memchr.c
--- memchr.c	2000/07/05 14:27:48	1.15
+++ memchr.c	2000/07/17 00:04:35
@@ -56,7 +56,7 @@
 
 /* Search no more than N bytes of S for C.  */
 __ptr_t
-memchr (s, c_in, n)
+__memchr (s, c_in, n)
      const __ptr_t s;
      int c_in;
      size_t n;
@@ -200,3 +200,4 @@ memchr (s, c_in, n)
 
   return 0;
 }
+weak_alias (__memrchr, memrchr)
Index: sysdeps/i386/memchr.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/i386/memchr.S,v
retrieving revision 1.8
diff -u -p -r1.8 memchr.S
--- memchr.S	2000/06/26 22:14:59	1.8
+++ memchr.S	2000/07/17 00:04:35
@@ -42,7 +42,7 @@
 #define LEN	CHR+4
 
 	.text
-ENTRY (BP_SYM (memchr))
+ENTRY (BP_SYM (__memchr))
 	ENTER
 
 	/* Save callee-safe registers used in this function.  */
@@ -325,4 +325,6 @@ L(pop):	popl %edi		/* pop saved register
 
 	LEAVE
 	RET_PTR
-END (BP_SYM (memchr))
+END (BP_SYM (__memchr))
+
+weak_alias (BP_SYM (__memchr), BP_SYM (memchr))
Index: sysdeps/ia64/memchr.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/ia64/memchr.S,v
retrieving revision 1.2
diff -u -p -r1.2 memchr.S
--- memchr.S	2000/05/21 21:56:19	1.2
+++ memchr.S	2000/07/17 00:04:35
@@ -56,7 +56,7 @@
 
 #define str		in0
 
-ENTRY(memchr)
+ENTRY(__memchr)
 	alloc saved_pfs = ar.pfs, 3, 0, 29, 32
 #include "softpipe.h"
 	.rotr	value[MEMLAT+1], addr[MEMLAT+3], aux[2], poschr[2]
@@ -121,4 +121,6 @@ ENTRY(memchr)
 	mov	ar.lc = saved_lc
 	br.ret.sptk.many b0
 
-END(memchr)
+END(__memchr)
+
+weak_alias (__memchr, memchr)
Index: sysdeps/m68k/memchr.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/m68k/memchr.S,v
retrieving revision 1.1
diff -u -p -r1.1 memchr.S
--- memchr.S	1999/06/14 00:59:40	1.1
+++ memchr.S	2000/07/17 00:04:35
@@ -1,7 +1,7 @@
 /* memchr (str, ch, n) -- Return pointer to first occurrence of CH in the
    first N bytes of STR.
    For Motorola 68000.
-   Copyright (C) 1999 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Andreas Schwab <schwab@gnu.org>.
 
@@ -24,7 +24,7 @@
 #include "asm-syntax.h"
 
 	TEXT
-ENTRY(memchr)
+ENTRY(__memchr)
 	/* Save the callee-saved registers we use.  */
 	moveml	R(d2)-R(d4),MEM_PREDEC(sp)
 
@@ -223,6 +223,6 @@ L(L9:)
 	movel	R(a0),R(d0)
 	moveml	MEM_POSTINC(sp),R(d2)-R(d4)
 	rts
-END(strchr)
+END(__memchr)
 
-weak_alias (strchr, index)
+weak_alias (__memchr, memchr)
Index: sysdeps/sparc/sparc32/memchr.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/sparc/sparc32/memchr.S,v
retrieving revision 1.1
diff -u -p -r1.1 memchr.S
--- memchr.S	1999/03/29 13:25:10	1.1
+++ memchr.S	2000/07/17 00:04:35
@@ -1,7 +1,7 @@
 /* memchr (str, ch, n) -- Return pointer to first occurrence of CH in STR less
    than N.
    For SPARC v7.
-   Copyright (C) 1996,1999 Free Software Foundation, Inc.
+   Copyright (C) 1996,1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jj@ultra.linux.cz> and
 		  David S. Miller <davem@caip.rutgers.edu>.
@@ -67,7 +67,7 @@
 1:	retl
 	 sub		%o0, 1, %o0
 
-ENTRY(memchr)
+ENTRY(__memchr)
 	andcc		%o1, 0xff, %o1
 	sll		%o1, 8, %g7
 	andcc		%o0, 3, %g0
@@ -140,4 +140,6 @@ ENTRY(memchr)
 	 sub		%o0, 3, %o0
 4:	retl
 	 sub		%o0, 4, %o0
-END(memchr)
+END(__memchr)
+
+weak_alias (__memchr, memchr)
Index: sysdeps/sparc/sparc64/memchr.S
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/sparc/sparc64/memchr.S,v
retrieving revision 1.3
diff -u -p -r1.3 memchr.S
--- memchr.S	1999/07/27 04:41:12	1.3
+++ memchr.S	2000/07/17 00:04:35
@@ -1,7 +1,7 @@
 /* memchr (str, ch, n) -- Return pointer to first occurrence of CH in STR less
    than N.
    For SPARC v9.
-   Copyright (C) 1998,1999 Free Software Foundation, Inc.
+   Copyright (C) 1998,1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
                   Jakub Jelinek <jj@ultra.linux.cz>.
@@ -57,7 +57,7 @@
 
 	.text
 	.align		32
-ENTRY(memchr)
+ENTRY(__memchr)
 	and		%o1, 0xff, %o1			/* IEU0		Group		*/
 #ifdef USE_BPR
 	brz,pn		%o2, 12f			/* CTI+IEU1			*/
@@ -256,4 +256,6 @@ ENTRY(memchr)
 
 23:	retl						/* CTI+IEU1	Group		*/
 	 add		%o0, -1, %o0			/* IEU0				*/
-END(memchr)
+END(__memchr)
+
+weak_alias (__memchr, memchr)
Index: sysdeps/vax/memchr.s
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/vax/memchr.s,v
retrieving revision 1.3
diff -u -p -r1.3 memchr.s
--- memchr.s	1999/06/09 12:58:10	1.3
+++ memchr.s	2000/07/17 00:04:35
@@ -45,7 +45,7 @@
 
 #include "DEFS.h"
 
-ENTRY(memchr, 0)
+ENTRY(__memchr, 0)
 	movq	4(ap),r1	# r1 = cp; r2 = c
 	movl	12(ap),r0	# r0 = n
 	movzwl	$65535,r4	# handy constant
@@ -67,3 +67,6 @@ ENTRY(memchr, 0)
 	decw	r0		# from 0 to 65535
 	subl2	r0,r4		# adjust n
 	brb	0b		# and loop
+
+weak_alias (__memchr, memchr)
+	
\ No newline at end of file

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]