]> sourceware.org Git - newlib-cygwin.git/blame - winsup/cygserver/shm.cc
Cygwin: sigfe: Fix a bug that signal handler destroys fpu states
[newlib-cygwin.git] / winsup / cygserver / shm.cc
CommitLineData
282113ba 1/* shm.cc: Single unix specification IPC interface for Cygwin.
f449bfef 2
2402700d 3This file is part of Cygwin.
f449bfef 4
2402700d
CF
5This software is a copyrighted work licensed under the terms of the
6Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7details. */
f449bfef 8
282113ba 9#ifdef __OUTSIDE_CYGWIN__
1c001dd2 10#include "woutsup.h"
f449bfef 11
f449bfef 12#include <errno.h>
1c001dd2 13#include <pthread.h>
f449bfef 14#include <stdio.h>
282113ba 15#include <stdlib.h>
1c001dd2
CS
16#include <string.h>
17#include <time.h>
f449bfef 18
56797078 19#include "cygserver.h"
282113ba
CV
20#include "process.h"
21#include "transport.h"
1c001dd2 22
282113ba
CV
23#include "cygserver_ipc.h"
24#include "cygserver_shm.h"
1c001dd2
CS
25
26client_request_shm::client_request_shm ()
27 : client_request (CYGSERVER_REQUEST_SHM,
28 &_parameters, sizeof (_parameters))
282113ba 29{
1c001dd2
CS
30}
31
1c001dd2
CS
32void
33client_request_shm::serve (transport_layer_base *const conn,
282113ba 34 process_cache *const cache)
1c001dd2 35{
1c001dd2
CS
36 if (msglen () != sizeof (_parameters.in))
37 {
38 syscall_printf ("bad request body length: expecting %lu bytes, got %lu",
39 sizeof (_parameters), msglen ());
40 error_code (EINVAL);
41 msglen (0);
f449bfef
RC
42 return;
43 }
282113ba
CV
44 if (support_sharedmem == TUN_FALSE)
45 {
46 syscall_printf ("Shared memory support not started");
47 error_code (ENOSYS);
48 if (_parameters.in.shmop == SHMOP_shmat)
49 _parameters.out.ptr = (vm_offset_t)0;
50 else
51 _parameters.out.ret = -1;
52 msglen (sizeof (_parameters.out));
53 return;
54 }
55 process *const client = cache->process (_parameters.in.ipcblk.cygpid,
8d8f4036 56 _parameters.in.ipcblk.winpid);
1c001dd2
CS
57 if (!client)
58 {
59 error_code (EAGAIN);
60 msglen (0);
61 return;
62 }
282113ba 63 if (!conn->impersonate_client ())
1c001dd2 64 {
282113ba
CV
65 client->release ();
66 error_code (EACCES);
67 msglen (0);
68 return;
1c001dd2 69 }
282113ba 70 if (!adjust_identity_info (&_parameters.in.ipcblk))
1c001dd2 71 {
282113ba
CV
72 client->release ();
73 conn->revert_to_self ();
74 error_code (EACCES);
1c001dd2 75 msglen (0);
282113ba 76 return;
1c001dd2 77 }
282113ba
CV
78 /* Early revert_to_self since IPC code runs in kernel mode. */
79 conn->revert_to_self ();
1f8b3049
CV
80 /* sysv_shm.cc takes care of itself. */
81 client->release ();
8d8f4036 82 thread td (client, &_parameters.in.ipcblk, false);
282113ba
CV
83 int res;
84 shmop_t shmop = _parameters.in.shmop; /* Get's overwritten otherwise. */
85 switch (shmop)
86 {
87 case SHMOP_shmat:
88 ipc_p_vmspace (td.ipcblk);
89 res = shmat (&td, &_parameters.in.atargs);
90 break;
91 case SHMOP_shmctl:
92 res = shmctl (&td, &_parameters.in.ctlargs);
93 break;
94 case SHMOP_shmdt:
95 ipc_p_vmspace (td.ipcblk);
96 res = shmdt (&td, &_parameters.in.dtargs);
97 break;
98 case SHMOP_shmget:
99 res = shmget (&td, &_parameters.in.getargs);
100 break;
101 case SHMOP_shmfork:
102 res = cygwin_shmfork_myhook (&td, &_parameters.in.forkargs);
103 break;
c026d842
CV
104 default:
105 res = ENOSYS;
106 td.td_retval[0] = -1;
107 break;
282113ba
CV
108 }
109 /* Allocated by the call to adjust_identity_info(). */
110 if (_parameters.in.ipcblk.gidlist)
111 free (_parameters.in.ipcblk.gidlist);
282113ba
CV
112 error_code (res);
113 if (shmop == SHMOP_shmat)
114 _parameters.out.ptr = td.td_retval[0];
1c001dd2 115 else
282113ba
CV
116 _parameters.out.ret = td.td_retval[0];
117 if (shmop == SHMOP_shmget)
118 _parameters.out.obj = td.td_retval[1];
119 msglen (sizeof (_parameters.out));
f449bfef 120}
282113ba 121#endif /* __OUTSIDE_CYGWIN__ */
This page took 0.309503 seconds and 6 git commands to generate.