public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Pedro Falcato" <pedro.falcato@gmail.com>
To: tlaronde@polynum.com
Cc: devel@edk2.groups.io, Andrew Fish <afish@apple.com>,
	Ray Ni <ray.ni@intel.com>
Subject: Re: PING [PATCH 1/1 v2] EmulatorPkg: fixes for NetBSD
Date: Thu, 5 Jan 2023 23:40:43 +0000	[thread overview]
Message-ID: <CAKbZUD1KD3t00Zqu-WhQoEJaiKB8J7s+m3z8STQy_ipBTeDfwg@mail.gmail.com> (raw)
In-Reply-To: <Y7a5lN0OsmMCZJ2v@polynum.com>

[-- Attachment #1: Type: text/plain, Size: 5390 bytes --]

On Thu, Jan 5, 2023 at 11:50 AM <tlaronde@polynum.com> wrote:

> Hello,
>
> Ping'ing for this patch sent on November 2022.
>
> The patch is trivial. Can someone review it or eventually merge it if OK?
>
> TIA,
> --
>         Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
>                      http://www.kergis.com/
>                     http://kertex.kergis.com/
> Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C
>
>
>
> ---------- Forwarded message ----------
> From: tlaronde@polynum.com
> To: devel@edk2.groups.io
> Cc: Andrew Fish <afish@apple.com>, Ray Ni <ray.ni@intel.com>, Pedro
> Falcato <pedro.falcato@gmail.com>
> Bcc:
> Date: Thu, 24 Nov 2022 15:46:59 +0100
> Subject: [edk2-devel] [PATCH 1/1 v2] EmulatorPkg: fixes for NetBSD
> Signed-off-by: Thierry Laronde <tlaronde@polynum.com>
>
> Fixes for compilation on NetBSD.
>
> ---
>  EmulatorPkg/Unix/Host/BlockIo.c | 16 +++++++++++++++-
>  EmulatorPkg/Unix/Host/Host.c    |  7 +++++--
>  EmulatorPkg/Unix/Host/Host.h    |  7 ++++++-
>  3 files changed, 26 insertions(+), 4 deletions(-)
>
> diff --git a/EmulatorPkg/Unix/Host/BlockIo.c
> b/EmulatorPkg/Unix/Host/BlockIo.c
> index cf2d6b4cda..57b4c8d3be 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
> +    {
> +      UINTN  BlockSize;
> +      off_t  DiskSize;
> +
> +      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;
> @@ -154,7 +168,7 @@ EmuBlockIoOpenDevice (
>      Private->Media->LastBlock = Private->NumberOfBlocks - 1;
>
>      if (fstatfs (Private->fd, &buf) == 0) {
> - #if __APPLE__
> + #if __APPLE__ || _NETBSD_SOURCE
>
Isn't this the wrong test? Shouldn't you test for __NetBSD__ instead? AIUI
_NETBSD_SOURCE is just a feature test macro like _GNU_SOURCE, right?

>        Private->Media->OptimalTransferLengthGranularity =
> buf.f_iosize/buf.f_bsize;
>   #else
>        Private->Media->OptimalTransferLengthGranularity =
> buf.f_bsize/buf.f_bsize;
> diff --git a/EmulatorPkg/Unix/Host/Host.c b/EmulatorPkg/Unix/Host/Host.c
> index 38c01c84af..1700a4b60f 100644
> --- a/EmulatorPkg/Unix/Host/Host.c
> +++ b/EmulatorPkg/Unix/Host/Host.c
> @@ -12,6 +12,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #define MAP_ANONYMOUS  MAP_ANON
>  #endif
>
> +#define MAP_ANON_FD_ (-1)
>
Again, I don't think you need a define for this. At most you could just
stick a -1 down there with a comment like:
// We're required to pass -1 for anonymous mappings on BSD-like systems

> +
>  //
>  // Globals
>  //
> @@ -187,7 +189,7 @@ main (
>    //
>    InitialStackMemorySize = STACK_SIZE;
>    InitialStackMemory     = (UINTN)MapMemory (
> -                                    0,
> +                                    MAP_ANON_FD_,
>                                      (UINT32)InitialStackMemorySize,
>                                      PROT_READ | PROT_WRITE | PROT_EXEC,
>                                      MAP_ANONYMOUS | MAP_PRIVATE
> @@ -348,6 +350,7 @@ MapMemory (
>    while ((!isAligned) && (base != 0)) {
>      res = mmap ((void *)base, length, prot, flags, fd, 0);
>      if (res == MAP_FAILED) {
> +      perror("MapMemory");
>        return NULL;
>      }
>
> @@ -640,7 +643,7 @@ SecUnixPeiAutoScan (
>
>    *MemoryBase = 0;
>    res         = MapMemory (
> -                  0,
> +                  MAP_ANON_FD_,
>                    gSystemMemory[Index].Size,
>                    PROT_READ | PROT_WRITE | PROT_EXEC,
>                    MAP_PRIVATE | MAP_ANONYMOUS
> diff --git a/EmulatorPkg/Unix/Host/Host.h b/EmulatorPkg/Unix/Host/Host.h
> index 0c81cdfc01..0de925adaf 100644
> --- a/EmulatorPkg/Unix/Host/Host.h
> +++ b/EmulatorPkg/Unix/Host/Host.h
> @@ -31,6 +31,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>
>  #if __CYGWIN__
>    #include <sys/dirent.h>
> +#elif _NETBSD_SOURCE
>
Same as above.

> +  #include <dirent.h>
>  #else
>    #include <sys/dir.h>
>  #endif
> @@ -55,7 +57,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <net/if.h>
>  #include <ifaddrs.h>
>
> -#ifdef __APPLE__
> +#if defined(__APPLE__)
>
   #include <net/if_dl.h>
>    #include <net/bpf.h>
>    #include <sys/param.h>
> @@ -65,6 +67,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>    #ifndef _Bool
>  #define _Bool  char  // for clang debug
>    #endif
> +#elif defined(_NETBSD_SOURCE)
> +  #define statfs statvfs
> +  #define fstatfs fstatvfs
>  #else
>    #include <termio.h>
>    #include <sys/vfs.h>
> --
> 2.34.1
>
> --
>         Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
>                      http://www.kergis.com/
>                     http://kertex.kergis.com/
> Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C
>

I can give you my Ack or RB after this, but FWIW I'm not a maintainer for
EmulatorPkg so you'll still need appropriate reviews from the package
mainainers.

-- 
Pedro

[-- Attachment #2: Type: text/html, Size: 7935 bytes --]

  reply	other threads:[~2023-01-05 23:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-05 11:50 PING [PATCH 1/1 v2] EmulatorPkg: fixes for NetBSD tlaronde
2023-01-05 23:40 ` Pedro Falcato [this message]
2023-01-06 18:01   ` tlaronde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKbZUD1KD3t00Zqu-WhQoEJaiKB8J7s+m3z8STQy_ipBTeDfwg@mail.gmail.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox