Skip to content

fix(foundation): use HW_PHYSMEM for physical memory detection on FreeBSD#1093

Open
PR9000 wants to merge 1 commit into
DeusData:mainfrom
PR9000:freebsd-hw-physmem
Open

fix(foundation): use HW_PHYSMEM for physical memory detection on FreeBSD#1093
PR9000 wants to merge 1 commit into
DeusData:mainfrom
PR9000:freebsd-hw-physmem

Conversation

@PR9000

@PR9000 PR9000 commented Jul 15, 2026

Copy link
Copy Markdown

What does this PR do?

This PR fixes physical memory detection on FreeBSD by using the standard HW_PHYSMEM sysctl in detect_system_bsd().

On FreeBSD 15.1-STABLE, the current implementation using HW_PHYSMEM64 does not return the expected physical memory size during system initialization. This change routes FreeBSD through the existing HW_PHYSMEM code path already used by OpenBSD.

Changes

  • Updated src/foundation/system_info.c.
  • Extended the BSD-specific condition:
#if defined(__OpenBSD__)

to:

#if defined(__OpenBSD__) || defined(__FreeBSD__)

so FreeBSD uses HW_PHYSMEM for physical memory detection.

Testing

Tested on FreeBSD 15.1-STABLE (amd64).

Validation performed:

  • Successfully built codebase-memory-mcp using:
gmake -f Makefile.cbm cbm
  • Successfully ran the CI linters:
gmake -f Makefile.cbm lint-ci CLANG_FORMAT=clang-format21

Result:

=== cppcheck ===
=== clang-format ===
=== NOLINT check ===
=== CI linters passed ===
  • Verified that the detected physical memory size is reported correctly after this change.

The test suite was also executed:

gmake -f Makefile.cbm test

However, the test build currently fails during linking with an unrelated AddressSanitizer duplicate symbol error:

duplicate symbol: bsearch
>>> defined at asan_interceptors.cpp
>>> defined at internal/cbm/vendored/grammars/perl/bsearch.h

This failure is independent from this change and occurs in the test infrastructure/linking stage before the tests are executed.

Why this is safe

This is a small, localized, platform-specific change affecting only the FreeBSD BSD implementation path.

Linux, macOS, Windows, and other supported platforms are unaffected. The change reuses the existing HW_PHYSMEM implementation already used for OpenBSD and does not modify the behavior of other operating systems.

Checklist

  • Every commit is signed off (git commit -s) — required, CI rejects unsigned commits ([DCO](../DCO), see [CONTRIBUTING.md](../CONTRIBUTING.md))
  • Tests pass locally (make -f Makefile.cbm test)
  • Lint passes (make -f Makefile.cbm lint-ci)
  • New behavior is covered by a test (reproduce-first for bug fixes)

Signed-off-by: Pedro Ramos <131530838+pr9000@users.noreply.github.com>
@PR9000 PR9000 requested a review from DeusData as a code owner July 15, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant