Skip to content

Commit 532b3cd

Browse files
committed
Smbios (NetBSD): add support
1 parent 437006f commit 532b3cd

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,13 @@ elseif(NetBSD)
744744
src/detection/btrfs/btrfs_nosupport.c
745745
src/detection/chassis/chassis_nbsd.c
746746
src/detection/cpu/cpu_nbsd.c
747-
src/detection/cpucache/cpucache_nosupport.c
747+
src/detection/cpucache/cpucache_shared.c
748748
src/detection/cpuusage/cpuusage_bsd.c
749749
src/detection/cursor/cursor_linux.c
750750
src/detection/disk/disk_bsd.c
751751
src/detection/dns/dns_linux.c
752752
src/detection/physicaldisk/physicaldisk_nosupport.c
753-
src/detection/physicalmemory/physicalmemory_nosupport.c
753+
src/detection/physicalmemory/physicalmemory_linux.c
754754
src/detection/diskio/diskio_nbsd.c
755755
src/detection/displayserver/linux/displayserver_linux.c
756756
src/detection/displayserver/linux/drm.c

src/util/smbiosHelper.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const FFSmbiosHeader* ffSmbiosNextEntry(const FFSmbiosHeader* header)
5050
return (const FFSmbiosHeader*) (p + 1);
5151
}
5252

53-
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__HAIKU__)
53+
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__)
5454
#include <fcntl.h>
5555
#include <sys/stat.h>
5656
#include <sys/mman.h>
@@ -63,6 +63,9 @@ const FFSmbiosHeader* ffSmbiosNextEntry(const FFSmbiosHeader* header)
6363
#define loff_t off_t // FreeBSD doesn't have loff_t
6464
#elif defined(__sun)
6565
#define loff_t off_t
66+
#elif defined(__NetBSD__)
67+
#include "common/sysctl.h"
68+
#define loff_t off_t
6669
#endif
6770

6871
bool ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
@@ -140,7 +143,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
140143
if (!ffAppendFileBuffer("/sys/firmware/dmi/tables/DMI", &buffer))
141144
#endif
142145
{
143-
#ifndef __sun
146+
#if !defined(__sun) && !defined(__NetBSD__)
144147
FF_STRBUF_AUTO_DESTROY strEntryAddress = ffStrbufCreate();
145148
#ifdef __FreeBSD__
146149
if (!ffSettingsGetFreeBSDKenv("hint.smbios.0.mem", &strEntryAddress))
@@ -177,7 +180,13 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
177180
if (fd < 0) return NULL;
178181

179182
FFSmbiosEntryPoint entryPoint;
180-
if (!ffReadFDData(fd, sizeof(entryPoint), &entryPoint)) return NULL;
183+
#ifdef __NetBSD__
184+
off_t addr = (off_t) ffSysctlGetInt64("machdep.smbios", 0);
185+
if (addr == 0) return NULL;
186+
if (pread(fd, &entryPoint, sizeof(entryPoint), addr) < 1) return NULL;
187+
#else
188+
if (ffReadFDData(fd, sizeof(entryPoint), &entryPoint) < 1) return NULL;
189+
#endif
181190
#endif
182191

183192
uint32_t tableLength = 0;
@@ -196,9 +205,11 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
196205
tableLength = entryPoint.Smbios30.StructureTableMaximumSize;
197206
tableAddress = (loff_t) entryPoint.Smbios30.StructureTableAddress;
198207
}
208+
else
209+
return NULL;
199210

200211
ffStrbufEnsureFixedLengthFree(&buffer, tableLength);
201-
if (pread(fd, buffer.chars, tableLength, tableAddress) == tableLength)
212+
if (pread(fd, buffer.chars, tableLength, tableAddress) == (ssize_t) tableLength)
202213
{
203214
buffer.length = tableLength;
204215
buffer.chars[buffer.length] = '\0';

0 commit comments

Comments
 (0)