diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2021-05-21 13:01:56 +0300 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2021-05-21 14:43:24 +0300 |
commit | 4fc922b2c8a5920304e3aca2f575de9627fa20a1 (patch) | |
tree | 2afab6c13727ba9906cba3a8e536e705f7262d0a /winsup/cygwin/mqueue_types.h | |
parent | c0949782b7dd123a78f5469ca9e088eb33f59030 (diff) |
Cygwin: POSIX msg queues: Convert mqd_t to a descriptor
So far, the mqd_t type returned a pointer to an allocated
area under the hood. The mutex and event objects attached
to the message queue were implemented as inheritable types.
As unfortunate side effect the HANDLEs to these objects
were inherited by exec'd child processes, even though all
other message queue properties are not inherted, per POSIX.
Fix this by converting an mqd_t to a descriptor, and create a
matching fhandler_mqueue object to handle various aspects of
the message queues inside the fhandler. Especially, create the
IPC objects as non-inheritable and duplicate the HANDLEs as
part of the fixup_after_fork mechanism.
Drop using mmap and create the memory map with NT functions.
This allows to control duplication of handle and mapping in the
forked child process, without the requirement to regenerate the
map in the same spot. It also allows to dup() the descriptor,
as on Linux, albeit this isn't implemented yet.
This patch is the first cut. There's a bit more to do, like
moving more functionality from the POSIX functions into the
fhandler and making sure the mqd_t type can't be used in other
descriptor-related functions willy-nilly.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/mqueue_types.h')
-rw-r--r-- | winsup/cygwin/mqueue_types.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/winsup/cygwin/mqueue_types.h b/winsup/cygwin/mqueue_types.h new file mode 100644 index 000000000..eab372238 --- /dev/null +++ b/winsup/cygwin/mqueue_types.h @@ -0,0 +1,58 @@ +/* mqueue_types.h: internal POSIX message queue types + +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. */ + +#pragma once + +#define MQI_MAGIC 0x98765432UL + +/* The mq_attr structure is defined using long datatypes per POSIX. + The mq_fattr is the in-file representation of the mq_attr struct. + Originally created this way for 32/64 bit interoperability, this + is of no concern anymore. */ +#pragma pack (push, 4) +struct mq_fattr +{ + uint32_t mq_flags; + uint32_t mq_maxmsg; + uint32_t mq_msgsize; + uint32_t mq_curmsgs; +}; + +struct mq_hdr +{ + struct mq_fattr mqh_attr; /* the queue's attributes */ + int32_t mqh_head; /* index of first message */ + int32_t mqh_free; /* index of first free message */ + int32_t mqh_nwait; /* #threads blocked in mq_receive() */ + pid_t mqh_pid; /* nonzero PID if mqh_event set */ + char mqh_uname[36]; /* unique name used to identify synchronization + objects connected to this queue */ + union { + struct sigevent mqh_event; /* for mq_notify() */ + uint64_t __mqh_dummy[4]; + }; + uint64_t __mgh_ext[4]; /* Free for extensions. */ + uint32_t mqh_magic; /* Expect MQI_MAGIC here, otherwise it's + an old-style message queue. */ +}; +#pragma pack (pop) + +struct mq_info +{ + struct mq_hdr *mqi_hdr; /* start of mmap'ed region */ + HANDLE mqi_sect; /* file mapping section handle */ + SIZE_T mqi_sectsize; /* file mapping section size */ + mode_t mqi_mode; /* st_mode of the mapped file */ + HANDLE mqi_lock; /* mutex lock */ + HANDLE mqi_waitsend; /* and condition variable for full queue */ + HANDLE mqi_waitrecv; /* and condition variable for empty queue */ + uint32_t mqi_magic; /* magic number if open */ + int mqi_flags; /* flags for this process */ +}; + + |