From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57449 invoked by alias); 7 Oct 2019 19:36:13 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 57407 invoked by uid 447); 7 Oct 2019 19:36:12 -0000 Date: Mon, 07 Oct 2019 19:36:00 -0000 Message-ID: <20191007193612.57405.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jeff Johnston To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Allow verifying _REENT_CHECK macros memory allocation X-Act-Checkin: newlib-cygwin X-Git-Author: Jeff Johnston X-Git-Refname: refs/heads/master X-Git-Oldrev: 175b215e054a8cee50d91317f3af22a3b2c3d320 X-Git-Newrev: e06f2fbde7d9d8ca3d363035dacbbc4b81e29c9a X-SW-Source: 2019-q4/txt/msg00002.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e06f2fbde7d9d8ca3d363035dacbbc4b81e29c9a commit e06f2fbde7d9d8ca3d363035dacbbc4b81e29c9a Author: Jeff Johnston 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 -#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