Commit Graph

3152 Commits

Author SHA1 Message Date
Kito Cheng 654398db84 RISC-V: Fix header guard for sys/fenv.h 2019-08-02 09:34:39 +02:00
Joel Sherrill 3e5302714f common/math_errf.c: Enable compilation of __math_oflowf
This resolved linking errors when using methods such as
	expm1().
2019-07-26 14:54:29 -05:00
Ken Brown dea3d8c73e hash.c: #include <reent.h>
This is needed for the prototypes of _stat64 and _fstat64 on Cygwin.

Fixes: commit 279805b2 "hash functions: use reentrant stat functions".
2019-07-26 13:06:12 -04:00
Richard Earnshaw 65416cca7e [arm] remove libc/sys/arm/sys/param.h
The Arm sys/param.h does not define anything differently to the
generic sys/param.h, but fails to define some things that that file
provides.  There does not appear to be any reason to keep this version
and we should revert to using the common version.
2019-07-26 16:13:30 +01:00
Vaibhav Gupta b39cd00f07 Port ndbm - Remove Declaration of dbm_forder 2019-07-25 15:28:32 +02:00
Corinna Vinschen 279805b20b hash functions: use reentrant stat functions
_stat64 and _fstat64 are not exported from Cygwin.  Use the
reentrant analogues, like everywhere else.

Signed-off-by: Corinna Vinschen <corinna-cygwin@cygwin.com>
2019-07-24 22:32:48 +02:00
Corinna Vinschen 280b21d373 Regenerate newlib/libc/search/Makefile.in for ndpm port
Signed-off-by: Corinna Vinschen <corinna-cygwin@cygwin.com>
2019-07-24 18:49:11 +02:00
uchan-nos 9cde02051e fix compile errors for efgcvt.c 2019-07-24 11:58:21 +02:00
Vaibhav Gupta e50ad9fbdc Port ndbm 2019-07-24 09:19:40 +02:00
Alexander Fedotov 942f60d714 Stack Pointer and Stack Limit initialization refactored.
SP initialization changes:
  1. set default value in semihosting case as well
  2. moved existing SP & SL init code for processor modes in separate routine and made it as "hook"
  3. init SP for processor modes in Thumb mode as well

Add new macro FN_RETURN, FN_EH_START and FN_EH_END.
2019-07-23 10:00:06 +02:00
Jeff Johnston 0d24a86822 Set errno in expm1{,f} / log1p{,f}
2019-07-09  Joern Rennecke  <joern.rennecke@riscy-ip.com>

	* libm/common/s_expm1.c ("math_config.h"): Include.
	(expm1): Use __math_oflow to set errno.
	* libm/common/s_log1p.c ("math_config.h"): Include.
	(log1p): Use __math_divzero and __math_invalid to set errno.
	* libm/common/sf_expm1.c ("math_config.h"): Include.
	(expm1f): Use __math_oflow to set errno.
	* libm/common/sf_log1p.c ("math_config.h"): Include.
	(log1pf): Use __math_divzero and __math_invalid to set errno.
2019-07-09 13:06:59 -04:00
Corinna Vinschen 383e19ca55 sched: Move Cygwin cpuset definitions into Cygwin-specific header
This avoids build breakage on RTEMS.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-06-27 20:19:31 +02:00
Martin Erik Werner 739e89cbe6 or1k: Avoid write outside setjmp buf & shrink buf
Update the offsets used to save registers into the stejmp jmp_buf
structure in order to:

* Avoid writing the supervision register outside the buffer and thus
  clobbering something on the stack. Previously the supervision register
  was written at offset 124 while the buffer was of length 124.

* Shrink the jmp_buf down to the size actually needed, by avoiding holes
  at the locations of omitted registers.
2019-06-27 12:51:54 +02:00
Martin Erik Werner 8b080534ca or1k: Correct longjmp return value
Invert equality check instruction to correct the return value handling
in longjmp.

The return value should be the value of the second argument to longjmp,
unless the argument value was 0 in which case it should be 1.

Previously, longjmp would set return value 1 if the second argument was
non-zero, and 0 if it was 0, which was incorrect.
2019-06-27 09:09:37 +02:00
Jozef Lawrynowicz 301facfb60 Support calculation of pointer size for __int20__ type in _intsup.h
GCC r272640 modifies the MSP430 target to use "__int20__" for
PTRDIFF_TYPE (and therefore INTPTR_TYPE) instead of "__int20".

To support the calculation of pointer size in
newlib/libc/include/sys/_intsup.h, definitions for __int20__ need to be
added.
2019-06-25 13:37:16 -04:00
Mark Geisert 641ecb0753 Cygwin: Implement sched_[gs]etaffinity()
This patch set implements the Linux syscalls sched_getaffinity,
sched_setaffinity, pthread_getaffinity_np, and pthread_setaffinity_np.
Linux has a straightforward view of the cpu sets used in affinity masks.
They are simply long (1024-bit) bit masks.  This code emulates that view
while internally dealing with Windows' distribution of available CPUs among
processor groups.
2019-06-24 09:18:14 +02:00
Corinna Vinschen ad101bcb0f Rename <xlocale.h> back to <sys/_locale.h>
libX11 provides <X11/Xlocale.h>.  The build of libX11 itself adds
include/X11 to the compiler's include path.  This results in a name
collision with /usr/include/xlocale.h on case-insensitive filesystems.

Commit 90e35b1eb3 renamed sys/_locale.h to xlocale.h in March 2017 under
the assumption that we should provide the locale_t type in the same file
as on Linux, FreeBSD, and Darwin.

A few weeks later (June 2017), glibc removed the xlocale.h file in favor
of bits/types/locale_t.h, which shouldn't be included directly anyway.

For reference and the reasoning, see
https://sourceware.org/git/?p=glibc.git;a=commit;h=f0be25b6336d

Given the above, revert 90e35b1eb3 and
fix additional usage of xlocale.h.
2019-06-14 10:02:08 +02:00
Jeff Johnston eb429ad509 Fix __getreent stack calculations for AMD GCN
From: Andrew Stubbs <ams@codesourcery.com>

Fix a bug in which the high-part of 64-bit values are being corrupted, leading
to erroneous stack overflow errors. The problem was only that the mixed-size
calculations are being treated as signed when they should be unsigned.
2019-06-07 13:57:45 -04:00
Jeff Johnston 007bc1923c Add gfortran support for AMD GCN
From: Kwok Cheung Yeung <kcy@codesourcery.com>

