[x64] Fix improper use of compare_exchange_strong when adjusting code commit mark

This commit is contained in:
Dr. Chat 2018-11-18 18:24:35 -06:00
parent bcfaf530cb
commit a8bef91cc4
1 changed files with 16 additions and 12 deletions

View File

@ -174,15 +174,17 @@ void* X64CodeCache::PlaceGuestCode(uint32_t guest_address, void* machine_code,
// If we are going above the high water mark of committed memory, commit // If we are going above the high water mark of committed memory, commit
// some more. It's ok if multiple threads do this, as redundant commits // some more. It's ok if multiple threads do this, as redundant commits
// aren't harmful. // aren't harmful.
size_t old_commit_mark = generated_code_commit_mark_; size_t old_commit_mark, new_commit_mark;
if (high_mark > old_commit_mark) { do {
size_t new_commit_mark = old_commit_mark + 16 * 1024 * 1024; old_commit_mark = generated_code_commit_mark_;
if (high_mark <= old_commit_mark) break;
new_commit_mark = old_commit_mark + 16 * 1024 * 1024;
xe::memory::AllocFixed(generated_code_base_, new_commit_mark, xe::memory::AllocFixed(generated_code_base_, new_commit_mark,
xe::memory::AllocationType::kCommit, xe::memory::AllocationType::kCommit,
xe::memory::PageAccess::kExecuteReadWrite); xe::memory::PageAccess::kExecuteReadWrite);
generated_code_commit_mark_.compare_exchange_strong(old_commit_mark, } while (generated_code_commit_mark_.compare_exchange_weak(
new_commit_mark); old_commit_mark, new_commit_mark));
}
// Copy code. // Copy code.
std::memcpy(code_address, machine_code, code_size); std::memcpy(code_address, machine_code, code_size);
@ -248,15 +250,17 @@ uint32_t X64CodeCache::PlaceData(const void* data, size_t length) {
// If we are going above the high water mark of committed memory, commit some // If we are going above the high water mark of committed memory, commit some
// more. It's ok if multiple threads do this, as redundant commits aren't // more. It's ok if multiple threads do this, as redundant commits aren't
// harmful. // harmful.
size_t old_commit_mark = generated_code_commit_mark_; size_t old_commit_mark, new_commit_mark;
if (high_mark > old_commit_mark) { do {
size_t new_commit_mark = old_commit_mark + 16 * 1024 * 1024; old_commit_mark = generated_code_commit_mark_;
if (high_mark <= old_commit_mark) break;
new_commit_mark = old_commit_mark + 16 * 1024 * 1024;
xe::memory::AllocFixed(generated_code_base_, new_commit_mark, xe::memory::AllocFixed(generated_code_base_, new_commit_mark,
xe::memory::AllocationType::kCommit, xe::memory::AllocationType::kCommit,
xe::memory::PageAccess::kExecuteReadWrite); xe::memory::PageAccess::kExecuteReadWrite);
generated_code_commit_mark_.compare_exchange_strong(old_commit_mark, } while (generated_code_commit_mark_.compare_exchange_weak(old_commit_mark,
new_commit_mark); new_commit_mark));
}
// Copy code. // Copy code.
std::memcpy(data_address, data, length); std::memcpy(data_address, data, length);