diff options
| author | Per Larsson <[email protected]> | 2021-12-09 17:01:57 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-12-09 17:01:57 +0100 |
| commit | 20f3c16b0012cfb8ce7bf9b6dd06a2720b6885c6 (patch) | |
| tree | fbb0f274840a12c32d93c7e342c0427f2617a651 /zenutil/zenserverprocess.cpp | |
| parent | Disabled cache tracker. (diff) | |
| parent | Return status_code as ErrorCode from jupiter api if not successful (diff) | |
| download | zen-20f3c16b0012cfb8ce7bf9b6dd06a2720b6885c6.tar.xz zen-20f3c16b0012cfb8ce7bf9b6dd06a2720b6885c6.zip | |
Merged main.
Diffstat (limited to 'zenutil/zenserverprocess.cpp')
| -rw-r--r-- | zenutil/zenserverprocess.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp index 4098954a8..e366a917f 100644 --- a/zenutil/zenserverprocess.cpp +++ b/zenutil/zenserverprocess.cpp @@ -89,11 +89,19 @@ ZenServerState::Initialize() { // TODO: there's a small chance of a race here, this logic could be tightened up with a mutex to // ensure only a single process at a time creates the mapping + // TODO: the fallback to Local instead of Global has a flaw where if you start a non-elevated instance + // first then start an elevated instance second you'll have the first instance with a local + // mapping and the second instance with a global mapping. This kind of elevated/non-elevated + // shouldn't be common, but handling for it should be improved in the future. if (HANDLE hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Global\\ZenMap")) { m_hMapFile = hMap; } + else if (HANDLE hLocalMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap")) + { + m_hMapFile = hLocalMap; + } else { // Security attributes to enable any user to access state @@ -108,6 +116,16 @@ ZenServerState::Initialize() if (hMap == NULL) { + hMap = CreateFileMapping(INVALID_HANDLE_VALUE, // use paging file + Attrs.Attributes(), // allow anyone to access + PAGE_READWRITE, // read/write access + 0, // maximum object size (high-order DWORD) + m_MaxEntryCount * sizeof(ZenServerEntry), // maximum object size (low-order DWORD) + L"Local\\ZenMap"); // name of mapping object + } + + if (hMap == NULL) + { ThrowLastError("Could not open or create file mapping object for Zen server state"); } @@ -136,6 +154,10 @@ ZenServerState::InitializeReadOnly() { m_hMapFile = hMap; } + else if (HANDLE hLocalMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"Local\\ZenMap")) + { + m_hMapFile = hLocalMap; + } else { return false; @@ -283,7 +305,7 @@ ZenServerState::ZenServerEntry::AddSponsorProcess(uint32_t PidToAdd) if (PidEntry.load(std::memory_order::memory_order_relaxed) == 0) { uint32_t Expected = 0; - if (PidEntry.compare_exchange_strong(Expected, uint16_t(PidToAdd))) + if (PidEntry.compare_exchange_strong(Expected, PidToAdd)) { // Success! return true; |