• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
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.
10  */
11 
12 #ifndef AOM_AOM_MEM_AOM_MEM_H_
13 #define AOM_AOM_MEM_AOM_MEM_H_
14 
15 #include "aom/aom_integer.h"
16 #include "config/aom_config.h"
17 
18 #if defined(__uClinux__)
19 #include <lddk.h>
20 #endif
21 
22 #if defined(__cplusplus)
23 extern "C" {
24 #endif
25 
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 
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);
38 void aom_free(void *memblk);
39 void *aom_memset16(void *dest, int val, size_t length);
40 
41 /*returns an addr aligned to the byte boundary specified by align*/
42 #define aom_align_addr(addr, align) \
43   (void *)(((uintptr_t)(addr) + ((align)-1)) & ~(uintptr_t)((align)-1))
44 
45 #include <string.h>
46 
47 #ifdef AOM_MEM_PLTFRM
48 #include AOM_MEM_PLTFRM
49 #endif
50 
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 
70 #if defined(__cplusplus)
71 }
72 #endif
73 
74 #endif  // AOM_AOM_MEM_AOM_MEM_H_
75