Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorConrad Scott <conrad.scott@dsl.pipex.com>2002-07-10 18:40:16 +0400
committerConrad Scott <conrad.scott@dsl.pipex.com>2002-07-10 18:40:16 +0400
commitbe3e38001e0b0ecdbd2f44209efe7f90c8db8b80 (patch)
tree07b2108dc2b4d101cea3d3b007bebf9627d575c4 /winsup
parentdf70c4fb8e6754ff81bd25c480d358586f223c0c (diff)
* msg.cc: New file of stub functions, no functionality.
* sem.cc: Ditto. * shm.cc (client_shmmgr::shmctl): Add support for an out shm_info buffer for the SHM_INFO command. (client_shmmgr::shmget): Use %X to print keys. * include/sys/ipc.h: Comment all fields and values. (IPC_PRIVATE): Change to be non-negative. * include/sys/msg.h: New file with SUSv3 and ipcs(8) interfaces. * include/sys/sem.h: Ditto. * include/sys/shm.h: Comment all fields and values. (struct shm_info): New struct. * cygserver_shm.h (client_request_shm::shminfo): Rename. (client_request_shm::shm_info): New method. (client_request_shm::_parameters.out.hFileMap): Move into union. (client_request_shm::_parameters.out.shminfo): Rename. (client_request_shm::_parameters.out.shm_info): New field. * cygserver_shm.cc (server_shmmgr::_shm_ids): Rename. (server_shmmgr::_shm_tot): New field. (server_shmmgr::shmctl): Rename `out_shminfo' argument. Add `out_shm_info' argument. Fill in the `out_shm_info' argument in the SHM_INFO command. (server_shmmgr::shmget): Check `shmflg' against the mode of existing segments as per Stevens 1990, p. 123. (server_shmmgr::server_shmmgr): Initialize the new `_shm_tot' field. (server_shmmgr::new_segment): Set ENOMEM if CreateFileMapping fails. Pass `size' to new_segment. (server_shmmgr::new_segment): Add size argument and use it to check against and update the new `_shm_tot' field. (server_shmmgr::delete_segment): Update the new `_shm_tot' field. * cygwin.din: Add the SysV IPC msg and sem interfaces. * Makefile.in (DLL_OFILES): Add new DLL object files.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/Makefile.in37
-rwxr-xr-xwinsup/cygwin/cygserver_shm.cc59
-rw-r--r--winsup/cygwin/cygserver_shm.h23
-rw-r--r--winsup/cygwin/cygwin.din7
-rw-r--r--winsup/cygwin/include/sys/ipc.h47
-rw-r--r--winsup/cygwin/include/sys/msg.h92
-rw-r--r--winsup/cygwin/include/sys/sem.h95
-rw-r--r--winsup/cygwin/include/sys/shm.h74
-rw-r--r--winsup/cygwin/msg.cc48
-rw-r--r--winsup/cygwin/sem.cc41
-rw-r--r--winsup/cygwin/shm.cc47
11 files changed, 449 insertions, 121 deletions
diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index bb49ffb86..96982e1a3 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -118,22 +118,27 @@ MALLOC_OFILES=@MALLOC_OFILES@
DLL_IMPORTS:=$(w32api_lib)/libkernel32.a
# Please maintain this list in sorted order, with maximum files per 80 col line
-DLL_OFILES:=assert.o autoload.o cygheap.o cygserver_client.o cygserver_transport.o \
- cygserver_transport_pipes.o cygserver_transport_sockets.o dcrt0.o debug.o \
- delqueue.o dir.o dlfcn.o dll_init.o dtable.o environ.o errno.o exceptions.o \
- exec.o external.o fcntl.o fhandler.o fhandler_clipboard.o fhandler_console.o \
- fhandler_disk_file.o fhandler_dsp.o fhandler_floppy.o fhandler_mem.o \
- fhandler_proc.o fhandler_process.o fhandler_random.o fhandler_raw.o \
- fhandler_registry.o fhandler_serial.o fhandler_socket.o \
- fhandler_tape.o fhandler_termios.o fhandler_tty.o fhandler_virtual.o \
- fhandler_windows.o fhandler_zero.o fnmatch.o fork.o glob.o grp.o \
- heap.o init.o ioctl.o ipc.o localtime.o malloc.o miscfuncs.o mmap.o \
- net.o ntea.o passwd.o path.o pinfo.o pipe.o poll.o pthread.o regcomp.o \
- regerror.o regexec.o regfree.o registry.o resource.o scandir.o sched.o \
- sec_acl.o sec_helper.o security.o select.o shared.o shm.o shortcut.o \
- signal.o sigproc.o smallprint.o spawn.o strace.o strsep.o sync.o \
- syscalls.o sysconf.o syslog.o termios.o thread.o times.o tty.o uinfo.o \
- uname.o v8_regexp.o v8_regerror.o v8_regsub.o wait.o wincap.o window.o \
+
+DLL_OFILES:=assert.o autoload.o cygheap.o cygserver_client.o \
+ cygserver_transport.o cygserver_transport_pipes.o \
+ cygserver_transport_sockets.o dcrt0.o debug.o delqueue.o dir.o \
+ dlfcn.o dll_init.o dtable.o environ.o errno.o exceptions.o \
+ exec.o external.o fcntl.o fhandler.o fhandler_clipboard.o \
+ fhandler_console.o fhandler_disk_file.o fhandler_dsp.o \
+ fhandler_floppy.o fhandler_mem.o fhandler_proc.o \
+ fhandler_process.o fhandler_random.o fhandler_raw.o \
+ fhandler_registry.o fhandler_serial.o fhandler_socket.o \
+ fhandler_tape.o fhandler_termios.o fhandler_tty.o \
+ fhandler_virtual.o fhandler_windows.o fhandler_zero.o \
+ fnmatch.o fork.o glob.o grp.o heap.o init.o ioctl.o ipc.o \
+ localtime.o malloc.o miscfuncs.o mmap.o msg.o net.o ntea.o \
+ passwd.o path.o pinfo.o pipe.o poll.o pthread.o regcomp.o \
+ regerror.o regexec.o regfree.o registry.o resource.o scandir.o \
+ sched.o sec_acl.o sec_helper.o security.o select.o sem.o \
+ shared.o shm.o shortcut.o signal.o sigproc.o smallprint.o \
+ spawn.o strace.o strsep.o sync.o syscalls.o sysconf.o syslog.o \
+ termios.o thread.o times.o tty.o uinfo.o uname.o v8_regexp.o \
+ v8_regerror.o v8_regsub.o wait.o wincap.o window.o \
$(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MALLOC_OFILES) $(MT_SAFE_OBJECTS)
GMON_OFILES:=gmon.o mcount.o profil.o
diff --git a/winsup/cygwin/cygserver_shm.cc b/winsup/cygwin/cygserver_shm.cc
index ea710f376..406c73be8 100755
--- a/winsup/cygwin/cygserver_shm.cc
+++ b/winsup/cygwin/cygserver_shm.cc
@@ -90,7 +90,7 @@ private:
const int intid;
const int shmid;
- shmid_ds ds;
+ struct shmid_ds ds;
int flg;
const HANDLE hFileMap;
@@ -115,8 +115,9 @@ public:
int shmat (HANDLE & hFileMap,
int shmid, int shmflg, pid_t, process_cache *, DWORD winpid);
- int shmctl (int & out_shmid, shmid_ds & out_ds, shminfo & out_info,
- const int shmid, int cmd, const shmid_ds &, pid_t);
+ int shmctl (int & out_shmid, struct shmid_ds & out_ds,
+ struct shminfo & out_shminfo, struct shm_info & out_shm_info,
+ const int shmid, int cmd, const struct shmid_ds &, pid_t);
int shmdt (int shmid, pid_t);
int shmget (int & out_shmid, key_t, size_t, int shmflg, pid_t, uid_t, gid_t);
@@ -129,7 +130,8 @@ private:
CRITICAL_SECTION _segments_lock;
segment_t *_segments_head; // A list sorted by int_id.
- int _shmseg_cnt; // Number of shm segments (for ipcs(8)).
+ int _shm_ids; // Number of shm segments (for ipcs(8)).
+ int _shm_tot; // Total bytes of shm segments (for ipcs(8)).
int _intid_max; // Highest intid yet allocated (for ipcs(8)).
server_shmmgr ();
@@ -144,7 +146,7 @@ private:
int new_segment (key_t, size_t, int shmflg, pid_t, uid_t, gid_t);
- segment_t *new_segment (key_t, HANDLE);
+ segment_t *new_segment (key_t, size_t, HANDLE);
void delete_segment (segment_t *);
};
@@ -241,8 +243,12 @@ server_shmmgr::shmat (HANDLE & hFileMap,
*---------------------------------------------------------------------------*/
int
-server_shmmgr::shmctl (int & out_shmid, shmid_ds & out_ds, shminfo & out_info,
- const int shmid, const int cmd, const shmid_ds & ds,
+server_shmmgr::shmctl (int & out_shmid,
+ struct shmid_ds & out_ds,
+ struct shminfo & out_shminfo,
+ struct shm_info & out_shm_info,
+ const int shmid, const int cmd,
+ const struct shmid_ds & ds,
const pid_t cygpid)
{
syscall_printf ("shmctl (shmid = %d, cmd = 0x%x) for %d",
@@ -304,15 +310,17 @@ server_shmmgr::shmctl (int & out_shmid, shmid_ds & out_ds, shminfo & out_info,
break;
case IPC_INFO:
- out_info.shmmax = SHMMAX;
- out_info.shmmin = SHMMIN;
- out_info.shmmni = SHMMNI;
- out_info.shmseg = SHMSEG;
- out_info.shmall = SHMALL;
+ out_shminfo.shmmax = SHMMAX;
+ out_shminfo.shmmin = SHMMIN;
+ out_shminfo.shmmni = SHMMNI;
+ out_shminfo.shmseg = SHMSEG;
+ out_shminfo.shmall = SHMALL;
break;
case SHM_INFO: // ipcs(8) i'face.
out_shmid = _intid_max;
+ out_shm_info.shm_ids = _shm_ids;
+ out_shm_info.shm_tot = _shm_tot;
break;
default:
@@ -395,7 +403,6 @@ server_shmmgr::shmget (int & out_shmid,
int result = 0;
EnterCriticalSection (&_segments_lock);
- /* Does a segment already exist with that key? */
if (key == IPC_PRIVATE)
result = new_segment (key, size, shmflg, cygpid, uid, gid);
else
@@ -411,6 +418,8 @@ server_shmmgr::shmget (int & out_shmid,
result = -EIDRM;
else if ((shmflg & IPC_CREAT) && (shmflg & IPC_EXCL))
result = -EEXIST;
+ else if ((shmflg & ~(segptr->ds.shm_perm.mode)) & 0777)
+ result = -EACCES;
else if (size && segptr->ds.shm_segsz < size)
result = -EINVAL;
else
@@ -461,7 +470,8 @@ server_shmmgr::initialise_instance ()
server_shmmgr::server_shmmgr ()
: _segments_head (NULL),
- _shmseg_cnt (0),
+ _shm_ids (0),
+ _shm_tot (0),
_intid_max (0)
{
InitializeCriticalSection (&_segments_lock);
@@ -538,10 +548,10 @@ server_shmmgr::new_segment (const key_t key,
"[size = %lu]: %s"),
size, msg));
- return -EINVAL; // FIXME
+ return -ENOMEM; // FIXME
}
- segment_t *const segptr = new_segment (key, hFileMap);
+ segment_t *const segptr = new_segment (key, size, hFileMap);
if (!segptr)
{
@@ -567,8 +577,12 @@ server_shmmgr::new_segment (const key_t key,
*---------------------------------------------------------------------------*/
server_shmmgr::segment_t *
-server_shmmgr::new_segment (const key_t key, const HANDLE hFileMap)
+server_shmmgr::new_segment (const key_t key, const size_t size,
+ const HANDLE hFileMap)
{
+ if (_shm_tot + size > SHMALL)
+ return NULL;
+
int intid = 0; // Next expected intid value.
segment_t *previous = NULL; // Insert pointer.
@@ -602,7 +616,8 @@ server_shmmgr::new_segment (const key_t key, const HANDLE hFileMap)
_segments_head = segptr;
}
- _shmseg_cnt += 1;
+ _shm_ids += 1;
+ _shm_tot += size;
if (intid > _intid_max)
_intid_max = intid;
@@ -638,8 +653,9 @@ server_shmmgr::delete_segment (segment_t *const segptr)
"[handle = 0x%x]: %s"),
segptr->hFileMap, msg));
- assert (_shmseg_cnt > 0);
- _shmseg_cnt -= 1;
+ assert (_shm_ids > 0);
+ _shm_ids -= 1;
+ _shm_tot -= segptr->ds.shm_segsz;
safe_delete (segment_t, segptr);
}
@@ -703,7 +719,8 @@ client_request_shm::serve (transport_layer_base *const conn,
case SHMOP_shmctl:
result = shmmgr.shmctl (_parameters.out.shmid,
- _parameters.out.ds, _parameters.out.info,
+ _parameters.out.ds, _parameters.out.shminfo,
+ _parameters.out.shm_info,
_parameters.in.shmid, _parameters.in.cmd,
_parameters.in.ds, _parameters.in.cygpid);
break;
diff --git a/winsup/cygwin/cygserver_shm.h b/winsup/cygwin/cygserver_shm.h
index b323651fb..5ebe04141 100644
--- a/winsup/cygwin/cygserver_shm.h
+++ b/winsup/cygwin/cygserver_shm.h
@@ -68,7 +68,7 @@ public:
#ifdef __INSIDE_CYGWIN__
client_request_shm (int shmid, int shmflg); // shmat
- client_request_shm (int shmid, int cmd, const shmid_ds *); // shmctl
+ client_request_shm (int shmid, int cmd, const struct shmid_ds *); // shmctl
client_request_shm (int shmid); // shmdt
client_request_shm (key_t, size_t, int shmflg); // shmget
#endif
@@ -87,16 +87,22 @@ public:
return _parameters.out.hFileMap;
}
- const shmid_ds & ds () const
+ const struct shmid_ds & ds () const
{
assert (!error_code ());
return _parameters.out.ds;
}
- const shminfo & info () const
+ const struct shminfo & shminfo () const
{
assert (!error_code ());
- return _parameters.out.info;
+ return _parameters.out.shminfo;
+ }
+
+ const struct shm_info & shm_info () const
+ {
+ assert (!error_code ());
+ return _parameters.out.shm_info;
}
private:
@@ -114,16 +120,17 @@ private:
DWORD winpid;
uid_t uid;
gid_t gid;
- shmid_ds ds;
+ struct shmid_ds ds;
} in;
struct {
int shmid;
- HANDLE hFileMap;
union
{
- shmid_ds ds;
- shminfo info;
+ HANDLE hFileMap;
+ struct shmid_ds ds;
+ struct shminfo shminfo;
+ struct shm_info shm_info;
};
} out;
} _parameters;
diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din
index e29b031d4..e5960d0fd 100644
--- a/winsup/cygwin/cygwin.din
+++ b/winsup/cygwin/cygwin.din
@@ -1277,6 +1277,13 @@ _acltotext = acltotext
aclfromtext
_aclfromtext = aclfromtext
ftok
+msgctl
+msgget
+msgrcv
+msgsnd
+semctl
+semget
+semop
shmat
shmctl
shmdt
diff --git a/winsup/cygwin/include/sys/ipc.h b/winsup/cygwin/include/sys/ipc.h
index a809fd4ec..22e0e3c26 100644
--- a/winsup/cygwin/include/sys/ipc.h
+++ b/winsup/cygwin/include/sys/ipc.h
@@ -17,41 +17,34 @@ extern "C"
{
#endif
-/*
- * <sys/types.h> must be included before <sys/ipc.h>. We aren't meant
- * to automatically include it however.
- */
-
-struct ipc_perm {
- uid_t uid;
- gid_t gid;
- uid_t cuid;
- gid_t cgid;
- mode_t mode;
+struct ipc_perm
+{
+ uid_t uid; /* Owner's user ID. */
+ gid_t gid; /* Owner's group ID. */
+ uid_t cuid; /* Creator's user ID. */
+ gid_t cgid; /* Creator's group ID. */
+ mode_t mode; /* Read/write permission. */
key_t key;
-};
+};
-/*
- * The mode flags used with the _get functions use the low order 9
- * bits for a mode request.
+/* Mode bits:
*/
-#define IPC_CREAT 0x0200
-#define IPC_EXCL 0x0400
-#define IPC_NOWAIT 0x0800
+#define IPC_CREAT 0x0200 /* Create entry if key does not exist. */
+#define IPC_EXCL 0x0400 /* Fail if key exists. */
+#define IPC_NOWAIT 0x0800 /* Error if request must wait. */
-/* This is a value that will _never_ be a valid key from ftok(3). */
-#define IPC_PRIVATE ((key_t) -2)
+/* Keys:
+ */
+#define IPC_PRIVATE ((key_t) 0) /* Private key. */
-/*
- * Values for the cmd argument to shmctl(2).
- * Commands 1000-1fff are reserved for IPC_xxx.
+/* Control commands:
*/
-#define IPC_RMID 0x1000
-#define IPC_SET 0x1001
-#define IPC_STAT 0x1002
+#define IPC_RMID 0x1000 /* Remove identifier. */
+#define IPC_SET 0x1001 /* Set options. */
+#define IPC_STAT 0x1002 /* Get options. */
#define IPC_INFO 0x1003 /* For ipcs(8). */
-key_t ftok(const char *, int);
+key_t ftok (const char *path, int id);
#ifdef __cplusplus
}
diff --git a/winsup/cygwin/include/sys/msg.h b/winsup/cygwin/include/sys/msg.h
new file mode 100644
index 000000000..2b00bb723
--- /dev/null
+++ b/winsup/cygwin/include/sys/msg.h
@@ -0,0 +1,92 @@
+/* sys/msg.h
+
+ Copyright 2002 Red Hat Inc.
+ Written by Conrad Scott <conrad.scott@dsl.pipex.com>
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license. Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifndef _SYS_MSG_H
+#define _SYS_MSG_H
+
+#include <sys/ipc.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* Message operation flags:
+ */
+#define MSG_NOERROR 0x01 /* No error if big message. */
+
+/* Command definitions for the semctl () function:
+ */
+#define MSG_STAT 0x2000 /* For ipcs(8) */
+#define MSG_INFO 0x2001 /* For ipcs(8) */
+
+/* Used for the number of messages in the message queue.
+ */
+typedef long int msgqnum_t;
+
+/* Used for the number of bytes allowed in a message queue.
+ */
+typedef long int msglen_t;
+
+struct msqid_ds
+{
+ struct ipc_perm msg_perm; /* Operation permission structure. */
+ msglen_t msg_cbytes; /* Number of bytes currently on queue. */
+ msgqnum_t msg_qnum; /* Number of messages currently on queue. */
+ msglen_t msg_qbytes; /* Maximum number of bytes allowed on queue. */
+ pid_t msg_lspid; /* Process ID of last msgsnd (). */
+ pid_t msg_lrpid; /* Process ID of last msgrcv (). */
+ timestruc_t msg_stim; /* Time of last msgsnd (). */
+ timestruc_t msg_rtim; /* Time of last msgrcv (). */
+ timestruc_t msg_ctim; /* Time of last change. */
+ long msg_spare4[2];
+};
+
+#define msg_stime msg_stim.tv_sec
+#define msg_rtime msg_rtim.tv_sec
+#define msg_ctime msg_ctim.tv_sec
+
+/* Buffer type for msgctl (IPC_INFO, ...) as used by ipcs(8).
+ */
+struct msginfo
+{
+ unsigned long msgpool; /* Maximum number of message bytes,
+ system wide. */
+ unsigned long msgmax; /* Maximum number of bytes per
+ message. */
+ unsigned long msgmnb; /* Maximum number of bytes on any one
+ message queue. */
+ unsigned long msgmni; /* Maximum number of message queues,
+ system wide. */
+ unsigned long msgtql; /* Maximum number of messages, system
+ wide. */
+ unsigned long msg_spare[4];
+};
+
+/* Buffer type for msgctl (MSG_INFO, ...) as used by ipcs(8).
+ */
+struct msg_info
+{
+ unsigned long msg_ids; /* Number of allocated queues. */
+ unsigned long msg_num; /* Number of messages, system wide. */
+ unsigned long msg_tot; /* Size in bytes of messages, system wide. */
+};
+
+int msgctl (int msqid, int cmd, struct msqid_ds *buf);
+int msgget (key_t key, int msgflg);
+ssize_t msgrcv (int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
+int msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS_MSG_H */
diff --git a/winsup/cygwin/include/sys/sem.h b/winsup/cygwin/include/sys/sem.h
new file mode 100644
index 000000000..bafd6c8d5
--- /dev/null
+++ b/winsup/cygwin/include/sys/sem.h
@@ -0,0 +1,95 @@
+/* sys/sem.h
+
+ Copyright 2002 Red Hat Inc.
+ Written by Conrad Scott <conrad.scott@dsl.pipex.com>
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license. Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifndef _SYS_SEM_H
+#define _SYS_SEM_H
+
+#include <sys/ipc.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* Semaphore operation flags:
+ */
+#define SEM_UNDO /* Set up adjust on exit entry. */
+
+/* Command definitions for the semctl () function:
+ */
+#define GETNCNT 0x3000 /* Get semncnt. */
+#define GETPID 0x3001 /* Get sempid. */
+#define GETVAL 0x3002 /* Get semval. */
+#define GETALL 0x3003 /* Get all cases of semval. */
+#define GETZCNT 0x3004 /* Get semzcnt. */
+#define SETVAL 0x3005 /* Set semval. */
+#define SETALL 0x3006 /* Set all cases of semval. */
+
+#define SEM_STAT 0x3010 /* For ipcs(8). */
+#define SEM_INFO 0x3011 /* For ipcs(8). */
+
+struct semid_ds
+{
+ struct ipc_perm sem_perm; /* Operation permission structure. */
+ unsigned short sem_nsems; /* Number of semaphores in set. */
+ timestruc_t sem_otim; /* Last semop () time. */
+ timestruc_t sem_ctim; /* Last time changed by semctl (). */
+ long sem_spare4[2];
+};
+
+#define sem_otime sem_otim.tv_sec
+#define sem_ctime sem_ctim.tv_sec
+
+struct sembuf
+{
+ unsigned short sem_num; /* Semaphore number. */
+ short sem_op; /* Semaphore operation. */
+ short sem_flg; /* Operation flags. */
+};
+
+/* Buffer type for semctl (IPC_INFO, ...) as used by ipcs(8).
+ */
+struct seminfo
+{
+ unsigned long semmni; /* Maximum number of unique semaphore
+ sets, system wide. */
+ unsigned long semmns; /* Maximum number of semaphores,
+ system wide. */
+ unsigned long semmsl; /* Maximum number of semaphores per
+ semaphore set. */
+ unsigned long semopm; /* Maximum number of operations per
+ semop call. */
+ unsigned long semmnu; /* Maximum number of undo structures,
+ system wide. */
+ unsigned long semume; /* Maximum number of undo entries per
+ undo structure. */
+ unsigned long semvmx; /* Maximum semaphore value. */
+ unsigned long semaem; /* Maximum adjust-on-exit value. */
+ unsigned long sem_spare[4];
+};
+
+/* Buffer type for semctl (SEM_INFO, ...) as used by ipcs(8).
+ */
+struct sem_info
+{
+ unsigned long sem_ids; /* Number of allocated semaphore sets. */
+ unsigned long sem_num; /* Number of allocated semaphores. */
+};
+
+int semctl (int semid, int semnum, int cmd, ...);
+int semget (key_t key, int nsems, int semflg);
+int semop (int semid, struct sembuf *sops, size_t nsops);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS_SEM_H */
diff --git a/winsup/cygwin/include/sys/shm.h b/winsup/cygwin/include/sys/shm.h
index 15be9e649..f800454da 100644
--- a/winsup/cygwin/include/sys/shm.h
+++ b/winsup/cygwin/include/sys/shm.h
@@ -19,36 +19,35 @@ extern "C"
{
#endif
-/*
- * 64 Kb was hardcoded for x86. MS states this may change, but we need
+/* 64 Kb was hardcoded for x86. MS states this may change, but we need
* it in the header file.
*/
-#define SHMLBA 65536
+#define SHMLBA 65536 /* Segment low boundary address multiple. */
-/*
- * Values for the shmflg argument to shmat(2).
+/* Shared memory operation flags:
*/
-#define SHM_RDONLY 0x01 /* Attach read-only, not read/write. */
-#define SHM_RND 0x02 /* Round shmaddr down to multiple of SHMLBA. */
+#define SHM_RDONLY 0x01 /* Attach read-only (else read-write). */
+#define SHM_RND 0x02 /* Round attach address to SHMLBA. */
-/*
- * Values for the cmd argument to shmctl(2).
- * Commands 4000-4fff are reserved for SHM_xxx.
+/* Command definitions for the semctl () function:
*/
#define SHM_STAT 0x4000 /* For ipcs(8) */
#define SHM_INFO 0x4001 /* For ipcs(8) */
+/* Unsigned integer used for the number of current attaches.
+ */
typedef long int shmatt_t;
-struct shmid_ds {
- struct ipc_perm shm_perm;
- size_t shm_segsz;
- pid_t shm_lpid;
- pid_t shm_cpid;
- shmatt_t shm_nattch;
- timestruc_t shm_atim;
- timestruc_t shm_dtim;
- timestruc_t shm_ctim;
+struct shmid_ds
+{
+ struct ipc_perm shm_perm; /* Operation permission structure. */
+ size_t shm_segsz; /* Size of segment in bytes. */
+ pid_t shm_lpid; /* Process ID of last operation. */
+ pid_t shm_cpid; /* Process ID of creator. */
+ shmatt_t shm_nattch; /* Number of current attaches. */
+ timestruc_t shm_atim; /* Time of last shmat (). */
+ timestruc_t shm_dtim; /* Time of last shmdt (). */
+ timestruc_t shm_ctim; /* Time of last change by shmctl (). */
long shm_spare4[2];
};
@@ -56,20 +55,35 @@ struct shmid_ds {
#define shm_dtime shm_dtim.tv_sec
#define shm_ctime shm_ctim.tv_sec
-/* Buffer type for shmctl(IPC_INFO, ...) as used by ipcs(8). */
-struct shminfo {
- unsigned long shmmax;
- unsigned long shmmin;
- unsigned long shmmni;
- unsigned long shmseg;
- unsigned long shmall;
+/* Buffer type for shmctl (IPC_INFO, ...) as used by ipcs(8).
+ */
+struct shminfo
+{
+ unsigned long shmmax; /* Maximum size in bytes of a shared
+ memory segment. */
+ unsigned long shmmin; /* Minimum size in bytes of a shared
+ memory segment. */
+ unsigned long shmmni; /* Maximum number of shared memory
+ segments, system wide. */
+ unsigned long shmseg; /* Maximum number of shared memory
+ segments attached per process. */
+ unsigned long shmall; /* Maximum number of bytes of shared
+ memory, system wide. */
unsigned long shm_spare[4];
};
-void *shmat(int shmid, const void *shmaddr, int shmflg);
-int shmctl(int shmid, int cmd, struct shmid_ds *buf);
-int shmdt(const void *shmaddr);
-int shmget(key_t key, size_t size, int shmflg);
+/* Buffer type for shmctl (SHM_INFO, ...) as used by ipcs(8).
+ */
+struct shm_info
+{
+ unsigned long shm_ids; /* Number of allocated segments. */
+ unsigned long shm_tot; /* Size in bytes of allocated segments. */
+};
+
+void *shmat (int shmid, const void *shmaddr, int shmflg);
+int shmctl (int shmid, int cmd, struct shmid_ds *buf);
+int shmdt (const void *shmaddr);
+int shmget (key_t key, size_t size, int shmflg);
#ifdef __cplusplus
}
diff --git a/winsup/cygwin/msg.cc b/winsup/cygwin/msg.cc
new file mode 100644
index 000000000..0daee06f7
--- /dev/null
+++ b/winsup/cygwin/msg.cc
@@ -0,0 +1,48 @@
+/* msg.cc: Single unix specification IPC interface for Cygwin.
+
+ Copyright 2002 Red Hat, Inc.
+
+ Written by Conrad Scott <conrad.scott@dsl.pipex.com>.
+
+This file is part of Cygwin.
+
+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"
+
+#include <sys/types.h>
+#include <sys/msg.h>
+
+#include <errno.h>
+
+#include "cygerrno.h"
+
+extern "C" int
+msgctl (int msqid, int cmd, struct msqid_ds *buf)
+{
+ set_errno (ENOSYS);
+ return -1;
+}
+
+extern "C" int
+msgget (key_t key, int msgflg)
+{
+ set_errno (ENOSYS);
+ return -1;
+}
+
+extern "C" ssize_t
+msgrcv (int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
+{
+ set_errno (ENOSYS);
+ return -1;
+}
+
+extern "C" int
+msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg)
+{
+ set_errno (ENOSYS);
+ return -1;
+}
diff --git a/winsup/cygwin/sem.cc b/winsup/cygwin/sem.cc
new file mode 100644
index 000000000..8d0f873a7
--- /dev/null
+++ b/winsup/cygwin/sem.cc
@@ -0,0 +1,41 @@
+/* sem.cc: Single unix specification IPC interface for Cygwin.
+
+ Copyright 2002 Red Hat, Inc.
+
+ Written by Conrad Scott <conrad.scott@dsl.pipex.com>.
+
+This file is part of Cygwin.
+
+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"
+
+#include <sys/types.h>
+#include <sys/sem.h>
+
+#include <errno.h>
+
+#include "cygerrno.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;
+}
+
+extern "C" int
+semop (int semid, struct sembuf *sops, size_t nsops)
+{
+ set_errno (ENOSYS);
+ return -1;
+}
diff --git a/winsup/cygwin/shm.cc b/winsup/cygwin/shm.cc
index 489154c45..93d4414aa 100644
--- a/winsup/cygwin/shm.cc
+++ b/winsup/cygwin/shm.cc
@@ -99,7 +99,7 @@ public:
static client_shmmgr & instance ();
void *shmat (int shmid, const void *, int shmflg);
- int shmctl (int shmid, int cmd, shmid_ds *);
+ int shmctl (int shmid, int cmd, struct shmid_ds *);
int shmdt (const void *);
int shmget (key_t, size_t, int shmflg);
@@ -190,19 +190,19 @@ client_shmmgr::shmat (const int shmid,
int
client_shmmgr::shmctl (const int shmid,
const int cmd,
- shmid_ds *const buf)
+ struct shmid_ds *const buf)
{
syscall_printf ("shmctl (shmid = %d, cmd = 0x%x, buf = 0x%p)",
shmid, cmd, buf);
// Check parameters and set up in parameters as required.
- const shmid_ds *in_buf = NULL;
+ const struct shmid_ds *in_buf = NULL;
switch (cmd)
{
case IPC_SET:
- if (__check_invalid_read_ptr_errno (buf, sizeof (shmid_ds)))
+ if (__check_invalid_read_ptr_errno (buf, sizeof (struct shmid_ds)))
{
syscall_printf (("-1 [EFAULT] = "
"shmctl (shmid = %d, cmd = 0x%x, buf = 0x%p)"),
@@ -215,7 +215,7 @@ client_shmmgr::shmctl (const int shmid,
case IPC_STAT:
case SHM_STAT:
- if (__check_null_invalid_struct_errno (buf, sizeof (shmid_ds)))
+ if (__check_null_invalid_struct_errno (buf, sizeof (struct shmid_ds)))
{
syscall_printf (("-1 [EFAULT] = "
"shmctl (shmid = %d, cmd = 0x%x, buf = 0x%p)"),
@@ -226,7 +226,18 @@ client_shmmgr::shmctl (const int shmid,
break;
case IPC_INFO:
- if (__check_null_invalid_struct_errno (buf, sizeof (shminfo)))
+ if (__check_null_invalid_struct_errno (buf, sizeof (struct shminfo)))
+ {
+ syscall_printf (("-1 [EFAULT] = "
+ "shmctl (shmid = %d, cmd = 0x%x, buf = 0x%p)"),
+ shmid, cmd, buf);
+ set_errno (EFAULT);
+ return -1;
+ }
+ break;
+
+ case SHM_INFO:
+ if (__check_null_invalid_struct_errno (buf, sizeof (struct shm_info)))
{
syscall_printf (("-1 [EFAULT] = "
"shmctl (shmid = %d, cmd = 0x%x, buf = 0x%p)"),
@@ -261,16 +272,17 @@ client_shmmgr::shmctl (const int shmid,
break;
case IPC_INFO:
- *(shminfo *) buf = request.info ();
+ *(struct shminfo *) buf = request.shminfo ();
break;
case SHM_STAT: // ipcs(8) i'face.
- *buf = request.ds ();
result = request.shmid ();
+ *buf = request.ds ();
break;
case SHM_INFO: // ipcs(8) i'face.
result = request.shmid ();
+ *(struct shm_info *) buf = request.shm_info ();
break;
}
@@ -354,32 +366,29 @@ client_shmmgr::shmdt (const void *const shmaddr)
/*---------------------------------------------------------------------------*
* client_shmmgr::shmget ()
- *
- * The `key = 0x%08x%08x' contortions in the tracing statements is
- * because small_printf () doesn't support 64-bit integers.
*---------------------------------------------------------------------------*/
int
client_shmmgr::shmget (const key_t key, const size_t size, const int shmflg)
{
- syscall_printf ("shmget (key = 0x%08x%08x, size = %u, shmflg = 0%o)",
- (unsigned) (key >> 32), (unsigned) key, size, shmflg);
+ syscall_printf ("shmget (key = 0x%016X, size = %u, shmflg = 0%o)",
+ key, size, shmflg);
client_request_shm request (key, size, shmflg);
if (request.make_request () == -1 || request.error_code ())
{
syscall_printf (("-1 [%d] = "
- "shmget (key = 0x%08x%08x, size = %u, shmflg = 0%o)"),
+ "shmget (key = 0x%016X, size = %u, shmflg = 0%o)"),
request.error_code (),
- (unsigned) (key >> 32), (unsigned) key, size, shmflg);
+ key, size, shmflg);
set_errno (request.error_code ());
return -1;
}
- syscall_printf (("%d = shmget (key = 0x%08x%08x, size = %u, shmflg = 0%o)"),
+ syscall_printf (("%d = shmget (key = 0x%016X, size = %u, shmflg = 0%o)"),
request.shmid (),
- (unsigned) (key >> 32), (unsigned) key, size, shmflg);
+ key, size, shmflg);
return request.shmid ();
}
@@ -608,7 +617,7 @@ shmat (const int shmid, const void *const shmaddr, const int shmflg)
*---------------------------------------------------------------------------*/
extern "C" int
-shmctl (const int shmid, const int cmd, shmid_ds *const buf)
+shmctl (const int shmid, const int cmd, struct shmid_ds *const buf)
{
return shmmgr.shmctl (shmid, cmd, buf);
}
@@ -669,7 +678,7 @@ client_request_shm::client_request_shm (const int shmid, const int shmflg)
client_request_shm::client_request_shm (const int shmid,
const int cmd,
- const shmid_ds *const buf)
+ const struct shmid_ds *const buf)
: client_request (CYGSERVER_REQUEST_SHM, &_parameters, sizeof (_parameters))
{
_parameters.in.shmop = SHMOP_shmctl;