]> sourceware.org Git - newlib-cygwin.git/log
newlib-cygwin.git
5 years agoCygwin: posix timers: some cleanup
Corinna Vinschen [Sat, 12 Jan 2019 19:23:55 +0000 (20:23 +0100)]
Cygwin: posix timers: some cleanup

- use int64_t instead of long long
- make is_timer_tracker const
- improve copyright header comment

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: posix timers: convert timer_tracker::fixup_after_fork to static method
Corinna Vinschen [Fri, 11 Jan 2019 19:36:46 +0000 (20:36 +0100)]
Cygwin: posix timers: convert timer_tracker::fixup_after_fork to static method

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: posix timers: move definition of timer_tracker class to new timer.h
Corinna Vinschen [Fri, 11 Jan 2019 18:40:03 +0000 (19:40 +0100)]
Cygwin: posix timers: move definition of timer_tracker class to new timer.h

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: clock_nanosleep is not supposed to crash, return EFAULT instead
Corinna Vinschen [Fri, 11 Jan 2019 14:15:32 +0000 (15:15 +0100)]
Cygwin: clock_nanosleep is not supposed to crash, return EFAULT instead

...in case rqtp or rmtp specified invalid addresses.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: timer: convert timer_tracker to a real C++ class
Corinna Vinschen [Fri, 11 Jan 2019 14:13:11 +0000 (15:13 +0100)]
Cygwin: timer: convert timer_tracker to a real C++ class

...with private members and all the jazz

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: af_unix_spinlock_t: add initializer
Ken Brown [Thu, 10 Jan 2019 17:56:55 +0000 (17:56 +0000)]
Cygwin: af_unix_spinlock_t: add initializer

Also fix a typo.

5 years agoCygwin: try_to_bin: don't check recycler filename all the time
Corinna Vinschen [Wed, 9 Jan 2019 20:14:58 +0000 (21:14 +0100)]
Cygwin: try_to_bin: don't check recycler filename all the time

So far we check the recycler name all the time, and the last interation
also only managed to handle two ways to write the recycler.  However,
an adventurous user might change the case of the recycler arbitrarily.

Fix this problem by keeping track of the name in a somewhat relaxed
fashion.  Use camel back on drive C by default, all upper case elsewhere.
Only if the rename op fails do we fix the recycler name on the fly
when trying to create it, and it turns out it already existed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: try_to_bin: fix rootdir handle after reopening
Corinna Vinschen [Wed, 9 Jan 2019 20:41:48 +0000 (21:41 +0100)]
Cygwin: try_to_bin: fix rootdir handle after reopening

If the first rename fails, we reopen the rootdir for creating a subdir.
The rootdir handle can change its value at this point, but the code
doesn't take this into account.  The subsequent rename then fails with
STATUS_INVALID_HANDLE.  Fix this by copying the new rootdir value to
pfri->RootDirectory.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: rename: use FILE_RENAME_POSIX_SEMANTICS if available
Corinna Vinschen [Wed, 9 Jan 2019 14:47:43 +0000 (15:47 +0100)]
Cygwin: rename: use FILE_RENAME_POSIX_SEMANTICS if available

starting with W10 1709 on local NTFS drives

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: rename: rename incoming flags argument to at2flags
Corinna Vinschen [Wed, 9 Jan 2019 13:45:37 +0000 (14:45 +0100)]
Cygwin: rename: rename incoming flags argument to at2flags

Avoid name confusion with later used flags variable

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: try_to_bin: don't reopen the file
Corinna Vinschen [Tue, 8 Jan 2019 20:43:25 +0000 (21:43 +0100)]
Cygwin: try_to_bin: don't reopen the file

So far we reopened the file if it was opened case sensitive to
workaround the problem that the recycler could be named in
camel back or all upper case, depending on who created it.
That's a problem for O_TMPFILE on pre-W10.  As soon as the
original HANDLE gets closed, delete-on-close is converted to full
delete disposition and all useful operations on the file cease to
work (STATUS_ACCESS_DENIED or STATUS_FILE_DELETED).

To avoid that problem drop the reopen code and check for the exact
recycler filename, either $Recycle.Bin or $RECYCLE.BIN, if the file
has been opened case sensitive.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: open: workaround reopen file w/ delete disposition set
Corinna Vinschen [Tue, 8 Jan 2019 20:37:43 +0000 (21:37 +0100)]
Cygwin: open: workaround reopen file w/ delete disposition set

On pre-W10 systems there's no way to reopen a file by handle if
the delete disposition is set.  We try to get around with
duplicating the handle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: open: handle O_CLOEXEC when opening file from handle
Corinna Vinschen [Tue, 8 Jan 2019 17:50:11 +0000 (18:50 +0100)]
Cygwin: open: handle O_CLOEXEC when opening file from handle

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: fhandler_process_fd: Fix spacing
Corinna Vinschen [Tue, 8 Jan 2019 20:38:04 +0000 (21:38 +0100)]
Cygwin: fhandler_process_fd: Fix spacing

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: remove unused tmpbuf.h
Corinna Vinschen [Tue, 8 Jan 2019 17:49:29 +0000 (18:49 +0100)]
Cygwin: remove unused tmpbuf.h

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agofcntl.h: expose AT_EMPTY_PATH with _GNU_SOURCE only
Corinna Vinschen [Mon, 7 Jan 2019 19:09:20 +0000 (20:09 +0100)]
fcntl.h: expose AT_EMPTY_PATH with _GNU_SOURCE only

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: linkat: support Linux-specific AT_EMPTY_PATH flag
Corinna Vinschen [Mon, 7 Jan 2019 18:36:37 +0000 (19:36 +0100)]
Cygwin: linkat: support Linux-specific AT_EMPTY_PATH flag

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: open: support Linux-specific O_PATH flag
Corinna Vinschen [Mon, 7 Jan 2019 18:33:11 +0000 (19:33 +0100)]
Cygwin: open: support Linux-specific O_PATH flag

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: rename pipe.cc to fhandler_pipe.cc
Corinna Vinschen [Mon, 7 Jan 2019 11:31:28 +0000 (12:31 +0100)]
Cygwin: rename pipe.cc to fhandler_pipe.cc

