1 /* sem.cc: Single unix specification IPC interface for Cygwin.
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 #ifdef __OUTSIDE_CYGWIN__
19 #include "cygserver.h"
21 #include "transport.h"
23 #include "cygserver_ipc.h"
24 #include "cygserver_sem.h"
26 client_request_sem::client_request_sem ()
27 : client_request (CYGSERVER_REQUEST_SEM
,
28 &_parameters
, sizeof (_parameters
))
33 client_request_sem::serve (transport_layer_base
*const conn
,
34 process_cache
*const cache
)
36 if (msglen () != sizeof (_parameters
.in
))
38 syscall_printf ("bad request body length: expecting %lu bytes, got %lu",
39 sizeof (_parameters
), msglen ());
44 if (support_semaphores
== TUN_FALSE
)
46 syscall_printf ("Semaphore support not started");
48 _parameters
.out
.ret
= -1;
49 msglen (sizeof (_parameters
.out
));
52 process
*const client
= cache
->process (_parameters
.in
.ipcblk
.cygpid
,
53 _parameters
.in
.ipcblk
.winpid
);
60 if (!conn
->impersonate_client ())
67 if (!adjust_identity_info (&_parameters
.in
.ipcblk
))
70 conn
->revert_to_self ();
75 /* Early revert_to_self since IPC code runs in kernel mode. */
76 conn
->revert_to_self ();
77 /* sysv_sem.cc takes care of itself. */
79 thread
td (client
, &_parameters
.in
.ipcblk
, true);
81 switch (_parameters
.in
.semop
)
84 res
= semctl (&td
, &_parameters
.in
.ctlargs
);
87 res
= semget (&td
, &_parameters
.in
.getargs
);
90 res
= semop (&td
, &_parameters
.in
.opargs
);
97 /* Allocated by the call to adjust_identity_info(). */
98 if (_parameters
.in
.ipcblk
.gidlist
)
99 free (_parameters
.in
.ipcblk
.gidlist
);
101 _parameters
.out
.ret
= td
.td_retval
[0];
102 msglen (sizeof (_parameters
.out
));
104 #endif /* __OUTSIDE_CYGWIN__ */