• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <sys/sem.h>
2 #include <stdarg.h>
3 #include <endian.h>
4 #include <unsupported_api.h>
5 
6 #include "syscall.h"
7 #include "ipc.h"
8 
9 #if __BYTE_ORDER != __BIG_ENDIAN
10 #undef SYSCALL_IPC_BROKEN_MODE
11 #endif
12 
13 union semun {
14 	int val;
15 	struct semid_ds *buf;
16 	unsigned short *array;
17 };
18 
semctl(int id,int num,int cmd,...)19 int semctl(int id, int num, int cmd, ...)
20 {
21 	unsupported_api(__FUNCTION__);
22 	union semun arg = {0};
23 	va_list ap;
24 	switch (cmd & ~IPC_TIME64) {
25 	case SETVAL: case GETALL: case SETALL: case IPC_SET:
26 	case IPC_INFO: case SEM_INFO:
27 	case IPC_STAT & ~IPC_TIME64:
28 	case SEM_STAT & ~IPC_TIME64:
29 	case SEM_STAT_ANY & ~IPC_TIME64:
30 		va_start(ap, cmd);
31 		arg = va_arg(ap, union semun);
32 		va_end(ap);
33 	}
34 #ifdef SYSCALL_IPC_BROKEN_MODE
35 	struct semid_ds tmp;
36 	if (cmd == IPC_SET) {
37 		tmp = *arg.buf;
38 		tmp.sem_perm.mode *= 0x10000U;
39 		arg.buf = &tmp;
40 	}
41 #endif
42 #ifndef SYS_ipc
43 	int r = __syscall(SYS_semctl, id, num, IPC_CMD(cmd), arg.buf);
44 #else
45 	int r = __syscall(SYS_ipc, IPCOP_semctl, id, num, IPC_CMD(cmd), &arg.buf);
46 #endif
47 #ifdef SYSCALL_IPC_BROKEN_MODE
48 	if (r >= 0) switch (cmd | IPC_TIME64) {
49 	case IPC_STAT:
50 	case SEM_STAT:
51 	case SEM_STAT_ANY:
52 		arg.buf->sem_perm.mode >>= 16;
53 	}
54 #endif
55 #if IPC_TIME64
56 	if (r >= 0 && (cmd&IPC_TIME64)) {
57 		IPC_HILO(arg.buf, sem_otime);
58 		IPC_HILO(arg.buf, sem_ctime);
59 	}
60 #endif
61 	return __syscall_ret(r);
62 }
63