support linux kernel apis (new archs) with old syscalls removed

such archs are expected to omit definitions of the SYS_* macros for
syscalls their kernels lack from arch/$ARCH/bits/syscall.h. the
preprocessor is then able to select the an appropriate implementation
for affected functions. two basic strategies are used on a
case-by-case basis:

where the old syscalls correspond to deprecated library-level
functions, the deprecated functions have been converted to wrappers
for the modern function, and the modern function has fallback code
(omitted at the preprocessor level on new archs) to make use of the
old syscalls if the new syscall fails with ENOSYS. this also improves
functionality on older kernels and eliminates the incentive to program
with deprecated library-level functions for the sake of compatibility
with older kernels.

in other situations where the old syscalls correspond to library-level
functions which are not deprecated but merely lack some new features,
such as the *at functions, the old syscalls are still used on archs
which support them. this may change at some point in the future if or
when fallback code is added to the new functions to make them usable
(possibly with reduced functionality) on old kernels.
fix sendfile syscall to use 64-bit off_t

somehow the remapping of this syscall to the 64-bit version was
overlooked. the issue was found, and patch provided, by Stefan
Kristiansson. presumably the reason this bug was not caught earlier is
that the syscall takes a pointer to off_t rather than a value, so on
little-endian systems, everything appears to work as long as the
offset value fits in the low 31 bits. on big-endian systems, though,
sendfile was presumably completely non-functional.
additional fixes for linux kernel apis with old syscalls removed
break down coarse-grained 64-bit-off_t syscall remappings

using the existence of SYS_stat64 as the condition for remapping other
related syscalls is no longer valid, since new archs that omit the old
syscalls will not have SYS_stat or SYS_stat64, but still potentially
need SYS_fstat and others remapped. it would probably be possible to
get by with just one or two extra conditionals, but just breaking them
all down into separate conditions is robust and not significantly
heavier for the preprocessor.
fix for broken kernel side RLIM_INFINITY on mips

On 32 bit mips the kernel uses -1UL/2 to mark RLIM_INFINITY (and
this is the definition in the userspace api), but since it is in
the middle of the valid range of limits and limits are often
compared with relational operators, various kernel side logic is
broken if larger than -1UL/2 limits are used. So we truncate the
limits to -1UL/2 in get/setrlimit and prlimit.

Even if the kernel side logic consistently treated -1UL/2 as greater
than any other limit value, there wouldn't be any clean workaround
that allowed using large limits:
* using -1UL/2 as RLIM_INFINITY in userspace would mean different
infinity value for get/setrlimt and prlimit (where infinity is always
-1ULL) and userspace logic could break easily (just like the kernel
is broken now) and more special case code would be needed for mips.
* translating -1UL/2 kernel side value to -1ULL in userspace would
mean that -1UL/2 limit cannot be set (eg. -1UL/2+1 had to be passed
to the kernel instead).
fix breakage from recent syscall commits due to missing errno macros
add sched_{get,set}attr syscall numbers and SCHED_DEADLINE macro

linux 3.14 introduced sched_getattr and sched_setattr syscalls in
commit d50dde5a10f305253cbc3855307f608f8a3c5f73

and the related SCHED_DEADLINE scheduling policy in
commit aab03e05e8f7e26f51dee792beddcb5cca9215a5

but struct sched_attr "extended scheduling parameters data structure"
is not yet exported to userspace (necessary for using the syscalls)
so related uapi definitions are not added yet.
add SO_BPF_EXTENSIONS socket option

this was introduced to query BPF extension support with getsockopt
in linux 3.14, commit ea02f9411d9faa3553ed09ce0ec9f00ceae9885e
update netinet/in.h to match the current kernel uapi

from linux/in.h and linux/in6.h uapi headers the following
missing socket options were added:

IP_NODEFRAG - used with customized ipv4 headers
IPV6_RECVPATHMTU - for ipv6 path mtu
IPV6_PATHMTU - for ipv6 path mtu
IPV6_DONTFRAG - for ipv6 path mtu
IPV6_ADDR_PREFERENCES - RFC5014 Source Address Selection
IPV6_MINHOPCOUNT - RFC5082 Generalized TTL Security Mechanism
IPV6_ORIGDSTADDR - used by tproxy
IPV6_RECVORIGDSTADDR - used by tproxy
IPV6_TRANSPARENT - used by tproxy
IPV6_UNICAST_IF - ipv6 version of IP_UNICAST_IF

and socket option values:

IP_PMTUDISC_OMIT - value for IP_MTU_DISCOVER option, new in linux 3.14
IPV6_PMTUDISC_OMIT - same for IPV6_MTU_DISCOVER
IPV6_PMTUDISC_INTERFACE - ipv6 version of IP_PMTUDISC_INTERFACE
IPV6_PREFER_* - flags for IPV6_ADDR_PREFERENCES

not added: ipv6 flow info and flow label related definitions.
(it's unclear if libc should define these and namespace polluting
type name is involved so they are not provided for now)
use cleaner code for handling float rounding in vfprintf

CONCAT(0x1p,LDBL_MANT_DIG) is not safe outside of libc,
use 2/LDBL_EPSILON instead.

fix was proposed by Morten Welinder.
fix POSIX namespace pollution in sys/types.h

int8_t, u_int8_t, etc types are moved under _BSD_SOURCE