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:
committed by
Isaac Manjarres
parent
eb50f663c4
commit
0be74214c0
@@ -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 */
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,3 +18,4 @@
|
||||
*/
|
||||
EXPORT_SYMBOL_GPL(is_ashmem_file);
|
||||
EXPORT_SYMBOL_GPL(ashmem_area_name);
|
||||
EXPORT_SYMBOL_GPL(ashmem_area_size);
|
||||
|
||||
Reference in New Issue
Block a user