blob: f533ab9f8b137e8c5c8f7fabd6d45deef1ca99e6 [file] [log] [blame]
Yaowu Xuf883b422016-08-30 14:01:10 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuf883b422016-08-30 14:01:10 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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 Xuf883b422016-08-30 14:01:10 -070010 */
11
James Zerne1cbb132018-08-22 14:10:36 -070012#ifndef AOM_AOM_MEM_AOM_MEM_H_
13#define AOM_AOM_MEM_AOM_MEM_H_
Yaowu Xuf883b422016-08-30 14:01:10 -070014
Hui Su1d1db112018-03-12 16:24:17 -070015#include "aom/aom_integer.h"
Tom Finegan60e653d2018-05-22 11:34:58 -070016#include "config/aom_config.h"
Hui Su1d1db112018-03-12 16:24:17 -070017
Yaowu Xuf883b422016-08-30 14:01:10 -070018#if defined(__uClinux__)
19#include <lddk.h>
20#endif
21
Yaowu Xuf883b422016-08-30 14:01:10 -070022#if defined(__cplusplus)
23extern "C" {
24#endif
25
Hui Su1d1db112018-03-12 16:24:17 -070026#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 Xuf883b422016-08-30 14:01:10 -070035void *aom_memalign(size_t align, size_t size);
36void *aom_malloc(size_t size);
37void *aom_calloc(size_t num, size_t size);
Yaowu Xuf883b422016-08-30 14:01:10 -070038void aom_free(void *memblk);
Yaowu Xuf883b422016-08-30 14:01:10 -070039void *aom_memset16(void *dest, int val, size_t length);
Yaowu Xuf883b422016-08-30 14:01:10 -070040
Wan-Teh Chang74b7c582019-07-03 18:36:20 -070041/*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 Xuf883b422016-08-30 14:01:10 -070045#include <string.h>
46
47#ifdef AOM_MEM_PLTFRM
48#include AOM_MEM_PLTFRM
49#endif
50
Alex Converse8d38fb72017-05-04 13:37:40 -070051#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 Xuf883b422016-08-30 14:01:10 -070070#if defined(__cplusplus)
71}
72#endif
73
James Zerne1cbb132018-08-22 14:10:36 -070074#endif // AOM_AOM_MEM_AOM_MEM_H_