dfhack/shmserver/shms.h

127 lines
2.9 KiB
C

2009-12-22 14:19:39 -07:00
#ifndef DFCONNECT_H
#define DFCONNECT_H
#define PINGPONG_VERSION 1
#define SHM_KEY 123466
2010-01-01 16:21:55 -07:00
#define SHM_HEADER 1024
#define SHM_BODY 1024*1024
#define SHM_SIZE SHM_HEADER+SHM_BODY
2009-12-22 14:19:39 -07:00
2010-01-04 15:20:17 -07:00
#ifdef LINUX_BUILD
2010-01-04 15:20:17 -07:00
// a full memory barrier! better be safe than sorry.
#define full_barrier asm volatile("" ::: "memory"); __sync_synchronize();
#else
// FIXME: detect MSVC here and use the right barrier magic
2010-01-04 15:20:17 -07:00
#define full_barrier
#endif
2009-12-22 14:19:39 -07:00
/*
* read - parameters are address and length
* write - parameters are address, length and the actual data to write
* wait - sent to DF so that it waits for more commands
* end - sent to DF for breaking out of the wait
*/
enum DF_SHM_ERRORSTATE
{
SHM_OK, // all OK
SHM_CANT_GET_SHM, // getting the SHM ID failed for some reason
SHM_CANT_ATTACH, // we can't attach the shm for some reason
SHM_SECOND_DF // we are a second DF process, can't use SHM at all
};
2009-12-22 14:19:39 -07:00
enum DF_PINGPONG
{
DFPP_RUNNING = 0, // no command, normal server execution
DFPP_VERSION, // protocol version query
DFPP_RET_VERSION, // return the protocol version
DFPP_PID, // query for the process ID
DFPP_RET_PID, // return process ID
// version 1 stuff below
DFPP_READ, // cl -> sv, read some data
DFPP_RET_DATA, // sv -> cl, returned data
DFPP_READ_DWORD, // cl -> sv, read a dword
DFPP_RET_DWORD, // sv -> cl, returned dword
DFPP_READ_WORD, // cl -> sv, read a word
DFPP_RET_WORD, // sv -> cl, returned word
DFPP_READ_BYTE, // cl -> sv, read a byte
DFPP_RET_BYTE, // sv -> cl, returned byte
DFPP_SV_ERROR, // there was a server error
DFPP_CL_ERROR, // there was a client error
DFPP_WRITE,// client writes to server
DFPP_WRITE_DWORD,// client writes a DWORD to server
DFPP_WRITE_WORD,// client writes a WORD to server
DFPP_WRITE_BYTE,// client writes a BYTE to server
DFPP_SUSPEND, // client notifies server to wait for commands (server is stalled in busy wait)
DFPP_SUSPENDED, // response to WAIT, server is stalled in busy wait
// similar to DFPP_WRITE, writes to a local buffer, writes the same back to shm, sends DFPP_RET_DATA
// used for benchmarking
DFPP_BOUNCE,
NUM_DFPP
};
enum DF_ERROR
{
DFEE_INVALID_COMMAND,
DFEE_BUFFER_OVERFLOW
};
typedef struct
{
uint32_t pingpong; // = 0
} shm_cmd;
typedef struct
{
uint32_t pingpong;
uint32_t address;
uint32_t length;
} shm_read;
typedef shm_read shm_write;
typedef shm_read shm_bounce;
typedef struct
{
uint32_t pingpong;
} shm_ret_data;
typedef struct
{
uint32_t pingpong;
uint32_t address;
} shm_read_small;
typedef struct
{
uint32_t pingpong;
uint32_t address;
uint32_t value;
} shm_write_small;
typedef struct
{
uint32_t pingpong;
uint32_t value;
} shm_retval;
void SHM_Act (void);
bool isValidSHM();
2010-01-04 15:20:17 -07:00
uint32_t getPID();
2010-01-04 15:20:17 -07:00
#endif