4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-02 04:20:28 +08:00

19628 Commits

Author SHA1 Message Date
Joel Sherrill
600d1902f4 libc/sys/rtems/include/machine/_types.h: Define daddr_t to be 64 bits for RTEMS
This type needs to be able to represent a position on a disk or
file system.
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
Kito Cheng
f685416883 RISC-V: Implment finite and fpclassify 2020-10-27 10:50:46 -04:00
Kito Cheng
245b6f20d5 RISC-V: Add fabs[f], fmax[f] and fmin[f]. 2020-10-27 10:50:46 -04:00
dougm
2d3c982b38 Define RB_SET_PARENT to do all assignments
to rb parent pointers. Define RB_SWAP_CHILD to replace the child of a parent
with its twin, and use it in 4 places. Use RB_SET in rb_link_node to remove the
only linuxkpi reference to color, and then drop color- and parent-related
definitions that are defined and used only in rbtree.h.

This is intended to be entirely cosmetic, with no impact on program
behavior, and leave RB_PARENT and RB_SET_PARENT as the only ways to
read and write rb parent pointers.

Reviewed by:	markj, kib
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25264
2020-10-27 10:50:46 -04:00
dougm
1857fbd2bb In concluding RB_REMOVE_COLOR, in the case when
the sibling of the root of the too-short tree is black and at least one of the
children of that sibling is red, either one or two rotations finish the
rebalancing. In the case when both of the children are red, the current
implementation uses two rotations where only one is necessary. This change
removes that extra rotation, and in that case also removes a needless
black-to-red-to-black recoloring.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D25335
2020-10-27 10:50:46 -04:00
dougm
cc374766cf Linuxkpi uses the rb-tree structures
without using their interfaces, making them break when the representation
changes. Revert changes that eliminated the color field from rb-trees, leaving
everything as it was before.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D25250
2020-10-27 10:50:46 -04:00
dougm
f73d29df76 Fixup r361997 by balancing parens. Duh. 2020-10-27 10:50:45 -04:00
dougm
a48b79b3c1 Restore an RB_COLOR macro, for the benefit of
a bit of DIAGNOSTIC code that depends on it.

Reported by:	rpokala, mjguzik
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D25204
2020-10-27 10:50:45 -04:00
dougm
fa79e63dee To reduce the size of an rb_node, drop the color
field. Set the least significant bit in the pointer to the node from its parent
to indicate that the node is red. Have the tree rotation macros leave the
old-parent/new-child node red and the new-parent/old-child node black.

This change makes RB_LEFT and RB_RIGHT no longer assignable, and
RB_COLOR no longer defined. Any code that modifies the tree or
examines a node color would have to be modified after this change.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25105
2020-10-27 10:50:45 -04:00
dougm
cc0692cd16 Remove from RB_REMOVE_COLOR some null checks
where the pointer checked is provably never null. Restructure the surrounding
code just enough to make the non-nullness obvious.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25089
2020-10-27 10:50:45 -04:00
dougm
900dea1fd3 RB_REMOVE invokes RB_REMOVE_COLOR either when
child is red or child is null. In the first case, RB_REMOVE_COLOR just changes
the child to black and returns. With this change, RB_REMOVE handles that case,
and drops the child argument to RB_REMOVE_COLOR, since that value is always
null.

RB_REMOVE_COLOR is changed to remove a couple of unneeded tests, and
to eliminate some deep indentation.

RB_ISRED is defined to combine a null check with a test for redness,
to replace that combination in several places.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D25032
2020-10-27 10:50:45 -04:00
dougm
c213fe81d8 For the case when RB_REMOVE requires a nontrivial
search to find the node to replace the one being removed, restructure to first
remove the replacement node and correct the parent pointers around it, and then
let the all-cases code at the end deal with the parent of the deleted node,
making it point to the replacement node. This removes one or two conditional
branches.

Reviewed by:	markj
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D24845
2020-10-27 10:50:45 -04:00
dougm
053a1e9b7d Correct the use of RB_AUGMENT in the RB_TREE
macros so that is invoked at the root of every subtree that changes in an
insert or delete, and only once, and ordered from the bottom of the tree to the
top. For intel_gas.c, the only user of RB_AUGMENT I can find, change the
augmenting routine so that it does not climb from entry to tree root on every
call, and remove a 'tree correcting' function that can be supplanted by proper
tree augmentation.

Reviewed by:	kib
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D23189
2020-10-27 10:50:45 -04:00
trasz
665fcdbe32 Add RB_REINSERT(3), a low overhead alternative to
removing a node and reinserting it back with an updated key.

This is one of dependencies for the upcoming stats(3) code.

Reviewed by:	cem
Obtained from:	Netflix
MFC after:	2 weeks
Sponsored by:	Klara Inc, Netflix
Differential Revision:	https://reviews.freebsd.org/D21786
2020-10-27 10:50:45 -04:00
jah
7c3be88a0c amd64: prevent KCSan false positives on LAPIC mapping
For configurations without x2APIC support (guests, older hardware), the global
LAPIC MMIO mapping will trigger false-positive KCSan reports as it will appear
that multiple CPUs are concurrently reading and writing the same address.
This isn't actually true, as the underlying physical access will be performed
on the local CPU's APIC. Additionally, because LAPIC access can happen during
event timer configuration, the resulting KCSan printf can produce a panic due
to attempted recursion on event timer resources.

