* bsd_helper.h: Throughout, convert "struct thread" to "class thread".

* bsd_mutex.cc (_msleep): Fetch signal_arrived handle from thread's
	ipcblk.
	* process.h (class process): Drop _signal_arrived and align methods.
	(process_cache::process): Drop signal_arrived parameter.
	* process.cc (process::process): Ditto.  Drop related code.
	(process::~process): Drop closing signal_arrived handle.
	(process_cache::process): Drop signal_arrived parameter in call to
	process::process.
	(thread::dup_signal_arrived): New method duplicating thread's
	signal_arrived handle.
	(thread::close_signal_arrived): New method closing thread's
	signal_arrived handle.
	* msg.cc (client_request_msg::serve): Drop signal_arrived parameter from
	call to process_cache::process. Use thread constructor to initialize td.
	* sem.cc (client_request_sem::serve): Ditto.
	* shm.cc (client_request_shm::serve): Ditto.
This commit is contained in:
Corinna Vinschen 2015-01-19 17:42:38 +00:00
parent c95ce02160
commit 8d8f40361f
8 changed files with 66 additions and 48 deletions

View File

@ -1,3 +1,23 @@
2015-01-19 Corinna Vinschen <corinna@vinschen.de>
* bsd_helper.h: Throughout, convert "struct thread" to "class thread".
* bsd_mutex.cc (_msleep): Fetch signal_arrived handle from thread's
ipcblk.
* process.h (class process): Drop _signal_arrived and align methods.
(process_cache::process): Drop signal_arrived parameter.
* process.cc (process::process): Ditto. Drop related code.
(process::~process): Drop closing signal_arrived handle.
(process_cache::process): Drop signal_arrived parameter in call to
process::process.
(thread::dup_signal_arrived): New method duplicating thread's
signal_arrived handle.
(thread::close_signal_arrived): New method closing thread's
signal_arrived handle.
* msg.cc (client_request_msg::serve): Drop signal_arrived parameter from
call to process_cache::process. Use thread constructor to initialize td.
* sem.cc (client_request_sem::serve): Ditto.
* shm.cc (client_request_shm::serve): Ditto.
2014-11-06 Florian Friesdorf <flo@chaoflow.net> 2014-11-06 Florian Friesdorf <flo@chaoflow.net>
* cygserver-config: Add -N option to allow different service name. * cygserver-config: Add -N option to allow different service name.

View File

