From 31f3df10fcb51c9da74c1c9db5dab2a7a566c77e Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 20 Apr 2021 08:45:10 +0200 Subject: build: FIXME add allocate-only allocators --- cpukit/libcsupport/src/alloconly.c | 88 ++++++++++++++++++++++++++++++++ cpukit/libcsupport/src/free.c | 6 +++ cpukit/libcsupport/src/malloc_deferred.c | 5 +- cpukit/libcsupport/src/malloc_p.h | 7 +++ cpukit/libcsupport/src/posix_memalign.c | 3 +- spec/build/cpukit/librtemscpu.yml | 2 + spec/build/cpukit/objqual.yml | 15 ++++++ 7 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 cpukit/libcsupport/src/alloconly.c create mode 100644 spec/build/cpukit/objqual.yml diff --git a/cpukit/libcsupport/src/alloconly.c b/cpukit/libcsupport/src/alloconly.c new file mode 100644 index 0000000000..4e9d167be0 --- /dev/null +++ b/cpukit/libcsupport/src/alloconly.c @@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup libcsupport + * + * @brief This source file contains the implementation of rtems_calloc(). + */ + +/* + * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +#include + +RTEMS_WEAK void *rtems_malloc( size_t size ) +{ + if ( size == 0 ) { + return NULL; + } + + return _Memory_Allocate( _Memory_Get(), size, CPU_HEAP_ALIGNMENT ); +} + +RTEMS_WEAK int posix_memalign( void **memptr, size_t alignment, size_t size ) +{ + void *p; + + RTEMS_OBFUSCATE_VARIABLE( memptr ); + + if ( memptr == NULL ) { + return EINVAL; + } + + *memptr = NULL; + + if ( alignment < sizeof (void *) ) { + return EINVAL; + } + + if ( ( ( alignment - 1 ) & alignment ) != 0 ) { + return EINVAL; + } + + if ( size == 0 ) { + return 0; + } + + p = _Memory_Allocate( _Memory_Get(), size, alignment ); + + if ( p == NULL ) { + return ENOMEM; + } + + *memptr = p; + return 0; +} diff --git a/cpukit/libcsupport/src/free.c b/cpukit/libcsupport/src/free.c index 9f7c577852..e8b1882c25 100644 --- a/cpukit/libcsupport/src/free.c +++ b/cpukit/libcsupport/src/free.c @@ -25,6 +25,12 @@ #include +#ifdef RTEMS_QUAL +#define INCLUDED_BY_FREE +#include "malloc_deferred.c" +#include "posix_memalign.c" +#endif + static RTEMS_CHAIN_DEFINE_EMPTY( _Malloc_GC_list ); RTEMS_INTERRUPT_LOCK_DEFINE( static, _Malloc_GC_lock, "Malloc GC" ) diff --git a/cpukit/libcsupport/src/malloc_deferred.c b/cpukit/libcsupport/src/malloc_deferred.c index b319d1213e..6f71c850f8 100644 --- a/cpukit/libcsupport/src/malloc_deferred.c +++ b/cpukit/libcsupport/src/malloc_deferred.c @@ -21,7 +21,8 @@ #include "config.h" #endif -#ifdef RTEMS_NEWLIB +#if defined( RTEMS_NEWLIB ) && \ + ( !defined( RTEMS_QUAL ) || defined( INCLUDED_BY_FREE ) ) #include #include @@ -47,6 +48,7 @@ Malloc_System_state _Malloc_System_state( void ) } } +#if !defined( INCLUDED_BY_FREE ) RTEMS_WEAK void _Malloc_Process_deferred_frees( void ) { /* @@ -54,6 +56,7 @@ RTEMS_WEAK void _Malloc_Process_deferred_frees( void ) * strong implementation of this function will be provided. */ } +#endif void *rtems_heap_allocate_aligned_with_boundary( size_t size, diff --git a/cpukit/libcsupport/src/malloc_p.h b/cpukit/libcsupport/src/malloc_p.h index cb26050ff1..4487b02960 100644 --- a/cpukit/libcsupport/src/malloc_p.h +++ b/cpukit/libcsupport/src/malloc_p.h @@ -9,6 +9,9 @@ * http://www.rtems.org/license/LICENSE. */ +#ifndef _MALLOC_P +#define _MALLOC_P + #include #include #include @@ -17,6 +20,8 @@ extern "C" { #endif /* __cplusplus */ + + typedef enum { MALLOC_SYSTEM_STATE_NORMAL, MALLOC_SYSTEM_STATE_NO_PROTECTION, @@ -30,3 +35,5 @@ void _Malloc_Process_deferred_frees( void ); #ifdef __cplusplus } #endif /* __cplusplus */ + +#endif /* _MALLOC_P */ diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c index 418de99275..125b534a83 100644 --- a/cpukit/libcsupport/src/posix_memalign.c +++ b/cpukit/libcsupport/src/posix_memalign.c @@ -17,7 +17,8 @@ #include "config.h" #endif -#ifdef RTEMS_NEWLIB +#if defined( RTEMS_NEWLIB ) && \ + ( !defined( RTEMS_QUAL ) || defined( INCLUDED_BY_FREE ) ) #include "malloc_p.h" #include diff --git a/spec/build/cpukit/librtemscpu.yml b/spec/build/cpukit/librtemscpu.yml index 07508478e2..45681216fe 100644 --- a/spec/build/cpukit/librtemscpu.yml +++ b/spec/build/cpukit/librtemscpu.yml @@ -252,6 +252,8 @@ links: uid: grprtemscpunoqual - role: build-dependency uid: librtemscpuextra +- role: build-dependency + uid: objqual - role: build-dependency uid: objqualonly - role: build-dependency diff --git a/spec/build/cpukit/objqual.yml b/spec/build/cpukit/objqual.yml new file mode 100644 index 0000000000..132441f52f --- /dev/null +++ b/spec/build/cpukit/objqual.yml @@ -0,0 +1,15 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: objects +cflags: [] +copyrights: +- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) +cppflags: [] +cxxflags: [] +enabled-by: +- RTEMS_QUAL +includes: [] +install: [] +links: [] +source: +- cpukit/libcsupport/src/alloconly.c +type: build -- cgit v1.2.3