From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp26.services.sfr.fr (smtp26.services.sfr.fr [93.17.128.204]) by mx.groups.io with SMTP id smtpd.web11.37823.1669036105988782079 for ; Mon, 21 Nov 2022 05:08:26 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="no key for verify" header.i=@polynum.com header.s=202006 header.b=R8M7VmUp; spf=pass (domain: sfr.fr, ip: 93.17.128.204, mailfrom: thierry.laronde@sfr.fr) X-mail-filterd: {"version":"1.5.3","queueID":"4NG7476ZCZz1LQLxk","contextId": "72e1ccc5-c77b-4c2a-a602-f79d84ac5620"} Received: from cauchy.polynum.local (20.204.0.93.rev.sfr.net [93.0.204.20]) by msfrf2624.sfr.fr (SMTP Server) with ESMTP id 4NG7476ZCZz1LQLxk for ; Mon, 21 Nov 2022 14:08:23 +0100 (CET) X-mail-filterd: {"version":"1.5.3","queueID":"4NG73y5LHBz1LQLxt","contextId": "e0f684c2-d724-4a65-85c3-39a3d89f2cfd"} X-sfr-mailing: LEGIT X-sfr-spamrating: 40 X-sfr-spam: not-spam DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=polynum.com; s=202006; t=1669036094; h=Date:From:To:Subject; bh=X9n8QUbtbK1zd53YPJ6hiqwGZab01VRbR+xq uqC5Yi8=; b=R8M7VmUpiMP5zB3mXXfqb7U8x5cdPZGIHDwZvJp29es0VFhQW8tv+CxVqKhZ8AOj Pb+EoL6GWT4asiMPU3jFbMwtQBE64Wi5N8UBaQyoFysLeI0KAu4zju2LLFYP2uBhWGnc/ytm8cRA h7AgiLF/v8bxIEOAZvWgRv4Em+b8CM0/RjCCidC6ET2/XdlZVt9R+JJ1sgk+55pmgc5KO6kSEcEW f2b2IP6IeTz3tqWxozV1BvifyJ63OXCGtXwz4i35oK+KzDRdRKVAq2bSshp//7t6AqFyViAwYJZ+ X2ivcjpLflGtgNnLHMJFOam+MmgnRgZmRONfZtd5dHASkwQ3oA== 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 msfrf2624.sfr.fr (SMTP Server) with ESMTPSA id 4NG73y5LHBz1LQLxt for ; Mon, 21 Nov 2022 14:08:14 +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 2ALD8CFU001514 for ; Mon, 21 Nov 2022 14:08:12 +0100 (CET) Received: (from tlaronde@localhost) by cauchy.polynum.local (8.15.2/8.14.9/Submit) id 2ALD8C6p001100 for devel@edk2.groups.io; Mon, 21 Nov 2022 14:08:12 +0100 (CET) X-Authentication-Warning: cauchy.polynum.local: tlaronde set sender to thierry.laronde@sfr.fr using -f Date: Mon, 21 Nov 2022 14:08:12 +0100 From: tlaronde@polynum.com To: devel@edk2.groups.io Subject: EmulatorPkg: fixes for NetBSD compilation Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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; + 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 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..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 + // // Globals // @@ -187,7 +193,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 +354,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 +647,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 +#elif _NETBSD_SOURCE + #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_SOURCE) + #define statfs statvfs + #define fstatfs fstatvfs #else #include #include signed-off-by: Thierry LARONDE -- Thierry Laronde http://www.kergis.com/ http://kertex.kergis.com/ Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C