From patchwork Fri Jun 1 07:30:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 137489 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp620771lji; Fri, 1 Jun 2018 00:55:03 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL6PZzQb8ngHl8NYqh9ad+F5GFbUv7ZXFj25aMzSo5Tu5H/d/eNe78aDpnuAAjgeu5Aq5KJ X-Received: by 2002:a0c:9dc3:: with SMTP id p3-v6mr9527337qvf.211.1527839703621; Fri, 01 Jun 2018 00:55:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527839703; cv=none; d=google.com; s=arc-20160816; b=UfKpymY/7OV2fXttB1yKrNx5jBjI8iB2a0c0Mq6N5t2HcYQ5NhIuPDrpGecqlB1lng E6S+D1uRPMLRcrYcr2usfr/Qy3Nx/okAQxFNIWjBexDBPetwmW0f78YDl1cqAKGZ+FJv L0SoeJwajz5FYPOHKzrNEnzkAV9+iN+Ue9xZWe+4JcCm/h6qWmQgbQ11IkjDIBS5M7oS pb2Bp8lzZUm7AgReoWpPcVI1HxWPkHXn5rP922gkZIRsl55L14wnzz3U4cGSk34/8wTX 2NJhU2Iziz8PQJIrKaLzcnhmbM6b1SlYloxg0hgts/8y3GVJcIMsmuXmpdXy4bC0Y4b0 XEUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=rhNC+tuyWGWk68/inmnUnXY6rXJTo7UnP2hjcGmv20k=; b=VKV5bUDPkVrgnXFSf6t7v63No7f0qL+G+sukiSUTnPgY7Mu3Lr1vUKV7/InlmD9QYv QgUTZuYz+A805XybyknYQZIxhShmYp/mM1FGuCkBbjs4hmNGMELrX+51NGeDqyplts81 in4z1UV1qv9AGGU0sk/6DjlndiSSdZ4KMFYgXC5BfyQE8t8ZqYBY+dPQE7HkD1ZR8Crd 06N1Ljf8JP7FQNgtkEuSDu+hNek2Yo4N8ROj3xJLAJNKW0+KIXk7pAGmP+nXRNHBeb8V xb+FsCGnWbOOeUfrDLlhXyfSqrQf3xfSdsBDcB+5TIHcr+TON0nsooNWMvPj14TY4wcJ PU/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jm78qk9u; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v57-v6si3979286qtj.154.2018.06.01.00.55.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 01 Jun 2018 00:55:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jm78qk9u; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOetr-0006A0-3A for patch@linaro.org; Fri, 01 Jun 2018 03:55:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOeX8-0005rZ-GY for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOeX7-0000mu-8K for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:34 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:37720) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fOeX7-0000m9-0h for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:33 -0400 Received: by mail-pg0-x244.google.com with SMTP id a13-v6so10873032pgu.4 for ; Fri, 01 Jun 2018 00:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rhNC+tuyWGWk68/inmnUnXY6rXJTo7UnP2hjcGmv20k=; b=jm78qk9uMZ94ULY9jap3/5RdFRYfr6Ro8mL6KHUZpD0Jmf5KRZP/WnKTH987+f6wNC hgsrUxo5v+jrFmEtGv/z28iAKXELddvzyU79z2N7YeRsjnsPDsDVFVBcBnusyJIplGG4 wahQ+4VD1AMBiVK1ygzVlnTLDlKFqj60N1AnY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rhNC+tuyWGWk68/inmnUnXY6rXJTo7UnP2hjcGmv20k=; b=pBn62IpVKQmYT+iL5mx3qM9fFhJzQ6nmQHFg65bK2D2rLZnP0e0ceXtTj+h3v67Cg/ uhfE2Xhk9BpwP/rXKaN8uvIN+17TkrXjSW2iGMQN75bfRncHLyfqLINh1fD0k6UOVlTO djqbdcwMOPDU8U7bcX5ScEXCrLJCcR4cnlUwg3S51WHYz4d+5EK7QjCCpTa7xfbtVn6F XmXD5O6QeJSN7XCKyp2t1VNQEBlVVrRSEiHCozCInYBXQbEsQ8ToMYCNMfU5rJ3xurYu RWCjSXSWtde/szjko6UM6rgEG/YCAUa6VTc+ss1xZOfmB2QTReVNYNp+HNBNDhX4WsOr qARg== X-Gm-Message-State: ALKqPwe7+YV+XS0e3oDRItben+W1RaMqnf0n6VxpVOngzPFMXuecLP8p S2fzkaiDSeeLq89r0DLL6i0jmZOdNPU= X-Received: by 2002:aa7:8009:: with SMTP id j9-v6mr9908674pfi.52.1527838291755; Fri, 01 Jun 2018 00:31:31 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-112-211.tukw.qwest.net. [97.126.112.211]) by smtp.gmail.com with ESMTPSA id c4-v6sm4431782pgv.86.2018.06.01.00.31.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Jun 2018 00:31:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 1 Jun 2018 00:30:44 -0700 Message-Id: <20180601073050.8054-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180601073050.8054-1-richard.henderson@linaro.org> References: <20180601073050.8054-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH 27/33] linux-user: Split out ioctl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" At the same time, merge do_ioctl into the new function. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 190 ++++++++++++++++++++++--------------------- 1 file changed, 97 insertions(+), 93 deletions(-) -- 2.17.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index bde1f9872f..4be71367fc 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5759,97 +5759,6 @@ static IOCTLEntry ioctl_entries[] = { { 0, 0, }, }; -/* ??? Implement proper locking for ioctls. */ -/* do_ioctl() Must return target values and target errnos. */ -static abi_long do_ioctl(int fd, int cmd, abi_long arg) -{ - const IOCTLEntry *ie; - const argtype *arg_type; - abi_long ret; - uint8_t buf_temp[MAX_STRUCT_SIZE]; - int target_size; - void *argptr; - - ie = ioctl_entries; - for(;;) { - if (ie->target_cmd == 0) { - gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); - return -TARGET_ENOSYS; - } - if (ie->target_cmd == cmd) - break; - ie++; - } - arg_type = ie->arg_type; -#if defined(DEBUG) - gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd, ie->name); -#endif - if (ie->do_ioctl) { - return ie->do_ioctl(ie, buf_temp, fd, cmd, arg); - } else if (!ie->host_cmd) { - /* Some architectures define BSD ioctls in their headers - that are not implemented in Linux. */ - return -TARGET_ENOSYS; - } - - switch(arg_type[0]) { - case TYPE_NULL: - /* no argument */ - ret = get_errno(safe_ioctl(fd, ie->host_cmd)); - break; - case TYPE_PTRVOID: - case TYPE_INT: - ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg)); - break; - case TYPE_PTR: - arg_type++; - target_size = thunk_type_size(arg_type, 0); - switch(ie->access) { - case IOC_R: - ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); - if (!is_error(ret)) { - argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); - if (!argptr) - return -TARGET_EFAULT; - thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); - unlock_user(argptr, arg, target_size); - } - break; - case IOC_W: - argptr = lock_user(VERIFY_READ, arg, target_size, 1); - if (!argptr) - return -TARGET_EFAULT; - thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); - unlock_user(argptr, arg, 0); - ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); - break; - default: - case IOC_RW: - argptr = lock_user(VERIFY_READ, arg, target_size, 1); - if (!argptr) - return -TARGET_EFAULT; - thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); - unlock_user(argptr, arg, 0); - ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); - if (!is_error(ret)) { - argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); - if (!argptr) - return -TARGET_EFAULT; - thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); - unlock_user(argptr, arg, target_size); - } - break; - } - break; - default: - gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", - (long)cmd, arg_type[0]); - ret = -TARGET_ENOSYS; - break; - } - return ret; -} - static const bitmask_transtbl iflag_tbl[] = { { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK }, { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT }, @@ -8231,6 +8140,102 @@ IMPL(getxpid) } #endif +/* ??? Implement proper locking for ioctls. */ +IMPL(ioctl) +{ + abi_long fd = arg1; + abi_long cmd = arg2; + abi_long arg = arg3; + const IOCTLEntry *ie; + const argtype *arg_type; + abi_long ret; + uint8_t buf_temp[MAX_STRUCT_SIZE]; + int target_size; + void *argptr; + + for (ie = ioctl_entries; ; ie++) { + if (ie->target_cmd == 0) { + gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); + return -TARGET_ENOSYS; + } + if (ie->target_cmd == cmd) { + break; + } + } + arg_type = ie->arg_type; +#if defined(DEBUG) + gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd, ie->name); +#endif + if (ie->do_ioctl) { + return ie->do_ioctl(ie, buf_temp, fd, cmd, arg); + } else if (!ie->host_cmd) { + /* Some architectures define BSD ioctls in their headers + that are not implemented in Linux. */ + return -TARGET_ENOSYS; + } + + switch (arg_type[0]) { + case TYPE_NULL: + /* no argument */ + ret = get_errno(safe_ioctl(fd, ie->host_cmd)); + break; + case TYPE_PTRVOID: + case TYPE_INT: + ret = get_errno(safe_ioctl(fd, ie->host_cmd, arg)); + break; + case TYPE_PTR: + arg_type++; + target_size = thunk_type_size(arg_type, 0); + switch (ie->access) { + case IOC_R: + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); + if (!is_error(ret)) { + argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); + if (!argptr) { + return -TARGET_EFAULT; + } + thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); + unlock_user(argptr, arg, target_size); + } + break; + case IOC_W: + argptr = lock_user(VERIFY_READ, arg, target_size, 1); + if (!argptr) { + return -TARGET_EFAULT; + } + thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); + unlock_user(argptr, arg, 0); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); + break; + default: + case IOC_RW: + argptr = lock_user(VERIFY_READ, arg, target_size, 1); + if (!argptr) { + return -TARGET_EFAULT; + } + thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); + unlock_user(argptr, arg, 0); + ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp)); + if (!is_error(ret)) { + argptr = lock_user(VERIFY_WRITE, arg, target_size, 0); + if (!argptr) { + return -TARGET_EFAULT; + } + thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); + unlock_user(argptr, arg, target_size); + } + break; + } + break; + default: + gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", + (long)cmd, arg_type[0]); + ret = -TARGET_ENOSYS; + break; + } + return ret; +} + IMPL(kill) { return get_errno(safe_kill(arg1, target_to_host_signal(arg2))); @@ -8900,8 +8905,6 @@ IMPL(everything_else) char *fn; switch(num) { - case TARGET_NR_ioctl: - return do_ioctl(arg1, arg2, arg3); #ifdef TARGET_NR_fcntl case TARGET_NR_fcntl: return do_fcntl(arg1, arg2, arg3); @@ -12990,6 +12993,7 @@ static impl_fn * const syscall_table[] = { #if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA) [TARGET_NR_getxpid] = impl_getxpid, #endif + [TARGET_NR_ioctl] = impl_ioctl, [TARGET_NR_kill] = impl_kill, #ifdef TARGET_NR_link [TARGET_NR_link] = impl_link,