2011-02-17 18:11:09 +01:00
|
|
|
#define _SYSTEM 1
|
2014-03-05 12:21:55 +01:00
|
|
|
#define _MINIX_SYSTEM 1
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <lib.h>
|
|
|
|
#include "namespace.h"
|
|
|
|
|
|
|
|
#include <minix/rs.h>
|
|
|
|
|
|
|
|
#include <lib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2013-11-04 22:48:08 +01:00
|
|
|
#include <string.h>
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
static int get_ipc_endpt(endpoint_t *pt)
|
|
|
|
{
|
|
|
|
return minix_rs_lookup("ipc", pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach shared memory segment. */
|
|
|
|
void *shmat(int shmid, const void *shmaddr, int shmflg)
|
|
|
|
{
|
|
|
|
message m;
|
|
|
|
endpoint_t ipc_pt;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (get_ipc_endpt(&ipc_pt) != OK) {
|
|
|
|
errno = ENOSYS;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2011-02-17 18:11:09 +01:00
|
|
|
m.SHMAT_ID = shmid;
|
|
|
|
m.SHMAT_ADDR = (long) shmaddr;
|
|
|
|
m.SHMAT_FLAG = shmflg;
|
|
|
|
|
|
|
|
r = _syscall(ipc_pt, IPC_SHMAT, &m);
|
|
|
|
if (r != OK)
|
|
|
|
return (void *) -1;
|
|
|
|
return (void *) m.SHMAT_RETADDR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Deattach shared memory segment. */
|
|
|
|
int shmdt(const void *shmaddr)
|
|
|
|
{
|
|
|
|
message m;
|
|
|
|
endpoint_t ipc_pt;
|
|
|
|
|
|
|
|
if (get_ipc_endpt(&ipc_pt) != OK) {
|
|
|
|
errno = ENOSYS;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
2011-02-17 18:11:09 +01:00
|
|
|
m.SHMDT_ADDR = (long) shmaddr;
|
|
|
|
|
|
|
|
return _syscall(ipc_pt, IPC_SHMDT, &m);
|
|
|
|
}
|
|
|
|
|