diff options
author | rbcollins <rbcollins> | 2001-09-30 13:56:37 +0000 |
---|---|---|
committer | rbcollins <rbcollins> | 2001-09-30 13:56:37 +0000 |
commit | 6f0cb845d96e289c7a79be32562a605b9a33acbb (patch) | |
tree | fe6f46385718ea9b4af2edc95150c0e34fca20cb /winsup/cygwin/shm.cc | |
parent | f2d986607e1da33cb0dd6a534fbdb96fe0bd13a6 (diff) | |
download | gdb-6f0cb845d96e289c7a79be32562a605b9a33acbb.tar.gz |
Sun Sep 30 23:41:00 2001 Robert Collins <rbtcollins@hotmail.com>
* Makefile.in: Add cygserver_process.o to cygserver.exe.
* cygserver.cc: Include signal.h and cygwin_version.h.
Define debug_printf as a macro.
Define DEBUG to a value.
(client_request_attach_tty::serve): Add beginning of process cache support.
Change from #ifdef DEBUG to work with new DEBUG style.
(client_request_get_version::serve): Add beginning of process cache support.
(class server_request): New prototype for support of process cache.
(class queue_process_param): New class to allow request loop threading.
(class server_request_queue): Add beginning of process cache support.
Allow request loop threading.
(request_loop): Thread function for request loops.
(server_request_queue::process_requests): Initiator for threaded request loops.
(client_request_shutdown::serve): Add beginning of process cache support.
(server_request::server_request): Ditto.
(server_request::process): Use debug_printf. Add beginning of process cache support.
(server_request_queue::cleanup): Kill off any request loop threads.
(server_request_queue::add): Add beginning of process cache support.
(handle_signal): Trigger a shutdown.
(main): Print out some useful info at startup - version, date time.
Add process cache support.
Spawn a separate thread for the transport request loop, thus allowing concurrent
support for multiple transports.
* cygserver_client.cc (client_request_get_version::serve): Add process cache support.
(client_request_attach_tty::serve): Add process cache support.
(client_request_shutdown::serve): Add process cache support.
* cygsserver_process.cc: New file with the process cache support.
* cygserver_shm.cc: Redefine debug_printf to allow conditional output.
* cygwin.din: Export shmdt().
* shm.cc: Run indent.
Update FIXME's.
(shmdt): New function.
* include/cygwin/cygserver.h (class client_request): Add process cache support.
(class client_request_get_version): Ditto.
(class client_request_shutdown): Ditto.
(class client_request_attach_tty): Ditto.
* include/cygwin/cygserver_process.h: New header for process cache support.
Diffstat (limited to 'winsup/cygwin/shm.cc')
-rw-r--r-- | winsup/cygwin/shm.cc | 166 |
1 files changed, 89 insertions, 77 deletions
diff --git a/winsup/cygwin/shm.cc b/winsup/cygwin/shm.cc index 840c0f23ac7..2caad7376f5 100644 --- a/winsup/cygwin/shm.cc +++ b/winsup/cygwin/shm.cc @@ -111,7 +111,8 @@ fixup_shms_after_fork () if (!newshmds) { /* don't worry about handle cleanup, we're dying! */ - system_printf("failed to reattach to shm control file view %x\n",tempnode); + system_printf ("failed to reattach to shm control file view %x\n", + tempnode); return 1; } tempnode->shmds = (class shmid_ds *) newshmds; @@ -126,7 +127,8 @@ fixup_shms_after_fork () if (newdata != attachnode->data) { /* don't worry about handle cleanup, we're dying! */ - system_printf("failed to reattach to mapped file view %x\n",attachnode->data); + system_printf ("failed to reattach to mapped file view %x\n", + attachnode->data); return 1; } attachnode = attachnode->next; @@ -142,14 +144,12 @@ fixup_shms_after_fork () */ /* FIXME: after fork, every memory area needs to have the attach count - * incremented and the mappings potentially reestablished, perhaps allowing - * inherit will work?!? + * incremented. This should be done in the server? */ -/* FIXME: are inherited mapped IPC_PRIVATE id's shared between process's - * YES from linux. +/* FIXME: tell the daemon when we attach, so at process close it can clean up + * the attach count */ - extern "C" void * shmat (int shmid, const void *shmaddr, int shmflg) { @@ -221,12 +221,24 @@ shmat (int shmid, const void *shmaddr, int shmflg) attachnode->data = rv; attachnode->shmflg = shmflg; attachnode->next = - (_shmattach *) InterlockedExchangePointer (&tempnode->attachhead, attachnode); + (_shmattach *) InterlockedExchangePointer (&tempnode->attachhead, + attachnode); return rv; } +/* FIXME: tell the daemon when we detach so it doesn't cleanup incorrectly. + */ +extern "C" int +shmdt (const void *shmaddr) +{ + /* this should be "rare" so a hefty search is ok. If this is common, then we + * should alter the data structs to allow more optimisation + */ + +} + //FIXME: who is allowed to perform STAT? extern "C" int shmctl (int shmid, int cmd, struct shmid_ds *buf) @@ -235,46 +247,46 @@ shmctl (int shmid, int cmd, struct shmid_ds *buf) while (tempnode && tempnode->shm_id != shmid) tempnode = tempnode->next; if (!tempnode) - { - /* couldn't find a currently open shm control area for the key - probably because - * shmget hasn't been called. - * Allocate a new control block - this has to be handled by the daemon */ - client_request_shm_get *req = - new client_request_shm_get (shmid, GetCurrentProcessId ()); - - int rc; - if ((rc = cygserver_request (req))) - { - delete req; - set_errno (ENOSYS); /* daemon communication failed */ - return -1; - } + { + /* couldn't find a currently open shm control area for the key - probably because + * shmget hasn't been called. + * Allocate a new control block - this has to be handled by the daemon */ + client_request_shm_get *req = + new client_request_shm_get (shmid, GetCurrentProcessId ()); - if (req->header.error_code) /* shm_get failed in the daemon */ - { - set_errno (req->header.error_code); - delete req; - return -1; - } + int rc; + if ((rc = cygserver_request (req))) + { + delete req; + set_errno (ENOSYS); /* daemon communication failed */ + return -1; + } + + if (req->header.error_code) /* shm_get failed in the daemon */ + { + set_errno (req->header.error_code); + delete req; + return -1; + } + + /* we've got the id, now we open the memory area ourselves. + * This tests security automagically + * FIXME: make this a method of shmnode ? + */ + tempnode = + build_inprocess_shmds (req->parameters.out.filemap, + req->parameters.out.attachmap, + req->parameters.out.key, + req->parameters.out.shm_id); + delete req; + if (!tempnode) + return -1; + } - /* we've got the id, now we open the memory area ourselves. - * This tests security automagically - * FIXME: make this a method of shmnode ? - */ - tempnode = - build_inprocess_shmds (req->parameters.out.filemap, - req->parameters.out.attachmap, - req->parameters.out.key, - req->parameters.out.shm_id); - delete req; - if (!tempnode) - return -1; - } - switch (cmd) { case IPC_STAT: - buf->shm_perm = tempnode->shmds->shm_perm; + buf->shm_perm = tempnode->shmds->shm_perm; buf->shm_segsz = tempnode->shmds->shm_segsz; buf->shm_lpid = tempnode->shmds->shm_lpid; buf->shm_cpid = tempnode->shmds->shm_cpid; @@ -285,40 +297,44 @@ shmctl (int shmid, int cmd, struct shmid_ds *buf) break; case IPC_RMID: { - /* TODO: check permissions. Or possibly, the daemon gets to be the only - * one with write access to the memory area? - */ - if (tempnode->shmds->shm_nattch) - system_printf ("call to shmctl with cmd= IPC_RMID when memory area still has" - " attachees\n"); - /* how does this work? - * we mark the ds area as "deleted", and the at and get calls all fail from now on - * on, when nattch becomes 0, the mapped data area is destroyed. - * and each process, as they touch this area detaches. eventually only the - * daemon has an attach. The daemon gets asked to detach immediately. - */ + /* TODO: check permissions. Or possibly, the daemon gets to be the only + * one with write access to the memory area? + */ + if (tempnode->shmds->shm_nattch) + system_printf + ("call to shmctl with cmd= IPC_RMID when memory area still has" + " attachees\n"); + /* how does this work? + * we mark the ds area as "deleted", and the at and get calls all fail from now on + * on, when nattch becomes 0, the mapped data area is destroyed. + * and each process, as they touch this area detaches. eventually only the + * daemon has an attach. The daemon gets asked to detach immediately. + */ #if 0 - client_request_shm_get *req = +//waiting for the daemon to handle terminating process's + client_request_shm_get *req = new client_request_shm_get (SHM_DEL, shmid, GetCurrentProcessId ()); - int rc; - if ((rc = cygserver_request (req))) - { - delete req; - set_errno (ENOSYS); /* daemon communication failed */ - return -1; - } + int rc; + if ((rc = cygserver_request (req))) + { + delete req; + set_errno (ENOSYS); /* daemon communication failed */ + return -1; + } + + if (req->header.error_code) /* shm_del failed in the daemon */ + { + set_errno (req->header.error_code); + delete req; + return -1; + } + + /* the daemon has deleted it's references */ + /* now for us */ + +#endif - if (req->header.error_code) /* shm_del failed in the daemon */ - { - set_errno (req->header.error_code); - delete req; - return -1; } - - /* the daemon has deleted it's references */ - /* now for us */ -#endif -} break; case IPC_SET: default: @@ -333,10 +349,6 @@ shmctl (int shmid, int cmd, struct shmid_ds *buf) * appropriately */ -/* Test result from openbsd: shm ids are persistent cross process if a handle is left - * open. This could lead to resource starvation: we're not copying that behaviour - * unless we have to. (It will involve acygwin1.dll gloal shared list :[ ). - */ /* FIXME: shmid should be a verifyable object */ |