Skip to content

Commit

Permalink
ntsync: Introduce NTSYNC_IOC_MUTEX_READ.
Browse files Browse the repository at this point in the history
This corresponds to the NT syscall NtQueryMutant().

This returns the recursion count, owner, and abandoned state of the mutex.

Signed-off-by: Elizabeth Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Frade <kernel@xanmod.org>
  • Loading branch information
Elizabeth Figura authored and xanmod committed Mar 1, 2024
1 parent a883ae8 commit 38a776c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions drivers/misc/ntsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,27 @@ static int ntsync_sem_read(struct ntsync_obj *sem, void __user *argp)
return 0;
}

static int ntsync_mutex_read(struct ntsync_obj *mutex, void __user *argp)
{
struct ntsync_mutex_args __user *user_args = argp;
struct ntsync_mutex_args args;
int ret;

if (mutex->type != NTSYNC_TYPE_MUTEX)
return -EINVAL;

args.mutex = 0;
spin_lock(&mutex->lock);
args.count = mutex->u.mutex.count;
args.owner = mutex->u.mutex.owner;
ret = mutex->u.mutex.ownerdead ? -EOWNERDEAD : 0;
spin_unlock(&mutex->lock);

if (copy_to_user(user_args, &args, sizeof(args)))
return -EFAULT;
return ret;
}

static int ntsync_obj_release(struct inode *inode, struct file *file)
{
struct ntsync_obj *obj = file->private_data;
Expand All @@ -572,6 +593,8 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd,
return ntsync_mutex_unlock(obj, argp);
case NTSYNC_IOC_MUTEX_KILL:
return ntsync_mutex_kill(obj, argp);
case NTSYNC_IOC_MUTEX_READ:
return ntsync_mutex_read(obj, argp);
case NTSYNC_IOC_EVENT_SET:
return ntsync_event_set(obj, argp, false);
case NTSYNC_IOC_EVENT_RESET:
Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/ntsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ struct ntsync_wait_args {
#define NTSYNC_IOC_EVENT_RESET _IOR ('N', 0x89, __u32)
#define NTSYNC_IOC_EVENT_PULSE _IOR ('N', 0x8a, __u32)
#define NTSYNC_IOC_SEM_READ _IOR ('N', 0x8b, struct ntsync_sem_args)
#define NTSYNC_IOC_MUTEX_READ _IOR ('N', 0x8c, struct ntsync_mutex_args)

#endif

0 comments on commit 38a776c

Please sign in to comment.