-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathSharedMemory.cpp
More file actions
54 lines (49 loc) · 2.15 KB
/
SharedMemory.cpp
File metadata and controls
54 lines (49 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//--------------------------------------------------------------------------------------
// SharedMemory.cpp
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "MemoryDemo.h"
// The code related to testing the shared address sample
namespace ATG
{
bool MemoryDemo::TestSharedAddress()
{
__try // There could be random pointer dereferencing in here on bad data
{ // we are building with /EHsc which means C++ try/catch will not catch OS exceptions like null pointer dereferences.
// these types of exceptions require SEH to catch
m_memoryBank.ReleaseBank();
m_memoryBank.CommitSharedBanks(c_memoryBankSize, 2, false);
memset(m_memoryBank.get(0), 1, c_memoryBankSize);
if (memcmp(m_memoryBank.get(0), m_memoryBank.get(1), c_memoryBankSize) != 0)
{
OutputDebugStringA("shared memory banks are not equal\n");
return false;
}
m_memoryBank.ReleaseBank();
m_memoryBank.CommitSharedBanks(c_memoryBankSize * sizeof(uint32_t), 2, true);
uint32_t *baseAddress = reinterpret_cast<uint32_t *> (m_memoryBank.get(0));
//write to memory so that is writes off the end of the buffer and into start due to the shared adjacent addresses
for (uint32_t i = 0; i < c_memoryBankSize; i++)
{
baseAddress[i + (c_memoryBankSize / 2)] = i;
}
for (uint32_t i = 0; i < c_memoryBankSize; i++)
{
if (baseAddress[i] != ((i + (c_memoryBankSize / 2)) % c_memoryBankSize))
{
OutputDebugStringA("Testing adjacent shared memory banks did not wrap correctly\n");
return false;
}
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
OutputDebugStringA("Testing shared memory banks threw an exception\n");
return false;
}
return true;
}
}