AHCI - Fix panic if additional I/O is queued during SATA error processing.

* If additional I/O is queued during SATA error processing the AHCI
  driver was improperly trying to initiate the new I/O.  This caused
  the error processing code to assert on unexpected command activity.

* Fix by implying exclusive access mode when the error CCB is in use and
  giving the error CCB queueing priority over all other CCBs.
tmpfs - Remove redundant call to insmntque()

vnode is moved to the mount queue specified in the call to getnewvnode(),
we do not need to move it again.
rtld: increase TLS storage space (bug 2566)

It appears that the TLS storage space, which is currently defined as 256
bytes on both platforms, is insufficient to handle libc TLS data.
Due to nmalloc setting of the thr_mags structure as Thread Local Storage,
the TLS elf section of x86-64 libc is 1172 bytes, while the i386 libc TLS
section weighs in at 588 bytes.  For comparison, the FreeBSD libc TLS
section is 17 bytes, and FreeBSD rtld only reserves 128 bytes for TLS.

The requirements for dmalloc are more modest, so this shortfall was likely
an unintended side-effect of switching from dmalloc back to nmalloc.

This commit sets the reserved TLS space to 1280 bytes for x86-64 and 640
bytes for i386.  This should allow 3.4 packages to continue to work on
the latest 3.5 branch as long as libc.so.7 is present.  For world upgrades
this is the normal case, but the libraries can be obtained by installing
misc/compat34x from dports as well.

Even if the libc TLS space requirements drop significantly, the large
RTLD_STATIC_TLS_EXTRA value needs to be maintained as long as
compatibility with old libc (3.4 and earlier) libraries is required.
libm: Add several new functions and symbol versioning

The following long double functions were added to the math library:
  logl
  log2l
  log10l
  log1pl
  expm1l
  acoshl
  asinhl
  atanhl

In addition, the FreeBSD functionality that creates symbol versioning
for libraries was adapted for FreeBSD.  The first version is called
"DFLY36.0".  If it is necessary to create a new version of the 3.5 or
3.6 branch, the number after the decimal will be incremented.  The 3.7
branch will start with "DFLY38.0" if it needs its own version.

libm was baselined with all symbols being the same version: DFLY36.0.
With symbol versioning, it will not be necessary to increment the major
version anymore, so this library shall always be known as libm.so.4 from
this point on.
Change initial symbol version from DFLY36.0 to DF306.0

The first one will make handling DragonFly 3.9 and later awkward.
Remove MACHINE_ARCH=amd64 and legacy make instructions from makefiles

Apparently the x86_64 platform used to be referred to as "amd64" so some
makefile code was added to help with the transition.  It probably should
have been removed when bringing bmake in.

With the commit, the makefiles expect bmake and will break if an older
make is used (e.g. from DragonFly 3.2).  That means an upgrade to
DragonFly 3.6 will have to be upgraded to DragonFly 3.4 first.  There
may be other reasons to do this as well, besides just bmake.

The recent symbol versioning makefile for libraries requires bmake, so
legacy make can't build world anymore in any case.
netstat - Do not double-count interfaces associated with bridges

* Do not double count packets & bytes for interfaces which are
  also associated with bridges when 'netstat -in' is used without
  an interface specification.
kernel - fix statistics counters for if_bridge.

* Count input statistics in bridge_input() instead of bridge_forward()

* Add output statistics in bridge_forward().  That is, the bridge should
  in abstract look like a piece of hardware from a statistics standpoint,
  so when a packet is forwarded through a bridge interface it needs to
  show up as both an input packet and an output packet.

* Fixes statistics reporting for e.g. 'netstat -in 1'.
kernel: Add three new commands to fctnl

This commit adds the following new commands to fcntl():
  F_DUP2FD         - non-portable functional equivalent of dup2(fd, arg)
  F_DUPFD_CLOEXEC  - A version of F_DUPFD that sets the close-on-exec
                     on the new file descriptor
  F_DUP2FD_CLOEXEC - A version of F_DUP2FD that sets the close-on-exec
                     on the new file descriptor.  It is non-portable

It also adds a missing break in a case statement for F_GETOWN in
sys_fnctl(), spotted by dillon.

reviewed-by: dillon
hammer2 - freemap part 4, misc fixes

* Revamp the freemap a bit.  Remove Layer 0.  Layer 1 is now the LEAF.
  2GB of media storage is now represented by a single 64KB Layer 1 block.
  Synchronize the FREEMAP document with the current thinking.

  The Layer 1 block contains 1024x64 entries.  Each entry represents 2MBytes
  of media storage.  These entries are no longer blockrefs pointing to
  Layer 0 but are instead terminal structures.

* Each entry represents a 16KB allocation granularity in 2 bits and has
  128 bit pairs (256 bits total), plus additional information to represent
  the 2MBytes of storage.

  Fine-grained allocations are supported via an iterator field, currently
  allowing fine-grained allocations down to 1KB and potentially expandable
  in the future to even smaller allocation sizes.

