Commit Graph

19880 Commits

Author SHA1 Message Date
Ken Brown 9037f01e51 Cygwin: AF_UNIX: implement recvmsg
First cut.  Not yet tested.
2021-06-04 12:41:43 -04:00
Ken Brown f95148f156 Cygwin: AF_UNIX: implement sendmsg
First cut.  Not yet tested.
2021-06-04 12:36:46 -04:00
Ken Brown 37b102057a Cygwin: AF_UNIX: adapt shutdown to mqueues 2021-06-04 12:36:46 -04:00
Ken Brown 7720ea9679 Cygwin: AF_UNIX: keep a reference count of open descriptors
Add a data member _ndesc to the af_unix_shmem_t class, along with
methods to increment and decrement it.

Increment it during socket/fork/exec/dup, and decrement it during
close.  When the last descriptor is closed, call shutdown (SHUT_RDWR)
and unlink the socket's message queue.

The shutdown call will make the socket's peer see EPIPE if it tries to
write.
2021-06-04 12:36:46 -04:00
Ken Brown 6172419ed2 Cygwin: AF_UNIX: adapt close to mqueues 2021-06-04 12:36:45 -04:00
Ken Brown 61116b051a Cygwin: AF_UNIX: adapt socketpair to mqueues 2021-06-04 12:36:45 -04:00
Ken Brown 37226b2763 Cygwin: AF_UNIX: adapt connect and accept to mqueues
- Flesh out connect_mqueue, which replaces connect_pipe.

- A new method wait_mqueue replaces wait_pipe.

- A new method wait_mqueue_thread replaces wait_pipe_thread.

- New methods send_mqueue_name and recv_peer_mqueue_name are used for
  making connection requests and responding to them.

- A new method xchg_sock_info is called after a connecting socket
  successfully receives its peer's mqueue name.  This functionality
  was previously in open_pipe.

- Remove open_pipe, listen_pipe, and create_pipe_instance, which are
  no longer needed.
2021-06-04 12:36:45 -04:00
Ken Brown 8ce83c452b Cygwin: AF_UNIX: adapt send_sock_info to mqueues
The socket info is sent as an administrative packet, for which we use
a higher priority "af_un_prio_admin" than for normal packets.
2021-06-04 12:36:45 -04:00
Ken Brown f1f66706a3 Cygwin: AF_UNIX: adapt recv_peer_info to mqueues 2021-06-04 12:36:45 -04:00
Ken Brown d9b2b63830 Cygwin: AF_UNIX: new helper function set_mqueue_non_blocking
This will replace set_pipe_non_blocking.
2021-06-04 12:36:45 -04:00
Ken Brown 9e3a04efb6 Cygwin: AF_UNIX: adapt grab_admin_pkt to mqueues
Use peek_mqueue instead of peek_pipe, and remove the latter.  Use
mq_receive instead of NtReadFile.
2021-06-04 12:36:45 -04:00
Ken Brown 92a7d6b532 Cygwin: AF_UNIX: new method peek_mqueue
This will replace peek_pipe.
2021-06-04 12:36:45 -04:00
Ken Brown cfed6351b0 Cygwin: AF_UNIX: add create_mqueue to replace create_pipe
Also add new data members mqd_in and mqd_out, along with getter and
setter methods.  mqd_in and mqd_out are mqueue descriptors for
input/output.  create_mqueue creates an mqueue for reading and sets
mqd_in to its descriptor.

Make other provisional changes so that compilation will succeed.
2021-06-04 12:36:45 -04:00
Ken Brown e5b69b9018 Cygwin: AF_UNIX: new method open_mqueue
This will replace open_pipe.
2021-06-04 12:36:45 -04:00
Ken Brown 83b2ac199d Cygwin: AF_UNIX: rework some internal methods
- open_abstract_link, open_reparse_point, and open_socket now return
  HANDLEs

- connect no longer checks the validity of the sockaddr structure.
  It's done in open_socket.
2021-06-04 12:36:45 -04:00
Ken Brown 700c140ba6 Cygwin: AF_UNIX: rename {create,open}_file to {create,open}_socket 2021-06-04 12:36:45 -04:00
Ken Brown 1b2475d7b9 Cygwin: AF_UNIX: adapt symlink and reparse point to mqueues
create_symlink, create_reparse_point, and create_file now take a char
*mqueue_name argument instead of a PUNICODE_STRING.  For
create_symlink, convert the string to a UNICODE_STRING and make that
the target of the symlink.  For create_reparse_point, store the string
in the reparse point as is.

