Each DF process on windows now has unique mutex and shm names.

develop
Petr Mrázek 2010-03-09 13:41:55 +01:00
parent 9d7574dafe
commit 3e581908c1
4 changed files with 43 additions and 28 deletions

@ -169,17 +169,23 @@ bool Process::Private::Aux_Core_Attach(bool & versionOK, uint32_t & PID)
Process::Process(uint32_t PID, vector <memory_info *> & known_versions)
: d(new Private())
{
char svmutexname [256];
sprintf(svmutexname,"DFSVMutex-%d",PID);
char clmutexname [256];
sprintf(clmutexname,"DFCLMutex-%d",PID);
// get server and client mutex
d->DFSVMutex = OpenMutex(SYNCHRONIZE,false, "DFSVMutex");
d->DFSVMutex = OpenMutex(SYNCHRONIZE,false, svmutexname);
if(d->DFSVMutex == 0)
{
return;
}
d->DFCLMutex = OpenMutex(SYNCHRONIZE,false, "DFCLMutex");
d->DFCLMutex = OpenMutex(SYNCHRONIZE,false, clmutexname);
if(d->DFCLMutex == 0)
{
return;
}
d->my_pid = PID;
// attach the SHM
if(!attach())
@ -469,8 +475,11 @@ bool Process::attach()
return false; // we couldn't lock it
}
char shmname [256];
sprintf(shmname,"DFShm-%d",d->my_pid);
// now try getting and attaching the shared memory
HANDLE shmHandle = OpenFileMapping(FILE_MAP_ALL_ACCESS,false,"DFShm");
HANDLE shmHandle = OpenFileMapping(FILE_MAP_ALL_ACCESS,false,shmname);
if(!shmHandle)
{
ReleaseMutex(d->DFCLMutex);

@ -183,30 +183,33 @@ DFPP_module InitCore(void)
core.modulestate = 0; // this one is dumb and has no real state
core.reserve(NUM_CORE_CMDS);
// basic states
core.set_command(CORE_RUNNING, CANCELLATION, "Running");
core.set_command(CORE_SUSPEND, CLIENT_WAIT, "Suspend", 0 , CORE_SUSPENDED);
core.set_command(CORE_SUSPENDED, CLIENT_WAIT, "Suspended");
core.set_command(CORE_ERROR, CANCELLATION, "Error");
// utility commands
core.set_command(CORE_ATTACH, FUNCTION,"Core attach",CoreAttach, CORE_SUSPENDED);
core.set_command(CORE_ACQUIRE_MODULE, FUNCTION, "Module lookup", FindModule, CORE_SUSPENDED);
core.set_command(CORE_ACQUIRE_COMMAND, FUNCTION, "Command lookup", FindCommand, CORE_SUSPENDED);
// raw reads
core.set_command(CORE_DFPP_READ, FUNCTION,"Raw read",ReadRaw, CORE_SUSPENDED);
core.set_command(CORE_READ_DWORD, FUNCTION,"Read DWORD",ReadDWord, CORE_SUSPENDED);
core.set_command(CORE_READ_WORD, FUNCTION,"Read WORD",ReadWord, CORE_SUSPENDED);
core.set_command(CORE_READ_BYTE, FUNCTION,"Read BYTE",ReadByte, CORE_SUSPENDED);
core.set_command(CORE_ERROR, CANCELLATION, "Error");
// raw writes
core.set_command(CORE_WRITE, FUNCTION, "Raw write", WriteRaw, CORE_SUSPENDED);
core.set_command(CORE_WRITE_DWORD, FUNCTION, "Write DWORD", WriteDWord, CORE_SUSPENDED);
core.set_command(CORE_WRITE_WORD, FUNCTION, "Write WORD", WriteWord, CORE_SUSPENDED);
core.set_command(CORE_WRITE_BYTE, FUNCTION, "Write BYTE", WriteByte, CORE_SUSPENDED);
// stl string commands
core.set_command(CORE_READ_STL_STRING, FUNCTION, "Read STL string", ReadSTLString, CORE_SUSPENDED);
core.set_command(CORE_READ_C_STRING, CLIENT_WAIT, "RESERVED");
core.set_command(CORE_WRITE_STL_STRING, FUNCTION, "Write STL string", WriteSTLString, CORE_SUSPENDED);
core.set_command(CORE_ACQUIRE_MODULE, FUNCTION, "Module lookup", FindModule, CORE_SUSPENDED);
core.set_command(CORE_ACQUIRE_COMMAND, FUNCTION, "Command lookup", FindCommand, CORE_SUSPENDED);
return core;
}

