From patchwork Sun Jun 10 03:00:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138100 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2584274lji; Sat, 9 Jun 2018 20:21:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLh8IrWTu2JtnAWARg7ejbJtgKk5sv00JlW+s1XhN9GUxQeKQ1zpN9QFSXyjUwHDfsZ4rET X-Received: by 2002:a0c:d6c7:: with SMTP id l7-v6mr10893185qvi.36.1528600890281; Sat, 09 Jun 2018 20:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528600890; cv=none; d=google.com; s=arc-20160816; b=HNDdk5OcCuFo5cgW8DWCH89K7tTJdYWFt6yKLq9+sdIqPebyVTAA5LA8HAZGnioG8z vTNtvrlZmGmD3i/n6m9+sFEeieE7LLfplQhHPv9Jjh2HuFDZb9xiy/KPSNQ/LM4MJ+V6 TsRH1S8mxXKlejl05BwogJeYKONSJbPpbXKu4ZxrNIPnA2XJkmdSffFZOB1UiGaa9poC jLkrW1kUfNtvznQ3AKCdSvvm1vkuxja3fkWT+QpNrVUhePI4GARifSw39mqG15pwhDDC Fk+nbvpL6pREdijwtPeJRbX98JAZZL/xLJoylJX2N1S/PAWf1JDUngj/I72reOovhrEq faUg== 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=Dr5d0oCNW5M4l5HB1MySFY3cQ+NoGuE+ieoRdjFlOso=; b=fRE+kseXUhBiuT09AJQ3WspcgKBr4izq+4I3xNVmY1mgOOygppmcJ47Z8njIy2je1a P/RS+UwBC7o4+77EeUxpJkw9so8XRlx5Bu+0oJ2g/NKE9D7vPkcyrIjmDJ6cSWDXuv7J +Dhj1WcxMFDFEIAeALPhcmC59m/ypn1qFmiV9a3YgtbTMz6jYjYBQSjxpsuX+BDhhbjE Sw5tkFIUf4QTfaMh+CLypnkjbdObROlJcoGuppvaxL5gZA6efCI4tKGTEd9+/BztLlEQ 5xjwsPugCQJo0TKhwPx2/c86l8BxOROG4b919Lt6Z6dXbQbpH3Lvu9u44r2OgH6Qp2YO ye8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=d4+SmkOw; 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 l127-v6si3123564qkc.251.2018.06.09.20.21.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:21:30 -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=d4+SmkOw; 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]:42273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqv3-0000wv-JI for patch@linaro.org; Sat, 09 Jun 2018 23:21:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqdb-0002IG-FF 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 1fRqda-0003RK-Al for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:27 -0400 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:34528) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqda-0003RA-2i for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:26 -0400 Received: by mail-pl0-x243.google.com with SMTP id g20-v6so10400293plq.1 for ; Sat, 09 Jun 2018 20:03:25 -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=Dr5d0oCNW5M4l5HB1MySFY3cQ+NoGuE+ieoRdjFlOso=; b=d4+SmkOw0gZv37taI0bQtULiYC+IwYdZpBUps5jPnAqaMEzg0Xub/W93LgMl+p3okw 19ny4DrRWWkGFOQDSK4PtHlzwRTjesnBtMxPy5pfG1364BqTJGwBLbdSKgm086Fjnge5 tFee/an7hQTlQAzhEW7jpagzyFtYRWB85AKK0= 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=Dr5d0oCNW5M4l5HB1MySFY3cQ+NoGuE+ieoRdjFlOso=; b=pYDudK05nhl8iOp3pyn1jU/RkF4b4yDjBfxEEuEwrw7zFv4+GbQtbWQ67tMky/tIs4 vtZPc9+RQfA5pvVGMNrK75WKrTq1h8jLli2vzGUKCI0DGMVxQAjcEtEcovofS/6oqxVa ZBZFua142McgoNqCjuWerUAhKjUEemU/6Quisw8ciq6aaYjAJyG723vRYYnsmCfYnxrp rJdt2izzOkt0+/wan+0IGvVGn8qTEMZLJ3Tak7oFOik+voymt4XETrd/u6wEGvcBhl8N YiELT2/NUzGhIs0Ff9TIQZUctCMLcJl2vOHBMFdwcBBIYGuONMyY7h73XbD7PgU1mmdX MW8w== X-Gm-Message-State: APt69E0JZwvfw3g5FO9J9NkMQn0cUtn3H8u8i/pkIwT07823uIS9AIMB KyOotaau5Hx5plu3xiTGny21Jzla1+Q= X-Received: by 2002:a17:902:1029:: with SMTP id b38-v6mr12788953pla.277.1528599804924; Sat, 09 Jun 2018 20:03:24 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:03:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:00:59 -1000 Message-Id: <20180610030220.3777-28-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::243 Subject: [Qemu-devel] [PATCH v2 027/108] 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" All targets define dup3; remove the ifdef. If !CONFIG_DUP3, fall back to dup2 when flags == 0. This will help emulation of new targets that do not define the dup2 syscall, using dup3 as the syscall backing the dup2 posix function. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 113 ++++++++++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 38 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ebe57d86aa..8e13a16e91 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7855,6 +7855,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) { fd_trans_unregister(arg1); @@ -7886,6 +7899,41 @@ IMPL(dup) return ret; } +#ifdef TARGET_NR_dup2 +IMPL(dup2) +{ + abi_long ret = get_errno(dup2(arg1, arg2)); + if (ret >= 0) { + fd_trans_dup(arg1, arg2); + } + return ret; +} +#endif + +IMPL(dup3) +{ + int host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl); + abi_long ret; + + if ((arg3 & ~TARGET_O_CLOEXEC) != 0) { + return -EINVAL; + } +#ifdef CONFIG_DUP3 + ret = dup3(arg1, arg2, host_flags); +#else + if (host_flags == 0) { + ret = dup2(arg1, arg2); + } else { + return -TARGET_ENOSYS; + } +#endif + ret = get_errno(ret); + if (ret >= 0) { + fd_trans_dup(arg1, arg2); + } + return ret; +} + IMPL(execve) { abi_ulong *guest_ptrs; @@ -8046,6 +8094,13 @@ IMPL(faccessat) return ret; } +#ifdef TARGET_NR_fcntl +IMPL(fcntl) +{ + return do_fcntl(arg1, arg2, arg3); +} +#endif + #ifdef TARGET_NR_fork IMPL(fork) { @@ -8553,6 +8608,11 @@ IMPL(rmdir) } #endif +IMPL(setpgid) +{ + return get_errno(setpgid(arg1, arg2)); +} + #ifdef TARGET_NR_stime IMPL(stime) { @@ -8611,6 +8671,11 @@ IMPL(times) return host_to_target_clock_t(ret); } +IMPL(umask) +{ + return get_errno(umask(arg1)); +} + #ifdef TARGET_NR_umount IMPL(umount) { @@ -8789,44 +8854,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; 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: - 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 ((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()); @@ -12622,6 +12649,7 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(brk); SYSCALL(close); SYSCALL(chdir); + SYSCALL(chroot); #ifdef TARGET_NR_chmod SYSCALL(chmod); #endif @@ -12629,9 +12657,16 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(creat); #endif SYSCALL(dup); +#ifdef TARGET_NR_dup2 + SYSCALL(dup2); +#endif + SYSCALL(dup3); SYSCALL(execve); SYSCALL(exit); SYSCALL(faccessat); +#ifdef TARGET_NR_fcntl + SYSCALL(fcntl); +#endif #ifdef TARGET_NR_fork SYSCALL(fork); #endif @@ -12691,6 +12726,7 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_rmdir SYSCALL(rmdir); #endif + SYSCALL(setpgid); #ifdef TARGET_NR_stime SYSCALL(stime); #endif @@ -12702,6 +12738,7 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(time); #endif SYSCALL(times); + SYSCALL(umask); #ifdef TARGET_NR_umount SYSCALL(umount); #endif