Skip to content

fix: implement MappedFile on POSIX (mmap)#22

Open
oozimok wants to merge 1 commit intoTitoot:mainfrom
oozimok:fix/mapped-file-posix
Open

fix: implement MappedFile on POSIX (mmap)#22
oozimok wants to merge 1 commit intoTitoot:mainfrom
oozimok:fix/mapped-file-posix

Conversation

@oozimok
Copy link
Copy Markdown

@oozimok oozimok commented Apr 13, 2026

Summary

Adds a POSIX implementation of MappedFile (macOS, Linux, etc.) using open / fstat / mmap, so PE scanning is not Windows-only at compile time.

Problem

The class and its implementation were guarded with #ifdef _WIN32. On macOS the header did not declare the type and mapped_file.cpp compiled to an empty translation unit, so pe_scanner.cpp failed to build (unknown type name 'MappedFile'), and the linker reported no symbols for mapped_file.cpp.o.

Solution

  • Declare MappedFile on all platforms, with separate private members for Windows vs POSIX.
  • On non-Windows: open the file, ensure it is a regular file, map it read-only with mmap, and unmap/close in the destructor.
  • Zero-length files: skip mmap; object remains valid and get_data() returns an empty std::span.

Testing

  • cmake --build … --config Release on macOS — full build including keydot succeeds.

Notes

  • Public API (is_valid(), get_data()) matches the Windows behavior; constructor failures log to stderr, consistent with the Win32 path.

@Titoot
Copy link
Copy Markdown
Owner

Titoot commented Apr 13, 2026

one thing to note, The utils.h was for some reason included twice which is unnecessary, you can just put the import outside of the _WIN32

and also do you suggest editing the build workflow to include other platforms (MacOS, Linux)?

@Titoot Titoot self-assigned this Apr 14, 2026
@Titoot
Copy link
Copy Markdown
Owner

Titoot commented Apr 14, 2026

@oozimok

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.

2 participants