From 567970786e0db398b9c2a990efb9060b95406e12 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 22 Oct 2003 10:04:11 +0000 Subject: [PATCH] Accomodate moving cygserver header files from cygwin/include/cygwin to here and cygwin dir. * Makefile.in (EXEEXT): Drop as unused. (EXEEXT_FOR_BUILD): Ditto. (all): Don't build libcygserver.a. * cygserver_process.h: Moved from cygwin/include/cygwin to here. * cygserver_transport.h: Ditto. * cygserver_transport_pipes.h: Ditto. * cygserver_transport_sockets.h: Ditto. * ipc.h: Moved to ../cygwin and renamed to cygserver_ipc.h. * shm.h: Moved to ../cygwin and renamed to cygserver_shm.h. --- winsup/cygserver/ChangeLog | 14 ++ winsup/cygserver/Makefile.in | 5 +- winsup/cygserver/client.cc | 4 +- winsup/cygserver/cygserver.cc | 6 +- winsup/cygserver/cygserver_process.h | 164 ++++++++++++++++++ winsup/cygserver/cygserver_transport.h | 39 +++++ winsup/cygserver/cygserver_transport_pipes.h | 53 ++++++ .../cygserver/cygserver_transport_sockets.h | 46 +++++ winsup/cygserver/ipc.h | 84 --------- winsup/cygserver/process.cc | 2 +- winsup/cygserver/shm.cc | 6 +- winsup/cygserver/shm.h | 147 ---------------- winsup/cygserver/transport.cc | 6 +- winsup/cygserver/transport_pipes.cc | 6 +- winsup/cygserver/transport_sockets.cc | 4 +- 15 files changed, 334 insertions(+), 252 deletions(-) create mode 100644 winsup/cygserver/cygserver_process.h create mode 100644 winsup/cygserver/cygserver_transport.h create mode 100644 winsup/cygserver/cygserver_transport_pipes.h create mode 100644 winsup/cygserver/cygserver_transport_sockets.h delete mode 100644 winsup/cygserver/ipc.h delete mode 100755 winsup/cygserver/shm.h diff --git a/winsup/cygserver/ChangeLog b/winsup/cygserver/ChangeLog index 813192a49..cb76730c4 100644 --- a/winsup/cygserver/ChangeLog +++ b/winsup/cygserver/ChangeLog @@ -1,3 +1,17 @@ +2003-10-22 Corinna Vinschen + + Accomodate moving cygserver header files from cygwin/include/cygwin + to here and cygwin dir. + * Makefile.in (EXEEXT): Drop as unused. + (EXEEXT_FOR_BUILD): Ditto. + (all): Don't build libcygserver.a. + * cygserver_process.h: Moved from cygwin/include/cygwin to here. + * cygserver_transport.h: Ditto. + * cygserver_transport_pipes.h: Ditto. + * cygserver_transport_sockets.h: Ditto. + * ipc.h: Moved to ../cygwin and renamed to cygserver_ipc.h. + * shm.h: Moved to ../cygwin and renamed to cygserver_shm.h. + 2003-08-30 Christopher Faylor * msg.cc: New file. diff --git a/winsup/cygserver/Makefile.in b/winsup/cygserver/Makefile.in index 5780dab99..767fcaa1f 100644 --- a/winsup/cygserver/Makefile.in +++ b/winsup/cygserver/Makefile.in @@ -22,9 +22,6 @@ INSTALL:=@INSTALL@ INSTALL_PROGRAM:=@INSTALL_PROGRAM@ INSTALL_DATA:=@INSTALL_DATA@ -EXEEXT:=@EXEEXT@ -EXEEXT_FOR_BUILD:=@EXEEXT_FOR_BUILD@ - CC:=@CC@ CC_FOR_TARGET:=$(CC) CXX:=@CXX@ @@ -44,7 +41,7 @@ LIBOBJS:=${patsubst %.o,lib%.o,$(OBJS)} CYGWIN_OBJS:=$(cygwin_build)/smallprint.o $(cygwin_build)/version.o \ $(cygwin_build)/wincap.o -all: cygserver.exe libcygserver.a +all: cygserver.exe install: all diff --git a/winsup/cygserver/client.cc b/winsup/cygserver/client.cc index eedc6769b..600ddbd67 100644 --- a/winsup/cygserver/client.cc +++ b/winsup/cygserver/client.cc @@ -25,8 +25,8 @@ details. */ #include "cygserver_shm.h" #include "safe_memory.h" -#include "cygwin/cygserver.h" -#include "cygwin/cygserver_transport.h" +#include "cygserver.h" +#include "cygserver_transport.h" int cygserver_running = CYGSERVER_UNKNOWN; // Nb: inherited by children. diff --git a/winsup/cygserver/cygserver.cc b/winsup/cygserver/cygserver.cc index 137730f9e..f152fc588 100644 --- a/winsup/cygserver/cygserver.cc +++ b/winsup/cygserver/cygserver.cc @@ -26,9 +26,9 @@ details. */ #include "cygerrno.h" #include "cygwin_version.h" -#include "cygwin/cygserver.h" -#include "cygwin/cygserver_process.h" -#include "cygwin/cygserver_transport.h" +#include "cygserver.h" +#include "cygserver_process.h" +#include "cygserver_transport.h" // Version string. static const char version[] = "$Revision$"; diff --git a/winsup/cygserver/cygserver_process.h b/winsup/cygserver/cygserver_process.h new file mode 100644 index 000000000..25c634e9e --- /dev/null +++ b/winsup/cygserver/cygserver_process.h @@ -0,0 +1,164 @@ +/* cygserver_process.h + + Copyright 2001, 2002 Red Hat Inc. + + Written by Robert Collins + +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_PROCESS_ +#define _CYGSERVER_PROCESS_ + +#include + +#include "threaded_queue.h" + +class process_cleanup : public queue_request +{ +public: + process_cleanup (class process *const theprocess) + : _process (theprocess) + { + assert (_process); + } + + virtual ~process_cleanup (); + + virtual void process (); + +private: + class process *const _process; +}; + +class process; + +class cleanup_routine +{ + friend class process; + +public: + cleanup_routine (void *const key) + : _key (key), + _next (NULL) + {} + + virtual ~cleanup_routine (); + + bool operator== (const cleanup_routine &rhs) const + { + return _key == rhs._key; + } + + void *key () const { return _key; } + + /* MUST BE SYNCHRONOUS */ + virtual void cleanup (class process *) = 0; + +private: + void *const _key; + cleanup_routine *_next; +}; + +class process_cache; + +class process +{ + friend class process_cache; + friend class process_cleanup; + +public: + process (pid_t cygpid, DWORD winpid); + ~process (); + + pid_t cygpid () const { return _cygpid; } + DWORD winpid () const { return _winpid; } + HANDLE handle () const { return _hProcess; } + + bool is_active () const { return _exit_status == STILL_ACTIVE; } + + void hold () { EnterCriticalSection (&_access); } + void release () { LeaveCriticalSection (&_access); } + + bool add (cleanup_routine *); + bool remove (const cleanup_routine *); + +private: + const pid_t _cygpid; + const DWORD _winpid; + HANDLE _hProcess; + long _cleaning_up; + DWORD _exit_status; // Set in the constructor and in exit_code (). + cleanup_routine *_routines_head; + /* used to prevent races-on-delete */ + CRITICAL_SECTION _access; + class process *_next; + + DWORD check_exit_code (); + void cleanup (); +}; + +class process_cache +{ + // Number of special (i.e., non-process) handles in _wait_array. + // See wait_for_processes () and sync_wait_array () for details. + enum { + SPECIALS_COUNT = 2 + }; + + class submission_loop : public queue_submission_loop + { + public: + submission_loop (process_cache *const cache, threaded_queue *const queue) + : queue_submission_loop (queue, true), + _cache (cache) + { + assert (_cache); + } + + private: + process_cache *const _cache; + + virtual void request_loop (); + }; + + friend class submission_loop; + +public: + process_cache (unsigned int initial_workers); + ~process_cache (); + + class process *process (pid_t cygpid, DWORD winpid); + + bool running () const { return _queue.running (); } + + bool start () { return _queue.start (); } + bool stop () { return _queue.stop (); } + +private: + threaded_queue _queue; + submission_loop _submitter; + + size_t _processes_count; + class process *_processes_head; // A list sorted by winpid. + + // Access to the _wait_array and related fields is not thread-safe, + // since they are used solely by wait_for_processes () and its callees. + + HANDLE _wait_array[MAXIMUM_WAIT_OBJECTS]; + class process *_process_array[MAXIMUM_WAIT_OBJECTS]; + + HANDLE _cache_add_trigger; // Actually both add and remove. + CRITICAL_SECTION _cache_write_access; // Actually both read and write access. + + void wait_for_processes (HANDLE interrupt); + size_t sync_wait_array (HANDLE interrupt); + void check_and_remove_process (const size_t index); + + class process *find (DWORD winpid, class process **previous = NULL); +}; + +#endif /* _CYGSERVER_PROCESS_ */ diff --git a/winsup/cygserver/cygserver_transport.h b/winsup/cygserver/cygserver_transport.h new file mode 100644 index 000000000..915f35e66 --- /dev/null +++ b/winsup/cygserver/cygserver_transport.h @@ -0,0 +1,39 @@ +/* cygserver_transport.h + + Copyright 2001, 2002 Red Hat Inc. + + Written by Robert Collins + +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_TRANSPORT_ +#define _CYGSERVER_TRANSPORT_ + +class transport_layer_base *create_server_transport (); + +class transport_layer_base +{ +public: +#ifndef __INSIDE_CYGWIN__ + virtual int listen () = 0; + virtual class transport_layer_base *accept (bool *recoverable) = 0; +#endif + + virtual void close () = 0; + virtual ssize_t read (void *buf, size_t len) = 0; + virtual ssize_t write (void *buf, size_t len) = 0; + virtual int connect () = 0; + +#ifndef __INSIDE_CYGWIN__ + virtual void impersonate_client (); + virtual void revert_to_self (); +#endif + + virtual ~transport_layer_base (); +}; + +#endif /* _CYGSERVER_TRANSPORT_ */ diff --git a/winsup/cygserver/cygserver_transport_pipes.h b/winsup/cygserver/cygserver_transport_pipes.h new file mode 100644 index 000000000..4bea2eb13 --- /dev/null +++ b/winsup/cygserver/cygserver_transport_pipes.h @@ -0,0 +1,53 @@ +/* cygserver_transport_pipes.h + + Copyright 2001, 2002 Red Hat Inc. + + Written by Robert Collins + +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_TRANSPORT_PIPES_ +#define _CYGSERVER_TRANSPORT_PIPES_ + +/* Named pipes based transport, for security on NT */ +class transport_layer_pipes : public transport_layer_base +{ +public: +#ifndef __INSIDE_CYGWIN__ + virtual int listen (); + virtual class transport_layer_pipes *accept (bool *recoverable); +#endif + + virtual void close (); + virtual ssize_t read (void *buf, size_t len); + virtual ssize_t write (void *buf, size_t len); + virtual int connect (); + +#ifndef __INSIDE_CYGWIN__ + virtual void impersonate_client (); + virtual void revert_to_self (); +#endif + + transport_layer_pipes (); + virtual ~transport_layer_pipes (); + +private: + /* for pipe based communications */ + void init_security (); + + //FIXME: allow inited, sd, all_nih_.. to be static members + SECURITY_DESCRIPTOR _sd; + SECURITY_ATTRIBUTES _sec_all_nih; + const char *const _pipe_name; + HANDLE _hPipe; + const bool _is_accepted_endpoint; + bool _is_listening_endpoint; + + transport_layer_pipes (HANDLE hPipe); +}; + +#endif /* _CYGSERVER_TRANSPORT_PIPES_ */ diff --git a/winsup/cygserver/cygserver_transport_sockets.h b/winsup/cygserver/cygserver_transport_sockets.h new file mode 100644 index 000000000..d960f9c2c --- /dev/null +++ b/winsup/cygserver/cygserver_transport_sockets.h @@ -0,0 +1,46 @@ +/* cygserver_transport_sockets.h + + Copyright 2001, 2002 Red Hat Inc. + + Written by Robert Collins + +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_TRANSPORT_SOCKETS_ +#define _CYGSERVER_TRANSPORT_SOCKETS_ + +#include +#include + +class transport_layer_sockets : public transport_layer_base +{ +public: +#ifndef __INSIDE_CYGWIN__ + virtual int listen (); + virtual class transport_layer_sockets *accept (bool *recoverable); +#endif + + virtual void close (); + virtual ssize_t read (void *buf, size_t len); + virtual ssize_t write (void *buf, size_t len); + virtual int connect (); + + transport_layer_sockets (); + virtual ~transport_layer_sockets (); + +private: + /* for socket based communications */ + int _fd; + struct sockaddr_un _addr; + socklen_t _addr_len; + const bool _is_accepted_endpoint; + bool _is_listening_endpoint; + + transport_layer_sockets (int fd); +}; + +#endif /* _CYGSERVER_TRANSPORT_SOCKETS_ */ diff --git a/winsup/cygserver/ipc.h b/winsup/cygserver/ipc.h deleted file mode 100644 index 0d0ebbc76..000000000 --- a/winsup/cygserver/ipc.h +++ /dev/null @@ -1,84 +0,0 @@ -/* 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__ */ diff --git a/winsup/cygserver/process.cc b/winsup/cygserver/process.cc index 2cc7be19c..aa8294f57 100644 --- a/winsup/cygserver/process.cc +++ b/winsup/cygserver/process.cc @@ -19,7 +19,7 @@ details. */ #include "cygerrno.h" -#include "cygwin/cygserver_process.h" +#include "cygserver_process.h" /*****************************************************************************/ diff --git a/winsup/cygserver/shm.cc b/winsup/cygserver/shm.cc index 90053eec2..50d2b6e1d 100644 --- a/winsup/cygserver/shm.cc +++ b/winsup/cygserver/shm.cc @@ -23,9 +23,9 @@ details. */ #include "cygserver_shm.h" #include "security.h" -#include "cygwin/cygserver.h" -#include "cygwin/cygserver_process.h" -#include "cygwin/cygserver_transport.h" +#include "cygserver.h" +#include "cygserver_process.h" +#include "cygserver_transport.h" /*---------------------------------------------------------------------------* * class server_shmmgr diff --git a/winsup/cygserver/shm.h b/winsup/cygserver/shm.h deleted file mode 100755 index 5a5ee3820..000000000 --- a/winsup/cygserver/shm.h +++ /dev/null @@ -1,147 +0,0 @@ -/* cygserver_shm.h: Single unix specification IPC interface for Cygwin. - - Copyright 2002 Red Hat, Inc. - - Written by Conrad Scott . - Based on code by Robert Collins . - -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_SHM_H__ -#define __CYGSERVER_SHM_H__ - -#include -#include - -#include -#include - -#include "cygserver_ipc.h" - -#include "cygwin/cygserver.h" - -/*---------------------------------------------------------------------------* - * Values for the shminfo entries. - * - * Nb. The values are segregated between two enums so that the `small' - * values aren't promoted to `unsigned long' equivalents. - *---------------------------------------------------------------------------*/ - -enum - { - SHMMAX = ULONG_MAX, - SHMSEG = ULONG_MAX, - SHMALL = ULONG_MAX - }; - -enum - { - SHMMIN = 1, - SHMMNI = IPCMNI // Must be <= IPCMNI. - }; - -/*---------------------------------------------------------------------------* - * class client_request_shm - *---------------------------------------------------------------------------*/ - -#ifndef __INSIDE_CYGWIN__ -class transport_layer_base; -class process_cache; -#endif - -class client_request_shm : public client_request -{ - friend class client_request; - -public: - enum shmop_t - { - SHMOP_shmat, - SHMOP_shmctl, - SHMOP_shmdt, - SHMOP_shmget - }; - -#ifdef __INSIDE_CYGWIN__ - client_request_shm (int shmid, int shmflg); // shmat - client_request_shm (int shmid, int cmd, const struct shmid_ds *); // shmctl - client_request_shm (int shmid); // shmdt - client_request_shm (key_t, size_t, int shmflg); // shmget -#endif - - // Accessors for out parameters. - - int shmid () const - { - assert (!error_code ()); - return _parameters.out.shmid; - } - - HANDLE hFileMap () const - { - assert (!error_code ()); - return _parameters.out.hFileMap; - } - - const struct shmid_ds & ds () const - { - assert (!error_code ()); - return _parameters.out.ds; - } - - const struct shminfo & shminfo () const - { - assert (!error_code ()); - return _parameters.out.shminfo; - } - - const struct shm_info & shm_info () const - { - assert (!error_code ()); - return _parameters.out.shm_info; - } - -private: - union - { - struct - { - shmop_t shmop; - key_t key; - size_t size; - int shmflg; - int shmid; - int cmd; - pid_t cygpid; - DWORD winpid; - __uid32_t uid; - __gid32_t gid; - struct shmid_ds ds; - } in; - - struct { - int shmid; - union - { - HANDLE hFileMap; - struct shmid_ds ds; - struct shminfo shminfo; - struct shm_info shm_info; - }; - } out; - } _parameters; - -#ifndef __INSIDE_CYGWIN__ - client_request_shm (); -#endif - -#ifndef __INSIDE_CYGWIN__ - virtual void serve (transport_layer_base *, process_cache *); -#endif -}; - -#endif /* __CYGSERVER_SHM_H__ */ diff --git a/winsup/cygserver/transport.cc b/winsup/cygserver/transport.cc index 8684a6148..2c7100d77 100644 --- a/winsup/cygserver/transport.cc +++ b/winsup/cygserver/transport.cc @@ -21,9 +21,9 @@ details. */ #include "safe_memory.h" -#include "cygwin/cygserver_transport.h" -#include "cygwin/cygserver_transport_pipes.h" -#include "cygwin/cygserver_transport_sockets.h" +#include "cygserver_transport.h" +#include "cygserver_transport_pipes.h" +#include "cygserver_transport_sockets.h" /* The factory */ transport_layer_base * diff --git a/winsup/cygserver/transport_pipes.cc b/winsup/cygserver/transport_pipes.cc index 6d80defd4..5fd11581d 100644 --- a/winsup/cygserver/transport_pipes.cc +++ b/winsup/cygserver/transport_pipes.cc @@ -25,11 +25,11 @@ details. */ #include #include "cygerrno.h" -#include "cygwin/cygserver_transport.h" -#include "cygwin/cygserver_transport_pipes.h" +#include "cygserver_transport.h" +#include "cygserver_transport_pipes.h" #ifndef __INSIDE_CYGWIN__ -#include "cygwin/cygserver.h" +#include "cygserver.h" #endif enum diff --git a/winsup/cygserver/transport_sockets.cc b/winsup/cygserver/transport_sockets.cc index 6ade14bff..78d237adc 100644 --- a/winsup/cygserver/transport_sockets.cc +++ b/winsup/cygserver/transport_sockets.cc @@ -26,8 +26,8 @@ details. */ #include #include -#include "cygwin/cygserver_transport.h" -#include "cygwin/cygserver_transport_sockets.h" +#include "cygserver_transport.h" +#include "cygserver_transport_sockets.h" /* to allow this to link into cygwin and the .dll, a little magic is needed. */ #ifndef __OUTSIDE_CYGWIN__ -- 2.43.5