#![cfg(target_os = "android")] //! Provides a wrapper around Android's ASharedMemory API. //! //! ashmem has existed in Android as a non-public API for some time. //! Originally accessed via ioctl, it was later available via libcutils as ashmem_create_region etc. //! ASharedMemory is the new public API, but it isn't available until API 26 (Android 8). //! Builds targeting Android 10 (API 29) are no longer permitted to access ashmem via the ioctl interface. //! This makes life for a portable program difficult - you can't reliably use the old or new interface during this transition period. //! We try to dynamically load the new API first, then fall back to the ioctl interface. //! //! References: //! - [ASharedMemory documentation](https://developer.android.com/ndk/reference/group/memory) //! - [Linux ashmem.h definitions](https://elixir.bootlin.com/linux/v5.11.8/source/drivers/staging/android/uapi/ashmem.h)
let fd = libc::open(ASHMEM_NAME_DEF, libc::O_RDWR, 0o600); if fd < 0 { return fd;
}
if !name.is_null() { // NOTE: libcutils uses a local stack copy of `name`. let r = libc::ioctl(fd, ASHMEM_SET_NAME, name); if r != 0 {
libc::close(fd); return -1;
}
}
let r = libc::ioctl(fd, ASHMEM_SET_SIZE, size); if r != 0 {
libc::close(fd); return -1;
}
fd
}
/// See [ASharedMemory_getSize NDK documentation](https://developer.android.com/ndk/reference/group/memory#asharedmemory_getsize) /// /// # Safety /// /// Directly calls C or kernel APIs. #[allow(non_snake_case)] pubunsafefn ASharedMemory_getSize(fd: libc::c_int) -> libc::size_t { const ASHMEM_GET_SIZE: libc::c_int = io!(__ASHMEMIOC, 4) as _;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.