@ -26,7 +26,7 @@ distribution.
#define SHMS_CORE_H
// increment on every core change
#define CORE_VERSION 6
#define CORE_VERSION 7
typedef struct
{
@ -60,37 +60,33 @@ typedef struct
enum CORE_COMMAND
{
// suspend / resume
// basic states
CORE_RUNNING = 0, // no command, normal server execution
CORE_SUSPEND, // client notifies server to wait for commands (server is stalled in busy wait)
CORE_SUSPENDED, // response to WAIT, server is stalled in busy wait
// aux
CORE_ERROR, // there was a server error
// utility commands
CORE_ATTACH, // compare affinity, get core version and process ID
// reads
CORE_ACQUIRE_MODULE, // get index of a loaded module by name and version
CORE_ACQUIRE_COMMAND, // get module::command callsign by module name, command name and module version
// raw reads
CORE_DFPP_READ, // cl -> sv, read some data
CORE_READ_DWORD, // cl -> sv, read a dword
CORE_READ_WORD, // cl -> sv, read a word
CORE_READ_BYTE, // cl -> sv, read a byte
// writes
// raw writes
CORE_WRITE,// client writes to server
CORE_WRITE_DWORD,// client writes a DWORD to server
CORE_WRITE_WORD,// client writes a WORD to server
CORE_WRITE_BYTE,// client writes a BYTE to server
// error state
CORE_ERROR, // there was a server error
// string functions
CORE_READ_STL_STRING,// client requests contents of STL string at address
CORE_READ_C_STRING,// client requests contents of a C string at address, max length (0 means zero terminated)
CORE_WRITE_STL_STRING,// client wants to set STL string at address to something
// extension module enumeration
CORE_ACQUIRE_MODULE, // get index of a loaded module by name and version
CORE_ACQUIRE_COMMAND, // get module::command callsign by module name, command name and module version
// total commands
NUM_CORE_CMDS

@ -38,7 +38,7 @@ distribution.
#include <string>
#include "shms.h"
#include "mod-core.h"
#include <cstdio>
#include <stdio.h>
int errorstate = 0;
char *shm = 0;
int shmid = 0;
@ -56,21 +56,28 @@ void SHM_Init ( void )
}
inited = true;
char svmutexname [256];
sprintf(svmutexname,"DFSVMutex-%d",OS_getPID());
char clmutexname [256];
sprintf(clmutexname,"DFCLMutex-%d",OS_getPID());
char shmname [256];
sprintf(shmname,"DFShm-%d",OS_getPID());
// create or open mutexes
DFSVMutex = CreateMutex( 0, 1, "DFSVMutex");
DFSVMutex = CreateMutex( 0, 1, svmutexname);
if(DFSVMutex == 0)
{
DFSVMutex = OpenMutex(SYNCHRONIZE,false, "DFSVMutex");
DFSVMutex = OpenMutex(SYNCHRONIZE,false, svmutexname);
if(DFSVMutex == 0)
{
errorstate = 1;
return;
}
}
DFCLMutex = CreateMutex( 0, 0, "DFCLMutex");
DFCLMutex = CreateMutex( 0, 0, clmutexname);
if(DFCLMutex == 0)
{
DFCLMutex = OpenMutex(SYNCHRONIZE,false, "DFCLMutex");
DFCLMutex = OpenMutex(SYNCHRONIZE,false, clmutexname);
if(DFCLMutex == 0)
{
CloseHandle(DFSVMutex);
@ -110,7 +117,7 @@ void SHM_Init ( void )
}
// create virtual memory mapping
shmHandle = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,SHM_SIZE,"DFShm");
shmHandle = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,SHM_SIZE,shmname);
// if can't create or already exists -> nothing happens
if(GetLastError() == ERROR_ALREADY_EXISTS)
{