4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-09 02:29:07 +08:00

9082 Commits

Author SHA1 Message Date
Ken Brown
ee4f7ec67e Cygwin: AF_UNIX: add a unique id to struct fh_ser 2020-11-21 08:01:10 -05:00
Ken Brown
5a98fbb4f8 Cygwin: AF_UNIX: tweak serialize/deserialize
Make them member functions of the fhandler_socket_unix class.

Make them use void * instead of fh_ser * so that fhandler.h doesn't
need to know about fh_ser.
2020-11-21 08:01:10 -05:00
Ken Brown
0dac3caaf5 Cygwin: AF_UNIX: update tests 2020-11-21 08:01:10 -05:00
Ken Brown
9e6f77d4ef Cygwin: AF_UNIX: peek_pipe_poll: fix thinko
The variable 'sleep_time' was being reset to 0 on every loop
iteration.
2020-11-21 08:01:10 -05:00
Jon Turney
e707b18446 Cygwin: Remove recursive configure
There's doesn't seem to be much use in independently distributing these
subdirectories, so allowing them to be independently configured seems
pointless and overcomplicated.

The order in which the subdirectories are built is still a little odd,
as cygwin is linked with libcygserver, and cygserver is then linked with
cygwin. So, we build the cygwin directory first, which invokes a build
of libcygserver in the cygserver directory, and then build in the
cygserver directory to build the cygserver executable.

Drop AC_CONFIGURE_ARGS, since we don't need to recursively call
configure with the same arguments anymore.

Slightly refine when we build utils: Previously we didn't build any
utils if MinGW compiler use was avoided, now we just avoid building
those utils which require that compiler.

Greatly simplify how winsup_srcdir and target_builddir are set, since
we're only configuring from one directory.  (These are still kept
absolute, since we don't adjust them where used for being used in a
subdirectory).

Remove configure.cygwin and put it's (greatly reduced) contents inline
in the one place it's used now.

Remove generated configure and aclocal.m4 in subdirectories.
2020-11-21 08:01:09 -05:00
Ken Brown
1395b4ea2c Cygwin: fhandler_fifo::cleanup_handlers: improve efficiency
Traverse the fifo_client_handler list from the top down to try to
avoid copying.
2020-11-21 08:01:09 -05:00
Corinna Vinschen
b1dfff7b01 malloc/nano-malloc: correctly check for out-of-bounds allocation reqs
The overflow check in mEMALIGn erroneously checks for INT_MAX,
albeit the input parameter is size_t.  Fix this to check for
__SIZE_MAX__ instead.  Also, it misses to check the req against
adding the alignment before calling mALLOc.

While at it, add out-of-bounds checks to pvALLOc, nano_memalign,
nano_valloc, and Cygwin's (unused) dlpvalloc.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-11-18 14:18:28 -05:00
Ken Brown
05d40cdef3 Cygwin: AF_UNIX: implement sending/receiving SCM_RIGHTS ancillary data
First cut.  This is currently implemented only for disk files, and
many things still need to be fixed.  But it works in limited testing
with the programs scm_rights_{recv,send} in
winsup/cygwin/socket_tests.
2020-11-17 14:42:04 -05:00
Ken Brown
e8b866676f Cygwin: AF_UNIX: add serialization/deserialization for fhandlers
Define static helper functions serialize/deserialize in
fhandler_socket_unix.cc.  These will be used to support sending file
descriptors via SCM_RIGHTS control messages.

The serialize function creates an 'fh_ser' structure that contains a
copy of the fhandler associated with the file descriptor, with all
allocated memory freed.  The structure also contains the Windows pid
of the current process, which deserialize can use for duplicating
handles.

The deserialize function reconstructs an fhandler from an fh_ser
structure, with the handles duplicated into its own process.

