void KillGLTextures() { if(bHasTextures) { glDeleteBuffers(2, gltextures); bHasTextures = FALSE; } DestroySharedMemory(); }
void ClearD3D11Data() { bHasTextures = false; texData = NULL; sharedHandle = NULL; SafeRelease(copyTextureGame); DestroySharedMemory(); }
void ClearD3D11Data() { bHasTextures = false; for(UINT i=0; i<2; i++) { SafeRelease(d3d11Textures[i]); } DestroySharedMemory(); }
void ClearD3D101Data() { bHasTextures = false; texData = NULL; sharedHandle = NULL; SafeRelease(copyD3D101TextureGame); DestroySharedMemory(); keepAliveTime = 0; resetCount++; logOutput << CurrentTimeString() << "---------------------- Cleared D3D10.1 Capture ----------------------" << endl; }
bool IProtocol::DeallocShmem(Shmem& aMem) { bool ok = DestroySharedMemory(aMem); #ifdef DEBUG if (!ok) { if (mSide == ChildSide) { FatalError("bad Shmem"); } else { NS_WARNING("bad Shmem"); } return false; } #endif // DEBUG aMem.forget(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead()); return ok; }
void ClearD3D11Data() { bHasTextures = false; if(texData) texData->lastRendered = -1; texData = NULL; for(UINT i=0; i<2; i++) { SafeRelease(keyedMutexes[i]); SafeRelease(sharedTextures[i]); sharedHandles[i] = NULL; } SafeRelease(copyTextureGame); SafeRelease(copyTextureIntermediary); SafeRelease(shareDevice); DestroySharedMemory(); }
int CreateSharedMemory ( void ) { struct stat statbuf; char *Path = NULL; struct group *grp; struct shmid_ds shm_info; #if !MMAP if ( ((Path = getenv("PKCS11_SHMEM_FILE")) == NULL ) || ( Path[0] == '\0' ) ) { Path = TOK_PATH; } InfoLog( "Shared memory file is %s", Path); // Get shared memory key token all users of the shared memory // need to get the same token if ( stat(Path, &statbuf) < 0 ) { ErrLog("Shared Memory Key Token creation file does not exist"); return FALSE; } // SAB Get the group information for the PKCS#11 group... fail if // it does not exist grp = getgrnam("pkcs11"); if ( !grp ) { ErrLog("Group PKCS#11 does not exist "); return FALSE; // Group does not exist... setup is wrong.. } tok = ftok(Path ,'b'); // Allocate the shared memory... Fail if the memory is already // allocated since the slot mgr is the owner of it. // Is this some attempt at exclusivity, or is that just a side effect? - SCM 9/1 shmid = shmget( tok, sizeof( Slot_Mgr_Shr_t ), IPC_CREAT | IPC_EXCL | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP ); // Explanation of options to shmget(): /* * IPC_CREAT Creates the data structure if it does not already exist. * IPC_EXCL Causes the shmget subroutine to be unsuccessful if the * IPC_CREAT flag is also set, and the data structure already exists. * S_IRUSR Permits the process that owns the data structure to read it. * S_IWUSR Permits the process that owns the data structure to modify it. * S_IRGRP Permits the group associated with the data structure to read it. * S_IWGRP Permits the group associated with the data structure to modify it. * * * WE DON"T WANT OTHERS * S_IROTH Permits others to read the data structure. * S_IWOTH Permits others to modify the data structure. */ if ( shmid < 0 ) { ErrLog("Shared memory creation failed (0x%X)\n", errno); ErrLog("Reclaiming 0x%X\n", tok); shmid = shmget( tok, sizeof( Slot_Mgr_Shr_t ), 0 ); DestroySharedMemory(); shmid = shmget( tok, sizeof( Slot_Mgr_Shr_t ), IPC_CREAT | IPC_EXCL | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP ); if ( shmid < 0 ) { ErrLog("Shared memory reclamation failed (0x%X)\n", errno); ErrLog("perform ipcrm -M 0x%X\n", tok); return FALSE; } } // SAB Set the group ownership of the shared mem segment.. // we already have the group structure.. if ( shmctl(shmid, IPC_STAT,&shm_info) == 0 ) { shm_info.shm_perm.gid = grp->gr_gid; if (shmctl(shmid,IPC_SET,&shm_info) == -1) { ErrLog("Failed to set group ownership for shm \n"); shmctl(shmid, IPC_RMID,NULL); } } else { ErrLog("Can't get status of shared memory %d\n",errno); // we know it was created... we need to destroy it... shmctl(shmid, IPC_RMID,NULL); } return TRUE; #else { #warning "EXPERIMENTAL" int fd; int i; char *buffer; grp = getgrnam("pkcs11"); if ( !grp ) { ErrLog("Group \"pkcs11\" does not exist! Please run %s/pkcs11_startup.", SBIN_PATH); return FALSE; // Group does not exist... setup is wrong.. } fd = open(MAPFILENAME,O_RDWR,MODE); if (fd < 0 ) { // File does not exist... this is cool, we creat it here fd = open(MAPFILENAME,O_RDWR|O_CREAT,MODE); // Create the file if (fd < 0 ){ // We are really hosed here, since we should be able // to create the file now ErrLog("%s: open(%s): %s", __FUNCTION__, MAPFILENAME, strerror(errno)); return FALSE; } else { if (fchmod(fd, MODE) == -1) { ErrLog("%s: fchmod(%s): %s", __FUNCTION__, MAPFILENAME, strerror(errno)); close(fd); return FALSE; } if (fchown(fd, 0, grp->gr_gid) == -1) { ErrLog("%s: fchown(%s, root, pkcs11): %s", __FUNCTION__, MAPFILENAME, strerror(errno)); close(fd); return FALSE; } // Create a buffer and make the file the right length i = sizeof(Slot_Mgr_Shr_t); buffer = malloc(sizeof(Slot_Mgr_Shr_t)); memset(buffer,'\0',i); write(fd,buffer,i); free(buffer); close(fd); } } else { ErrLog("%s: [%s] exists; you may already have a pkcsslot daemon running. If this " "is not the case, then the prior daemon was not shut down cleanly. " "Please delete this file and try again\n", __FUNCTION__, MAPFILENAME); close(fd); return FALSE; } return TRUE; } #endif }
int main ( int argc, char *argv[], char *envp[]) { int ret; /**********************************/ /* Read in command-line arguments */ /**********************************/ /* FIXME: Argument for daemonizing or not */ /* FIXME: Argument for debug level */ /* FIXME: Arguments affecting the log files, whether to use syslog, etc. (Read conf file?) */ /* Report our debug level */ if ( GetDebugLevel() > DEBUG_NONE) { DbgLog(GetDebugLevel(), "Starting with debugging messages logged at level %d (%d = No messages; %d = few; %d = more, etc.)", GetDebugLevel(), DEBUG_NONE, DEBUG_LEVEL0, DEBUG_LEVEL1); } /* Save our startup directory */ SaveStartupDirectory( argv[0] ); ret = load_and_parse(OCK_CONFIG); if (ret != 0) { ErrLog("Failed to read config file.\n"); return 1; } else DbgLog (DL0, "Parse config file succeeded.\n"); /* Allocate and Attach the shared memory region */ if ( ! CreateSharedMemory() ) { /* CreateSharedMemory() does it's own error logging */ return 1; } DbgLog(DL0,"SHMID %d token %#X \n", shmid, tok); /* Now that we've created the shared memory segment, we attach to it */ if ( ! AttachToSharedMemory() ) { /* AttachToSharedMemory() does it's own error logging */ DestroySharedMemory(); return 2; } /* Initialize the global shared memory mutex (and the attribute used to create the per-process mutexes */ if ( ! InitializeMutexes() ) { DetachFromSharedMemory(); DestroySharedMemory(); return 3; } /* Get the global shared memory mutex */ XProcLock(); /* Populate the Shared Memory Region */ if ( ! InitSharedMemory(shmp) ) { XProcUnLock(); DetachFromSharedMemory(); DestroySharedMemory(); return 4; } /* Release the global shared memory mutex */ XProcUnLock(); if ((socketfd = CreateListenerSocket()) < 0) { DestroyMutexes(); DetachFromSharedMemory(); DestroySharedMemory(); return 5; } if (!InitSocketData(&socketData)) { DetachSocketListener(socketfd); DestroyMutexes(); DetachFromSharedMemory(); DestroySharedMemory(); return 6; } /* * Become a Daemon, if called for */ if ( Daemon ) { pid_t pid; if ( (pid = fork()) < 0 ){ DetachSocketListener(socketfd); DestroyMutexes(); DetachFromSharedMemory(); DestroySharedMemory(); return 7; } else { if ( pid != 0) { exit(0); // Terminate the parent } else { setsid(); // Session leader #ifndef DEV fclose(stderr); fclose(stdout); fclose(stdin); #endif } } } else { #ifdef DEV // Log only on development builds LogLog("Not becoming a daemon...\n"); #endif } /***************************************** * * Register Signal Handlers * Daemon probably should ignore ALL signals possible, since termination * while active is a bad thing... however one could check for * any processes active in the shared memory, and destroy the shm if * the process wishes to terminate. * *****************************************/ /* * We have to set up the signal handlers after we daemonize because * the daemonization process redefines our handler for (at least) SIGTERM */ if ( ! SetupSignalHandlers() ) { DetachSocketListener(socketfd); DestroyMutexes(); DetachFromSharedMemory(); DestroySharedMemory(); return 8; } /* ultimatly we will create a couple of threads which monitor the slot db and handle the insertion and removal of tokens from the slot. */ /* For Testing the Garbage collection routines */ /* shmp->proc_table[3].inuse = TRUE; shmp->proc_table[3].proc_id = 24328; */ #if !defined(NOGARBAGE) printf("Start garbage \n"); /* start garbage collection thread */ if ( ! StartGCThread(shmp) ) { DetachSocketListener(socketfd); DestroyMutexes(); DetachFromSharedMemory(); DestroySharedMemory(); return 9; } #endif // We've fully become a daemon. Now create the PID file { FILE *pidfile; pidfile = fopen(PID_FILE_PATH,"w"); if (pidfile) { fprintf(pidfile,"%d",getpid()); fclose(pidfile); } } while (1) { #if !(THREADED) && !(NOGARBAGE) CheckForGarbage(shmp); #endif SocketConnectionHandler(socketfd, 10); } /************************************************************* * * Here we need to actualy go through the processes and verify that thye * still exist. If not, then they terminated with out properly calling * C_Finalize and therefore need to be removed from the system. * Look for a system routine to determine if the shared memory is held by * the process to further verify that the proper processes are in the * table. * *************************************************************/ } /* end main */
void CleanUpDDraw() { logOutput << CurrentTimeString() << "Cleaning up" << endl; if (copyData) copyData->lastRendered = -1; if (hCopyThread) { bKillThread = true; SetEvent(hCopyEvent); if (WaitForSingleObject(hCopyThread, 500) != WAIT_OBJECT_0) TerminateThread(hCopyThread, -1); CloseHandle(hCopyThread); CloseHandle(hCopyEvent); hCopyThread = NULL; hCopyEvent = NULL; } ddrawSurfaceRelease.Unhook(); for (int i = 0; i < NUM_BUFFERS; i++) { if (ddCaptures[i]) { ddCaptures[i]->Release(); ddCaptures[i] = NULL; } } ddrawSurfaceRelease.Rehook(); DestroySharedMemory(); bHasTextures = false; curCapture = 0; curCPUTexture = 0; keepAliveTime = 0; resetCount++; copyWait = 0; lastTime = 0; g_frontSurface = NULL; g_bUseFlipMethod = false; bTargetAcquired = false; g_dwSize = 0; g_bUse32bitCapture = false; g_bConvert16to32 = false; g_bUsePalette = false; g_dwCaptureSize = 0; if (g_ddInterface) { g_ddInterface->Release(); g_ddInterface = NULL; } g_CurrentPalette.Free(); if (g_surfaceDesc) delete g_surfaceDesc; g_surfaceDesc = NULL; if (ddUnlockFctMutex) { CloseHandle(ddUnlockFctMutex); ddUnlockFctMutex = 0; } //UnhookAll(); logOutput << CurrentTimeString() << "---------------------- Cleared DirectDraw Capture ----------------------" << endl; }
void MhProtoClient::ClearResources(void) { if (sem_ != NULL) delete sem_; DestroySharedMemory(); }
MhProtoClient::~MhProtoClient(void) { DEBUG("MhProtoClient::Destructor\n"); if (sem_ != NULL) delete sem_; DestroySharedMemory(); }
void ClearGLData() { if(copyData) copyData->lastRendered = -1; if(hCopyThread) { bKillThread = true; SetEvent(hCopyEvent); if(WaitForSingleObject(hCopyThread, 500) != WAIT_OBJECT_0) TerminateThread(hCopyThread, -1); CloseHandle(hCopyThread); CloseHandle(hCopyEvent); hCopyThread = NULL; hCopyEvent = NULL; } for(int i=0; i<NUM_BUFFERS; i++) { if(glLockedTextures[i]) { OSEnterMutex(glDataMutexes[i]); glBindBuffer(GL_PIXEL_PACK_BUFFER, gltextures[i]); glUnmapBuffer(GL_PIXEL_PACK_BUFFER); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glLockedTextures[i] = false; OSLeaveMutex(glDataMutexes[i]); } } if(bHasTextures) { glDeleteBuffers(NUM_BUFFERS, gltextures); bHasTextures = false; ZeroMemory(gltextures, sizeof(gltextures)); } for(int i=0; i<NUM_BUFFERS; i++) { if(glDataMutexes[i]) { OSCloseMutex(glDataMutexes[i]); glDataMutexes[i] = NULL; } } DestroySharedMemory(); copyData = NULL; copyWait = 0; lastTime = 0; curCapture = 0; curCPUTexture = 0; keepAliveTime = 0; resetCount++; pCopyData = NULL; logOutput << CurrentTimeString() << "---------------------- Cleared OpenGL Capture ----------------------" << endl; }