From nobody Mon Feb 9 08:29:41 2026 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=1680730646; cv=none; d=zohomail.com; s=zohoarc; b=J/0OmI0S1EcimnRnrWA3SVFiWFNC4QSaBigMV2fT+LpjgDas8xlDcHcWmj1HGj/4ULfRpVD+Ew6rZu5yYcaITCpcBG2jJyKT5+wocbPyESsws/Qf9JFFTkPMKKUf5b4NMLmFae7gr5Smn2+6F7aNV1cP6bi+f1BLy/UxO45HN88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680730646; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fdI4FOHX2F3suDBHi4XUkEMxaX1KjSb9ZI97Vo0+ATM=; b=Ug2Qeprxc7siW1+Vo37zhvHcPGITOjYjRLsoF6B7lBmvJfNoE9U9yZJ7tvRFm+6iiauArQpJb25D9vjgD+dy14aHDJ+1IK8nwS+HoxdI6Wy9BkvMJ9k1tSA3tPDFZ3gBnUBcGIuOt3ETuIM7lE6yi7g5ov3TKm+rYfd4vfxHW4c= 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 1680730646007627.8634482103652; Wed, 5 Apr 2023 14:37:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pkAoF-0005OH-T3; Wed, 05 Apr 2023 17:36:51 -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 1pkAnw-0005Hn-WD for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:34 -0400 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pkAnu-0005aG-GD for qemu-devel@nongnu.org; Wed, 05 Apr 2023 17:36:32 -0400 Received: by mail-il1-x129.google.com with SMTP id n1so18792364ili.10 for ; Wed, 05 Apr 2023 14:36:30 -0700 (PDT) Received: from dune.bsdimp.com (c-71-237-47-177.hsd1.co.comcast.net. [71.237.47.177]) by smtp.gmail.com with ESMTPSA id i18-20020a926d12000000b003261b6acc8asm4110473ilc.79.2023.04.05.14.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 14:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680730589; 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=fdI4FOHX2F3suDBHi4XUkEMxaX1KjSb9ZI97Vo0+ATM=; b=JW9gyOITO/oP91IUVq7Cebd9akgIO7eyLFUDb8doRmA7OOczMD2qyGtF+L/45JqDBt I7+1YyMrHEoVt3MU29k4rX5OKMa6gTCBAsGXdbmRMgVIE+55BbN/yT75WrZP63FK/yZg zYkk6heAh3UgrkPM2yUePg8I/RFcOjE5XprwhUMS8rAq0A9KWGuCb8pMgVi49FZvYTwZ jz0cuRbibwlsjSa2ml3oT6oIsYjxwXmRsx32zLB61ZED/r45tR6P5p+08ZG9gSJofBLF bWYPSQcxcmlIrqCaBVSflKH0ivpD7xjBF9x/v1sb1TaLkJWwzfelGUu0RQBrj5DWMZyF 84hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680730589; 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=fdI4FOHX2F3suDBHi4XUkEMxaX1KjSb9ZI97Vo0+ATM=; b=g3gKpRJAd/vIS16+40CZtTWXMiEULwCoSzyCP0E5zbAmrPvrXJwjLfURaQjsX8xJhd 2K4etUnGQDwmCKkXVZfTZI6/iyt+rpOLpv6mYieYf46wmH19OKBQjxoKX28E9G3HEcCU eGS4u+1t8OEEz62yDuLnJOctKZkIjHyBewBzFr1Vntz77O/xAYt9bsVCkj0lwp6yoStS AVRdpzoetSsBKLq2dVv1HTi3WS2XZ0HzT+eodQvzckwSq0PiC5gRfvXki4A4Uig+T5uH 4C6goRIlLd2tY2MS4JkuIHsaaAy6YYTmGjVtksuZ0taZHVa0jSYasyJPOv62Kqo8QRef Ypiw== X-Gm-Message-State: AAQBX9cn+Y10i/NAwrVPmW2iPReyrNnqK1qNO2EkK+zwbDas1FLLVPY7 ZVzYYFHQFAPZGPj4Xspq/EB/D2Qo2eOSuQBOjXM= X-Google-Smtp-Source: AKy350aXJVuRa3FLtDpjs+2+8Tbo4gW/XduyGpoG/PMv2J7Q1Ety9z7srrOREH1uM2M1IPLAqqLKJA== X-Received: by 2002:a05:6e02:2162:b0:326:45fd:3ea1 with SMTP id s2-20020a056e02216200b0032645fd3ea1mr3035715ilv.13.1680730589036; Wed, 05 Apr 2023 14:36:29 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: reinoud@netbsd.org, riastradh@netbsd.org, ryoon@netbsd.org, jrtc27@jrtc27.com, Warner Losh , kevans@freebsd.org, Brad Smith Subject: [PATCH 03/16] bsd-user: Cleanup style. Date: Wed, 5 Apr 2023 15:35:59 -0600 Message-Id: <20230405213612.15942-4-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405213612.15942-1-imp@bsdimp.com> References: <20230405213612.15942-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::129; envelope-from=imp@bsdimp.com; helo=mail-il1-x129.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.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1680730646775100003 Content-Type: text/plain; charset="utf-8" The only diffs between bsd-user fork and qemu upstream is style. Make mmap.c pass checkpatch.pl. Signed-off-by: Warner Losh Acked-by: Richard Henderson --- bsd-user/mmap.c | 91 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index f732a6f6f2b..5f60efb3c5d 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -45,17 +45,19 @@ bool have_mmap_lock(void) /* Grab lock to make sure things are in a consistent state after fork(). = */ void mmap_fork_start(void) { - if (mmap_lock_count) + if (mmap_lock_count) { abort(); + } pthread_mutex_lock(&mmap_mutex); } =20 void mmap_fork_end(int child) { - if (child) + if (child) { pthread_mutex_init(&mmap_mutex, NULL); - else + } else { pthread_mutex_unlock(&mmap_mutex); + } } =20 /* NOTE: all the constants are the HOST ones, but addresses are target. */ @@ -69,15 +71,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, int= prot) prot & PROT_READ ? 'r' : '-', prot & PROT_WRITE ? 'w' : '-', prot & PROT_EXEC ? 'x' : '-'); - if ((start & ~TARGET_PAGE_MASK) !=3D 0) + if ((start & ~TARGET_PAGE_MASK) !=3D 0) { return -EINVAL; + } len =3D TARGET_PAGE_ALIGN(len); end =3D start + len; - if (end < start) + if (end < start) { return -EINVAL; + } prot &=3D PROT_READ | PROT_WRITE | PROT_EXEC; - if (len =3D=3D 0) + if (len =3D=3D 0) { return 0; + } =20 mmap_lock(); host_start =3D start & qemu_host_page_mask; @@ -96,8 +101,9 @@ int target_mprotect(abi_ulong start, abi_ulong len, int = prot) } ret =3D mprotect(g2h_untagged(host_start), qemu_host_page_size, prot1 & PAGE_BITS); - if (ret !=3D 0) + if (ret !=3D 0) { goto error; + } host_start +=3D qemu_host_page_size; } if (end < host_end) { @@ -107,16 +113,18 @@ int target_mprotect(abi_ulong start, abi_ulong len, i= nt prot) } ret =3D mprotect(g2h_untagged(host_end - qemu_host_page_size), qemu_host_page_size, prot1 & PAGE_BITS); - if (ret !=3D 0) + if (ret !=3D 0) { goto error; + } host_end -=3D qemu_host_page_size; } =20 /* handle the pages in the middle */ if (host_start < host_end) { ret =3D mprotect(g2h_untagged(host_start), host_end - host_start, = prot); - if (ret !=3D 0) + if (ret !=3D 0) { goto error; + } } page_set_flags(start, start + len, prot | PAGE_VALID); mmap_unlock(); @@ -161,31 +169,37 @@ static int mmap_frag(abi_ulong real_start, /* get the protection of the target pages outside the mapping */ prot1 =3D 0; for (addr =3D real_start; addr < real_end; addr++) { - if (addr < start || addr >=3D end) + if (addr < start || addr >=3D end) { prot1 |=3D page_get_flags(addr); + } } =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, flags | ((fd !=3D -1) ? MAP_ANON : 0), -1, 0); - if (p =3D=3D MAP_FAILED) + if (p =3D=3D MAP_FAILED) { return -1; + } prot1 =3D prot; } prot1 &=3D PAGE_BITS; =20 prot_new =3D 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 */ + /* + * 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)) + (prot & PROT_WRITE)) { return -1; + } =20 /* adjust protection to be able to read */ - if (!(prot1 & PROT_WRITE)) + if (!(prot1 & PROT_WRITE)) { mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); + } =20 /* read the corresponding file data */ if (pread(fd, g2h_untagged(start), end - start, offset) =3D=3D -1)= { @@ -193,8 +207,9 @@ static int mmap_frag(abi_ulong real_start, } =20 /* put final protection */ - if (prot_new !=3D (prot1 | PROT_WRITE)) + if (prot_new !=3D (prot1 | PROT_WRITE)) { mprotect(host_start, qemu_host_page_size, prot_new); + } } else { if (prot_new !=3D prot1) { mprotect(host_start, qemu_host_page_size, prot_new); @@ -554,8 +569,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, */ p =3D mmap(g2h_untagged(start), host_len, prot, flags | MAP_FIXED | ((fd !=3D -1) ? MAP_ANON : 0), -1, 0); - if (p =3D=3D MAP_FAILED) + 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) { @@ -604,8 +620,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, retaddr =3D target_mmap(start, len, prot | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0); - if (retaddr =3D=3D -1) + if (retaddr =3D=3D -1) { goto fail; + } if (pread(fd, g2h_untagged(start), len, offset) =3D=3D -1) { goto fail; } @@ -630,14 +647,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, /* one single host page */ ret =3D mmap_frag(real_start, start, end, prot, flags, fd, offset); - if (ret =3D=3D -1) + 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); - if (ret =3D=3D -1) + if (ret =3D=3D -1) { goto fail; + } real_start +=3D qemu_host_page_size; } /* handle the end of the mapping */ @@ -646,8 +665,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, real_end - qemu_host_page_size, end, prot, flags, fd, offset + real_end - qemu_host_page_size - star= t); - if (ret =3D=3D -1) + if (ret =3D=3D -1) { goto fail; + } real_end -=3D qemu_host_page_size; } =20 @@ -655,14 +675,16 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, if (real_start < real_end) { void *p; unsigned long offset1; - if (flags & MAP_ANON) + if (flags & MAP_ANON) { offset1 =3D 0; - else + } else { offset1 =3D offset + real_start - start; + } p =3D mmap(g2h_untagged(real_start), real_end - real_start, prot, flags, fd, offset1); - if (p =3D=3D MAP_FAILED) + if (p =3D=3D MAP_FAILED) { goto fail; + } } } the_end1: @@ -732,11 +754,13 @@ int target_munmap(abi_ulong start, abi_ulong len) TARGET_ABI_FMT_lx "\n", start, len); #endif - if (start & ~TARGET_PAGE_MASK) + if (start & ~TARGET_PAGE_MASK) { return -EINVAL; + } len =3D TARGET_PAGE_ALIGN(len); - if (len =3D=3D 0) + if (len =3D=3D 0) { return -EINVAL; + } mmap_lock(); end =3D start + len; real_start =3D start & qemu_host_page_mask; @@ -754,16 +778,18 @@ int target_munmap(abi_ulong start, abi_ulong len) } end =3D real_end; } - if (prot !=3D 0) + if (prot !=3D 0) { real_start +=3D qemu_host_page_size; + } } if (end < real_end) { prot =3D 0; for (addr =3D end; addr < real_end; addr +=3D TARGET_PAGE_SIZE) { prot |=3D page_get_flags(addr); } - if (prot !=3D 0) + if (prot !=3D 0) { real_end -=3D qemu_host_page_size; + } } =20 ret =3D 0; @@ -787,14 +813,17 @@ int target_msync(abi_ulong start, abi_ulong len, int = flags) { abi_ulong end; =20 - if (start & ~TARGET_PAGE_MASK) + if (start & ~TARGET_PAGE_MASK) { return -EINVAL; + } len =3D TARGET_PAGE_ALIGN(len); end =3D start + len; - if (end < start) + if (end < start) { return -EINVAL; - if (end =3D=3D start) + } + if (end =3D=3D start) { return 0; + } =20 start &=3D qemu_host_page_mask; return msync(g2h_untagged(start), end - start, flags); --=20 2.40.0