Lines Matching refs:fd

163     android::base::unique_fd fd(  in __has_memfd_support()  local
165 if (fd == -1) { in __has_memfd_support()
170 if (fcntl(fd, F_ADD_SEALS, F_SEAL_FUTURE_WRITE) == -1) { in __has_memfd_support()
211 int fd = TEMP_FAILURE_RETRY(open(ashmem_device_path.c_str(), O_RDWR | O_CLOEXEC)); in __ashmem_open_locked() local
214 if (fd < 0) { in __ashmem_open_locked()
215 fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDWR | O_CLOEXEC)); in __ashmem_open_locked()
218 if (fd < 0) { in __ashmem_open_locked()
219 return fd; in __ashmem_open_locked()
223 int ret = TEMP_FAILURE_RETRY(fstat(fd, &st)); in __ashmem_open_locked()
226 close(fd); in __ashmem_open_locked()
231 close(fd); in __ashmem_open_locked()
237 return fd; in __ashmem_open_locked()
242 int fd; in __ashmem_open() local
245 fd = __ashmem_open_locked(); in __ashmem_open()
248 return fd; in __ashmem_open()
252 static int __ashmem_is_ashmem(int fd, int fatal) in __ashmem_is_ashmem() argument
257 if (fstat(fd, &st) < 0) { in __ashmem_is_ashmem()
268 int fd = __ashmem_open_locked(); in __ashmem_is_ashmem() local
269 if (fd < 0) { in __ashmem_is_ashmem()
276 close(fd); in __ashmem_is_ashmem()
287 fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev), in __ashmem_is_ashmem()
292 fd, st.st_mode, major(st.st_rdev), minor(st.st_rdev), in __ashmem_is_ashmem()
302 static int __ashmem_check_failure(int fd, int result) in __ashmem_check_failure() argument
304 if (result == -1 && errno == ENOTTY) __ashmem_is_ashmem(fd, 1); in __ashmem_check_failure()
308 static bool memfd_is_ashmem(int fd) { in memfd_is_ashmem() argument
311 if (__ashmem_is_ashmem(fd, 0) == 0) { in memfd_is_ashmem()
323 int ashmem_valid(int fd) in ashmem_valid() argument
325 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_valid()
329 return __ashmem_is_ashmem(fd, 0) >= 0; in ashmem_valid()
333 android::base::unique_fd fd(syscall(__NR_memfd_create, name, MFD_ALLOW_SEALING)); in memfd_create_region() local
335 if (fd == -1) { in memfd_create_region()
340 if (ftruncate(fd, size) == -1) { in memfd_create_region()
346 ALOGE("memfd_create(%s, %zd) success. fd=%d\n", name, size, fd.get()); in memfd_create_region()
348 return fd.release(); in memfd_create_region()
366 int fd = __ashmem_open(); in ashmem_create_region() local
367 if (fd < 0) { in ashmem_create_region()
368 return fd; in ashmem_create_region()
375 ret = TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_NAME, buf)); in ashmem_create_region()
381 ret = TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_SIZE, size)); in ashmem_create_region()
386 return fd; in ashmem_create_region()
390 close(fd); in ashmem_create_region()
395 static int memfd_set_prot_region(int fd, int prot) { in memfd_set_prot_region() argument
401 if (fcntl(fd, F_ADD_SEALS, F_SEAL_FUTURE_WRITE) == -1) { in memfd_set_prot_region()
402 ALOGE("memfd_set_prot_region(%d, %d): F_SEAL_FUTURE_WRITE seal failed: %s\n", fd, prot, in memfd_set_prot_region()
410 int ashmem_set_prot_region(int fd, int prot) in ashmem_set_prot_region() argument
412 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_set_prot_region()
413 return memfd_set_prot_region(fd, prot); in ashmem_set_prot_region()
416 return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_SET_PROT_MASK, prot))); in ashmem_set_prot_region()
419 int ashmem_pin_region(int fd, size_t offset, size_t len) in ashmem_pin_region() argument
426 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_pin_region()
432 return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_PIN, &pin))); in ashmem_pin_region()
435 int ashmem_unpin_region(int fd, size_t offset, size_t len) in ashmem_unpin_region() argument
442 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_unpin_region()
448 return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_UNPIN, &pin))); in ashmem_unpin_region()
451 int ashmem_get_size_region(int fd) in ashmem_get_size_region() argument
453 if (has_memfd_support() && !memfd_is_ashmem(fd)) { in ashmem_get_size_region()
456 if (fstat(fd, &sb) == -1) { in ashmem_get_size_region()
457 ALOGE("ashmem_get_size_region(%d): fstat failed: %s\n", fd, strerror(errno)); in ashmem_get_size_region()
462 ALOGD("ashmem_get_size_region(%d): %d\n", fd, static_cast<int>(sb.st_size)); in ashmem_get_size_region()
468 return __ashmem_check_failure(fd, TEMP_FAILURE_RETRY(ioctl(fd, ASHMEM_GET_SIZE, NULL))); in ashmem_get_size_region()