xref: /aosp_15_r20/external/pdfium/third_party/libopenjpeg/0034-opj_malloc.patch (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1*3ac0a46fSAndroid Build Coastguard Workerdiff --git a/third_party/libopenjpeg/opj_malloc.cc b/third_party/libopenjpeg/opj_malloc.cc
2*3ac0a46fSAndroid Build Coastguard Workernew file mode 100644
3*3ac0a46fSAndroid Build Coastguard Worker--- /dev/null
4*3ac0a46fSAndroid Build Coastguard Worker+++ b/third_party/libopenjpeg/opj_malloc.cc
5*3ac0a46fSAndroid Build Coastguard Worker@@ -0,0 +1,42 @@
6*3ac0a46fSAndroid Build Coastguard Worker+// Copyright 2020 The PDFium Authors
7*3ac0a46fSAndroid Build Coastguard Worker+// Use of this source code is governed by a BSD-style license that can be
8*3ac0a46fSAndroid Build Coastguard Worker+// found in the LICENSE file.
9*3ac0a46fSAndroid Build Coastguard Worker+
10*3ac0a46fSAndroid Build Coastguard Worker+// Deliberately not including opj_malloc.h, which has poisoned malloc and
11*3ac0a46fSAndroid Build Coastguard Worker+// friends.
12*3ac0a46fSAndroid Build Coastguard Worker+
13*3ac0a46fSAndroid Build Coastguard Worker+#include "core/fxcrt/fx_memory.h"
14*3ac0a46fSAndroid Build Coastguard Worker+#include "third_party/base/memory/aligned_memory.h"
15*3ac0a46fSAndroid Build Coastguard Worker+
16*3ac0a46fSAndroid Build Coastguard Worker+extern "C" {
17*3ac0a46fSAndroid Build Coastguard Worker+
18*3ac0a46fSAndroid Build Coastguard Worker+void* opj_malloc(size_t size) {
19*3ac0a46fSAndroid Build Coastguard Worker+  return FXMEM_DefaultAlloc(size);
20*3ac0a46fSAndroid Build Coastguard Worker+}
21*3ac0a46fSAndroid Build Coastguard Worker+
22*3ac0a46fSAndroid Build Coastguard Worker+void* opj_calloc(size_t numOfElements, size_t sizeOfElements) {
23*3ac0a46fSAndroid Build Coastguard Worker+  return FXMEM_DefaultCalloc(numOfElements, sizeOfElements);
24*3ac0a46fSAndroid Build Coastguard Worker+}
25*3ac0a46fSAndroid Build Coastguard Worker+
26*3ac0a46fSAndroid Build Coastguard Worker+void* opj_aligned_malloc(size_t size) {
27*3ac0a46fSAndroid Build Coastguard Worker+  return size ? pdfium::base::AlignedAlloc(size, 16) : nullptr;
28*3ac0a46fSAndroid Build Coastguard Worker+}
29*3ac0a46fSAndroid Build Coastguard Worker+
30*3ac0a46fSAndroid Build Coastguard Worker+void opj_aligned_free(void* ptr) {
31*3ac0a46fSAndroid Build Coastguard Worker+  pdfium::base::AlignedFree(ptr);
32*3ac0a46fSAndroid Build Coastguard Worker+}
33*3ac0a46fSAndroid Build Coastguard Worker+
34*3ac0a46fSAndroid Build Coastguard Worker+void* opj_aligned_32_malloc(size_t size) {
35*3ac0a46fSAndroid Build Coastguard Worker+  return size ? pdfium::base::AlignedAlloc(size, 32) : nullptr;
36*3ac0a46fSAndroid Build Coastguard Worker+}
37*3ac0a46fSAndroid Build Coastguard Worker+
38*3ac0a46fSAndroid Build Coastguard Worker+void* opj_realloc(void* m, size_t s) {
39*3ac0a46fSAndroid Build Coastguard Worker+  return FXMEM_DefaultRealloc(m, s);
40*3ac0a46fSAndroid Build Coastguard Worker+}
41*3ac0a46fSAndroid Build Coastguard Worker+
42*3ac0a46fSAndroid Build Coastguard Worker+void opj_free(void* m) {
43*3ac0a46fSAndroid Build Coastguard Worker+  if (m)
44*3ac0a46fSAndroid Build Coastguard Worker+    FXMEM_DefaultFree(m);
45*3ac0a46fSAndroid Build Coastguard Worker+}
46*3ac0a46fSAndroid Build Coastguard Worker+
47*3ac0a46fSAndroid Build Coastguard Worker+}  // extern "C"
48*3ac0a46fSAndroid Build Coastguard Workerdiff --git a/third_party/libopenjpeg/opj_malloc.h b/third_party/libopenjpeg/opj_malloc.h
49*3ac0a46fSAndroid Build Coastguard Worker--- a/third_party/libopenjpeg/opj_malloc.h
50*3ac0a46fSAndroid Build Coastguard Worker+++ b/third_party/libopenjpeg/opj_malloc.h
51*3ac0a46fSAndroid Build Coastguard Worker@@ -33,6 +33,11 @@
52*3ac0a46fSAndroid Build Coastguard Worker #define OPJ_MALLOC_H
53*3ac0a46fSAndroid Build Coastguard Worker
54*3ac0a46fSAndroid Build Coastguard Worker #include <stddef.h>
55*3ac0a46fSAndroid Build Coastguard Worker+
56*3ac0a46fSAndroid Build Coastguard Worker+#ifdef __cplusplus
57*3ac0a46fSAndroid Build Coastguard Worker+extern "C" {
58*3ac0a46fSAndroid Build Coastguard Worker+#endif
59*3ac0a46fSAndroid Build Coastguard Worker+
60*3ac0a46fSAndroid Build Coastguard Worker /**
61*3ac0a46fSAndroid Build Coastguard Worker @file opj_malloc.h
62*3ac0a46fSAndroid Build Coastguard Worker @brief Internal functions
63*3ac0a46fSAndroid Build Coastguard Worker@@ -68,7 +73,6 @@ Allocate memory aligned to a 16 byte bou
64*3ac0a46fSAndroid Build Coastguard Worker @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
65*3ac0a46fSAndroid Build Coastguard Worker */
66*3ac0a46fSAndroid Build Coastguard Worker void * opj_aligned_malloc(size_t size);
67*3ac0a46fSAndroid Build Coastguard Worker-void * opj_aligned_realloc(void *ptr, size_t size);
68*3ac0a46fSAndroid Build Coastguard Worker void opj_aligned_free(void* ptr);
69*3ac0a46fSAndroid Build Coastguard Worker
70*3ac0a46fSAndroid Build Coastguard Worker /**
71*3ac0a46fSAndroid Build Coastguard Worker@@ -77,7 +81,6 @@ Allocate memory aligned to a 32 byte bou
72*3ac0a46fSAndroid Build Coastguard Worker @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
73*3ac0a46fSAndroid Build Coastguard Worker */
74*3ac0a46fSAndroid Build Coastguard Worker void * opj_aligned_32_malloc(size_t size);
75*3ac0a46fSAndroid Build Coastguard Worker-void * opj_aligned_32_realloc(void *ptr, size_t size);
76*3ac0a46fSAndroid Build Coastguard Worker
77*3ac0a46fSAndroid Build Coastguard Worker /**
78*3ac0a46fSAndroid Build Coastguard Worker Reallocate memory blocks.
79*3ac0a46fSAndroid Build Coastguard Worker@@ -102,5 +105,8 @@ void opj_free(void * m);
80*3ac0a46fSAndroid Build Coastguard Worker
81*3ac0a46fSAndroid Build Coastguard Worker /*@}*/
82*3ac0a46fSAndroid Build Coastguard Worker
83*3ac0a46fSAndroid Build Coastguard Worker-#endif /* OPJ_MALLOC_H */
84*3ac0a46fSAndroid Build Coastguard Worker+#ifdef __cplusplus
85*3ac0a46fSAndroid Build Coastguard Worker+}  // extern "C"
86*3ac0a46fSAndroid Build Coastguard Worker+#endif
87*3ac0a46fSAndroid Build Coastguard Worker
88*3ac0a46fSAndroid Build Coastguard Worker+#endif /* OPJ_MALLOC_H */
89