Skip to content

Commit b93cb95

Browse files
Mark FashehAvenger-285714
authored andcommitted
ANDROID: Add ashmem ioctl to return a unique file identifier
This will allow a client program to avoid redundant actions on ashmem buffers which it has already seen. Bug: 244233389 Change-Id: Ica57a8842ff163eae5f9eca8141b439091ec0940 Signed-off-by: Mark Fasheh <mfasheh@google.com> (cherry picked from commit fb15c7c8b02354464e3a1c54d9a1700e3470c7a2) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 1bd9124 commit b93cb95

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

drivers/staging/android/ashmem.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
820820
static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
821821
{
822822
struct ashmem_area *asma = file->private_data;
823+
unsigned long ino;
823824
long ret = -ENOTTY;
824825

825826
switch (cmd) {
@@ -863,6 +864,23 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
863864
ashmem_shrink_scan(&ashmem_shrinker, &sc);
864865
}
865866
break;
867+
case ASHMEM_GET_FILE_ID:
868+
/* Lock around our check to avoid racing with ashmem_mmap(). */
869+
mutex_lock(&ashmem_mutex);
870+
if (!asma || !asma->file) {
871+
mutex_unlock(&ashmem_mutex);
872+
ret = -EINVAL;
873+
break;
874+
}
875+
ino = file_inode(asma->file)->i_ino;
876+
mutex_unlock(&ashmem_mutex);
877+
878+
if (copy_to_user((void __user *)arg, &ino, sizeof(ino))) {
879+
ret = -EFAULT;
880+
break;
881+
}
882+
ret = 0;
883+
break;
866884
}
867885

868886
return ret;

drivers/staging/android/uapi/ashmem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ struct ashmem_pin {
3939
#define ASHMEM_UNPIN _IOW(__ASHMEMIOC, 8, struct ashmem_pin)
4040
#define ASHMEM_GET_PIN_STATUS _IO(__ASHMEMIOC, 9)
4141
#define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10)
42+
#define ASHMEM_GET_FILE_ID _IOR(__ASHMEMIOC, 11, unsigned long)
4243

4344
#endif /* _UAPI_LINUX_ASHMEM_H */

0 commit comments

Comments
 (0)