xref: /aosp_15_r20/external/pdfium/third_party/libopenjpeg/opj_malloc.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1*3ac0a46fSAndroid Build Coastguard Worker /*
2*3ac0a46fSAndroid Build Coastguard Worker  * The copyright in this software is being made available under the 2-clauses
3*3ac0a46fSAndroid Build Coastguard Worker  * BSD License, included below. This software may be subject to other third
4*3ac0a46fSAndroid Build Coastguard Worker  * party and contributor rights, including patent rights, and no such rights
5*3ac0a46fSAndroid Build Coastguard Worker  * are granted under this license.
6*3ac0a46fSAndroid Build Coastguard Worker  *
7*3ac0a46fSAndroid Build Coastguard Worker  * Copyright (c) 2005, Herve Drolon, FreeImage Team
8*3ac0a46fSAndroid Build Coastguard Worker  * Copyright (c) 2007, Callum Lerwick <[email protected]>
9*3ac0a46fSAndroid Build Coastguard Worker  * All rights reserved.
10*3ac0a46fSAndroid Build Coastguard Worker  *
11*3ac0a46fSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
12*3ac0a46fSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
13*3ac0a46fSAndroid Build Coastguard Worker  * are met:
14*3ac0a46fSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
15*3ac0a46fSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
16*3ac0a46fSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
17*3ac0a46fSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
18*3ac0a46fSAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
19*3ac0a46fSAndroid Build Coastguard Worker  *
20*3ac0a46fSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
21*3ac0a46fSAndroid Build Coastguard Worker  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*3ac0a46fSAndroid Build Coastguard Worker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*3ac0a46fSAndroid Build Coastguard Worker  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24*3ac0a46fSAndroid Build Coastguard Worker  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25*3ac0a46fSAndroid Build Coastguard Worker  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26*3ac0a46fSAndroid Build Coastguard Worker  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27*3ac0a46fSAndroid Build Coastguard Worker  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28*3ac0a46fSAndroid Build Coastguard Worker  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29*3ac0a46fSAndroid Build Coastguard Worker  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30*3ac0a46fSAndroid Build Coastguard Worker  * POSSIBILITY OF SUCH DAMAGE.
31*3ac0a46fSAndroid Build Coastguard Worker  */
32*3ac0a46fSAndroid Build Coastguard Worker #ifndef OPJ_MALLOC_H
33*3ac0a46fSAndroid Build Coastguard Worker #define OPJ_MALLOC_H
34*3ac0a46fSAndroid Build Coastguard Worker 
35*3ac0a46fSAndroid Build Coastguard Worker #include <stddef.h>
36*3ac0a46fSAndroid Build Coastguard Worker 
37*3ac0a46fSAndroid Build Coastguard Worker #ifdef __cplusplus
38*3ac0a46fSAndroid Build Coastguard Worker extern "C" {
39*3ac0a46fSAndroid Build Coastguard Worker #endif
40*3ac0a46fSAndroid Build Coastguard Worker 
41*3ac0a46fSAndroid Build Coastguard Worker /**
42*3ac0a46fSAndroid Build Coastguard Worker @file opj_malloc.h
43*3ac0a46fSAndroid Build Coastguard Worker @brief Internal functions
44*3ac0a46fSAndroid Build Coastguard Worker 
45*3ac0a46fSAndroid Build Coastguard Worker The functions in opj_malloc.h are internal utilities used for memory management.
46*3ac0a46fSAndroid Build Coastguard Worker */
47*3ac0a46fSAndroid Build Coastguard Worker 
48*3ac0a46fSAndroid Build Coastguard Worker /** @defgroup MISC MISC - Miscellaneous internal functions */
49*3ac0a46fSAndroid Build Coastguard Worker /*@{*/
50*3ac0a46fSAndroid Build Coastguard Worker 
51*3ac0a46fSAndroid Build Coastguard Worker /** @name Exported functions */
52*3ac0a46fSAndroid Build Coastguard Worker /*@{*/
53*3ac0a46fSAndroid Build Coastguard Worker /* ----------------------------------------------------------------------- */
54*3ac0a46fSAndroid Build Coastguard Worker 
55*3ac0a46fSAndroid Build Coastguard Worker /**
56*3ac0a46fSAndroid Build Coastguard Worker Allocate an uninitialized memory block
57*3ac0a46fSAndroid Build Coastguard Worker @param size Bytes to allocate
58*3ac0a46fSAndroid Build Coastguard Worker @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
59*3ac0a46fSAndroid Build Coastguard Worker */
60*3ac0a46fSAndroid Build Coastguard Worker void * opj_malloc(size_t size);
61*3ac0a46fSAndroid Build Coastguard Worker 
62*3ac0a46fSAndroid Build Coastguard Worker /**
63*3ac0a46fSAndroid Build Coastguard Worker Allocate a memory block with elements initialized to 0
64*3ac0a46fSAndroid Build Coastguard Worker @param numOfElements  Blocks to allocate
65*3ac0a46fSAndroid Build Coastguard Worker @param sizeOfElements Bytes per block to allocate
66*3ac0a46fSAndroid Build Coastguard Worker @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
67*3ac0a46fSAndroid Build Coastguard Worker */
68*3ac0a46fSAndroid Build Coastguard Worker void * opj_calloc(size_t numOfElements, size_t sizeOfElements);
69*3ac0a46fSAndroid Build Coastguard Worker 
70*3ac0a46fSAndroid Build Coastguard Worker /**
71*3ac0a46fSAndroid Build Coastguard Worker Allocate memory aligned to a 16 byte boundary
72*3ac0a46fSAndroid Build Coastguard Worker @param size Bytes to allocate
73*3ac0a46fSAndroid Build Coastguard Worker @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
74*3ac0a46fSAndroid Build Coastguard Worker */
75*3ac0a46fSAndroid Build Coastguard Worker void * opj_aligned_malloc(size_t size);
76*3ac0a46fSAndroid Build Coastguard Worker void opj_aligned_free(void* ptr);
77*3ac0a46fSAndroid Build Coastguard Worker 
78*3ac0a46fSAndroid Build Coastguard Worker /**
79*3ac0a46fSAndroid Build Coastguard Worker Allocate memory aligned to a 32 byte boundary
80*3ac0a46fSAndroid Build Coastguard Worker @param size Bytes to allocate
81*3ac0a46fSAndroid Build Coastguard Worker @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
82*3ac0a46fSAndroid Build Coastguard Worker */
83*3ac0a46fSAndroid Build Coastguard Worker void * opj_aligned_32_malloc(size_t size);
84*3ac0a46fSAndroid Build Coastguard Worker 
85*3ac0a46fSAndroid Build Coastguard Worker /**
86*3ac0a46fSAndroid Build Coastguard Worker Reallocate memory blocks.
87*3ac0a46fSAndroid Build Coastguard Worker @param m Pointer to previously allocated memory block
88*3ac0a46fSAndroid Build Coastguard Worker @param s New size in bytes
89*3ac0a46fSAndroid Build Coastguard Worker @return Returns a void pointer to the reallocated (and possibly moved) memory block
90*3ac0a46fSAndroid Build Coastguard Worker */
91*3ac0a46fSAndroid Build Coastguard Worker void * opj_realloc(void * m, size_t s);
92*3ac0a46fSAndroid Build Coastguard Worker 
93*3ac0a46fSAndroid Build Coastguard Worker /**
94*3ac0a46fSAndroid Build Coastguard Worker Deallocates or frees a memory block.
95*3ac0a46fSAndroid Build Coastguard Worker @param m Previously allocated memory block to be freed
96*3ac0a46fSAndroid Build Coastguard Worker */
97*3ac0a46fSAndroid Build Coastguard Worker void opj_free(void * m);
98*3ac0a46fSAndroid Build Coastguard Worker 
99*3ac0a46fSAndroid Build Coastguard Worker #if defined(__GNUC__) && !defined(OPJ_SKIP_POISON)
100*3ac0a46fSAndroid Build Coastguard Worker #pragma GCC poison malloc calloc realloc free
101*3ac0a46fSAndroid Build Coastguard Worker #endif
102*3ac0a46fSAndroid Build Coastguard Worker 
103*3ac0a46fSAndroid Build Coastguard Worker /* ----------------------------------------------------------------------- */
104*3ac0a46fSAndroid Build Coastguard Worker /*@}*/
105*3ac0a46fSAndroid Build Coastguard Worker 
106*3ac0a46fSAndroid Build Coastguard Worker /*@}*/
107*3ac0a46fSAndroid Build Coastguard Worker 
108*3ac0a46fSAndroid Build Coastguard Worker #ifdef __cplusplus
109*3ac0a46fSAndroid Build Coastguard Worker }  // extern "C"
110*3ac0a46fSAndroid Build Coastguard Worker #endif
111*3ac0a46fSAndroid Build Coastguard Worker 
112*3ac0a46fSAndroid Build Coastguard Worker #endif /* OPJ_MALLOC_H */
113