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