For now, serialization and deserialization are fully implemented only
for disk files, and even in that case there are many FIXMEs that need
attention.
2020-11-17 14:42:01 -05:00
Ken Brown
0c98e9f6a0 Cygwin: path_conv::set_conv_handle(): new method 2020-11-17 09:22:32 -05:00
Ken Brown
5465d2dc75 Cygwin: device::free_strings(): new method
This is extracted from the destructor ~device().
2020-11-17 09:22:32 -05:00
Ken Brown
b9feec71ff Cygwin: fhandler_base::set_name_from _handle: new method
This is based on a new static member function dtable::handle_to_fn,
which was previously a static function in dtable.cc.
2020-11-17 09:21:57 -05:00
Ken Brown
91ce3d3fd7 Cygwin: fhandler_*::dup: add a 'src_pid' argument
This allows duplication of handles from an fhandler created in a
different process.  For now, this is implemented only for
fhandler_base and fhandler_disk_file.
2020-11-17 09:21:56 -05:00
Ken Brown
cf1034bd38 Cygwin: fhandler_base::get_size(): new method
Override this in each derived class to give the size of each fhandler
class so that the size can be computed dynamically from an
fhandler_base pointer.
2020-11-17 09:21:12 -05:00
Ken Brown
426976b01a Update tests 2020-11-17 09:21:05 -05:00
Ken Brown
84836642f9 Cygwin: path_conv::eq_worker: add NULL pointer checks
Don't call cstrdup on NULL pointers.

This fixes a crash that was observed when cloning an fhandler whose
path_conv member had freed its strings.
2020-11-16 14:46:15 -05:00
Ken Brown
7deff41e89 Cygwin: fhandler_fifo: reduce size
Replace the 'WCHAR pipe_name_buf[48]' class member by 'PWCHAR
pipe_name_buf', and allocate space for the latter as needed.

Change the default constructor to accommodate this change, and add a
destructor that frees the allocated space.

Also change get_pipe_name and clone to accommodate this change.
2020-11-09 08:50:08 -05:00
Ken Brown
410810968b Cygwin: FIFO: update_my_handlers: fix handle leak 2020-11-06 08:19:21 -05:00
Jon Turney
903cf7af11 Cygwin: Drop passing '-c' compiler flag into gentls_offsets
That script appends a '-E', since we only use $(CC) to preprocess, and
thus adding '-c' is having no effect.
2020-11-06 08:19:21 -05:00
Jon Turney
b96d9a4a55 Cygwin: Remove rules for building libcygwin_s.a
Untouched since added in 66a83f3e, and described as 'non-working'.
2020-11-06 08:19:21 -05:00
Jon Turney
7209c26c97 Cygwin: Remove Makefile contents conditional on PREPROCESS, which is never defined 2020-11-06 08:19:21 -05:00
Jon Turney
3aa3626e2f Cygwin: Drop autoconf variable all_host
The autoconf variable all_host is used to make building of the stub
library used by the testsuite conditional on not cross-compiling.

Make it unconditional, so we will notice if it's broken when
cross-compiling.
2020-11-06 08:19:21 -05:00
Jon Turney
4898c47419 Cygwin: Remove autoconf variable DLL_NAME
Remove autoconf variable DLL_NAME, which has a constant value which is
only used in one place.
2020-11-06 08:19:21 -05:00
Jon Turney
e7ecf188fa Revert "Cygwin: gendef generates sigfe.s and cygwin.def"
This reverts commit 74a164f1c162645f4389bbd9edb2f89a630853af.

Shame we can't use '&:' for a grouped target here, since that requires
GNU make 4.3
2020-11-06 08:19:20 -05:00
Ken Brown
3d37fd9cef Cygwin: AF_UNIX: improve control message handling
This includes various changes to create_cmsg_data and
evaluate_cmsg_data.  The most important are:

- create_cmsg_data now allows only one SCM_RIGHTS message and one
  SCM_CREDENTIALS message.

- evaluate_cmsg_data now truncates the ancillary data to the number of
  control messages that will fit in the supplied buffer.  Previously
  it discarded all control messages if the buffer was too small.

