Skip to content

[sanitizer_common] Return nullptr from ASan on ERROR_COMMITMENT_LIMIT #119753

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

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void *ReturnNullptrOnOOMOrDie(uptr size, const char *mem_type,

// Assumption: VirtualAlloc is the last system call that was invoked before
// this method.
// VirtualAlloc emits one of 2 error codes when running out of memory
// VirtualAlloc emits one of 3 error codes when running out of memory
// 1. ERROR_NOT_ENOUGH_MEMORY:
// There's not enough memory to execute the command
// 2. ERROR_INVALID_PARAMETER:
Expand All @@ -176,12 +176,12 @@ static void *ReturnNullptrOnOOMOrDie(uptr size, const char *mem_type,
// (the `lpMaximumApplicationAddress` field within the `SystemInfo` struct).
// This does not seem to be officially documented, but is corroborated here:
// https://stackoverflow.com/questions/45833674/why-does-virtualalloc-fail-for-lpaddress-greater-than-0x6ffffffffff

// Note - It's possible that 'ERROR_COMMITMENT_LIMIT' needs to be handled here
// as well. It is currently not handled due to the lack of a reproducer that
// induces the error code.
// 3. ERROR_COMMITMENT_LIMIT:
// VirtualAlloc will return this if e.g. the pagefile is too small to commit
// the requested amount of memory.
if (last_error == ERROR_NOT_ENOUGH_MEMORY ||
last_error == ERROR_INVALID_PARAMETER)
last_error == ERROR_INVALID_PARAMETER ||
last_error == ERROR_COMMITMENT_LIMIT)
Copy link
Collaborator

Choose a reason for hiding this comment

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

would be nice to extend a test if it's reasonably easy to reproduce

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't found a trivial way to trigger it, unfortunately. At least not in the time I had to try.

return nullptr;
ReportMmapFailureAndDie(size, mem_type, mmap_type, last_error);
}
Expand Down
Loading