custom message type for SHMCTL, SEMCTL, SEMGET

This commit is contained in:
Ben Gras 2014-07-26 13:53:53 +02:00 committed by Lionel Sambuc
parent e57d31d331
commit c476408dea
6 changed files with 66 additions and 47 deletions

View file

@ -830,22 +830,10 @@
#define IPC_SHMAT (IPC_BASE+2) #define IPC_SHMAT (IPC_BASE+2)
#define IPC_SHMDT (IPC_BASE+3) #define IPC_SHMDT (IPC_BASE+3)
#define IPC_SHMCTL (IPC_BASE+4) #define IPC_SHMCTL (IPC_BASE+4)
# define SHMCTL_ID m2_i1
# define SHMCTL_CMD m2_i2
# define SHMCTL_BUF m2_l1
# define SHMCTL_RET m2_i3
/* Semaphore */ /* Semaphore */
#define IPC_SEMGET (IPC_BASE+5) #define IPC_SEMGET (IPC_BASE+5)
# define SEMGET_KEY m2_l1
# define SEMGET_NR m2_i1
# define SEMGET_FLAG m2_i2
# define SEMGET_RETID m2_i3
#define IPC_SEMCTL (IPC_BASE+6) #define IPC_SEMCTL (IPC_BASE+6)
# define SEMCTL_ID m2_i1
# define SEMCTL_NUM m2_i2
# define SEMCTL_CMD m2_i3
# define SEMCTL_OPT m2_l1
#define IPC_SEMOP (IPC_BASE+7) #define IPC_SEMOP (IPC_BASE+7)
# define SEMOP_ID m2_i1 # define SEMOP_ID m2_i1
# define SEMOP_OPS m2_l1 # define SEMOP_OPS m2_l1

View file

@ -1789,6 +1789,34 @@ typedef struct {
} mess_lc_ipc_shmdt; } mess_lc_ipc_shmdt;
_ASSERT_MSG_SIZE(mess_lc_ipc_shmdt); _ASSERT_MSG_SIZE(mess_lc_ipc_shmdt);
typedef struct {
int id;
int cmd;
void *buf;
int ret;
uint8_t padding[40];
} mess_lc_ipc_shmctl;
_ASSERT_MSG_SIZE(mess_lc_ipc_shmctl);
typedef struct {
key_t key;
int nr;
int flag;
int retid;
uint8_t padding[40];
} mess_lc_ipc_semget;
_ASSERT_MSG_SIZE(mess_lc_ipc_semget);
typedef struct {
int id;
int num;
int cmd;
int opt;
int ret;
uint8_t padding[36];
} mess_lc_ipc_semctl;
_ASSERT_MSG_SIZE(mess_lc_ipc_semctl);
typedef struct { typedef struct {
endpoint_t m_source; /* who sent the message */ endpoint_t m_source; /* who sent the message */
int m_type; /* what kind of message is it */ int m_type; /* what kind of message is it */
@ -2018,6 +2046,9 @@ typedef struct {
mess_lc_ipc_shmget m_lc_ipc_shmget; mess_lc_ipc_shmget m_lc_ipc_shmget;
mess_lc_ipc_shmat m_lc_ipc_shmat; mess_lc_ipc_shmat m_lc_ipc_shmat;
mess_lc_ipc_shmdt m_lc_ipc_shmdt; mess_lc_ipc_shmdt m_lc_ipc_shmdt;
mess_lc_ipc_shmctl m_lc_ipc_shmctl;
mess_lc_ipc_semget m_lc_ipc_semget;
mess_lc_ipc_semctl m_lc_ipc_semctl;
mess_vfs_lchardriver_cancel m_vfs_lchardriver_cancel; mess_vfs_lchardriver_cancel m_vfs_lchardriver_cancel;
mess_vfs_lchardriver_openclose m_vfs_lchardriver_openclose; mess_vfs_lchardriver_openclose m_vfs_lchardriver_openclose;

View file

@ -35,15 +35,15 @@ int semget(key_t key, int nsems, int semflag)
} }
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.SEMGET_KEY = key; m.m_lc_ipc_semget.key = key;
m.SEMGET_NR = nsems; m.m_lc_ipc_semget.nr = nsems;
m.SEMGET_FLAG = semflag; m.m_lc_ipc_semget.flag = semflag;
r = _syscall(ipc_pt, IPC_SEMGET, &m); r = _syscall(ipc_pt, IPC_SEMGET, &m);
if (r != OK) if (r != OK)
return r; return r;
return m.SEMGET_RETID; return m.m_lc_ipc_semget.retid;
} }
/* Semaphore control operation. */ /* Semaphore control operation. */
@ -60,21 +60,21 @@ int semctl(int semid, int semnum, int cmd, ...)
} }
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.SEMCTL_ID = semid; m.m_lc_ipc_semctl.id = semid;
m.SEMCTL_NUM = semnum; m.m_lc_ipc_semctl.num = semnum;
m.SEMCTL_CMD = cmd; m.m_lc_ipc_semctl.cmd = cmd;
va_start(ap, cmd); va_start(ap, cmd);
if (cmd == IPC_STAT || cmd == IPC_SET || cmd == IPC_INFO || if (cmd == IPC_STAT || cmd == IPC_SET || cmd == IPC_INFO ||
cmd == SEM_INFO || cmd == SEM_STAT || cmd == GETALL || cmd == SEM_INFO || cmd == SEM_STAT || cmd == GETALL ||
cmd == SETALL || cmd == SETVAL) cmd == SETALL || cmd == SETVAL)
m.SEMCTL_OPT = (long) va_arg(ap, long); m.m_lc_ipc_semctl.opt = (long) va_arg(ap, long);
va_end(ap); va_end(ap);
r = _syscall(ipc_pt, IPC_SEMCTL, &m); r = _syscall(ipc_pt, IPC_SEMCTL, &m);
if ((r != -1) && (cmd == GETNCNT || cmd == GETZCNT || cmd == GETPID || if ((r != -1) && (cmd == GETNCNT || cmd == GETZCNT || cmd == GETPID ||
cmd == GETVAL || cmd == IPC_INFO || cmd == SEM_INFO || cmd == GETVAL || cmd == IPC_INFO || cmd == SEM_INFO ||
cmd == SEM_STAT)) cmd == SEM_STAT))
return m.SHMCTL_RET; return m.m_lc_ipc_semctl.ret;
return r; return r;
} }

