* 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.
This commit is contained in:
Corinna Vinschen 2003-10-22 10:07:59 +00:00
parent 567970786e
commit e217832c4c
15 changed files with 331 additions and 461 deletions

View File

@ -1,3 +1,25 @@
2003-10-22 Corinna Vinschen <corinna@vinschen.de>
* 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.
2003-10-16 Pierre Humblet <pierre.humblet@ieee.org>
* syscalls.cc (seteuid32): Always construct a default DACL including

View File

@ -365,6 +365,9 @@ $(LIB_NAME): rmsym newsym $(TEST_DLL_NAME) $(LIBCOS)
$(TEST_LIB_NAME): $(LIB_NAME)
perl -p -e 'BEGIN{binmode(STDIN); binmode(STDOUT);}; s/cygwin1/cygwin0/g' < $? > $@
$(LIBSERVER): $(bupdir)/cygserver/Makefile
$(MAKE) -C $(bupdir)/cygserver libcygserver.a
dll_ofiles: $(DLL_OFILES)
$(LIBGMON_A): $(GMON_OFILES) $(GMON_START)

View File

View File

@ -0,0 +1,84 @@
/* cygserver_ipc.h
Copyright 2002 Red Hat, Inc.
Originally written by Conrad Scott <conrad.scott@dsl.pipex.com>
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 <assert.h>
#include <limits.h> /* 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__ */

View File

@ -0,0 +1,147 @@
/* cygserver_shm.h: Single unix specification IPC interface for Cygwin.
Copyright 2002 Red Hat, Inc.
Written by Conrad Scott <conrad.scott@dsl.pipex.com>.
Based on code by Robert Collins <robert.collins@hotmail.com>.
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 <sys/types.h>
#include <cygwin/shm.h>
#include <assert.h>
#include <limits.h>
#include "cygserver_ipc.h"
#include "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__ */

View File

@ -1198,6 +1198,10 @@ sexecp = sexecve_is_bad
sexecv = sexecve_is_bad
sexecve = sexecve_is_bad
sexecvpe = sexecve_is_bad
shmat
shmctl
shmdt
shmget
sigaction
_sigaction = sigaction
sigaddset

View File

@ -25,7 +25,7 @@ details. */
#include "pinfo.h"
#include "cygheap.h"
#include "shared_info.h"
#include "cygwin/cygserver.h"
#include "cygserver.h"
#include "cygthread.h"
/* Tty master stuff */
@ -516,8 +516,9 @@ fhandler_tty_slave::open (int flags, mode_t)
|| !cygserver_attach_tty (&from_master_local, &to_master_local))
#endif
{
#ifdef USE_SERVER
termios_printf ("cannot dup handles via server. using old method.");
#endif
HANDLE tty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE,
get_ttyp ()->master_pid);
termios_printf ("tty own handle %p",tty_owner);

View File

@ -1,164 +0,0 @@
/* cygserver_process.h
Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com>
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 <assert.h>
#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_ */

View File

@ -1,39 +0,0 @@
/* cygserver_transport.h
Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com>
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_ */

View File

@ -1,53 +0,0 @@
/* cygserver_transport_pipes.h
Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com>
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_ */

View File

@ -1,46 +0,0 @@
/* cygserver_transport_sockets.h
Copyright 2001, 2002 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com>
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 <sys/socket.h>
#include <sys/un.h>
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_ */

View File