move pipe syscalls to syscalls.cc

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: move fhandler_cygdrive methods into own source file
Corinna Vinschen [Mon, 7 Jan 2019 11:29:07 +0000 (12:29 +0100)]
Cygwin: move fhandler_cygdrive methods into own source file

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: drop redundant includes from fhandler_process_fd.cc
Corinna Vinschen [Sun, 6 Jan 2019 21:40:17 +0000 (22:40 +0100)]
Cygwin: drop redundant includes from fhandler_process_fd.cc

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: fix regression in O_TMPFILE | O_EXCL case
Corinna Vinschen [Sun, 6 Jan 2019 21:39:45 +0000 (22:39 +0100)]
Cygwin: fix regression in O_TMPFILE | O_EXCL case

The new proc fd code accidentally allowed to linkat an O_TMPFILE
even if the file has been opened with O_EXCL.  This patch fixes it.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: document proc fd changes
Corinna Vinschen [Sun, 6 Jan 2019 19:28:48 +0000 (20:28 +0100)]
Cygwin: document proc fd changes

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: introduce fhandler_process_fd and add stat(2) handling
Corinna Vinschen [Sun, 6 Jan 2019 19:18:14 +0000 (20:18 +0100)]
Cygwin: introduce fhandler_process_fd and add stat(2) handling

move special fd symlink code into own fhandler_process_fd class
to simplify further additions to /proc/PID/fd/DESCRIPTOR symlink
handling.

Add a method to handle stat(2) on such a proc fd symlink by handle.
This allows correct reply from stat(2) if the target file has been
deleted.  This eventually fixes `awk -f /dev/fd/3 3<<eof'.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: path_conv: add PATH_RESOLVE_PROCFD path_types flag
Corinna Vinschen [Sun, 6 Jan 2019 19:13:52 +0000 (20:13 +0100)]
Cygwin: path_conv: add PATH_RESOLVE_PROCFD path_types flag

path_conv now sets the PATH_RESOLVE_PROCFD flag in path_flags if
the PC_SYM_NOFOLLOW_PROCFD pathconv_arg flag has been set on input
*and* the file is actually a proc fd symlink.

Add matching path_conv::follow_fd_symlink method for checking and
use it in open(2).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: path_conv: decouple path_types from mount types
Corinna Vinschen [Sun, 6 Jan 2019 16:44:20 +0000 (17:44 +0100)]
Cygwin: path_conv: decouple path_types from mount types

- Remove another unfortunate amalgamation: Mount flags (MOUNT_xxx)
  are converted to path_types (PATH_xxx) and mixed with non-mount
  path_types flags in the same storage, leading to a tangled,
  pell-mell usage of mount flags and path flags in path_conv and
  symlink_info.

- There's also the case of PC_NONULLEMPTY.  It's used in exactly
  one place with a path_conv constructor only used in this single
  place, just to override the automatic PC_NULLEMPTY addition
  when calling the other path_conv constructors.  Crazily,
  PC_NONULLEMPTY is a define, no path_types flag, despite its
  name.

- It doesn't help that the binary flag exists as mount and path
  flag, while the text flag only exists as path flag.  This leads
  to mount code using path flags to set text/binary.  Very confusing
  is the fact that a text mount/path flag is not actually required;
  the mount code sets the text flag on non binary mounts anyway, so
  there are only two states.  However, to puzzle people a bit more,
  path_conv::binary wrongly implies there's a third, non-binary/non-text
  state.

Clean up this mess:

- Store path flags separately from mount flags in path_conv and
  symlink_info classes and change all checks and testing inline
  methods accordingly.

- Make PC_NONULLEMPTY a simple path_types flag and drop the
  redundant path_check constructor.

- Clean up the definition of pathconv_arg, path_types, and mount flags.
  Use _BIT expression, newly define in cygwin/bits.h.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: path_conv: decouple pathconv_flags from path_types
Corinna Vinschen [Sun, 6 Jan 2019 13:29:53 +0000 (14:29 +0100)]
Cygwin: path_conv: decouple pathconv_flags from path_types

There's an unfortunate amalgamation of caller-provided pathconv_arg
flags with path_types flags which in turn are mostly mount flags.

This leads to a confusion of flag values in sylink_info::pflags and,
in turn, in path_conv::path_flags.

This patch decouples pathconv_flags from the other flags by making
sure that a pathconv_flag is never copied into a variable used for
path_types flags.  Also, remove PATH_NO_ACCESS_CHECK since it's
not necessary.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: Mark all O_TMPFILEs as deleted
Corinna Vinschen [Sat, 5 Jan 2019 21:16:30 +0000 (22:16 +0100)]
Cygwin: Mark all O_TMPFILEs as deleted

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: Move O_TMPFILE to bin and allow linkat by handle
Corinna Vinschen [Sat, 5 Jan 2019 21:15:58 +0000 (22:15 +0100)]
Cygwin: Move O_TMPFILE to bin and allow linkat by handle

Along the same lines as the previous patch: By reopening an
O_TMPFILE by handle, we can now move the file to the bin at
open time and thus free'ing up the parent dir and *still*
open the file as /proc/PID/fd/DESCRIPTOR by linkat(2).

5 years agoCygwin: try_to_bin: allow to move O_TMPFILE files into bin
Corinna Vinschen [Sat, 5 Jan 2019 20:44:12 +0000 (21:44 +0100)]
Cygwin: try_to_bin: allow to move O_TMPFILE files into bin

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: implement /proc/PID/fd/DESCRIPTOR reopening by handle
Corinna Vinschen [Sat, 5 Jan 2019 21:13:42 +0000 (22:13 +0100)]
Cygwin: implement /proc/PID/fd/DESCRIPTOR reopening by handle

Allows expressions along the lines of `cat /proc/self/fd/0 <<EOF'.
The problem here is that the temporary file used for the here script
has already been deleted by the shell.  Opening by filename, as
implemented so far, doesn't work because the file has been moved
to the bin.

