Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AOM_MEM_AOM_MEM_H_ |
| 13 | #define AOM_AOM_MEM_AOM_MEM_H_ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 14 | |
Hui Su | 1d1db11 | 2018-03-12 16:24:17 -0700 | [diff] [blame] | 15 | #include "aom/aom_integer.h" |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 16 | #include "config/aom_config.h" |
Hui Su | 1d1db11 | 2018-03-12 16:24:17 -0700 | [diff] [blame] | 17 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 18 | #if defined(__uClinux__) |
| 19 | #include <lddk.h> |
| 20 | #endif |
| 21 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 22 | #if defined(__cplusplus) |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Hui Su | 1d1db11 | 2018-03-12 16:24:17 -0700 | [diff] [blame] | 26 | #ifndef AOM_MAX_ALLOCABLE_MEMORY |
| 27 | #if SIZE_MAX > (1ULL << 32) |
| 28 | #define AOM_MAX_ALLOCABLE_MEMORY 8589934592 // 8 GB |
| 29 | #else |
| 30 | // For 32-bit targets keep this below INT_MAX to avoid valgrind warnings. |
| 31 | #define AOM_MAX_ALLOCABLE_MEMORY ((1ULL << 31) - (1 << 16)) |
| 32 | #endif |
| 33 | #endif |
| 34 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 35 | void *aom_memalign(size_t align, size_t size); |
| 36 | void *aom_malloc(size_t size); |
| 37 | void *aom_calloc(size_t num, size_t size); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 38 | void aom_free(void *memblk); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 39 | void *aom_memset16(void *dest, int val, size_t length); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 40 | |
Wan-Teh Chang | 74b7c58 | 2019-07-03 18:36:20 -0700 | [diff] [blame] | 41 | /*returns an addr aligned to the byte boundary specified by align*/ |
| 42 | #define aom_align_addr(addr, align) \ |
| 43 | (void *)(((size_t)(addr) + ((align)-1)) & ~(size_t)((align)-1)) |
| 44 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | #include <string.h> |
| 46 | |
| 47 | #ifdef AOM_MEM_PLTFRM |
| 48 | #include AOM_MEM_PLTFRM |
| 49 | #endif |
| 50 | |
Alex Converse | 8d38fb7 | 2017-05-04 13:37:40 -0700 | [diff] [blame] | 51 | #if CONFIG_DEBUG |
| 52 | #define AOM_CHECK_MEM_ERROR(error_info, lval, expr) \ |
| 53 | do { \ |
| 54 | lval = (expr); \ |
| 55 | if (!lval) \ |
| 56 | aom_internal_error(error_info, AOM_CODEC_MEM_ERROR, \ |
| 57 | "Failed to allocate " #lval " at %s:%d", __FILE__, \ |
| 58 | __LINE__); \ |
| 59 | } while (0) |
| 60 | #else |
| 61 | #define AOM_CHECK_MEM_ERROR(error_info, lval, expr) \ |
| 62 | do { \ |
| 63 | lval = (expr); \ |
| 64 | if (!lval) \ |
| 65 | aom_internal_error(error_info, AOM_CODEC_MEM_ERROR, \ |
| 66 | "Failed to allocate " #lval); \ |
| 67 | } while (0) |
| 68 | #endif |
| 69 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 70 | #if defined(__cplusplus) |
| 71 | } |
| 72 | #endif |
| 73 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 74 | #endif // AOM_AOM_MEM_AOM_MEM_H_ |