Make other provisional changes so that compilation will succeed.  This
includes adding a methode connect_mqueue that does nothing for now.
2021-06-04 12:36:45 -04:00
Ken Brown c001dd883f Cygwin: AF_UNIX: replace gen_pipe_name by gen_mqueue_name
The generated name is now an ordinary string instead of a UNICODE_STRING.

Store it in pc.path.  For clarity, add methods set_mqueue_name and
get_mqueue name to do the storing and retrieving.  Add a method
path_conv::get_path to help with this.
2021-06-04 12:36:45 -04:00
Ken Brown 90f4337ea1 Cygwin: AF_UNIX: prepare for use of message queues
We will switch to using POSIX message queues instead of Windows pipes
for data transport.  In preparation for that, update the commentary in
fhandler_socket_unix.cc.

Also move the definition of class af_unix_pkt_hdr_t to fhandler.h and
make a few minor changes.
2021-06-04 12:36:45 -04:00
Ken Brown 19a7e4723c Cygwin: AF_UNIX: first cut of mqueue modifications 2021-06-04 12:23:15 -04:00
Ken Brown fdeedfb979 Cygwin: AF_UNIX: add saw_shutdown_read and saw_shutdown_write
For consistency between the fhandler_socket_unix and
fhandler_socket_wsock classes, add virtual methods saw_shutdown_read
and saw_shutdown_write to fhandler_socket.  Implement them for
fhandler_socket_unix.  (They were already implemented for
fhandler_socket_wsock.)
2021-06-04 11:19:28 -04:00
Ken Brown db2d38eb95 Cygwin: AF_UNIX: getpeername: fail if not connected 2021-06-04 11:19:28 -04:00
Ken Brown 94f6c2767c Cygwin: AF_UNIX: reopen_shmem: fix view size
Use sizeof (af_unix_shmem_t) as the view size, as when the shared
memory was created.  Previously PAGESIZE was used, causing
NtMapViewOfSection to fail with STATUS_INVALID_VIEW_SIZE.
2021-06-04 11:19:28 -04:00
Corinna Vinschen 0eaa7b8144 Cygwin: AF_UNIX: convert AF_UNIX_PKT helpers to inline functions
Add AF_UNIX_PKT_DATA_END and AF_UNIX_PKT_DATA_APPEND
2021-06-04 11:19:28 -04:00
Ken Brown 973af68fff Cygwin: AF_UNIX: implement constructor 2021-06-04 11:19:28 -04:00
Ken Brown 315920326a Cygwin: AF_UNIX: add socket tests 2021-06-04 11:19:28 -04:00
Ken Brown dfe5988f96 Cygwin: fhandler_mqueue::mq_open: fix typo 2021-05-26 12:48:58 -04:00
Richard Earnshaw 2a3a03972b aarch64: support binary mode for opening files
Newlib for aarch64 uses libgloss for the backend.  One common libgloss
implementation is the 'rdimon' implementation, which uses the Arm
Semihosting protocol.  In order to support a remote host that runs on
Windows we need to know whether a file is to be opened in binary or
text mode.  That means that we need to preserve this information via
O_BINARY until we know what the libgloss binding will be.

This patch simply copies the arm implementation from sys/arm/sys and
puts it in machine/aarch64/sys, because we don't have a 'sys' subtree
on aarch64.
2021-05-26 15:17:11 +01:00
Corinna Vinschen fd84f6cf51 Cygwin: utils: enable -idirafter to fetch Cygwin headers from mingw sources
Get rid of the last dreaded relative paths pointing to the cygwin dir.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-26 11:01:32 +02:00
Corinna Vinschen 48a76190e8 Cygwin: utils: set _WIN32_WINNT and NTDDI_VERSION via Makefile
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-26 11:01:32 +02:00
Corinna Vinschen 88a2f9875a Cygwin: set NTDDI_VERSION to enable more recent windows definitions
Set to WDK_NTDDI_VERSION since that enables all the latest.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-26 11:01:32 +02:00
Corinna Vinschen 1adb3f11b7 Cygwin: fhandler_mqueue: add missing __reg2 for 32 bit build
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-26 11:01:32 +02:00
Corinna Vinschen 59ba43dd9e Cygwin: fhandler_mqueue: disable more methods, add fcntl
Unsupported functionality returns EPERM, fcntl supports
only F_GETFD and F_GETFL.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 23:00:32 +02:00
Corinna Vinschen 2b4c7f90d4 Cygwin: fhandler_mqueue::mq_open: set all required fhandler flags
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:43:41 +02:00
Corinna Vinschen fd3fb7a147 Cygwin: disable creating directories below /dev/mqueue
...as on Linux.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:05:13 +02:00
Corinna Vinschen 90e5dbfc24 Cygwin: fhandler_mqueue: fix method declarations
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:04:43 +02:00
Corinna Vinschen 782b338530 Cygwin: path_conv: fix mqueue path check
The check for a file or dir within /dev/mqueue is accidentally using
the incoming path, which could be a relative path.  Make sure to
restore the absolute POSIX path in path_copy and only then test the
path.

