public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jeff Johnston <jjohnstn@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] Allow verifying _REENT_CHECK macros memory allocation
Date: Mon, 07 Oct 2019 19:36:00 -0000	[thread overview]
Message-ID: <20191007193612.57405.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e06f2fbde7d9d8ca3d363035dacbbc4b81e29c9a

commit e06f2fbde7d9d8ca3d363035dacbbc4b81e29c9a
Author: Jeff Johnston <jjohnstn@redhat.com>
Date:   Mon Oct 7 15:29:33 2019 -0400

    Allow verifying _REENT_CHECK macros memory allocation
    
    - change sys/reent.h to replace _REENT_CHECK_DEBUG with
      _REENT_CHECK_VERIFY which when set asserts that any memory
      allocated is non-NULL and calls __assert_func directly
    - add new --enable-newlib-reent-check-verify configure option
    - add support for configure.host to specify default for
      newlib_reent_check_verify
    - add _REENT_CHECK_VERIFY macro support to acconfig.h and newlib.hin

Diff:
---
 newlib/acconfig.h               |  3 +++
 newlib/configure                | 24 ++++++++++++++++++++++--
 newlib/configure.host           |  9 +++++++++
 newlib/configure.in             | 14 ++++++++++++++
 newlib/libc/include/sys/reent.h |  6 +++---
 newlib/newlib.hin               |  3 +++
 6 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/newlib/acconfig.h b/newlib/acconfig.h
index de26c5e..c28f7d6 100644
--- a/newlib/acconfig.h
+++ b/newlib/acconfig.h
@@ -26,6 +26,9 @@
    very restricted storage.  */
 #undef _WANT_REENT_SMALL
 
+/* Verify _REENT_CHECK macros allocate memory successfully. */
+#undef _REENT_CHECK_VERIFY
+
 /* Multibyte supported */
 #undef _MB_CAPABLE
 
diff --git a/newlib/configure b/newlib/configure
index 6eef23c..55c6642 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -788,6 +788,7 @@ enable_newlib_register_fini
 enable_newlib_io_long_long
 enable_newlib_io_long_double
 enable_newlib_mb
+enable_newlib_reent_check_verify
 enable_newlib_iconv_encodings
 enable_newlib_iconv_from_encodings
 enable_newlib_iconv_to_encodings
@@ -1463,6 +1464,7 @@ Optional Features:
   --enable-newlib-io-long-long   enable long long type support in IO functions like printf/scanf
   --enable-newlib-io-long-double   enable long double type support in IO functions printf/scanf
   --enable-newlib-mb        enable multibyte support
+  --enable-newlib-reent-check-verify        enable checking of _REENT_CHECK memory allocation
   --enable-newlib-iconv-encodings   enable specific comma-separated list of bidirectional iconv encodings to be built-in
   --enable-newlib-iconv-from-encodings   enable specific comma-separated list of \"from\" iconv encodings to be built-in
   --enable-newlib-iconv-to-encodings   enable specific comma-separated list of \"to\" iconv encodings to be built-in
@@ -2310,6 +2312,17 @@ else
   newlib_mb=
 fi
 
+# Check whether --enable-newlib-reent-check-verify was given.
+if test "${enable_newlib_reent_check_verify+set}" = set; then :
+  enableval=$enable_newlib_reent_check_verify; case "${enableval}" in
+  yes) newlib_reent_check_verify=yes;;
+  no)  newlib_reent_check_verify=no ;;
+  *)   as_fn_error $? "bad value ${enableval} for newlib-reent-check-verify option" "$LINENO" 5 ;;
+ esac
+else
+  newlib_reent_check_verify=
+fi
+
 # Check whether --enable-newlib-iconv-encodings was given.
 if test "${enable_newlib_iconv_encodings+set}" = set; then :
   enableval=$enable_newlib_iconv_encodings; if test x${enableval} = x; then
@@ -11840,7 +11853,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11843 "configure"
+#line 11856 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11946,7 +11959,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11949 "configure"
+#line 11962 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12351,6 +12364,13 @@ _ACEOF
 
 fi
 
+if test "${newlib_reent_check_verify}" = "yes"; then
+cat >>confdefs.h <<_ACEOF
+#define _REENT_CHECK_VERIFY 1
+_ACEOF
+
+fi
+
 if test "${newlib_io_c99_formats}" = "yes"; then
 cat >>confdefs.h <<_ACEOF
 #define _WANT_IO_C99_FORMATS 1
