about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOndřej Bílka <neleai@seznam.cz>2013-12-04 02:02:25 +0100
committerOndřej Bílka <neleai@seznam.cz>2013-12-04 02:41:12 +0100
commitd674f0ef3898c0d1fd5cec76c1c736d9cd9bc7d1 (patch)
treeb6a4f57e8e469c61fb3b81e7903961d50a4203f3
parent6905a19f7a8443950f105b6716f6b4b1f98c4dbd (diff)
downloadglibc-d674f0ef3898c0d1fd5cec76c1c736d9cd9bc7d1.tar.gz
glibc-d674f0ef3898c0d1fd5cec76c1c736d9cd9bc7d1.tar.xz
glibc-d674f0ef3898c0d1fd5cec76c1c736d9cd9bc7d1.zip
Refactor several debug routines.
To simplify additions of debug routines we replace a custom function
implementation by a simple call.
-rw-r--r--ChangeLog10
-rw-r--r--debug/memcpy_chk.c31
-rw-r--r--debug/memmove_chk.c63
-rw-r--r--debug/mempcpy_chk.c31
-rw-r--r--debug/memset_chk.c61
-rw-r--r--debug/stpncpy_chk.c51
-rw-r--r--debug/strncpy_chk.c57
7 files changed, 16 insertions, 288 deletions
diff --git a/ChangeLog b/ChangeLog
index de64f3f71b..6320d1969e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2013-12-04  Ondřej Bílka  <neleai@seznam.cz>
+
+	* debug/memcpy_chk.c (__memcpy_chk): Use call instead of custom
+	implementation.
+	* debug/memmove_chk.c (MEMMOVE_CHK): Likewise.
+	* debug/mempcpy_chk.c (__mempcpy_chk): Likewise.
+	* debug/memset_chk.c (__memset_chk): Likewise.
+	* debug/stpncpy_chk.c (__stpncpy_chk): Likewise.
+	* debug/strncpy_chk.c: Likewise.
+
 2013-12-03  Joseph Myers  <joseph@codesourcery.com>
 
 	[BZ #15268]
diff --git a/debug/memcpy_chk.c b/debug/memcpy_chk.c
index a53dd7642b..5bbc44f57a 100644
--- a/debug/memcpy_chk.c
+++ b/debug/memcpy_chk.c
@@ -32,34 +32,5 @@ __memcpy_chk (dstpp, srcpp, len, dstlen)
   if (__builtin_expect (dstlen < len, 0))
     __chk_fail ();
 
-  unsigned long int dstp = (long int) dstpp;
-  unsigned long int srcp = (long int) srcpp;
-
-  /* Copy from the beginning to the end.  */
-
-  /* If there not too few bytes to copy, use word copy.  */
-  if (len >= OP_T_THRES)
-    {
-      /* Copy just a few bytes to make DSTP aligned.  */
-      len -= (-dstp) % OPSIZ;
-      BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
-
-      /* Copy whole pages from SRCP to DSTP by virtual address manipulation,
-	 as much as possible.  */
-
-      PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
-
-      /* Copy from SRCP to DSTP taking advantage of the known alignment of
-	 DSTP.  Number of bytes remaining is put in the third argument,
-	 i.e. in LEN.  This number may vary from machine to machine.  */
-
-      WORD_COPY_FWD (dstp, srcp, len, len);
-
-      /* Fall out and copy the tail.  */
-    }
-
-  /* There are just a few bytes to copy.  Use byte memory operations.  */
-  BYTE_COPY_FWD (dstp, srcp, len);
-
-  return dstpp;
+  return memcpy (dstpp, srcpp, len);
 }
diff --git a/debug/memmove_chk.c b/debug/memmove_chk.c
index 3ea34c6d04..6337e76ec2 100644
--- a/debug/memmove_chk.c
+++ b/debug/memmove_chk.c
@@ -36,66 +36,5 @@ MEMMOVE_CHK (dest, src, len, destlen)
   if (__builtin_expect (destlen < len, 0))
     __chk_fail ();
 
