From nobody Sun Nov 24 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1722643191; cv=none; d=zohomail.com; s=zohoarc; b=YRKnjlrDIZhx4q1UArfh7kYG4+zTtqKJpVXjA5QCVIfeEaT7liDsgdxZHpCzCUyDQAYucYHBkUQ2cbztD5ixzvR7UucJ5ecOzBd17GfKvbivV6gJa74NRfyyKthlaNkYTMRnS2ZjHzN6gr2RyXR5nysiy7ahmRLq3lbEE+mYGis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722643191; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hxMMYdUIWV7BpRLm7ZCMIQipXwTZjxzuoSHO0vQ0wkg=; b=mhRXGEVWpfSwXYxdpqUvwyZUzRHe0mAJVp89TnbOvOUZ1YyTvlPTYrAH7vyhxgLLcG0HfwEOYp63cACyd9Qt4st2ygCnkHP3dM8JlDg1luheHgfMDC26f3MDxPMJzZMSGGIwAFXQ9KmzCh7hS0m6sUUP+wAZqUGVezkw9ljsAo8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722643191848274.2616931600944; Fri, 2 Aug 2024 16:59:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sa29p-0002Jc-0k; Fri, 02 Aug 2024 19:58:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sa29l-00024Q-HP for qemu-devel@nongnu.org; Fri, 02 Aug 2024 19:57:57 -0400 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sa29j-0004JB-LL for qemu-devel@nongnu.org; Fri, 02 Aug 2024 19:57:57 -0400 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-81fd1e1d38bso100892439f.1 for ; Fri, 02 Aug 2024 16:57:55 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c8d69a8227sm683131173.47.2024.08.02.16.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 16:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1722643074; x=1723247874; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hxMMYdUIWV7BpRLm7ZCMIQipXwTZjxzuoSHO0vQ0wkg=; b=SQ1KV4Ef2K1ALJpMrxtJH8Y+H3hRJa922zdfzx5woN4S9FO+5hwrtqAyVxPKGShxT8 w6iRryQEGYW0wFy3Nk/OSXRMOPfI3xG4LPo0mv9XQPbcd+FZzB3Kzkdbi1g2+Y0815a9 zJ/+xe8Ftl9oc91ZAspktksNIV0K7t8sQLxoe4Xdh5dLhTQ4Jr41cStBTnVmABVNigSt 0nbp090Nd/v82UD4PTZ0WNpemvGi+WNakzc0iW3CqLaFOzxBPks8hDRufR7UWMlkDKps Qsx4hzuSvjQQbU/1hgo9MkCdyzKnqku1UNEp37JpKbVxkFOVtLYiTxRtM5JgE07exOqj FEiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722643074; x=1723247874; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hxMMYdUIWV7BpRLm7ZCMIQipXwTZjxzuoSHO0vQ0wkg=; b=VWblmrtNVf0TxG4r3U73Wh/KRguYIJjpeky7H/DWkmEdFm+EcDThKGmES+HukniUUM qu51ADmezY3VPoDdb3wgFdXIZEr8UegP/8eOgHKssPfVTHB3Qlfq3inNCGMFzt10rASW q/hO/dwz/1tZ0WuahdPcD7HVNpV6EGlVZ6Vh4MS16/pXzZEXDfKD+4y9BT8bpmPkvBuw 8FcFBlejlJydujuAaMjhYFLWCGa92ZJgofMTojNyzEUOv/OQfjQf2i0yX38DnPe8Ptcf lTYaNvPLu2S53EO7OvXu8S1PBBFfcSzO6u2kz7Y2TOvZByMYPA9KAXf4C32bsEFAd3fS xo1g== X-Gm-Message-State: AOJu0YxFuiYT1YNsaAlqn3NfBHmuFurgbBWKdFkKqHstv9/PJGb2mhhZ z2OamCD9+4HzxITGATGhpqkn9Oo0WmCf1858PVRlhced+JNegSpFnL/wpJFSKV41mUP7rZl1BFN fPTI= X-Google-Smtp-Source: AGHT+IGOtmJw+WDFJLDwZQOmXBDlkxuSSUI+xcUIY8OIa5mLiv99XnDwXo+CCxGno1/WCschjBcdRg== X-Received: by 2002:a05:6602:641f:b0:7f7:e273:a97d with SMTP id ca18e2360f4ac-81fd437a1d5mr638006239f.9.1722643074290; Fri, 02 Aug 2024 16:57:54 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Warner Losh , Kyle Evans , Jessica Clarke Subject: [PATCH 14/17] bsd-user: target_mmap*: change prot to target_prot Date: Fri, 2 Aug 2024 17:56:14 -0600 Message-ID: <20240802235617.7971-15-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240802235617.7971-1-imp@bsdimp.com> References: <20240802235617.7971-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::d29; envelope-from=imp@bsdimp.com; helo=mail-io1-xd29.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1722643193164116600 Content-Type: text/plain; charset="utf-8" Adopt the linux-user convention of using target_prot for passed in protections. no functional change. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index d34075c5c64..2118972f073 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -152,7 +152,7 @@ error: */ static int mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong end, - int prot, int flags, int fd, abi_ulong offset) + int target_prot, int flags, int fd, abi_ulong offset) { abi_ulong real_end, addr; void *host_start; @@ -170,20 +170,20 @@ static int mmap_frag(abi_ulong real_start, =20 if (prot1 =3D=3D 0) { /* no page was there, so we allocate one. See also above. */ - void *p =3D mmap(host_start, qemu_host_page_size, prot, + void *p =3D mmap(host_start, qemu_host_page_size, target_prot, flags | ((fd !=3D -1) ? MAP_ANON : 0), -1, 0); if (p =3D=3D MAP_FAILED) return -1; - prot1 =3D prot; + prot1 =3D target_prot; } prot1 &=3D PAGE_RWX; =20 - prot_new =3D prot | prot1; + prot_new =3D target_prot | prot1; if (fd !=3D -1) { /* msync() won't work here, so we return an error if write is possible while it is a shared mapping */ if ((flags & TARGET_BSD_MAP_FLAGMASK) =3D=3D MAP_SHARED && - (prot & PROT_WRITE)) + (target_prot & PROT_WRITE)) return -1; =20 /* adjust protection to be able to read */ @@ -367,7 +367,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size) } =20 /* 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, off_t offset) { abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_l= en; @@ -377,9 +377,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, qemu_log("mmap: start=3D0x" TARGET_ABI_FMT_lx " len=3D0x" TARGET_ABI_FMT_lx " prot=3D%c%c%c flags=3D", start, len, - prot & PROT_READ ? 'r' : '-', - prot & PROT_WRITE ? 'w' : '-', - prot & PROT_EXEC ? 'x' : '-'); + target_prot & PROT_READ ? 'r' : '-', + target_prot & PROT_WRITE ? 'w' : '-', + target_prot & PROT_EXEC ? 'x' : '-'); if (flags & MAP_ALIGNMENT_MASK) { qemu_log("MAP_ALIGNED(%u) ", (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); @@ -416,13 +416,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, goto fail; } if (flags & MAP_STACK) { - if ((fd !=3D -1) || ((prot & (PROT_READ | PROT_WRITE)) !=3D - (PROT_READ | PROT_WRITE))) { + if (fd !=3D -1 || + ((target_prot & (PROT_READ | PROT_WRITE)) !=3D + (PROT_READ | PROT_WRITE))) { errno =3D EINVAL; goto fail; } } - if ((flags & MAP_GUARD) && (prot !=3D PROT_NONE || fd !=3D -1 || + if ((flags & MAP_GUARD) && (target_prot !=3D PROT_NONE || fd !=3D -1 || offset !=3D 0 || (flags & (MAP_SHARED | MAP_PRIVATE | /* MAP_PREFAULT | */ /* MAP_PREFAULT not in mman.h */ MAP_PREFAULT_READ | MAP_ANON | MAP_STACK)) !=3D 0)) { @@ -512,14 +513,14 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, * especially important if qemu_host_page_size > * qemu_real_host_page_size */ - p =3D mmap(g2h_untagged(start), host_len, prot, + p =3D mmap(g2h_untagged(start), host_len, target_prot, flags | MAP_FIXED | ((fd !=3D -1) ? MAP_ANON : 0), -1, 0); if (p =3D=3D MAP_FAILED) goto fail; /* update start so that it points to the file position at 'offset'= */ host_start =3D (unsigned long)p; if (fd !=3D -1) { - p =3D mmap(g2h_untagged(start), len, prot, + p =3D mmap(g2h_untagged(start), len, target_prot, flags | MAP_FIXED, fd, host_offset); if (p =3D=3D MAP_FAILED) { munmap(g2h_untagged(start), host_len); @@ -557,11 +558,11 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, * possible while it is a shared mapping */ if ((flags & TARGET_BSD_MAP_FLAGMASK) =3D=3D MAP_SHARED && - (prot & PROT_WRITE)) { + (target_prot & PROT_WRITE)) { errno =3D EINVAL; goto fail; } - retaddr =3D target_mmap(start, len, prot | PROT_WRITE, + retaddr =3D target_mmap(start, len, target_prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0); if (retaddr =3D=3D -1) @@ -569,8 +570,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, if (pread(fd, g2h_untagged(start), len, offset) =3D=3D -1) { goto fail; } - if (!(prot & PROT_WRITE)) { - ret =3D target_mprotect(start, len, prot); + if (!(target_prot & PROT_WRITE)) { + ret =3D target_mprotect(start, len, target_prot); assert(ret =3D=3D 0); } goto the_end; @@ -587,13 +588,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, if (real_end =3D=3D real_start + qemu_host_page_size) { /* one single host page */ ret =3D mmap_frag(real_start, start, end, - prot, flags, fd, offset); + target_prot, flags, fd, offset); if (ret =3D=3D -1) goto fail; goto the_end1; } ret =3D mmap_frag(real_start, start, real_start + qemu_host_pa= ge_size, - prot, flags, fd, offset); + target_prot, flags, fd, offset); if (ret =3D=3D -1) goto fail; real_start +=3D qemu_host_page_size; @@ -602,7 +603,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, if (end < real_end) { ret =3D mmap_frag(real_end - qemu_host_page_size, real_end - qemu_host_page_size, end, - prot, flags, fd, + target_prot, flags, fd, offset + real_end - qemu_host_page_size - star= t); if (ret =3D=3D -1) goto fail; @@ -618,13 +619,13 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, else offset1 =3D offset + real_start - start; p =3D mmap(g2h_untagged(real_start), real_end - real_start, - prot, flags, fd, offset1); + target_prot, flags, fd, offset1); if (p =3D=3D MAP_FAILED) goto fail; } } the_end1: - page_set_flags(start, start + len - 1, prot | PAGE_VALID); + page_set_flags(start, start + len - 1, target_prot | PAGE_VALID); the_end: #ifdef DEBUG_MMAP printf("ret=3D0x" TARGET_ABI_FMT_lx "\n", start); --=20 2.45.1