From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp26.services.sfr.fr (smtp26.services.sfr.fr [93.17.128.4]) by mx.groups.io with SMTP id smtpd.web11.78232.1673283824863527004 for ; Mon, 09 Jan 2023 09:03:45 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="no key for verify" header.i=@polynum.com header.s=202006 header.b=fPV/ON/b; spf=pass (domain: sfr.fr, ip: 93.17.128.4, mailfrom: thierry.laronde@sfr.fr) X-mail-filterd: {"version":"1.6.0","queueID":"4NrKz30Df9z1LQLsC","contextId": "3fb3a02e-a526-466c-b606-658fa2ea1fbb"} Received: from cauchy.polynum.local (20.204.0.93.rev.sfr.net [93.0.204.20]) by msfrf2617.sfr.fr (SMTP Server) with ESMTP id 4NrKz30Df9z1LQLsC; Mon, 9 Jan 2023 18:03:43 +0100 (CET) X-mail-filterd: {"version":"1.6.0","queueID":"4NrKz24KZFz1LQKd9","contextId": "8fc6fe06-08e9-4c05-89a6-b440dda0f3fb"} X-sfr-mailing: LEGIT X-sfr-spamrating: 36 X-sfr-spam: not-spam DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=polynum.com; s=202006; t=1673283823; h=Date:From:To:Cc:Subject; bh=UbL+amkMY0X5NFDqiH3QsW4fzUYvwdmzL FJgbTUJIK8=; b=fPV/ON/bIgXCMSQvKSjRt/vwDkhozdB2ClmUDZT2lTMEcnimAU0LXU2J36pbD FJDL0WVK7fZKKQHUZbnuTrkDuQAb9zDQDBinJAqRub/r0RV5O7mwip2hG1R7uhPAIpUmcGqQPkBv l/l8/FATiMchI5+vW12OTy2DqS+zhHXePXXtLpO9U+ta+xxAfaDfn/K+aMuvErbyrWoMhdYUhH/K s8WU/+QtECElACmWK5iueEBhid6+9cLB93hhRzzw4XAY/v1GXsuSpveE9Oh19lFymizCPtcv4l2S 48uL/l7Fke94T3C91+J1ipYFHOqJSS0u8fNKU3GKRzO/JMtwYDGTw== Received: from cauchy.polynum.local (20.204.0.93.rev.sfr.net [93.0.204.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: thierry.laronde@sfr.fr) by msfrf2617.sfr.fr (SMTP Server) with ESMTPSA id 4NrKz24KZFz1LQKd9; Mon, 9 Jan 2023 18:03:42 +0100 (CET) Authentication-Results: sfr.fr; auth=pass (LOGIN) smtp.auth=thierry.laronde@sfr.fr Received: from cauchy.polynum.local (localhost [127.0.0.1]) by cauchy.polynum.local (8.15.2/8.15.2) with ESMTP id 309H3d1t028029; Mon, 9 Jan 2023 18:03:39 +0100 (CET) Received: (from tlaronde@localhost) by cauchy.polynum.local (8.15.2/8.14.9/Submit) id 309H3dIc017117; Mon, 9 Jan 2023 18:03:39 +0100 (CET) X-Authentication-Warning: cauchy.polynum.local: tlaronde set sender to thierry.laronde@sfr.fr using -f Date: Mon, 9 Jan 2023 18:03:38 +0100 From: tlaronde@polynum.com To: devel@edk2.groups.io Cc: Andrew Fish , Ray Ni , Pedro Falcato Subject: [PATCH 1/1 v3] EmulatorPkg: fixes for NetBSD compilation Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Date: Mon, 9 Jan 2023 17:49:59 +0100 Subject: [PATCH] EmulatorPkg: fixes for NetBSD compilation Signed-off-by: Thierry LARONDE --- 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 +#elif __NetBSD__ + #include #else #include #endif @@ -55,7 +57,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include -#ifdef __APPLE__ +#if defined(__APPLE__) #include #include #include @@ -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 #include -- 2.39.0 -- Thierry Laronde http://www.kergis.com/ http://kertex.kergis.com/ Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C