OSDN Git Service

Add in the sysvipc patch from Michael Shmulevich
authorEric Andersen <andersen@codepoet.org>
Mon, 19 Mar 2001 21:51:29 +0000 (21:51 -0000)
committerEric Andersen <andersen@codepoet.org>
Mon, 19 Mar 2001 21:51:29 +0000 (21:51 -0000)
include/sys/sem.h [new file with mode: 0644]
libc/misc/Makefile
libc/misc/sysvipc/.indent.pro [new file with mode: 0644]
libc/misc/sysvipc/Makefile [new file with mode: 0644]
libc/misc/sysvipc/ftok.c [new file with mode: 0644]
libc/misc/sysvipc/ipc.h [new file with mode: 0644]
libc/misc/sysvipc/sem.c [new file with mode: 0644]
libc/misc/sysvipc/shm.c [new file with mode: 0644]

diff --git a/include/sys/sem.h b/include/sys/sem.h
new file mode 100644 (file)
index 0000000..6ae76e2
--- /dev/null
@@ -0,0 +1,58 @@
+/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   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.  */
+
+#ifndef _SYS_SEM_H
+#define _SYS_SEM_H     1
+
+#include <features.h>
+
+#include <sys/types.h>
+
+/* Get common definition of System V style IPC.  */
+#include <sys/ipc.h>
+
+/* Get system dependent definition of `struct semid_ds' and more.  */
+#include <bits/sem.h>
+
+/* The following System V style IPC functions implement a semaphore
+   handling.  The definition is found in XPG2.  */
+
+/* Structure used for argument to `semop' to describe operations.  */
+struct sembuf
+{
+  short int sem_num;           /* semaphore number */
+  short int sem_op;            /* semaphore operation */
+  short int sem_flg;           /* operation flag */
+};
+
+
+__BEGIN_DECLS
+
+/* Semaphore control operation.  */
+extern int semctl __P ((int __semid, int __semnum, int __cmd, ...));
+
+/* Get semaphore.  */
+extern int semget __P ((key_t __key, int __nsems, int __semflg));
+
+/* Operate on semaphore.  */
+extern int semop __P ((int __semid, struct sembuf *__sops,
+                      unsigned int __nsops));
+
+__END_DECLS
+
+#endif /* sys/sem.h */
index 3bae40b..47c0edd 100644 (file)
@@ -25,14 +25,8 @@ include $(TOPDIR)Rules.mak
 LIBC=$(TOPDIR)libc.a
 
 
-DIRS = assert crypt ctype fnmatch glob internals lsearch mntent syslog shm \
-       time utmp tsearch locale
-
-# regex bombs out with an internal compiler error using m68k-pic-coff-gcc.
-ifneq ($(TARGET_ARCH),m68k)
-       DIRS += regex
-endif
-
+DIRS = assert crypt ctype fnmatch glob internals lsearch mntent syslog \
+       time utmp tsearch locale sysvipc
 
 all: libc.a
 
diff --git a/libc/misc/sysvipc/.indent.pro b/libc/misc/sysvipc/.indent.pro
new file mode 100644 (file)
index 0000000..492ecf1
--- /dev/null
@@ -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 (file)
index 0000000..d2c8f8e
--- /dev/null
@@ -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 (file)
index 0000000..06843ed
--- /dev/null
@@ -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 (file)
index 0000000..19e6bd1
--- /dev/null
@@ -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 (file)
index 0000000..83724d4
--- /dev/null
@@ -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 (file)
index 0000000..5fdfe6c
--- /dev/null
@@ -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