1 : /*
2 : * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : #include "native_client/src/shared/platform/aligned_malloc.h"
8 :
9 : #if NACL_ANDROID
10 : #include <malloc.h>
11 : #endif
12 : #include <stdlib.h>
13 :
14 :
15 20878 : void *NaClAlignedMalloc(size_t size, size_t alignment) {
16 : /*
17 : * Bionic in Android ICS (4.0) and earlier doesn't have
18 : * posix_memalign(), so we shall use memalign(), which
19 : * luckily, in Bionic, returns free()'able memory, although it is not
20 : * required to in general.
21 : * TODO(olonho): once/if we'll obsolete 4.0 support remove this #ifdef.
22 : */
23 : #if NACL_ANDROID
24 : return memalign(alignment, size);
25 : #else
26 20878 : void *block;
27 20878 : if (posix_memalign(&block, alignment, size) != 0)
28 0 : return NULL;
29 20878 : return block;
30 : #endif
31 20878 : }
32 :
33 20699 : void NaClAlignedFree(void *block) {
34 20699 : free(block);
35 20699 : }
|