Lines Matching refs:fd
165 android::base::unique_fd fd( in __has_memfd_support() local
167 if (fd == -1) { in __has_memfd_support()
172 if (fcntl(fd, F_ADD_SEALS, F_SEAL_FUTURE_WRITE) == -1) { in __has_memfd_support()
213 int fd = TEMP_FAILURE_RETRY(open(ashmem_device_path.c_str(), O_RDWR | O_CLOEXEC)); in __ashmem_open_locked() local
216 if (fd < 0) { in __ashmem_open_locked()
218 fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDWR | O_CLOEXEC)); in __ashmem_open_locked()
219 if (fd < 0) { in __ashmem_open_locked()
224 return fd; in __ashmem_open_locked()
228 int ret = TEMP_FAILURE_RETRY(fstat(fd, &st)); in __ashmem_open_locked()
231 close(fd); in __ashmem_open_locked()
236 close(fd); in __ashmem_open_locked()
242 return fd; in __ashmem_open_locked()
247 int fd; in __ashmem_open() local
250 fd = __ashmem_open_locked(); in __ashmem_open()
253 return fd; in __ashmem_open()
257 static int __ashmem_is_ashmem(int fd, int fatal) in __ashmem_is_ashmem() argument
262 if (fstat(fd, &st) < 0) { in __ashmem_is_ashmem()
273 int fd = __ashmem_open_locked(); in __ashmem_is_ashmem() local
274 if (fd < 0) { in __ashmem_is_ashmem()
281 close(fd); in __ashmem_is_ashmem()
292 fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev), in __ashmem_is_ashmem()
297 fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev), in __ashmem_is_ashmem()
307 static int __ashmem_check_failure(int fd, int result) in __ashmem_check_failure() argument
309 if (result == -1 && errno == ENOTTY) __ashmem_is_ashmem(fd, 1); in __ashmem_check_failure()
313 static bool memfd_is_ashmem(int fd) { in memfd_is_ashmem() argument
316 if (__ashmem_is_ashmem(fd, 0) == 0) { in memfd_is_ashmem()
328 int ashmem_valid(int fd) in ashmem_valid() argument
330 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_valid()
334 return __ashmem_is_ashmem(fd, 0) >= 0; in ashmem_valid()
340 android::base::unique_fd fd(syscall(__NR_memfd_create, name, MFD_CLOEXEC | MFD_ALLOW_SEALING)); in memfd_create_region() local
342 if (fd == -1) { in memfd_create_region()
347 if (ftruncate(fd, size) == -1) { in memfd_create_region()
353 if (fcntl(fd, F_ADD_SEALS, F_SEAL_GROW | F_SEAL_SHRINK) == -1) { in memfd_create_region()
359 ALOGE("memfd_create(%s, %zd) success. fd=%d\n", name, size, fd.get()); in memfd_create_region()
361 return fd.release(); in memfd_create_region()
379 int fd = __ashmem_open(); in ashmem_create_region() local
380 if (fd < 0) { in ashmem_create_region()
381 return fd; in ashmem_create_region()
388 ret = TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_NAME, buf)); in ashmem_create_region()
394 ret = TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_SIZE, size)); in ashmem_create_region()
399 return fd; in ashmem_create_region()
403 close(fd); in ashmem_create_region()
408 static int memfd_set_prot_region(int fd, int prot) { in memfd_set_prot_region() argument
409 int seals = fcntl(fd, F_GET_SEALS); in memfd_set_prot_region()
411 ALOGE("memfd_set_prot_region(%d, %d): F_GET_SEALS failed: %s\n", fd, prot, strerror(errno)); in memfd_set_prot_region()
420 ALOGE("memfd_set_prot_region(%d, %d): region is write protected\n", fd, prot); in memfd_set_prot_region()
429 if (fcntl(fd, F_ADD_SEALS, F_SEAL_FUTURE_WRITE | F_SEAL_SEAL) == -1) { in memfd_set_prot_region()
431 fd, prot, strerror(errno)); in memfd_set_prot_region()
438 int ashmem_set_prot_region(int fd, int prot) in ashmem_set_prot_region() argument
440 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_set_prot_region()
441 return memfd_set_prot_region(fd, prot); in ashmem_set_prot_region()
444 return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_PROT_MASK, prot))); in ashmem_set_prot_region()
447 int ashmem_pin_region(int fd, size_t offset, size_t len) in ashmem_pin_region() argument
454 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_pin_region()
460 return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_PIN, &pin))); in ashmem_pin_region()
463 int ashmem_unpin_region(int fd, size_t offset, size_t len) in ashmem_unpin_region() argument
470 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_unpin_region()
476 return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_UNPIN, &pin))); in ashmem_unpin_region()
479 int ashmem_get_size_region(int fd) in ashmem_get_size_region() argument
481 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_get_size_region()
484 if (fstat(fd, &sb) == -1) { in ashmem_get_size_region()
485 ALOGE("ashmem_get_size_region(%d): fstat failed: %s\n", fd, strerror(errno)); in ashmem_get_size_region()
490 ALOGD("ashmem_get_size_region(%d): %d\n", fd, static_cast<int>(sb.st_size)); in ashmem_get_size_region()
496 return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_GET_SIZE, NULL))); in ashmem_get_size_region()