From patchwork Fri Jun 1 07:30:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 137492 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp623668lji; Fri, 1 Jun 2018 00:59:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK5bhqIAK7oU0kjg84drMCSumVffJt+XtFHM7wBf3zcqzxBhM9NiGsiu/MZikipXOvzRCVt X-Received: by 2002:a37:82c6:: with SMTP id e189-v6mr8816471qkd.322.1527839951166; Fri, 01 Jun 2018 00:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527839951; cv=none; d=google.com; s=arc-20160816; b=Zec4IqCcme6xL5LEy0YwGb3OOFynG73MHj/SBMJuQRVCMgexsVVzHEr2Tpc6Ak5Ed+ xaxw02sbIqTrmyNdk3+Cq7ZDZ8sL3sD6maM80yTNuEmn/x18j8BQ6KXSXAb/qVd+9I4r vXIPvNSzfWDtSMtQWoEujTMutNvwTAgyUjLJXvMEWOdvGr9AWN/eWNdbxGtbcC/U0Jsk HBAP/fDPJjQ6j/5HXBVZsVnYu63/8BkkwexLraAaZppsbW7EaFyr1MUtBLJdL14K/29G JJrGHz41bpsLDfPqcenrSarCykkL8xI6ior7AUN3ldYOvVEgdIZJ2vIf+LB8d7pIAefQ B3Hg== 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=cFIM79gp+dF/NwbdEPIwKiJ9sLTkgusYgw7G++Ve26c=; b=qDsRYE9XALf17mgdsvujPiEn7zBkyfOs6ubzJ8KXNLbv2xPaGoKX3IU5qWoI4yexn5 d6yJ/1gG3DEaD+LqT4ol3emkQ1lqlDPoIqPqcHjhAaSTjJYRyUCL2KoZQnoUzJ4f2JEy BvOcPM/h8fVOiy4VGxqb6JSWdrIcxRnvjvMAHwh7Zhe9LbUoUPa7A1X5GCNEWuDJD1s7 W2w8kUzrb2Fx4bENnVk0KSpKavhVzzHIaYJFQ26BUMHjpmeb7mjibeJr9krPFAZddsYe e9/azUCyhd0HCeeLc2I6OmP/pW824tkETxNNVdGkr9ZVkuwYq8GIxjixTirwGPz6kK8g LHWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GLIbwcRq; 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 a42-v6si163913qtk.91.2018.06.01.00.59.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 01 Jun 2018 00:59:11 -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=GLIbwcRq; 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]:47969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOexq-0001vL-Kq for patch@linaro.org; Fri, 01 Jun 2018 03:59:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOeXC-0005vM-IO for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOeX8-0000oF-Kh for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:38 -0400 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:41503) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fOeX8-0000nb-CF for qemu-devel@nongnu.org; Fri, 01 Jun 2018 03:31:34 -0400 Received: by mail-pl0-x244.google.com with SMTP id az12-v6so14819689plb.8 for ; Fri, 01 Jun 2018 00:31:34 -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=cFIM79gp+dF/NwbdEPIwKiJ9sLTkgusYgw7G++Ve26c=; b=GLIbwcRq7rRj57eWf3KtskQA9+s9/3/XtPXSjWUtVqQ6UAfVXHE3wHoBZlNr4hDq6A L7yYQjoKKQlQoKOQai0FLYaQJ39A2lIp6zBgTgEvzX3lZvlSYN8sHFcESI907TRCQRaV Ik0cF0EAhQHCHhrmDKyUS1BRF8PaGhNtBMXgU= 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=cFIM79gp+dF/NwbdEPIwKiJ9sLTkgusYgw7G++Ve26c=; b=asIrcILic3WCJhbeNOIC2ptn42zQwYeoqkg3iy7vO/hoPN113RsLlWm805BC2YDPSa HTxIDivHiu0yHLLlHyxyKBerp4NyatopCe2TjJg4p6IxONq9x9MWqa0NAnjI26p4owup Nv79mS0jdnp0Qx0ZcCN2fabKifOi1e6KJP/X/7PNM2T1ssACun33M/XN2RBf7pYiAp57 Pu+u7aTTv4OvflbsLSXILpka0kCfyxaK7y1/eT8wu1vMMQjUuCfUDsTdLgSPIyH41e+s llADG5QuFJRszyaLCyQSfO3iQhkPshYfDpDN/f753okPPyagTUxMZhrqDm2GkVv/rAj2 W+tw== X-Gm-Message-State: ALKqPweXsJEHvznpr6kd6Uh1E9UQM9ug84gLfB9YD54qgSnTmy6tsYjn XTNNHLaKaqMONw37oP0YejVU+YdV7rw= X-Received: by 2002:a17:902:ab8d:: with SMTP id f13-v6mr10101628plr.81.1527838293169; Fri, 01 Jun 2018 00:31:33 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Jun 2018 00:31:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 1 Jun 2018 00:30:45 -0700 Message-Id: <20180601073050.8054-29-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:c01::244 Subject: [Qemu-devel] [PATCH 28/33] linux-user: Split out chroot, dup2, dup3, fcntl, setpgid, umask 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" Signed-off-by: Richard Henderson --- linux-user/syscall.c | 123 +++++++++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 44 deletions(-) -- 2.17.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 4be71367fc..4d9b9cad6e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7879,6 +7879,19 @@ IMPL(chmod) } #endif +IMPL(chroot) +{ + char *p = lock_user_string(arg1); + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(chroot(p)); + unlock_user(p, arg1, 0); + return ret; +} + IMPL(close) { if (is_hostfd(arg1)) { @@ -7918,6 +7931,43 @@ IMPL(dup) return ret; } +#ifdef TARGET_NR_dup2 +IMPL(dup2) +{ + abi_long ret; + + if (is_hostfd(arg1) || is_hostfd(arg2)) { + return -TARGET_EBADF; + } + ret = get_errno(dup2(arg1, arg2)); + if (ret >= 0) { + fd_trans_dup(arg1, arg2); + } + return ret; +} +#endif + +#if defined(TARGET_NR_dup3) && defined(CONFIG_DUP3) +IMPL(dup3) +{ + int host_flags; + abi_long ret; + + if (is_hostfd(arg1) || is_hostfd(arg2)) { + return -TARGET_EBADF; + } + if ((arg3 & ~TARGET_O_CLOEXEC) != 0) { + return -EINVAL; + } + host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl); + ret = get_errno(dup3(arg1, arg2, host_flags)); + if (ret >= 0) { + fd_trans_dup(arg1, arg2); + } + return ret; +} +#endif + IMPL(execve) { abi_ulong *guest_ptrs; @@ -8087,6 +8137,13 @@ IMPL(faccessat) } #endif +#ifdef TARGET_NR_fcntl +IMPL(fcntl) +{ + return do_fcntl(arg1, arg2, arg3); +} +#endif + #ifdef TARGET_NR_fork IMPL(fork) { @@ -8659,6 +8716,11 @@ IMPL(rmdir) } #endif +IMPL(setpgid) +{ + return get_errno(setpgid(arg1, arg2)); +} + #ifdef TARGET_NR_stime IMPL(stime) { @@ -8716,6 +8778,11 @@ IMPL(times) return ret; } +IMPL(umask) +{ + return get_errno(umask(arg1)); +} + #ifdef TARGET_NR_umount IMPL(umount) { @@ -8905,50 +8972,6 @@ IMPL(everything_else) char *fn; switch(num) { -#ifdef TARGET_NR_fcntl - case TARGET_NR_fcntl: - return do_fcntl(arg1, arg2, arg3); -#endif - case TARGET_NR_setpgid: - return get_errno(setpgid(arg1, arg2)); - case TARGET_NR_umask: - return get_errno(umask(arg1)); - case TARGET_NR_chroot: - if (!(p = lock_user_string(arg1))) - return -TARGET_EFAULT; - ret = get_errno(chroot(p)); - unlock_user(p, arg1, 0); - return ret; -#ifdef TARGET_NR_dup2 - case TARGET_NR_dup2: - if (is_hostfd(arg1) || is_hostfd(arg2)) { - return -TARGET_EBADF; - } - ret = get_errno(dup2(arg1, arg2)); - if (ret >= 0) { - fd_trans_dup(arg1, arg2); - } - return ret; -#endif -#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3) - case TARGET_NR_dup3: - { - int host_flags; - - if (is_hostfd(arg1) || is_hostfd(arg2)) { - return -TARGET_EBADF; - } - if ((arg3 & ~TARGET_O_CLOEXEC) != 0) { - return -EINVAL; - } - host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl); - ret = get_errno(dup3(arg1, arg2, host_flags)); - if (ret >= 0) { - fd_trans_dup(arg1, arg2); - } - return ret; - } -#endif #ifdef TARGET_NR_getppid /* not on alpha */ case TARGET_NR_getppid: return get_errno(getppid()); @@ -12969,6 +12992,7 @@ static impl_fn * const syscall_table[] = { [TARGET_NR_brk] = impl_brk, [TARGET_NR_close] = impl_close, [TARGET_NR_chdir] = impl_chdir, + [TARGET_NR_chroot] = impl_chroot, #ifdef TARGET_NR_chmod [TARGET_NR_chmod] = impl_chmod, #endif @@ -12976,11 +13000,20 @@ static impl_fn * const syscall_table[] = { [TARGET_NR_creat] = impl_creat, #endif [TARGET_NR_dup] = impl_dup, +#ifdef TARGET_NR_dup2 + [TARGET_NR_dup2] = impl_dup2, +#endif +#if defined(TARGET_NR_dup3) && defined(CONFIG_DUP3) + [TARGET_NR_dup3] = impl_dup3, +#endif [TARGET_NR_execve] = impl_execve, [TARGET_NR_exit] = impl_exit, #ifdef TARGET_NR_faccessat [TARGET_NR_faccessat] = impl_faccessat, #endif +#ifdef TARGET_NR_fcntl + [TARGET_NR_fcntl] = impl_fcntl, +#endif #ifdef TARGET_NR_fork [TARGET_NR_fork] = impl_fork, #endif @@ -13050,6 +13083,7 @@ static impl_fn * const syscall_table[] = { #ifdef TARGET_NR_rmdir [TARGET_NR_rmdir] = impl_rmdir, #endif + [TARGET_NR_setpgid] = impl_setpgid, #ifdef TARGET_NR_stime [TARGET_NR_stime] = impl_stime, #endif @@ -13061,6 +13095,7 @@ static impl_fn * const syscall_table[] = { [TARGET_NR_time] = impl_time, #endif [TARGET_NR_times] = impl_times, + [TARGET_NR_umask] = impl_umask, #ifdef TARGET_NR_umount [TARGET_NR_umount] = impl_umount, #endif