2007-05-23 21:02:19 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2007-09-26 10:17:43 +00:00
|
|
|
#elif (!defined(__EMX__))
|
|
|
|
#include <sys/stat.h>
|
2007-05-23 21:02:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "shmem.h"
|
2007-05-23 22:36:07 +00:00
|
|
|
#include "filesys.h"
|
2007-05-23 21:02:19 +00:00
|
|
|
#include "app_ipc.h"
|
|
|
|
#include "boinc_api.h"
|
|
|
|
#include "graphics2.h"
|
|
|
|
|
2007-09-26 10:17:43 +00:00
|
|
|
#ifdef __EMX__
|
2007-05-23 21:02:19 +00:00
|
|
|
static key_t get_shmem_name(char* prog_name) {
|
|
|
|
char cwd[256], path[256];
|
2007-05-23 22:36:07 +00:00
|
|
|
boinc_getcwd(cwd);
|
2007-05-23 21:02:19 +00:00
|
|
|
sprintf(path, "%s/init_data.xml", cwd);
|
|
|
|
return ftok(path, 2);
|
|
|
|
}
|
2007-09-26 10:17:43 +00:00
|
|
|
#else
|
|
|
|
// V6 Unix/Linux/Mac applications always use mmap() shared memory for gfx communication
|
|
|
|
static void get_shmem_name(char* prog_name, char* shmem_name) {
|
|
|
|
APP_INIT_DATA aid;
|
|
|
|
boinc_get_init_data(aid);
|
|
|
|
sprintf(shmem_name, "boinc_%s_%d", prog_name, aid.slot);
|
|
|
|
}
|
2007-05-23 21:02:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void* boinc_graphics_make_shmem(char* prog_name, int size) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE shmem_handle;
|
|
|
|
char shmem_name[256];
|
|
|
|
void* p;
|
|
|
|
get_shmem_name(prog_name, shmem_name);
|
|
|
|
shmem_handle = create_shmem(shmem_name, size, &p, false);
|
|
|
|
if (shmem_handle == NULL) return 0;
|
|
|
|
return p;
|
|
|
|
#else
|
|
|
|
void* p;
|
2007-09-26 10:17:43 +00:00
|
|
|
#ifdef __EMX__
|
|
|
|
key_t key = get_shmem_name(prog_name);
|
|
|
|
int retval = create_shmem(key, size, 0, &p);
|
|
|
|
#else
|
|
|
|
// V6 Unix/Linux/Mac applications always use mmap() shared memory for graphics communication
|
2007-08-29 01:26:57 +00:00
|
|
|
char shmem_name[256];
|
|
|
|
get_shmem_name(prog_name, shmem_name);
|
2007-09-26 10:17:43 +00:00
|
|
|
int retval = create_shmem_mmap(shmem_name, size, &p);
|
2007-09-04 07:40:18 +00:00
|
|
|
// Graphics app may be run by a different user & group than worker app
|
|
|
|
// Although create_shmem passed 0666 to open(), it was modified by umask
|
|
|
|
if (retval == 0) chmod(shmem_name, 0666);
|
2007-08-27 09:17:38 +00:00
|
|
|
#endif
|
2007-05-23 21:02:19 +00:00
|
|
|
if (retval) return 0;
|
|
|
|
return p;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2007-08-27 09:17:38 +00:00
|
|
|
void* boinc_graphics_get_shmem(char* prog_name) {
|
2007-05-23 21:02:19 +00:00
|
|
|
HANDLE shmem_handle;
|
|
|
|
char shmem_name[256];
|
|
|
|
void* p;
|
|
|
|
get_shmem_name(prog_name, shmem_name);
|
|
|
|
shmem_handle = attach_shmem(shmem_name, &p);
|
2007-09-27 03:34:27 +00:00
|
|
|
if (shmem_handle == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-05-23 21:02:19 +00:00
|
|
|
return p;
|
2007-08-27 09:17:38 +00:00
|
|
|
}
|
2007-05-23 21:02:19 +00:00
|
|
|
#else
|
2007-08-27 09:17:38 +00:00
|
|
|
void* boinc_graphics_get_shmem(char* prog_name) {
|
2007-05-23 21:02:19 +00:00
|
|
|
void* p;
|
2007-09-04 07:40:18 +00:00
|
|
|
int retval;
|
2007-09-26 10:17:43 +00:00
|
|
|
#ifdef __EMX__
|
2007-05-23 21:02:19 +00:00
|
|
|
key_t key = get_shmem_name(prog_name);
|
2007-09-04 07:40:18 +00:00
|
|
|
retval = attach_shmem(key, &p);
|
2007-09-26 10:17:43 +00:00
|
|
|
#else
|
|
|
|
// V6 Unix/Linux/Mac applications always use mmap() shared memory for graphics communication
|
|
|
|
char shmem_name[256];
|
|
|
|
get_shmem_name(prog_name, shmem_name);
|
|
|
|
retval = attach_shmem_mmap(shmem_name, &p);
|
2007-08-27 12:27:48 +00:00
|
|
|
#endif
|
2007-05-23 21:02:19 +00:00
|
|
|
if (retval) return 0;
|
|
|
|
return p;
|
2007-05-23 22:36:07 +00:00
|
|
|
}
|
2007-08-27 09:17:38 +00:00
|
|
|
#endif
|