This patch adds enough support for constructors/destructors and OS functions
to be able to link and run gfortran programs on AMD GCN.

There's no actual ability to do I/O operations on this targets, besides
"write" to stdout and stderr, so most of the functions are just stubs.
2019-06-07 13:55:43 -04:00
trasz 4feb21d705 Mark inline functions with __unused;
prevents compiler warning when they end up being unused.

Reviewed by:	kib
Obtained from:	OpenBSD
MFC after:	2 weeks
Sponsored by:	Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D20185
2019-06-07 09:13:13 +02:00
pfg 160f9f0bf2 sys/sys: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

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.
2019-06-07 09:11:15 +02:00
Lucio Andrés Illanes Albornoz d5daede26c Fix vfwscanf(3) assignment suppression flag handling bug
newlib's vfwscanf(3) (or specifically, __SVFWSCANF_R()) fails to correctly set
the assignment-suppressing character (`*') flag[1] which, when present in the
formatting string, results in undefined behaviour comprising retrieving and
dereferencing a pointer that was not supplied by the caller as such or at all.
When compared to the vfscanf(3) implementation, this would appear to be over
the missing goto match_failure statement preceded by the flags test seen below.
Hence, this patch (re)introduces it.

[1] <http://pubs.opengroup.org/onlinepubs/009695399/functions/fwscanf.html>

--
2019-06-03 10:38:40 +02:00
Sebastian Huber f5a5a23ea8 Fix <sys/_types.h> issues with <stddef.h>
A commit from 2016 tried to address this GCC provided <stddef.h> issue

    #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
      || defined(__DragonFly__) \
      || defined(__FreeBSD_kernel__)
    /* __size_t is a typedef on FreeBSD 5, must not trash it. */
    #elif defined (__VMS__)
    /* __size_t is also a typedef on VMS.  */
    #else
    #define __size_t
    #endif

with an include of <stddef.h> before <sys/_types.h> in <sys/types.h>.
Is is not robust enough.  Do the include of <stddef.h> in <sys/_types.h>
directly and request only the necessary types.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-06-03 10:20:15 +02:00
Sebastian Huber 86809750bb Avoid <sys/cdefs.h> dependency in <sys/_types.h>
Including <sys/cdefs.h> could result in cyclic header dependencies.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-06-03 10:20:15 +02:00
Sebastian Huber 66e75b6961 Avoid cyclic header dependencies
RTEMS uses a considerable part of FreeBSD kernel and user space sources.
These sources are compiled with a __FreeBSD__ define.  On 2018-06-26
Gerald Pfeifer changed the GCC provided <stddef.h> so that it includes
<sys/_types.h> if __FreeBSD__ is defined.  The Newlib <sys/_types.h>
included <sys/lock.h> which includes <sys/cdefs.h> on RTEMS which
includes <stddef.h>.  To get rid of this cyclic dependency move the
optional _flock_t definition to <sys/reent.h>.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-06-03 10:20:15 +02:00
Jim Wilson 5c86f0da5f RISC-V: Add size optimized memcpy, memmove, memset and strcmp.
This patch adds implementations of memcpy, memmove, memset and strcmp
optimized for size. The changes have been tested in
riscv/riscv-gnu-toolchain by riscv-dejagnu with
riscv-sim.exp/riscv-sim-nano.exp.
2019-05-22 17:36:57 -07:00
Jozef Lawrynowicz 1e6c561d48 Implement reduced code size "tiny" printf and puts
"tiny" printf is derived from _vfprintf_r in libc/stdio/nano-vfprintf.c.
"tiny" puts has been implemented so that it just calls write, without
any other processing.
Support for buffering, reentrancy and streams has been removed from
these functions to achieve reduced code size.

This reduced code size implementation of printf and puts can be enabled
in an application by passing "--wrap printf" and "--wrap puts" to the
GNU linker. This will replace references to "printf" and "puts" in user
code with "__wrap_printf" and "__wrap_puts" respectively.
If there is no implementation of these __wrap* functions in user code,
these "tiny" printf and puts implementations will be linked into the
final executable.

The wrapping mechanism is supposed to be invisible to the user:
- A GCC wrapper option such as "-mtiny-printf" will be added to alias
  these wrap commands.
- If the user is unaware of the "tiny" implementation, and chooses to
  implement their own __wrap_printf and __wrap_puts, their own
  implementation will be automatically chosen over the "tiny" printf and
  puts from the library.

Newlib must be configured with --enable-newlib-nano-formatted-io for
the "tiny" printf and puts functions to be built into the library.

Code size reduction examples:
printf("Hello World\n")
  baseline - msp430-elf-gcc gcc-8_3_0-release
     text    data     bss
   5638     214      26
  "tiny" puts enabled
    text    data     bss
     714      90      20

printf("Hello %d\n", a)
  baseline - msp430-elf-gcc gcc-8_3_0-release
    text    data     bss
   10916     614      28

  "tiny" printf enabled
    text    data     bss
    4632     280      20
2019-04-15 14:22:33 +02:00
Jozef Lawrynowicz 2af6ad9f05 Copy prerequisite file for "tiny" printf implementation
Use newlib/libc/stdio/nano-vfprintf.c as baseline for tiny-printf.c
2019-04-15 14:22:30 +02:00
Alexander Fedotov a0b0a4a018 Align comments and spaces in libgloss/arm/crt0.S and newlib/libc/sys/arm/crt0.S to ease further code alignment. 2019-04-12 14:34:47 +01:00
Christophe Lyon cc430406ac Include code in trap.S for APCS only.
The code in trap.S is to support the old APCS chunked stack variant,
which dates back to the Acorn days, so put it under #ifndef
__ARM_EABI__.

	* libgloss/arm/trap.S: Use __ARM_EABI rather than PREFER_THUMB.
	* newlib/libc/sys/arm/trap.S: Use __ARM_EABI rather than
	__thumb2__.
2019-04-11 14:20:21 +00:00
Christophe Lyon 630808d2a2 Make more macro checks ARMv8-M baseline proof.
Commit 69f4c40291 improved most
macro checks to be ARMv8-M baseline proof, but missed a few
occurrences which otherwise fail to build when using a CPU setting
such as cortex-m0 or cortex-m23. This patch brings the same
changes as the ones that were committed to libgloss at that time.

	newlib:
	* libc/sys/arm/crt0.S: Use THUMB1_ONLY rather than
	__ARM_ARCH_6M__.
2019-04-11 14:20:21 +00:00
Andrew Stubbs e8b23909e4 Add missing includes.
These missing includes were causing build warnings, but also a real bug in
which the "size" parameter to "write" was being passed in 32-bit, whereas it
ought to be 64-bit.  This led to intermittent bad behaviour.
2019-03-25 16:44:10 +01:00
Andrew Stubbs 62c66a39bd AMD GCN: Implement circular buffering.
The GCN port outputs stdout and stderr via a shared-memory interface.
Previously the buffer was limited to 1000 write operations, which was enough
for testing purposes, but easy to exhaust.

This patch implements a new circular buffering system allowing a greater
amount of output.  The interface must allow hundreds of hardware threads to
output simultaneously.  The new limit is UINT32_MAX write operations.

Unfortunately, there's no way to tell if the host side has also been updated.
This code will misbehave unless the gcn-run from GCC is also updated (although
it's fine the other way around), but that patch has already been committed.

OK?

Andrew Stubbs
Mentor Graphics / CodeSourcery
2019-03-18 17:38:25 +01:00
Corinna Vinschen 5fcbbf7ead stdio: drop unused O_TEXT handling on non-Cygwin
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-22 21:58:51 +01:00
Yaakov Selkowitz 850705f92e Cygwin: add secure_getenv
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2019-02-19 13:01:50 -06:00
Sebastian Huber 1d35a003fd Define u_register_t if __BSD_VISIBLE
Add u_register_t definition for FreeBSD compatibility.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-02-19 09:06:22 +01:00
Sebastian Huber 688e584efe Change register_t definition
On 64-bit targets, the register_t type must be a 64-bit integer.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-02-19 09:06:22 +01:00
Sebastian Huber 6246ef7949 Fix comment in <sys/types.h>
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-02-19 09:06:22 +01:00
Sebastian Huber 9d4a6534fb Move RTEMS and XMK specific type definitions
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-02-19 09:06:22 +01:00
Sebastian Huber 3e24fbf6f0 scandir: Add support for struct dirent::d_type
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-02-01 10:37:00 +01:00
ache 67613cbbd8 a) Use strcoll() in opendir() and alphasort()
as POSIX 2008 requires. It also matches now how our 'ls' works for years.

b) Remove comment expressed 2 fears:
 1) One just simple describe how strcoll() works in _any_ context,
 not for directories only. Are we plan to remove strcoll() from everything
 just because it is little more complex than strcmp()? I doubt, and
 directories give nothing different here. Moreover, strcoll() used
 in 'ls' for years and nobody complaints yet.

 2) Plain wrong statement about undefined strcoll() behaviour. strcoll()
 always gives predictable results, falling back to strcmp() on any
 trouble, see strcoll(3).

No objections from -current list discussion.
2019-02-01 10:37:00 +01:00
das 2d3c2f4697 scandir(3) previously used st_size
to obtain an initial estimate of the array length needed to store all
the directory entries. Although BSD has historically guaranteed that
st_size is the size of the directory file, POSIX does not, and more to
the point, some recent filesystems such as ZFS use st_size to mean
something else.

The fix is to not stat the directory at all, set the initial
array size to 32 entries, and realloc it in powers of 2 if that
proves insufficient.

PR:	113668
2019-02-01 10:36:40 +01:00
obrien d785551a46 Remove __P and convert to ANSI prototypes.
* Fix SCM ID's.
2019-02-01 10:33:14 +01:00
jhb 0e7db0c356 Clean up the vcs ID strings
in libc's gen/ directory.

- Move CSRG IDs into __SCCSID().
- When a file has been copied, consistently use 'From: <tag>' for strings
  referencing the version of the source file copied from in the license
  block comment.
- Some of the 'From:' tags were using $FreeBSD$ that was being expanded on
  each checkout.  Fix those to hardcode the FreeBSD tag from the file that
  was copied at the time of the copy.
- When multiple strings are present list them in "chronological" order,
  so CSRG (__SCCSID) before FreeBSD (__FBSDID).  If a file came from
  OtherBSD and contains a CSRG ID from the OtherBSD file, use the order
  CSRG -> OtherBSD -> FreeBSD.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D15831
2019-02-01 10:32:24 +01:00
imp b46ef7699f 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
2019-02-01 10:32:24 +01:00
Sebastian Huber 62fb0614c6 scandir: Update copyright notice from FreeBSD
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-02-01 10:32:24 +01:00
pfg 24629e9701 General 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.
2019-02-01 10:32:24 +01:00
Jozef Lawrynowicz b644774b8f Use nanf() instead of nan() in single-precision float libm math functions
This patch reduces code size for a few single-precision float math
functions, by using nanf() instead of nan() where required.
2019-01-23 10:46:30 +01:00
Jozef Lawrynowicz d451d9ec78 Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions
This patch replaces instances of "(float).*HUGE_VAL" with a direct usage of
HUGE_VALF, which is also defined in math.h.
2019-01-23 10:46:30 +01:00
Jozef Lawrynowicz 7db203304e Remove HUGE_VAL definition from libm math functions
This patch removes the definitions of HUGE_VAL from some of the float math
functions. HUGE_VAL is defined in newlib/libc/include/math.h, so it is not
necessary to have a further definition in the math functions.
2019-01-23 10:46:30 +01:00
Jozef Lawrynowicz b14a879d85 Remove matherr, and SVID and X/Open math library configurations
Default math library configuration is now IEEE
2019-01-23 10:46:24 +01:00
Corinna Vinschen 13ea67a3c6 time.h: Add CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM
Slightly reshuffle and add comment

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:39:39 +01:00
Jeff Johnston 1787e9d033 AMD GCN Port contributed by Andrew Stubbs <ams@codesourcery.com>
Add support for the AMD GCN GPU architecture.  This is primarily intended for
use with OpenMP and OpenACC offloading.  It can also be used for stand-alone
programs, but this is intended mostly for testing the compiler and is not
expected to be useful in general.

The GPU architecture is highly parallel, and therefore Newlib must be
configured to use dynamic re-entrancy, and thread-safe malloc.

The only I/O available is a via a shared-memory interface provided by libgomp
and the gcn-run tool included with GCC.  At this time this is limited to
stdout, argc/argv, and the return code.
2019-01-15 10:48:08 -05:00
Thomas Wolff 41397e13ce update to Unicode 11.0 2019-01-13 23:33:51 +01:00
Thomas Wolff 30062d409d map WEOF to undefined rather than the control char category
Fixes https://cygwin.com/ml/cygwin/2018-12/msg00173.html
2019-01-13 23:33:51 +01:00
Corinna Vinschen fe8f406cc6 fcntl.h: expose AT_EMPTY_PATH with _GNU_SOURCE only
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-07 20:09:20 +01:00
Corinna Vinschen 9443efe099 Cygwin: linkat: support Linux-specific AT_EMPTY_PATH flag
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-07 19:36:37 +01:00
Corinna Vinschen b93022a82d Cygwin: open: support Linux-specific O_PATH flag
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-07 19:35:00 +01:00
Wilco Dijkstra 353ebae304 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>
2019-01-01 09:44:59 -06:00
Jeff Johnston 5726873100 Bump release to 3.1.0 for yearly snapshot 2018-12-31 23:40:11 -05:00
Sebastian Huber dc6e94551f 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>
2018-12-20 12:12:38 +01:00
markj 44756a36ab 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
2018-12-20 12:12:37 +01:00
Jon Beniston b3692aed5e nano-vfprintf_float.c: Fix check if negative for nans. 2018-12-13 13:15:32 +01:00
Szabolcs Nagy df6915f029 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.
2018-12-10 16:51:05 +01:00
Sebastian Huber 55db4a8e3a sys/time.h: Remove KASSERT
The KASSERT is only used by the FreeBSD kernel.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-12-04 07:39:20 +01:00
imp be517bd298 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
2018-12-04 07:39:15 +01:00
imp 7bf8fc0987 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
2018-12-04 07:30:18 +01:00
ian 68b1d72e1d Correct a misplaced closing paren.
Does not affect the result, but does clarify (at least for me) that the
multiplication happens before the shift.
2018-12-04 07:30:09 +01:00
pfg 3266b2dd5e 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.
2018-12-04 07:30:05 +01:00
ian 3c3c17500c 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.)
2018-12-04 07:29:51 +01:00
imp 8f4149ea93 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
2018-12-04 07:29:50 +01:00
Corinna Vinschen 09870c6e95 stdio.h: Expose cuserid with __GNU_VISIBLE
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-29 11:22:42 +01:00
Corinna Vinschen f4d6ef2d41 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>
2018-11-29 10:01:57 +01:00
Matthew Malcomson 2d6b71ee6d 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.
2018-11-26 10:07:55 -05:00
Wilco Dijkstra df7824d1a4 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.

--
2018-11-08 16:45:19 +00:00
Sebastian Huber 2ab57ad59b 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>
2018-11-08 09:38:13 +01:00
Sebastian Huber 1471e7cd74 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>
2018-11-08 09:38:12 +01:00
Wilco Dijkstra d80db60066 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.
2018-11-06 14:59:51 +00:00
Stafford Horne 8ac94ca7bb 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>
2018-11-05 10:02:20 +01:00
Sebastian Huber 08eab6396f 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>
2018-10-22 11:26:39 +02:00
Sebastian Huber 5835688440 RTEMS: Use function and data sections
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-22 11:26:39 +02:00
Joel Sherrill 037428fae3 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()
2018-10-18 17:19:50 -05:00
Wilco Dijkstra 473f1a3a5d 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).

--
2018-10-18 19:51:39 +02:00
Christophe Lyon 4f7a6c326a 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.
2018-10-11 16:32:14 +02:00
Sebastian Huber 103b055035 Add generic implementation of fdopendir()
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-11 08:29:17 +02:00
Sebastian Huber ab4fdab5d5 Add generic implementation of dirfd()
Use existing HAVE_OPENDIR define to determine if a generic
implementation should be provided.  Cygwin for example has its own
implementation of opendir() and dirfd().

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-11 08:29:16 +02:00
Sebastian Huber 738fdc6a42 RTEMS: Add struct dirent::d_type member
This is used by the file system support of libstdc++ for example.  Use
content from latest FreeBSD <sys/dirent.h>

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-11 08:29:16 +02:00
Sebastian Huber da418955f5 Move common <sys/dirent.h> content to <dirent.h>
Move common content of the various <sys/dirent.h> and the latest FreeBSD
<dirent.h> to <dirent.h>.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-11 08:29:16 +02:00
Sebastian Huber 61fc64ed97 Open a directory with the usual flags
Use O_RDONLY since you are not supposed to write to a directory.

Use O_DIRECTORY as mandated by POSIX (The Open Group Base Specifications
Issue 7, 2018 edition IEEE Std 1003.1-2017):

"If the type DIR is implemented using a file descriptor, the descriptor
shall be obtained as if the O_DIRECTORY flag was passed to open()."

Use O_CLOEXEC as mandated by POSIX:

"When a file descriptor is used to implement the directory stream, it
behaves as if the FD_CLOEXEC had been set for the file descriptor."

Drop the fcntl() call in favour of O_CLOEXEC.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-11 08:29:16 +02:00
Sebastian Huber d3d838cc26 Make some standard open() flags visible
Make the POSIX O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_SEARCH
open() flags available also to non-Cygwin systems.

Make the BSD/glibc O_DIRECT open() flag  available also to non-Cygwin
systems.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-11 08:29:16 +02:00
Corinna Vinschen 256f1171ac newlib: Build internal strtold code only if HAVE_LONG_DOUBLE defined
Commit fbace81684
("Import correctly working strtold from David M. Gay.")
introduced two new files, strtorx.c and strtodg.c.  The functions
are only called from strtold.c.  However, while strtold.c is only
built if HAVE_LONG_DOUBLE is defined, the patch erroneously added
the two new files to GENERAL_SOURCES unconditionally.

Fix this by building both files only if HAVE_LONG_DOUBLE has been
defined.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-10-10 18:01:22 +02:00
Corinna Vinschen 35555851d7 newlib: strtold: use __builtin_nanl to avoid libm dependency
Commit 6c212a8b78
("Fix strtod ("nan") and strtold ("nan") returns wrong negative NaN")
introduced an unconditional dependency to nanl and, in turn, to libm.

Rather than including nanl in libc as well, just call __builtin_nanl
from here.  Requires GCC 3.3 or later.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-10-10 17:53:55 +02:00
Corinna Vinschen 682c4a9f1e Implement nanl in newlib only
Drop Cygwin-specific nanl in favor of a generic implementation
in newlib.  Requires GCC 3.3 or later.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-10-10 17:49:53 +02:00
Corinna Vinschen 9479563e48 newlib: Drop incorrect const qualifier from __loadlocale parameter
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-10-10 11:18:20 +02:00
Sebastian Huber 201bbec6e4 Add attributes to malloc-like functions
These attributes help static analysis tools to produce less false
positives, e.g. double free warnings.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-10 07:40:06 +02:00
Christophe Lyon 8a7536e91d [ARM] Make _kill() a noreturn function.
AngelSWI_Reason_ReportException does not return accoring to the ARM
documentation, so it is valid to mark _kill() as noreturn.  This way,
the compiler does not warn about _exit() returning a value despite
being noreturn.

2018-10-01  Christophe Lyon  <christophe.lyon@linaro.org>

	* libgloss/arm/_exit.c (_exit): Declare _kill() as noreturn.
	* libgloss/arm/_exit.c (_kill): Likewise. Remove the return
	statements.
	* newlib/libc/sys/arm/syscalls.c (_kill): Likewise..
2018-10-08 14:35:43 +01:00
Christophe Lyon f53ce01125 Define _COMPILING_NEWLIB on aarch64 to define function prototypes from unistd.h.
2018-10-01  Christophe Lyon  <christophe.lyon@linaro.org>

    	* newlib/configure.host: Define _COMPILING_NEWLIB for aarch64.
2018-10-05 13:27:34 +01:00
Christophe Lyon 3878d82a2b [ARM] Cast string pointers to int to avoid compiler warnings.
2018-10-01  Christophe Lyon  <christophe.lyon@linaro.org>

    	* newlib/libc/sys/arm/syscalls.c (_unlink): Cast 'path' to int.
    	(_system): Cast 's' to int.
    	(_rename): Cast 'newpath' and 'oldpath' to int.
2018-10-05 12:00:44 +01:00
Wilco Dijkstra 71e187bc07 Update Arm copyright notices in new math files
While working on the strstr patch I noticed several copyright headers
of the new math functions are missing closing quotes after ``AS IS.
I've added these.  Also update spellings of Arm Ltd in a few places
(but still use ARM LTD in upper case portion).  Finally add SPDX
identifiers to make everything consistent.
2018-09-28 11:03:55 +01:00
Szabolcs Nagy 877a386d76 Fix the documentation comment of checkint
checkint in pow is not supposed to be used with 0, inf or nan inputs.
2018-09-18 14:12:18 -04:00
Hans-Peter Nilsson e3ddbeb84c Committed, CRIS port: fix fallout from time_t defaulting to 64 bits, part 2
It's been a while...  I see the CRIS port broke with the
time_t-default-to-64-bit change, observable by a few test-cases in the gcc
fortran(!) tests failing, regressing when trying a recent newlib.

This is a two-part belt-and-suspenders change: adjust the CRIS port
gettimeofday syscall (the only one in newlib/CRIS passing a time_t or
struct timeval) to handle a userspace 64-bit time_t and secondly default
time_t to 32-bit long anyway.  I considered making the local
"kernel_timeval" copy in _gettimeofday conditional on (userspace) time_t
being 64 bits, but thought it not worth bothering with the few move insns.
The effect of a 64-bit time_t is however observable as longer simulation
time when running the gcc testsuite and as bigger binaries without any
actual upside from the larger time_t size, so I thought better make the
default for this port go back to being a "long" again.

Tested by running the gcc testsuite over the three combinations of two
parts of the patch and observing the expected changes.  Committed.

newlib:
	* configure.host (cris, crisv32): Default to "long" time_t.

Signed-off-by: Hans-Peter Nilsson <hp@axis.com>
2018-09-13 17:58:01 +02:00
Jon Beniston bd993df0e6 search: Fix Berkeley DB hash code for 16-bit targets.
hash.h: Use 32-bit type for data stored on disk, so code
works for 16 and 64-bit targets. Reduce maximum bucket size on 16-bit
targets, so it fits in available memory.
hash.c: Check bucket size isn't too big for target.
hash_buf.c: Fix overflow warning on 16-bit targets.
2018-09-06 17:29:49 +02:00
Keith Packard 77f8a6dfab Use !__HAVE_LOCALE_INFO__ define to use _ctype_ directly [v2]
When __HAVE_LOCALE_INFO__ is not selected, directly access the
existing _ctype_ variable from __locale_ctype_ptr() and
__locale_ctype_ptr_l(), eliminating the need for any locale or reent
structure

Signed-off-by: Keith Packard <keithp@keithp.com>

v2:
	locale: fix conflict with __locale_ctype_ptr macro

	If we are building without __HAVE_LOCALE_INFO__, there is a
	macro providing __locale_ctype_ptr which in turn fouls up this
	declaration.

	Signed-off-by: Michael Lyle <mlyle@lyle.org>
2018-09-06 14:19:53 +02:00
Keith Packard 3b6994ec5f stdlib: Use __get_numeric_locale instead of __localeconv_l for decimal_point
The string/float conversion functions need to get the locale decimal
point. Instead of calling __localeconv_l (which copies locale data
into lconv form from __get_numeric_locale), use __get_numeric_locale
directly.

Signed-off-by: Keith Packard <keithp@keithp.com>
2018-09-06 14:14:05 +02:00
Keith Packard 28ecec475f Include sys/syslimits.h in limits.h
This makes sure any system-defined limits are specified before the
defaults are checked. Without this, ARG_MAX and PATH_MAX end up
getting the default definitions from limits.h rather than the defines
from syslimits.h. This could potentially cause problems when
different files used different values for the same name.

Signed-off-by: Keith Packard <keithp@keithp.com>
2018-09-06 14:11:45 +02:00
Keith Packard 81e0841dbc xdr_private.h needs sys/types.h for u_char
u_char is defined in sys/types.h, which doesn't appear to get
included, at least in my environments.

Signed-off-by: Keith Packard <keithp@keithp.com>
2018-09-06 14:10:42 +02:00
Szabolcs Nagy f92a4c5d2d Document the log table generation method
Add comments with enough detail so the log lookup tables can be recreated.
2018-09-06 13:34:13 +02:00
Jon Beniston 7283d2513c stdlib/arc4random.c: Fix reseed count for 16-bit targets. 2018-09-06 13:26:25 +02:00
Wilco Dijkstra 6dbb20dfc7 Improve strstr performance of short needles
Improve strstr performance for the common case of short needles.  For a single
character strchr is best, for 2-4 characters a small loop is fastest.  For these
the speedup over the Two-Way algorithm is ~10 times on large strings.

Newlib builds, the new code passes GLIBC testsuite. OK for commit?
2018-09-05 10:09:31 +02:00
Jon Beniston 86c31ae47b math_config.h: Fix signed overflow warning for 16-bit targets 2018-09-03 09:41:26 +02:00
Jon Beniston fcc1e7039f e_scalb.c: Call scalbln instead of scalbn on 16-bit targets to ensure constant fits in an int. 2018-09-03 09:41:23 +02:00
Andy Koppe 3017f23f1c Avoid ARM SWI Seek when querying file position
Issuing an ARM semi-hosting Seek command when just querying file
position with SEEK_CUR and offset zero is unnecessary, because unlike
the lseek() Unix system call the Seek command does not actually return
the file position. For that reason, syscalls.c for ARM keeps track of
file position in the 'poslog', so we can just return that.

Moreover, since the Seek command only accepts an absolute file position,
SEEK_CUR operations are implemented by adding the relative offset to the
position in the poslog. If the host implements non-binary files with
implicit carriage return characters but doesn't discount those implicit
CRs when implementing Seek (by just mapping straight to Windows file
operations), this actually ended up wrongly changing file position when
using SEEK_CUR with offset zero or functions like ftell() or fgetpos()
that are based on that.

Also, use off_t rather than int for the poslog.
2018-09-03 09:40:39 +02:00
Jon Beniston a9cfb33b6c Add --disable-newlib-fno-builtin to allow compilation without -fno-builtin for smaller and faster code. 2018-08-31 15:40:42 -04:00
Andy Koppe d8ccbcdacc Drop non-reserved parameter names from sys/signal.h
Standard headers shouldn't use non-reserved identifiers as parameter
names in function declarations, because programs could in theory
define macros with such names before including a header.
2018-08-29 17:46:27 +02:00
Keith Packard 82dfae9ab0 Use __inhibit_loop_to_libcall in all memset/memcpy implementations
This macro selects a compiler option that disables recognition of
common memset/memcpy patterns and converting those to direct
memset/memcpy calls.

Signed-off-by: Keith Packard <keithp@keithp.com>
2018-08-29 16:05:37 +02:00
Keith Packard 088a45cdf6 Remove unused variable 'one' from sf_cos.c
Defined, never mentioned.

Signed-off-by: Keith Packard <keithp@keithp.com>
2018-08-29 15:57:27 +02:00
Keith Packard 2c245028af Use nanf("") instead of nanf(NULL)
Newer GCC versions require a non-NULL argument to this function for
some reason.

Signed-off-by: Keith Packard <keithp@keithp.com>
2018-08-29 15:57:27 +02:00
Sebastian Huber d13c84eb07 RTEMS: Add kvaddr_t and ksize_t
These types were introduced by FreeBSD commit:

"Make struct xinpcb and friends word-size independent.

Replace size_t members with ksize_t (uint64_t) and pointer members
(never used as pointers in userspace, but instead as unique
idenitifiers) with kvaddr_t (uint64_t). This makes the structs
identical between 32-bit and 64-bit ABIs.

On 64-bit bit systems, the ABI is maintained. On 32-bit systems,
this is an ABI breaking change. The ABI of most of these structs
was previously broken in r315662.  This also imposes a small API
change on userspace consumers who must handle kernel pointers
becoming virtual addresses.

PR:		228301 (exp-run by antoine)
Reviewed by:	jtl, kib, rwatson (various versions)
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D15386"

In RTEMS, there is no user/kernel space separation.  So, use the types
size_t and uintptr_t.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:07:29 +02:00
Sebastian Huber d35971f392 RTEMS: Introduce <machine/_kernel_mman.h>
This helps to avoid Newlib updates due to FreeBSD kernel space changes.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:04:43 +02:00
Sebastian Huber a2a8600f7d RTEMS: Introduce <machine/_kernel_socket.h>
This helps to avoid Newlib updates due to FreeBSD kernel space changes.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:04:43 +02:00
Sebastian Huber 764d748c9c RTEMS: Introduce <machine/_kernel_if.h>
This helps to avoid Newlib updates due to FreeBSD kernel space changes.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:04:43 +02:00
Sebastian Huber 0c0dd28596 RTEMS: Introduce <machine/_kernel_in.h>
This helps to avoid Newlib updates due to FreeBSD kernel space changes.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:04:43 +02:00
Sebastian Huber 9ce55ee716 RTEMS: Introduce <machine/_kernel_in6.h>
This helps to avoid Newlib updates due to FreeBSD kernel space changes.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:04:43 +02:00
Sebastian Huber c07fa084e0 RTEMS: Introduce <machine/_kernel_uio.h>
This helps to avoid Newlib updates due to FreeBSD kernel space changes.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:04:43 +02:00
Sebastian Huber 9bbf89dd11 RTEMS: Add __BSD_VISIBLE in <sys/_termios.h>
The __XSI_VISIBLE is not enabled by default in Newlib.  This is an
incompatiblity between FreeBSD and glibc.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:04:42 +02:00
Sebastian Huber 890c86d633 RTEMS: Update FreeBSD version tags
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:04:39 +02:00
tuexen fe3e8b90dc Add SOL_SOCKET level socket option
with name SO_DOMAIN to get the domain of a socket.

This is helpful when testing and Solaris and Linux have the same
socket option using the same name.

Reviewed by:		bcr@, rrs@
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D16791
2018-08-24 15:00:04 +02:00
jtl 823b096471 Implement a limit on on the number of IPv6 reassembly
queues per bucket.

There is a hashing algorithm which should distribute IPv6 reassembly
queues across the available buckets in a relatively even way. However,
if there is a flaw in the hashing algorithm which allows a large number
of IPv6 fragment reassembly queues to end up in a single bucket, a per-
bucket limit could help mitigate the performance impact of this flaw.

Implement such a limit, with a default of twice the maximum number of
reassembly queues divided by the number of buckets. Recalculate the
limit any time the maximum number of reassembly queues changes.
However, allow the user to override the value using a sysctl
(net.inet6.ip6.maxfragbucketsize).

Reviewed by:	jhb
Security:	FreeBSD-SA-18:10.ip
Security:	CVE-2018-6923
2018-08-24 15:00:04 +02:00
jtl 0e5c59050d Add a limit of the number of fragments per IPv6 packet.
The IPv4 fragment reassembly code supports a limit on the number of
fragments per packet. The default limit is currently 17 fragments.
Among other things, this limit serves to limit the number of fragments
the code must parse when trying to reassembly a packet.

Add a limit to the IPv6 reassembly code. By default, limit a packet
to 65 fragments (64 on the queue, plus one final fragment to complete
the packet). This allows an average fragment size of 1,008 bytes, which
should be sufficient to hold a fragment. (Recall that the IPv6 minimum
MTU is 1280 bytes. Therefore, this configuration allows a full-size
IPv6 packet to be fragmented on a link with the minimum MTU and still
carry approximately 272 bytes of headers before the fragmented portion
of the packet.)

Users can adjust this limit using the net.inet6.ip6.maxfragsperpacket
sysctl.

Reviewed by:	jhb
Security:	FreeBSD-SA-18:10.ip
Security:	CVE-2018-6923
2018-08-24 15:00:04 +02:00
rrs 215e33310b This commit brings in a new refactored TCP stack called Rack.
Rack includes the following features: - A different SACK processing
scheme (the old sack structures are not used). - RACK (Recent
acknowledgment) where counting dup-acks is no longer done instead time
is used to knwo when to retransmit. (see the I-D) - TLP (Tail Loss
Probe) where we will probe for tail-losses to attempt to try not to take
a retransmit time-out. (see the I-D) - Burst mitigation using TCPHTPS -
PRR (partial rate reduction) see the RFC.

Once built into your kernel, you can select this stack by either
socket option with the name of the stack is "rack" or by setting
the global sysctl so the default is rack.

Note that any connection that does not support SACK will be kicked
back to the "default" base  FreeBSD stack (currently known as "default").

To build this into your kernel you will need to enable in your
kernel:
   makeoptions WITH_EXTRA_TCP_STACKS=1
   options TCPHPTS

Sponsored by:	Netflix Inc.
Differential Revision:		https://reviews.freebsd.org/D15525
2018-08-24 15:00:04 +02:00
sbruno b40c48e057 Load balance sockets with new SO_REUSEPORT_LB option.
This patch adds a new socket option, SO_REUSEPORT_LB, which allow multiple
programs or threads to bind to the same port and incoming connections will be
load balanced using a hash function.

Most of the code was copied from a similar patch for DragonflyBSD.

However, in DragonflyBSD, load balancing is a global on/off setting and can not
be set per socket. This patch allows for simultaneous use of both the current
SO_REUSEPORT and the new SO_REUSEPORT_LB options on the same system.

Required changes to structures:
Globally change so_options from 16 to 32 bit value to allow for more options.
Add hashtable in pcbinfo to hold all SO_REUSEPORT_LB sockets.

Limitations:
As DragonflyBSD, a load balance group is limited to 256 pcbs (256 programs or
threads sharing the same socket).

This is a substantially different contribution as compared to its original
incarnation at svn r332894 and reverted at svn r332967.  Thanks to rwatson@
for the substantive feedback that is included in this commit.

Submitted by:	Johannes Lundberg <johalun0@gmail.com>
Obtained from:	DragonflyBSD
Relnotes:	Yes
Sponsored by:	Limelight Networks
Differential Revision:	https://reviews.freebsd.org/D11003
2018-08-24 15:00:04 +02:00
mmacy 44e0190a8c iflib(9): Add support for cloning pseudo interfaces
Part 3 of many ...
The VPC framework relies heavily on cloning pseudo interfaces
(vmnics, vpc switch, vcpswitch port, hostif, vxlan if, etc).

This pulls in that piece. Some ancillary changes get pulled
in as a side effect.

Reviewed by:	shurd@
Approved by:	sbruno@
Sponsored by:	Joyent, Inc.
Differential Revision:	https://reviews.freebsd.org/D15347
2018-08-24 15:00:04 +02:00
sbruno 6a98562b52 Revert r332894 at the request of the submitter.
Submitted by:	Johannes Lundberg <johalun0_gmail.com>
Sponsored by:	Limelight Networks
2018-08-24 15:00:04 +02:00
sbruno 5c636abe89 Load balance sockets with new SO_REUSEPORT_LB option
This patch adds a new socket option, SO_REUSEPORT_LB, which allow multiple
programs or threads to bind to the same port and incoming connections will be
load balanced using a hash function.

Most of the code was copied from a similar patch for DragonflyBSD.

However, in DragonflyBSD, load balancing is a global on/off setting and can not
be set per socket. This patch allows for simultaneous use of both the current
SO_REUSEPORT and the new SO_REUSEPORT_LB options on the same system.

Required changes to structures
Globally change so_options from 16 to 32 bit value to allow for more options.
Add hashtable in pcbinfo to hold all SO_REUSEPORT_LB sockets.

Limitations
As DragonflyBSD, a load balance group is limited to 256 pcbs
(256 programs or threads sharing the same socket).

Submitted by:	Johannes Lundberg <johanlun0@gmail.com>
Sponsored by:	Limelight Networks
Differential Revision:	https://reviews.freebsd.org/D11003
2018-08-24 15:00:04 +02:00
brooks 341e131f7f Add 32-bit compat for ioctls that take struct ifgroupreq.
Use an accessor to access ifgr_group and ifgr_groups.

Use an macro CASE_IOC_IFGROUPREQ(cmd) in place of case statements such
as "case SIOCAIFGROUP:". This avoids poluting the switch statements
with large numbers of #ifdefs.

Reviewed by:	kib
Obtained from:	CheriBSD
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D14960
2018-08-24 15:00:03 +02:00
brooks 79291d6123 Use an accessor function to access ifr_data.
This fixes 32-bit compat (no ioctl command defintions are required
as struct ifreq is the same size).  This is believed to be sufficent to
fully support ifconfig on 32-bit systems.

Reviewed by:	kib
Obtained from:	CheriBSD
MFC after:	1 week
Relnotes:	yes
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D14900
2018-08-24 15:00:03 +02:00
jeff c0f64943e7 Implement several enhancements to NUMA policies.
Add a new "interleave" allocation policy which stripes pages across
domains with a stride or width keeping contiguity within a multi-page
region.

Move the kernel to the dedicated numbered cpuset #2 making it possible
to assign kernel threads and memory policy separately from user.  This
also eliminates the need for the complicated interrupt binding code.

Add a sysctl API for viewing and manipulating domainsets.  Refactor some
of the cpuset_t manipulation code using the generic bitset type so that
it can be used for both.  This probably belongs in a dedicated subr file.

Attempt to improve the include situation.

Reviewed by:	kib
Discussed with:	jhb (cpuset parts)
Tested by:	pho (before review feedback)
Sponsored by:	Netflix, Dell/EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D14839
2018-08-24 15:00:03 +02:00
brooks f967e60cab Fix access to ifru_buffer on freebsd32.
Make all kernel accesses to ifru_buffer go via access functions
which take the process ABI into account and use an appropriate union
to access members in the correct place in struct ifreq.

Reviewed by:	kib
Obtained from:	CheriBSD
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D14846
2018-08-24 15:00:03 +02:00
kib b0250c7356 Allow to specify PCP on packets not belonging to any VLAN.
According to 802.1Q-2014, VLAN tagged packets with VLAN id 0 should be
considered as untagged, and only PCP and DEI values from the VLAN tag
are meaningful.  See for instance
https://www.cisco.com/c/en/us/td/docs/switches/connectedgrid/cg-switch-sw-master/software/configuration/guide/vlan0/b_vlan_0.html.

Make it possible to specify PCP value for outgoing packets on an
ethernet interface.  When PCP is supplied, the tag is appended, VLAN
id set to 0, and PCP is filled by the supplied value.  The code to do
VLAN tag encapsulation is refactored from the if_vlan.c and moved into
if_ethersubr.c.

Drivers might have issues with filtering VID 0 packets on
receive.  This bug should be fixed for each driver.

Reviewed by:	ae (previous version), hselasky, melifaro
Sponsored by:	Mellanox Technologies
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D14702
2018-08-24 15:00:03 +02:00
brooks 9cea1c4489 Move uio enums to sys/_uio.h.
Include _uio.h instead of uio.h in several headers to reduce header
polution.

Fix a few places that relied on header polution to get the uio.h header.

I have not moved struct uio as many more things that use it rely on
header polution to get other definitions from uio.h.

Reviewed by:	cem, kib, markj
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D14811
2018-08-24 15:00:03 +02:00
jtl 61d5f8adfa Add the "TCP Blackbox Recorder"
which we discussed at the developer summits at BSDCan and BSDCam in 2017.

The TCP Blackbox Recorder allows you to capture events on a TCP connection
in a ring buffer. It stores metadata with the event. It optionally stores
the TCP header associated with an event (if the event is associated with a
packet) and also optionally stores information on the sockets.

It supports setting a log ID on a TCP connection and using this to correlate
multiple connections that share a common log ID.

You can log connections in different modes. If you are doing a coordinated
test with a particular connection, you may tell the system to put it in
mode 4 (continuous dump). Or, if you just want to monitor for errors, you
can put it in mode 1 (ring buffer) and dump all the ring buffers associated
with the connection ID when we receive an error signal for that connection
ID. You can set a default mode that will be applied to a particular ratio
of incoming connections. You can also manually set a mode using a socket
option.

This commit includes only basic probes. rrs@ has added quite an abundance
of probes in his TCP development work. He plans to commit those soon.

There are user-space programs which we plan to commit as ports. These read
the data from the log device and output pcapng files, and then let you
analyze the data (and metadata) in the pcapng files.

Reviewed by:	gnn (previous version)
Obtained from:	Netflix, Inc.
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D11085
2018-08-24 15:00:03 +02:00
brooks 4d144963ea Add _IOC_NEWLEN() and _IOC_NEWTYPE() macros.
These macros take an existing ioctl(2) command and replace the length
with the specified length or length of the specified type respectively.
These can be used to define commands for 32-bit compatibility with fewer
opportunities for cut-and-paste errors then a whole new definition.

Reviewed by:	cem, kib
Obtained from:	CheriBSD
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D14706
2018-08-24 15:00:03 +02:00
pkelsey b4d6660d85 This is an implementation of the client side of TCP Fast Open (TFO)
[RFC7413]. It also includes a pre-shared key mode of operation in which
the server requires the client to be in possession of a shared secret in
order to successfully open TFO connections with that server.

The names of some existing fastopen sysctls have changed (e.g.,
net.inet.tcp.fastopen.enabled -> net.inet.tcp.fastopen.server_enable).

Reviewed by:	tuexen
MFC after:	1 month
Sponsored by:	Limelight Networks
Differential Revision:	https://reviews.freebsd.org/D14047
2018-08-24 15:00:03 +02:00
ae@FreeBSD.org b43341334e Follow the RFC6980 and silently ignore following IPv6 NDP messages
that had the IPv6 fragmentation header:
o Neighbor Solicitation
o Neighbor Advertisement
o Router Solicitation
o Router Advertisement
o Redirect

Introduce M_FRAGMENTED mbuf flag, and set it after IPv6 fragment reassembly
is completed. Then check the presence of this flag in correspondig ND6
handling routines.

PR:		224247
MFC after:	2 weeks
2018-08-24 15:00:03 +02:00
pfg ba2eaf10ad SPDX: license IDs for some ISC-related files. 2018-08-24 15:00:03 +02:00
glebius d937538075 Garbage collect IFCAP_POLLING_NOCOUNT.
It wasn't used since very beginning of polling(4). The module always
ignored return value from driver polling handler.
2018-08-24 15:00:03 +02:00
pfg fba31eac2e sys/sys: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

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.
2018-08-24 15:00:03 +02:00
pfg 1329e846c7 include: 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.
2018-08-24 15:00:03 +02:00
pfg 9f0f4785e8 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.
2018-08-24 15:00:03 +02:00
kib 91e828be4f Use hardware timestamps to report packet timestamps
for SO_TIMESTAMP and other similar socket options.

Provide new control message SCM_TIME_INFO to supply information about
timestamp.  Currently it indicates that the timestamp was
hardware-assisted and high-precision, for software timestamps the
message is not returned.  Reserved fields are added to ABI to report
additional info about it, it is expected that raw hardware clock value
might be useful for some applications.

Reviewed by:	gallatin (previous version), hselasky
Sponsored by:	Mellanox Technologies
MFC after:	2 weeks
X-Differential revision:	https://reviews.freebsd.org/D12638
2018-08-24 15:00:02 +02:00