Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we don't reallocate during 2GB address space block #49

Merged
merged 5 commits into from
Oct 4, 2023

Conversation

encounter
Copy link
Member

@encounter encounter commented Oct 2, 2023

  • Adds procLine.reserve(0x8000); to ensure that the std::string doesn't cause memory allocation between reading /proc/self/maps and the mmap calls. Replaced with Linux syscalls and stack buffer to avoid any allocations.
  • Replaces MAP_FIXED with MAP_FIXED_NOREPLACE (Linux 4.17+) to ensure that we bail if our mapping would overwrite an existing one.
  • Moves this logic into a separate method blockUpper2GB to simplify cleanup.
  • Adds -fno-pie -no-pie cflags to ensure that we're not using PIE. (Probably unnecessary, but seems good)

Copy link
Contributor

@simonlindholm simonlindholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes.

Linux 4.17 is from 2018, which feels like it may be recent enough to break for some people. Can we fall back to MAP_FIXED?

main.cpp Outdated

const unsigned int FILL_MEMORY_ABOVE = 0x80000000; // 2GB

while (getline(procMap, procLine)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifstream is probably using a buffer internally, so it would make sense to start by switch this to reading the entire file using read() calls and then parsing out lines of that by hand.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@encounter encounter merged commit 5a4af7d into decompals:main Oct 4, 2023
1 check passed
@encounter encounter deleted the 2gb-fix branch October 4, 2023 01:26
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