* Fix a SMP race in voldata handling during flush.  The freemap portion of
  voldata could be updated during crc calculations due to hmp->fchain not
  being held locked, causing random volume header/backups to fail their CRC
  test on remount.

* Add missing BUF_KERNPROC() when chain->bp is replaced.  Fixes a kernel
  lock ownership assertion.

* Add freezone/radix fields to the inode_data structure.  Each inode can
  accomodate four fields.  The fields are not yet utilized.  Current thinking
  is to use them to optimize the bulk free-scan for freeing blocks.
rtld: Sync 1/7 - Handle premature symlook_obj call

It doesn't appear that this code is needed for x86 platforms as this
case should already be caught in early code, but it doesn't hurt
DragonFly to handle every possible case.

  Work around a situation where symlook_obj() could be called for the
  object for which digest_dynamic1() was not done yet.  Just return
  EINVAL and do not try to dereference NULL buckets hash array.

  This seems to happen on ia64 for rtld object itself where the
  R_IA_64_FPTR64LSB relocations require symbol lookup.  The dynamic
  linker itself does not rely on identity of the C-level function
  pointers (i.e. function descriptors).

Taken verbatim from:
FreeBSD SVN 235054 (05 MAY 2012)
rtld: Sync 2/7 - Remove potential map leakage

Eliminate the static buffer used to read the first page of the mapped
object, and eliminate the pread(2) call as well.  Mmap the first page
of the object temporarily and unmap it on error or last use.  Potentially
this leaves a one page gap between succeeding dlopen(3), but there are
other mmap(2) consumers as well.

This fixes several cases where the whole mapping of the object leaked
upon error.  The MAP_PREFAULT_READ code had to be skipped because the
mmap on DragonFly doesn't support this flag.

----

Map libraries linked with -Ttext-segment=base_addr at base_addr.
Normal libraries have a base address of zero and are unaffected by this
change.

Taken from:
FreeBSD SVN 237058 (14 JUN 2012)
FreeBSD SVN 247396 (27 FEB 2013)
rtld: Sync 3/7 - LD_PRELOAD and z_nodeflib fix

Do not reference z_nodeflib for !objgiven case in order to fix LD_PRELOAD
for a non-absolute path.

Taken from:
FreeBSD SVN 240686 (18 SEP 2012)
rtld: Sync 4/7 - Fix token substitution

The origin_subst_one() function limits the length of the string to
PATH_MAX after the token substitution.  This is wrong, because
origin_subst_one() performs the substitution on the whole rpath and
similar strings, which contain several pathes separated by colon.  As
result, a long (but correct) rpath consisting of many path elements is
rejected by the function.

Correct the problem by rewriting the origin_subst_one() to perform two
passes, first pass to calculate the number of substitutions to be
performed, and second pass to generate the resulting string.  Second
pass allocates the memory for the result based on the count from the
first pass, without enforcing a limit.

Taken verbatim from:
FreeBSD SVN 249525 (15 APR 2013)
FreeBSD SVN 250075 (29 APR 2013)
rtld: Sync 5/7 - Fix fd leak with parallel dlopen and fork

Rtld did not set FD_CLOEXEC on its internal file descriptors; therefore,
such a file descriptor may be passed to a process created by another
thread running in parallel to dlopen() or fdlopen().

No other threads are expected to be running during parsing of the hints
and libmap files but the file descriptors need not be passed to child
processes so add O_CLOEXEC there as well.

As the F_DUPFD_CLOEXEC support was added in the kernel today, rtld
will temporarily fall back to separate dup/cloexec commands if
F_DUPFD_CLOEXEC fails.  This fallback should be removed before
3.6 branches.

Taken from:
FreeBSD SVN 242587 (04 NOV 2012)
rtld: Sync 6/7 - Minimize differences from FreeBSD

DragonFly developed some rtld features before FreeBSD, and consequently
those features were ported back to FreeBSD.  Some portions of these
new lines were modified for various reasons, e.g. the variable names
weren't liked or additional constraints were deemed necessary such as
the ability to maintain the old (incorrect) behavior of RUNPATH.

In any case, there were minor differences including whitespace, and
this commit reduces those differences to ease future syncing.
rtld: Sync 7/7 - Use symbol versioning instead of exports mapping

Now that DragonFly has the symbol versioning framework in place, rtld
can leverage it by offloading the symbol export duties to it.  This
further reduces differences between FreeBSD and DragonFly linkers.
Keeping the exports table up to date after FreeBSD removed it was extra
work.
tools/netrate: Add simple tools to calculated multiple netperf results

netperf itself must be installed through dports.
Fix SEE ALSO sorting order in some manual pages.
/usr/share/mk: Install bsd.symver.mk and version_gen.awk