]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygserver/shm.cc
Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option
[newlib-cygwin.git] / winsup / cygserver / shm.cc
1 /* shm.cc: Single unix specification IPC interface for Cygwin.
2
3 This file is part of Cygwin.
4
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
8
9 #ifdef __OUTSIDE_CYGWIN__
10 #include "woutsup.h"
11
12 #include <errno.h>
13 #include <pthread.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <time.h>
18
19 #include "cygserver.h"
20 #include "process.h"
21 #include "transport.h"
22
23 #include "cygserver_ipc.h"
24 #include "cygserver_shm.h"
25
26 client_request_shm::client_request_shm ()
27 : client_request (CYGSERVER_REQUEST_SHM,
28 &_parameters, sizeof (_parameters))
29 {
30 }
31
32 void
33 client_request_shm::serve (transport_layer_base *const conn,
34 process_cache *const cache)
35 {
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);
42 return;
43 }
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,
56 _parameters.in.ipcblk.winpid);
57 if (!client)
58 {
59 error_code (EAGAIN);
60 msglen (0);
61 return;
62 }
63 if (!conn->impersonate_client ())
64 {
65 client->release ();
66 error_code (EACCES);
67 msglen (0);
68 return;
69 }
70 if (!adjust_identity_info (&_parameters.in.ipcblk))
71 {
72 client->release ();
73 conn->revert_to_self ();
74 error_code (EACCES);
75 msglen (0);
76 return;
77 }
78 /* Early revert_to_self since IPC code runs in kernel mode. */
79 conn->revert_to_self ();
80 /* sysv_shm.cc takes care of itself. */
81 client->release ();
82 thread td (client, &_parameters.in.ipcblk, false);
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;
104 default:
105 res = ENOSYS;
106 td.td_retval[0] = -1;
107 break;
108 }
109 /* Allocated by the call to adjust_identity_info(). */
110 if (_parameters.in.ipcblk.gidlist)
111 free (_parameters.in.ipcblk.gidlist);
112 error_code (res);
113 if (shmop == SHMOP_shmat)
114 _parameters.out.ptr = td.td_retval[0];
115 else
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));
120 }
121 #endif /* __OUTSIDE_CYGWIN__ */
This page took 0.039513 seconds and 5 git commands to generate.