See https://man7.org/linux/man-pages/man7/unix.7.html.
2020-11-02 11:50:46 -05:00
Ken Brown
d42acb9bc8 Cygwin: AF_UNIX: recv_peer_info: fix return value
The variable 'ret' was being used with two different meanings.  As a
result, setting ret to an error code was not actualy setting the
return value.
2020-11-01 21:58:34 -05:00
Ken Brown
6da65394a3 Cygwin: AF_UNIX: update tests 2020-11-01 21:58:34 -05:00
Ken Brown
852fb2afba Cygwin: AF_UNIX: allow more than one control message
Previously, create_cmsg_data and evaluate_cmsg_data required the
ancillary data to contain only a single control message, of type
SCM_CREDENTIALS.  In preparation for supporting SCM_RIGHTS in the
future, allow more than one.

create_cmsg_data now iterates through the specified control messages
and allows both SCM_CREDENTIALS and SCM_RIGHTS.  If no SCM_CREDENTIALS
message is present, it creates one.  This was previously done in
sendmsg.

evaluate_cmsg_data also iterates through the received control messages
and allows both SCM_CREDENTIALS and SCM_RIGHTS.  Control messages of
type SCM_CREDENTIALS are discarded unless the SO_PASSCRED option has
been set.

Update tests.
2020-11-01 15:58:00 -05:00
Jon Turney
67f6939275 Cygwin: Restore setting CC and CXX Makefile variables
b55e3f19 was a bit too aggressive in dropping, rather than just
un-exporting these Makefile variables.  We need to set these to the
configured host compiler if we are cross-compiling, otherwise they
default to the build compiler.

Also export CC to the mkvers.sh script (which requires it since
4eca5e6a).  It's unclear why we can't just cause windres to use the
build 'cpp' as the pre-processor there.
2020-10-29 12:28:59 -04:00
Ken Brown
a55b1a60c5 Cygwin: AF_UNIX: recvmsg: fix MSG_PEEK support for datagrams
Add a new HANDLE argument to peek_pipe and peek_pipe_poll so that the
caller can specify a pipe handle to use in lieu of get_handle().  Use
this in recvmsg to make the MSG_PEEK flag work for unbound datagram
sockets.

Untested.
2020-10-29 12:27:24 -04:00
Ken Brown
d68d091944 Cygwin: AF_UNIX: recvmsg: support the MSG_TRUNC flag
This is in Linux since Linux 3.4 but not in Posix.

Not tested.
2020-10-29 11:39:00 -04:00
Ken Brown
c69c850df4 Cygwin: AF_UNIX: sendmsg: always send credentials
If the caller doesn't specify ancillary data, add credentials to the
outgoing packet.

