dec21140A ethernet driver for virtualpc, contributed by nicolas tittley.
[minix.git] / lib / sysvipc / shm.c
blob50146005b5b79bdf8518fc65ff9b534ed64caf6d
1 #define _SYSTEM 1
2 #define _MINIX 1
4 #include <minix/callnr.h>
5 #include <minix/com.h>
6 #include <minix/config.h>
7 #include <minix/ipc.h>
8 #include <minix/endpoint.h>
9 #include <minix/sysutil.h>
10 #include <minix/const.h>
11 #include <minix/type.h>
12 #include <minix/rs.h>
14 #include <lib.h>
15 #include <sys/types.h>
16 #include <sys/ipc.h>
17 #include <sys/shm.h>
18 #include <time.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <errno.h>
23 PRIVATE int get_ipc_endpt(endpoint_t *pt)
25 return minix_rs_lookup("ipc", pt);
28 /* Shared memory control operation. */
29 PUBLIC int shmctl(int shmid, int cmd, struct shmid_ds *buf)
31 message m;
32 endpoint_t ipc_pt;
33 int r;
35 if (get_ipc_endpt(&ipc_pt) != OK) {
36 errno = ENOSYS;
37 return -1;
40 m.SHMCTL_ID = shmid;
41 m.SHMCTL_CMD = cmd;
42 m.SHMCTL_BUF = (long) buf;
44 r = _syscall(ipc_pt, IPC_SHMCTL, &m);
45 if ((cmd == IPC_INFO || cmd == SHM_INFO || cmd == SHM_STAT)
46 && (r == OK))
47 return m.SHMCTL_RET;
48 return r;
51 /* Get shared memory segment. */
52 PUBLIC int shmget(key_t key, size_t size, int shmflg)
54 message m;
55 endpoint_t ipc_pt;
56 int r;
58 if (get_ipc_endpt(&ipc_pt) != OK) {
59 errno = ENOSYS;
60 return -1;
63 m.SHMGET_KEY = key;
64 m.SHMGET_SIZE = size;
65 m.SHMGET_FLAG = shmflg;
67 r = _syscall(ipc_pt, IPC_SHMGET, &m);
68 if (r != OK)
69 return r;
70 return m.SHMGET_RETID;
73 /* Attach shared memory segment. */
74 PUBLIC void *shmat(int shmid, const void *shmaddr, int shmflg)
76 message m;
77 endpoint_t ipc_pt;
78 int r;
80 if (get_ipc_endpt(&ipc_pt) != OK) {
81 errno = ENOSYS;
82 return NULL;
85 m.SHMAT_ID = shmid;
86 m.SHMAT_ADDR = (long) shmaddr;
87 m.SHMAT_FLAG = shmflg;
89 r = _syscall(ipc_pt, IPC_SHMAT, &m);
90 if (r != OK)
91 return (void *) -1;
92 return (void *) m.SHMAT_RETADDR;
95 /* Deattach shared memory segment. */
96 PUBLIC int shmdt(const void *shmaddr)
98 message m;
99 endpoint_t ipc_pt;
101 if (get_ipc_endpt(&ipc_pt) != OK) {
102 errno = ENOSYS;
103 return -1;
106 m.SHMDT_ADDR = (long) shmaddr;
108 return _syscall(ipc_pt, IPC_SHMDT, &m);