2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/portability/Memory.h>
19 #include <folly/portability/Config.h>
20 #include <folly/portability/Malloc.h>
26 #if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || \
27 (defined(__ANDROID__) && (__ANDROID_API__ > 15)) || \
28 (defined(__APPLE__) && \
29 (__MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_6 || \
30 __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0))
32 // Use posix_memalign, but mimic the behaviour of memalign
33 void* aligned_malloc(size_t size, size_t align) {
35 int rc = posix_memalign(&ptr, align, size);
43 void aligned_free(void* aligned_ptr) {
48 void* aligned_malloc(size_t size, size_t align) {
49 return _aligned_malloc(size, align);
52 void aligned_free(void* aligned_ptr) {
53 _aligned_free(aligned_ptr);
57 void* aligned_malloc(size_t size, size_t align) {
58 return memalign(align, size);
61 void aligned_free(void* aligned_ptr) {