@ -1,6 +1,6 @@
/* bsd_helper.h: Helps integrating BSD kernel code /* bsd_helper.h: Helps integrating BSD kernel code
Copyright 2003, 2012 Red Hat, Inc. Copyright 2003, 2012, 2015 Red Hat, Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -39,24 +39,24 @@ extern SECURITY_ATTRIBUTES sec_all_nih;
void securityinit (void); void securityinit (void);
int win_copyin (struct thread *, const void *, void *, size_t); int win_copyin (class thread *, const void *, void *, size_t);
int win_copyout (struct thread *, const void *, void *, size_t); int win_copyout (class thread *, const void *, void *, size_t);
#define copyin(a,b,c) win_copyin((td),(a),(b),(c)) #define copyin(a,b,c) win_copyin((td),(a),(b),(c))
#define copyout(a,b,c) win_copyout((td),(a),(b),(c)) #define copyout(a,b,c) win_copyout((td),(a),(b),(c))
void *get_token_info (HANDLE, TOKEN_INFORMATION_CLASS); void *get_token_info (HANDLE, TOKEN_INFORMATION_CLASS);
int ipcperm (struct thread *, struct ipc_perm *, unsigned int); int ipcperm (class thread *, struct ipc_perm *, unsigned int);
int suser (struct thread *); int suser (class thread *);
bool adjust_identity_info (struct proc *p); bool adjust_identity_info (struct proc *p);
struct vmspace *ipc_p_vmspace (struct proc *); struct vmspace *ipc_p_vmspace (struct proc *);
int ipcexit_creat_hookthread(struct thread *); int ipcexit_creat_hookthread(class thread *);
void ipcinit (void); void ipcinit (void);
int ipcunload (void); int ipcunload (void);
vm_object_t _vm_pager_allocate (int, int); vm_object_t _vm_pager_allocate (int, int);
#define vm_pager_allocate(a,b,s,c,d) _vm_pager_allocate((s),(mode)) #define vm_pager_allocate(a,b,s,c,d) _vm_pager_allocate((s),(mode))
vm_object_t vm_object_duplicate (struct thread *td, vm_object_t object); vm_object_t vm_object_duplicate (class thread *td, vm_object_t object);
void vm_object_deallocate (vm_object_t object); void vm_object_deallocate (vm_object_t object);
void tunable_param_init (const char *, bool); void tunable_param_init (const char *, bool);

View File

@ -1,6 +1,6 @@
/* bsd_mutex.cc /* bsd_mutex.cc
Copyright 2003, 2004, 2005, 2007, 2012, 2014 Red Hat Inc. Copyright 2003, 2004, 2005, 2007, 2012, 2014, 2015 Red Hat Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -314,13 +314,12 @@ _msleep (void *ident, struct mtx *mtx, int priority,
evt, evt,
msleep_glob_evt, msleep_glob_evt,
td->client->handle (), td->client->handle (),
td->client->signal_arrived () td->ipcblk->signal_arrived
}; };
/* PCATCH handling. If PCATCH is given and signal_arrived is a valid /* PCATCH handling. If PCATCH is given and signal_arrived is a valid
handle, then it's used in the WaitFor call and EINTR is returned. */ handle, then it's used in the WaitFor call and EINTR is returned. */
int obj_cnt = 3; int obj_cnt = 3;
if ((priority & PCATCH) if ((priority & PCATCH) && obj[3])
&& td->client->signal_arrived () != INVALID_HANDLE_VALUE)
obj_cnt = 4; obj_cnt = 4;
switch (WaitForMultipleObjects (obj_cnt, obj, FALSE, timo ?: INFINITE)) switch (WaitForMultipleObjects (obj_cnt, obj, FALSE, timo ?: INFINITE))
{ {

View File

@ -55,8 +55,7 @@ client_request_msg::serve (transport_layer_base *const conn,
return; return;
} }
process *const client = cache->process (_parameters.in.ipcblk.cygpid, process *const client = cache->process (_parameters.in.ipcblk.cygpid,
_parameters.in.ipcblk.winpid, _parameters.in.ipcblk.winpid);
_parameters.in.ipcblk.signal_arrived);
if (!client) if (!client)
{ {
error_code (EAGAIN); error_code (EAGAIN);
@ -82,7 +81,7 @@ client_request_msg::serve (transport_layer_base *const conn,
conn->revert_to_self (); conn->revert_to_self ();
/* sysv_msg.cc takes care of itself. */ /* sysv_msg.cc takes care of itself. */
client->release (); client->release ();
thread td = { client, &_parameters.in.ipcblk, {-1, -1} }; thread td (client, &_parameters.in.ipcblk, true);
int res; int res;
msgop_t msgop = _parameters.in.msgop; /* Get's overwritten otherwise. */ msgop_t msgop = _parameters.in.msgop; /* Get's overwritten otherwise. */
switch (msgop) switch (msgop)

View File

@ -1,6 +1,6 @@
/* process.cc /* process.cc
Copyright 2001, 2002, 2003, 2004, 2005, 2014 Red Hat Inc. Copyright 2001, 2002, 2003, 2004, 2005, 2014, 2015 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -20,6 +20,8 @@ details. */
#include "process.h" #include "process.h"
#include "cygserver_ipc.h"
/*****************************************************************************/ /*****************************************************************************/
#define elements(ARRAY) (sizeof (ARRAY) / sizeof (*ARRAY)) #define elements(ARRAY) (sizeof (ARRAY) / sizeof (*ARRAY))
@ -39,11 +41,10 @@ process_cleanup::process ()
/*****************************************************************************/ /*****************************************************************************/
process::process (const pid_t cygpid, const DWORD winpid, HANDLE signal_arrived) process::process (const pid_t cygpid, const DWORD winpid)
: _cygpid (cygpid), : _cygpid (cygpid),
_winpid (winpid), _winpid (winpid),
_hProcess (NULL), _hProcess (NULL),
_signal_arrived (INVALID_HANDLE_VALUE),
_cleaning_up (false), _cleaning_up (false),
_exit_status (STILL_ACTIVE), _exit_status (STILL_ACTIVE),
_routines_head (NULL), _routines_head (NULL),
@ -60,19 +61,6 @@ process::process (const pid_t cygpid, const DWORD winpid, HANDLE signal_arrived)
else else
debug_printf ("got handle %p for new cache process %d(%u)", debug_printf ("got handle %p for new cache process %d(%u)",
_hProcess, _cygpid, _winpid); _hProcess, _cygpid, _winpid);
if (!signal_arrived)
debug_printf ("signal_arrived NULL for process %d(%u)", _cygpid, _winpid);
else if (signal_arrived != INVALID_HANDLE_VALUE)
{
if (!DuplicateHandle (_hProcess, signal_arrived,
GetCurrentProcess (), &_signal_arrived,
0, FALSE, DUPLICATE_SAME_ACCESS))
{
system_printf ("error getting signal_arrived to server (%u)",
GetLastError ());
_signal_arrived = INVALID_HANDLE_VALUE;
}
}
InitializeCriticalSection (&_access); InitializeCriticalSection (&_access);
debug ("initialized (%u)", _cygpid); debug ("initialized (%u)", _cygpid);
} }
@ -81,8 +69,6 @@ process::~process ()
{ {
debug ("deleting (%u)", _cygpid); debug ("deleting (%u)", _cygpid);
DeleteCriticalSection (&_access); DeleteCriticalSection (&_access);
if (_signal_arrived && _signal_arrived != INVALID_HANDLE_VALUE)
CloseHandle (_signal_arrived);
CloseHandle (_hProcess); CloseHandle (_hProcess);
} }
@ -239,8 +225,7 @@ process_cache::~process_cache ()
* have been deleted once it has been unlocked. * have been deleted once it has been unlocked.
*/ */
class process * class process *
process_cache::process (const pid_t cygpid, const DWORD winpid, process_cache::process (const pid_t cygpid, const DWORD winpid)
HANDLE signal_arrived)
{ {
/* TODO: make this more granular, so a search doesn't involve the /* TODO: make this more granular, so a search doesn't involve the
* write lock. * write lock.
@ -260,7 +245,7 @@ process_cache::process (const pid_t cygpid, const DWORD winpid,
return NULL; return NULL;
} }
entry = new class process (cygpid, winpid, signal_arrived); entry = new class process (cygpid, winpid);
if (!entry->is_active ()) if (!entry->is_active ())
{ {
LeaveCriticalSection (&_cache_write_access); LeaveCriticalSection (&_cache_write_access);
@ -495,5 +480,26 @@ process_cache::find (const DWORD winpid, class process **previous)
return NULL; return NULL;
} }
void
thread::dup_signal_arrived ()
{
if (ipcblk && ipcblk->signal_arrived
&& !DuplicateHandle (client->handle (), ipcblk->signal_arrived,
GetCurrentProcess (), &ipcblk->signal_arrived,
0, FALSE, DUPLICATE_SAME_ACCESS))
{
system_printf ("error duplicating thread's signal_arrived "
"to server (%u)", GetLastError ());
ipcblk->signal_arrived = NULL;
}
}
void
thread::close_signal_arrived ()
{
if (ipcblk && ipcblk->signal_arrived)
CloseHandle (ipcblk->signal_arrived);
}
/*****************************************************************************/ /*****************************************************************************/
#endif /* __OUTSIDE_CYGWIN__ */ #endif /* __OUTSIDE_CYGWIN__ */

View File

@ -1,6 +1,6 @@
/* process.h /* process.h
Copyright 2001, 2002, 2003, 2004, 2005, 2012 Red Hat Inc. Copyright 2001, 2002, 2003, 2004, 2005, 2012, 2015 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com> Written by Robert Collins <rbtcollins@hotmail.com>
@ -74,14 +74,12 @@ class process
friend class process_cleanup; friend class process_cleanup;
public: public:
process (pid_t cygpid, DWORD winpid, process (pid_t cygpid, DWORD winpid);
HANDLE signal_arrived = INVALID_HANDLE_VALUE);
~process (); ~process ();
pid_t cygpid () const { return _cygpid; } pid_t cygpid () const { return _cygpid; }
DWORD winpid () const { return _winpid; } DWORD winpid () const { return _winpid; }
HANDLE handle () const { return _hProcess; } HANDLE handle () const { return _hProcess; }
HANDLE signal_arrived () const { return _signal_arrived; }
bool is_active () const { return _exit_status == STILL_ACTIVE; } bool is_active () const { return _exit_status == STILL_ACTIVE; }
@ -102,7 +100,6 @@ private:
const pid_t _cygpid; const pid_t _cygpid;
const DWORD _winpid; const DWORD _winpid;
HANDLE _hProcess; HANDLE _hProcess;
HANDLE _signal_arrived;
LONG _cleaning_up; LONG _cleaning_up;
DWORD _exit_status; // Set in the constructor and in exit_code (). DWORD _exit_status; // Set in the constructor and in exit_code ().
cleanup_routine *_routines_head; cleanup_routine *_routines_head;
@ -144,8 +141,7 @@ public:
process_cache (const size_t max_procs, const unsigned int initial_workers); process_cache (const size_t max_procs, const unsigned int initial_workers);
~process_cache (); ~process_cache ();
class process *process (pid_t cygpid, DWORD winpid, class process *process (pid_t cygpid, DWORD winpid);
HANDLE signal_arrived = INVALID_HANDLE_VALUE);
bool running () const { return _queue.running (); } bool running () const { return _queue.running (); }

View File

@ -52,8 +52,7 @@ client_request_sem::serve (transport_layer_base *const conn,
return; return;
} }
process *const client = cache->process (_parameters.in.ipcblk.cygpid, process *const client = cache->process (_parameters.in.ipcblk.cygpid,
_parameters.in.ipcblk.winpid, _parameters.in.ipcblk.winpid);
_parameters.in.ipcblk.signal_arrived);
if (!client) if (!client)
{ {
error_code (EAGAIN); error_code (EAGAIN);
@ -79,7 +78,7 @@ client_request_sem::serve (transport_layer_base *const conn,
conn->revert_to_self (); conn->revert_to_self ();
/* sysv_sem.cc takes care of itself. */ /* sysv_sem.cc takes care of itself. */
client->release (); client->release ();
thread td = { client, &_parameters.in.ipcblk, {-1, -1} }; thread td (client, &_parameters.in.ipcblk, true);
int res; int res;
switch (_parameters.in.semop) switch (_parameters.in.semop)
{ {

View File

@ -55,8 +55,7 @@ client_request_shm::serve (transport_layer_base *const conn,
return; return;
} }
process *const client = cache->process (_parameters.in.ipcblk.cygpid, process *const client = cache->process (_parameters.in.ipcblk.cygpid,
_parameters.in.ipcblk.winpid, _parameters.in.ipcblk.winpid);
_parameters.in.ipcblk.signal_arrived);
if (!client) if (!client)
{ {
error_code (EAGAIN); error_code (EAGAIN);
@ -82,7 +81,7 @@ client_request_shm::serve (transport_layer_base *const conn,
conn->revert_to_self (); conn->revert_to_self ();
/* sysv_shm.cc takes care of itself. */ /* sysv_shm.cc takes care of itself. */
client->release (); client->release ();
thread td = { client, &_parameters.in.ipcblk, {0, 0} }; thread td (client, &_parameters.in.ipcblk, false);
int res; int res;
shmop_t shmop = _parameters.in.shmop; /* Get's overwritten otherwise. */ shmop_t shmop = _parameters.in.shmop; /* Get's overwritten otherwise. */
switch (shmop) switch (shmop)