* 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 */
| 104 | * `size' is the size of the region, in page-aligned bytes |
| 105 | */ |
| 106 | int 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 | |
| 139 | int copy_file_to_memfd(int fd, const char *name) { |
| 140 | if (!has_memfd_support()) { |
nothing calls this directly
no test coverage detected