Allow reopening files by handle the same way from another process
as long as we have sufficient permissions on the foreign process.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: pinfo: add method to send a serialized path_conv and HANDLE
Corinna Vinschen [Sat, 5 Jan 2019 20:57:03 +0000 (21:57 +0100)]
Cygwin: pinfo: add method to send a serialized path_conv and HANDLE

To allow reopening a file open in another process by HANDLE, introduce
a matching file_pathconv method, taking a file descriptor as parameter.
The result is a serialized path_conv and a HANDLE value.  The HANDLE is
valid in the foreign process and MUST be duplicated into the target
process before usage.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: path_conv: add serialization/deserialization facility
Corinna Vinschen [Sat, 5 Jan 2019 20:50:48 +0000 (21:50 +0100)]
Cygwin: path_conv: add serialization/deserialization facility

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: path_conv: reorder private method declarations
Corinna Vinschen [Sat, 5 Jan 2019 20:51:51 +0000 (21:51 +0100)]
Cygwin: path_conv: reorder private method declarations

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: fhandler_base::open: allow to reopen file from handle
Corinna Vinschen [Sat, 5 Jan 2019 20:49:16 +0000 (21:49 +0100)]
Cygwin: fhandler_base::open: allow to reopen file from handle

So far io_handle is NULL when calling fhandler_base::open to
open or create a file.  Add a check for io_handle to allow
priming the fhandler with a HANDLE value so we can reopen a
file from a HANDLE on file systems supporting it.  This allows
to open already deleted files for further action.  This will
be used by open("/proc/PID/fd/DESCRIPTOR") scenarios.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: pipe: use /proc/PID/fd/... or /proc/self/fd/... name
Corinna Vinschen [Sat, 5 Jan 2019 20:42:33 +0000 (21:42 +0100)]
Cygwin: pipe: use /proc/PID/fd/... or /proc/self/fd/... name

Don't emit /dev/fd/... filename.  This simplifies pipe path handling
and avoids another symlink redirection.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: introduce virt_fdsymlink to simplify /proc/PID/fd symlink handling
Corinna Vinschen [Sat, 5 Jan 2019 20:41:01 +0000 (21:41 +0100)]
Cygwin: introduce virt_fdsymlink to simplify /proc/PID/fd symlink handling

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: return correct FH_PROCESSFD for files under /proc/PID/fd subdir
Corinna Vinschen [Sat, 5 Jan 2019 20:36:34 +0000 (21:36 +0100)]
Cygwin: return correct FH_PROCESSFD for files under /proc/PID/fd subdir

This allows easier handling of fd symlinks.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: try_to_bin: fix typos in comments
Corinna Vinschen [Sat, 5 Jan 2019 10:32:23 +0000 (11:32 +0100)]
Cygwin: try_to_bin: fix typos in comments

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: path_conv: nobody cares if a path had symlinks after the fact
Corinna Vinschen [Sat, 5 Jan 2019 10:31:52 +0000 (11:31 +0100)]
Cygwin: path_conv: nobody cares if a path had symlinks after the fact

remove set_has_symlinks/has_symlinks/PATH_HAS_SYMLINKS.  Nobody's
asking for this information.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: drop disabled O_TMPFILE POSIX unlink code
Corinna Vinschen [Fri, 4 Jan 2019 10:00:57 +0000 (11:00 +0100)]
Cygwin: drop disabled O_TMPFILE POSIX unlink code

The commit message of commit 07e0a9584f9a5b2668c767ede0482a5fba498731
and the expectation set therein, are wrong.

There's no POSIX semantics allowing to link a file with a link
count of 0 and making it available in the file system again.
In fact, the Linux linkat extension AT_EMPTY_PATH explicitely
disallows to link a file descriptor to a file with a link count
of 0, except for O_TMPFILE without O_EXCL.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoImprove performance of memmem
Wilco Dijkstra [Mon, 31 Dec 2018 18:01:52 +0000 (18:01 +0000)]
Improve performance of memmem

This patch significantly improves performance of memmem using a novel
modified Horspool algorithm.  Needles up to size 256 use a bad-character
table indexed by hashed pairs of characters to quickly skip past mismatches.
Long needles use a self-adapting filtering step to avoid comparing the whole
needle repeatedly.

By limiting the needle length to 256, the shift table only requires 8 bits
per entry, lowering preprocessing overhead and minimizing cache effects.
This limit also implies worst-case performance is linear.

Small needles up to size 2 use a dedicated linear search.  Very long needles
use the Two-Way algorithm (to avoid increasing stack size inlining is now disabled).

