From patchwork Mon Feb 7 06:05:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 82222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3CAECB7137 for ; Tue, 8 Feb 2011 10:04:21 +1100 (EST) Received: from localhost ([127.0.0.1]:34767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PmKGs-0002s0-Oj for incoming@patchwork.ozlabs.org; Mon, 07 Feb 2011 01:08:23 -0500 Received: from [140.186.70.92] (port=34880 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PmKEs-0002qp-L8 for qemu-devel@nongnu.org; Mon, 07 Feb 2011 01:06:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PmKEq-0001Wd-SR for qemu-devel@nongnu.org; Mon, 07 Feb 2011 01:06:18 -0500 Received: from smtp.gentoo.org ([140.211.166.183]:48148) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PmKEq-0001WD-DR for qemu-devel@nongnu.org; Mon, 07 Feb 2011 01:06:16 -0500 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 16EC71B40E7; Mon, 7 Feb 2011 06:05:53 +0000 (UTC) From: Mike Frysinger To: qemu-devel@nongnu.org, Riku Voipio Date: Mon, 7 Feb 2011 01:05:55 -0500 Message-Id: <1297058757-7611-7-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 1.7.4 In-Reply-To: <1297058757-7611-1-git-send-email-vapier@gentoo.org> References: <1297058757-7611-1-git-send-email-vapier@gentoo.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.211.166.183 Cc: Subject: [Qemu-devel] [PATCH 7/9] linux-user: implement sched_{g, s}etaffinity X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Mike Frysinger --- linux-user/syscall.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 67 insertions(+), 0 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index bb6ef43..4412a9b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -235,6 +235,12 @@ _syscall6(int,sys_futex,int *,uaddr,int,op,int,val, const struct timespec *,timeout,int *,uaddr2,int,val3) #endif #endif +#define __NR_sys_sched_getaffinity __NR_sched_getaffinity +_syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len, + unsigned long *, user_mask_ptr); +#define __NR_sys_sched_setaffinity __NR_sched_setaffinity +_syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len, + unsigned long *, user_mask_ptr); static bitmask_transtbl fcntl_flags_tbl[] = { { TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, }, @@ -6354,6 +6360,67 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, return value. */ ret = -TARGET_ENOTDIR; break; + case TARGET_NR_sched_getaffinity: + { + unsigned int mask_size; + unsigned long *mask; + + /* + * sched_getaffinity needs multiples of ulong, so need to take + * care of mismatches between target ulong and host ulong sizes. + */ + if (arg2 & (sizeof(abi_ulong) - 1)) { + ret = -TARGET_EINVAL; + break; + } + mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); + + mask = alloca(mask_size); + ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask)); + + if (!is_error(ret)) { + if (arg2 > ret) { + /* Zero out any extra space kernel didn't fill */ + unsigned long zero = arg2 - ret; + p = alloca(zero); + memset(p, 0, zero); + if (copy_to_user(arg3 + zero, p, zero)) { + goto efault; + } + arg2 = ret; + } + if (copy_to_user(arg3, mask, arg2)) { + goto efault; + } + ret = arg2; + } + } + break; + case TARGET_NR_sched_setaffinity: + { + unsigned int mask_size; + unsigned long *mask; + + /* + * sched_setaffinity needs multiples of ulong, so need to take + * care of mismatches between target ulong and host ulong sizes. + */ + if (arg2 & (sizeof(abi_ulong) - 1)) { + ret = -TARGET_EINVAL; + break; + } + mask_size = (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) - 1); + + mask = alloca(mask_size); + if (!lock_user_struct(VERIFY_READ, p, arg3, 1)) { + goto efault; + } + memcpy(mask, p, arg2); + unlock_user_struct(p, arg2, 0); + + ret = get_errno(sys_sched_setaffinity(arg1, mask_size, mask)); + } + break; case TARGET_NR_sched_setparam: { struct sched_param *target_schp;