diff options
Diffstat (limited to 'winsup/cygserver/sem.cc')
-rw-r--r-- | winsup/cygserver/sem.cc | 107 |
1 files changed, 84 insertions, 23 deletions
diff --git a/winsup/cygserver/sem.cc b/winsup/cygserver/sem.cc index 97d91a3..6a179b0 100644 --- a/winsup/cygserver/sem.cc +++ b/winsup/cygserver/sem.cc @@ -1,8 +1,6 @@ /* sem.cc: Single unix specification IPC interface for Cygwin. - Copyright 2002 Red Hat, Inc. - - Written by Conrad Scott <conrad.scott@dsl.pipex.com>. + Copyright 2003 Red Hat, Inc. This file is part of Cygwin. @@ -10,31 +8,94 @@ This software is a copyrighted work licensed under the terms of the Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ -#include "winsup.h" +#ifdef __OUTSIDE_CYGWIN__ +#include "woutsup.h" -#include <sys/types.h> -#include <cygwin/sem.h> +#include <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include "cygserver.h" +#include "process.h" +#include "transport.h" -#include "cygerrno.h" +#include "cygserver_ipc.h" +#include "cygserver_sem.h" -extern "C" int -semctl (int semid, int semnum, int cmd, ...) -{ - set_errno (ENOSYS); - return -1; -} - -extern "C" int -semget (key_t key, int nsems, int semflg) -{ - set_errno (ENOSYS); - return -1; +client_request_sem::client_request_sem () + : client_request (CYGSERVER_REQUEST_SEM, + &_parameters, sizeof (_parameters)) +{ } -extern "C" int -semop (int semid, struct sembuf *sops, size_t nsops) +void +client_request_sem::serve (transport_layer_base *const conn, + process_cache *const cache) { - set_errno (ENOSYS); - return -1; + if (msglen () != sizeof (_parameters.in)) + { + syscall_printf ("bad request body length: expecting %lu bytes, got %lu", + sizeof (_parameters), msglen ()); + error_code (EINVAL); + msglen (0); + return; + } + if (support_semaphores == TUN_FALSE) + { + syscall_printf ("Semaphore support not started"); + error_code (ENOSYS); + _parameters.out.ret = -1; + msglen (sizeof (_parameters.out)); + return; + } + process *const client = cache->process (_parameters.in.ipcblk.cygpid, + _parameters.in.ipcblk.winpid); + if (!client) + { + error_code (EAGAIN); + msglen (0); + return; + } + if (!conn->impersonate_client ()) + { + client->release (); + error_code (EACCES); + msglen (0); + return; + } + if (!adjust_identity_info (&_parameters.in.ipcblk)) + { + client->release (); + conn->revert_to_self (); + error_code (EACCES); + msglen (0); + return; + } + /* Early revert_to_self since IPC code runs in kernel mode. */ + conn->revert_to_self (); + thread td = { client, &_parameters.in.ipcblk, {-1, -1} }; + int res; + switch (_parameters.in.semop) + { + case SEMOP_semctl: + res = semctl (&td, &_parameters.in.ctlargs); + break; + case SEMOP_semget: + res = semget (&td, &_parameters.in.getargs); + break; + case SEMOP_semop: + res = semop (&td, &_parameters.in.opargs); + break; + } + /* Allocated by the call to adjust_identity_info(). */ + if (_parameters.in.ipcblk.gidlist) + free (_parameters.in.ipcblk.gidlist); + client->release (); + error_code (res); + _parameters.out.ret = td.td_retval[0]; + msglen (sizeof (_parameters.out)); } +#endif /* __OUTSIDE_CYGWIN__ */ |