summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-12-19 09:25:29 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-12-21 07:56:35 +0100
commit2158621366c19dc32418ace48f49f4474a40c669 (patch)
tree424b6457086884a6ed0cdbef8366c23992e03cbc
parenttftpfs: Some bug fixes (diff)
downloadrtems-2158621366c19dc32418ace48f49f4474a40c669.tar.bz2
Add aligned_alloc() and memalign()
Ensure that the C++17 aligned new operator works. Close #3666.
-rw-r--r--cpukit/Makefile.am1
-rw-r--r--cpukit/libcsupport/src/alignedalloc.c41
-rw-r--r--testsuites/sptests/Makefile.am12
-rw-r--r--testsuites/sptests/configure.ac1
-rw-r--r--testsuites/sptests/spcxx01/init.cc68
-rw-r--r--testsuites/sptests/spcxx01/spcxx01.doc11
-rw-r--r--testsuites/sptests/spcxx01/spcxx01.scn7
7 files changed, 141 insertions, 0 deletions
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index 143c5d6686..23f4f40521 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -78,6 +78,7 @@ librtemscpu_a_SOURCES += libcrypt/crypt-sha512.c
librtemscpu_a_SOURCES += libcrypt/misc.c
librtemscpu_a_SOURCES += libcsupport/src/access.c
librtemscpu_a_SOURCES += libcsupport/src/arc4random_getentropy_fail.c
+librtemscpu_a_SOURCES += libcsupport/src/alignedalloc.c
librtemscpu_a_SOURCES += libcsupport/src/__assert.c
librtemscpu_a_SOURCES += libcsupport/src/assoc32tostring.c
librtemscpu_a_SOURCES += libcsupport/src/assoclocalbyname.c
diff --git a/cpukit/libcsupport/src/alignedalloc.c b/cpukit/libcsupport/src/alignedalloc.c
new file mode 100644
index 0000000000..0ecf7393d8
--- /dev/null
+++ b/cpukit/libcsupport/src/alignedalloc.c
@@ -0,0 +1,41 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018 embedded brains GmbH
+ *
+ * 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.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <rtems/malloc.h>
+
+void *aligned_alloc( size_t alignment, size_t size )
+{
+ return rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 );
+}
+
+void *memalign( size_t, size_t ) RTEMS_ALIAS( aligned_alloc );
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index 8f92873d2b..a3c9b1e3bf 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -772,6 +772,18 @@ spcpuset01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spcpuset01) \
$(support_includes) -DSMPTEST
endif
+if HAS_CPLUSPLUS
+if TEST_spcxx01
+sp_tests += spcxx01
+sp_screens += spcxx01/spcxx01.scn
+sp_docs += spcxx01/spcxx01.doc
+spcxx01_SOURCES = spcxx01/init.cc
+spcxx01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_spcxx01) \
+ $(support_includes)
+spcxx01_CXXFLAGS = $(AM_CXXFLAGS) -std=gnu++17
+endif
+endif
+
if TEST_spedfsched01
sp_tests += spedfsched01
sp_screens += spedfsched01/spedfsched01.scn
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac
index d25d9e9e32..322219696d 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -124,6 +124,7 @@ RTEMS_TEST_CHECK([spcontext01])
RTEMS_TEST_CHECK([spcoverage])
RTEMS_TEST_CHECK([spcpucounter01])
RTEMS_TEST_CHECK([spcpuset01])
+RTEMS_TEST_CHECK([spcxx01])
RTEMS_TEST_CHECK([spedfsched01])
RTEMS_TEST_CHECK([spedfsched02])
RTEMS_TEST_CHECK([spedfsched03])
diff --git a/testsuites/sptests/spcxx01/init.cc b/testsuites/sptests/spcxx01/init.cc
new file mode 100644
index 0000000000..986731634b
--- /dev/null
+++ b/testsuites/sptests/spcxx01/init.cc
@@ -0,0 +1,68 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2018 embedded brains GmbH
+ *
+ * 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 <new>
+
+#include <rtems.h>
+
+#include <tmacros.h>
+
+const char rtems_test_name[] = "SPCXX 1";
+
+extern "C" void Init(rtems_task_argument arg)
+{
+ TEST_BEGIN();
+
+ int *i = static_cast<decltype(i)>(
+ ::operator new(sizeof(*i), std::align_val_t(256))
+ );
+ RTEMS_OBFUSCATE_VARIABLE(i);
+ rtems_test_assert(i != nullptr);
+ rtems_test_assert(reinterpret_cast<uintptr_t>(i) % 256 == 0);
+ ::delete(i);
+
+ TEST_END();
+ exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/sptests/spcxx01/spcxx01.doc b/testsuites/sptests/spcxx01/spcxx01.doc
new file mode 100644
index 0000000000..669e6820ab
--- /dev/null
+++ b/testsuites/sptests/spcxx01/spcxx01.doc
@@ -0,0 +1,11 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: spcxx01
+
+directives:
+
+ - ::operator new()
+
+concepts:
+
+ - Ensure that the aligned new operator works.
diff --git a/testsuites/sptests/spcxx01/spcxx01.scn b/testsuites/sptests/spcxx01/spcxx01.scn
new file mode 100644
index 0000000000..111050e731
--- /dev/null
+++ b/testsuites/sptests/spcxx01/spcxx01.scn
@@ -0,0 +1,7 @@
+*** BEGIN OF TEST SPCXX 1 ***
+*** TEST VERSION: 5.0.0.cfa82b34b0c53ab4e3d84dd8ab5225793d48fcd0
+*** TEST STATE: EXPECTED-PASS
+*** TEST BUILD:
+*** TEST TOOLS: 7.4.0 20181206 (RTEMS 5, RSB ddba5372522da341fa20b2c75dfe966231cb6790, Newlib df6915f029ac9acd2b479ea898388cbd7dda4974)
+
+*** END OF TEST SPCXX 1 ***