From patchwork Sun Jun 10 03:01:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138106 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2586296lji; Sat, 9 Jun 2018 20:25:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJo4Y4sioQIWhks3tY8RK3fGfFwpZYx3ZBVjOcrZGt5sH5x9MKO6Ut5oy+Xtd/KehdivZba X-Received: by 2002:ac8:509:: with SMTP id u9-v6mr11292639qtg.97.1528601128430; Sat, 09 Jun 2018 20:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528601128; cv=none; d=google.com; s=arc-20160816; b=q5aFKZUzOVPXsi8kERrx7/VcyZdcfiwXxrgikXk7RITYS5br3QBx7Eko4q1yiz3GrV 5loCxwEDd8A7ia4zw9WEaalqFFjl3elr2eek1dbMIinGNZjR2bb9vmJpYZKH2ycubjHq yF7efcjSSaYD769UM08qz/Vd6FMcg5zbp+9ROB69lvl+MwYX9om8NPVqfiL9a+JC5YZP k3/pP64LlUQ3NWmF0TEsD/Sl75cszLLRWZ2aH9SEtwIHoQ1o13bWU8BThL8Br3rKLVR6 wQ5+Wjb9HbDoTkCBvEqL4tn6z7SlqUYv0DsMsg9SrkKfXoMuSD6ECz90WrXh62SaEebS 5o6Q== 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=NquHwfpUFzaw1yvcQe0KD+aaVwrtvkWldlItTbf1Tls=; b=PE6JSiQjbgNWsUhwQCXUqsTAJzayC1nDwkEFCxXY40UTbjX6Cd5sH2Y0ERe3qH7pFb hh+ZeFu/GGuUoseo3vHzF+ySyuOWHW29+HtGLsiaNrxYTjoAoCDUcTuA2+XSSHInKidH 8UYMcLzO9LkndqvP46FOZszKfKohxWX6Iye/Z8SRta4ZR8U8YjAZIQVmbvErVvkNvgFM 5DNU5hQqTRoR292zGHhYGkcOfQey1I1/EKIhZIRsf8nCyZnRFiOv6+Pf97H68g29Omo4 gxegHXw50ydmR3BeBQUWsuMy+CmbNBN3hM+BjiSFrSl+bcVJHroLKOO59PptFx8NOSOx xGzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Ye7XVlCo; 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 w66-v6si18797436qkb.343.2018.06.09.20.25.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:25:28 -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=Ye7XVlCo; 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]:42299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqyt-0004YV-Qo for patch@linaro.org; Sat, 09 Jun 2018 23:25:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqdx-0002bu-9H for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqdw-0003ao-E9 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:49 -0400 Received: from mail-pf0-x236.google.com ([2607:f8b0:400e:c00::236]:38365) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqdw-0003ac-8T for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:48 -0400 Received: by mail-pf0-x236.google.com with SMTP id b74-v6so8493620pfl.5 for ; Sat, 09 Jun 2018 20:03:48 -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=NquHwfpUFzaw1yvcQe0KD+aaVwrtvkWldlItTbf1Tls=; b=Ye7XVlCoh1jYHtdUgc5rN+RT9DlwEiXTEwTW2iGc91P26ndTNUHAOjIcnE95z4uQLC 50BJYIHXE86NU+vqtDDjDZqdxyv6KnzM+u93BrJMzeGajH7s4dWy5BCtFBIJZIKQFmyi pU3C98M19HUunety/nRWbAODcOm3GnWdVQAg0= 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=NquHwfpUFzaw1yvcQe0KD+aaVwrtvkWldlItTbf1Tls=; b=mh9D5mQsZYojwYcLt7nGOWkkNln07hwVE6+qct00kVSCqBsReT9OCWAYv2Yn9DhEWc BxbLZuBB86LY+SRuFcIBfJOEOF3BFAC/V879pl69I88px5HnsTaGKCQ24UonJ0jVGHcu yFpQ0Ii+O+5y+8nL3FdNeCmHOX7qw20/PjnDJwRWZ7WPAj4o2QodexF+9A710HzQFtUe EEXy2Go2J8ieLlj+xnM35ua4PWjROL/Edh51hI5sMx2eXh6lgFpB3Q2DPpQrW5IlRnF6 1YW6g67NPgT7CspNrMKh2EyeYwhJicYw45eWAtUXElmmsm//mcKKVomJZ5aGOPN2784X o1yA== X-Gm-Message-State: APt69E2w41PsUko89+T/Wk270CjvNMZLPOadBlNkb7b/2mkqlefNgwdK HXMmy+YBvp8xR4jjhNX26quzRWPN3vE= X-Received: by 2002:a63:8c4f:: with SMTP id q15-v6mr10643292pgn.236.1528599827041; Sat, 09 Jun 2018 20:03:47 -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.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:03:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:09 -1000 Message-Id: <20180610030220.3777-38-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:c00::236 Subject: [Qemu-devel] [PATCH v2 037/108] linux-user: Split out readlink, readlinkat 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 readlinkat; remove the ifdef. Unify the two with do_readlinkat so that we do not replicate the /proc/self/exe handling. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 96 ++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 53 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 39d8a70d7d..f1123479df 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8712,6 +8712,45 @@ IMPL(read) return ret; } +static abi_long do_readlinkat(abi_long dirfd, abi_long target_path, + abi_long target_buf, abi_long bufsize) +{ + char *host_path, *host_buf; + abi_long ret; + + host_path = lock_user_string(target_path); + host_buf = lock_user(VERIFY_WRITE, target_buf, bufsize, 0); + if (!host_path || !host_buf) { + ret = -TARGET_EFAULT; + } else if (is_proc_myself(host_path, "exe")) { + char real[PATH_MAX], *temp; + temp = realpath(exec_path, real); + if (temp == NULL) { + ret = get_errno(-1); + } else { + ret = MIN(strlen(real), bufsize); + memcpy(host_buf, real, ret); + } + } else { + ret = get_errno(readlinkat(dirfd, path(host_path), host_buf, bufsize)); + } + unlock_user(host_buf, target_buf, ret); + unlock_user(host_path, target_path, 0); + return ret; +} + +#ifdef TARGET_NR_readlink +IMPL(readlink) +{ + return do_readlinkat(AT_FDCWD, arg1, arg2, arg3); +} +#endif + +IMPL(readlinkat) +{ + return do_readlinkat(arg1, arg2, arg3, arg4); +} + #ifdef TARGET_NR_rename IMPL(rename) { @@ -9591,59 +9630,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_readlink - case TARGET_NR_readlink: - { - void *p2; - p = lock_user_string(arg1); - p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0); - if (!p || !p2) { - ret = -TARGET_EFAULT; - } else if (!arg3) { - /* Short circuit this for the magic exe check. */ - ret = -TARGET_EINVAL; - } else if (is_proc_myself((const char *)p, "exe")) { - char real[PATH_MAX], *temp; - temp = realpath(exec_path, real); - /* Return value is # of bytes that we wrote to the buffer. */ - if (temp == NULL) { - ret = get_errno(-1); - } else { - /* Don't worry about sign mismatch as earlier mapping - * logic would have thrown a bad address error. */ - ret = MIN(strlen(real), arg3); - /* We cannot NUL terminate the string. */ - memcpy(p2, real, ret); - } - } else { - ret = get_errno(readlink(path(p), p2, arg3)); - } - unlock_user(p2, arg2, ret); - unlock_user(p, arg1, 0); - } - return ret; -#endif -#if defined(TARGET_NR_readlinkat) - case TARGET_NR_readlinkat: - { - void *p2; - p = lock_user_string(arg2); - p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0); - if (!p || !p2) { - ret = -TARGET_EFAULT; - } else if (is_proc_myself((const char *)p, "exe")) { - char real[PATH_MAX], *temp; - temp = realpath(exec_path, real); - ret = temp == NULL ? get_errno(-1) : strlen(real) ; - snprintf((char *)p2, arg4, "%s", real); - } else { - ret = get_errno(readlinkat(arg1, path(p), p2, arg4)); - } - unlock_user(p2, arg3, ret); - unlock_user(p, arg2, 0); - } - return ret; -#endif #ifdef TARGET_NR_swapon case TARGET_NR_swapon: if (!(p = lock_user_string(arg1))) @@ -12783,6 +12769,10 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(pipe2); SYSCALL(pselect6); SYSCALL(read); +#ifdef TARGET_NR_readlink + SYSCALL(readlink); +#endif + SYSCALL(readlinkat); #ifdef TARGET_NR_rename SYSCALL(rename); #endif