From patchwork Sun Aug 23 14:59:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 275793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F0C7C433E1 for ; Sun, 23 Aug 2020 15:00:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 58C7B20724 for ; Sun, 23 Aug 2020 15:00:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58C7B20724 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rTc-0006TD-Ga for qemu-devel@archiver.kernel.org; Sun, 23 Aug 2020 11:00:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSq-0004q1-8y for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:20 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:39683) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSo-0006do-JF for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:19 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MF418-1kPJwh0Nr6-00FWNg; Sun, 23 Aug 2020 16:59:15 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 1/6] linux-user: Fix "print_fdset()" in "strace.c" to not print ", " after last value Date: Sun, 23 Aug 2020 16:59:07 +0200 Message-Id: <20200823145912.1171738-2-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:fQMcgnkCFnxaicvpaHt7bUk2jrLc0OM4pV+KWmfeJkkP9th9/bI C6fQgRJtnV/Rb1qJMKmmHGl+wooO4CTHGk7JMsVBGhDzIm+7roVuwx7S133uJTI1e/6XU8W SwKBWdhTTymLgTl6D5XUG2v2XxZmrrp0TF9aub3lHCCUrYE952lGnolDBeja4PlLEXeWzVU 4VOF7zsoUDeu/am2JFjQA== X-UI-Out-Filterresults: notjunk:1; V03:K0:dY4q/t3LkVo=:g5cyiyOzHR2xYXvjbQ0oDT GWdfL+ASgrDN7F1nopAnQVRHr3nY70t2nl6Uf+2ezmh9elwcx7JohPNXiqeVfyvVYJhHNqovx U0P9PNcAL4dJdlo9muJzFk5dvuO8QBSDJVRAnnaie/M8Nrw4dYICHTkv3cELhnt6FlxH2qeAs QQdTJVIHJOuFf9NpMP3DDBKzvHzbjBoTS0z3VRPIvE8od3Mwp/JiiMoPtxuQ8JWjVEBVEUv27 lgfqMTYGISLE/aJ1aP2gVS7MerwM7I8Dzxh8eDmj3h1LMEtl2UPbvuBmztwFSQ3Vr36fmlcrD X6/zY1jL3LPClvjTC5e0tz/ZZf1rt7ctYX5Ibjy29d+u325MNsf9i+EuWp9vhqoWNDG0RaUFS UNw0FYoVQUyZV41+KlxXRBuxDLty2dfJkGppVbLkVoeifKDGcS1nco7BH+/xdm2WJdR3RRwak loemA2yA8arWLrSKX0SFbh8eLgCUMDKGQUonNq6l01q4t74oidNbLWsNINrhFX/mC5+9mcvVr VpYSAUSCSXNuel5BwHlaC/0VBfKTERL8YuiGkCf9Q7sWkugRIAO7+sy5I/aVsF1i+Sdx3dL1l gn/0KZr467rL2WtSEC6FEehk54mOq3+lTgoKbQbpdrLIN9WAzLsW6ytyELvWxFFwdjVTRmgqy saO1Tl7CB/4oBxibLxLtrglUlUIBLJf50MkbJj3zjYQamBNfFP1+J88BVxvjEqS90Y4tFwqEJ gIn3OEhRs+E9yBO/Riuh2IhMbAP5CR/q1DGlNwb/77XKrCaFBq0uEJv4l4qayDB5dPva504Ln K5/pH3hFxrT/zoqyupKLH0/fzAT2/7cf+/I66b23n1S/K5+PpFjXDUvWbXW0ASIYNFyrOaU Received-SPF: none client-ip=217.72.192.75; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Filip Bozuta Function "print_fdset()" in "strace.c" is used to print the file descriptor values in "print__newselect()" which prints arguments of syscall _newselect(). Until changes from this patch, this function was printing "," even after the last value of the fd_set argument. This was changed in this patch by removing this unnecessary "," after the last fd value and thus improving the estetics of the _newselect() "-strace" print. Implementation notes: The printing fix was made possible by using an existing function "get_comma()" which returns a "," or an empty string "" based on its argument (0 for "," and other for ""). Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200702160915.9517-1-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/strace.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index 13981341b327..5e380486433c 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -541,6 +541,7 @@ static void print_fdset(int n, abi_ulong target_fds_addr) { int i; + int first = 1; qemu_log("["); if( target_fds_addr ) { @@ -555,9 +556,12 @@ print_fdset(int n, abi_ulong target_fds_addr) return; for (i=n; i>=0; i--) { - if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1) - qemu_log("%d,", i); + if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> + (i & (TARGET_ABI_BITS - 1))) & 1) { + qemu_log("%s%d", get_comma(first), i); + first = 0; } + } unlock_user(target_fds, target_fds_addr, 0); } qemu_log("]"); From patchwork Sun Aug 23 14:59:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 248148 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:522:0:0:0:0 with SMTP id h2csp1881520ils; Sun, 23 Aug 2020 07:59:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8cDo9uZVcTb3Z0SqkvvvF9G2fl3Hf49TiJQ5ET0bBcjpNfuhbxcCxnCWuFon/PGg1oHqT X-Received: by 2002:a25:e00e:: with SMTP id x14mr2059637ybg.263.1598194773905; Sun, 23 Aug 2020 07:59:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598194773; cv=none; d=google.com; s=arc-20160816; b=v6xkvkZxnqfLFQpcolFkz9UVPZuXZVRINSaKBiWwrU3WbcmPrZQN5r21B4kvlKsEFl DntRc+/ic/fu3aDIDvh0OIJBjzBJGqLrGus8HQk1Rp+2rMXWEd4RlPYobCdqymjsBZNa QlW6vPukDHaUAHhqnIMAxkd/u3y8id61b4UDKSO0rJGHjQJ4RO4vex822P90IFOIetqc xefSTJUSl87s9YErwV+G1nFq1qjqogVT8WepI532+qyhq5Fho+fqgCBRL7RSWW2Eilbx mPC/Ip3376U87B3MRGHVAEbw2fmbwyJARn52k6sPdVlbwnMwgirEZsl7pFV3thQpIaYP XdpA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=JiEkVxcOfuMktQAh35q+WwnwzNzBhoyR5assqUVwYxs=; b=QMyAEgZNGCf4a9T5MNyGRHzejZwNaVqUSZgQREH/dlh3kyAFD861THpB3xUS35GLN/ kuHGQ4cM68poHn/Z20QIKo55MTDVKWXKeHhlPtYsBKRplmxyMVNAKurLtXmNE22F/VYb cXuPMZ89yLTbQqQ06biTC/oRzwGmbXqgOmrb/tFmwAT+JEtkZNFTI4grcFG2XyqzUXYA bGwG+UBDRc44NCVZOMR48SfucN1Ha6EvaYadviEjJpPDMGkscX+MC9wnv4O/DLKbMMBV 6pOdWrI0LruQn393X36cP7VSl4Yf13w69dVdHg4XGZe5uqT8sUc38jr7h15iJffBU6jq d/6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y124si8456396ybe.458.2020.08.23.07.59.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Aug 2020 07:59:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:34782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rT3-0004tt-AQ for patch@linaro.org; Sun, 23 Aug 2020 10:59:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSr-0004rM-Rs for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:40005) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSp-0006dq-Ap for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N18I8-1kbt0r2bl4-012W6Y; Sun, 23 Aug 2020 16:59:15 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 2/6] linux-user: Validate mmap/mprotect prot value Date: Sun, 23 Aug 2020 16:59:08 +0200 Message-Id: <20200823145912.1171738-3-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Go7dNnmGWvrNwcfNOSZtXSLggfMJP+pnuQ1MiqldJQLatJdV5Bp 7rod3jpuAIgYINDwB9/9/yNwXCHC/F0QcZCVXmV6RL2cbV3Yne9fEygttjz87Y6kJuo8zQT Cs7vdmrV5JZu+oPHg2kiCF2RQy1B8bzs8Lr1BstahPjIv0EtVMAB528wnjxAdErGcbUIttN cL5I2OcKKFI8/DYhX4WUA== X-UI-Out-Filterresults: notjunk:1; V03:K0:/wutq+zkr2A=:ex7dAghrSnrnQAjeiAe10v U5dlOgNLBo2EAGR6IpPx7j06p9DF5u3d/d37YkuJU1JryH9qcufAvSO6Et294Tjb8bjyul1aV QNeU4e+3wmssnUopNixLT5u0MvU720AkVx+X6HSQnq1VHLKpPttEVeb47BBePOtO7rAI4ElGQ 6DCmR2G8u4r1dh5z6S3dnC5DQBegEe6mmvhjmnnoVB9pYUxlW5MJ5GGluNUYlJpS6Spiti0dc C/TueLKsLCeYynGnXkflhiU2umHMNtuxl+LfKckBSbjLaEfsUW2g1jw9lJOcnU3QG8wSMCT1t 8xV4v3oiU7BDMYcP6Q/H7gMWQcwZdh3J/R+mp4vNEXF87Lf1dgFweYs2ULFBOBgZlsS3nh6HI fXiFHHKErkNPNnyGXxkQryQBs9DO3RmeFX0sdlyvXKIxrsELPZcKhM9p8LfoyOPJgEG5n+dNF F5zzqsZHX3VDB9zPc9d7gZ+sitZHIO1/3b5YX0J7F3r7JBxcU7Z+alYOl2a3G6NBMphJ7nPVV eG3x/dl/eVMGEgmiU+S5EHIPxcSKJVNyiBN3U+SbxYlOXH3BLdh/7RGUMY6TOPg8indZSLelO 2V05tVymVR0t9uMLwntgEqipRyxpkoSfHFnueTSXLLufRwKV910Zlp6iGMtyfydobggvp43Cg FilZg2LiWfz0PgIXb5pQ4SLGb6XVDvrmhpvk7ljL9HU2Zhjs+yJnLEMhANLmIuOLuFfxfOF97 evy8l7BtevQhTwVrSYoz59MYORFafFh0cY1UfUG3hW+j3vFk2pbrRCR2CbImXFR3NTCOm9gNt gPtV8iij/kGvfetkGQFfxvn+RBi8yq/3/ICscxYP70rSDHFRUCdqgIl7mSt//l+gqcB9r/4 Received-SPF: none client-ip=217.72.192.74; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson The kernel will return -EINVAL for bits set in the prot argument that are unknown or invalid. Previously we were simply cropping out the bits that we care about. Introduce validate_prot_to_pageflags to perform this check in a single place between the two syscalls. Differentiate between the target and host versions of prot. Compute the qemu internal page_flags value at the same time. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Message-Id: <20200519185645.3915-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 106 +++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 33 deletions(-) -- 2.26.2 diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 0019447892e0..46c7eeba9bd2 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -59,64 +59,96 @@ void mmap_fork_end(int child) pthread_mutex_unlock(&mmap_mutex); } +/* + * Validate target prot bitmask. + * Return the prot bitmask for the host in *HOST_PROT. + * Return 0 if the target prot bitmask is invalid, otherwise + * the internal qemu page_flags (which will include PAGE_VALID). + */ +static int validate_prot_to_pageflags(int *host_prot, int prot) +{ + int valid = PROT_READ | PROT_WRITE | PROT_EXEC | TARGET_PROT_SEM; + int page_flags = (prot & PAGE_BITS) | PAGE_VALID; + + /* + * For the host, we need not pass anything except read/write/exec. + * While PROT_SEM is allowed by all hosts, it is also ignored, so + * don't bother transforming guest bit to host bit. Any other + * target-specific prot bits will not be understood by the host + * and will need to be encoded into page_flags for qemu emulation. + */ + *host_prot = prot & (PROT_READ | PROT_WRITE | PROT_EXEC); + + return prot & ~valid ? 0 : page_flags; +} + /* NOTE: all the constants are the HOST ones, but addresses are target. */ -int target_mprotect(abi_ulong start, abi_ulong len, int prot) +int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) { abi_ulong end, host_start, host_end, addr; - int prot1, ret; + int prot1, ret, page_flags, host_prot; - trace_target_mprotect(start, len, prot); + trace_target_mprotect(start, len, target_prot); - if ((start & ~TARGET_PAGE_MASK) != 0) + if ((start & ~TARGET_PAGE_MASK) != 0) { return -TARGET_EINVAL; + } + page_flags = validate_prot_to_pageflags(&host_prot, target_prot); + if (!page_flags) { + return -TARGET_EINVAL; + } len = TARGET_PAGE_ALIGN(len); end = start + len; if (!guest_range_valid(start, len)) { return -TARGET_ENOMEM; } - prot &= PROT_READ | PROT_WRITE | PROT_EXEC; - if (len == 0) + if (len == 0) { return 0; + } mmap_lock(); host_start = start & qemu_host_page_mask; host_end = HOST_PAGE_ALIGN(end); if (start > host_start) { /* handle host page containing start */ - prot1 = prot; - for(addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) { + prot1 = host_prot; + for (addr = host_start; addr < start; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } if (host_end == host_start + qemu_host_page_size) { - for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { + for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } end = host_end; } - ret = mprotect(g2h(host_start), qemu_host_page_size, prot1 & PAGE_BITS); - if (ret != 0) + ret = mprotect(g2h(host_start), qemu_host_page_size, + prot1 & PAGE_BITS); + if (ret != 0) { goto error; + } host_start += qemu_host_page_size; } if (end < host_end) { - prot1 = prot; - for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { + prot1 = host_prot; + for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) { prot1 |= page_get_flags(addr); } - ret = mprotect(g2h(host_end - qemu_host_page_size), qemu_host_page_size, - prot1 & PAGE_BITS); - if (ret != 0) + ret = mprotect(g2h(host_end - qemu_host_page_size), + qemu_host_page_size, prot1 & PAGE_BITS); + if (ret != 0) { goto error; + } host_end -= qemu_host_page_size; } /* handle the pages in the middle */ if (host_start < host_end) { - ret = mprotect(g2h(host_start), host_end - host_start, prot); - if (ret != 0) + ret = mprotect(g2h(host_start), host_end - host_start, host_prot); + if (ret != 0) { goto error; + } } - page_set_flags(start, start + len, prot | PAGE_VALID); + page_set_flags(start, start + len, page_flags); mmap_unlock(); return 0; error: @@ -360,19 +392,26 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) } /* NOTE: all the constants are the HOST ones */ -abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, +abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, int flags, int fd, abi_ulong offset) { abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len; + int page_flags, host_prot; mmap_lock(); - trace_target_mmap(start, len, prot, flags, fd, offset); + trace_target_mmap(start, len, target_prot, flags, fd, offset); if (!len) { errno = EINVAL; goto fail; } + page_flags = validate_prot_to_pageflags(&host_prot, target_prot); + if (!page_flags) { + errno = EINVAL; + goto fail; + } + /* Also check for overflows... */ len = TARGET_PAGE_ALIGN(len); if (!len) { @@ -438,14 +477,15 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, /* Note: we prefer to control the mapping address. It is especially important if qemu_host_page_size > qemu_real_host_page_size */ - p = mmap(g2h(start), host_len, prot, + p = mmap(g2h(start), host_len, host_prot, flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) + if (p == MAP_FAILED) { goto fail; + } /* update start so that it points to the file position at 'offset' */ host_start = (unsigned long)p; if (!(flags & MAP_ANONYMOUS)) { - p = mmap(g2h(start), len, prot, + p = mmap(g2h(start), len, host_prot, flags | MAP_FIXED, fd, host_offset); if (p == MAP_FAILED) { munmap(g2h(start), host_len); @@ -479,19 +519,19 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, /* msync() won't work here, so we return an error if write is possible while it is a shared mapping */ if ((flags & MAP_TYPE) == MAP_SHARED && - (prot & PROT_WRITE)) { + (host_prot & PROT_WRITE)) { errno = EINVAL; goto fail; } - retaddr = target_mmap(start, len, prot | PROT_WRITE, + retaddr = target_mmap(start, len, target_prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (retaddr == -1) goto fail; if (pread(fd, g2h(start), len, offset) == -1) goto fail; - if (!(prot & PROT_WRITE)) { - ret = target_mprotect(start, len, prot); + if (!(host_prot & PROT_WRITE)) { + ret = target_mprotect(start, len, target_prot); assert(ret == 0); } goto the_end; @@ -502,13 +542,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, if (real_end == real_start + qemu_host_page_size) { /* one single host page */ ret = mmap_frag(real_start, start, end, - prot, flags, fd, offset); + host_prot, flags, fd, offset); if (ret == -1) goto fail; goto the_end1; } ret = mmap_frag(real_start, start, real_start + qemu_host_page_size, - prot, flags, fd, offset); + host_prot, flags, fd, offset); if (ret == -1) goto fail; real_start += qemu_host_page_size; @@ -517,7 +557,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, if (end < real_end) { ret = mmap_frag(real_end - qemu_host_page_size, real_end - qemu_host_page_size, end, - prot, flags, fd, + host_prot, flags, fd, offset + real_end - qemu_host_page_size - start); if (ret == -1) goto fail; @@ -533,13 +573,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, else offset1 = offset + real_start - start; p = mmap(g2h(real_start), real_end - real_start, - prot, flags, fd, offset1); + host_prot, flags, fd, offset1); if (p == MAP_FAILED) goto fail; } } the_end1: - page_set_flags(start, start + len, prot | PAGE_VALID); + page_set_flags(start, start + len, page_flags); the_end: trace_target_mmap_complete(start); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { From patchwork Sun Aug 23 14:59:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 248149 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:522:0:0:0:0 with SMTP id h2csp1881663ils; Sun, 23 Aug 2020 07:59:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3txVMY/qAvdSvz8jydQakobBRzY4nJjEk5uC6upHTiqew9B7vcVx1Knh63FOjPIJhuvCd X-Received: by 2002:a25:ab0d:: with SMTP id u13mr2194772ybi.248.1598194794229; Sun, 23 Aug 2020 07:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598194794; cv=none; d=google.com; s=arc-20160816; b=e/YlD58q3tC2kpeggBjmtUMe7xnycFToRTbWLqJgwpMVh1E/4c0FS/+sWRsw0OvDvb SyZi2wN+roMvWh5NAWvIUQ3qWTfD9Nqu9Lwk0oq/hOZQOC7IkX3kI+m49bqfBriZuf+b 9lcqco0qCudY2/M0z9ByDO6Bz4WgMf/IP++lvI59tQg88Q507y8nydh7ZZP6HpqhSzp3 H7PGZGIXDF9IrZ6qU5h86LCLlrPE4aU9Mb++JMqLeBbe1x3PXmcX7GqS0hFBepOkr9Nz /bIB/nwDodY7kFTpZ6E6N0avR/vC1M3atoxtE9GNdrT08Qva6dF11nQ5dOOaaQBoH958 hclQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from; bh=wur1SFGp5xDijZMn7bJkUj1KQAmzkSNHK88wQEnF7jk=; b=FdE2gModCzi9pfgGG07wWXFmC8TwKUDCTlZ9yEFDzn/1qHi0TuwrS6bN6voRkRnQj1 +kru6GxAIIKVzk4ZydfSi/ToBX+p5axTxY+sUrCE6qazgzIemTuTgev+LIDFsuQUcDNT 7PKW/rOUFuy42PuN0i2chLm27W5VPK3nHxDcLnUjYyqG87E5v4Z4Z9tRAHMI6uAT73JT aKTkuaJq9skD1rQKq++Zi8muoFXuBmOzbgHSs04cStxKFFI2m4120jcvf9Cuy6aUfRmI 8I9Z8lf9l8ftCbgeuDnnKCOzILwO0+GeYRPM4MfY+07HxLuJyvR0F9UPeFSCXslru/Vp MfEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m17si8699443ybt.300.2020.08.23.07.59.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Aug 2020 07:59:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:34902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rTN-0004x5-Mc for patch@linaro.org; Sun, 23 Aug 2020 10:59:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSr-0004r1-HD for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:52415) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSp-0006dz-PQ for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MrgcU-1kxGiW1FZ6-00nljk; Sun, 23 Aug 2020 16:59:16 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 3/6] linux-user: Adjust guest page protection for the host Date: Sun, 23 Aug 2020 16:59:09 +0200 Message-Id: <20200823145912.1171738-4-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:uVSC+BN8iffnkVovJ5et5KG/MimAMbh6ytMx2N7MYhuKxwm2lXf pm5282ABPtW5oxmMgi8dvLGg1PHoCBh7R9znGic0L6LkcjmsD7cP0i998jpvA9vM43rDp8m JWTsw1dGeO4sD83jxN9m3iJJDSDodXoDjPEv0n3TLlAWSHCNjM7JDF0NozNvdcJNDr0kOi/ oDB4YsaeOXMh4iPgQObnA== X-UI-Out-Filterresults: notjunk:1; V03:K0:+930OTmX7ew=:8+r9hGeTbX+k/Jokb28Vju 1WkyEYFeX/sgS41Z8vCpUedbsFB67c5ffe27pzM/1R21p9TlBWPE5Zw5kTgu1lbW7mnUoG0Zr QZZrazNnfOdhYj9mK6cxXClavvpJuBWinxIyhAQMvNI1FFIQq0sGQKjGJpVA/ye5oVN5ga8X3 GLU/hQ2BpfXUU9twhnGgy5g7GVJ201N/JvjDCfK+oeGiVpknnfmbjO8s3IgiavRTzd5OF83bF q522eFKL8FljtGwr/NcceQhrVflAYd/SSBVt4RKgum7Q/Gs4LG7rGpwY4SN7BExSJMKyHptcN 2h+2GYrNXeJ0l6QdOhTYikltVlk0d/ePaTqaV9iw6FRkwOvttnuO733D8+fS4mGDsN9AKSjTu RaC/iKJQl8myWOCSu587DVMX+JnCfVBeP9mZipcelC/u4ZBYqQ/X9kP4+QeEri/n3J9UkqgDI dA1dKcWqke0siqB7SsKZgLGimX90e4r32lFTMBrhaIM1s9F2iKlM5g+w7qxG2TXKn1hLDA3R1 Vl0/OkYIbSO5NN/QZAcXTw1+dpxtt1m1+xQNeez/wsAdMXnBxeC5kP3g8RkoJDoyMsnjUXvUC bxqvgs0QNSgQx+0r6GTlJh6AgFvYlHz1BKw5Ixyn/3zGtcX4KxpfJ/BBGGirbvbtzBIW9F0b8 3dals+rooEVUAS7G5rLzuvynzXkDRTCmyl7fi4KMBCkBcYSbqCVOzYfXPWG05qjCDKrqsw9ET D96FpSUc2ufv0d0Y79al93nJgsuqPybMeYBqGl1e7/IbK6pnIXCMAOC4sdSQhRNWWjyq+Zhjr eYHeeakIbNpQYj1gIesn8TcMWo4e2BJJYKxFmb5yHMtCdYOKZAhsy8kEOSCyIpqIb4pC+m6 Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Richard Henderson , Laurent Vivier , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Executable guest pages are never directly executed by the host, but do need to be readable for translation. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell Message-Id: <20200519185645.3915-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/mmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.26.2 diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 46c7eeba9bd2..f2615634201d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -76,8 +76,12 @@ static int validate_prot_to_pageflags(int *host_prot, int prot) * don't bother transforming guest bit to host bit. Any other * target-specific prot bits will not be understood by the host * and will need to be encoded into page_flags for qemu emulation. + * + * Pages that are executable by the guest will never be executed + * by the host, but the host will need to be able to read them. */ - *host_prot = prot & (PROT_READ | PROT_WRITE | PROT_EXEC); + *host_prot = (prot & (PROT_READ | PROT_WRITE)) + | (prot & PROT_EXEC ? PROT_READ : 0); return prot & ~valid ? 0 : page_flags; } From patchwork Sun Aug 23 14:59:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 275791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CFABC433E3 for ; Sun, 23 Aug 2020 15:01:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 34B622067C for ; Sun, 23 Aug 2020 15:01:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 34B622067C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=vivier.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9rVI-00019q-Ev for qemu-devel@archiver.kernel.org; Sun, 23 Aug 2020 11:01:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSs-0004re-5g for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:22 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:51113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9rSp-0006dy-Oo for qemu-devel@nongnu.org; Sun, 23 Aug 2020 10:59:21 -0400 Received: from localhost.localdomain ([82.252.135.186]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MBV6n-1kLjAo0vkd-00D24x; Sun, 23 Aug 2020 16:59:17 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 5/6] linux-user: Add support for a group of 2038 safe syscalls Date: Sun, 23 Aug 2020 16:59:11 +0200 Message-Id: <20200823145912.1171738-6-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200823145912.1171738-1-laurent@vivier.eu> References: <20200823145912.1171738-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:v/JmIcn/3gVAHzsA1rNfUefu5YhhsxT8oo0s52LsPvme60BSJxl W4tKmN3tSlrZj4bdLxt1X9g6Pb0arUJiFb/X9sSU5TlkxiR6N1zVAcb1+tegRgYSQ+0qfAv 7LPvt6Ecntzdm7I8uBGFExthaNHCC3XqavvTPz2Wf/pMbOBGfy4qpt0COXi1Imt3zuAoxLf 64jtSGS1ooICij8nM/iCA== X-UI-Out-Filterresults: notjunk:1; V03:K0:t7GN+OD/ZlQ=:vpH4QomBu6+qsKavJRGm4w ghvkmbHIo9Fuyv0JbUYCm/PHZXapCf+TGXxPUHCDIs21m8RAkZ/dk5Pk2m5v08U+xbdqyzi4v 4CBnX+aGSO1JwfIvJLopqG7yr0ZyQtOCJyg3FfOJKCYWOY/FAyRwQUh5+zejnRacR/g6/5w6y a5CXoiVyHjJwu01SZv0DfmaEd1gOcb9l6B/MDpCozOL/DJGCa7upj4H+xP/T7sba4HmZrhHP0 A0M5zUwPInfLCaqDfXvHp/vAdxvlbVuj47/YMg03KYUqvuP3CEZngLCkO3zJg4IxdRTTqna3/ BPqLs+mmZO2dDfNnLinfrB7RBPXMIDyi1siTaPmQzRoxmrH3oqAJePzDbNM6p37zP+AW5Z+VT ceZfAe1Vx8ZWOSJsx/58HipbNzaSL7nQ9qw/pc/2ScZA3cUXxCNb6ubnfZHyPFKxRV4L/PkRM guvcXVdOX+pv9eXkRJ7E4zHPfVnRA50v2tacLQ7WgDWqV29/bj1hCHxkAt1W7WrnIU1G+U8dc Zjw/pY5i5yW+rmIyCPwOuSTIijMQX0G8c6r3xRQ2ek28HkTIx/KXUgLPwXwG5ISalrPibvvD3 qqASYlNgm4Dff/PvGt32zN984F5/rKCP5uT6kiUFpDqn/QwRNuQgbRrd6PEOUavsFplngLmjh eibsmVpk45kXhqPEWyRQZ6pqmu/W3PHYRPBgPJJCM5BN3VySmoFNJ7mRwEPI0+i3UvuaLEYzV TMNOETjqzksVEySXrM/oZ793Yi52jyTWYWefrYY3QL4Ip2qOb3HnUqV9ZqhIFqVZOahybJnAZ TMgXJTEVj/oFDsxIfXx9F1wtJrbNfJR5VqYPHoJz0ej9TViqlLf89YcNGNMYAZtXBIZiNlF Received-SPF: none client-ip=217.72.192.73; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 10:59:18 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Filip Bozuta This patch implements functionality for following time64 syscalls: *clock_getres_time64 This a year 2038 safe variant of syscall: int clock_getres(clockid_t clockid, struct timespec *res) --finding the resoultion of a specified clock-- man page: https://man7.org/linux/man-pages/man2/clock_getres.2.html *timer_gettime64 *timer_settime64 These are year 2038 safe variants of syscalls: int timer_settime(timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec *old_value) int timer_gettime(timer_t timerid, struct itimerspec *curr_value) --arming/dissarming and fetching state of POSIX per-process timer-- man page: https://man7.org/linux/man-pages/man2/timer_settime.2.html *timerfd_gettime64 *timerfd_settime64 These are year 2038 safe variants of syscalls: int timerfd_settime(int fd, int flags, const struct itimerspec *new_value, struct itimerspec *old_value) int timerfd_gettime(int fd, struct itimerspec *curr_value) --timers that notify via file descriptor-- man page: https://man7.org/linux/man-pages/man2/timerfd_settime.2.html Implementation notes: Syscall 'clock_getres_time64' was implemented similarly to 'clock_getres()'. The only difference was that for the conversion of 'struct timespec' from host to target, function 'host_to_target_timespec64()' was used instead of 'host_to_target_timespec()'. For other syscalls, new functions 'host_to_target_itimerspec64()' and 'target_to_host_itimerspec64()' were added to convert the value of the 'struct itimerspec' from host to target and vice versa. A new type 'struct target__kernel_itimerspec' was added in 'syscall_defs.h'. This type was defined with fields which are of the already defined type 'struct target_timespec'. This new 'struct target__kernel_itimerspec' type is used in these new converting functions. These new functions were defined similarly to 'host_to_target_itimerspec()' and 'target_to_host_itimerspec()' the only difference being that 'target_to_host_timespec64()' and 'host_to_target_timespec64()' were used. Signed-off-by: Filip Bozuta Reviewed-by: Laurent Vivier Message-Id: <20200722153421.295411-3-Filip.Bozuta@syrmia.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 139 +++++++++++++++++++++++++++++++++++++- linux-user/syscall_defs.h | 5 ++ 2 files changed, 143 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index aea1160804a2..bbb61a59c72f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1247,7 +1247,9 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts, } #endif -#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) +#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) || \ + defined(TARGET_NR_timer_settime64) || \ + (defined(TARGET_NR_timerfd_settime64) && defined(CONFIG_TIMERFD)) static inline abi_long target_to_host_timespec64(struct timespec *host_ts, abi_ulong target_addr) { @@ -6801,6 +6803,24 @@ static inline abi_long target_to_host_itimerspec(struct itimerspec *host_its, } #endif +#if defined(TARGET_NR_timer_settime64) || \ + (defined(TARGET_NR_timerfd_settime64) && defined(CONFIG_TIMERFD)) +static inline abi_long target_to_host_itimerspec64(struct itimerspec *host_its, + abi_ulong target_addr) +{ + if (target_to_host_timespec64(&host_its->it_interval, target_addr + + offsetof(struct target__kernel_itimerspec, + it_interval)) || + target_to_host_timespec64(&host_its->it_value, target_addr + + offsetof(struct target__kernel_itimerspec, + it_value))) { + return -TARGET_EFAULT; + } + + return 0; +} +#endif + #if ((defined(TARGET_NR_timerfd_gettime) || \ defined(TARGET_NR_timerfd_settime)) && defined(CONFIG_TIMERFD)) || \ defined(TARGET_NR_timer_gettime) || defined(TARGET_NR_timer_settime) @@ -6819,6 +6839,26 @@ static inline abi_long host_to_target_itimerspec(abi_ulong target_addr, } #endif +#if ((defined(TARGET_NR_timerfd_gettime64) || \ + defined(TARGET_NR_timerfd_settime64)) && defined(CONFIG_TIMERFD)) || \ + defined(TARGET_NR_timer_gettime64) || defined(TARGET_NR_timer_settime64) +static inline abi_long host_to_target_itimerspec64(abi_ulong target_addr, + struct itimerspec *host_its) +{ + if (host_to_target_timespec64(target_addr + + offsetof(struct target__kernel_itimerspec, + it_interval), + &host_its->it_interval) || + host_to_target_timespec64(target_addr + + offsetof(struct target__kernel_itimerspec, + it_value), + &host_its->it_value)) { + return -TARGET_EFAULT; + } + return 0; +} +#endif + #if defined(TARGET_NR_adjtimex) || \ (defined(TARGET_NR_clock_adjtime) && defined(CONFIG_CLOCK_ADJTIME)) static inline abi_long target_to_host_timex(struct timex *host_tx, @@ -11811,6 +11851,17 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return ret; } #endif +#ifdef TARGET_NR_clock_getres_time64 + case TARGET_NR_clock_getres_time64: + { + struct timespec ts; + ret = get_errno(clock_getres(arg1, &ts)); + if (!is_error(ret)) { + host_to_target_timespec64(arg2, &ts); + } + return ret; + } +#endif #ifdef TARGET_NR_clock_nanosleep case TARGET_NR_clock_nanosleep: { @@ -12405,6 +12456,32 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, } #endif +#ifdef TARGET_NR_timer_settime64 + case TARGET_NR_timer_settime64: + { + target_timer_t timerid = get_timer_id(arg1); + + if (timerid < 0) { + ret = timerid; + } else if (arg3 == 0) { + ret = -TARGET_EINVAL; + } else { + timer_t htimer = g_posix_timers[timerid]; + struct itimerspec hspec_new = {{0},}, hspec_old = {{0},}; + + if (target_to_host_itimerspec64(&hspec_new, arg3)) { + return -TARGET_EFAULT; + } + ret = get_errno( + timer_settime(htimer, arg2, &hspec_new, &hspec_old)); + if (arg4 && host_to_target_itimerspec64(arg4, &hspec_old)) { + return -TARGET_EFAULT; + } + } + return ret; + } +#endif + #ifdef TARGET_NR_timer_gettime case TARGET_NR_timer_gettime: { @@ -12428,6 +12505,29 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, } #endif +#ifdef TARGET_NR_timer_gettime64 + case TARGET_NR_timer_gettime64: + { + /* args: timer_t timerid, struct itimerspec64 *curr_value */ + target_timer_t timerid = get_timer_id(arg1); + + if (timerid < 0) { + ret = timerid; + } else if (!arg2) { + ret = -TARGET_EFAULT; + } else { + timer_t htimer = g_posix_timers[timerid]; + struct itimerspec hspec; + ret = get_errno(timer_gettime(htimer, &hspec)); + + if (host_to_target_itimerspec64(arg2, &hspec)) { + ret = -TARGET_EFAULT; + } + } + return ret; + } +#endif + #ifdef TARGET_NR_timer_getoverrun case TARGET_NR_timer_getoverrun: { @@ -12481,6 +12581,20 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return ret; #endif +#if defined(TARGET_NR_timerfd_gettime64) && defined(CONFIG_TIMERFD) + case TARGET_NR_timerfd_gettime64: + { + struct itimerspec its_curr; + + ret = get_errno(timerfd_gettime(arg1, &its_curr)); + + if (arg2 && host_to_target_itimerspec64(arg2, &its_curr)) { + return -TARGET_EFAULT; + } + } + return ret; +#endif + #if defined(TARGET_NR_timerfd_settime) && defined(CONFIG_TIMERFD) case TARGET_NR_timerfd_settime: { @@ -12504,6 +12618,29 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return ret; #endif +#if defined(TARGET_NR_timerfd_settime64) && defined(CONFIG_TIMERFD) + case TARGET_NR_timerfd_settime64: + { + struct itimerspec its_new, its_old, *p_new; + + if (arg3) { + if (target_to_host_itimerspec64(&its_new, arg3)) { + return -TARGET_EFAULT; + } + p_new = &its_new; + } else { + p_new = NULL; + } + + ret = get_errno(timerfd_settime(arg1, arg2, p_new, &its_old)); + + if (arg4 && host_to_target_itimerspec64(arg4, &its_old)) { + return -TARGET_EFAULT; + } + } + return ret; +#endif + #if defined(TARGET_NR_ioprio_get) && defined(__NR_ioprio_get) case TARGET_NR_ioprio_get: return get_errno(ioprio_get(arg1, arg2)); diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 3c261cff0e5e..427a25f5bce5 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -259,6 +259,11 @@ struct target_itimerspec { struct target_timespec it_value; }; +struct target__kernel_itimerspec { + struct target__kernel_timespec it_interval; + struct target__kernel_timespec it_value; +}; + struct target_timex { abi_uint modes; /* Mode selector */ abi_long offset; /* Time offset */