| 1 | /* libc/sys/linux/ipc.c - IPC semaphore and message queue functions */ |
|---|
| 2 | |
|---|
| 3 | /* Copyright 2002, Red Hat Inc. */ |
|---|
| 4 | |
|---|
| 5 | #include <sys/types.h> |
|---|
| 6 | #include <sys/sem.h> |
|---|
| 7 | #include <sys/msg.h> |
|---|
| 8 | #include <stdarg.h> |
|---|
| 9 | |
|---|
| 10 | #include <machine/syscall.h> |
|---|
| 11 | |
|---|
| 12 | #define IPC_64 0x100 |
|---|
| 13 | |
|---|
| 14 | #define IPCOP_semop 1 |
|---|
| 15 | #define IPCOP_semget 2 |
|---|
| 16 | #define IPCOP_semctl 3 |
|---|
| 17 | #define IPCOP_msgsnd 11 |
|---|
| 18 | #define IPCOP_msgrcv 12 |
|---|
| 19 | #define IPCOP_msgget 13 |
|---|
| 20 | #define IPCOP_msgctl 14 |
|---|
| 21 | |
|---|
| 22 | static _syscall5(int,ipc,int,op,int,arg1,int,arg2,int,arg3,void *,arg4); |
|---|
| 23 | |
|---|
| 24 | int |
|---|
| 25 | semget (key_t key, int nsems, int semflgs) |
|---|
| 26 | { |
|---|
| 27 | return __libc_ipc(IPCOP_semget, (int)key, nsems, semflgs, NULL); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | int |
|---|
| 31 | semctl (int semid, int semnum, int cmd, ...) |
|---|
| 32 | { |
|---|
| 33 | va_list va; |
|---|
| 34 | union semun { |
|---|
| 35 | int val; |
|---|
| 36 | struct semid_ds *buf; |
|---|
| 37 | unsigned short *array; |
|---|
| 38 | } arg; |
|---|
| 39 | |
|---|
| 40 | va_start (va, cmd); |
|---|
| 41 | |
|---|
| 42 | arg = va_arg (va, union semun); |
|---|
| 43 | |
|---|
| 44 | va_end (va); |
|---|
| 45 | |
|---|
| 46 | return __libc_ipc(IPCOP_semctl, semid, semnum, cmd | IPC_64, &arg); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | int |
|---|
| 50 | semop (int semid, struct sembuf *sops, size_t nsems) |
|---|
| 51 | { |
|---|
| 52 | return __libc_ipc(IPCOP_semop, semid, (int)nsems, 0, sops); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | int |
|---|
| 56 | msgget (key_t key, int msgflg) |
|---|
| 57 | { |
|---|
| 58 | return __libc_ipc(IPCOP_msgget, (int)key, msgflg, 0, NULL); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | int |
|---|
| 62 | msgctl (int msqid, int cmd, struct msqid_ds *buf) |
|---|
| 63 | { |
|---|
| 64 | return __libc_ipc(IPCOP_msgctl, msqid, cmd | IPC_64, 0, buf); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | int |
|---|
| 68 | msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg) |
|---|
| 69 | { |
|---|
| 70 | return __libc_ipc(IPCOP_msgsnd, msqid, (int)msgsz, msgflg, (void *)msgp); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | int |
|---|
| 74 | msgrcv (int msqid, void *msgp, size_t msgsz, long int msgtyp, int msgflg) |
|---|
| 75 | { |
|---|
| 76 | /* last argument must contain multiple args */ |
|---|
| 77 | struct { |
|---|
| 78 | void *msgp; |
|---|
| 79 | long int msgtyp; |
|---|
| 80 | } args; |
|---|
| 81 | |
|---|
| 82 | args.msgp = msgp; |
|---|
| 83 | args.msgtyp = msgtyp; |
|---|
| 84 | |
|---|
| 85 | return (ssize_t)__libc_ipc(IPCOP_msgrcv, msqid, (int)msgsz, msgflg, &args); |
|---|
| 86 | } |
|---|
| 87 | |
|---|