-  unsigned long int dstp = (long int) dest;
-  unsigned long int srcp = (long int) src;
-
-  /* This test makes the forward copying code be used whenever possible.
-     Reduces the working set.  */
-  if (dstp - srcp >= len)	/* *Unsigned* compare!  */
-    {
-      /* Copy from the beginning to the end.  */
-
-      /* If there not too few bytes to copy, use word copy.  */
-      if (len >= OP_T_THRES)
-	{
-	  /* Copy just a few bytes to make DSTP aligned.  */
-	  len -= (-dstp) % OPSIZ;
-	  BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
-
-	  /* Copy whole pages from SRCP to DSTP by virtual address
-	     manipulation, as much as possible.  */
-
-	  PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
-
-	  /* Copy from SRCP to DSTP taking advantage of the known
-	     alignment of DSTP.  Number of bytes remaining is put
-	     in the third argument, i.e. in LEN.  This number may
-	     vary from machine to machine.  */
-
-	  WORD_COPY_FWD (dstp, srcp, len, len);
-
-	  /* Fall out and copy the tail.  */
-	}
-
-      /* There are just a few bytes to copy.  Use byte memory operations.  */
-      BYTE_COPY_FWD (dstp, srcp, len);
-    }
-  else
-    {
-      /* Copy from the end to the beginning.  */
-      srcp += len;
-      dstp += len;
-
-      /* If there not too few bytes to copy, use word copy.  */
-      if (len >= OP_T_THRES)
-	{
-	  /* Copy just a few bytes to make DSTP aligned.  */
-	  len -= dstp % OPSIZ;
-	  BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
-
-	  /* Copy from SRCP to DSTP taking advantage of the known
-	     alignment of DSTP.  Number of bytes remaining is put
-	     in the third argument, i.e. in LEN.  This number may
-	     vary from machine to machine.  */
-
-	  WORD_COPY_BWD (dstp, srcp, len, len);
-
-	  /* Fall out and copy the tail.  */
-	}
-
-      /* There are just a few bytes to copy.  Use byte memory operations.  */
-      BYTE_COPY_BWD (dstp, srcp, len);
-    }
-
-  return dest;
+  return memmove (dest, src, len);
 }
diff --git a/debug/mempcpy_chk.c b/debug/mempcpy_chk.c
index 6895883841..1573a29d02 100644
--- a/debug/mempcpy_chk.c
+++ b/debug/mempcpy_chk.c
@@ -33,34 +33,5 @@ __mempcpy_chk (dstpp, srcpp, len, dstlen)
   if (__builtin_expect (dstlen < len, 0))
     __chk_fail ();
 
-  unsigned long int dstp = (long int) dstpp;
-  unsigned long int srcp = (long int) srcpp;
-
-  /* Copy from the beginning to the end.  */
-
-  /* If there not too few bytes to copy, use word copy.  */
-  if (len >= OP_T_THRES)
-    {
-      /* Copy just a few bytes to make DSTP aligned.  */
-      len -= (-dstp) % OPSIZ;
-      BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
-
-      /* Copy whole pages from SRCP to DSTP by virtual address manipulation,
-	 as much as possible.  */
-
-      PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
-
-      /* Copy from SRCP to DSTP taking advantage of the known alignment of
-	 DSTP.  Number of bytes remaining is put in the third argument,
-	 i.e. in LEN.  This number may vary from machine to machine.  */
-
-      WORD_COPY_FWD (dstp, srcp, len, len);
-
-      /* Fall out and copy the tail.  */
-    }
-
-  /* There are just a few bytes to copy.  Use byte memory operations.  */
-  BYTE_COPY_FWD (dstp, srcp, len);
-
-  return (void *) dstp;
+  return __mempcpy (dstpp, srcpp, len);
 }
diff --git a/debug/memset_chk.c b/debug/memset_chk.c
index bfbc29d294..ef1cadb60f 100644
--- a/debug/memset_chk.c
+++ b/debug/memset_chk.c
@@ -28,64 +28,5 @@ __memset_chk (dstpp, c, len, dstlen)
   if (__builtin_expect (dstlen < len, 0))
     __chk_fail ();
 