This enables us to satisfy the requirement
(https://man7.org/linux/man-pages/man7/unix.7.html) that a socket with
the SO_PASSCRED option enabled can get the credentials of its peer in
every message it receives.

FIXME: I'm not sure if this is the right way to satisfy that
requirement.  A possible alternative would be to arrange for a socket
to be notified when its peer enables SO_PASSCRED.
2020-10-29 10:14:34 -04:00
Ken Brown
20fd0db075 Cygwin: AF_UNIX: create_cmsg_data: fix credential checking
Require the pid specified by an administrator to be the pid of an
existing process.
2020-10-29 09:17:38 -04:00
Ken Brown
fab8f9b104 Cygwin: AF_UNIX: create_cmsg_data: check credentials
If the user is not an administrator, check that the specified
credentials match the user's credentials.
2020-10-28 12:10:54 -04:00
Ken Brown
e5f2a0b1c8 Cygwin: AF_UNIX: FIXME comments 2020-10-28 10:38:49 -04:00
Ken Brown
d662a977f9 Cygwin: AF_UNIX: socketpair: set blocking mode earlier
Call set_nonblocking before creating the pipe so that the pipe is
created with the correct blocking mode.

Also call set_pipe_non_blocking on the second socket so that the
client end of the pipe has the correct blocking mode.  This also makes
sure that the client end of the pipe is set to message mode for
reading.
2020-10-28 10:01:03 -04:00
Ken Brown
7563d755f4 Cygwin: AF_UNIX: recvmsg: various improvements
If the caller has requested the source address, try to get it on each
iteration of the main read loop, not just the first.  Set msg_namelen
to 0 if it is never received.

If a packet containing control message data is received, don't read
any more packets, even if MSG_WAITALL is set.
2020-10-28 09:25:16 -04:00
Ken Brown
b1593593f0 Cygwin: AF_UNIX: create_cmsg_data: improve error handling
Set an errno before returning false.
2020-10-28 09:06:13 -04:00
Ken Brown
3ef34ca308 Cygwin: AF_UNIX: evaluate_cmsg_data: improve error handling
Set msg_controllen to the number of bytes of ancillary data actually
copied to msg_control.

Set the MSG_CTRUNC flag when appropriate.
2020-10-28 09:06:13 -04:00
Ken Brown
82474332a6 Cygwin: AF_UNIX: recvmsg: set MSG_TRUNC for truncated datagrams
If a datagram is truncated because it is larger than the supplied
buffer, set MSG_TRUNC in the msg_flags field of the (msghdr *)
argument.  See https://man7.org/linux/man-pages/man2/recvmsg.2.html.
2020-10-28 09:06:12 -04:00
Ken Brown
785de1a08d Cygwin: AF_UNIX: recvmsg: fix indentation 2020-10-28 09:06:12 -04:00
Ken Brown
784b811131 Cygwin: fix return value of sqrtl on negative infinity
The return value is now -NaN.

This fixes a bug in the mingw-w64 code that was imported into Cygwin.
The fix is consistent with Posix and Linux.  It is also consistent
with the current mingw-w64 code, with one exception: The mingw-w64
code sets errno to EDOM if the input is -NaN, but this appears to
differ from Posix and Linux.

Addresses: https://cygwin.com/pipermail/cygwin/2020-October/246606.html
2020-10-27 10:50:46 -04:00
Takashi Yano via Cygwin-patches
c5bf5617c0 Cygwin: pty: Disable ResizePseudoConsole() if stdout is redirected.
- Calling ResizePseudoConsole() generates some escape sequences.
  Due to this behaviour, if the output of non-cygwin app is piped
  to less, screen is sometimes distorted when the screen is resized.
  With this patch, ResizePseudoConsole() is not called if stdout is
  redirected.
2020-10-27 10:50:46 -04:00
Takashi Yano via Cygwin-patches
cef9a6cfb2 Cygwin: pty: Fix race condition in initialization of pseudo console.
- If output of non-cygwin process is piped to cygwin process, such
  as less, the non-cygwin process sometimes fails to start and hangs.
  This patch fixes the issue.
2020-10-27 10:50:45 -04:00
Ken Brown
a4f00ed42f Cygwin: AF_UNIX: add winsup/cygwin/socket_tests 2020-10-26 17:43:43 -04:00
Ken Brown
7d9bb0b2bc Cygwin: AF_UNIX: modify some FIXME comments 2020-10-26 15:08:39 -04:00
Ken Brown
7c0d061ec8 Cygwin: AF_UNIX: minor tweak 2020-10-26 14:51:08 -04:00
Ken Brown
67da0f3087 Cygwin: AF_UNIX: peek_pipe: check for STATUS_BUFFER_OVERFLOW
Treat this the same as STATUS_SUCCESS.
2020-10-26 14:50:09 -04:00
Ken Brown
abb6475a3b Cygwin: AF_UNIX: grab_admin_pkt: check for unread data in pipe
If there's unread data in the pipe from a previous partial read of a
packet, just return.  There can't be an administrative packet waiting
to be read in that case.
2020-10-26 14:38:20 -04:00
Ken Brown
3a6137eb3a Cygwin: AF_UNIX: accept4: set O_RDWR on new file descriptor 2020-10-26 10:53:37 -04:00