summaryrefslogtreecommitdiffhomepage
path: root/compat/shm.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-01-23 15:22:20 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-01-23 15:22:20 +0100
commite719ab6cf5efef6deef0848a666e7603a170f775 (patch)
tree4d3587a80feedc1e4f9fe48ef6891122e5d781e1 /compat/shm.cpp
parent01a1f8871fb62a2997d2bac64a1fd4b41e8957f7 (diff)
compat/shm: add never_inline
Also, move out of header in `struct secattr'.
Diffstat (limited to 'compat/shm.cpp')
-rw-r--r--compat/shm.cpp172
1 files changed, 88 insertions, 84 deletions
diff --git a/compat/shm.cpp b/compat/shm.cpp
index 7b04e774..c11e48e7 100644
--- a/compat/shm.cpp
+++ b/compat/shm.cpp
@@ -9,17 +9,17 @@
#if defined(_WIN32)
-#if !defined __WINE__
-# include <QDebug>
-#endif
-
#include <cstring>
#include <stdio.h>
#include <accctrl.h>
#include <aclapi.h>
-struct secattr
+#if !defined __WINE__
+# include <QDebug>
+#endif
+
+struct secattr final
{
bool success;
SECURITY_DESCRIPTOR* pSD;
@@ -27,85 +27,9 @@ struct secattr
PSID pEveryoneSID;
PACL pACL;
- void cleanup()
- {
- if (pEveryoneSID)
- FreeSid(pEveryoneSID);
- if (pACL)
- LocalFree(pACL);
- if (pSD)
- LocalFree(pSD);
- success = false;
- pSD = nullptr;
- pEveryoneSID = nullptr;
- pACL = nullptr;
- }
-
- secattr(DWORD perms) : success(true), pSD(nullptr), pEveryoneSID(nullptr), pACL(nullptr)
- {
- SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
- EXPLICIT_ACCESS ea;
-
- if(!AllocateAndInitializeSid(&SIDAuthWorld, 1,
- SECURITY_WORLD_RID,
- 0, 0, 0, 0, 0, 0, 0,
- &pEveryoneSID))
- {
- fprintf(stderr, "AllocateAndInitializeSid: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- memset(&ea, 0, sizeof(ea));
-
- ea.grfAccessPermissions = perms;
- ea.grfAccessMode = SET_ACCESS;
- ea.grfInheritance = NO_INHERITANCE;
- ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
- ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
- ea.Trustee.ptstrName = (LPTSTR) pEveryoneSID;
-
- if (SetEntriesInAcl(1, &ea, NULL, &pACL) != ERROR_SUCCESS)
- {
- fprintf(stderr, "SetEntriesInAcl: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- pSD = (SECURITY_DESCRIPTOR*) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
- if (pSD == nullptr)
- {
- fprintf(stderr, "LocalAlloc: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- if (!InitializeSecurityDescriptor(pSD,
- SECURITY_DESCRIPTOR_REVISION))
- {
- fprintf(stderr, "InitializeSecurityDescriptor: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- if (!SetSecurityDescriptorDacl(pSD,
- TRUE,
- pACL,
- FALSE))
- {
- fprintf(stderr, "SetSecurityDescriptorDacl: %d\n", (int) GetLastError());
- goto cleanup;
- }
-
- attrs.bInheritHandle = false;
- attrs.lpSecurityDescriptor = pSD;
- attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
-
- return;
-cleanup:
- cleanup();
- }
-
- ~secattr()
- {
- cleanup();
- }
+ void cleanup();
+ secattr(DWORD perms);
+ ~secattr();
};
shm_wrapper::shm_wrapper(const char* shm_name, const char* mutex_name, int map_size)
@@ -233,3 +157,83 @@ bool shm_wrapper::success()
return mem != NULL;
#endif
}
+
+void secattr::cleanup()
+{
+ if (pEveryoneSID)
+ FreeSid(pEveryoneSID);
+ if (pACL)
+ LocalFree(pACL);
+ if (pSD)
+ LocalFree(pSD);
+ success = false;
+ pSD = nullptr;
+ pEveryoneSID = nullptr;
+ pACL = nullptr;
+}
+
+secattr::secattr(DWORD perms) : success(true), pSD(nullptr), pEveryoneSID(nullptr), pACL(nullptr)
+{
+ SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
+ EXPLICIT_ACCESS ea;
+
+ if(!AllocateAndInitializeSid(&SIDAuthWorld, 1,
+ SECURITY_WORLD_RID,
+ 0, 0, 0, 0, 0, 0, 0,
+ &pEveryoneSID))
+ {
+ fprintf(stderr, "AllocateAndInitializeSid: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ memset(&ea, 0, sizeof(ea));
+
+ ea.grfAccessPermissions = perms;
+ ea.grfAccessMode = SET_ACCESS;
+ ea.grfInheritance = NO_INHERITANCE;
+ ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
+ ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
+ ea.Trustee.ptstrName = (LPTSTR) pEveryoneSID;
+
+ if (SetEntriesInAcl(1, &ea, NULL, &pACL) != ERROR_SUCCESS)
+ {
+ fprintf(stderr, "SetEntriesInAcl: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ pSD = (SECURITY_DESCRIPTOR*) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
+ if (pSD == nullptr)
+ {
+ fprintf(stderr, "LocalAlloc: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ if (!InitializeSecurityDescriptor(pSD,
+ SECURITY_DESCRIPTOR_REVISION))
+ {
+ fprintf(stderr, "InitializeSecurityDescriptor: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ if (!SetSecurityDescriptorDacl(pSD,
+ TRUE,
+ pACL,
+ FALSE))
+ {
+ fprintf(stderr, "SetSecurityDescriptorDacl: %d\n", (int) GetLastError());
+ goto cleanup;
+ }
+
+ attrs.bInheritHandle = false;
+ attrs.lpSecurityDescriptor = pSD;
+ attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
+
+ return;
+cleanup:
+ cleanup();
+}
+
+secattr::~secattr()
+{
+ cleanup();
+}