From: Ben Gras Date: Mon, 21 Sep 2009 14:41:03 +0000 (+0000) Subject: new sysv ipc call stubs X-Git-Tag: v3.1.5~132 X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=1c217d038cf8805aee676071097481ff4ee0c595;p=minix.git new sysv ipc call stubs --- diff --git a/lib/Makefile b/lib/Makefile index ad4d8b320..cc8b0a072 100755 --- a/lib/Makefile +++ b/lib/Makefile @@ -49,6 +49,8 @@ all-ack: makefiles cd util && $(MAKE) $@ mkdir -p obj-ack//./sysutil cd sysutil && $(MAKE) $@ + mkdir -p obj-ack//./sysvipc + cd sysvipc && $(MAKE) $@ mkdir -p obj-ack//./timers cd timers && $(MAKE) $@ mkdir -p obj-ack//./i386 @@ -91,6 +93,8 @@ all-gnu: makefiles cd util && $(MAKE) $@ mkdir -p obj-gnu/./sysutil cd sysutil && $(MAKE) $@ + mkdir -p obj-gnu/./sysvipc + cd sysvipc && $(MAKE) $@ mkdir -p obj-gnu/./timers cd timers && $(MAKE) $@ mkdir -p obj-gnu/./i386 @@ -117,6 +121,7 @@ clean depend depend-ack depend-gnu:: makefiles cd syslib && $(MAKE) $@ cd util && $(MAKE) $@ cd sysutil && $(MAKE) $@ + cd sysvipc && $(MAKE) $@ cd timers && $(MAKE) $@ cd i386 && $(MAKE) $@ cd ack && $(MAKE) $@ @@ -138,6 +143,7 @@ makefiles: syscall/Makefile makefiles: syslib/Makefile makefiles: util/Makefile makefiles: sysutil/Makefile +makefiles: sysvipc/Makefile makefiles: timers/Makefile makefiles: i386/Makefile makefiles: ack/Makefile @@ -175,6 +181,8 @@ util/Makefile: util/Makefile.in cd util && sh ../generate.sh ./util ../obj-ack/ ../obj-gnu && $(MAKE) makefiles sysutil/Makefile: sysutil/Makefile.in cd sysutil && sh ../generate.sh ./sysutil ../obj-ack/ ../obj-gnu && $(MAKE) makefiles +sysvipc/Makefile: sysvipc/Makefile.in + cd sysvipc && sh ../generate.sh ./sysvipc ../obj-ack/ ../obj-gnu && $(MAKE) makefiles timers/Makefile: timers/Makefile.in cd timers && sh ../generate.sh ./timers ../obj-ack/ ../obj-gnu && $(MAKE) makefiles i386/Makefile: i386/Makefile.in diff --git a/lib/sysvipc/Makefile.in b/lib/sysvipc/Makefile.in new file mode 100644 index 000000000..67f72e61c --- /dev/null +++ b/lib/sysvipc/Makefile.in @@ -0,0 +1,10 @@ +# Makefile for lib/posix. + +CFLAGS="-O -D_MINIX -D_POSIX_SOURCE" + +LIBRARIES=libc + +libc_FILES="ftok.c sem.c shm.c" + +TYPE=both + diff --git a/lib/sysvipc/ds.c b/lib/sysvipc/ds.c new file mode 100644 index 000000000..c79796a8e --- /dev/null +++ b/lib/sysvipc/ds.c @@ -0,0 +1,41 @@ +#define _SYSTEM 1 +#define _MINIX 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +int mini_ds_retrieve_u32(char *ds_name, u32_t *value) +{ + int r; + message m; + size_t len_key; + + len_key = strlen(ds_name)+1; + + m.DS_KEY_GRANT = ds_name; + m.DS_KEY_LEN = len_key; + m.DS_FLAGS = DS_TYPE_U32; + + r = _taskcall(DS_PROC_NR, DS_RETRIEVE_LIBC, &m); + + if(r == OK) { + /* Assign u32 value. */ + *value = m.DS_VAL; + } + + return r; +} + diff --git a/lib/sysvipc/ftok.c b/lib/sysvipc/ftok.c new file mode 100644 index 000000000..e2e891284 --- /dev/null +++ b/lib/sysvipc/ftok.c @@ -0,0 +1,15 @@ +#include +#include + +key_t ftok(const char *path, int id) +{ + struct stat st; + + if (lstat(path, &st) < 0) + return (key_t) -1; + + return (key_t) ((st.st_ino & 0xffff) | + ((st.st_dev & 0xff) << 16) | + ((id & 0xff) << 24)); +} + diff --git a/lib/sysvipc/sem.c b/lib/sysvipc/sem.c new file mode 100644 index 000000000..b0e87722f --- /dev/null +++ b/lib/sysvipc/sem.c @@ -0,0 +1,100 @@ +#define __USE_MISC +#define _SYSTEM 1 +#define _MINIX 1 + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +PRIVATE int get_ipc_endpt(endpoint_t *pt) +{ + return minix_rs_lookup("ipc", pt); +} + +/* Get semaphore. */ +PUBLIC int semget(key_t key, int nsems, int semflag) +{ + message m; + endpoint_t ipc_pt; + int r; + + if (get_ipc_endpt(&ipc_pt) != OK) { + errno = ENOSYS; + return -1; + } + + m.SEMGET_KEY = key; + m.SEMGET_NR = nsems; + m.SEMGET_FLAG = semflag; + + r = _syscall(ipc_pt, IPC_SEMGET, &m); + if (r != OK) + return r; + + return m.SEMGET_RETID; +} + +/* Semaphore control operation. */ +PUBLIC int semctl(int semid, int semnum, int cmd, ...) +{ + message m; + endpoint_t ipc_pt; + va_list ap; + int r; + + if (get_ipc_endpt(&ipc_pt) != OK) { + errno = ENOSYS; + return -1; + } + + m.SEMCTL_ID = semid; + m.SEMCTL_NUM = semnum; + m.SEMCTL_CMD = cmd; + va_start(ap, cmd); + if (cmd == IPC_STAT || cmd == IPC_SET || cmd == IPC_INFO || + cmd == SEM_INFO || cmd == SEM_STAT || cmd == GETALL || + cmd == SETALL || cmd == SETVAL) + m.SEMCTL_OPT = (long) va_arg(ap, long); + va_end(ap); + + r = _syscall(ipc_pt, IPC_SEMCTL, &m); + if ((r != -1) && (cmd == GETNCNT || cmd == GETZCNT || cmd == GETPID || + cmd == GETVAL || cmd == IPC_INFO || cmd == SEM_INFO || + cmd == SEM_STAT)) + return m.SHMCTL_RET; + return r; +} + +/* Operate on semaphore. */ +PUBLIC int semop(int semid, struct sembuf *sops, size_t nsops) +{ + message m; + endpoint_t ipc_pt; + + if (get_ipc_endpt(&ipc_pt) != OK) { + errno = ENOSYS; + return -1; + } + + m.SEMOP_ID = semid; + m.SEMOP_OPS = (long) sops; + m.SEMOP_SIZE = nsops; + + return _syscall(ipc_pt, IPC_SEMOP, &m); +} + diff --git a/lib/sysvipc/shm.c b/lib/sysvipc/shm.c new file mode 100644 index 000000000..50146005b --- /dev/null +++ b/lib/sysvipc/shm.c @@ -0,0 +1,110 @@ +#define _SYSTEM 1 +#define _MINIX 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +PRIVATE int get_ipc_endpt(endpoint_t *pt) +{ + return minix_rs_lookup("ipc", pt); +} + +/* Shared memory control operation. */ +PUBLIC int shmctl(int shmid, int cmd, struct shmid_ds *buf) +{ + message m; + endpoint_t ipc_pt; + int r; + + if (get_ipc_endpt(&ipc_pt) != OK) { + errno = ENOSYS; + return -1; + } + + m.SHMCTL_ID = shmid; + m.SHMCTL_CMD = cmd; + m.SHMCTL_BUF = (long) buf; + + r = _syscall(ipc_pt, IPC_SHMCTL, &m); + if ((cmd == IPC_INFO || cmd == SHM_INFO || cmd == SHM_STAT) + && (r == OK)) + return m.SHMCTL_RET; + return r; +} + +/* Get shared memory segment. */ +PUBLIC int shmget(key_t key, size_t size, int shmflg) +{ + message m; + endpoint_t ipc_pt; + int r; + + if (get_ipc_endpt(&ipc_pt) != OK) { + errno = ENOSYS; + return -1; + } + + m.SHMGET_KEY = key; + m.SHMGET_SIZE = size; + m.SHMGET_FLAG = shmflg; + + r = _syscall(ipc_pt, IPC_SHMGET, &m); + if (r != OK) + return r; + return m.SHMGET_RETID; +} + +/* Attach shared memory segment. */ +PUBLIC void *shmat(int shmid, const void *shmaddr, int shmflg) +{ + message m; + endpoint_t ipc_pt; + int r; + + if (get_ipc_endpt(&ipc_pt) != OK) { + errno = ENOSYS; + return NULL; + } + + m.SHMAT_ID = shmid; + m.SHMAT_ADDR = (long) shmaddr; + m.SHMAT_FLAG = shmflg; + + r = _syscall(ipc_pt, IPC_SHMAT, &m); + if (r != OK) + return (void *) -1; + return (void *) m.SHMAT_RETADDR; +} + +/* Deattach shared memory segment. */ +PUBLIC int shmdt(const void *shmaddr) +{ + message m; + endpoint_t ipc_pt; + + if (get_ipc_endpt(&ipc_pt) != OK) { + errno = ENOSYS; + return -1; + } + + m.SHMDT_ADDR = (long) shmaddr; + + return _syscall(ipc_pt, IPC_SHMDT, &m); +} +