ANDROID: Add ashmem ioctl to return a unique file identifier 33/310533/1
authorMark Fasheh <mfasheh@google.com>
Thu, 27 Oct 2022 23:48:03 +0000 (23:48 +0000)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 30 Apr 2024 08:34:20 +0000 (17:34 +0900)
This will allow a client program to avoid redundant actions on ashmem
buffers which it has already seen.

Bug: 244233389
Signed-off-by: Mark Fasheh <mfasheh@google.com>
[sw0312.kim: cherry-pick commit fb15c7c8b023 of https://android.googlesource.com/kernel/common/+/refs/heads/android15-6.6 to support waydroid on tizen]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ica57a8842ff163eae5f9eca8141b439091ec0940

drivers/staging/android/ashmem.c
drivers/staging/android/uapi/ashmem.h

index ce1e2ab..feadf79 100644 (file)
@@ -820,6 +820,7 @@ out_unlock:
 static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct ashmem_area *asma = file->private_data;
+       unsigned long ino;
        long ret = -ENOTTY;
 
        switch (cmd) {
@@ -863,6 +864,23 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        ashmem_shrink_scan(&ashmem_shrinker, &sc);
                }
                break;
+       case ASHMEM_GET_FILE_ID:
+               /* Lock around our check to avoid racing with ashmem_mmap(). */
+               mutex_lock(&ashmem_mutex);
+               if (!asma || !asma->file) {
+                       mutex_unlock(&ashmem_mutex);
+                       ret = -EINVAL;
+                       break;
+               }
+               ino = file_inode(asma->file)->i_ino;
+               mutex_unlock(&ashmem_mutex);
+
+               if (copy_to_user((void __user *)arg, &ino, sizeof(ino))) {
+                       ret = -EFAULT;
+                       break;
+               }
+               ret = 0;
+               break;
        }
 
        return ret;
index 134efac..f962a5f 100644 (file)
@@ -39,5 +39,6 @@ struct ashmem_pin {
 #define ASHMEM_UNPIN           _IOW(__ASHMEMIOC, 8, struct ashmem_pin)
 #define ASHMEM_GET_PIN_STATUS  _IO(__ASHMEMIOC, 9)
 #define ASHMEM_PURGE_ALL_CACHES        _IO(__ASHMEMIOC, 10)
+#define ASHMEM_GET_FILE_ID             _IOR(__ASHMEMIOC, 11, unsigned long)
 
 #endif /* _UAPI_LINUX_ASHMEM_H */