HOOKFUNC HANDLE WINAPI MyOpenSemaphoreW(DWORD dwDesiredAccess,BOOL bInheritHandle,LPCWSTR lpName) { HANDLE rv = OpenSemaphoreW(dwDesiredAccess, bInheritHandle, lpName); debuglog(LCF_SYNCOBJ, __FUNCTION__ " returned 0x%X.\n", rv); EnterCriticalSection(&s_handleCS); std::set<HANDLE>& handles = s_threadIdHandles[GetCurrentThreadId()]; handles.insert(rv); LeaveCriticalSection(&s_handleCS); return rv; }
HOOKFUNC HANDLE WINAPI MyOpenSemaphoreW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName) { ENTER(); HANDLE rv = OpenSemaphoreW(dwDesiredAccess, bInheritHandle, lpName); LEAVE(rv); EnterCriticalSection(&s_handleCS); std::set<HANDLE>& handles = s_threadIdHandles[GetCurrentThreadId()]; handles.insert(rv); LeaveCriticalSection(&s_handleCS); return rv; }
HANDLE APIENTRY OpenSemaphoreA( DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName ) /*++ Routine Description: ANSI thunk to OpenSemaphoreW --*/ { PUNICODE_STRING Unicode; ANSI_STRING AnsiString; NTSTATUS Status; if ( ARGUMENT_PRESENT(lpName) ) { Unicode = &NtCurrentTeb()->StaticUnicodeString; RtlInitAnsiString(&AnsiString,lpName); Status = RtlAnsiStringToUnicodeString(Unicode,&AnsiString,FALSE); if ( !NT_SUCCESS(Status) ) { if ( Status == STATUS_BUFFER_OVERFLOW ) { SetLastError(ERROR_FILENAME_EXCED_RANGE); } else { BaseSetLastNTError(Status); } return NULL; } } else { BaseSetLastNTError(STATUS_INVALID_PARAMETER); return NULL; } return OpenSemaphoreW( dwDesiredAccess, bInheritHandle, (LPCWSTR)Unicode->Buffer ); }
/* * @implemented */ HANDLE WINAPI OpenSemaphoreA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName) { NTSTATUS Status; ANSI_STRING AnsiName; PUNICODE_STRING UnicodeCache; /* Check for a name */ if (lpName) { /* Use TEB Cache */ UnicodeCache = &NtCurrentTeb()->StaticUnicodeString; /* Convert to unicode */ RtlInitAnsiString(&AnsiName, lpName); Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE); if (!NT_SUCCESS(Status)) { /* Conversion failed */ SetLastErrorByStatus(Status); return NULL; } } else { /* We need a name */ SetLastError(ERROR_INVALID_PARAMETER); return NULL; } /* Call the Unicode API */ return OpenSemaphoreW(dwDesiredAccess, bInheritHandle, (LPCWSTR)UnicodeCache->Buffer); }
/************************************************************************* * SHGlobalCounterCreateNamedW [SHLWAPI.423] * * Unicode version of SHGlobalCounterCreateNamedA. */ HANDLE WINAPI SHGlobalCounterCreateNamedW(LPCWSTR lpszName, DWORD iInitial) { static const WCHAR szPrefix[] = { 's', 'h', 'e', 'l', 'l', '.', '\0' }; const int iPrefixLen = 6; WCHAR szBuff[MAX_PATH]; const int iBuffLen = sizeof(szBuff)/sizeof(WCHAR); SECURITY_DESCRIPTOR sd; SECURITY_ATTRIBUTES sAttr, *pSecAttr; HANDLE hRet; TRACE("(%s,%d)\n", debugstr_w(lpszName), iInitial); /* Create Semaphore name */ memcpy(szBuff, szPrefix, (iPrefixLen + 1) * sizeof(WCHAR)); if (lpszName) StrCpyNW(szBuff + iPrefixLen, lpszName, iBuffLen - iPrefixLen); /* Initialise security attributes */ pSecAttr = CreateAllAccessSecurityAttributes(&sAttr, &sd, 0); if (!(hRet = CreateSemaphoreW(pSecAttr , iInitial, MAXLONG, szBuff))) hRet = OpenSemaphoreW(SYNCHRONIZE|SEMAPHORE_MODIFY_STATE, 0, szBuff); return hRet; }