-  long int dstp = (long int) dstpp;
-
-  if (len >= 8)
-    {
-      size_t xlen;
-      op_t cccc;
-
-      cccc = (unsigned char) c;
-      cccc |= cccc << 8;
-      cccc |= cccc << 16;
-      if (OPSIZ > 4)
-	/* Do the shift in two steps to avoid warning if long has 32 bits.  */
-	cccc |= (cccc << 16) << 16;
-
-      /* There are at least some bytes to set.
-	 No need to test for LEN == 0 in this alignment loop.  */
-      while (dstp % OPSIZ != 0)
-	{
-	  ((byte *) dstp)[0] = c;
-	  dstp += 1;
-	  len -= 1;
-	}
-
-      /* Write 8 `op_t' per iteration until less than 8 `op_t' remain.  */
-      xlen = len / (OPSIZ * 8);
-      while (xlen > 0)
-	{
-	  ((op_t *) dstp)[0] = cccc;
-	  ((op_t *) dstp)[1] = cccc;
-	  ((op_t *) dstp)[2] = cccc;
-	  ((op_t *) dstp)[3] = cccc;
-	  ((op_t *) dstp)[4] = cccc;
-	  ((op_t *) dstp)[5] = cccc;
-	  ((op_t *) dstp)[6] = cccc;
-	  ((op_t *) dstp)[7] = cccc;
-	  dstp += 8 * OPSIZ;
-	  xlen -= 1;
-	}
-      len %= OPSIZ * 8;
-
-      /* Write 1 `op_t' per iteration until less than OPSIZ bytes remain.  */
-      xlen = len / OPSIZ;
-      while (xlen > 0)
-	{
-	  ((op_t *) dstp)[0] = cccc;
-	  dstp += OPSIZ;
-	  xlen -= 1;
-	}
-      len %= OPSIZ;
-    }
-
-  /* Write the last few bytes.  */
-  while (len > 0)
-    {
-      ((byte *) dstp)[0] = c;
-      dstp += 1;
-      len -= 1;
-    }
-
-  return dstpp;
+  return memset (dstpp, c, len);
 }
diff --git a/debug/stpncpy_chk.c b/debug/stpncpy_chk.c
index 35a2c23508..f9fa66ccaf 100644
--- a/debug/stpncpy_chk.c
+++ b/debug/stpncpy_chk.c
@@ -31,54 +31,5 @@ __stpncpy_chk (char *dest, const char *src, size_t n, size_t destlen)
   if (__builtin_expect (destlen < n, 0))
     __chk_fail ();
 
-  if (n >= 4)
-    {
-      size_t n4 = n >> 2;
-
-      for (;;)
-	{
-	  c = *src++;
-	  *dest++ = c;
-	  if (c == '\0')
-	    break;
-	  c = *src++;
-	  *dest++ = c;
-	  if (c == '\0')
-	    break;
-	  c = *src++;
-	  *dest++ = c;
-	  if (c == '\0')
-	    break;
-	  c = *src++;
-	  *dest++ = c;
-	  if (c == '\0')
-	    break;
-	  if (--n4 == 0)
-	    goto last_chars;
-	}
-      n -= dest - s;
-      goto zero_fill;
-    }
-
- last_chars:
-  n &= 3;
-  if (n == 0)
-    return dest;
-
-  for (;;)
-    {
-      c = *src++;
-      --n;
-      *dest++ = c;
-      if (c == '\0')
-	break;
-      if (n == 0)
-	return dest;
-    }
-
- zero_fill:
-  while (n-- > 0)
-    dest[n] = '\0';
-
-  return dest - 1;
+  return __stpncpy (dest, src, n);
 }
diff --git a/debug/strncpy_chk.c b/debug/strncpy_chk.c
index d067bd9ac3..2e078b1e4f 100644
--- a/debug/strncpy_chk.c
+++ b/debug/strncpy_chk.c
@@ -26,63 +26,8 @@ __strncpy_chk (s1, s2, n, s1len)
      size_t n;
      size_t s1len;
 {
-  char c;
-  char *s = s1;
-
   if (__builtin_expect (s1len < n, 0))
     __chk_fail ();
 
-  --s1;
-
-  if (n >= 4)
-    {
-      size_t n4 = n >> 2;
-
-      for (;;)
-	{
-	  c = *s2++;
-	  *++s1 = c;
-	  if (c == '\0')
-	    break;
-	  c = *s2++;
-	  *++s1 = c;
-	  if (c == '\0')
-	    break;
-	  c = *s2++;
-	  *++s1 = c;
-	  if (c == '\0')
-	    break;
-	  c = *s2++;
-	  *++s1 = c;
-	  if (c == '\0')
-	    break;
-	  if (--n4 == 0)
-	    goto last_chars;
-	}
-      n = n - (s1 - s) - 1;
-      if (n == 0)
-	return s;
-      goto zero_fill;
-    }
-
- last_chars:
-  n &= 3;
-  if (n == 0)
-    return s;
-
-  do
-    {
-      c = *s2++;
-      *++s1 = c;
-      if (--n == 0)
-	return s;
-    }
-  while (c != '\0');
-
- zero_fill:
-  do
-    *++s1 = '\0';
-  while (--n > 0);
-
-  return s;
+  return strncpy (s1, s2, n);
 }