Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Commit

Permalink
[Fix] Possible AV during background save.
Browse files Browse the repository at this point in the history
This fix is a refinement of a previous fix to avoid a possible AV if the buffer
to write to disk ends exactly at the last byte of a memory page.
  • Loading branch information
enricogior committed Jun 21, 2016
1 parent 9503e70 commit a7ded33
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/Win32_Interop/Win32_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,13 @@ namespace Globals
/* This function is used to force the VEH on the entire size of the buffer length,
* in the event that the buffer crosses the memory page boundaries */
void EnsureMemoryIsMapped(const void *buffer, size_t size) {
// Use 'volatile' to make sure the compiler doesn't remove "c = *((char*) (p + offset));"
volatile char c;
char* p = (char*) buffer;
char* pStart = p - ((size_t) p % Globals::pageSize);
char* pEnd = p + size;
if ((size_t) (pEnd - pStart) > Globals::pageSize) {
size_t offset = 0;
while (offset < size) {
offset += Globals::pageSize;
if (offset > size) {
offset = size;
}
c = *((char*) (p + offset));
}
char* pFirstByte = (char*) buffer;
char* pLastByte = (char*) buffer + size - 1;
char* pFirstPage = pFirstByte - ((size_t) pFirstByte % Globals::pageSize);
char* pLastPage = pLastByte - ((size_t) pLastByte % Globals::pageSize);
// Use 'volatile' to make sure the compiler doesn't remove the memory access
for (volatile char* p = pFirstPage; p <= pLastPage; p += Globals::pageSize) {
volatile char c = *p;
}
}

Expand Down

3 comments on commit a7ded33

@knocte
Copy link

@knocte knocte commented on a7ded33 Aug 19, 2016

Choose a reason for hiding this comment

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

What does AV mean?

@Patryk27
Copy link

@Patryk27 Patryk27 commented on a7ded33 Jun 8, 2017

Choose a reason for hiding this comment

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

@knocte: memory access violation (yeah, fast answer :-P).

@knocte
Copy link

@knocte knocte commented on a7ded33 Jun 8, 2017

Choose a reason for hiding this comment

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

thanks

Please sign in to comment.