diff --git a/newlib/configure.host b/newlib/configure.host
index 87bf78a..fe7d9b7 100644
--- a/newlib/configure.host
+++ b/newlib/configure.host
@@ -29,6 +29,7 @@
 #   newlib_io_long_double --enable-newlib-io-long-double ("yes", "no", "")
 #   newlib_global_stdio_streams --enable-global-stdio-streams ("yes", "no, "")
 #   newlib_fno_builtin  --disable-newlib-fno-builtin ("yes", "no, "")
+#   newlib_reent_check_verify  --enable-newlib-reent-check-verify ("yes", "no, "")
 
 # It sets the following shell variables:
 #   newlib_cflags	Special CFLAGS to use when building
@@ -76,6 +77,7 @@ default_newlib_io_long_double=no
 default_newlib_io_pos_args=no
 default_newlib_atexit_dynamic_alloc=yes
 default_newlib_nano_malloc=no
+default_newlib_reent_check_verify=no
 aext=a
 oext=o
 lpfx="lib_a-"
@@ -952,6 +954,13 @@ if [ "x${newlib_nano_malloc}" = "x" ]; then
 	fi
 fi
 
+# Enable _REENT_CHECK macro memory allocation verification.
+if [ "x${newlib_reent_check_verify}" = "x" ]; then
+	if [ ${default_newlib_reent_check_verify} = "yes" ]; then
+		newlib_reent_check_verify="yes";
+	fi
+fi
+
 # Remove rpc headers if xdr_dir not specified
 if [ "x${xdr_dir}" = "x" ]; then
 	noinclude="${noinclude} rpc/types.h rpc/xdr.h"
diff --git a/newlib/configure.in b/newlib/configure.in
index adce036..ec5039d 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -66,6 +66,16 @@ AC_ARG_ENABLE(newlib-mb,
   *)   AC_MSG_ERROR(bad value ${enableval} for newlib-mb option) ;;
  esac], [newlib_mb=])dnl
 
+dnl Enable verification of successful memory allocation for _REENT_CHECK family of macros
+dnl Support --enable-newlib-reent-check-verify
+AC_ARG_ENABLE(newlib-reent-check-verify,
+[  --enable-newlib-reent-check-verify        enable checking of _REENT_CHECK memory allocation],
+[case "${enableval}" in
+  yes) newlib_reent_check_verify=yes;;
+  no)  newlib_reent_check_verify=no ;;
+  *)   AC_MSG_ERROR(bad value ${enableval} for newlib-reent-check-verify option) ;;
+ esac], [newlib_reent_check_verify=])dnl
+
 dnl Support --enable-newlib-iconv-encodings
 AC_ARG_ENABLE(newlib-iconv-encodings,
 [  --enable-newlib-iconv-encodings   enable specific comma-separated list of bidirectional iconv encodings to be built-in],
@@ -396,6 +406,10 @@ if test "${newlib_elix_level}" -gt "0"; then
 AC_DEFINE_UNQUOTED(_ELIX_LEVEL,${newlib_elix_level})
 fi
 
+if test "${newlib_reent_check_verify}" = "yes"; then
+AC_DEFINE_UNQUOTED(_REENT_CHECK_VERIFY)
+fi
+
 if test "${newlib_io_c99_formats}" = "yes"; then
 AC_DEFINE_UNQUOTED(_WANT_IO_C99_FORMATS)
 fi
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 7f8124d..74b70e9 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -498,10 +498,10 @@ extern const struct __sFILE_fake __sf_fake_stderr;
 
 #endif /* _REENT_GLOBAL_STDIO_STREAMS */
 
-/* Only add assert() calls if we are specified to debug.  */
-#ifdef _REENT_CHECK_DEBUG
+/* Specify how to handle reent_check malloc failures. */
+#ifdef _REENT_CHECK_VERIFY
 #include <assert.h>
-#define __reent_assert(x) assert(x)
+#define __reent_assert(x) ((x) ? (void)0 : __assert_func(__FILE__, __LINE__, (char *)0, "REENT malloc succeeded"))
 #else
 #define __reent_assert(x) ((void)0)
 #endif
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index 18306f2..416d0c6 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -32,6 +32,9 @@
    very restricted storage.  */
 #undef _WANT_REENT_SMALL
 
+/* Verify _REENT_CHECK macros allocate memory successfully. */
+#undef _REENT_CHECK_VERIFY
+
 /* Multibyte supported */
 #undef _MB_CAPABLE


                 reply	other threads:[~2019-10-07 19:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191007193612.57405.qmail@sourceware.org \
    --to=jjohnstn@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).