]>
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, | |
8d8f4036 | 58 | _parameters.in.ipcblk.winpid); |
1c001dd2 CS |
59 | if (!client) |
60 | { | |
61 | error_code (EAGAIN); | |
62 | msglen (0); | |
63 | return; | |
64 | } | |
282113ba | 65 | if (!conn->impersonate_client ()) |
1c001dd2 | 66 | { |
282113ba CV |
67 | client->release (); |
68 | error_code (EACCES); | |
69 | msglen (0); | |
70 | return; | |
1c001dd2 | 71 | } |
282113ba | 72 | if (!adjust_identity_info (&_parameters.in.ipcblk)) |
1c001dd2 | 73 | { |
282113ba CV |
74 | client->release (); |
75 | conn->revert_to_self (); | |
76 | error_code (EACCES); | |
1c001dd2 | 77 | msglen (0); |
282113ba | 78 | return; |
1c001dd2 | 79 | } |
282113ba CV |
80 | /* Early revert_to_self since IPC code runs in kernel mode. */ |
81 | conn->revert_to_self (); | |
1f8b3049 CV |
82 | /* sysv_shm.cc takes care of itself. */ |
83 | client->release (); | |
8d8f4036 | 84 | thread td (client, &_parameters.in.ipcblk, false); |
282113ba CV |
85 | int res; |
86 | shmop_t shmop = _parameters.in.shmop; /* Get's overwritten otherwise. */ | |
87 | switch (shmop) | |
88 | { | |
89 | case SHMOP_shmat: | |
90 | ipc_p_vmspace (td.ipcblk); | |
91 | res = shmat (&td, &_parameters.in.atargs); | |
92 | break; | |
93 | case SHMOP_shmctl: | |
94 | res = shmctl (&td, &_parameters.in.ctlargs); | |
95 | break; | |
96 | case SHMOP_shmdt: | |
97 | ipc_p_vmspace (td.ipcblk); | |
98 | res = shmdt (&td, &_parameters.in.dtargs); | |
99 | break; | |
100 | case SHMOP_shmget: | |
101 | res = shmget (&td, &_parameters.in.getargs); | |
102 | break; | |
103 | case SHMOP_shmfork: | |
104 | res = cygwin_shmfork_myhook (&td, &_parameters.in.forkargs); | |
105 | break; | |
c026d842 CV |
106 | default: |
107 | res = ENOSYS; | |
108 | td.td_retval[0] = -1; | |
109 | break; | |
282113ba CV |
110 | } |
111 | /* Allocated by the call to adjust_identity_info(). */ | |
112 | if (_parameters.in.ipcblk.gidlist) | |
113 | free (_parameters.in.ipcblk.gidlist); | |
282113ba CV |
114 | error_code (res); |
115 | if (shmop == SHMOP_shmat) | |
116 | _parameters.out.ptr = td.td_retval[0]; | |
1c001dd2 | 117 | else |
282113ba CV |
118 | _parameters.out.ret = td.td_retval[0]; |
119 | if (shmop == SHMOP_shmget) | |
120 | _parameters.out.obj = td.td_retval[1]; | |
121 | msglen (sizeof (_parameters.out)); | |
f449bfef | 122 | } |
282113ba | 123 | #endif /* __OUTSIDE_CYGWIN__ */ |