MCPcopy Create free account
hub / github.com/cinit/TMoe / ashmem_create_region

Function ashmem_create_region

app/src/main/cpp/utils/shared_memory.cpp:106–137  ·  view source on GitHub ↗

* ashmem_create_region - creates a new ashmem region and returns the file * descriptor, or <0 on error * * `name' is an optional label to give the region (visible in /proc/pid/maps) * `size' is the size of the region, in page-aligned bytes */

Source from the content-addressed store, hash-verified

104 * `size' is the size of the region, in page-aligned bytes
105 */
106int ashmem_create_region(const char *name, size_t size) {
107 int ret, save_errno;
108 size_t pagesize = getpagesize();
109 if (size % pagesize != 0) {
110 size = pagesize * (size / pagesize + 1);
111 }
112 if (has_memfd_support()) {
113 return memfd_create_region_post_q(name ? name : "none", size);
114 }
115 int fd = ashmem_open_legacy();
116 if (fd < 0) {
117 return fd;
118 }
119 if (name) {
120 char buf[ASHMEM_NAME_LEN] = {0};
121 strncpy(buf, name, sizeof(buf));
122 ret = TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_NAME, buf));
123 if (ret < 0) {
124 goto L_ERROR;
125 }
126 }
127 ret = TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_SIZE, size));
128 if (ret < 0) {
129 goto L_ERROR;
130 }
131 return fd;
132 L_ERROR:
133 save_errno = errno;
134 close(fd);
135 errno = save_errno;
136 return ret;
137}
138
139int copy_file_to_memfd(int fd, const char *name) {
140 if (!has_memfd_support()) {

Callers

nothing calls this directly

Calls 3

has_memfd_supportFunction · 0.85
ashmem_open_legacyFunction · 0.85

Tested by

no test coverage detected