ANDROID: ashmem_rust: Add support for querying the size of an ashmem region

Given a pointer to a file structure that represents an ashmem region,
return the size of the region. This should only be used for dumping
information about ashmem regions in debug scenarios.

Bug: 193397560
Change-Id: I24e6a2f7a469d667dc37ec8714e591b911043ee4
Signed-off-by: Isaac J. Manjarres <isaacmanjarres@google.com>
This commit is contained in:
Isaac J. Manjarres
2025-07-02 22:46:26 +00:00
committed by Isaac Manjarres
parent eb50f663c4
commit 0be74214c0
3 changed files with 19 additions and 0 deletions

View File

@@ -33,5 +33,6 @@ enum {
bool is_ashmem_file(struct file *file);
int ashmem_area_name(struct file *file, char *name);
long ashmem_area_size(struct file *file);
#endif /* _LINUX_ASHMEM_H */

View File

@@ -707,3 +707,20 @@ unsafe extern "C" fn ashmem_area_name(
Err(err) => err.to_errno() as c_int,
}
}
/// # Safety
///
/// The caller must ensure that `file` is valid for the duration of this function.
#[no_mangle]
unsafe extern "C" fn ashmem_area_size(file: *mut bindings::file) -> isize {
// SAFETY: file is valid for the duration of this function.
let ashmem = match unsafe { get_ashmem_area(file) } {
Ok(area) => area,
Err(_err) => return 0,
};
match ashmem.get_size() {
Ok(size) => size,
Err(_err) => 0,
}
}

View File

@@ -18,3 +18,4 @@
*/
EXPORT_SYMBOL_GPL(is_ashmem_file);
EXPORT_SYMBOL_GPL(ashmem_area_name);
EXPORT_SYMBOL_GPL(ashmem_area_size);