void* OpenShm(const char* pShmName, size_t szShmSize) { HANDLE hMapFile; void* pBuf; hMapFile = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, pShmName); if (hMapFile == NULL) { //printf("Failed to OpenFIle... %d\n", GetLastError()); return NULL; } pBuf = (LPSTR)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, szShmSize); if (pBuf == NULL) { //printf("Failed to MapFileOfFile... %d\n", GetLastError()); CloseHandle(hMapFile); return NULL; } return pBuf; }
bool LH_SpeedFanData::getData(float& value, QString& text, QString& units, int& count, int index) { #ifdef Q_WS_WIN bool resultVal = false; HANDLE filemap = OpenFileMappingA(FILE_MAP_READ, FALSE, "SFSharedMemory_ALM"); if(filemap != NULL) { SFMemory* sfmemory = (SFMemory*)MapViewOfFile(filemap, FILE_MAP_READ, 0, 0, sizeof(SFMemory)); if (sfmemory) { if(sfmemory->MemSize!=0) { if (ui_->count(mon_item) == 0) loadSensorList(sfmemory); getSelectedValue(sfmemory, value, text, units, count, index); resultVal = true; } UnmapViewOfFile(sfmemory); } CloseHandle(filemap); } ui_->setReadonly(mon_type | mon_item, !resultVal); return resultVal; #else Q_UNUSED(value); Q_UNUSED(text); Q_UNUSED(units); Q_UNUSED(count); Q_UNUSED(index); return false; #endif }
/* * ::openSharedMemory */ BOOL openSharedMemory(HANDLE *outShMem, void **outBaseAddr, const int size) { #define SHMEM_NAME_LEN (64) char shMemName[SHMEM_NAME_LEN]; if (!GetEnvironmentVariableA("GLSL_DEBUGGER_SHMID", shMemName, SHMEM_NAME_LEN)) { dbgPrint(DBGLVL_ERROR, "Oh Shit! No Shmid! Set GLSL_DEBUGGER_SHMID.\n"); return FALSE; } /* This creates a non-inheritable shared memory mapping! */ *outShMem = OpenFileMappingA(FILE_MAP_WRITE, FALSE, shMemName); if ((*outShMem == NULL) || (*outShMem == INVALID_HANDLE_VALUE)) { dbgPrint(DBGLVL_ERROR, "Opening of shared mem segment \"%s\" failed: %u.\n", shMemName, GetLastError()); return FALSE; } /* FILE_MAP_WRITE implies read */ *outBaseAddr = MapViewOfFile(*outShMem, FILE_MAP_WRITE, 0, 0, size); if (*outBaseAddr == NULL) { dbgPrint(DBGLVL_ERROR, "View mapping of shared mem segment \"%s\" failed: %u.\n", shMemName, GetLastError()); CloseHandle(*outShMem); return FALSE; } return TRUE; #undef SHMEM_NAME_LEN }
static char * read_shm (const char *shm_name) { HANDLE shared_mem; char *shared_data; char *res; int i; res = NULL; for (i = 0; i < 20; i++) { shared_mem = OpenFileMappingA (FILE_MAP_READ, FALSE, shm_name); if (shared_mem != 0) break; Sleep (100); } if (shared_mem != 0) { shared_data = MapViewOfFile (shared_mem, FILE_MAP_READ, 0, 0, 0); if (shared_data != NULL) { res = g_strdup (shared_data); UnmapViewOfFile (shared_data); } CloseHandle (shared_mem); } return res; }
bool CheckSingleInstance() { char moduleFileName[_MAX_PATH]; GetModuleFileNameA(NULL, moduleFileName, _MAX_PATH - 1); for (char *p = moduleFileName; *p; p++) { if (*p == ':' || *p == '\\') *p = '_'; } std::string mappingName = std::string("IntelliJLauncherMapping.") + moduleFileName; std::string eventName = std::string("IntelliJLauncherEvent.") + moduleFileName; hEvent = CreateEventA(NULL, FALSE, FALSE, eventName.c_str()); hFileMapping = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, mappingName.c_str()); if (!hFileMapping) { hFileMapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, FILE_MAPPING_SIZE, mappingName.c_str()); return true; } else { SendCommandLineToFirstInstance(); CloseHandle(hFileMapping); CloseHandle(hEvent); return false; } }
static bool shm_create(impl_type& impl,const String& name_,size_t size_,int flag_) { HANDLE hMapFile; if(flag_&FileAccess::FLAG_CR) { FileAccess::LargeInteger tmp; tmp.dval=size_; hMapFile = CreateFileMappingA( INVALID_HANDLE_VALUE, // Use paging file - shared memory NULL, // Default security attributes PAGE_READWRITE, // Allow read and write access tmp.d[1], // High-order DWORD of file mapping max size tmp.d[0], // Low-order DWORD of file mapping max size name_.empty()?NULL:name_.c_str() ); } else { hMapFile = OpenFileMappingA( FileAccess::makeflag(flag_,FILE_MAP_READ,FILE_MAP_WRITE), FALSE, // Do not inherit the name name_.c_str() // File mapping name ); } if (hMapFile == NULL) { System::CheckError("CreateFileMapping/OpenFileMapping"); return false; } char* pView = (char*)MapViewOfFile( hMapFile, // Handle of the map object FileAccess::makeflag(flag_,FILE_MAP_READ,FILE_MAP_WRITE), // access 0, // High-order DWORD of the file offset 0, // Low-order DWORD of the file offset size_ // The number of bytes to map to view ); if(!pView) { ::CloseHandle(hMapFile); System::CheckError("MapViewOfFile"); return false; } impl.m_pAddr=pView; impl.m_nSize=size_; impl.m_sName=name_; impl.m_pHandle.reset(hMapFile); return true; }
bool SpoutSharedMemory::Open(const char* name) { // Don't call open twice on the same object without a Close() assert(name); if (m_hMap) { assert(strcmp(name, m_pName) == 0); assert(m_pBuffer && m_hMutex); return true; } m_hMap = OpenFileMappingA ( FILE_MAP_ALL_ACCESS, FALSE, (LPCSTR)name); if (m_hMap == NULL) { return false; } DWORD err = GetLastError(); if (err == ERROR_ALREADY_EXISTS) { // We should ensure the already existing mapping is at least // the size we expect } m_pBuffer = (char*)MapViewOfFile(m_hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); if (!m_pBuffer) { Close(); return false; } std::string mutexName; mutexName = name; mutexName += "_mutex"; m_hMutex = CreateMutexA(NULL, FALSE, mutexName.c_str()); if (!m_hMutex) { Close(); return false; } // m_pName = strdup(name); m_pName = _strdup(name); m_size = 0; return true; }
SHMEMHandle AttachShareMem(SHMEMKey keyShmem, INT iSize) { #ifdef WIN32 char keybuf[32] = { 0 }; sprintf_s(keybuf, "%d", keyShmem); return OpenFileMappingA(FILE_MAP_ALL_ACCESS, TRUE, keybuf); #else return shmget(keyShmem, iSize, 0); #endif }
Air::U1 FileMapping::OpenFile() { if(m_hFile==NULL){ m_hFile = OpenFileMappingA(FILE_MAP_ALL_ACCESS,NULL,m_strProductName.c_str()); if(m_hFile!=NULL){ Lock(0,m_Info.uiFileSize); } } return m_hFile!=NULL; }
void ThTypes_Init() { if (!MMFHandle) { MMFHandle = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(TGlobalDLLData), "GoldenDictTextOutHookSharedMem"); } if (!MMFHandle) { MMFHandle = OpenFileMappingA(FILE_MAP_READ | FILE_MAP_WRITE, 0, "GoldenDictTextOutHookSharedMem"); } if (!GlobalData && MMFHandle != NULL) GlobalData = MapViewOfFile(MMFHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0); }
void * __open_mmap_file (void ** pHandle, const char * pcFileName, const char * pcTagName, size_t size, size_t offset) { bool err = false; struct _WIN32_MMAP * pstMapped = NULL; void * mappedAddr = NULL; if (pstMapped = (struct _WIN32_MMAP * )(*pHandle = malloc(sizeof(struct _WIN32_MMAP)))) { pstMapped->file = pstMapped->memory = INVALID_HANDLE_VALUE; } else { return *pHandle = NULL; } if (pcTagName) { if (pstMapped->memory = OpenFileMappingA(FILE_MAP_WRITE, 0, pcTagName)) { if (mappedAddr = MapViewOfFile(pstMapped->memory, FILE_MAP_WRITE, 0, offset, size)) { return mappedAddr; } else { err = true; goto error; } } else { pstMapped->memory = INVALID_HANDLE_VALUE, err = true; goto error; } } else if (pcFileName) { if ((pstMapped->file = CreateFileA(pcFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { err = true; goto error; } if (!(pstMapped->memory = CreateFileMappingA(pstMapped->file, 0, PAGE_READWRITE, 0, size, pcTagName))) { pstMapped->memory = INVALID_HANDLE_VALUE, err = true; goto error; } } else { err = true; goto error; } if (!(mappedAddr = MapViewOfFile(pstMapped->memory, FILE_MAP_WRITE, 0, offset, size))) { err = true; goto error; } error: if (err) { if (pstMapped) { if (pstMapped->memory != INVALID_HANDLE_VALUE) { CloseHandle(pstMapped->memory), pstMapped->memory = INVALID_HANDLE_VALUE; } if (pstMapped->file != INVALID_HANDLE_VALUE) { CloseHandle(pstMapped->file), pstMapped->file = INVALID_HANDLE_VALUE; } free (pstMapped), *pHandle = pstMapped = NULL; } return *pHandle; } return mappedAddr; }
int LH_TextSpeedFan::notify(int n,void* p) { if( !n || n&LH_NOTE_SECOND ) { HANDLE filemap = OpenFileMappingA(FILE_MAP_READ, FALSE, "SFSharedMemory_ALM"); if( filemap != NULL ) { SFMemory* sfmemory = (SFMemory*)MapViewOfFile(filemap, FILE_MAP_READ, 0, 0, sizeof(SFMemory)); if( sfmemory ) { QString outText = setup_template_->value(); QRegExp rx("%(t|f|v)(n|[0-9]+)"); int pos = 0; while ((pos = rx.indexIn(outText, pos)) != -1) { QString repVal; if(rx.cap(1) == "t") { if (rx.cap(2) == "n") repVal = QString("%1").arg(sfmemory->NumTemps); else repVal = QString("%1\260C").arg(sfmemory->temps[rx.cap(2).toInt()]/100); } if(rx.cap(1) == "f") { if (rx.cap(2) == "n") repVal = QString("%1").arg(sfmemory->NumFans); else repVal = QString("%1").arg(sfmemory->fans[rx.cap(2).toInt()]); } if(rx.cap(1) == "v") { if (rx.cap(2) == "n") repVal = QString("%1").arg(sfmemory->NumVolts); else repVal = QString("%1V").arg(float(sfmemory->volts[rx.cap(2).toInt()])/100); } outText.replace(rx.cap(0),repVal); pos += rx.matchedLength(); } if( setText( outText ) ) callback(lh_cb_render,NULL); // only render if the text changed } else { if( setText( "Failed to open shared memory." ) ) callback(lh_cb_render,NULL); // only render if the text changed } // Close the handles we opened. CloseHandle(filemap); } else if( setText( "N/A" ) ) callback(lh_cb_render,NULL); } return LH_Text::notify(n,p) | LH_NOTE_SECOND; };
void IPC::process() { IPCLock(this); for (unsigned i = 0; i < N_SLOTS; i++){ if (s[i] != SLOT_IN) continue; QString in; QString out; string name = prefix(); name += number(i); HANDLE hMem = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, name.c_str()); if (hMem == NULL){ s[i] = SLOT_NONE; PulseEvent(hEventOut); continue; } unsigned short *mem = (unsigned short*)MapViewOfFile(hMem, FILE_MAP_ALL_ACCESS, 0, 0, 0); if (mem == NULL){ log(L_WARN, "Map error"); s[i] = SLOT_NONE; PulseEvent(hEventOut); continue; } unsigned short *p; for (p = mem; *p; p++) in += QChar(*p); bool bError = false; bool bRes = remote->command(in, out, bError); p = mem; unsigned size = 0; if (!bError){ if (bRes){ *(p++) = QChar('>').unicode(); }else{ *(p++) = QChar('?').unicode(); } size = out.length(); if (size > 0x3F00) size = 0x3F00; memcpy(p, out.unicode(), size * sizeof(unsigned short)); size++; } p[size] = 0; UnmapViewOfFile(mem); CloseHandle(hMem); s[i] = SLOT_OUT; PulseEvent(hEventOut); } }
/* * QueueOpen * * Open existing queue which has given key. If there is no queue with given * key, or matched shared memory segment is not created by pgut, error occurs * and never return. */ Queue * QueueOpen(unsigned key) { Queue *self; ShmemHandle handle; QueueHeader *header; #ifdef WIN32 char shmemName[MAX_PATH]; win32_shmemName(shmemName, lengthof(shmemName), key); handle = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, shmemName); if (handle == NULL) elog(ERROR, "OpenFileMapping(%s) failed: errcode=%lu", shmemName, GetLastError()); header = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0); if (header == NULL) elog(ERROR, "MapViewOfFile failed: errcode=%lu", GetLastError()); #else handle = shmget(key, 0, 0); if (handle < 0) elog(ERROR, "shmget(id=%d) failed: %m", key); /* OK, should be able to attach to the segment */ header = shmat(handle, NULL, PG_SHMAT_FLAGS); /* failed: must be some other app's */ if (header == (void *) -1) elog(ERROR, "shmat(id=%d) failed: %m", key); #endif /* check magic number */ if (header->magic != PGUTShmemMagic) { #ifdef WIN32 UnmapViewOfFile(header); CloseHandle(handle); #else shmdt(header); shmctl(handle, IPC_RMID, NULL); #endif elog(ERROR, "segment belongs to a non-pgut app"); } self = palloc(sizeof(Queue)); self->handle = handle; self->header = header; self->size = header->size; return self; }
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; }
LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam){ PMSG pMsg=(PMSG)lParam; char* lpAddr; if(wParam==0){ switch (pMsg->message){ case 0x801: hGame_LOL=pMsg->hwnd; g_hGetMsg=(HHOOK)(pMsg->lParam); if(!bInitLOLClient) { bInitLOLClient=TRUE; CreateThread(NULL,NULL,&dwWaitThread,NULL,NULL,NULL); } break; case 0x802: g_hMemFile=OpenFileMappingA(FILE_MAP_ALL_ACCESS,FALSE,FILE_CFG); if(g_hMemFile){ lpAddr=(char*)MapViewOfFile(g_hMemFile,FILE_MAP_ALL_ACCESS,0,0,255); DbgPrintA("[Hook]GetCFG PATH %s",lpAddr); LoadCFG(lpAddr,&cfgEXE); UnmapViewOfFile(lpAddr); CloseHandle(g_hMemFile); }else{ DbgPrintA("[Hook] OpenFileFILE_CFG Error"); } break; case 0x803: g_hGetMsg=(HHOOK)(pMsg->lParam); if(!bInitLOL) { DbgPrintA("[Hook]Init"); bInitLOL=TRUE; CreateThread(NULL,NULL,&dwWaitThread,NULL,NULL,NULL); } else { DbgPrintA("[Hook]has been Inited"); } break; case 0x805: if (!bInitLOL) { bInitLOL = TRUE; CreateThread(NULL, NULL, &dwWaitThread, NULL, NULL, NULL); } break; } } return CallNextHookEx(g_hGetMsg,code,wParam,lParam); }
void handleGet(struct ns_connection *nc, struct http_message *hm) { // Open the memory mapped file HANDLE fileHandle = OpenFileMappingA(PAGE_READONLY, FALSE, MAP_OBJECT_NAME); if (fileHandle == NULL) { // File is not available, build service unavailable response sendServiceUnavailable(nc); } else{ // File is available, process the file processFile(nc, fileHandle, hm); // Close the file CloseHandle(fileHandle); } }
// Checks if the controller already exists in the process bool DoesControllerExist() { // If it's open of course it exists if(this->IsOpen()) return true; // Open it to check if it exists if(HANDLE hMap = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, CBM_NAME)) { // Yes, it does, close it and tell that it exists CloseHandle(hMap); return true; } // Nope return false; }
// Tries to open the controller block (if it already exists) void OpenController() { // Get handle to the mapped memory if(hMemory || (hMemory = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, CBM_NAME))) { // Get the mapped memory pointer this->MapMemory(); if(this->IsOpen()) { // Updates the controller interface if necessary if(this->IsInterfaceUpToDate() == false) this->UpdateInterface(); } } }
// // Create a memory-mapping to the Freetrack data. // It contains the tracking data, a handle to the main-window and the program-name of the Game! // // bool FTCreateMapping() { bool bMappingExists = false; // // Memory-mapping already exists! // if ( pMemData != NULL ) { return true; } dbg_report("FTCreateMapping request (pMemData == NULL).\n"); // // A FileMapping is used to create 'shared memory' between the FTClient and the FTServer. // // Try to create a FileMapping to the Shared Memory. This is done to check if it's already there (what // may mean the face-tracker program is already running). // // If one already exists: close it and open the file-mapping to the existing one. // hFTMemMap = CreateFileMappingA( INVALID_HANDLE_VALUE , 00 , PAGE_READWRITE , 0 , sizeof( FTMemMap ), (LPCSTR) FT_MM_DATA ); if ( ( hFTMemMap != 0 ) && ( GetLastError() == ERROR_ALREADY_EXISTS ) ) { dbg_report("FTCreateMapping: Mapping already exists.\n"); bMappingExists = true; // So the server was (probably) already started! CloseHandle( hFTMemMap ); hFTMemMap = 0; } // // Create a new FileMapping, Read/Write access // hFTMemMap = OpenFileMappingA( FILE_MAP_WRITE , false , (LPCSTR) FT_MM_DATA ); if ( ( hFTMemMap != 0 ) ) { dbg_report("FTCreateMapping: Mapping opened.\n"); pMemData = (FTMemMap *) MapViewOfFile(hFTMemMap, FILE_MAP_WRITE, 0, 0, sizeof( FTMemMap ) ); hFTMutex = CreateMutexA(NULL, false, FREETRACK_MUTEX); } else { return false; } return true; }
bool LLPluginSharedMemory::attach(const std::string &name, size_t size) { mName = name; mSize = size; mImpl->mMapFile = OpenFileMappingA( FILE_MAP_ALL_ACCESS, // read/write access FALSE, // do not inherit the name mName.c_str()); // name of mapping object if(mImpl->mMapFile == NULL) { LL_WARNS("Plugin") << "OpenFileMapping failed: " << GetLastError() << LL_ENDL; return false; } return map(); }
static void *stdiofile_contents(void *ptr, size_t *size) { struct stdiofile *self = ptr; int oflag; #ifndef WIN32 int prot; struct stat s; #endif if (self->contents) { if (size) { *size = self->size; } return self->contents; } #ifdef WIN32 oflag = (self->mode&ILA_FILE_READ? FILE_MAP_READ : 0) | (self->mode&ILA_FILE_WRITE? FILE_MAP_WRITE : 0);// | //(self->mode&ILA_FILE_EXEC? FILE_MAP_EXECUTE : 0); // TODO: find out why mingw thinks there's no such thing as executable files self->handle = OpenFileMappingA(oflag, FALSE, self->path); self->size = GetFileSize(self->handle, NULL); self->contents = MapViewOfFile(self->handle, oflag, 0, 0, self->size); #else oflag = (self->mode&ILA_FILE_READ && self->mode&ILA_FILE_WRITE? O_RDWR : (self->mode&ILA_FILE_READ? O_RDONLY : 0) | (self->mode&ILA_FILE_WRITE? O_WRONLY : 0)); self->fd = open(self->path, oflag); if (fstat(self->fd, &s) != 0) { return NULL; } self->size = s.st_size; prot = (self->mode&ILA_FILE_READ? PROT_READ : 0) | (self->mode&ILA_FILE_WRITE? PROT_WRITE : 0) | (self->mode&ILA_FILE_EXEC? PROT_EXEC : 0); self->contents = mmap(NULL, self->size, prot, MAP_SHARED, self->fd, 0); #endif if (size) { *size = self->size; } return self->contents; }
char *get_saver_name(void) { static char s_saver[MAX_PATH]; HANDLE hMapping; LPVOID p = NULL; s_saver[0] = '\0'; hMapping = OpenFileMappingA(FILE_MAP_READ, TRUE, "Katayama Hirofumi MZ XScreenSaverWin"); if (hMapping != NULL) { p = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 256); if (p) { lstrcpyA(s_saver, (char *)p); UnmapViewOfFile(p); } CloseHandle(hMapping); } return s_saver; }
// Open //------------------------------------------------------------------------------ void SharedMemory::Open( const char * name, unsigned int size ) { #if defined( __WINDOWS__ ) m_MapFile = OpenFileMappingA( FILE_MAP_ALL_ACCESS, // read/write access FALSE, // do not inherit the name name ); // name of mapping object if ( m_MapFile ) { m_Memory = MapViewOfFile( m_MapFile, // handle to map object FILE_MAP_ALL_ACCESS, // read/write permission 0, // DWORD dwFileOffsetHigh 0, // DWORD dwFileOffsetLow size ); } #elif defined( __APPLE__ ) || defined(__LINUX__) PosixMapMemory(name, size, false, &m_MapFile, &m_Memory, m_Name); m_Length = size; #else #error #endif }
void IPC::process() { IPCLock(this); for (unsigned i = 0; i < N_SLOTS; i++){ if (s[i] != SLOT_IN) continue; QString in; QString out; string name = prefix(); name += number(i); HANDLE hMem = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, name.c_str()); if (hMem == NULL){ s[i] = SLOT_NONE; PulseEvent(hEventOut); continue; } unsigned short *mem = (unsigned short*)MapViewOfFile(hMem, FILE_MAP_ALL_ACCESS, 0, 0, 0); unsigned short *p; for (p = mem; *p; p++) in += QChar(*p); bool bError = false; bool bRes = remote->command(in, out, bError); p = mem; if (!bError){ if (bRes){ *(p++) = QChar('>').unicode(); }else{ *(p++) = QChar('?').unicode(); } for (int n = 0; n < (int)(out.length()); n++) *(p++) = out[n].unicode(); } *(p++) = 0; UnmapViewOfFile(mem); CloseHandle(hMem); s[i] = SLOT_OUT; PulseEvent(hEventOut); } }
XCODE_IPC_DESCR_T *xcode_ipc_open(unsigned int sz, key_t key) { XCODE_IPC_DESCR_T *pIpc = NULL; pIpc = avc_calloc(1, sizeof(XCODE_IPC_DESCR_T)); pIpc->sz = sz; if((pIpc->hFile = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, XCODE_FILE_MAPPING_NAME)) == NULL) { LOG(X_ERROR("OpenFileMapping %s failed (error:%d)"), XCODE_FILE_MAPPING_NAME, GetLastError()); xcode_ipc_close(pIpc); return NULL; } if((pIpc->pmem = MapViewOfFile(pIpc->hFile, FILE_MAP_ALL_ACCESS, 0, 0, pIpc->sz)) == NULL) { LOG(X_ERROR("MapViewOfFile %s failed (error:%d)"), XCODE_FILE_MAPPING_NAME, GetLastError()); xcode_ipc_close(pIpc); return NULL; } if((pIpc->hSemSrv = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, XCODE_SEM_SRV_NAME)) == NULL) { LOG(X_ERROR("OpenSemaphore %s failed (error:%d)"), XCODE_SEM_SRV_NAME, GetLastError()); xcode_ipc_close(pIpc); return NULL; } if((pIpc->hSemCli = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, XCODE_SEM_CLI_NAME)) == NULL) { LOG(X_ERROR("OpenSemaphore %s failed (error:%d)"), XCODE_SEM_CLI_NAME, GetLastError()); xcode_ipc_close(pIpc); return NULL; } pIpc->pmem->hdr.cmd = XCODE_IPC_CMD_NONE; return pIpc; }
bool LH_AfterburnerData::getData(float& value, QString& text, QString& units, QString& format, float& min, float& max, int index) { #ifdef Q_WS_WIN bool resultVal = false; HANDLE filemap = OpenFileMappingA(FILE_MAP_READ, FALSE, "MAHMSharedMemory"); if(filemap != NULL) { MAHM_SHARED_MEMORY_HEADER* MAHMHeader = (MAHM_SHARED_MEMORY_HEADER*)MapViewOfFile(filemap, FILE_MAP_READ, 0, 0, 0); if (MAHMHeader) { if (MAHMHeader->dwSignature == 0xDEAD) { qDebug() << "LH_Afterburner: Shared memory has been terminated; try again later."; } else { if (ui_->count(mon_type) == 0) loadTypesList(MAHMHeader); getSelectedValue(MAHMHeader, value, text, units, format, min, max, index); resultVal = true; } UnmapViewOfFile(MAHMHeader); } CloseHandle(filemap); } ui_->setReadonly(mon_type | mon_item, !resultVal); return resultVal; #else Q_UNUSED(value); Q_UNUSED(text); Q_UNUSED(units); Q_UNUSED(format); Q_UNUSED(min); Q_UNUSED(max); Q_UNUSED(index); return false; #endif }
hSharedMemory* OpenSharedMemory(char* MapFileName, char* mutex, int size) { hSharedMemory* handle = malloc(sizeof(hSharedMemory)); handle->hFile = NULL; handle->hFileView = NULL; handle->hFileMutex = NULL; // Try to open File Mapping... handle->hFile = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, MapFileName); // ... ok it might not exist, so create try to create it... if (handle->hFile == NULL) handle->hFile = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, size & 0xFFFF0000, size & 0xFFFF, MapFileName); // ... if create fails we are lost... if (handle->hFile == 0) { CloseSharedMemory(handle); return NULL; } handle->hFileView = MapViewOfFile(handle->hFile, FILE_MAP_ALL_ACCESS, 0, 0, size); if (handle->hFileView == NULL) { CloseSharedMemory(handle); return NULL; } handle->hFileMutex = CreateMutexA(NULL, FALSE, mutex); if (handle->hFileMutex == NULL) { CloseSharedMemory(handle); return NULL; } return handle; }
// Open //------------------------------------------------------------------------------ void SharedMemory::Open( const char * name, unsigned int size ) { #if defined( __WINDOWS__ ) m_MapFile = OpenFileMappingA( FILE_MAP_ALL_ACCESS, // read/write access FALSE, // do not inherit the name name ); // name of mapping object if ( m_MapFile ) { m_Memory = MapViewOfFile( m_MapFile, // handle to map object FILE_MAP_ALL_ACCESS, // read/write permission 0, // DWORD dwFileOffsetHigh 0, // DWORD dwFileOffsetLow size ); } #elif defined( __APPLE__ ) // TODO:MAC Implement SharedMemory #elif defined( __LINUX__ ) // TODO:LINUX Implement SharedMemory #else #error #endif }
APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m, const char *file, apr_pool_t *pool) { HANDLE hMap; void *mapkey; void *base; if (!file) { return APR_EINVAL; } else { /* res_name_from_filename turns file into a pseudo-name * without slashes or backslashes, and prepends the \global * prefix on Win2K and later */ mapkey = res_name_from_filename(file, 1, pool); } #if APR_HAS_UNICODE_FS IF_WIN_OS_IS_UNICODE { #ifndef _WIN32_WCE hMap = OpenFileMappingW(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, mapkey); #else /* The WCE 3.0 lacks OpenFileMapping. So we emulate one with * opening the existing shmem and reading its size from the header */ hMap = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(apr_shm_t), mapkey); #endif } #endif #if APR_HAS_ANSI_FS ELSE_WIN_OS_IS_ANSI { hMap = OpenFileMappingA(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, mapkey); } #endif if (!hMap) { return apr_get_os_error(); } base = MapViewOfFile(hMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); if (!base) { CloseHandle(hMap); return apr_get_os_error(); } *m = (apr_shm_t *) apr_palloc(pool, sizeof(apr_shm_t)); (*m)->pool = pool; (*m)->memblk = base; /* Real (*m)->mem->size could be recovered with VirtualQuery */ (*m)->size = (*m)->memblk->size; #if _WIN32_WCE /* Reopen with real size */ UnmapViewOfFile(base); CloseHandle(hMap); hMap = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (*m)->size, mapkey); if (!hMap) { return apr_get_os_error(); } base = MapViewOfFile(hMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); if (!base) { CloseHandle(hMap); return apr_get_os_error(); } #endif (*m)->hMap = hMap; (*m)->length = (*m)->memblk->length; (*m)->usrmem = (char*)base + sizeof(memblock_t); (*m)->filename = NULL; apr_pool_cleanup_register((*m)->pool, *m, shm_cleanup, apr_pool_cleanup_null); return APR_SUCCESS; }