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