@ -219,13 +219,14 @@ details. */
openpty, forkpty, revoke, logwtmp, updwtmp
94: Export getopt, getopt_long, optarg, opterr, optind, optopt,
optreset, __check_rhosts_file, __rcmd_errstr.
95: Export shmat, shmctl, shmdt, shmget.
*/
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
#define CYGWIN_VERSION_API_MAJOR 0
#define CYGWIN_VERSION_API_MINOR 94
#define CYGWIN_VERSION_API_MINOR 95
/* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible

View File

@ -12,6 +12,7 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
#include "cygerrno.h"
#ifdef USE_SERVER
#include <sys/types.h>
@ -19,7 +20,6 @@ details. */
#include <stdio.h>
#include <unistd.h>
#include "cygerrno.h"
#include "safe_memory.h"
#include "sigproc.h"
@ -551,50 +551,6 @@ client_shmmgr::new_segment (const int shmid,
return segptr;
}
/*---------------------------------------------------------------------------*
* shmat ()
*---------------------------------------------------------------------------*/
extern "C" void *
shmat (const int shmid, const void *const shmaddr, const int shmflg)
{
sigframe thisframe (mainthread);
return shmmgr.shmat (shmid, shmaddr, shmflg);
}
/*---------------------------------------------------------------------------*
* shmctl ()
*---------------------------------------------------------------------------*/
extern "C" int
shmctl (const int shmid, const int cmd, struct shmid_ds *const buf)
{
sigframe thisframe (mainthread);
return shmmgr.shmctl (shmid, cmd, buf);
}
/*---------------------------------------------------------------------------*
* shmdt ()
*---------------------------------------------------------------------------*/
extern "C" int
shmdt (const void *const shmaddr)
{
sigframe thisframe (mainthread);
return shmmgr.shmdt (shmaddr);
}
/*---------------------------------------------------------------------------*
* shmget ()
*---------------------------------------------------------------------------*/
extern "C" int
shmget (const key_t key, const size_t size, const int shmflg)
{
sigframe thisframe (mainthread);
return shmmgr.shmget (key, size, shmflg);
}
/*---------------------------------------------------------------------------*
* fixup_shms_after_fork ()
*---------------------------------------------------------------------------*/
@ -691,3 +647,67 @@ client_request_shm::client_request_shm (const key_t key,
msglen (sizeof (_parameters.in));
}
#endif /* USE_SERVER */
/*---------------------------------------------------------------------------*
* shmat ()
*---------------------------------------------------------------------------*/
extern "C" void *
shmat (const int shmid, const void *const shmaddr, const int shmflg)
{
#ifdef USE_SERVER
sigframe thisframe (mainthread);
return shmmgr.shmat (shmid, shmaddr, shmflg);
#else
set_errno (ENOSYS);
return (void *) -1;
#endif
}
/*---------------------------------------------------------------------------*
* shmctl ()
*---------------------------------------------------------------------------*/
extern "C" int
shmctl (const int shmid, const int cmd, struct shmid_ds *const buf)
{
#ifdef USE_SERVER
sigframe thisframe (mainthread);
return shmmgr.shmctl (shmid, cmd, buf);
#else
set_errno (ENOSYS);
return -1;
#endif
}
/*---------------------------------------------------------------------------*
* shmdt ()
*---------------------------------------------------------------------------*/
extern "C" int
shmdt (const void *const shmaddr)
{
#ifdef USE_SERVER
sigframe thisframe (mainthread);
return shmmgr.shmdt (shmaddr);
#else
set_errno (ENOSYS);
return -1;
#endif
}
/*---------------------------------------------------------------------------*
* shmget ()
*---------------------------------------------------------------------------*/
extern "C" int
shmget (const key_t key, const size_t size, const int shmflg)
{
#ifdef USE_SERVER
sigframe thisframe (mainthread);
return shmmgr.shmget (key, size, shmflg);
#else
set_errno (ENOSYS);
return -1;
#endif
}

View File

@ -21,7 +21,7 @@ details. */
#include "dtable.h"
#include "cygheap.h"
#include "pinfo.h"
#include "cygwin/cygserver.h"
#include "cygserver.h"
#include "shared_info.h"
#include "cygthread.h"

View File

@ -1,110 +0,0 @@
/* woutsup.h: for Cygwin code compiled outside the DLL (i.e. cygserver).
Copyright 2002 Red Hat, Inc.
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. */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef __INSIDE_CYGWIN__
#error "woutsup.h is not for code being compiled inside the dll"
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#if _WIN32_WINNT < 0x0500
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#define WIN32_LEAN_AND_MEAN 1
#define _WINGDI_H
#define _WINUSER_H
#define _WINNLS_H
#define _WINVER_H
#define _WINNETWK_H
#define _WINSVC_H
#include <windows.h>
#include <wincrypt.h>
#include <lmcons.h>
#undef _WINGDI_H
#undef _WINUSER_H
#undef _WINNLS_H
#undef _WINVER_H
#undef _WINNETWK_H
#undef _WINSVC_H
#include "wincap.h"
/* The one function we use from winuser.h most of the time */
extern "C" DWORD WINAPI GetLastError (void);
extern int cygserver_running;
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
#define NEW_MACRO_VARARGS
#endif
/*
* A reproduction of the <sys/strace.h> macros. This allows code that
* runs both inside and outside the Cygwin DLL to use the same macros
* for logging messages.
*/
extern "C" void __cygserver__printf (const char *, const char *, ...);
#ifdef NEW_MACRO_VARARGS
#define system_printf(...) \
do \
{ \
__cygserver__printf (__PRETTY_FUNCTION__, __VA_ARGS__); \
} while (false)
#define __noop_printf(...) do {;} while (false)
#else /* !NEW_MACRO_VARARGS */
#define system_printf(args...) \
do \
{ \
__cygserver__printf (__PRETTY_FUNCTION__, ## args); \
} while (false)
#define __noop_printf(args...) do {;} while (false)
#endif /* !NEW_MACRO_VARARGS */
#ifdef DEBUGGING
#define debug_printf system_printf
#define paranoid_printf system_printf
#define select_printf system_printf
#define sigproc_printf system_printf
#define syscall_printf system_printf
#define termios_printf system_printf
#define wm_printf system_printf
#define minimal_printf system_printf
#define malloc_printf system_printf
#define thread_printf system_printf
#else
#define debug_printf __noop_printf
#define paranoid_printf __noop_printf
#define select_printf __noop_printf
#define sigproc_printf __noop_printf
#define syscall_printf __noop_printf
#define termios_printf __noop_printf
#define wm_printf __noop_printf
#define minimal_printf __noop_printf
#define malloc_printf __noop_printf
#define thread_printf __noop_printf
#endif
#include "safe_memory.h"