From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mx.groups.io with SMTP id smtpd.web11.4491.1669069983343080346 for ; Mon, 21 Nov 2022 14:33:03 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=DRihU87z; spf=pass (domain: gmail.com, ip: 209.85.214.181, mailfrom: pedro.falcato@gmail.com) Received: by mail-pl1-f181.google.com with SMTP id w4so3097779plp.1 for ; Mon, 21 Nov 2022 14:33:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=CkYbfW8uQFDWbvb5WkDQdbuDzK1TUKgNbpV1/mFORN8=; b=DRihU87zS/pCNeMC8G3CY2ess6/ZfYMp69lN7ohTqxROORRvy/+JRm/3+hArg5i/TC M051IzPbunQhJ8fF5jMC+ttH3c1Ez8UD9WmuFIdgSt5Y+uOfio0qpVqiY73f6n78Fok6 7srMpNUf/qA36lI5t+iKJSz1pe6QNv6YdEu0wuK0n5aCE8mYsXEHUngqL4oVPl/8RhMS Au8EJt0P3yPnNKyF5wbb9aSp2JtgoPbPzzf/L/vAviAGUU3P+PfizGy0bpjQZivKMkmX 5W+RC9DXTwl/5U2nU9ZgHDofIx8Jd0idYrf7FtG3KKa83O7GSGKDrVbAgyom8+sbncOt euIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CkYbfW8uQFDWbvb5WkDQdbuDzK1TUKgNbpV1/mFORN8=; b=D5SIwZKFpOr0WpJz3HnQAPJemPGxrinOesr3bXLEnGLopc4wJKwAiBoDLOn5oBXJdh Jjh/taFrhVpuGkpX+FmMZMxasv4ekgl+jqr24mlCiOR1EhS0x2Z124mrGLZNXLGNOjg6 8DRElXhISqzkplmwNQd/B86Pl5TS+ZZf8amR5djOz/dWTJSaeX8WKnbag8bPruPe0DsN LQsOMppTfPhOaVOfii/IrPM0zvs73J6JlZhQTfH0ktTDul/i69n4bgVvsuIRTiF9ADit W3/nPNQmg6Jz198sDPuFfQBxo+J/CbhDoCk6BxwZpZLoTqdRwYaCM2PudUzXXcoYSYD1 3mFg== X-Gm-Message-State: ANoB5pnQzNiyVhMFe5Yf0/4h/jp00XTa9a+hpzqkZ+sDVOCRjANo0UBm 3qHm7UyvTT0DKs51GTRtwbJscB97jG7X9FSg6i35/Mz6ago= X-Google-Smtp-Source: AA0mqf6zOQhCE+hkScKG1PzKDiYNxYfZvsRZ+LBK/mtUzJ0CyaXGImiMShX21ancRxpMQ+aXRvXi7xNbjOTj25glwmk= X-Received: by 2002:a17:902:ce8b:b0:186:a8c1:884f with SMTP id f11-20020a170902ce8b00b00186a8c1884fmr1481837plg.25.1669069982479; Mon, 21 Nov 2022 14:33:02 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "Pedro Falcato" Date: Mon, 21 Nov 2022 22:32:51 +0000 Message-ID: Subject: Re: [edk2-devel] EmulatorPkg: fixes for NetBSD compilation To: devel@edk2.groups.io, tlaronde@polynum.com Content-Type: multipart/alternative; boundary="000000000000693bfe05ee02a356" --000000000000693bfe05ee02a356 Content-Type: text/plain; charset="UTF-8" On Mon, Nov 21, 2022 at 9:21 PM wrote: > diff --git a/EmulatorPkg/Unix/Host/BlockIo.c > b/EmulatorPkg/Unix/Host/BlockIo.c > index cf2d6b4cda..c0c694be55 100644 > --- a/EmulatorPkg/Unix/Host/BlockIo.c > +++ b/EmulatorPkg/Unix/Host/BlockIo.c > @@ -133,6 +133,20 @@ EmuBlockIoOpenDevice ( > > ioctl (Private->fd, DKIOCGETMAXBLOCKCOUNTWRITE, > &Private->Media->OptimalTransferLengthGranularity); > } > + #elif _NETBSD_SOURCE > + { > + u_int BlockSize; > Hi, Again, thanks for the patches. Please send them in the way I kind of described in my other reply. s/u_int/UINT/ + off_t DiskSize; > I think this off_t is fine, per the other off_t usages, I don't know if the maintainers agree. > + > + if (ioctl (Private->fd, DIOCGSECTORSIZE, &BlockSize) == 0) { > + Private->Media->BlockSize = BlockSize; > + } > + > + if (ioctl (Private->fd, DIOCGMEDIASIZE, &DiskSize) == 0) { > + Private->NumberOfBlocks = DivU64x32 (DiskSize, > (UINT32)BlockSize); > + Private->Media->LastBlock = Private->NumberOfBlocks - 1; > + } > + } > #else > { > size_t BlockSize; > > diff --git a/EmulatorPkg/Unix/Host/Host.c b/EmulatorPkg/Unix/Host/Host.c > index 38c01c84af..c505300129 100644 > --- a/EmulatorPkg/Unix/Host/Host.c > +++ b/EmulatorPkg/Unix/Host/Host.c > @@ -12,6 +12,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #define MAP_ANONYMOUS MAP_ANON > #endif > > +#ifdef _NETBSD_SOURCE > +#define MAP_ANON_FD_ (-1) > +#else > +#define MAP_ANON_FD_ (0) > +#endif > Would there be a harm if we just passed -1 everywhere? It's a bit odd NetBSD explicitly requires this, but AFAIK implementations either EINVAL on fd != -1 or take whatever since it's anon. The main implementations (Linux, FreeBSD, NetBSD, OpenBSD, macOS) seem to agree that passing -1 should be safe everywhere (in fact, it's pretty funny that all BSD-derived implementations agree with the fd = -1 thing, but I digress). The rest of the patch looks mostly ok to me, but then again, I'm not a maintainer for this. Thanks, Pedro --000000000000693bfe05ee02a356 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Nov 21, 2022 at 9:21 PM <tlaronde@polynum.com> wrote:
diff --git a/EmulatorPkg/Unix/Host/BlockIo.c b/EmulatorPkg/Unix/Host/Blo= ckIo.c
index cf2d6b4cda..c0c694be55 100644
--- a/EmulatorPkg/Unix/Host/BlockIo.c
+++ b/EmulatorPkg/Unix/Host/BlockIo.c
@@ -133,6 +133,20 @@ EmuBlockIoOpenDevice (

=C2=A0 =C2=A0 =C2=A0 =C2=A0ioctl (Private->fd, DKIOCGETMAXBLOCKCOUNTWRIT= E, &Private->Media->OptimalTransferLengthGranularity);
=C2=A0 =C2=A0 =C2=A0}
+ #elif _NETBSD_SOURCE
+=C2=A0 =C2=A0 {
+=C2=A0 =C2=A0 =C2=A0 u_int=C2=A0 BlockSize;
Hi,
=

Again, thanks for the patches. Please send them in the = way I kind of described in my other reply.

s/u= _int/UINT/

+=C2=A0 =C2=A0 =C2=A0 off_t=C2=A0 DiskSize;
I think th= is off_t is fine, per the other off_t usages, I don't know if the maint= ainers agree.=C2=A0
+
+=C2=A0 =C2=A0 =C2=A0 if (ioctl (Private->fd,=C2=A0 DIOCGSECTORSIZE, &am= p;BlockSize) =3D=3D 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Private->Media->BlockSize =3D BlockSize;=
+=C2=A0 =C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 =C2=A0 if (ioctl (Private->fd, DIOCGMEDIASIZE, &DiskS= ize) =3D=3D 0) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Private->NumberOfBlocks=C2=A0 =C2=A0=3D Div= U64x32 (DiskSize, (UINT32)BlockSize);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Private->Media->LastBlock =3D Private-&g= t;NumberOfBlocks - 1;
+=C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
=C2=A0 #else
=C2=A0 =C2=A0 =C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0size_t=C2=A0 BlockSize;
=C2= =A0
diff --git a/EmulatorPkg/Unix/Host/Host.c b/EmulatorPkg/Unix/Host/Host.c index 38c01c84af..c505300129 100644
--- a/EmulatorPkg/Unix/Host/Host.c
+++ b/EmulatorPkg/Unix/Host/Host.c
@@ -12,6 +12,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
=C2=A0#define MAP_ANONYMOUS=C2=A0 MAP_ANON
=C2=A0#endif

+#ifdef _NETBSD_SOURCE
+#define MAP_ANON_FD_ (-1)
+#else
+#define MAP_ANON_FD_ (0)
+#endif
Would there be a harm if we just passed -1 eve= rywhere? It's a bit odd NetBSD explicitly requires this, but AFAIK impl= ementations
either EINVAL on fd !=3D -1 or take whatever since it= 's anon. The main implementations (Linux, FreeBSD, NetBSD, OpenBSD, mac= OS) seem to
agree that passing -1 should be safe everywhere (in f= act, it's pretty funny that all BSD-derived implementations agree with = the fd =3D -1 thing, but I digress).

The rest of t= he patch looks mostly ok to me, but then again, I'm not a maintainer fo= r this.

Thanks,
Pedro
--000000000000693bfe05ee02a356--