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