/** * Mutex */ LPDM_MUTEX mutexNew(const char *name) { LPDM_MUTEX m = NULL; #ifdef WIN32 m = CreateMutexA(NULL, FALSE, name); if(m == NULL){ DWORD dwError = GetLastError(); if(dwError == ERROR_ACCESS_DENIED) m = OpenMutexA(SYNCHRONIZE, FALSE, name); } #else pthread_mutexattr_t mutexattr; pthread_mutexattr_init(&mutexattr); m = (LPDM_MUTEX)malloc(sizeof(DM_MUTEX)); m->context = NULL; if(name){ int mutexexist = 0; mutexexist = shm_exist(name); m->context = mmapOpen(name, sizeof(pthread_mutex_t)); m->mutex = (pthread_mutex_t*)m->context->data; if(mutexexist) return m; pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED); pthread_mutexattr_setrobust(&mutexattr, PTHREAD_MUTEX_ROBUST); } else m->mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(m->mutex, &mutexattr); pthread_mutexattr_destroy(&mutexattr); #endif return m; }
// address: 0x4012f8 void _start(int param1, int param2, int param3, int param4, RECT param5, int param6) { int eax; // r24 union { __size32 * x7; unsigned int x8; } eax_1; // r24{257} int ecx; // r25 int edx; // r26 unsigned int edx_1; // r26{338} int esp; // r28 eax = GetCurrentProcessId(); if (eax != 1019) { } CharUpperA(); OpenEventW(); GetDC(); eax = GetCurrentThreadId(); /* Warning: also results in ecx */ if (eax == 621) { ecx = ecx ^ param6; } if (ecx != 0) { } __set_app_type(); GetFileAttributesA(); CharUpperA(); GetProcessHeap(); CharUpperA(); OpenMutexA(); IsWindow(); eax = GetCurrentThreadId(); /* Warning: also results in ecx */ if ((eax & 0xae4) != ecx) { } eax = GetClientRect(0, ¶m5); /* Warning: also results in edx */ eax = eax | param4; if (eax != edx) { eax = (esp - 552); edx = edx ^ param2; edx = edx ^ param3; edx = edx & param1; } eax_1 = eax; edx_1 = edx; edx = edx_1 ^ 0x21cd; flags = SUBFLAGS32(eax_1, edx_1 ^ 0x21cd, eax_1 - (edx_1 ^ 0x21cd)); if (eax_1 != (edx_1 ^ 0x21cd)) { edx = (edx_1 ^ 0x21cd) + (edx_1 ^ 0x21cd) + (eax_1 < (unsigned int)(edx_1 ^ 0x21cd)); eax_1 = eax_1 - 0x3421; flags = SUBFLAGS32(eax_1, 0x3421, eax_1 - 0x3421); } if (eax_1 + edx + CF == 816) { } eax = CreateItemMoniker(); /* Warning: also results in edx */ if ((eax ^ 0x80070057) == 0) { if ((eax ^ 0x80070057) + edx == 0) { } } return; }
HOOKFUNC HANDLE WINAPI MyOpenMutexA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName) { HANDLE rv = OpenMutexA(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 MyOpenMutexA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName) { ENTER(); HANDLE rv = OpenMutexA(dwDesiredAccess, bInheritHandle, lpName); LEAVE(rv); EnterCriticalSection(&s_handleCS); std::set<HANDLE>& handles = s_threadIdHandles[GetCurrentThreadId()]; handles.insert(rv); LeaveCriticalSection(&s_handleCS); return rv; }
// for a receiver to release the mutex if a sender is present void spoutMemoryShare::ReleaseSenderMutex() { HANDLE hMutex = OpenMutexA(MUTEX_ALL_ACCESS, 0, "SpoutMemorySender"); if(hMutex) { #ifdef CONSOLE_DEBUG printf("ReleaseSenderMutex - mutex exists\n"); #endif ReleaseMutex(hMutex); } }
static HANDLE init_mutex(const char *name, DWORD pid) { char new_name[64]; HANDLE handle; sprintf(new_name, "%s%d", name, pid); handle = OpenMutexA(MUTEX_ALL_ACCESS, false, new_name); if (!handle) hlog("Failed to open mutex '%s': %lu", name, GetLastError()); return handle; }
APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex, const char *fname, apr_pool_t *pool) { HANDLE hMutex; void *mutexkey; if (!fname) { /* Reinitializing unnamed mutexes is a noop in the Unix code. */ return APR_SUCCESS; } /* res_name_from_filename turns file into a pseudo-name * without slashes or backslashes, and prepends the \global * prefix on Win2K and later */ mutexkey = res_name_from_filename(fname, 1, pool); #if defined(_WIN32_WCE) hMutex = CreateMutex(NULL, FALSE, mutexkey); if (hMutex && ERROR_ALREADY_EXISTS != GetLastError()) { CloseHandle(hMutex); hMutex = NULL; SetLastError(ERROR_FILE_NOT_FOUND); } #else #if APR_HAS_UNICODE_FS IF_WIN_OS_IS_UNICODE { hMutex = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, mutexkey); } #endif #if APR_HAS_ANSI_FS ELSE_WIN_OS_IS_ANSI { hMutex = OpenMutexA(MUTEX_ALL_ACCESS, FALSE, mutexkey); } #endif #endif if (!hMutex) { return apr_get_os_error(); } *mutex = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t)); (*mutex)->pool = pool; (*mutex)->handle = hMutex; (*mutex)->fname = fname; apr_pool_cleanup_register((*mutex)->pool, *mutex, proc_mutex_cleanup, apr_pool_cleanup_null); return APR_SUCCESS; }
void Entry(void) { HANDLE hMutex; int result=1; Options options; g_controlMsg=RegisterWindowMessageA(CONTROL_MESSAGE_NAME); ZeroFill(&options,sizeof options); ProcessCommandLine(&options); #ifdef _DEBUG options.showWindow=TRUE; #endif hMutex=OpenMutexA(MUTEX_ALL_ACCESS,FALSE,MUTEX_NAME); if(hMutex) { // Already running. ApplyOptions(&options); } else { if(options.nextLayout||options.prevLayout) { // Don't do anything. } else { hMutex=CreateMutexA(0,FALSE,MUTEX_NAME); if(!RunHelpers()) result=1; else { result=Main(&options); ReleaseMutex(hMutex); hMutex=NULL; } PostMessage(HWND_BROADCAST,g_controlMsg,CONTROL_QUIT,0); } } LocalFree(options.pLayoutToSet); options.pLayoutToSet=NULL; ExitProcess(result); }
// for a sender to set a mutex for a receiver to test void spoutMemoryShare::CreateSenderMutex() { HANDLE hMutex = OpenMutexA(MUTEX_ALL_ACCESS, 0, "SpoutMemorySender"); // If no sender is running yet, create a mutex that a receiver can check if (!hMutex) { #ifdef CONSOLE_DEBUG printf("Creating sender mutex\n"); #endif hSenderMutex = CreateMutexA(0, 0, "SpoutMemorySender"); } CloseHandle(hMutex); }
BOOL UniqueApp::IsUnique() { BOOL bRetCode = FALSE; BOOL bResult = FALSE; HANDLE hMutex = NULL; hMutex = OpenMutexA(READ_CONTROL, FALSE, m_szKey); YG_PROCESS_ERROR(!hMutex); bResult = TRUE; Exit0: SAFE_RELEASE_MUTEX(hMutex); return bResult; }
bool CShareMem::Open(std::string strSMName) { bool bResult = false; do { if(strSMName.empty()) break; m_strSMName = strSMName; if(!m_hMutexSyncData) { m_hFileMapObj = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, strSMName.c_str()); if(NULL == m_hFileMapObj) break; m_pMapView = (char *)MapViewOfFile(m_hFileMapObj, FILE_MAP_ALL_ACCESS,0,0,0); if(NULL == m_pMapView) break; std::string strMutexName = strSMName + "Mutex"; m_hMutexSyncData = OpenMutexA(MUTEX_ALL_ACCESS, FALSE, strMutexName.c_str()); if(NULL == m_hMutexSyncData) break; std::string strSemName = strSMName + "Recv"; m_hWait[0] = OpenSemaphoreA(SEMAPHORE_ALL_ACCESS , FALSE, strSemName.c_str()); if(NULL == m_hWait[0]) break; std::string strSemExit = strSMName + "Exit"; m_hWait[1] = OpenSemaphoreA(SEMAPHORE_ALL_ACCESS, FALSE, strSemExit.c_str()); if(NULL == m_hWait[0]) break; m_pWRPos = reinterpret_cast<PSWRPos>(m_pMapView); m_pUserBufBasePos = m_pMapView + sizeof(SWRPos); } m_bSMSuccess = bResult = true; } while (false); if(!bResult) close(); return bResult; }
// for a receiver to check the presence of a sender bool spoutMemoryShare::CheckSenderMutex() { HANDLE hMutex = OpenMutexA(MUTEX_ALL_ACCESS, 0, "SpoutMemorySender"); if(hMutex) { #ifdef CONSOLE_DEBUG // printf("CheckSenderMutex - mutex exists\n"); #endif CloseHandle(hMutex); return true; } else { #ifdef CONSOLE_DEBUG printf("CheckSenderMutex - mutex does not exist\n"); #endif return false; } }
int __cdecl main(int argc_ansi, char** argv_ansi) { DWORD size; register HANDLE mutex, stdout; stdout = GetStdHandle(STD_OUTPUT_HANDLE); mutex = OpenMutexA(SYNCHRONIZE, FALSE, "Global/Rufus_CmdLine"); if (mutex == NULL) goto error; WaitForSingleObject(mutex, INFINITE); goto out; error: WriteFile(stdout, error_msg, sizeof(error_msg), &size, 0); out: ExitProcess(0); }
bool CLogin::CheckLoginFlag(unsigned long uin, const string& strID, bool bCreate, bool bFree) { bool bRetVal = false; HANDLE hUinFlag = NULL, hNameFlag = NULL; if (uin != 0) { char strUin[MAX_256_LEN]; sprintf_s(strUin, "_TQ_%lu_", uin); if (bCreate) { UinMutex = CreateMutexA(NULL, FALSE, strUin); } else { hUinFlag = OpenMutexA(MUTEX_ALL_ACCESS, FALSE, strUin); } if (hUinFlag) { bRetVal = TRUE; if (hUinFlag) { CloseHandle(hUinFlag); hUinFlag = NULL; } } } if (!strID.empty()) { char strName[MAX_256_LEN]; sprintf_s(strName, "_TQ_%s_", strID.c_str()); if (bCreate) { NameMutex = CreateMutexA(NULL, FALSE, strName); } else { hNameFlag = OpenMutexA(MUTEX_ALL_ACCESS, FALSE, strName); } if (hNameFlag) { bRetVal = TRUE; if (hNameFlag) { CloseHandle(hNameFlag); hNameFlag = NULL; } } } if (bFree) { if (UinMutex) { CloseHandle(UinMutex); UinMutex = NULL; } if (NameMutex) { CloseHandle(NameMutex); NameMutex = NULL; } } return bRetVal; }
void am_log_init(int id, int status) { int i; char opened = 0; am_agent_instance_init_init(id); if (am_log_handle == NULL) { am_log_handle = (struct am_shared_log *) malloc(sizeof (struct am_shared_log)); if (am_log_handle == NULL) { return; } } else if (am_log_handle->reader_pid == getpid()) { return; } am_log_handle->reader_pid = getpid(); snprintf(am_log_handle->area_file_name, sizeof (am_log_handle->area_file_name), #ifdef __sun "/am_log_%d" #else AM_GLOBAL_PREFIX"am_log_%d" #endif , id); am_log_handle->area_size = page_size(sizeof (struct am_log)); #ifdef _WIN32 am_log_handle->area_file_id = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD) am_log_handle->area_size, am_log_handle->area_file_name); if (am_log_handle->area_file_id == NULL) return; if (NULL != am_log_handle->area_file_id && GetLastError() == ERROR_ALREADY_EXISTS) { opened = 1; } if (am_log_handle->area_file_id != NULL) { am_log_handle->area = MapViewOfFile(am_log_handle->area_file_id, FILE_MAP_ALL_ACCESS, 0, 0, am_log_handle->area_size); } if (am_log_handle->area != NULL) { if (status == AM_SUCCESS || status == AM_EAGAIN) { struct am_log *log = (struct am_log *) am_log_handle->area; memset(log, 0, am_log_handle->area_size); log->bucket_count = AM_LOG_QUEUE_SIZE; log->bucket_size = AM_LOG_MESSAGE_SIZE; log->in = log->out = log->read_count = log->write_count = 0; for (i = 0; i < AM_MAX_INSTANCES; i++) { struct log_files *f = &log->files[i]; f->fd_audit = f->fd_debug = -1; f->used = AM_FALSE; f->instance_id = 0; f->level_debug = f->level_audit = AM_LOG_LEVEL_NONE; f->max_size_debug = f->max_size_audit = 0; } am_log_lck.exit = CreateEvent(NULL, FALSE, FALSE, get_global_name(AM_GLOBAL_PREFIX"am_log_exit", id)); if (am_log_lck.exit == NULL && GetLastError() == ERROR_ACCESS_DENIED) { am_log_lck.exit = OpenEventA(SYNCHRONIZE, TRUE, get_global_name(AM_GLOBAL_PREFIX"am_log_exit", id)); } am_log_lck.lock = CreateMutex(NULL, FALSE, get_global_name(AM_GLOBAL_PREFIX"am_log_lock", id)); if (am_log_lck.lock == NULL && GetLastError() == ERROR_ACCESS_DENIED) { am_log_lck.lock = OpenMutexA(SYNCHRONIZE, TRUE, get_global_name(AM_GLOBAL_PREFIX"am_log_lock", id)); } am_log_lck.new_data_cond = CreateEvent(NULL, FALSE, FALSE, get_global_name(AM_GLOBAL_PREFIX"am_log_queue_empty", id)); if (am_log_lck.new_data_cond == NULL && GetLastError() == ERROR_ACCESS_DENIED) { am_log_lck.new_data_cond = OpenEventA(SYNCHRONIZE, TRUE, get_global_name(AM_GLOBAL_PREFIX"am_log_queue_empty", id)); } am_log_lck.new_space_cond = CreateEvent(NULL, FALSE, FALSE, get_global_name(AM_GLOBAL_PREFIX"am_log_queue_overflow", id)); if (am_log_lck.new_space_cond == NULL && GetLastError() == ERROR_ACCESS_DENIED) { am_log_lck.new_space_cond = OpenEventA(SYNCHRONIZE, TRUE, get_global_name(AM_GLOBAL_PREFIX"am_log_queue_overflow", id)); } log->owner = getpid(); am_log_handle->reader_thr = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) am_log_worker, NULL, 0, NULL); } } #else am_log_handle->area_file_id = shm_open(am_log_handle->area_file_name, O_CREAT | O_EXCL | O_RDWR, 0666); if (am_log_handle->area_file_id == -1 && EEXIST != errno) { return; } if (am_log_handle->area_file_id == -1) { /* already there, open without O_EXCL and go; if * something goes wrong, close and cleanup */ am_log_handle->area_file_id = shm_open(am_log_handle->area_file_name, O_RDWR, 0666); if (am_log_handle->area_file_id == -1) { fprintf(stderr, "am_log_init() shm_open failed (%d)\n", errno); free(am_log_handle); am_log_handle = NULL; return; } else { opened = 1; } } else { /* we just created the shm area, must setup; if * something goes wrong, delete the shm area and * cleanup */ if (ftruncate(am_log_handle->area_file_id, am_log_handle->area_size) == -1) { fprintf(stderr, "am_log_init() ftruncate failed\n"); return; } } if (am_log_handle->area_file_id != -1) { am_log_handle->area = mmap(NULL, am_log_handle->area_size, PROT_READ | PROT_WRITE, MAP_SHARED, am_log_handle->area_file_id, 0); if (am_log_handle->area == MAP_FAILED) { fprintf(stderr, "am_log_init() mmap failed (%d)\n", errno); free(am_log_handle); am_log_handle = NULL; } else { pthread_mutexattr_t exit_attr, lock_attr; pthread_condattr_t new_data_attr, new_space_attr; struct am_log *log = (struct am_log *) am_log_handle->area; pthread_mutexattr_init(&exit_attr); pthread_mutexattr_init(&lock_attr); pthread_condattr_init(&new_data_attr); pthread_condattr_init(&new_space_attr); pthread_mutexattr_setpshared(&exit_attr, PTHREAD_PROCESS_SHARED); pthread_mutexattr_setpshared(&lock_attr, PTHREAD_PROCESS_SHARED); pthread_condattr_setpshared(&new_data_attr, PTHREAD_PROCESS_SHARED); pthread_condattr_setpshared(&new_space_attr, PTHREAD_PROCESS_SHARED); if (status == AM_SUCCESS || status == AM_EAGAIN) { memset(log, 0, am_log_handle->area_size); log->bucket_count = AM_LOG_QUEUE_SIZE; log->bucket_size = AM_LOG_MESSAGE_SIZE; log->in = log->out = log->read_count = log->write_count = 0; for (i = 0; i < AM_MAX_INSTANCES; i++) { struct log_files *f = &log->files[i]; f->fd_audit = f->fd_debug = -1; f->used = AM_FALSE; f->instance_id = 0; f->level_debug = f->level_audit = AM_LOG_LEVEL_NONE; f->max_size_debug = f->max_size_audit = 0; } pthread_mutex_init(&log->exit, &exit_attr); pthread_mutex_init(&log->lock, &lock_attr); pthread_cond_init(&log->new_data_cond, &new_data_attr); pthread_cond_init(&log->new_space_cond, &new_space_attr); pthread_mutex_lock(&log->exit); pthread_create(&am_log_handle->reader_thr, NULL, am_log_worker, NULL); log->owner = getpid(); } pthread_mutexattr_destroy(&exit_attr); pthread_mutexattr_destroy(&lock_attr); pthread_condattr_destroy(&new_data_attr); pthread_condattr_destroy(&new_space_attr); } } #endif }
void fn004012F8(word32 edx, word32 ebp, word32 dwArg00, word32 dwArg01, word32 dwArg05, word32 dwArg0B) { // def fp // def dwArg00 // def dwArg01 // def dwLoc0120 // def dwLocB8 // def dwLoc0180 // def dwLoc03 // def dwLoc0154 // def dwLoc01B4 // def dwArg0B // def dwLoc010E // def dwLoc0118 // def dwLoc4C // def dwLoc8C // def dwLoc0234 // def dwLocBD // def dwLocC3 // def dwLoc0225 // def dwLoc021C // def dwLoc0227 // def dwLoc0140 // def dwArg05 eax_7 = GetCurrentProcessId(); if (eax_7 != 0x000003FB) ; dwLoc0268_28 = fp - 0x00000004; v15_29 = fp - 0x00000098; dwLoc0268_30 = fp - 0x00000098; CharUpperA(fp - 0x00000098); ecx_36 = &fp->dwFFFFFD98; dwLoc0268_38 = &fp->dwFFFFFD98; dwLoc026C_41 = 0x00000000; dwLoc0270_43.u0 = 0x00000000; OpenEventW(0x00000000, 0x00000000, &fp->dwFFFFFD98); dwLoc0268_52 = 0x00000000; GetDC(0x00000000); eax_55 = GetCurrentThreadId(); if (eax_55 == 0x0000026D) ecx_595 = &fp->dwFFFFFD98 ^ dwArg05; // ecx_64 = PHI(ecx_36, ecx_595) esp_68 = fp - 0x00000268; fp->dwFFFFFD98 = 0x00000002; if (ecx_64 != 0x00000000) ; __set_app_type(); dwLoc026C_85 = fp - 0x00000004; v20_86 = fp - 0x000000B4; dwLoc026C_87 = fp - 0x000000B4; GetFileAttributesA(fp - 0x000000B4); dwLoc026C_92 = &fp->dwFFFFFD98; CharUpperA(&fp->dwFFFFFD98); GetProcessHeap(); dwLoc026C_98 = &fp->dwFFFFFD98; eax_99 = CharUpperA(&fp->dwFFFFFD98); dwLoc026C_107 = &fp->dwFFFFFD98; esp_108 = &fp->tFFFFFD90; fp->tFFFFFD90.u0 = 0x00000000; eax_110 = eax_99 & 0x00000008; dwLoc0274_112 = eax_99 & 0x00000008; eax_113 = OpenMutexA(eax_99 & 0x00000008, 0x00000000, &fp->dwFFFFFD98); ecx_115 = &fp->dwFFFFFD98 & 0x0000011C; eax_118 = eax_113 - dwArg00; ecx_120 = ecx_115 - dwArg01; dwLoc026C_122 = eax_118; IsWindow(eax_118); v22_126 = dwLoc0120 - (fp - 0x00000004); dwLoc0120_127 = v22_126; edx_128 = fp - 0x00000004 ^ 0x00000611; eax_129 = GetCurrentThreadId(); eax_130 = eax_129 & 0x00000AE4; if ((eax_129 & 0x00000AE4) != ecx_120) { edx_564 = edx_128 | ecx_120; ecx_566 = ecx_120 | dwLoc0140; v25_570 = dwLocB8 + ecx_566; dwLocB8_571 = v25_570; ecx_572 = fp - 0x00000004; } // dwLocB8_142 = PHI(dwLocB8, dwLocB8_571) // ecx_143 = PHI(ecx_120, ecx_572) // edx_144 = PHI(edx_128, edx_564) dwLoc026C_148 = fp - 0x00000004; v26_149 = fp - 0x00000060; dwLoc026C_150 = fp - 0x00000060; esp_151 = &fp->tFFFFFD90; fp->tFFFFFD90.u0 = 0x00000000; eax_153 = GetClientRect(0x00000000, fp - 0x00000060); eax_156 = eax_153 | dwLoc0180; if (eax_156 != edx_144) { eax_552 = &fp->dwFFFFFD98; edx_556 = edx_144 ^ dwLoc0225; edx_558 = edx_556 ^ dwLoc021C; edx_560 = edx_558 & dwLoc0227; } // edx_165 = PHI(edx_144, edx_560) // eax_166 = PHI(eax_156, eax_552) edx_169 = edx_165 ^ 0x000021CD; SCZO_170 = cond(eax_166 - edx_169); C_173 = SCZO_170; if (eax_166 != edx_169) { edx_534 = edx_169 * 0x00000002 + (eax_166 <u edx_169); ecx_535 = ecx_143 + v22_126; eax_542 = eax_166 - 0x00003421; SCZO_545 = cond(eax_542); C_548 = SCZO_545; } // ecx_179 = PHI(ecx_143, ecx_535) // edx_180 = PHI(edx_169, edx_534) // eax_181 = PHI(eax_166, eax_542) // C_182 = PHI(C_173, C_548) esp_183 = &fp->tFFFFFD90; fp->tFFFFFD90.u0 = 0x00000000; eax_185 = eax_181 + edx_180 + C_182; if (eax_185 == 0x00000330) { edx_530 = edx_180 ^ 0x00001DF0; ecx_531 = ecx_179 - 0x0000292F; } // ecx_193 = PHI(ecx_179, ecx_531) // edx_194 = PHI(edx_180, edx_530) dwLoc0274_197 = 0x00000000; eax_198 = CreateItemMoniker(0x00000000, 0x00000000, null); eax_200 = eax_198 ^ 0x80070057; if ((eax_198 ^ 0x80070057) == 0x00000000) { eax_271 = (eax_198 ^ 0x80070057) + edx_194; if (eax_271 == 0x00000000) { edx_521 = &fp->dwFFFFFD98; eax_522 = eax_271 - dwLocB8_142; ecx_525 = ecx_193 & dwLocBD; ecx_527 = ecx_525 - dwLocC3; } // ecx_278 = PHI(ecx_193, ecx_527) // edx_279 = PHI(edx_194, edx_521) // eax_280 = PHI(eax_271, eax_522) esp_281 = &fp->dwFFFFFD94; fp->dwFFFFFD94 = eax_280; esp_283 = &fp->tFFFFFD90; fp->tFFFFFD90 = ecx_278; esp_285 = &fp->dwFFFFFD8C; fp->dwFFFFFD8C = edx_279; ecx_299 = ecx_278 & 0x00002F37; ecx_305 = ecx_299 + dwLoc03; if (fp - 0x00000004 != ecx_305) ecx_508 = &fp->dwFFFFFD98; // ecx_316 = PHI(ecx_305, ecx_508) if (ecx_316 != 0x00000000) ; dwLoc0294_329 = 0x00002000; dwLoc0298_334 = 0x00000000; eax_337 = VirtualAlloc(0x00000000, 0x00002000, 0x00001000, 0x00000040); dwLoc0218_340 = eax_337; if (dwLoc0154 == ecx_316) { ecx_487 = ecx_316 + 0x00001D56; ecx_491 = ecx_487 ^ 0x00002863; } // ecx_350 = PHI(ecx_316, ecx_491) ecx_354 = ecx_350 - dwLoc01B4; ecx_358 = ecx_354 | dwArg0B; eax_361 = fp - 0x00000004 ^ dwLoc010E; eax_363 = eax_361 + dwLoc0118; edi_365 = &globals->dw412E33; ecx_366 = ecx_358 + eax_363; esi_367 = eax_337; edx_370 = fp + 0xFFFFDB3F; dwLoc68_371 = 0xA37A6ED7; ecx_372 = ecx_366 - 0x000028C3; if (ecx_366 != 0x000028C3) { ecx_475 = ecx_366 - 0x000028C3 | 0x000028C3; goto l00401606; } l00401606: do { // dwLoc68_378 = PHI(dwLoc68_371, dwLoc68_371, dwLoc68_393) // edi_382 = PHI(edi_365, edi_365, edi_413) // esi_383 = PHI(esi_367, esi_367, esi_415) // ecx_384 = PHI(ecx_372, ecx_475, ecx_402) // edx_385 = PHI(edx_370, edx_370, edx_414) // eax_386 = PHI(eax_363, eax_363, eax_424) ebx_388 = *edi_382; ecx_390 = ecx_384 ^ dwLoc4C; ebx_391 = ebx_388 + dwLoc68_378; v44_392 = dwLoc68_378 + 0x623ED7F6; dwLoc68_393 = v44_392; ecx_394 = ecx_390 & edx_385; C_395 = false; edx_396 = edx_385 - eax_386; Mem397[esi_383 + 0x00000000:word32] = ebx_391; eax_398 = eax_386 | 0x00002279; edi_400 = edi_382 + 20138706; ecx_402 = ecx_394 - dwLoc8C; esi_404 = esi_383 + 0xA596E2A8; if (eax_398 == 0x000003EF) { eax_466 = eax_398 | 0x000038A7; edx_468 = &fp->dwFFFFFD98 - ecx_402; eax_469 = (eax_398 | 0x000038A7) & 0x00003565; } // edx_410 = PHI(edx_396, edx_468) // eax_412 = PHI(eax_398, eax_469) edi_413 = edi_400 + 0x04CD2B4C; edx_414 = edx_410 + 0x00003BBE; esi_415 = esi_404 + 0x5A691D5C; if ((dwLoc0234 & ecx_402) != 0x00000000) eax_461 = eax_412 ^ 0x000034ED; // eax_424 = PHI(eax_412, eax_461) } while (edi_413 != &globals->dw413EBF); dwLoc0218_340(); if (eax_424 == edx_414) ; }
////////////////////////////////////////////////////////////////////////// // This is the routine where we create the data being output by the Virtual // Camera device. // Modified as per red5 to allow for dropped frames and reset of time stamps // // http://comSender.googlecode.com/svn/trunk/ // ////////////////////////////////////////////////////////////////////////// HRESULT CVCamStream::FillBuffer(IMediaSample *pms) { unsigned int imagesize, width, height; long l, lDataLen; bool bResult = false; DWORD dwSpoutPanel = 0; HRESULT hr=S_OK;; BYTE *pData; VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER *) m_mt.Format(); // If graph is inactive stop cueing samples if(!m_pParent->IsActive()) { return S_FALSE; } // first get the timing right // create some working info REFERENCE_TIME rtNow, rtDelta, rtDelta2=0; // delta for dropped, delta 2 for sleep. REFERENCE_TIME avgFrameTime = ((VIDEOINFOHEADER*)m_mt.pbFormat)->AvgTimePerFrame; // Simple method - avoids "stuttering" in yawcam but VLC fails ! /* rtNow = m_rtLastTime; m_rtLastTime += avgFrameTime; pms->SetTime(&rtNow, &m_rtLastTime); pms->SetSyncPoint(TRUE); */ // What Time is it REALLY ??? // m_pClock is returned NULL with Skype, but OK for YawCam and VLC m_pParent->GetSyncSource(&m_pClock); if(m_pClock) { m_pClock->GetTime(&refSync1); m_pClock->Release(); } else { refSync1 = NumFrames*avgFrameTime; } if(NumFrames <= 1) { // initiate values refStart = refSync1; // FirstFrame No Drop. refSync2 = 0; } // Set the timestamps that will govern playback frame rate. // The current time is the sample's start rtNow = m_rtLastTime; m_rtLastTime = avgFrameTime + m_rtLastTime; // IAMDropppedFrame. We only have avgFrameTime to generate image. // Find generated stream time and compare to real elapsed time rtDelta=((refSync1-refStart)-(((NumFrames)*avgFrameTime)-avgFrameTime)); if(rtDelta-refSync2 < 0) { //we are early rtDelta2=rtDelta-refSync2; if( abs(rtDelta2/10000)>=1) Sleep(abs(rtDelta2/10000)); } // endif (rtDelta-refSync2 < 0) else if(rtDelta/avgFrameTime>NumDroppedFrames) { // new dropped frame NumDroppedFrames = rtDelta/avgFrameTime; // Figure new RT for sleeping refSync2 = NumDroppedFrames*avgFrameTime; // Our time stamping needs adjustment. // Find total real stream time from start time rtNow = refSync1-refStart; m_rtLastTime = rtNow+avgFrameTime; pms->SetDiscontinuity(true); } // end else if(rtDelta/avgFrameTime>NumDroppedFrames) // The SetTime method sets the stream times when this sample should begin and finish. hr = pms->SetTime(&rtNow, &m_rtLastTime); // Set true on every sample for uncompressed frames hr = pms->SetSyncPoint(true); // ============== END OF INITIAL TIMING ============ // Check access to the sample's data buffer pms->GetPointer(&pData); if(pData == NULL) { return NOERROR; } // Get the current frame size for texture transfers imagesize = (unsigned int)pvi->bmiHeader.biSizeImage; width = (unsigned int)pvi->bmiHeader.biWidth; height = (unsigned int)pvi->bmiHeader.biHeight; if(width == 0 || height == 0) { return NOERROR; } // Don't do anything if disconnected because it will already have connected // previously and something has changed. It can only disconnect after it has connected. if(!bDisconnected) { // If connected, sizes should be OK, but check again unsigned int size = (unsigned int)pms->GetSize(); imagesize = width*height*3; // Retrieved above if(size != imagesize) { if(bInitialized) receiver.ReleaseReceiver(); bInitialized = false; bDisconnected = true; // don't try again return NOERROR; } // Quit if nothing running at all if(!receiver.GetActiveSender(g_ActiveSender)) { if(bInitialized) { receiver.ReleaseReceiver(); bInitialized = false; // Reset the registry entries for SpoutCam dwSpoutPanel = 0; receiver.spout.interop.spoutdx.WriteDwordToRegistry(dwSpoutPanel, "Software\\Leading Edge\\SpoutCam\\", "SpoutPanel"); receiver.spout.WritePathToRegistry("", "Software\\Leading Edge\\SpoutCam\\", "Sender"); } goto ShowStatic; } // Has SpoutPanel been opened HANDLE hMutex = OpenMutexA(MUTEX_ALL_ACCESS, 0, "SpoutPanel"); if(hMutex) { bSpoutPanelOpened = true; // We opened it so close it, otherwise it is never released CloseHandle(hMutex); } else { // Wait for SpoutPanel to close if(bSpoutPanelOpened) { // Check the registry for the SpoutPanel flag dwSpoutPanel = 0; if(receiver.spout.interop.spoutdx.ReadDwordFromRegistry(&dwSpoutPanel, "Software\\Leading Edge\\SpoutCam\\", "SpoutPanel")) { if(dwSpoutPanel == 1) { if(bInitialized) receiver.ReleaseReceiver(); bInitialized = false; // start again } } // Reset the registry flag dwSpoutPanel = 0; receiver.spout.interop.spoutdx.WriteDwordToRegistry(dwSpoutPanel, "Software\\Leading Edge\\SpoutCam\\", "SpoutPanel"); bSpoutPanelOpened = false; } } // end SpoutPanel check // everything ready if(!bInitialized) { // If not initialized, look for a sender if(receiver.GetActiveSender(g_SenderName)) { // Initialize OpenGl if is has not been done if(!bGLinitialized) { if(InitOpenGL()) { // Find out whether bgra extensions are supported at runtime // bBGRA = receiver.spout.interop.IsBGRAavailable(); bBGRA = isExtensionSupported("GL_EXT_bgra"); bGLinitialized = true; // Call OpenSpout so that OpenGL extensions are loaded receiver.spout.OpenSpout(); } else { bGLinitialized = false; bDisconnected = true; // don't try again return NOERROR; } } // Found a sender so initialize the receiver if(receiver.CreateReceiver(g_SenderName, g_SenderWidth, g_SenderHeight)) { // Create a local rgba OpenGL texture to receive the sender's shared texture CreateSenderTexture(g_SenderWidth, g_SenderHeight); // Create a local rgb buffer for data tranfser from the shared texture if(g_senderBuffer) free((void *)g_senderBuffer); g_senderBuffer = (unsigned char *)malloc(g_SenderWidth*g_SenderHeight*3*sizeof(unsigned char)); // Write the sender path to the registry for SpoutPanel receiver.spout.WritePathToRegistry(g_SenderName, "Software\\Leading Edge\\SpoutCam", "Sender"); bInitialized = true; NumFrames++; return NOERROR; // no more for this frame } else { // TODO : what } } // end found a sender } // end not initialized else { // Receive the shared texture or memoryshare pixels into a local rgba OpenGL texture // The shared texture is inverted at the same time, so no software inversion is needed. width = g_SenderWidth; // for sender size check height = g_SenderHeight; if(receiver.ReceiveTexture(g_SenderName, width, height, g_senderTexture, GL_TEXTURE_2D, bInvert)) { // Sender size check if(g_SenderWidth != width || g_SenderHeight != height) { g_SenderWidth = width; g_SenderHeight = height; // restart to initialize with the new size receiver.ReleaseReceiver(); bInitialized = false; NumFrames++; return NOERROR; } glBindTexture(GL_TEXTURE_2D, g_senderTexture); #ifdef GL_EXT_bgra // Or else GL_BGR_EXT is not defined if (bBGRA && g_SenderWidth == g_Width && g_SenderHeight == g_Height) { // If bgra is supported at runtime and the sizes match, transfer the // texture data directly to the filter pixel buffer using bgr format. glGetTexImage(GL_TEXTURE_2D, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, (void *)pData); } else #endif { // If GL_EXT_bgra is not supported by the compiler, or bgra is not // supported at runtime, or the sender and filter are different sizes, // load the sender buffer with rgb data for software conversion to bgr. glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, g_senderBuffer); } glBindTexture(GL_TEXTURE_2D, 0); if(g_SenderWidth != g_Width || g_SenderHeight != g_Height) { // For different sender and filter sizes, resample the rgb sender buffer into the bgr filter buffer. rgb2bgrResample(g_senderBuffer, (unsigned char *)pData, g_SenderWidth, g_SenderHeight, g_Width, g_Height); } else if(!bBGRA) { // Otherwise if the buffer dimensions match but bgra is not supported, convert from rgb to bgr. rgb2bgr(g_senderBuffer, (unsigned char *)pData, g_SenderWidth, g_SenderHeight); } NumFrames++; return NOERROR; } // endif received OK else { receiver.ReleaseReceiver(); bInitialized = false; } // endif received texture OK } // endif initialized } // endif not disconnected ShowStatic : // drop through to default static image if it did not work pms->GetPointer(&pData); lDataLen = pms->GetSize(); for(l = 0; l <lDataLen; ++l) pData[l] = rand(); NumFrames++; return NOERROR; } // FillBuffer
ComputeShader::ComputeShader( Device& _Device, const char* _pShaderFileName, const char* _pShaderCode, D3D_SHADER_MACRO* _pMacros, const char* _pEntryPoint, ID3DInclude* _pIncludeOverride ) : Component( _Device ) , m_pCS( NULL ) , m_pShaderPath( NULL ) #if defined(_DEBUG) || !defined(GODCOMPLEX) , m_LastShaderModificationTime( 0 ) #endif #ifdef COMPUTE_SHADER_COMPILE_THREADED , m_hCompileThread( 0 ) #endif { ASSERT( Shader::ms_LoadFromBinary || _pShaderCode != NULL, "Shader code is NULL!" ); m_pIncludeOverride = _pIncludeOverride; m_bHasErrors = false; // Store the default NULL pointer to point to the shader path #if defined(_DEBUG) || !defined(GODCOMPLEX) m_pShaderFileName = CopyString( _pShaderFileName ); #endif #ifndef GODCOMPLEX m_pShaderPath = GetShaderPath( _pShaderFileName ); m_Pointer2FileName.Add( NULL, m_pShaderPath ); #endif #if defined(_DEBUG) && defined(WATCH_SHADER_MODIFICATIONS) if ( _pShaderFileName != NULL ) { // Just ensure the file exists ! FILE* pFile; fopen_s( &pFile, _pShaderFileName, "rb" ); ASSERT( pFile != NULL, "Compute Shader file not found => You can ignore this assert but compute shader file will NOT be watched for modification!" ); fclose( pFile ); // Register as a watched shader ms_WatchedShaders.Add( _pShaderFileName, this ); #ifndef COMPUTE_SHADER_COMPILE_AT_RUNTIME m_LastShaderModificationTime = GetFileModTime( _pShaderFileName ); #endif } #endif m_pEntryPointCS = _pEntryPoint; if ( _pMacros != NULL ) { D3D_SHADER_MACRO* pMacro = _pMacros; while ( pMacro->Name != NULL ) pMacro++; int MacrosCount = int( 1 + pMacro - _pMacros ); m_pMacros = new D3D_SHADER_MACRO[MacrosCount]; memcpy( m_pMacros, _pMacros, MacrosCount*sizeof(D3D_SHADER_MACRO) ); } else m_pMacros = NULL; #ifdef COMPUTE_SHADER_COMPILE_THREADED // Create the mutex for compilation exclusivity m_hCompileMutex = CreateMutexA( NULL, false, m_pShaderFileName ); if ( m_hCompileMutex == NULL ) m_hCompileMutex = OpenMutexA( SYNCHRONIZE, false, m_pShaderFileName ); // Try and reuse any existing mutex ASSERT( m_hCompileMutex != 0, "Failed to create compilation mutex!" ); #endif #ifndef COMPUTE_SHADER_COMPILE_AT_RUNTIME #ifdef COMPUTE_SHADER_COMPILE_THREADED ASSERT( false, "The COMPUTE_SHADER_COMPILE_THREADED option should only work in pair with the COMPUTE_SHADER_COMPILE_AT_RUNTIME option! (i.e. You CANNOT define COMPUTE_SHADER_COMPILE_THREADED without defining COMPUTE_SHADER_COMPILE_AT_RUNTIME at the same time!)" ); #endif // Compile immediately CompileShaders( _pShaderCode ); #endif }
am_shm_t *am_shm_create(const char *name, size_t usize) { struct mem_pool *pool = NULL; size_t size; char opened = AM_FALSE; void *area = NULL; am_shm_t *ret = NULL; #ifdef _WIN32 char dll_path[AM_URI_SIZE]; DWORD error = 0; HMODULE hm = NULL; void *caller = _ReturnAddress(); #else int fdflags; int error = 0; #endif ret = calloc(1, sizeof(am_shm_t)); if (ret == NULL) return NULL; #ifdef _WIN32 if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) caller, &hm) && GetModuleFileNameA(hm, dll_path, sizeof(dll_path) - 1) > 0) { PathRemoveFileSpecA(dll_path); strcat(dll_path, FILE_PATH_SEP); snprintf(ret->name[0], sizeof(ret->name[0]), AM_GLOBAL_PREFIX"%s_l", name); /* mutex/semaphore */ snprintf(ret->name[1], sizeof(ret->name[1]), AM_GLOBAL_PREFIX"%s_s", name); /* shared memory name */ snprintf(ret->name[2], sizeof(ret->name[2]), "%s.."FILE_PATH_SEP"log"FILE_PATH_SEP"%s_f", dll_path, name); /* shared memory file name */ snprintf(ret->name[3], sizeof(ret->name[3]), AM_GLOBAL_PREFIX"%s_sz", name); /* shared memory name for global_size */ } else { ret->error = AM_NOT_FOUND; return ret; } #else snprintf(ret->name[0], sizeof(ret->name[0]), "/%s_l", name); /* mutex/semaphore */ snprintf(ret->name[1], sizeof(ret->name[1]), #ifdef __sun "/%s_s" #else "%s_s" #endif , name); /* shared memory name */ #endif size = page_size(usize + SIZEOF_mem_pool); /* need at least the size of the mem_pool header */ #ifdef _WIN32 ret->h[0] = CreateMutexA(NULL, TRUE, ret->name[0]); error = GetLastError(); if (ret->h[0] != NULL && error == ERROR_ALREADY_EXISTS) { do { error = WaitForSingleObject(ret->h[0], INFINITE); } while (error == WAIT_ABANDONED); } else { if (error == ERROR_ACCESS_DENIED) { ret->h[0] = OpenMutexA(SYNCHRONIZE, FALSE, ret->name[0]); } if (ret->h[0] == NULL) { ret->error = error; return ret; } } ret->h[1] = CreateFileA(ret->name[2], GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING, NULL); error = GetLastError(); if (ret->h[1] == INVALID_HANDLE_VALUE && error == ERROR_FILE_EXISTS) { ret->h[1] = CreateFileA(ret->name[2], GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING, NULL); error = GetLastError(); if (ret->h[1] != INVALID_HANDLE_VALUE) { opened = AM_TRUE; size = GetFileSize(ret->h[1], NULL); } } if (ret->h[1] == INVALID_HANDLE_VALUE || error != 0) { CloseHandle(ret->h[0]); ret->error = error; am_shm_unlock(ret); return ret; } if (!opened) { ret->h[2] = CreateFileMappingA(ret->h[1], NULL, PAGE_READWRITE, 0, (DWORD) size, ret->name[1]); error = GetLastError(); } else { ret->h[2] = OpenFileMappingA(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, ret->name[1]); error = GetLastError(); if (ret->h[2] == NULL && error == ERROR_FILE_NOT_FOUND) { ret->h[2] = CreateFileMappingA(ret->h[1], NULL, PAGE_READWRITE, 0, (DWORD) size, ret->name[1]); error = GetLastError(); } } if (ret->h[2] == NULL || error != 0) { CloseHandle(ret->h[0]); CloseHandle(ret->h[1]); ret->error = error; am_shm_unlock(ret); return ret; } area = MapViewOfFile(ret->h[2], FILE_MAP_ALL_ACCESS, 0, 0, 0); error = GetLastError(); if (area == NULL || (error != 0 && error != ERROR_ALREADY_EXISTS)) { CloseHandle(ret->h[0]); CloseHandle(ret->h[1]); CloseHandle(ret->h[2]); ret->error = error; am_shm_unlock(ret); return ret; } ret->h[3] = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD) sizeof(size_t), ret->name[3]); if (ret->h[3] == NULL) { ret->error = GetLastError(); CloseHandle(ret->h[0]); CloseHandle(ret->h[1]); CloseHandle(ret->h[2]); am_shm_unlock(ret); return ret; } ret->global_size = MapViewOfFile(ret->h[3], FILE_MAP_ALL_ACCESS, 0, 0, 0); if (ret->global_size == NULL) { ret->error = GetLastError(); CloseHandle(ret->h[0]); CloseHandle(ret->h[1]); CloseHandle(ret->h[2]); CloseHandle(ret->h[3]); am_shm_unlock(ret); return ret; } *(ret->global_size) = ret->local_size = size; #else ret->lock = mmap(NULL, sizeof(pthread_mutex_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); if (ret->lock == MAP_FAILED) { ret->error = errno; return ret; } else { pthread_mutexattr_t attr; pthread_mutex_t *lock = (pthread_mutex_t *) ret->lock; pthread_mutexattr_init(&attr); pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); #if defined(__sun) #if defined(__SunOS_5_10) #if defined(_POSIX_THREAD_PRIO_INHERIT) pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP); #endif #else pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST); #endif #endif #if defined(LINUX) pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP); #endif pthread_mutex_init(lock, &attr); pthread_mutexattr_destroy(&attr); } ret->global_size = mmap(NULL, sizeof(size_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); if (ret->global_size == MAP_FAILED) { ret->error = errno; return ret; } *(ret->global_size) = ret->local_size = size; am_shm_lock(ret); ret->fd = shm_open(ret->name[1], O_CREAT | O_EXCL | O_RDWR, 0666); error = errno; if (ret->fd == -1 && error != EEXIST) { munmap(ret->lock, sizeof(pthread_mutex_t)); ret->error = error; am_shm_unlock(ret); return ret; } if (ret->fd == -1) { ret->fd = shm_open(ret->name[1], O_RDWR, 0666); error = errno; if (ret->fd == -1) { munmap(ret->lock, sizeof(pthread_mutex_t)); ret->error = error; am_shm_unlock(ret); return ret; } /* reset FD_CLOEXEC */ fdflags = fcntl(ret->fd, F_GETFD); fdflags &= ~FD_CLOEXEC; fcntl(ret->fd, F_SETFD, fdflags); /* try with just a header */ area = mmap(NULL, SIZEOF_mem_pool, PROT_READ | PROT_WRITE, MAP_SHARED, ret->fd, 0); if (area == MAP_FAILED) { ret->error = errno; am_shm_unlock(ret); return ret; } size = ((struct mem_pool *) area)->size; if (munmap(area, SIZEOF_mem_pool) == -1) { ret->error = errno; am_shm_unlock(ret); return ret; } area = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ret->fd, 0); if (area == MAP_FAILED) { ret->error = errno; am_shm_unlock(ret); return ret; } opened = AM_TRUE; } else { /* reset FD_CLOEXEC */ fdflags = fcntl(ret->fd, F_GETFD); fdflags &= ~FD_CLOEXEC; fcntl(ret->fd, F_SETFD, fdflags); if (ftruncate(ret->fd, size) == -1) { ret->error = errno; am_shm_unlock(ret); return ret; } area = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ret->fd, 0); if (area == MAP_FAILED) { ret->error = errno; am_shm_unlock(ret); return ret; } } #endif ret->init = !opened; pool = (struct mem_pool *) area; if (ret->init) { struct mem_chunk *e = (struct mem_chunk *) ((char *) pool + SIZEOF_mem_pool); pool->size = size; pool->user_offset = 0; pool->open = 1; pool->resize = 0; /* add all available (free) space as one chunk in a freelist */ e->used = 0; e->usize = 0; e->size = pool->size - SIZEOF_mem_pool; e->lh.next = e->lh.prev = 0; /* update head prev/next pointers */ pool->lh.next = pool->lh.prev = AM_GET_OFFSET(pool, e); } else { if (pool->user_offset > 0) { ret->user = AM_GET_POINTER(pool, pool->user_offset); } pool->open++; } ret->pool = pool; ret->error = 0; am_shm_unlock(ret); return ret; }
HANDLE WINAPI Hook_OpenMutexA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName) { if (lpName != nullptr && strcmp(lpName, "report") == 0) lpName = mutexName; return OpenMutexA(dwDesiredAccess, bInheritHandle, lpName); }