retire BIOS_SEG and umap_bios
[minix3.git] / lib / libc / sys-minix / shmat.c
blob6ed02ce58a928b62bdd26c685c1ed9750e79a668
1 #define _SYSTEM 1
2 #define _MINIX 1
4 #include <sys/cdefs.h>
5 #include <lib.h>
6 #include "namespace.h"
8 #include <minix/rs.h>
10 #include <lib.h>
11 #include <sys/types.h>
12 #include <sys/ipc.h>
13 #include <sys/shm.h>
14 #include <stdlib.h>
15 #include <errno.h>
17 #ifdef __weak_alias
18 __weak_alias(shmat, _shmat)
19 __weak_alias(shmdt, _shmdt)
20 #endif
23 static int get_ipc_endpt(endpoint_t *pt)
25 return minix_rs_lookup("ipc", pt);
28 /* Attach shared memory segment. */
29 void *shmat(int shmid, const void *shmaddr, int shmflg)
31 message m;
32 endpoint_t ipc_pt;
33 int r;
35 if (get_ipc_endpt(&ipc_pt) != OK) {
36 errno = ENOSYS;
37 return NULL;
40 m.SHMAT_ID = shmid;
41 m.SHMAT_ADDR = (long) shmaddr;
42 m.SHMAT_FLAG = shmflg;
44 r = _syscall(ipc_pt, IPC_SHMAT, &m);
45 if (r != OK)
46 return (void *) -1;
47 return (void *) m.SHMAT_RETADDR;
50 /* Deattach shared memory segment. */
51 int shmdt(const void *shmaddr)
53 message m;
54 endpoint_t ipc_pt;
56 if (get_ipc_endpt(&ipc_pt) != OK) {
57 errno = ENOSYS;
58 return -1;
61 m.SHMDT_ADDR = (long) shmaddr;
63 return _syscall(ipc_pt, IPC_SHMDT, &m);