From patchwork Wed Feb 14 23:52:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 201192 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp62289dyb; Wed, 14 Feb 2024 15:58:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVgh7yBibv6mkjgXySvyvGutaG4FFHKFWiOLBgVT/TIRVgY119iSssfARFbbDD7CXIN9ITQ5Mos5yJ1ucZFMnivJsK5IQ== X-Google-Smtp-Source: AGHT+IFaMmsvC5vo3zvGNAftuCsH5cfAYzlmyzgG5iZAYA067bJBTvsr3wpkM3l+LX4S5q5IDO6R X-Received: by 2002:a5b:991:0:b0:dc7:32ea:c89f with SMTP id c17-20020a5b0991000000b00dc732eac89fmr110377ybq.15.1707955125401; Wed, 14 Feb 2024 15:58:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707955125; cv=pass; d=google.com; s=arc-20160816; b=vEh8Vs+iADIgwJgM62KBV6Qm/y2vI5BUNr5RFj5EFy6hgkQD/arkxgA8F3IxQlHpBb ZnfysxtdsL9mvG7rrA6WaBtrCiyduiHfM/i7pFvVUhH+tmgyhZ1t62TtePShSzvXF+ea vvYgTAStbKvDOp6pcH7npsHCgRBLjyg6cZqW26v9U64IPYS6VFpLsd0Yq4fScc0XSd1A smZSd2Mab+qcPSa1VOiYoPgw1tRlJBesaiT6Pb65sVFrxJwX4nr0h0yZ5m6pVjtkszQj wWWC8FwdiYwv1YFeNOLkoE43au48p+MtNY/dGySUtPBhLM8JDGW9PkkdkK0tI9sc/92M VFoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1u6I14flCka8KvOp2oxl+aQw0301epnL+50/ePKMgkQ=; fh=sOAzP1IXJnllEbSCBRlwdfT0MN3UiaRLwzx1Tpw7GJA=; b=O3dWhspQRVxnnNUkwETkumabXqHsa71ZTa6oDCBZ8knthoyM8uoZ71htvnCV098W/h t/fySMtVs8EG+oFxjZ/B5Y2AFWje6akrehMOhlTgxiPy5cRp1k6QgEyFq3UuGYJ0ks+T mi84CnozXCQNp7RE9NAK4XBk0wEQhQCfdvGUiQBD/q6ZtR/Z+cWxEZfwNRFw5nQs3SSp 356CCm9imxcL7hXHZzFU+IOfoatpk3PxR+vAtvDlwmLS5cgoZRwaBJZFZmuYVCkGu14V yYBJdlLs6UwLtoGzTJwHEpqUuWafpU0r29LNpL/dUskr2aVibGehdTgrFHg26vgEBG77 ssDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b="T/9JqNhq"; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-66146-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66146-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b13-20020a65668d000000b005dbe215856dsi5875pgw.765.2024.02.14.15.58.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 15:58:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66146-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b="T/9JqNhq"; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-66146-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66146-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id ECAA9291AA1 for ; Wed, 14 Feb 2024 23:56:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0895E1487F6; Wed, 14 Feb 2024 23:53:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="T/9JqNhq" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A86AE1474B2; Wed, 14 Feb 2024 23:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707954815; cv=none; b=g/ZCYHAEJ5vV4P/hseNWVXb0GF4uXRp5i2m1Fcy2+yHqdwbBlo55pNWFtpmmnpEEfO8VHB/C48WqofsZqpAWbMP4nVRJG42sTivIKATNoePKxXvCnJeVJXNiyknVz3buC09/4zvTUFWVIEwJYucH2OalgdDhlIU2xYsu7tNSQaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707954815; c=relaxed/simple; bh=SoOGgKEby/90/0Z1NNUySJMvgGZ/kgGpsJcso4mQE8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c/2G8HGy1ypDpoTmITwoC66Lt2CE8wqnmUNqLpVI4IPCL5KhYJERxPfZLDFG4FXGhW/b0HZFR1OQYCv58nsRX8PIHYRtQLXxbv8LeNY1uKKZwCpgIiJeXkGp9BO/CfEqgAqDeiKKHFhEKSxu48YQ5pPJKgRr+c0jL0AhwrE/O/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=T/9JqNhq; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=1u6I14flCka8KvOp2oxl+aQw0301epnL+50/ePKMgkQ=; b=T/9JqNhqVElMAvvaEPKdNTINrp jfHVmSQB4xyzs8wH1I/u0FpJHwQkzXsS3HMu8MGGNxw6OGY+W/TvJKPApUb25tKe5pNfkw3Vd8mBw 1qww/NufbrvOXQ5BEeugzNB3lsUAl+u3/wpplRawEudLda0JSM+FTwukL3+yIy8amhP0FzVYZlmXI b7trE/fMe0yKt2tO5+tiNdu/N8dluMNQaOxKP9ZBwU7uvuVN5foWS7L/DXYxdpcOSU6vwUXbozwQJ OIjyfFLChma2eYcRv5QG2kOGPI/CappG/F65dEEORO2xpfDl//ytr4uVsUdPYeEacEpOq1T8EaNrO GUZ8ojsA==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1raP48-00GcSK-0e; Wed, 14 Feb 2024 17:53:27 -0600 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Elizabeth Figura Subject: [PATCH 13/31] ntsync: Introduce NTSYNC_IOC_SEM_READ. Date: Wed, 14 Feb 2024 17:52:48 -0600 Message-ID: <20240214235307.10494-4-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214235307.10494-1-zfigura@codeweavers.com> References: <20240214233645.9273-1-zfigura@codeweavers.com> <20240214235307.10494-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790920753657075428 X-GMAIL-MSGID: 1790920753657075428 This corresponds to the NT syscall NtQuerySemaphore(). This returns the current count and maximum count of the semaphore. Signed-off-by: Elizabeth Figura --- drivers/misc/ntsync.c | 21 +++++++++++++++++++++ include/uapi/linux/ntsync.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/misc/ntsync.c b/drivers/misc/ntsync.c index e8e58274e4e8..e42dbd5d6d14 100644 --- a/drivers/misc/ntsync.c +++ b/drivers/misc/ntsync.c @@ -515,6 +515,25 @@ static int ntsync_event_reset(struct ntsync_obj *event, void __user *argp) return 0; } +static int ntsync_sem_read(struct ntsync_obj *sem, void __user *argp) +{ + struct ntsync_sem_args __user *user_args = argp; + struct ntsync_sem_args args; + + if (sem->type != NTSYNC_TYPE_SEM) + return -EINVAL; + + args.sem = 0; + spin_lock(&sem->lock); + args.count = sem->u.sem.count; + args.max = sem->u.sem.max; + spin_unlock(&sem->lock); + + if (copy_to_user(user_args, &args, sizeof(args))) + return -EFAULT; + return 0; +} + static int ntsync_obj_release(struct inode *inode, struct file *file) { struct ntsync_obj *obj = file->private_data; @@ -534,6 +553,8 @@ static long ntsync_obj_ioctl(struct file *file, unsigned int cmd, switch (cmd) { case NTSYNC_IOC_SEM_POST: return ntsync_sem_post(obj, argp); + case NTSYNC_IOC_SEM_READ: + return ntsync_sem_read(obj, argp); case NTSYNC_IOC_MUTEX_UNLOCK: return ntsync_mutex_unlock(obj, argp); case NTSYNC_IOC_MUTEX_KILL: diff --git a/include/uapi/linux/ntsync.h b/include/uapi/linux/ntsync.h index 598f894f868d..6017f621687e 100644 --- a/include/uapi/linux/ntsync.h +++ b/include/uapi/linux/ntsync.h @@ -51,5 +51,6 @@ struct ntsync_wait_args { #define NTSYNC_IOC_EVENT_SET _IOR ('N', 0x88, __u32) #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) #endif