public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/1 v3] EmulatorPkg: fixes for NetBSD compilation
@ 2023-01-09 17:03 tlaronde
  2023-01-27 17:30 ` Pedro Falcato
       [not found] ` <173E3AAD68434D4F.686@groups.io>
  0 siblings, 2 replies; 3+ messages in thread
From: tlaronde @ 2023-01-09 17:03 UTC (permalink / raw)
  To: devel; +Cc: Andrew Fish, Ray Ni, Pedro Falcato

EmulatorPkg: fixes for NetBSD compilation.

Note: generated against today (2023-01-09) master.

v3:
- Macro __NetBSD__ used instead of lower level _NETBSD_SOURCE;
- The required fd value (-1) for mmap(3) under *BSD is given as is
  with a comment indicating why this particular value for MAP_ANON;
- Supplementary: mapFd0() is using mmap(3) also, with MAP_ANON, and the
  fd was not corrected as above in the previous versions of the patch.

>From 708079397bb35eb50cfb12f7d5f2c66b64177a76 Mon Sep 17 00:00:00 2001
From: Thierry LARONDE <tlaronde@polynum.com>
Date: Mon, 9 Jan 2023 17:49:59 +0100
Subject: [PATCH] EmulatorPkg: fixes for NetBSD compilation

Signed-off-by: Thierry LARONDE <tlaronde@polynum.com>
---
 EmulatorPkg/Unix/Host/BlockIo.c | 16 +++++++++++++++-
 EmulatorPkg/Unix/Host/Host.c    |  7 ++++---
 EmulatorPkg/Unix/Host/Host.h    |  7 ++++++-
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/EmulatorPkg/Unix/Host/BlockIo.c b/EmulatorPkg/Unix/Host/BlockIo.c
index cf2d6b4cda..2eb062b03d 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__
+    {
+      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__
       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 1f29dd00a3..6a338b81a1 100644
--- a/EmulatorPkg/Unix/Host/Host.c
+++ b/EmulatorPkg/Unix/Host/Host.c
@@ -199,7 +199,7 @@ main (
   //
   InitialStackMemorySize = STACK_SIZE;
   InitialStackMemory     = (UINTN)MapMemory (
-                                    0,
+                                    -1, // This value required by *BSD for MAP_ANON
                                     (UINT32)InitialStackMemorySize,
                                     PROT_READ | PROT_WRITE | PROT_EXEC,
                                     MAP_ANONYMOUS | MAP_PRIVATE
@@ -360,6 +360,7 @@ MapMemory (
   while ((!isAligned) && (base != 0)) {
     res = mmap ((void *)base, length, prot, flags, fd, 0);
     if (res == MAP_FAILED) {
+      perror("MapMemory");
       return NULL;
     }
 
@@ -511,7 +512,7 @@ MapFd0 (
               4096,
               PROT_READ | PROT_WRITE,
               MAP_PRIVATE | MAP_ANONYMOUS,
-              0,
+              -1, // This value required by *BSD for MAP_ANON
               0
               );
     if (res3 != EmuMagicPage) {
@@ -652,7 +653,7 @@ SecUnixPeiAutoScan (
 
   *MemoryBase = 0;
   res         = MapMemory (
-                  0,
+                  -1, // This value required by *BSD for MAP_ANON
                   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..d6b70e8320 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__
+  #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__)
+  #define statfs statvfs
+  #define fstatfs fstatvfs
 #else
   #include <termio.h>
   #include <sys/vfs.h>
-- 
2.39.0

-- 
        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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1 v3] EmulatorPkg: fixes for NetBSD compilation
  2023-01-09 17:03 [PATCH 1/1 v3] EmulatorPkg: fixes for NetBSD compilation tlaronde
@ 2023-01-27 17:30 ` Pedro Falcato
       [not found] ` <173E3AAD68434D4F.686@groups.io>
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Falcato @ 2023-01-27 17:30 UTC (permalink / raw)
  To: tlaronde; +Cc: devel, Andrew Fish, Ray Ni

On Mon, Jan 9, 2023 at 5:03 PM <tlaronde@polynum.com> wrote:
>
> EmulatorPkg: fixes for NetBSD compilation.
>
> Note: generated against today (2023-01-09) master.
>
> v3:
> - Macro __NetBSD__ used instead of lower level _NETBSD_SOURCE;
> - The required fd value (-1) for mmap(3) under *BSD is given as is
>   with a comment indicating why this particular value for MAP_ANON;
> - Supplementary: mapFd0() is using mmap(3) also, with MAP_ANON, and the
>   fd was not corrected as above in the previous versions of the patch.
>
> From 708079397bb35eb50cfb12f7d5f2c66b64177a76 Mon Sep 17 00:00:00 2001
> From: Thierry LARONDE <tlaronde@polynum.com>
> Date: Mon, 9 Jan 2023 17:49:59 +0100
> Subject: [PATCH] EmulatorPkg: fixes for NetBSD compilation
>
> Signed-off-by: Thierry LARONDE <tlaronde@polynum.com>
> ---
>  EmulatorPkg/Unix/Host/BlockIo.c | 16 +++++++++++++++-
>  EmulatorPkg/Unix/Host/Host.c    |  7 ++++---
>  EmulatorPkg/Unix/Host/Host.h    |  7 ++++++-
>  3 files changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/EmulatorPkg/Unix/Host/BlockIo.c b/EmulatorPkg/Unix/Host/BlockIo.c
> index cf2d6b4cda..2eb062b03d 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__
> +    {
> +      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__
>        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 1f29dd00a3..6a338b81a1 100644
> --- a/EmulatorPkg/Unix/Host/Host.c
> +++ b/EmulatorPkg/Unix/Host/Host.c
> @@ -199,7 +199,7 @@ main (
>    //
>    InitialStackMemorySize = STACK_SIZE;
>    InitialStackMemory     = (UINTN)MapMemory (
> -                                    0,
> +                                    -1, // This value required by *BSD for MAP_ANON
>                                      (UINT32)InitialStackMemorySize,
>                                      PROT_READ | PROT_WRITE | PROT_EXEC,
>                                      MAP_ANONYMOUS | MAP_PRIVATE
> @@ -360,6 +360,7 @@ MapMemory (
>    while ((!isAligned) && (base != 0)) {
>      res = mmap ((void *)base, length, prot, flags, fd, 0);
>      if (res == MAP_FAILED) {
> +      perror("MapMemory");
>        return NULL;
>      }
>
> @@ -511,7 +512,7 @@ MapFd0 (
>                4096,
>                PROT_READ | PROT_WRITE,
>                MAP_PRIVATE | MAP_ANONYMOUS,
> -              0,
> +              -1, // This value required by *BSD for MAP_ANON
>                0
>                );
>      if (res3 != EmuMagicPage) {
> @@ -652,7 +653,7 @@ SecUnixPeiAutoScan (
>
>    *MemoryBase = 0;
>    res         = MapMemory (
> -                  0,
> +                  -1, // This value required by *BSD for MAP_ANON
>                    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..d6b70e8320 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__
> +  #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__)
> +  #define statfs statvfs
> +  #define fstatfs fstatvfs
>  #else
>    #include <termio.h>
>    #include <sys/vfs.h>
> --
> 2.39.0
>
> --
>         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

Hi,

I do not have any authority in EmulatorPkg but

Reviewed-by: Pedro Falcato <pedro.falcato@gmail.com>

Can one of the maintainers please give their feedback and/or merge?

This patch has been soaking up for way too long for no good reason.
The feedback has been addressed. I don't think there are any other
issues and there has been 0 feedback from the actual maintainers.

-- 
Pedro

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH 1/1 v3] EmulatorPkg: fixes for NetBSD compilation
       [not found] ` <173E3AAD68434D4F.686@groups.io>
@ 2023-01-27 17:37   ` Pedro Falcato
  0 siblings, 0 replies; 3+ messages in thread
From: Pedro Falcato @ 2023-01-27 17:37 UTC (permalink / raw)
  To: devel, pedro.falcato; +Cc: tlaronde, Andrew Fish, Ray Ni, Kinney, Michael D

(+cc Mike Kinney)

On Fri, Jan 27, 2023 at 5:30 PM Pedro Falcato via groups.io
<pedro.falcato=gmail.com@groups.io> wrote:
>
> On Mon, Jan 9, 2023 at 5:03 PM <tlaronde@polynum.com> wrote:
> >
> > EmulatorPkg: fixes for NetBSD compilation.
> >
> > Note: generated against today (2023-01-09) master.
> >
> > v3:
> > - Macro __NetBSD__ used instead of lower level _NETBSD_SOURCE;
> > - The required fd value (-1) for mmap(3) under *BSD is given as is
> >   with a comment indicating why this particular value for MAP_ANON;
> > - Supplementary: mapFd0() is using mmap(3) also, with MAP_ANON, and the
> >   fd was not corrected as above in the previous versions of the patch.
> >
> > From 708079397bb35eb50cfb12f7d5f2c66b64177a76 Mon Sep 17 00:00:00 2001
> > From: Thierry LARONDE <tlaronde@polynum.com>
> > Date: Mon, 9 Jan 2023 17:49:59 +0100
> > Subject: [PATCH] EmulatorPkg: fixes for NetBSD compilation
> >
> > Signed-off-by: Thierry LARONDE <tlaronde@polynum.com>
> > ---
> >  EmulatorPkg/Unix/Host/BlockIo.c | 16 +++++++++++++++-
> >  EmulatorPkg/Unix/Host/Host.c    |  7 ++++---
> >  EmulatorPkg/Unix/Host/Host.h    |  7 ++++++-
> >  3 files changed, 25 insertions(+), 5 deletions(-)
> >
> > diff --git a/EmulatorPkg/Unix/Host/BlockIo.c b/EmulatorPkg/Unix/Host/BlockIo.c
> > index cf2d6b4cda..2eb062b03d 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__
> > +    {
> > +      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__
> >        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 1f29dd00a3..6a338b81a1 100644
> > --- a/EmulatorPkg/Unix/Host/Host.c
> > +++ b/EmulatorPkg/Unix/Host/Host.c
> > @@ -199,7 +199,7 @@ main (
> >    //
> >    InitialStackMemorySize = STACK_SIZE;
> >    InitialStackMemory     = (UINTN)MapMemory (
> > -                                    0,
> > +                                    -1, // This value required by *BSD for MAP_ANON
> >                                      (UINT32)InitialStackMemorySize,
> >                                      PROT_READ | PROT_WRITE | PROT_EXEC,
> >                                      MAP_ANONYMOUS | MAP_PRIVATE
> > @@ -360,6 +360,7 @@ MapMemory (
> >    while ((!isAligned) && (base != 0)) {
> >      res = mmap ((void *)base, length, prot, flags, fd, 0);
> >      if (res == MAP_FAILED) {
> > +      perror("MapMemory");
> >        return NULL;
> >      }
> >
> > @@ -511,7 +512,7 @@ MapFd0 (
> >                4096,
> >                PROT_READ | PROT_WRITE,
> >                MAP_PRIVATE | MAP_ANONYMOUS,
> > -              0,
> > +              -1, // This value required by *BSD for MAP_ANON
> >                0
> >                );
> >      if (res3 != EmuMagicPage) {
> > @@ -652,7 +653,7 @@ SecUnixPeiAutoScan (
> >
> >    *MemoryBase = 0;
> >    res         = MapMemory (
> > -                  0,
> > +                  -1, // This value required by *BSD for MAP_ANON
> >                    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..d6b70e8320 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__
> > +  #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__)
> > +  #define statfs statvfs
> > +  #define fstatfs fstatvfs
> >  #else
> >    #include <termio.h>
> >    #include <sys/vfs.h>
> > --
> > 2.39.0
> >
> > --
> >         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
>
> Hi,
>
> I do not have any authority in EmulatorPkg but
>
> Reviewed-by: Pedro Falcato <pedro.falcato@gmail.com>
>
> Can one of the maintainers please give their feedback and/or merge?
>
> This patch has been soaking up for way too long for no good reason.
> The feedback has been addressed. I don't think there are any other
> issues and there has been 0 feedback from the actual maintainers.
>
> --
> Pedro
>
>
> 
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-27 17:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-09 17:03 [PATCH 1/1 v3] EmulatorPkg: fixes for NetBSD compilation tlaronde
2023-01-27 17:30 ` Pedro Falcato
     [not found] ` <173E3AAD68434D4F.686@groups.io>
2023-01-27 17:37   ` [edk2-devel] " Pedro Falcato

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox