#include <cstring>
#include "include/private/base/SkAPI.h"
Go to the source code of this file.
|
SK_API void | sk_free (void *) |
|
SK_API void | sk_out_of_memory (void) |
|
SK_API void * | sk_malloc_flags (size_t size, unsigned flags) |
|
SK_API void * | sk_realloc_throw (void *buffer, size_t size) |
|
SK_API size_t | sk_malloc_size (void *addr, size_t size) |
|
static void * | sk_malloc_throw (size_t size) |
|
static void * | sk_calloc_throw (size_t size) |
|
static void * | sk_calloc_canfail (size_t size) |
|
SK_API void * | sk_calloc_throw (size_t count, size_t elemSize) |
|
SK_API void * | sk_malloc_throw (size_t count, size_t elemSize) |
|
SK_API void * | sk_realloc_throw (void *buffer, size_t count, size_t elemSize) |
|
static void * | sk_malloc_canfail (size_t size) |
|
SK_API void * | sk_malloc_canfail (size_t count, size_t elemSize) |
|
static void | sk_bzero (void *buffer, size_t size) |
|
static void * | sk_careful_memcpy (void *dst, const void *src, size_t len) |
|
static void * | sk_careful_memmove (void *dst, const void *src, size_t len) |
|
static int | sk_careful_memcmp (const void *a, const void *b, size_t len) |
|
◆ anonymous enum
Enumerator |
---|
SK_MALLOC_ZERO_INITIALIZE | If this bit is set, the returned buffer must be zero-initialized. If this bit is not set the buffer can be uninitialized.
|
SK_MALLOC_THROW | If this bit is set, the implementation must throw/crash/quit if the request cannot be fulfilled. If this bit is not set, then it should return nullptr on failure.
|
Definition at line 29 of file SkMalloc.h.
29 {
30
31
32
33
35
36
37
38
39
41};
@ SK_MALLOC_ZERO_INITIALIZE
◆ sk_bzero()
static void sk_bzero |
( |
void * |
buffer, |
|
|
size_t |
size |
|
) |
| |
|
inlinestatic |
Definition at line 105 of file SkMalloc.h.
105 {
106
109 }
110}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
◆ sk_calloc_canfail()
static void * sk_calloc_canfail |
( |
size_t |
size | ) |
|
|
inlinestatic |
Definition at line 75 of file SkMalloc.h.
75 {
76#if defined(SK_BUILD_FOR_FUZZER)
77
79 return nullptr;
80 }
81#endif
83}
SK_API void * sk_malloc_flags(size_t size, unsigned flags)
◆ sk_calloc_throw() [1/2]
SK_API void * sk_calloc_throw |
( |
size_t |
count, |
|
|
size_t |
elemSize |
|
) |
| |
Definition at line 8 of file SkMalloc.cpp.
8 {
10}
void * sk_calloc_throw(size_t count, size_t elemSize)
static size_t Mul(size_t x, size_t y)
◆ sk_calloc_throw() [2/2]
static void * sk_calloc_throw |
( |
size_t |
size | ) |
|
|
inlinestatic |
◆ sk_careful_memcmp()
static int sk_careful_memcmp |
( |
const void * |
a, |
|
|
const void * |
b, |
|
|
size_t |
len |
|
) |
| |
|
inlinestatic |
Definition at line 143 of file SkMalloc.h.
143 {
144
145
147 return 0;
148 }
149 return memcmp(
a,
b,
len);
150}
◆ sk_careful_memcpy()
static void * sk_careful_memcpy |
( |
void * |
dst, |
|
|
const void * |
src, |
|
|
size_t |
len |
|
) |
| |
|
inlinestatic |
sk_careful_memcpy() is just like memcpy(), but guards against undefined behavior.
It is undefined behavior to call memcpy() with null dst or src, even if len is 0. If an optimizer is "smart" enough, it can exploit this to do unexpected things. memcpy(dst, src, 0); if (src) { printf("%x\n", *src); } In this code the compiler can assume src is not null and omit the if (src) {...} check, unconditionally running the printf, crashing the program if src really is null. Of the compilers we pay attention to only GCC performs this optimization in practice.
Definition at line 125 of file SkMalloc.h.
◆ sk_careful_memmove()
static void * sk_careful_memmove |
( |
void * |
dst, |
|
|
const void * |
src, |
|
|
size_t |
len |
|
) |
| |
|
inlinestatic |
◆ sk_free()
SK_API void sk_free |
( |
void * |
p | ) |
|
Free memory returned by sk_malloc(). It is safe to pass null.
Definition at line 83 of file SkMemory_malloc.cpp.
◆ sk_malloc_canfail() [1/2]
SK_API void * sk_malloc_canfail |
( |
size_t |
count, |
|
|
size_t |
elemSize |
|
) |
| |
Definition at line 20 of file SkMalloc.cpp.
20 {
22}
void * sk_malloc_canfail(size_t count, size_t elemSize)
◆ sk_malloc_canfail() [2/2]
static void * sk_malloc_canfail |
( |
size_t |
size | ) |
|
|
inlinestatic |
These variants return nullptr on failure
Definition at line 93 of file SkMalloc.h.
93 {
94#if defined(SK_BUILD_FOR_FUZZER)
95
97 return nullptr;
98 }
99#endif
101}
◆ sk_malloc_flags()
SK_API void * sk_malloc_flags |
( |
size_t |
size, |
|
|
unsigned |
flags |
|
) |
| |
Return a block of memory (at least 4-byte aligned) of at least the specified size. If the requested memory cannot be returned, either return nullptr or throw/exit, depending on the SK_MALLOC_THROW bit. If the allocation succeeds, the memory will be zero-initialized if the SK_MALLOC_ZERO_INITIALIZE bit was set.
To free the memory, call sk_free()
Definition at line 91 of file SkMemory_malloc.cpp.
91 {
95 } else {
96#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(__BIONIC__)
97
98
99
100
101
102
103
104
105 (void)mallopt(M_THREAD_DISABLE_MEM_INIT, 1);
106#endif
108#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && defined(__BIONIC__)
109 (void)mallopt(M_THREAD_DISABLE_MEM_INIT, 0);
110#endif
111 }
114 } else {
116 }
117}
static void * throw_on_failure(size_t size, void *p)
FlutterSemanticsFlag flags
void * malloc(size_t size)
void * calloc(size_t n, size_t size)
◆ sk_malloc_size()
SK_API size_t sk_malloc_size |
( |
void * |
addr, |
|
|
size_t |
size |
|
) |
| |
Return the size of the block of memory allocated in reality for a given pointer. The pointer passed must have been allocated using the sk_malloc_* or sk_realloc_* functions. The "size" parameter indicates the size originally requested when the memory block was allocated, and the value returned by this function must be bigger or equal to it.
Definition at line 119 of file SkMemory_malloc.cpp.
119 {
120 size_t completeSize =
size;
121
122
123 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
124
126 #elif defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 17
127 completeSize = malloc_usable_size(
addr);
129 #elif defined(SK_BUILD_FOR_UNIX)
130 completeSize = malloc_usable_size(
addr);
132 #elif defined(SK_BUILD_FOR_WIN)
133 completeSize = _msize(
addr);
135 #endif
136
137 return completeSize;
138}
static float max(float r, float g, float b)
◆ sk_malloc_throw() [1/2]
SK_API void * sk_malloc_throw |
( |
size_t |
count, |
|
|
size_t |
elemSize |
|
) |
| |
Definition at line 12 of file SkMalloc.cpp.
12 {
14}
void * sk_malloc_throw(size_t count, size_t elemSize)
◆ sk_malloc_throw() [2/2]
static void * sk_malloc_throw |
( |
size_t |
size | ) |
|
|
inlinestatic |
◆ sk_out_of_memory()
SK_API void sk_out_of_memory |
( |
void |
| ) |
|
Called internally if we run out of memory. The platform implementation must not return, but should either throw an exception or otherwise exit.
Definition at line 66 of file SkMemory_malloc.cpp.
66 {
68#if defined(SK_BUILD_FOR_AFL_FUZZ)
70#else
71 abort();
72#endif
73}
#define SkDEBUGFAIL(message)
◆ sk_realloc_throw() [1/2]
SK_API void * sk_realloc_throw |
( |
void * |
buffer, |
|
|
size_t |
count, |
|
|
size_t |
elemSize |
|
) |
| |
Definition at line 16 of file SkMalloc.cpp.
16 {
18}
void * sk_realloc_throw(void *buffer, size_t count, size_t elemSize)
◆ sk_realloc_throw() [2/2]
SK_API void * sk_realloc_throw |
( |
void * |
buffer, |
|
|
size_t |
size |
|
) |
| |
Same as standard realloc(), but this one never returns null on failure. It will throw if it fails. If size is 0, it will call sk_free on buffer and return null. (This behavior is implementation- defined for normal realloc. We follow what glibc does.)
Definition at line 75 of file SkMemory_malloc.cpp.
75 {
78 return nullptr;
79 }
81}
void * realloc(void *ptr, size_t size)