Also, move the actual check for a valid path below /dev/mqueue into
the fhandler_mqueue class.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:03:36 +02:00
Corinna Vinschen 4c09dc4f9c Cygwin: cwdstuff: check if /dev exists
/dev has been handled as virtual dir in cwdstuff, thus not allowing
to start native apps from /dev as CWD, even if /dev actually exists
on disk.  Unfortunately this also affects Cygwin executables started
from a debugger.

When chdir'ing to /dev, check if /dev exists on disk.  If so, treat
it as any other existing path.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 21:46:13 +02:00
Corinna Vinschen efef4b8bf1 Cygwin: POSIX msg queues: implement read(2)/lseek(2)
reuse fhandler_virtual implementation to implement read and lseek.
The output from read(2) is modelled after the output when reading
from an mq file on Linux.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 20:19:19 +02:00
Corinna Vinschen 517c7e79da Cygwin: POSIX msg queues: implement ioctl(2)
Call into fhandler_base::ioctl immediately, thus only allowing
FIONBIO to manipulate blocking behaviour.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 20:17:07 +02:00
Corinna Vinschen 46f3b0ce85 Cygwin: POSIX msg queues: move all mq_* functionality into fhandler_mqueue
The POSIX entry points are just wrappers now, calling into
fhandler_mqueue.  While at it, eliminate mqi_flags, replace with
standard fhandler nonblocking flag.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 20:15:16 +02:00
Corinna Vinschen e0cdd462f1 Cygwin: POSIX msg queues: allocate section views top down
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:55:38 +02:00
Corinna Vinschen fbcd61063b Cygwin: POSIX msg queues: Implement dup
Create a private method fhandler_mqueue::_dup and call it from
dup and fixup_after_fork methods.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:50:16 +02:00
Corinna Vinschen b62450cf17 Cygwin: POSIX msg queues: implement open/mq_open entirely in fhandler
The mq_open call is just a framework now.  This patch moves the
entire functionality into fhandler_mqueue.  To support standard
OS calls (as on Linux), make fhandler_mqueue a derived class from
fhandler_disk_file and keep the base handle the handle to the
default stream, to allow implementing O_PATH functionlaity as well
as reading from the file and NOT reading binary message queue data.

Implement a standard fhandler_mqueue::open method, allowing, for
instance, to touch a file under /dev/mqueue and if it doesn't exist,
to create a message queue file.

FIXME: This introduces a BAD HACK into path_conv::check, which needs
reviewing.

Keep the posix path intact in the fhandler, and change get_proc_fd_name
accordingly to return only the basename plus leading slash for
/proc/<PID>/fd.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:49:04 +02:00
Corinna Vinschen a4e074672a Cygwin: POSIX msg queues: slightly rephrase get_mqinfo
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:42:44 +02:00
Corinna Vinschen 2cc914a34e Cygwin: POSIX msg queues: simplify mq_close
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:41:45 +02:00
Corinna Vinschen 15c96f2b26 Cygwin: get_nt_native_path: allow to append suffix
POSIX message queues will be moved into NTFS streams.
Extend get_nt_native_path to provide a filename suffix which is not
subject to special character transposition, to allow specifying
a colon.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:31:26 +02:00
Corinna Vinschen 4ea7c12a20 Cygwin: POSIX msg queues: move definition of struct msg_hdr
...to mqueue_types.h header.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:17:58 +02:00
Corinna Vinschen 49b84cb264 Cygwin: POSIX msg queues: improve error output in fixup_after_fork
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-22 18:03:01 +02:00
Jon Turney a9c8050c36
Cygwin: Ensure PSAPI_VERSION is 1 when building ldd
The default PSAPI_VERSION is controlled by WIN32_WINNT, which we set to
0x0a00 when building ldd, which gets PSAPI_VERSION=2.

This causes K32GetModuleFileNameEx to be used for GetModuleFileNameEx,
which isn't available on Windows Vista.

Define PSAPI_VERSION as 1 for the built executable to work on Windows
Vista.
2021-05-22 16:06:51 +01:00