The performance gain is 6.6 times on English text on AArch64 using random
needles with average size 8 (this is even faster than the recently improved strstr
algorithm, so I'll update that in the near future).

The size-optimized memmem has also been rewritten from scratch to get a
2.7x performance gain.

Tested against GLIBC testsuite and randomized tests.

Message-Id: <DB5PR08MB1030649D051FA8532A4512C883B20@DB5PR08MB1030.eurprd08.prod.outlook.com>

5 years agoBump release to 3.1.0 for yearly snapshot newlib-3.1.0 newlib-snapshot-20181231
Jeff Johnston [Tue, 1 Jan 2019 04:40:11 +0000 (23:40 -0500)]
Bump release to 3.1.0 for yearly snapshot

5 years agoCygwin: open(2): Change comment in disabled O_TMPFILE POSIX unlink code
Corinna Vinschen [Wed, 26 Dec 2018 20:51:13 +0000 (21:51 +0100)]
Cygwin: open(2): Change comment in disabled O_TMPFILE POSIX unlink code

- Turns out, the definition of POSIX unlink semantics is half-hearted
  so far: It's not possible to link an open file HANDLE if it has
  been deleted with POSIX semantics, nor is it possible to remove
  the delete disposition.  This breaks linkat on an O_TMPFILE.

  Tested with W10 1809.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: Change /proc/$PID/fd/<fd> symlink target for deleted files
Corinna Vinschen [Wed, 26 Dec 2018 20:22:40 +0000 (21:22 +0100)]
Cygwin: Change /proc/$PID/fd/<fd> symlink target for deleted files

- As on Linux, print the file name with an attached " (deleted)"

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: Add Christmas hacking release notes
Corinna Vinschen [Wed, 26 Dec 2018 10:36:22 +0000 (11:36 +0100)]
Cygwin: Add Christmas hacking release notes

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: Add documentation for chattr and lsattr
Corinna Vinschen [Wed, 26 Dec 2018 10:22:06 +0000 (11:22 +0100)]
Cygwin: Add documentation for chattr and lsattr

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: Add lsattr and chattr tools
Corinna Vinschen [Tue, 25 Dec 2018 22:39:11 +0000 (23:39 +0100)]
Cygwin: Add lsattr and chattr tools

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: Add FS_IOC_GETFLAGS and FS_IOC_SETFLAGS ioctls
Corinna Vinschen [Tue, 25 Dec 2018 22:38:52 +0000 (23:38 +0100)]
Cygwin: Add FS_IOC_GETFLAGS and FS_IOC_SETFLAGS ioctls

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: mkdir: create case-sensitive dirs
Corinna Vinschen [Tue, 25 Dec 2018 00:09:12 +0000 (01:09 +0100)]
Cygwin: mkdir: create case-sensitive dirs

On Windows 10 1803 and later, create dirs under the Cygwin
installation dir as case sensitive, if WSL is installed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: wincap: add wincap_10_1803, add has_case_sensitive_dirs item
Corinna Vinschen [Tue, 25 Dec 2018 00:07:39 +0000 (01:07 +0100)]
Cygwin: wincap: add wincap_10_1803, add has_case_sensitive_dirs item

- Allow to disable the flag by calling disable_case_sensitive_dirs.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: cygheap: convert installation paths to UNICODE_STRINGS
Corinna Vinschen [Tue, 25 Dec 2018 00:06:34 +0000 (01:06 +0100)]
Cygwin: cygheap: convert installation paths to UNICODE_STRINGS

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: utilize FILE_DISPOSITION_POSIX_SEMANTICS
Corinna Vinschen [Sun, 23 Dec 2018 20:36:42 +0000 (21:36 +0100)]
Cygwin: utilize FILE_DISPOSITION_POSIX_SEMANTICS

- short-circuit most code in unlink_nt since it's not necessary
  anymore if FILE_DISPOSITION_POSIX_SEMANTICS is supported.

- Immediately remove O_TMPFILE from filesystem after creation.
  Disable code for now because we have to implement /proc/self/fd
  opening by handle first, lest linkat fails.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: support exFAT and fix remote FAT/FAT32 recognition
Corinna Vinschen [Sun, 23 Dec 2018 16:53:55 +0000 (17:53 +0100)]
Cygwin: support exFAT and fix remote FAT/FAT32 recognition

Newer FAT32 and exFAT add FILE_SUPPORTS_ENCRYPTION to their
flags which wasn't handled by Cygwin yet.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: wincap: add wincap_10_1709, add has_posix_file_info item
Corinna Vinschen [Sat, 22 Dec 2018 23:21:21 +0000 (00:21 +0100)]
Cygwin: wincap: add wincap_10_1709, add has_posix_file_info item

Various new file info class members adding important POSIX semantics
have been added with W10 1709.  We may want to utilize them, so add
a matching wincaps.

Rearrange checking the W10 build number to prefer the latest builds
over the older builds.  Rename wincap_10 to wincap_10_1507 for
enhanced clarity.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: ntdll.h: Update _FILE_INFORMATION_CLASS
Corinna Vinschen [Sat, 22 Dec 2018 23:17:34 +0000 (00:17 +0100)]
Cygwin: ntdll.h: Update _FILE_INFORMATION_CLASS

- Add missing members added in later OS versions
- Rearrange accompanying FILE_foo_INFORMATION structs
  ordered by info class
- Add promising FILE_foo_INFORMATION structs of later
  Windows 10 releases plus accompanying enums
- Drop "Checked on 64 bit" comments since that's self-evident
  these days

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoRTEMS: Use __uint64_t for __ino_t
Sebastian Huber [Thu, 20 Dec 2018 09:55:28 +0000 (10:55 +0100)]
RTEMS: Use __uint64_t for __ino_t

FreeBSD uses a 64-bit ino_t since 2017-05-23.  We need this for the
pipe() support in libbsd.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
5 years agoPlug routing sysctl leaks.
markj [Mon, 26 Nov 2018 13:42:18 +0000 (13:42 +0000)]
Plug routing sysctl leaks.

Various structures exported by sysctl_rtsock() contain padding fields
which were not being zeroed.

Reported by: Thomas Barabosch, Fraunhofer FKIE
Reviewed by: ae
MFC after: 3 days
Security: kernel memory disclosure
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D18333

5 years agoCygwin: fix heap allocation on WOW64 and /3GB enabled 32 bit machines
Corinna Vinschen [Wed, 19 Dec 2018 20:10:37 +0000 (21:10 +0100)]
Cygwin: fix heap allocation on WOW64 and /3GB enabled 32 bit machines

The check for the TEB being allocated beyond the first 2GB area is not
valid anymore.  At least on W10 WOW64, the TEB is allocated in the
lower 2GB even in large-address aware executables.  Use VirtualQuery
instead.  It fails for invalid addresses so that's a simple enough test.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agonano-vfprintf_float.c: Fix check if negative for nans.
Jon Beniston [Tue, 11 Dec 2018 21:03:03 +0000 (21:03 +0000)]
nano-vfprintf_float.c: Fix check if negative for nans.

5 years agoFix powf overflow handling in non-nearest rounding mode
Szabolcs Nagy [Mon, 10 Dec 2018 14:40:01 +0000 (14:40 +0000)]
Fix powf overflow handling in non-nearest rounding mode

The threshold value at which powf overflows depends on the rounding mode
and the current check did not take this into account. So when the result
was rounded away from zero it could become infinity without setting
errno to ERANGE.

Example: pow(0x1.7ac7cp+5, 23) is 0x1.fffffep+127 + 0.1633ulp

If the result goes above 0x1.fffffep+127 + 0.5ulp then errno is set,
which is fine in nearest rounding mode, but

  powf(0x1.7ac7cp+5, 23) is inf in upward rounding mode
  powf(-0x1.7ac7cp+5, 23) is -inf in downward rounding mode

and the previous implementation did not set errno in these cases.

The fix tries to avoid affecting the common code path or calling a
function that may introduce a stack frame, so float arithmetics is used
to check the rounding mode and the threshold is selected accordingly.

5 years agosys/time.h: Remove KASSERT
Sebastian Huber [Tue, 4 Dec 2018 06:34:25 +0000 (07:34 +0100)]
sys/time.h: Remove KASSERT

The KASSERT is only used by the FreeBSD kernel.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
5 years agoEnsure that all values of ns, us and ms work
imp [Tue, 20 Nov 2018 07:11:23 +0000 (07:11 +0000)]
Ensure that all values of ns, us and ms work

for {n,u,m}stosbt

Integer overflows and wrong constants limited the accuracy of these
functions and created situatiosn where sbttoXs(Xstosbt(Y)) != Y. This
was especailly true in the ns case where we had millions of values
that were wrong.

Instead, used fixed constants because there's no way to say ceil(X)
for integer math. Document what these crazy constants are.

Also, use a shift one fewer left to avoid integer overflow causing
incorrect results, and adjust the equasion accordingly. Document this.

Allow times >= 1s to be well defined for these conversion functions
(at least the Xstosbt). There's too many users in the tree that they
work for >= 1s.

This fixes a failure on boot to program firmware on the mlx4
NIC. There was a msleep(1000) in the code. Prior to my recent rounding
changes, msleep(1000) worked, but msleep(1001) did not because the old
code rounded to just below 2^64 and the new code rounds to just above
it (overflowing, causing the msleep(1000) to really sleep 1ms).

A test program to test all cases will be committed shortly. The test
exaustively tries every value (thanks to bde for the test).

Sponsored by: Netflix, Inc
Differential Revision: https://reviews.freebsd.org/D18051

5 years agoWhen converting ns,us,ms to sbt, return the ceil()
imp [Thu, 15 Nov 2018 16:02:13 +0000 (16:02 +0000)]
When converting ns,us,ms to sbt, return the ceil()

of the result rather than the floor(). Returning the floor means that
sbttoX(Xtosbt(y)) != y for almost all values of y. In practice, this
results in a difference of at most 1 in the lsb of the sbintime_t. This
difference is meaningless for all current users of these functions, but
is important for the newly introduced sysctl conversion routines which
implicitly rely on the transformation being idempotent.

Sponsored by: Netflix, Inc

5 years agoCorrect a misplaced closing paren.
ian [Sat, 3 Mar 2018 22:28:20 +0000 (22:28 +0000)]
Correct a misplaced closing paren.

Does not affect the result, but does clarify (at least for me) that the
multiplication happens before the shift.

5 years agosys: further adoption of SPDX licensing ID tags.
pfg [Mon, 20 Nov 2017 19:43:44 +0000 (19:43 +0000)]
sys: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.

5 years agoAdd inline functions to convert between sbintime_t
ian [Sat, 29 Jul 2017 17:00:23 +0000 (17:00 +0000)]
Add inline functions to convert between sbintime_t

and decimal time units. Use them in some existing code that is
vulnerable to roundoff errors.

The existing constant SBT_1NS is a honeypot, luring unsuspecting folks into
writing code such as long_timeout_ns*SBT_1NS to generate the argument for a
sleep call.  The actual value of 1ns in sbt units is ~4.3, leading to a
large roundoff error giving a shorter sleep than expected when multiplying
by the trucated value of 4 in SBT_1NS.  (The evil honeypot aspect becomes
clear after you waste a whole day figuring out why your sleeps return early.)

5 years agoRenumber copyright clause 4
imp [Tue, 28 Feb 2017 23:42:47 +0000 (23:42 +0000)]
Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96

5 years agoCygwin: mkvers: fix a bug in sed statement
Corinna Vinschen [Sat, 1 Dec 2018 15:50:40 +0000 (16:50 +0100)]
Cygwin: mkvers: fix a bug in sed statement

While reformatting the script, backticks `` were replaced with
brackets $().  This in turn invalidated the \\( ... \\) expressions in the
sed script because backslash resolution in $() works differently from
backslash resolution in ``.  Only a single backslash is valid now.

While at it, fix up the uname(2) date representation when building a
snapshot.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: clocks: fix a hang on pre-Windows 10 machines
Corinna Vinschen [Fri, 30 Nov 2018 21:39:57 +0000 (22:39 +0100)]
Cygwin: clocks: fix a hang on pre-Windows 10 machines

when calling clocks too early in DLL init, the vtables are not correctly
set up for some reason.  Calls to init() from now() fail because the init
pointer in the vtable is NULL.

Real life example is mintty which runs into a minor problem at startup,
triggering a system_printf call.  Strace is another problem, it's called
the first time prior to any class initialization.

Workaround is to make sure that no virtual methods are called in an
early stage.  Make init() non-virtual and convert resolution() to a
virtual method instead.  Add a special non-virtual
clk_monotonic_t::strace_usecs.

While at it:

- Inline internal-only methods.

- Drop the `inited' member.  Convert period/ticks_per_sec toa union.
  Initialize period/ticks_per_sec via InterlockeExchange64.

- Fix GetTickCount64 usage.  No, it's not returning ticks but
  milliseconds since boot (unbiased).

- Fix comment indentation.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agofix version typo
Mark Geisert [Sat, 1 Dec 2018 06:14:00 +0000 (22:14 -0800)]
fix version typo

5 years agoCygwin: clocks: use either tickcount or tick period
Corinna Vinschen [Thu, 29 Nov 2018 11:56:18 +0000 (12:56 +0100)]
Cygwin: clocks: use either tickcount or tick period

Use whatever native unit the system provides for the resolution of
a timer to avoid rounding problems

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agostdio.h: Expose cuserid with __GNU_VISIBLE
Corinna Vinschen [Thu, 29 Nov 2018 10:22:42 +0000 (11:22 +0100)]
stdio.h: Expose cuserid with __GNU_VISIBLE

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: document latest changes
Corinna Vinschen [Thu, 29 Nov 2018 10:12:05 +0000 (11:12 +0100)]
Cygwin: document latest changes

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: implement extensible clock interface
Corinna Vinschen [Tue, 27 Nov 2018 12:47:02 +0000 (13:47 +0100)]
Cygwin: implement extensible clock interface

- Drop hires_[nm]s clocks, rename hires.h to clock.h.

- Implement clk_t class as an extensible clock class in new file clock.cc.

- Introduce get_clock(clock_id) returning a pointer to the clk_t instance
  for clock_id.  Provide the following methods along the lines of the former
  hires classes:

void clk_t::nsecs (struct timespec *);
ULONGLONG clk_t::nsecs ();
LONGLONG clk_t::usecs ();
LONGLONG clk_t::msecs ();
void  clk_t::resolution (struct timespec *);

- Add CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE
  and CLOCK_BOOTTIME clocks.

- Allow clock_nanosleep, pthread_condattr_setclock and timer_create to use
  all new clocks (both clocks should be usable with a small tweak, though).

- Bump DLL major version to 2.12.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agotime.h: Introduce Linux-specific CLOCK id values
Corinna Vinschen [Wed, 28 Nov 2018 21:49:30 +0000 (22:49 +0100)]
time.h: Introduce Linux-specific CLOCK id values

- Add CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_RAW,
  CLOCK_MONOTONIC_COARSE and CLOCK_BOOTTIME

- Guard new values with __GNU_VISIBLE

- Add CLOCK_REALTIME_COARSE as (clockid_t) 0 for simplicity
  (It allows to have all values < 8 and so be used as array
   index into an array of clocks)

- Fix macro bracketing

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: timers: clock_setres: make no-op
Corinna Vinschen [Tue, 27 Nov 2018 12:59:37 +0000 (13:59 +0100)]
Cygwin: timers: clock_setres: make no-op

clock_setres is a questionable function only existing on QNX.
Disable the function, just return success for CLOCK_REALTIME
to maintain backward compatibility.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: pthread_cond_timedwait: make sure to wait until abstime finishes
Corinna Vinschen [Wed, 28 Nov 2018 22:49:59 +0000 (23:49 +0100)]
Cygwin: pthread_cond_timedwait: make sure to wait until abstime finishes

5 years agoCygwin: timers: use spinlock to prime hires_ns thread-safe
Corinna Vinschen [Mon, 26 Nov 2018 16:47:53 +0000 (17:47 +0100)]
Cygwin: timers: use spinlock to prime hires_ns thread-safe

The current method to make hires_ns priming thread-safe isn't
thread-safe.  Rather than hoping that running the thread in
TIME_CRITICAL priority is doing the right thing, use a spinlock.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: timers: drop error handling for Windows perf timer functions
Corinna Vinschen [Mon, 26 Nov 2018 16:38:15 +0000 (17:38 +0100)]
Cygwin: timers: drop error handling for Windows perf timer functions

Per MSDN, the perf timer functions always succeed on Windows XP or
later.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: timers: Simplify hires_ms and hires_ns
Corinna Vinschen [Mon, 26 Nov 2018 16:24:35 +0000 (17:24 +0100)]
Cygwin: timers: Simplify hires_ms and hires_ns

Drop hires_base and move inited into hires_ns.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: spinlock: remove useless get_ll call
Corinna Vinschen [Mon, 26 Nov 2018 16:25:47 +0000 (17:25 +0100)]
Cygwin: spinlock: remove useless get_ll call

LARGE_INTEGER has QuadPart anyway, no reason to compute the
64 bit value from HighPart and LowPart.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoBuiltin enable return code with SYS_EXIT_EXTENDED
Matthew Malcomson [Fri, 16 Nov 2018 11:45:48 +0000 (11:45 +0000)]
Builtin enable return code with SYS_EXIT_EXTENDED

A previous commit introduced the ability to use the semi-hosting
SYS_EXIT_EXTENDED operation to libgloss, this commit adds the same
ability to the sys/arm/ backend so that building newlib only will
provide the same capabilities.

5 years agoAdd libgloss install-pdf and install-html targets.
Jim Wilson [Mon, 19 Nov 2018 23:27:05 +0000 (15:27 -0800)]
Add libgloss install-pdf and install-html targets.

The toplevel makefile used by binutils/gcc/newlib/etc has install-pdf and
install-html targets, but they fail because libgloss doesn't support them.
Tested with an arm-eabi combined tree build and install, and verifying that
the install-pdf and install-html targets now work, and that the pdf and html
doc files are now in the install tree.

libgloss/
* Makefile.in (install-html, install-pdf): New.
* doc/Makefile.in (htmldir, pdfdir): New.
(porting.ps): Delete white space on blank line.
(install-pdf, install-html): New.

5 years agoEnable return code with semi-hosting SYS_EXIT_EXTENDED
Matthew Malcomson [Fri, 16 Nov 2018 11:45:48 +0000 (11:45 +0000)]
Enable return code with semi-hosting SYS_EXIT_EXTENDED

The _exit function currently passes -1 as a "sig" to the _kill function as an
invalid signal number so that _kill can distinguish between an abort and a
standard exit.

For boards using the SYS_EXIT_EXTENDED semi-hosting operation to return a
status code, this means that the "status" paramter to _exit is ignored and the
return code is always -1.
https://developer.arm.com/docs/100863/latest/semihosting-operations/sys_exit_extended-0x20

This patch puts shared code between _kill and _exit into a new function
_kill_shared that takes the semi-hosting "reason" to use (if semi-hosting is
available) as an argument.

For semi-hosting _kill_shared provides that "reason".

Without the "sig" argument being used to distinguish between a normal and
abnormal exit, the _exit function can provide the return code to be used if the
SYS_EXIT_EXTENDED operation is available.

Hence the exit code can be returned.

5 years agoFix issue with dst bias in memset
Wilco Dijkstra [Thu, 8 Nov 2018 15:50:42 +0000 (15:50 +0000)]
Fix issue with dst bias in memset

This patch fixes an issue in the previous memset loop change. If the
zva size is >= 256 and there are more than 64 bytes left in the
tail, we could enter the loop and thus need to rebias dst by 32 as
well.

Since no known CPUs use this size this can't be tested natively, so I've
tested it on a simulator initialized with a large zva size.

--

5 years agoCygwin: Bump DLL version to 2.11.3
Corinna Vinschen [Thu, 8 Nov 2018 14:31:25 +0000 (15:31 +0100)]
Cygwin: Bump DLL version to 2.11.3

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoFix v850 target for RTEMS cygwin-2_11_2-release
Sebastian Huber [Wed, 7 Nov 2018 13:59:19 +0000 (14:59 +0100)]
Fix v850 target for RTEMS

Do not define __ATTRIBUTE_IMPURE_PTR__ for RTMES on the v850 target.
The previous definition lead to the following linker error in
combination with -fdata-sections:

relocation truncated to fit: R_V810_GPWLO_1 against symbol
`_global_impure_ptr' defined in .rodata._global_impure_ptr section in
libc.a(lib_a-impure.o)

relocation truncated to fit: R_V810_GPWLO_1 against symbol `_impure_ptr'
defined in .data._impure_ptr section in libc.a(lib_a-impure.o)

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
5 years agoRTEMS: Avoid <machine/param.h> in <sys/_cpuset.h>
Sebastian Huber [Thu, 8 Nov 2018 08:33:13 +0000 (09:33 +0100)]
RTEMS: Avoid <machine/param.h> in <sys/_cpuset.h>

The <machine/param.h> header file exposes some unrelated stuff not
covered by C or POSIX.  Avoid its use in <sys/_cpuset.h> since it is
included in <rtems.h>.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
5 years agoAdjust writeback in non-zero memset
Wilco Dijkstra [Tue, 6 Nov 2018 14:42:10 +0000 (14:42 +0000)]
Adjust writeback in non-zero memset

This fixes an ineffiency in the non-zero memset.  Delaying the writeback
until the end of the loop is slightly faster on some cores - this shows
~5% performance gain on Cortex-A53 when doing large non-zero memsets.

Tested against the GLIBC testsuite.

5 years agoCygwin: honor SOCK_NONBLOCK/SOCK_CLOEXEC in socket(2)/socketpair(2)
Corinna Vinschen [Mon, 5 Nov 2018 20:02:22 +0000 (21:02 +0100)]
Cygwin: honor SOCK_NONBLOCK/SOCK_CLOEXEC in socket(2)/socketpair(2)

fhandler_socket_wsock::set_socket_handle calls set_flags after
setting the O_NONBLOCK/O_CLOEXEC flags, thus overwriting them.

It also turns out that fhandler_socket_wsock::init_events is called
too late.  The inheritence flags are changed before creating the
socket event handling objects.  Thus, inheritence flags for
those objects are wrong with SOCK_CLOEXEC.

Fix this by reordering the calls and setting the file flags through
fhandler_base::set_flags.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agonewlib/configure.host: Set have_init_fini to no for OpenRISC
Stafford Horne [Fri, 2 Nov 2018 22:00:02 +0000 (07:00 +0900)]
newlib/configure.host: Set have_init_fini to no for OpenRISC

The new GCC port for OpenRISC will use the init_fini_array only and not
provide the init() and fini() functions.  Disable the function usage by
default as its no longer needed.

Signed-off-by: Stafford Horne <shorne@gmail.com>
5 years agoInitialize SVE system registers.
Tamar Christina [Fri, 26 Oct 2018 09:18:17 +0000 (10:18 +0100)]
Initialize SVE system registers.

This patch initializes the SVE system registers if available
and initializes the vector length to the maximum supported.

This is done according to the SVE specification [1].

[1] https://developer.arm.com/docs/ddi0584/latest/arm-architecture-reference-manual-supplement-the-scalable-vector-extension-sve-for-armv8-a

5 years agoCygwin: fix memory corruption/SEGV if certain socket functions fail
Corinna Vinschen [Mon, 29 Oct 2018 15:12:54 +0000 (16:12 +0100)]
Cygwin: fix memory corruption/SEGV if certain socket functions fail

Regression introduced with 2.11.0:

The failure paths in socket, socketpair and accept4 functions and
methods accidentally release *unused* cygheap_fdmanip objects.  The
subsequently called dtable::release method was designed to be called for
*used* cygheap_fdmanip objects only.  Using them on unused objects leads
to NULL pointer member dereferencing.

Worse, the inet/local accept4 methods only release the cygheap_fdmanip
object but neglect to delete the just created fhandler_socket_* object.

Fix this by removing the erroneous release calls in the aforementioned
failure paths and delete the fhandler_socket_* object in accept4 instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
5 years agoCygwin: Fix cygheap corruption caused by cloned atomic buffer
David McFarland [Sun, 28 Oct 2018 19:22:44 +0000 (16:22 -0300)]
Cygwin: Fix cygheap corruption caused by cloned atomic buffer

The fhandler_base_overlapped::copyto clears atomic_write_buf on the
clone, but none of the derived classes were doing this.  This allowed
the destructor to double-free the buffer and corrupt cygheap.
Clear atomic_write_buf in copyto of all derived classes.

5 years agoFix posix_memalign() attributes
Sebastian Huber [Mon, 22 Oct 2018 09:23:15 +0000 (11:23 +0200)]
Fix posix_memalign() attributes

The malloc, alloc_size and alloc_aligned attributes must be only used in
case the function returns the pointer to the allocated memory.

See also:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87683

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
5 years agoRTEMS: Use function and data sections
Sebastian Huber [Mon, 8 Oct 2018 12:29:08 +0000 (14:29 +0200)]
RTEMS: Use function and data sections

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
5 years agonewlib/libc/sys/rtems/include/machine/param.h: Add _KERNEL to stop method leakage
Joel Sherrill [Thu, 18 Oct 2018 22:19:50 +0000 (17:19 -0500)]
newlib/libc/sys/rtems/include/machine/param.h: Add _KERNEL to stop method leakage

The following FreeBSD kernel methods are not in any standard and
prototypes/definitions were leaking into application space:

  + round_page()
  + trunc_page()
  + atop()
  + ptoa()
  + pgtok()

5 years agoImprove performance of strstr
Wilco Dijkstra [Thu, 18 Oct 2018 17:29:36 +0000 (17:29 +0000)]
Improve performance of strstr

v3: Add support for read ahead using strnlen, giving an additional 25% speedup
on large inputs (both short and long needles).

This patch significantly improves performance of strstr by using Sunday's
Quick-Search algorithm.  Due to its simplicity it has the best average
performance of string matching algorithms on almost all inputs.  It uses a
bad-character shift table to skip past mismatches.

The needle length is limited to 254 - this reduces the shift table memory
4 to 8 times, lowering preprocessing overhead and minimizing cache effects.
The limit also implies its worst-case performance is linear.

Larger needles are processed by the Two-Way algorithm.  The macro AVAILABLE
has been improved to use strnlen to read the input in chunks.  This results
in a 2.5 times speedup for large needles, reducing the performance drop when
the Quick-Search algorithm can't be used.

The code for 1-4 byte needles has been simplified and now uses unsigned
char.  Since the optimized code relies on 8-bit chars, we defer to the
size-optimized implementation if CHAR_BIT > 8.

The performance gain of finding a set of randomly chosen words of size 8 in
256 bytes of English text is 14 times on AArch64. For longer haystacks the
gain is well over 20 times.

The size-optimized strstr has also been rewritten from scratch to improve
performance.  On the same test the performance gain is 69%.

Tested against GLIBC testsuite, randomized tests and the GNULIB strstr test
(https://git.savannah.gnu.org/cgit/gnulib.git/tree/tests/test-strstr.c).

--

5 years agonewlib/libc/ctype/jp2uc.c: Declare "cs" variable as "const char *"
Christophe Lyon [Fri, 5 Oct 2018 09:11:05 +0000 (09:11 +0000)]
newlib/libc/ctype/jp2uc.c: Declare "cs" variable as "const char *"

Instead of "char *" to avoid compiler warnings.
This is OK because "cs" is only used as input of strcmp.

This page took 0.078455 seconds and 5 git commands to generate.