From e217832c4c4d8dba3c13af35b1d107851271b77d Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 22 Oct 2003 10:07:59 +0000 Subject: * Makefile.in: Add $(LIBSERVER) rule. * cygserver.h: Moved from include/cygwin to here. * cygserver_ipc.h: Moved from ../cygserver to here. * cygserver_shm.h: Ditto. * cygwin.din: Add shmat, shmctl, shmdt and shmget. * fhandler_tty.cc (fhandler_tty_slave::open): Don't warn about handle dup'ing if not build with USE_SERVER. * shm.cc: Include cygerrno.h unconditionally. (shmat): Set errno to ENOSYS and return -1 if not build with USE_SERVER. (shmctl): Ditto. (shmdt): Ditto. (shmget): Ditto. * woutsup.h: Remove. * include/cygwin/cygserver_process.h: Moved to ../cygserver directory. * include/cygwin/cygserver_transport.h: Ditto. * include/cygwin/cygserver_transport_pipes.h: Ditto. * include/cygwin/cygserver_transport_sockets.h: Ditto. * include/cygwin/version.h: Bump API minor number. --- winsup/cygwin/cygserver_ipc.h | 84 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 winsup/cygwin/cygserver_ipc.h (limited to 'winsup/cygwin/cygserver_ipc.h') diff --git a/winsup/cygwin/cygserver_ipc.h b/winsup/cygwin/cygserver_ipc.h new file mode 100644 index 000000000..0d0ebbc76 --- /dev/null +++ b/winsup/cygwin/cygserver_ipc.h @@ -0,0 +1,84 @@ +/* cygserver_ipc.h + + Copyright 2002 Red Hat, Inc. + + Originally written by Conrad Scott + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#ifndef __CYGSERVER_IPC_H__ +#define __CYGSERVER_IPC_H__ + +#include +#include /* For OPEN_MAX. */ + +/* + * The sysv ipc id's (msgid, semid, shmid) are integers arranged such + * that they no subsystem will generate the same id as some other + * subsystem; nor do these ids overlap file descriptors (the other + * common integer ids). Since Cygwin can allocate more than OPEN_MAX + * file descriptors, it can't be guaranteed not to overlap, but it + * should help catch some errors. + * + * msgid's: OPEN_MAX, OPEN_MAX + 3, OPEN_MAX + 6, . . . + * semid's: OPEN_MAX + 1, OPEN_MAX + 4, OPEN_MAX + 7, . . . + * shmid's: OPEN_MAX + 2, OPEN_MAX + 5, OPEN_MAX + 8, . . . + * + * To further ensure that ids are unique, if ipc objects are created + * and destroyed and then re-created, they are given new ids by + * munging the basic id (as above) with a sequence number. + * + * Internal ipc id's, which are 0, 1, ... within each subsystem (and + * not munged with a sequence number), are used solely by the ipcs(8) + * interface. + */ + +enum ipc_subsys_t + { + IPC_MSGOP = 0, + IPC_SEMOP = 1, + IPC_SHMOP = 2, + IPC_SUBSYS_COUNT + }; + +/* + * IPCMNI - The absolute maximum number of simultaneous ipc ids for + * any one subsystem. + */ + +enum + { + IPCMNI = 0x10000 // Must be a power of two. + }; + +inline int +ipc_int2ext (const int intid, const ipc_subsys_t subsys, long & sequence) +{ + assert (0 <= intid && intid < IPCMNI); + + const long tmp = InterlockedIncrement (&sequence); + + return (((tmp & 0x7fff) << 16) + | (OPEN_MAX + (intid * IPC_SUBSYS_COUNT) + subsys)); +} + +inline int +ipc_ext2int_subsys (const int extid) +{ + return ((extid & (IPCMNI - 1)) - OPEN_MAX) % IPC_SUBSYS_COUNT; +} + +inline int +ipc_ext2int (const int extid, const ipc_subsys_t subsys) +{ + if (ipc_ext2int_subsys (extid) != subsys) + return -1; + else + return ((extid & (IPCMNI - 1)) - OPEN_MAX) / IPC_SUBSYS_COUNT; +} + +#endif /* __CYGSERVER_IPC_H__ */ -- cgit v1.2.3