summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-04-20 08:45:10 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-07-12 15:08:04 +0200
commit31f3df10fcb51c9da74c1c9db5dab2a7a566c77e (patch)
tree2111aede6d67a246158ecad84f00b79017a344a2
parent3c00538f777371dcf129753e80fcf6d55e6928a5 (diff)
build: FIXME add allocate-only allocators
-rw-r--r--cpukit/libcsupport/src/alloconly.c88
-rw-r--r--cpukit/libcsupport/src/free.c6
-rw-r--r--cpukit/libcsupport/src/malloc_deferred.c5
-rw-r--r--cpukit/libcsupport/src/malloc_p.h7
-rw-r--r--cpukit/libcsupport/src/posix_memalign.c3
-rw-r--r--spec/build/cpukit/librtemscpu.yml2
-rw-r--r--spec/build/cpukit/objqual.yml15
7 files changed, 124 insertions, 2 deletions
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 <rtems/malloc.h>
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <rtems/score/memory.h>
+
+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 <rtems/chain.h>
+#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 <stdlib.h>
#include <string.h>
@@ -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 <rtems.h>
#include <rtems/score/protectedheap.h>
#include <rtems/malloc.h>
@@ -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 <stdlib.h>
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
@@ -253,6 +253,8 @@ links:
- role: build-dependency
uid: librtemscpuextra
- role: build-dependency
+ uid: objqual
+- role: build-dependency
uid: objqualonly
- role: build-dependency
uid: objsmpqual
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