Add a __nosanitizethread preprocessor define to prevent the compiler from
inserting TSan hooks, and apply it to the x86 LAPIC accessors.

PR:		249149
Reported by:	gbe
Reviewed by:	andrew, kib
Tested by:	gbe
Differential Revision:	https://reviews.freebsd.org/D26354
2020-10-27 10:50:45 -04:00
mjg
756358e990 sys: clean up empty lines in .c and .h files 2020-10-27 10:50:45 -04:00
rlibby
60f7ea94ea gcc: quiet Wattribute for no_sanitize("address")
This is an unfortunate instance where the __has_attribute check does
not function usefully.  Gcc does have the attribute, but for gcc it only
applies to functions, not variables, and trying to apply it to a
variable generates Wattribute.  So far we only apply the attribute to
variables.  Only enable the attribute for clang, for now.

Reviewed by:	Anton Rang <rang at acm.org>
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D22875
2020-10-27 10:50:45 -04:00
dab
baa3465cf6 Don't sanitize linker_set
The assumptions of linker_set don't play nicely with
AddressSanitizer. AddressSanitizer adds a 'redzone' of zeros around
globals (including those in named sections), whereas linker_set
assumes they are all packed consecutively like a pointer array. So:
let's annotate linker_set so that AddressSanitizer ignores it.

Submitted by:	Matthew Bryan <matthew.bryan@isilon.com>
Reviewed by:	kib, rang_acm.org
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D22239
2020-10-27 10:50:45 -04:00
jhb
d9f12d2c76 Make the system C11 atomics headers fully compatible with external GCC.
The <sys/cdefs.h> and <stdatomic.h> headers already included support for
C11 atomics via intrinsincs in modern versions of GCC, but these versions
tried to "hide" atomic variables inside a wrapper structure.  This wrapper
is not compatible with GCC's internal <stdatomic.h> header, so that if
GCC's <stdatomic.h> was used together with <sys/cdefs.h>, use of C11
atomics would fail to compile.  Fix this by not hiding atomic variables
in a structure for modern versions of GCC.  The headers already avoid
using a wrapper structure on clang.

Note that this wrapper was only used if C11 was not enabled (e.g.
via -std=c99), so this also fixes compile failures if a modern version
of GCC was used with -std=c11 but with FreeBSD's <stdatomic.h> instead
of GCC's <stdatomic.h> and this change fixes that case as well.

Reported by:	Mark Millard
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D16585
2020-10-27 10:50:45 -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
Ken Brown
f4cfd55ee0 Cygwin: AF_UNIX: improve select_printf output
Don't call get_name, which is useless.
2020-10-26 10:22:21 -04:00
Ken Brown
6afbd9bf9a Cygwin: AF_UNIX: fix MAX_AF_PKT_LEN
Define it to be UINT16_MAX, since the pckt_len member of
af_unix_pkt_hdr_t is of type uint16_t.

Previously it was 65536 (== UINT16_MAX + 1), which is 0 when cast to
uint16_t.  So an attempt to write a packet of size MAX_AF_PKT_LEN
actually wrote 0 bytes.
2020-10-26 09:13:42 -04:00
Ken Brown
fc26f2932b Cygwin: AF_UNIX: select_read: fix thinko
Don't set read_ready true if the socket is not connected.  One of the
uses of select is for a listening socket to wait for a connection
request.
2020-10-25 17:05:37 -04:00
Ken Brown
b3cef213d8 Cygwin: AF_UNIX: evaluate_cmsg_data: more FIXMEs 2020-10-24 10:48:55 -04:00
Ken Brown
408636b186 Cygwin: AF_UNIX: sendmsg: add FIXME comment 2020-10-24 10:05:17 -04:00
Ken Brown
f85a03882e Cygwin: AF_UNIX: implement evaluate_cmsg_data
And use it in recvmsg.

I'm not sure this implementation is what was intended when the
evaluate_cmsg_data method was added.

For now, just support an ancillary data block consisting of a single
cmsghdr, containing SCM_CREDENTIALS.

For convenience, add a 'mshdr *' argument and make the 'cloexec'
argument false by default.  The 'cloexec' argument is not currently
used, and I want to avoid having to artificially specify a value for
it when recvmsg calls evaluate_cmsg_data.
2020-10-24 10:00:40 -04:00
Ken Brown
9cfea13054 Cygwin: AF_UNIX: implement create_cmsg_data
For now, just support an ancillary data block consisting of a single
cmsghdr, containing SCM_CREDENTIALS.

FIXME: We're supposed to check the credentials.
2020-10-24 09:56:58 -04:00
Ken Brown via Cygwin-patches
6940081505 Cygwin: AF_INET and AF_LOCAL: recv_internal: fix MSG_WAITALL support
If MSG_WAITALL is set, recv_internal calls WSARecv or WSARecvFrom in a
loop, in an effort to fill all the scatter-gather buffers.  The test
for whether all the buffers are full was previously incorrect.
2020-10-23 08:25:29 -04:00
Ken Brown
324faf1e07 Cygwin: AF_UNIX: socketpair: fix connect state
Both sockets should have connect state 'connected', not just the
second.
2020-10-22 15:12:29 -04:00
Ken Brown
6b08c5e15d 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.
2020-10-22 14:55:52 -04:00