From patchwork Sun Jun 10 03:00:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138102 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2584947lji; Sat, 9 Jun 2018 20:22:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKguHNS//wwKcTb3qeoEWCRiQMspKKOLWlb8sJn/h3KTPvAie71ufYOSo1+I2NST3ZBfhBK X-Received: by 2002:a37:91c3:: with SMTP id t186-v6mr10823124qkd.37.1528600977684; Sat, 09 Jun 2018 20:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528600977; cv=none; d=google.com; s=arc-20160816; b=kr6hpbeX/SempsdknFN7kAXOAypuR0kuUeTK7tLeQhqy/zzEjpkv8K0nyXJhZV5Bjo R47eOs2DJCSUU6dqGXS13PsWRUIy5vNMQ0f9P4UekotJHIlaosOMAcSXdEmuny/Vr0/i ojoBUnKilNyaeJRYTMGHXpQTz7ytkWnJ3LsrxlZCBctwyv8Q9QPaLJlmVeEu5kRE4B6s 5FWhUPpgjx70m11hsPsVvSm7ovc1fhldDZeIB1jeTV5YQOur7beiObKKrAzUmD08vPHx b8DfTYWFMIXfBWsxNKG6cv4MLg4LC6eE9XvgTzAZFgWXv28XDyDSPrQShvNzaHoIw1fA JgHA== 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=pcSZ52MrlGhMS8uvqUG+ZdJZ3IYLPDZ4l5v1NgkUIiQ=; b=cJLGVHdnVAT0sRupMJAGsbs5klFumHwGa3eHaL1wsO7BAv6o5vnxm/5e+4+fbmEe0/ Si2PIY5bzKLMlm+tuUzNHOyiwoJIPz6KVOKaWUxbEvMrD50nlAAFs3X+EGCfAqFvvGB5 AmNhnQBP2hMC7MV/DfBtq3JJN906w+IXFveSO8X+/VsTOW5Gfc1Yp+/pRYJupaTs6wOo rCvwP2y5H7M/4bt2yG6OyZoj7agssZlvm9SHlR4D/Nza0h8eN1EvjVfPUZ1fJdR7nFep l2bhevQena9VJmXAjQTKNqeiUqQVHGWefELW/IBzFDSdzqhVf18ijog/tGpPjfcW7dSF 57nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C/S9KUSl; 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 j5-v6si2487898qvg.130.2018.06.09.20.22.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:22:57 -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=C/S9KUSl; 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]:42281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqwT-0002Pg-3p for patch@linaro.org; Sat, 09 Jun 2018 23:22:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqdb-0002Hu-3U for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqdX-0003Qr-Us for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:27 -0400 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:41581) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqdX-0003Qc-N2 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:23 -0400 Received: by mail-pl0-x241.google.com with SMTP id az12-v6so10379703plb.8 for ; Sat, 09 Jun 2018 20:03:23 -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=pcSZ52MrlGhMS8uvqUG+ZdJZ3IYLPDZ4l5v1NgkUIiQ=; b=C/S9KUSlgtimrnaawGdSdz720qJdIASt8S/35vhECriXvndBlxT4Ayq7x6USqYgN+v o6y0n69YU/gFQUtoMXnQCkp8/LtDXKE7quIc0INKheR+S2lTVcW5QNHmlFiWGkgs52L2 oln9ogO1bLsbhl9I7JcOAMZyvTXuwh4SEu3g8= 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=pcSZ52MrlGhMS8uvqUG+ZdJZ3IYLPDZ4l5v1NgkUIiQ=; b=ZJHdegWE9164VI9AE47bCM+V63mKlltW2Rrge/NkPOa3NdMd/Th4QTgLHqBpV7hx46 3CzFQ4ywD0m2U9XF7H/eAsM/CV7kw1tJePQNlBb+RrV/HjuIfH7ASiL608fgiPe/SEYl ZNBrnoG4YRyz9F5vKZsXhfhesx+86k/T/RcJBHWCG89akmOzwc+uW4OFC4EeGm/llFlf s2Q65LOfSTsge++Ahefk1nsiXWhXTo3Nbdknzss73iUmBGecbjfXqRWzfaq+9h9aExes xgqUGczIV7IoLlU6I/r6ALlBkQYjNe451mbsdoE1icmK1v9r+Vit2QBaDWHEoCIYWrsO PCsg== X-Gm-Message-State: APt69E1v45fUylEgHtk4qdIG7sOfg2utdlxPd7oZTHCo/XAItyfhxvTh 2fbTI7jksfZbsSFhrMd0JtcPPHGhfhw= X-Received: by 2002:a17:902:784d:: with SMTP id e13-v6mr12974182pln.197.1528599802522; Sat, 09 Jun 2018 20:03:22 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id y17-v6sm31712718pfe.33.2018.06.09.20.03.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:03:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:00:58 -1000 Message-Id: <20180610030220.3777-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-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:c01::241 Subject: [Qemu-devel] [PATCH v2 026/108] 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 | 184 ++++++++++++++++++++++--------------------- 1 file changed, 94 insertions(+), 90 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 81e142f091..ebe57d86aa 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5754,94 +5754,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 (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 }, @@ -8179,6 +8091,99 @@ 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 (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))); @@ -8784,8 +8789,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; 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); @@ -12641,6 +12644,7 @@ static impl_fn *syscall_table(unsigned num) #if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA) SYSCALL(getxpid); #endif + SYSCALL(ioctl); SYSCALL(kill); #ifdef TARGET_NR_link SYSCALL(link);