From nobody Tue Feb 10 23:01:13 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=1681233150; cv=none; d=zohomail.com; s=zohoarc; b=AcEwbm68qcOhq78iNoqAIkqETby/PxuizkMOpBQvr/DjaxD0b+IBYbeyYlZIfbPyAQhmRKPlGL8P29XUciVxCUWokBlrt8kTp4os8pt0/Kbp/sFuSn7Hadbxwcq5m0T+/7zTi4OxaxKG6zHhYKh7jlWA/2KlNmXrbdzPHK9zfb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681233150; 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=KKhb1NLkZTXMdbuk1c6jApM9kMzNhp0oHnhtXy58THA=; b=ExOcykWrwXt4mW8iS1yQK7e+XMb5l6+YIRi5uiKMMfZT+a1n/pwMHAYva6tm9Yo1uubgunawgiNDZHaJOKkr768uDwA6u+0zVkz7QbwOkPyD6A+Zwmkxue8r5T2LIIhZJnp88wiKxBgJW2RgfkEXD7CTm0XWyoBdR/Rjjg/RvAM= 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 1681233150113643.4369596318433; Tue, 11 Apr 2023 10:12:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmHW2-0003sC-AW; Tue, 11 Apr 2023 13:10:46 -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 1pmHVm-0003pD-OH for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:30 -0400 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmHVj-00067C-9K for qemu-devel@nongnu.org; Tue, 11 Apr 2023 13:10:29 -0400 Received: by mail-il1-x12f.google.com with SMTP id o12so22672328ilh.13 for ; Tue, 11 Apr 2023 10:10:26 -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 d36-20020a0285a7000000b0040b11b7ef54sm4140942jai.39.2023.04.11.10.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 10:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1681233025; 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=KKhb1NLkZTXMdbuk1c6jApM9kMzNhp0oHnhtXy58THA=; b=duLxO/6mnxFuXt9QUHXrkX09gWmPaPOx6dGKH4qkNG2kKLHOetaTkGsRNSItc32n56 DG0TWAvCvlNY4Esjt5rZf+/XGzJ+FUyIQ0rqhM2wNPqIhpft8DY3W0l8UhYG/+77xfpL 4/3a/gOGM7xlb1ZEH/XZfQa55qfVadhyc7vv70+bw0feS3feHqWebtrGDusZ4GMdIu4d ybe+mTSSyAU2y9WAbJH9/YiJurYpTxHiSda8jmoyc8AYgXflKK8gTYBZWItzZZyZDgpx LAk+cLO3Z0rBylCXABuHBF33ThZnVb98/ebJfjgNksC+et8V+QxY6cUUzfZ9XCFs0+K5 e2DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681233025; 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=KKhb1NLkZTXMdbuk1c6jApM9kMzNhp0oHnhtXy58THA=; b=Xz3eMUtLCt0RbV6Dg6eydjsywHl0r1b+bogthN7iwSyMKL2G46gRdwovo6Yhsgl9GM ZktEOlsEo03CZS92wa43UK9x1221d/rlkzNOePiuXhSVdhTeJnLjltcD8DAgGMCoqJca jHZuPYBBo27IHuUI9aT4+31r3eaBhhHTYvwNF73pFOoyQ115xl9ULwhZn6n+nPKPbUs6 mphKNpqjlZXMse4vaANDD056L/g+bbQZ98SYmweC/deQSi5t6m2Iz67SjVaGAmVLRIqy UCjjzAuSR6stGgh4Ru2XuUPqFe1PJnkhdcQk0u7rCOqWlDoWO1QcmSvW1eUEtzXZUUyN z/CQ== X-Gm-Message-State: AAQBX9c7Rjpowk5GtHTFG6sC6wnUfDatGjg6X8gP0ROLXhfdr+Q6xchZ DNx39Z3eOFQiSLCfteWHlDMutTiqBhRiD5aThfo= X-Google-Smtp-Source: AKy350axTqMQ0K2G5U6GOnJsiRR8u+BCFzoGKavw6Qhmg41enebzfmOtRFucGaNbfkzkfH8nJ7ebCQ== X-Received: by 2002:a92:dc41:0:b0:326:2d3a:c770 with SMTP id x1-20020a92dc41000000b003262d3ac770mr9841257ilq.26.1681233025193; Tue, 11 Apr 2023 10:10:25 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: ryoon@netbsd.org, kevans@freebsd.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , riastradh@netbsd.org, brad@comstyle.com, reinoud@netbsd.org, jrtc27@jrtc27.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Warner Losh , Richard Henderson Subject: [PATCH v3 03/20] bsd-user: Cleanup style. Date: Tue, 11 Apr 2023 11:09:38 -0600 Message-Id: <20230411170955.17358-4-imp@bsdimp.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230411170955.17358-1-imp@bsdimp.com> References: <20230411170955.17358-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::12f; envelope-from=imp@bsdimp.com; helo=mail-il1-x12f.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: 1681233151096100001 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 2d91e8e8826..d0ade1b52f3 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -59,17 +59,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. */ @@ -83,15 +85,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; @@ -110,8 +115,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) { @@ -121,16 +127,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(); @@ -175,31 +183,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)= { @@ -207,8 +221,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); @@ -560,8 +575,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) { @@ -610,8 +626,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; } @@ -634,14 +651,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 */ @@ -650,8 +669,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 @@ -659,14 +679,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: @@ -736,11 +758,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; @@ -758,16 +782,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; @@ -791,14 +817,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