forked from Imagelibrary/rtems
Add aligned_alloc() and memalign()
Ensure that the C++17 aligned new operator works. Close #3666.
This commit is contained in:
@@ -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
|
||||
|
||||
41
cpukit/libcsupport/src/alignedalloc.c
Normal file
41
cpukit/libcsupport/src/alignedalloc.c
Normal file
@@ -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 );
|
||||
@@ -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
|
||||
|
||||
@@ -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])
|
||||
|
||||
68
testsuites/sptests/spcxx01/init.cc
Normal file
68
testsuites/sptests/spcxx01/init.cc
Normal file
@@ -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>
|
||||
11
testsuites/sptests/spcxx01/spcxx01.doc
Normal file
11
testsuites/sptests/spcxx01/spcxx01.doc
Normal file
@@ -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.
|
||||
7
testsuites/sptests/spcxx01/spcxx01.scn
Normal file
7
testsuites/sptests/spcxx01/spcxx01.scn
Normal file
@@ -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 ***
|
||||
Reference in New Issue
Block a user