Skip to content

Commit

Permalink
winesync: Introduce WINESYNC_IOC_READ_MUTEX
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebediah Figura authored and xanmod committed May 30, 2022
1 parent f97d5bc commit 79ee408
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions drivers/misc/winesync.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,35 @@ static int winesync_read_sem(struct winesync_device *dev, void __user *argp)
return 0;
}

static int winesync_read_mutex(struct winesync_device *dev, void __user *argp)
{
struct winesync_mutex_args __user *user_args = argp;
struct winesync_mutex_args args;
struct winesync_obj *mutex;
__u32 id;
int ret;

if (get_user(id, &user_args->mutex))
return -EFAULT;

mutex = get_obj_typed(dev, id, WINESYNC_TYPE_MUTEX);
if (!mutex)
return -EINVAL;

args.mutex = id;
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);

put_obj(mutex);

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

/*
* Actually change the mutex state to mark its owner as dead.
*/
Expand Down Expand Up @@ -908,6 +937,8 @@ static long winesync_char_ioctl(struct file *file, unsigned int cmd,
return winesync_put_mutex(dev, argp);
case WINESYNC_IOC_PUT_SEM:
return winesync_put_sem(dev, argp);
case WINESYNC_IOC_READ_MUTEX:
return winesync_read_mutex(dev, argp);
case WINESYNC_IOC_READ_SEM:
return winesync_read_sem(dev, argp);
case WINESYNC_IOC_WAIT_ALL:
Expand Down
2 changes: 2 additions & 0 deletions include/uapi/linux/winesync.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ struct winesync_wait_args {
#define WINESYNC_IOC_KILL_OWNER _IOW (WINESYNC_IOC_BASE, 7, __u32)
#define WINESYNC_IOC_READ_SEM _IOWR(WINESYNC_IOC_BASE, 8, \
struct winesync_sem_args)
#define WINESYNC_IOC_READ_MUTEX _IOWR(WINESYNC_IOC_BASE, 9, \
struct winesync_mutex_args)

#endif

0 comments on commit 79ee408

Please sign in to comment.