Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions runtime/test/d3d12_existing_heap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,8 +1606,10 @@ int check_rereserved(ID3D12Device* device) {
// write-watched one (kept hot, so every submission asks about it) and a plain one (guarded), while submissions run back
// to back and:
// - threads take the process heap's lock (HeapLock, as HeapAlloc does inside, and the heap gate above: every
// allocation waits for them), _aligned_malloc and _aligned_free under it and write a guarded page: a fault, with
// the heap's lock held, at every submission;
// allocation waits for them), HeapAlloc and HeapFree a block under it and write a guarded page: a fault, with
// the heap's lock held, at every submission. HeapAlloc, not this program's _aligned_malloc: the title's comes
// down to HeapAlloc, but a debug CRT's takes the CRT's own heap lock first, which the threads below hold while
// they wait for the process heap, so a toucher holding HeapLock would deadlock with them without the handler;
// - threads _aligned_malloc and _aligned_free blocks of every size class without it;
// - a thread keeps the write-watched half hot;
// - threads change the write-watch record (a reservation added and removed), the journal (mark), the alias set and
Expand Down Expand Up @@ -1673,10 +1675,10 @@ int check_heap_lock_faults(ID3D12Device* device) {
for (std::uint8_t round = 1; !stop.load(std::memory_order_relaxed); ++round) {
AcquireSRWLockExclusive(&g_heap_gate);
HeapLock(heap);
void* block = _aligned_malloc(64 + (round % 32) * 160, 16);
void* block = HeapAlloc(heap, 0, 64 + (round % 32) * 160);
for (SIZE_T at = t * 64; at < committed; at += 0x10000) // a byte per block
*reinterpret_cast<volatile std::uint8_t*>(guarded + at) = round;
_aligned_free(block);
HeapFree(heap, 0, block);
HeapUnlock(heap);
ReleaseSRWLockExclusive(&g_heap_gate);
progress.fetch_add(1, std::memory_order_relaxed);
Expand Down
12 changes: 8 additions & 4 deletions runtime/test/xmem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,9 +1094,13 @@ void spin_for(LONGLONG us) {
// its own or not, so whoever holds that lock exclusively (a map or an unmap of physical pages) must never wait for the
// process heap meanwhile: it would wait for the faulting thread, which waits for it. While
// - threads take the process heap's lock (HeapLock, as HeapAlloc does inside, and the heap gate above) and, holding
// it, _aligned_malloc and _aligned_free and write a word into every page of a window whose pages are mapped fresh
// it, HeapAlloc and HeapFree a block and write a word into every page of a window whose pages are mapped fresh
// all the time (a first-touch commit, or a fault on a page that is being unmapped) and into a read-only page (a
// fault that isn't xmem's, as on a guarded shadow page);
// fault that isn't xmem's, as on a guarded shadow page). HeapAlloc, not this program's _aligned_malloc: the title's
// _aligned_malloc comes down to HeapAlloc, but a debug CRT's takes the CRT's own heap lock first, and any thread
// of this program that allocates through that CRT (vcruntime's exception dispatch does, past the heap gate) holds
// that lock while it waits for the process heap: holding HeapLock, the toucher would then deadlock with it
// without xmem in the cycle;
// - threads allocate physical pages, map them into their part of the window (as a run, or page by page through the
// scatter call), and unmap and free them, some freed while still mapped so that the unmap drops the last
// reference to their section;
Expand Down Expand Up @@ -1157,14 +1161,14 @@ void test_heap_lock_faults(const PhysicalApi& api) {
bool round_read_only = false;
AcquireSRWLockExclusive(&g_heap_gate);
HeapLock(heap);
void* block = _aligned_malloc(64 + (round % 32) * 160, 16);
void* block = HeapAlloc(heap, 0, 64 + (round % 32) * 160);
for (uint64_t p = 0; p < kPages; ++p) {
auto* const word =
static_cast<volatile uint32_t*>(static_cast<void*>(window + p * kPage64k)) + t;
round_missed += access_faults(word, true);
}
round_read_only = access_faults(static_cast<volatile uint32_t*>(static_cast<void*>(read_only)), true);
_aligned_free(block);
HeapFree(heap, 0, block);
HeapUnlock(heap);
ReleaseSRWLockExclusive(&g_heap_gate);
missed.fetch_add(round_missed, std::memory_order_relaxed);
Expand Down
Loading