]>
Commit | Line | Data |
---|---|---|
a245bd6e CF |
1 | /* sem.cc: Single unix specification IPC interface for Cygwin. |
2 | ||
1dcd520b | 3 | Copyright 2003, 2004 Red Hat, Inc. |
a245bd6e CF |
4 | |
5 | This file is part of Cygwin. | |
6 | ||
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. */ | |
10 | ||
282113ba CV |
11 | #ifdef __OUTSIDE_CYGWIN__ |
12 | #include "woutsup.h" | |
a245bd6e | 13 | |
282113ba CV |
14 | #include <errno.h> |
15 | #include <pthread.h> | |
16 | #include <stdio.h> | |
17 | #include <stdlib.h> | |
18 | #include <string.h> | |
19 | #include <time.h> | |
a245bd6e | 20 | |
282113ba CV |
21 | #include "cygserver.h" |
22 | #include "process.h" | |
23 | #include "transport.h" | |
a245bd6e | 24 | |
282113ba CV |
25 | #include "cygserver_ipc.h" |
26 | #include "cygserver_sem.h" | |
a245bd6e | 27 | |
282113ba CV |
28 | client_request_sem::client_request_sem () |
29 | : client_request (CYGSERVER_REQUEST_SEM, | |
30 | &_parameters, sizeof (_parameters)) | |
31 | { | |
a245bd6e CF |
32 | } |
33 | ||
282113ba CV |
34 | void |
35 | client_request_sem::serve (transport_layer_base *const conn, | |
36 | process_cache *const cache) | |
a245bd6e | 37 | { |
282113ba CV |
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); | |
44 | return; | |
45 | } | |
46 | if (support_semaphores == TUN_FALSE) | |
47 | { | |
48 | syscall_printf ("Semaphore support not started"); | |
49 | error_code (ENOSYS); | |
50 | _parameters.out.ret = -1; | |
51 | msglen (sizeof (_parameters.out)); | |
52 | return; | |
53 | } | |
54 | process *const client = cache->process (_parameters.in.ipcblk.cygpid, | |
373a036f CV |
55 | _parameters.in.ipcblk.winpid, |
56 | _parameters.in.ipcblk.signal_arrived); | |
282113ba CV |
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 (); | |
1f8b3049 CV |
80 | /* sysv_sem.cc takes care of itself. */ |
81 | client->release (); | |
282113ba CV |
82 | thread td = { client, &_parameters.in.ipcblk, {-1, -1} }; |
83 | int res; | |
84 | switch (_parameters.in.semop) | |
85 | { | |
86 | case SEMOP_semctl: | |
87 | res = semctl (&td, &_parameters.in.ctlargs); | |
88 | break; | |
89 | case SEMOP_semget: | |
90 | res = semget (&td, &_parameters.in.getargs); | |
91 | break; | |
92 | case SEMOP_semop: | |
93 | res = semop (&td, &_parameters.in.opargs); | |
94 | break; | |
c026d842 CV |
95 | default: |
96 | res = ENOSYS; | |
97 | td.td_retval[0] = -1; | |
98 | break; | |
282113ba CV |
99 | } |
100 | /* Allocated by the call to adjust_identity_info(). */ | |
101 | if (_parameters.in.ipcblk.gidlist) | |
102 | free (_parameters.in.ipcblk.gidlist); | |
282113ba CV |
103 | error_code (res); |
104 | _parameters.out.ret = td.td_retval[0]; | |
105 | msglen (sizeof (_parameters.out)); | |
a245bd6e | 106 | } |
282113ba | 107 | #endif /* __OUTSIDE_CYGWIN__ */ |