1 /* ccapi/common/win/OldCC/ccutils.c */
3 * Copyright 2008 Massachusetts Institute of Technology.
6 * Export of this software from the United States of America may
7 * require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. Furthermore if you modify this software you must label
19 * your software as modified software and not distribute it in such a
20 * fashion that it might be confused with the original M.I.T. software.
21 * M.I.T. makes no representations about the suitability of
22 * this software for any purpose. It is provided "as is" without express
23 * or implied warranty.
30 #include "cci_debugging.h"
36 BOOL bSupportedVersion = FALSE;
39 memset(&osvi, 0, sizeof(osvi));
40 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
42 status = !GetVersionEx(&osvi); // Returns a boolean. Invert to 0 is OK.
45 switch(osvi.dwPlatformId) {
46 case VER_PLATFORM_WIN32_WINDOWS:
48 bSupportedVersion = TRUE;
50 case VER_PLATFORM_WIN32_NT:
52 bSupportedVersion = TRUE;
54 case VER_PLATFORM_WIN32s:
60 if (!bSupportedVersion) {
61 cci_debug_printf("%s Running on an unsupported version of Windows", __FUNCTION__);
66 return (!status && bIsNT && bSupportedVersion);
69 char* allocEventName(char* uuid_string, char* suffix) {
70 LPSTR event_name = NULL;
71 cc_int32 err = ccNoError;
73 event_name = malloc(strlen(uuid_string) + strlen(suffix) + 3);
74 if (!event_name) err = cci_check_error(ccErrNoMem);
77 strcpy(event_name, uuid_string);
78 strcat(event_name, "_");
79 strcat(event_name, suffix);
85 HANDLE createThreadEvent(char* uuid, char* suffix) {
86 LPSTR event_name = NULL;
88 PSECURITY_ATTRIBUTES psa = 0; // Everything having to do with
89 SECURITY_ATTRIBUTES sa = { 0 }; // sa, psa, security is copied
90 DWORD status = 0; // from the previous implementation.
92 psa = isNT() ? &sa : 0;
95 sa.nLength = sizeof(sa);
96 status = alloc_own_security_descriptor_NT(&sa.lpSecurityDescriptor);
97 cci_check_error(status);
101 event_name = allocEventName(uuid, suffix);
102 if (!event_name) status = cci_check_error(ccErrNoMem);
105 cci_debug_printf("%s event_name:%s", __FUNCTION__, event_name);
108 hEvent = CreateEvent(psa, FALSE, FALSE, event_name);
109 if (!hEvent) status = cci_check_error(GetLastError());
112 if (!status) ResetEvent(hEvent);
115 if (event_name) free(event_name);
116 if (isNT()) free(sa.lpSecurityDescriptor);
121 HANDLE openThreadEvent(char* uuid, char* suffix) {
122 LPSTR event_name = NULL;
123 HANDLE hEvent = NULL;
126 event_name = allocEventName(uuid, suffix);
127 if (!event_name) status = cci_check_error(ccErrNoMem);
129 cci_debug_printf("%s event_name:%s", __FUNCTION__, event_name);
132 hEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name);
133 if (!hEvent) status = cci_check_error(GetLastError());
136 if (event_name) free(event_name);