xref: /minix/minix/lib/libc/sys/shmctl.c (revision 83133719)
1 #define _SYSTEM	1
2 #define _MINIX_SYSTEM	1
3 
4 #include <sys/cdefs.h>
5 #include <lib.h>
6 #include "namespace.h"
7 
8 #include <minix/rs.h>
9 #include <lib.h>
10 #include <sys/types.h>
11 #include <sys/ipc.h>
12 #include <sys/shm.h>
13 #include <stdlib.h>
14 #include <errno.h>
15 #include <string.h>
16 
17 static int get_ipc_endpt(endpoint_t *pt)
18 {
19 	return minix_rs_lookup("ipc", pt);
20 }
21 
22 /* Shared memory control operation. */
23 int shmctl(int shmid, int cmd, struct shmid_ds *buf)
24 {
25 	message m;
26 	endpoint_t ipc_pt;
27 	int r;
28 
29 	if (get_ipc_endpt(&ipc_pt) != OK) {
30 		errno = ENOSYS;
31 		return -1;
32 	}
33 
34 	memset(&m, 0, sizeof(m));
35 	m.m_lc_ipc_shmctl.id = shmid;
36 	m.m_lc_ipc_shmctl.cmd = cmd;
37 	m.m_lc_ipc_shmctl.buf = buf;
38 
39 	r = _syscall(ipc_pt, IPC_SHMCTL, &m);
40 	if ((cmd == IPC_INFO || cmd == SHM_INFO || cmd == SHM_STAT)
41 		&& (r == OK))
42 		return m.m_lc_ipc_shmctl.ret;
43 	return r;
44 }
45 
46 #if defined(__minix) && defined(__weak_alias)
47 __weak_alias(shmctl, __shmctl50)
48 #endif
49