summaryrefslogtreecommitdiff
path: root/libc/misc/sysvipc
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-03-19 21:51:29 +0000
committerEric Andersen <andersen@codepoet.org>2001-03-19 21:51:29 +0000
commit91a034c61a32ebd6601fb8b894127d43b817f5fc (patch)
tree9f8cf05b7a61fe9d51651d4476dafc9235cc1552 /libc/misc/sysvipc
parentd777bf75160493485c76754012735e911fbde5e1 (diff)
Add in the sysvipc patch from Michael Shmulevich
Diffstat (limited to 'libc/misc/sysvipc')
-rw-r--r--libc/misc/sysvipc/.indent.pro33
-rw-r--r--libc/misc/sysvipc/Makefile71
-rw-r--r--libc/misc/sysvipc/ftok.c38
-rw-r--r--libc/misc/sysvipc/ipc.h22
-rw-r--r--libc/misc/sysvipc/sem.c79
-rw-r--r--libc/misc/sysvipc/shm.c82
6 files changed, 325 insertions, 0 deletions
diff --git a/libc/misc/sysvipc/.indent.pro b/libc/misc/sysvipc/.indent.pro
new file mode 100644
index 000000000..492ecf1c7
--- /dev/null
+++ b/libc/misc/sysvipc/.indent.pro
@@ -0,0 +1,33 @@
+--blank-lines-after-declarations
+--blank-lines-after-procedures
+--break-before-boolean-operator
+--no-blank-lines-after-commas
+--braces-on-if-line
+--braces-on-struct-decl-line
+--comment-indentation25
+--declaration-comment-column25
+--no-comment-delimiters-on-blank-lines
+--cuddle-else
+--continuation-indentation4
+--case-indentation0
+--else-endif-column33
+--space-after-cast
+--line-comments-indentation0
+--declaration-indentation1
+--dont-format-first-column-comments
+--dont-format-comments
+--honour-newlines
+--indent-level4
+/* changed from 0 to 4 */
+--parameter-indentation4
+--line-length78 /* changed from 75 */
+--continue-at-parentheses
+--no-space-after-function-call-names
+--dont-break-procedure-type
+--dont-star-comments
+--leave-optional-blank-lines
+--dont-space-special-semicolon
+--tab-size4
+/* additions by Mark */
+--case-brace-indentation0
+--leave-preprocessor-space
diff --git a/libc/misc/sysvipc/Makefile b/libc/misc/sysvipc/Makefile
new file mode 100644
index 000000000..d2c8f8e66
--- /dev/null
+++ b/libc/misc/sysvipc/Makefile
@@ -0,0 +1,71 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000 by Lineo, inc.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Library General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Library General Public License
+# along with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Derived in part from the Linux-8086 C library, the GNU C Library, and several
+# other sundry sources. Files within this library are copyright by their
+# respective copyright holders.
+
+TOPDIR=../../
+include $(TOPDIR)Rules.mak
+LIBC=$(TOPDIR)libc.a
+
+MSRC=sem.c
+MOBJ=semget.o semctl.o semop.o
+
+MSRC2=shm.c
+MOBJ2=shmat.o shmctl.o shmdt.o shmget.o
+
+CSRC = ftok.c
+COBJS=$(patsubst %.c,%.o, $(CSRC))
+
+OBJS=$(MOBJ) $(MOBJ2) $(COBJS)
+
+
+all: $(OBJS) $(LIBC)
+
+$(LIBC): ar-target subdirs
+
+ar-target: $(OBJS)
+ $(AR) $(ARFLAGS) $(LIBC) $(OBJS)
+
+$(MOBJ): $(MSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(STRIPTOOL) -x -R .note -R .comment $*.o
+
+$(MOBJ2): $(MSRC2)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(STRIPTOOL) -x -R .note -R .comment $*.o
+
+$(COBJS): %.o : %.c
+ $(CC) $(CFLAGS) -c $< -o $@
+ $(STRIPTOOL) -x -R .note -R .comment $*.o
+
+clean: subdirs_clean
+ rm -f *.[oa] *~ core
+
+subdirs: $(patsubst %, _dir_%, $(DIRS))
+subdirs_clean: $(patsubst %, _dirclean_%, $(DIRS))
+
+$(patsubst %, _dir_%, $(DIRS)) : dummy
+ $(MAKE) -C $(patsubst _dir_%, %, $@)
+
+$(patsubst %, _dirclean_%, $(DIRS)) : dummy
+ $(MAKE) -C $(patsubst _dirclean_%, %, $@) clean
+
+.PHONY: dummy
+
diff --git a/libc/misc/sysvipc/ftok.c b/libc/misc/sysvipc/ftok.c
new file mode 100644
index 000000000..06843edda
--- /dev/null
+++ b/libc/misc/sysvipc/ftok.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <sys/ipc.h>
+#include <sys/stat.h>
+
+key_t
+ftok (pathname, proj_id)
+ const char *pathname;
+ int proj_id;
+{
+ struct stat st;
+ key_t key;
+
+ if (_xstat (_STAT_VER, pathname, &st) < 0)
+ return (key_t) -1;
+
+ key = ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16)
+ | ((proj_id & 0xff) << 24));
+
+ return key;
+}
diff --git a/libc/misc/sysvipc/ipc.h b/libc/misc/sysvipc/ipc.h
new file mode 100644
index 000000000..19e6bd106
--- /dev/null
+++ b/libc/misc/sysvipc/ipc.h
@@ -0,0 +1,22 @@
+#ifndef IPC_H
+#define IPC_H
+
+/* The actual system call: all functions are multiplexed by this. */
+extern int __ipc __P((int __call, int __first, int __second,
+ int __third, void *__ptr));
+
+
+/* The codes for the functions to use the multiplexer `__syscall_ipc'. */
+#define IPCOP_semop 1
+#define IPCOP_semget 2
+#define IPCOP_semctl 3
+#define IPCOP_msgsnd 11
+#define IPCOP_msgrcv 12
+#define IPCOP_msgget 13
+#define IPCOP_msgctl 14
+#define IPCOP_shmat 21
+#define IPCOP_shmdt 22
+#define IPCOP_shmget 23
+#define IPCOP_shmctl 24
+
+#endif /* IPC_H */
diff --git a/libc/misc/sysvipc/sem.c b/libc/misc/sysvipc/sem.c
new file mode 100644
index 000000000..83724d4c6
--- /dev/null
+++ b/libc/misc/sysvipc/sem.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <sys/sem.h>
+#include "ipc.h"
+
+#ifdef L_semctl
+/* Return identifier for array of NSEMS semaphores associated with
+ KEY. */
+#include <stdarg.h>
+/* Define a `union semun' suitable for Linux here. */
+union semun
+{
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
+ unsigned short int *array; /* array for GETALL & SETALL */
+ struct seminfo *__buf; /* buffer for IPC_INFO */
+};
+
+
+int
+semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg;
+ va_list ap;
+
+ va_start (ap, cmd);
+
+ /* Get the argument. */
+ arg = va_arg (ap, union semun);
+
+ va_end (ap);
+
+ return __ipc(IPCOP_semctl, semid, semnum, cmd, &arg);
+}
+#endif
+
+#ifdef L_semget
+#include <stdlib.h> /* for definition of NULL */
+/* Return identifier for array of NSEMS semaphores associated with
+ KEY. */
+int
+semget (key, nsems, semflg)
+ key_t key;
+ int nsems;
+ int semflg;
+{
+ return __ipc(IPCOP_semget, key, nsems, semflg, NULL);
+}
+#endif
+
+#ifdef L_semop
+/* Perform user-defined atomical operation of array of semaphores. */
+int
+semop (semid, sops, nsops)
+ int semid;
+ struct sembuf *sops;
+ unsigned int nsops;
+{
+ return __ipc(IPCOP_semop, semid, (int) nsops, 0, sops);
+}
+#endif
diff --git a/libc/misc/sysvipc/shm.c b/libc/misc/sysvipc/shm.c
new file mode 100644
index 000000000..5fdfe6ca7
--- /dev/null
+++ b/libc/misc/sysvipc/shm.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <errno.h>
+#include <sys/shm.h>
+#include "ipc.h"
+
+#ifdef L_shmat
+/* Attach the shared memory segment associated with SHMID to the data
+ segment of the calling process. SHMADDR and SHMFLG determine how
+ and where the segment is attached. */
+
+void *
+shmat (shmid, shmaddr, shmflg)
+ int shmid;
+ const void *shmaddr;
+ int shmflg;
+{
+ int retval;
+ unsigned long raddr;
+
+ retval = __ipc(IPCOP_shmat, shmid, shmflg, (int) &raddr, (void *) shmaddr);
+ return ((unsigned long int) retval > -(unsigned long int) SHMLBA
+ ? (void *) retval : (void *) raddr);
+}
+#endif
+
+#ifdef L_shmctl
+/* Provide operations to control over shared memory segments. */
+
+int
+shmctl (shmid, cmd, buf)
+ int shmid;
+ int cmd;
+ struct shmid_ds *buf;
+{
+ return __ipc(IPCOP_shmctl, shmid, cmd, 0, buf);
+}
+#endif
+
+
+#ifdef L_shmdt
+/* Detach shared memory segment starting at address specified by SHMADDR
+ from the caller's data segment. */
+
+int
+shmdt (shmaddr)
+ const void *shmaddr;
+{
+ return __ipc(IPCOP_shmdt, 0, 0, 0, (void *) shmaddr);
+}
+#endif
+
+#ifdef L_shmget
+/* Return an identifier for an shared memory segment of at least size SIZE
+ which is associated with KEY. */
+
+int
+shmget (key, size, shmflg)
+ key_t key;
+ size_t size;
+ int shmflg;
+{
+ return __ipc(IPCOP_shmget, key, size, shmflg, NULL);
+}
+#endif