View file

@ -32,14 +32,14 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf)
} }
memset(&m, 0, sizeof(m)); memset(&m, 0, sizeof(m));
m.SHMCTL_ID = shmid; m.m_lc_ipc_shmctl.id = shmid;
m.SHMCTL_CMD = cmd; m.m_lc_ipc_shmctl.cmd = cmd;
m.SHMCTL_BUF = (long) buf; m.m_lc_ipc_shmctl.buf = buf;
r = _syscall(ipc_pt, IPC_SHMCTL, &m); r = _syscall(ipc_pt, IPC_SHMCTL, &m);
if ((cmd == IPC_INFO || cmd == SHM_INFO || cmd == SHM_STAT) if ((cmd == IPC_INFO || cmd == SHM_INFO || cmd == SHM_STAT)
&& (r == OK)) && (r == OK))
return m.SHMCTL_RET; return m.m_lc_ipc_shmctl.ret;
return r; return r;
} }

View file

@ -57,9 +57,9 @@ int do_semget(message *m)
int nsems, flag, id; int nsems, flag, id;
struct sem_struct *sem; struct sem_struct *sem;
key = m->SEMGET_KEY; key = m->m_lc_ipc_semget.key;
nsems = m->SEMGET_NR; nsems = m->m_lc_ipc_semget.nr;
flag = m->SEMGET_FLAG; flag = m->m_lc_ipc_semget.flag;
if ((sem = sem_find_key(key))) { if ((sem = sem_find_key(key))) {
if ((flag & IPC_CREAT) && (flag & IPC_EXCL)) if ((flag & IPC_CREAT) && (flag & IPC_EXCL))
@ -94,7 +94,7 @@ int do_semget(message *m)
sem_list_nr++; sem_list_nr++;
} }
m->SEMGET_RETID = id; m->m_lc_ipc_semget.retid = id;
return OK; return OK;
} }
@ -287,14 +287,14 @@ int do_semctl(message *m)
struct semid_ds *ds, tmp_ds; struct semid_ds *ds, tmp_ds;
struct sem_struct *sem; struct sem_struct *sem;
id = m->SEMCTL_ID; id = m->m_lc_ipc_semctl.id;
num = m->SEMCTL_NUM; num = m->m_lc_ipc_semctl.num;
cmd = m->SEMCTL_CMD; cmd = m->m_lc_ipc_semctl.cmd;
if (cmd == IPC_STAT || cmd == IPC_SET || cmd == IPC_INFO || if (cmd == IPC_STAT || cmd == IPC_SET || cmd == IPC_INFO ||
cmd == SEM_INFO || cmd == SEM_STAT || cmd == GETALL || cmd == SEM_INFO || cmd == SEM_STAT || cmd == GETALL ||
cmd == SETALL || cmd == SETVAL) cmd == SETALL || cmd == SETVAL)
opt = m->SEMCTL_OPT; opt = m->m_lc_ipc_semctl.opt;
if (!(sem = sem_find_id(id))) { if (!(sem = sem_find_id(id))) {
return EINVAL; return EINVAL;
@ -367,22 +367,22 @@ int do_semctl(message *m)
case GETNCNT: case GETNCNT:
if (num < 0 || num >= sem->semid_ds.sem_nsems) if (num < 0 || num >= sem->semid_ds.sem_nsems)
return EINVAL; return EINVAL;
m->SHMCTL_RET = sem->sems[num].semncnt; m->m_lc_ipc_semctl.ret = sem->sems[num].semncnt;
break; break;
case GETPID: case GETPID:
if (num < 0 || num >= sem->semid_ds.sem_nsems) if (num < 0 || num >= sem->semid_ds.sem_nsems)
return EINVAL; return EINVAL;
m->SHMCTL_RET = sem->sems[num].sempid; m->m_lc_ipc_semctl.ret = sem->sems[num].sempid;
break; break;
case GETVAL: case GETVAL:
if (num < 0 || num >= sem->semid_ds.sem_nsems) if (num < 0 || num >= sem->semid_ds.sem_nsems)
return EINVAL; return EINVAL;
m->SHMCTL_RET = sem->sems[num].semval; m->m_lc_ipc_semctl.ret = sem->sems[num].semval;
break; break;
case GETZCNT: case GETZCNT:
if (num < 0 || num >= sem->semid_ds.sem_nsems) if (num < 0 || num >= sem->semid_ds.sem_nsems)
return EINVAL; return EINVAL;
m->SHMCTL_RET = sem->sems[num].semzcnt; m->m_lc_ipc_semctl.ret = sem->sems[num].semzcnt;
break; break;
case SETALL: case SETALL:
buf = malloc(sizeof(unsigned short) * sem->semid_ds.sem_nsems); buf = malloc(sizeof(unsigned short) * sem->semid_ds.sem_nsems);

View file

@ -217,9 +217,9 @@ int do_shmdt(message *m)
*===========================================================================*/ *===========================================================================*/
int do_shmctl(message *m) int do_shmctl(message *m)
{ {
int id = m->SHMCTL_ID; int id = m->m_lc_ipc_shmctl.id;
int cmd = m->SHMCTL_CMD; int cmd = m->m_lc_ipc_shmctl.cmd;
struct shmid_ds *ds = (struct shmid_ds *)m->SHMCTL_BUF; struct shmid_ds *ds = (struct shmid_ds *)m->m_lc_ipc_shmctl.buf;
struct shmid_ds tmp_ds; struct shmid_ds tmp_ds;
struct shm_struct *shm = NULL; struct shm_struct *shm = NULL;
struct shminfo sinfo; struct shminfo sinfo;
@ -286,9 +286,9 @@ int do_shmctl(message *m)
who_e, (vir_bytes)ds, sizeof(struct shminfo)); who_e, (vir_bytes)ds, sizeof(struct shminfo));
if (r != OK) if (r != OK)
return EFAULT; return EFAULT;
m->SHMCTL_RET = shm_list_nr - 1; m->m_lc_ipc_shmctl.ret = (shm_list_nr - 1);
if (m->SHMCTL_RET < 0) if (m->m_lc_ipc_shmctl.ret < 0)
m->SHMCTL_RET = 0; m->m_lc_ipc_shmctl.ret = 0;
break; break;
case SHM_INFO: case SHM_INFO:
if (!ds) if (!ds)
@ -306,9 +306,9 @@ int do_shmctl(message *m)
who_e, (vir_bytes)ds, sizeof(struct shm_info)); who_e, (vir_bytes)ds, sizeof(struct shm_info));
if (r != OK) if (r != OK)
return EFAULT; return EFAULT;
m->SHMCTL_RET = shm_list_nr - 1; m->m_lc_ipc_shmctl.ret = shm_list_nr - 1;
if (m->SHMCTL_RET < 0) if (m->m_lc_ipc_shmctl.ret < 0)
m->SHMCTL_RET = 0; m->m_lc_ipc_shmctl.ret = 0;
break; break;
case SHM_STAT: case SHM_STAT:
if (id < 0 || id >= shm_list_nr) if (id < 0 || id >= shm_list_nr)
@ -318,7 +318,7 @@ int do_shmctl(message *m)
who_e, (vir_bytes)ds, sizeof(struct shmid_ds)); who_e, (vir_bytes)ds, sizeof(struct shmid_ds));
if (r != OK) if (r != OK)
return EFAULT; return EFAULT;
m->SHMCTL_RET = shm->id; m->m_lc_ipc_shmctl.ret = shm->id;
break; break;
default: default:
return EINVAL; return EINVAL;