2 #define _MINIX_SYSTEM 1
11 #include <sys/types.h>
19 static int get_ipc_endpt(endpoint_t
*pt
)
21 return minix_rs_lookup("ipc", pt
);
25 int semget(key_t key
, int nsems
, int semflag
)
31 if (get_ipc_endpt(&ipc_pt
) != OK
) {
36 memset(&m
, 0, sizeof(m
));
37 m
.m_lc_ipc_semget
.key
= key
;
38 m
.m_lc_ipc_semget
.nr
= nsems
;
39 m
.m_lc_ipc_semget
.flag
= semflag
;
41 r
= _syscall(ipc_pt
, IPC_SEMGET
, &m
);
45 return m
.m_lc_ipc_semget
.retid
;
48 /* Semaphore control operation. */
49 int semctl(int semid
, int semnum
, int cmd
, ...)
56 if (get_ipc_endpt(&ipc_pt
) != OK
) {
61 memset(&m
, 0, sizeof(m
));
62 m
.m_lc_ipc_semctl
.id
= semid
;
63 m
.m_lc_ipc_semctl
.num
= semnum
;
64 m
.m_lc_ipc_semctl
.cmd
= cmd
;
68 m
.m_lc_ipc_semctl
.opt
= (vir_bytes
)va_arg(ap
, int);
77 m
.m_lc_ipc_semctl
.opt
= (vir_bytes
)va_arg(ap
, void *);
80 m
.m_lc_ipc_semctl
.opt
= 0;
85 r
= _syscall(ipc_pt
, IPC_SEMCTL
, &m
);
86 if ((r
!= -1) && (cmd
== GETNCNT
|| cmd
== GETZCNT
|| cmd
== GETPID
||
87 cmd
== GETVAL
|| cmd
== IPC_INFO
|| cmd
== SEM_INFO
||
89 return m
.m_lc_ipc_semctl
.ret
;
93 /* Operate on semaphore. */
94 int semop(int semid
, struct sembuf
*sops
, size_t nsops
)
99 if (get_ipc_endpt(&ipc_pt
) != OK
) {
104 memset(&m
, 0, sizeof(m
));
105 m
.m_lc_ipc_semop
.id
= semid
;
106 m
.m_lc_ipc_semop
.ops
= sops
;
107 m
.m_lc_ipc_semop
.size
= nsops
;
109 return _syscall(ipc_pt
, IPC_SEMOP
, &m
);