mirror of https://github.com/ARMmbed/mbed-os.git
73 lines
1.8 KiB
Plaintext
73 lines
1.8 KiB
Plaintext
|
/* mbed Microcontroller Library
|
||
|
* Copyright (c) 2019 ARM Limited
|
||
|
* SPDX-License-Identifier: Apache-2.0
|
||
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
#ifndef MSTD_MEMORY_
|
||
|
#define MSTD_MEMORY_
|
||
|
|
||
|
/* <mstd_memory>
|
||
|
*
|
||
|
* - includes toolchain's <memory>
|
||
|
* - For ARM C 5, C++11/14 features:
|
||
|
* - std::align
|
||
|
* - std::addressof
|
||
|
*/
|
||
|
|
||
|
#include <memory>
|
||
|
|
||
|
#ifdef __CC_ARM
|
||
|
|
||
|
#include <cstddef> // size_t, ptrdiff_t
|
||
|
|
||
|
namespace std
|
||
|
{
|
||
|
// [ptr.align]
|
||
|
inline void *align(size_t alignment, size_t size, void *&ptr, size_t &space) noexcept
|
||
|
{
|
||
|
/* Behavior is undefined if alignment is not a power of 2 */
|
||
|
uintptr_t addr = reinterpret_cast<uintptr_t>(ptr);
|
||
|
uintptr_t new_addr = (addr + (alignment - 1)) & ~(alignment - 1);
|
||
|
uintptr_t pad = new_addr - addr;
|
||
|
if (pad + size <= space) {
|
||
|
space -= pad;
|
||
|
ptr = reinterpret_cast<void *>(new_addr);
|
||
|
return ptr;
|
||
|
} else {
|
||
|
return nullptr;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// [specialized.addressof]
|
||
|
template <typename T>
|
||
|
T *addressof(T &arg) noexcept
|
||
|
{
|
||
|
return reinterpret_cast<T *>(const_cast<char *>(&reinterpret_cast<const volatile char &>(arg)));
|
||
|
}
|
||
|
|
||
|
} // namespace std
|
||
|
|
||
|
#endif // __CC_ARM
|
||
|
|
||
|
namespace mstd {
|
||
|
using std::allocator;
|
||
|
using std::uninitialized_copy;
|
||
|
using std::uninitialized_fill;
|
||
|
using std::uninitialized_fill_n;
|
||
|
using std::addressof;
|
||
|
using std::align;
|
||
|
}
|
||
|
|
||
|
#endif // MSTD_MEMORY_
|