aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid E. O'Brien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
committerDavid E. O'Brien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
commitd9a447559bc04121f7c6682e64abe67efa154864 (patch)
treeb2f038222ff8a70f687652441df00d2b564c8abe /lib
parent3cbf5f97aafc2b249c509ee1162c47c9b28e591e (diff)
parentfbda3d5daeeb730a49d025b614b35a32f0319718 (diff)
downloadsrc-d9a447559bc04121f7c6682e64abe67efa154864.tar.gz
src-d9a447559bc04121f7c6682e64abe67efa154864.zip
Sync with HEAD.
Notes
Notes: svn path=/projects/bmake/; revision=246555
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile22
-rw-r--r--lib/atf/libatf-c++/Makefile4
-rw-r--r--lib/bind/config.h8
-rw-r--r--lib/bind/dns/Makefile1
-rw-r--r--lib/bind/isc/isc/platform.h8
-rw-r--r--lib/clang/Makefile29
-rw-r--r--lib/clang/clang.build.mk35
-rw-r--r--lib/clang/include/Makefile6
-rw-r--r--lib/clang/include/MipsGenAsmMatcher.inc2
-rw-r--r--lib/clang/include/MipsGenMCPseudoLowering.inc2
-rw-r--r--lib/clang/include/clang/AST/CommentCommandInfo.inc2
-rw-r--r--lib/clang/include/clang/AST/CommentHTMLTags.inc2
-rw-r--r--lib/clang/include/clang/AST/CommentHTMLTagsProperties.inc2
-rw-r--r--lib/clang/include/clang/Basic/Version.inc4
-rw-r--r--lib/clang/include/llvm/Config/config.h6
-rw-r--r--lib/clang/libclanganalysis/Makefile6
-rw-r--r--lib/clang/libclangarcmigrate/Makefile2
-rw-r--r--lib/clang/libclangast/Makefile5
-rw-r--r--lib/clang/libclangbasic/Makefile2
-rw-r--r--lib/clang/libclangcodegen/Makefile2
-rw-r--r--lib/clang/libclangdriver/Makefile2
-rw-r--r--lib/clang/libclangedit/Makefile2
-rw-r--r--lib/clang/libclangfrontend/Makefile2
-rw-r--r--lib/clang/libclangfrontendtool/Makefile2
-rw-r--r--lib/clang/libclanglex/Makefile2
-rw-r--r--lib/clang/libclangparse/Makefile2
-rw-r--r--lib/clang/libclangrewrite/Makefile.depend79
-rw-r--r--lib/clang/libclangrewritecore/Makefile20
-rw-r--r--lib/clang/libclangrewritefrontend/Makefile (renamed from lib/clang/libclangrewrite/Makefile)16
-rw-r--r--lib/clang/libclangsema/Makefile5
-rw-r--r--lib/clang/libclangserialization/Makefile2
-rw-r--r--lib/clang/libclangstaticanalyzercheckers/Makefile10
-rw-r--r--lib/clang/libclangstaticanalyzercore/Makefile9
-rw-r--r--lib/clang/libclangstaticanalyzerfrontend/Makefile2
-rw-r--r--lib/clang/libllvmanalysis/Makefile5
-rw-r--r--lib/clang/libllvmarchive/Makefile2
-rw-r--r--lib/clang/libllvmarmasmparser/Makefile2
-rw-r--r--lib/clang/libllvmarmcodegen/Makefile3
-rw-r--r--lib/clang/libllvmarmdesc/Makefile2
-rw-r--r--lib/clang/libllvmarmdisassembler/Makefile2
-rw-r--r--lib/clang/libllvmarminfo/Makefile2
-rw-r--r--lib/clang/libllvmarminstprinter/Makefile2
-rw-r--r--lib/clang/libllvmasmparser/Makefile2
-rw-r--r--lib/clang/libllvmasmprinter/Makefile2
-rw-r--r--lib/clang/libllvmbitreader/Makefile2
-rw-r--r--lib/clang/libllvmbitwriter/Makefile2
-rw-r--r--lib/clang/libllvmcodegen/Makefile15
-rw-r--r--lib/clang/libllvmcore/Makefile5
-rw-r--r--lib/clang/libllvmdebuginfo/Makefile3
-rw-r--r--lib/clang/libllvmexecutionengine/Makefile2
-rw-r--r--lib/clang/libllvminstcombine/Makefile2
-rw-r--r--lib/clang/libllvminstrumentation/Makefile4
-rw-r--r--lib/clang/libllvminterpreter/Makefile2
-rw-r--r--lib/clang/libllvmipo/Makefile1
-rw-r--r--lib/clang/libllvmjit/Makefile2
-rw-r--r--lib/clang/libllvmlinker/Makefile2
-rw-r--r--lib/clang/libllvmmcdisassembler/Makefile2
-rw-r--r--lib/clang/libllvmmcjit/Makefile4
-rw-r--r--lib/clang/libllvmmcparser/Makefile2
-rw-r--r--lib/clang/libllvmmipsasmparser/Makefile5
-rw-r--r--lib/clang/libllvmmipscodegen/Makefile3
-rw-r--r--lib/clang/libllvmmipsdesc/Makefile3
-rw-r--r--lib/clang/libllvmmipsdisassembler/Makefile2
-rw-r--r--lib/clang/libllvmmipsinfo/Makefile2
-rw-r--r--lib/clang/libllvmmipsinstprinter/Makefile2
-rw-r--r--lib/clang/libllvmobject/Makefile2
-rw-r--r--lib/clang/libllvmpowerpccodegen/Makefile2
-rw-r--r--lib/clang/libllvmpowerpcdesc/Makefile2
-rw-r--r--lib/clang/libllvmpowerpcinfo/Makefile2
-rw-r--r--lib/clang/libllvmpowerpcinstprinter/Makefile2
-rw-r--r--lib/clang/libllvmruntimedyld/Makefile2
-rw-r--r--lib/clang/libllvmscalaropts/Makefile3
-rw-r--r--lib/clang/libllvmselectiondag/Makefile2
-rw-r--r--lib/clang/libllvmtablegen/Makefile3
-rw-r--r--lib/clang/libllvmtarget/Makefile8
-rw-r--r--lib/clang/libllvmtransformutils/Makefile7
-rw-r--r--lib/clang/libllvmvectorize/Makefile3
-rw-r--r--lib/clang/libllvmx86asmparser/Makefile2
-rw-r--r--lib/clang/libllvmx86codegen/Makefile3
-rw-r--r--lib/clang/libllvmx86desc/Makefile2
-rw-r--r--lib/clang/libllvmx86info/Makefile2
-rw-r--r--lib/clang/libllvmx86instprinter/Makefile2
-rw-r--r--lib/clang/libllvmx86utils/Makefile2
-rw-r--r--lib/csu/amd64/crt1.c4
-rw-r--r--lib/csu/arm/crt1.c5
-rw-r--r--lib/csu/common/ignore_init.c14
-rw-r--r--lib/csu/i386-elf/crt1_c.c5
-rw-r--r--lib/csu/mips/crt1.c4
-rw-r--r--lib/csu/powerpc/crt1.c4
-rw-r--r--lib/csu/powerpc64/crt1.c5
-rw-r--r--lib/csu/sparc64/crt1.c4
-rw-r--r--lib/libarchive/Makefile7
-rw-r--r--lib/libbsnmp/libbsnmp/Makefile1
-rw-r--r--lib/libc/amd64/sys/__vdso_gettc.c11
-rw-r--r--lib/libc/arm/Makefile.inc8
-rw-r--r--lib/libc/arm/SYS.h8
-rw-r--r--lib/libc/arm/Symbol.map4
-rw-r--r--lib/libc/arm/Symbol_oabi.map16
-rw-r--r--lib/libc/arm/aeabi/Makefile.inc11
-rw-r--r--lib/libc/arm/aeabi/Symbol.map47
-rw-r--r--lib/libc/arm/aeabi/aeabi_atexit.c38
-rw-r--r--lib/libc/arm/aeabi/aeabi_double.c101
-rw-r--r--lib/libc/arm/aeabi/aeabi_float.c101
-rw-r--r--lib/libc/arm/aeabi/aeabi_unwind_cpp.c61
-rw-r--r--lib/libc/arm/gen/Makefile.inc6
-rw-r--r--lib/libc/arm/softfloat/arm-gcc.h2
-rw-r--r--lib/libc/arm/sys/Makefile.inc2
-rw-r--r--lib/libc/arm/sys/__vdso_gettc.c (renamed from lib/libdisk/write_mips_disk.c)30
-rw-r--r--lib/libc/gen/Makefile.inc10
-rw-r--r--lib/libc/gen/Symbol.map14
-rw-r--r--lib/libc/gen/check_utility_compat.c12
-rw-r--r--lib/libc/gen/fmtmsg.c2
-rw-r--r--lib/libc/gen/fstab.c12
-rw-r--r--lib/libc/gen/getbsize.338
-rw-r--r--lib/libc/gen/getcap.c4
-rw-r--r--lib/libc/gen/getgrent.c8
-rw-r--r--lib/libc/gen/getnetgrent.c4
-rw-r--r--lib/libc/gen/getttyent.c2
-rw-r--r--lib/libc/gen/getusershell.c2
-rw-r--r--lib/libc/gen/getutxent.c2
-rw-r--r--lib/libc/gen/glob.c113
-rw-r--r--lib/libc/gen/isnan.c7
-rw-r--r--lib/libc/gen/sysctlbyname.c9
-rw-r--r--lib/libc/gen/unvis-compat.c46
-rw-r--r--lib/libc/gen/unvis.3200
-rw-r--r--lib/libc/gen/unvis.c293
-rw-r--r--lib/libc/gen/vis.3308
-rw-r--r--lib/libc/gen/vis.c201
-rw-r--r--lib/libc/gen/waitid.c65
-rw-r--r--lib/libc/i386/sys/__vdso_gettc.c10
-rw-r--r--lib/libc/ia64/sys/Makefile.inc2
-rw-r--r--lib/libc/ia64/sys/__vdso_gettc.c (renamed from lib/libdisk/write_arm_disk.c)31
-rw-r--r--lib/libc/iconv/citrus_mmap.c6
-rw-r--r--lib/libc/include/namespace.h1
-rw-r--r--lib/libc/include/un-namespace.h1
-rw-r--r--lib/libc/locale/collate.c2
-rw-r--r--lib/libc/locale/setrunelocale.c18
-rw-r--r--lib/libc/mips/sys/Makefile.inc2
-rw-r--r--lib/libc/mips/sys/__vdso_gettc.c48
-rw-r--r--lib/libc/net/getnetent.35
-rw-r--r--lib/libc/net/getprotoent.35
-rw-r--r--lib/libc/net/getservent.35
-rw-r--r--lib/libc/net/name6.c10
-rw-r--r--lib/libc/net/sctp_sys_calls.c86
-rw-r--r--lib/libc/nls/Makefile.inc3
-rw-r--r--lib/libc/nls/msgcat.c1
-rw-r--r--lib/libc/nls/zh_CN.GB18030.msg297
-rw-r--r--lib/libc/nls/zh_CN.GB2312.msg297
-rw-r--r--lib/libc/nls/zh_CN.UTF-8.msg295
-rw-r--r--lib/libc/powerpc/Makefile.inc2
-rw-r--r--lib/libc/powerpc/sys/__vdso_gettc.c48
-rw-r--r--lib/libc/powerpc64/Makefile.inc2
-rw-r--r--lib/libc/powerpc64/sys/__vdso_gettc.c48
-rw-r--r--lib/libc/quad/Makefile.inc4
-rw-r--r--lib/libc/sparc64/Makefile.inc2
-rw-r--r--lib/libc/sparc64/sys/__vdso_gettc.c48
-rw-r--r--lib/libc/stdio/Makefile.inc5
-rw-r--r--lib/libc/stdio/Symbol.map1
-rw-r--r--lib/libc/stdio/fdopen.c6
-rw-r--r--lib/libc/stdio/flags.c5
-rw-r--r--lib/libc/stdio/fmemopen.c258
-rw-r--r--lib/libc/stdio/fopen.371
-rw-r--r--lib/libc/stdio/freopen.c5
-rw-r--r--lib/libc/stdio/getline.34
-rw-r--r--lib/libc/stdio/printf.32
-rw-r--r--lib/libc/sys/Makefile.inc3
-rw-r--r--lib/libc/sys/Symbol.map3
-rw-r--r--lib/libc/sys/__vdso_gettimeofday.c4
-rw-r--r--lib/libc/sys/bind.22
-rw-r--r--lib/libc/sys/chroot.28
-rw-r--r--lib/libc/sys/getpeername.24
-rw-r--r--lib/libc/sys/getsockname.24
-rw-r--r--lib/libc/sys/gettimeofday.c5
-rw-r--r--lib/libc/sys/kqueue.26
-rw-r--r--lib/libc/sys/mlock.217
-rw-r--r--lib/libc/sys/mlockall.217
-rw-r--r--lib/libc/sys/open.213
-rw-r--r--lib/libc/sys/posix_fadvise.22
-rw-r--r--lib/libc/sys/ptrace.212
-rw-r--r--lib/libc/sys/rtprio.212
-rw-r--r--lib/libc/sys/sendfile.22
-rw-r--r--lib/libc/sys/socket.219
-rw-r--r--lib/libc/sys/wait.2311
-rw-r--r--lib/libcompiler_rt/Makefile32
-rw-r--r--lib/libcrypt/tests/Makefile10
-rw-r--r--lib/libcrypt/tests/crypt_tests.c54
-rw-r--r--lib/libcxxrt/Version.map118
-rw-r--r--lib/libdevstat/devstat.331
-rw-r--r--lib/libdevstat/devstat.c47
-rw-r--r--lib/libdevstat/devstat.h6
-rw-r--r--lib/libdisk/Makefile43
-rw-r--r--lib/libdisk/Makefile.depend16
-rw-r--r--lib/libdisk/blocks.c50
-rw-r--r--lib/libdisk/change.c129
-rw-r--r--lib/libdisk/chunk.c595
-rw-r--r--lib/libdisk/create_chunk.c296
-rw-r--r--lib/libdisk/disk.c411
-rw-r--r--lib/libdisk/libdisk.3341
-rw-r--r--lib/libdisk/libdisk.h368
-rw-r--r--lib/libdisk/open_disk.c311
-rw-r--r--lib/libdisk/open_ia64_disk.c239
-rw-r--r--lib/libdisk/rules.c296
-rw-r--r--lib/libdisk/tst01.c323
-rw-r--r--lib/libdisk/write_amd64_disk.c204
-rw-r--r--lib/libdisk/write_disk.c76
-rw-r--r--lib/libdisk/write_i386_disk.c204
-rw-r--r--lib/libdisk/write_ia64_disk.c423
-rw-r--r--lib/libdisk/write_pc98_disk.c179
-rw-r--r--lib/libdisk/write_sparc64_disk.c106
-rw-r--r--lib/libedit/editline.32
-rw-r--r--lib/libedit/editrc.57
-rw-r--r--lib/libedit/map.c4
-rw-r--r--lib/libfetch/http.c8
-rw-r--r--lib/libipsec/policy_parse.y1
-rw-r--r--lib/libnetbsd/Makefile13
-rw-r--r--lib/libnetbsd/README7
-rw-r--r--lib/libnetbsd/rmd160.h44
-rw-r--r--lib/libnetbsd/sha1.h43
-rw-r--r--lib/libnetbsd/sha2.h39
-rw-r--r--lib/libnetbsd/stdlib.h70
-rw-r--r--lib/libnetbsd/strsuftoll.c222
-rw-r--r--lib/libnetbsd/sys/cdefs.h50
-rw-r--r--lib/libnetbsd/util.c (renamed from lib/libdisk/write_powerpc_disk.c)53
-rw-r--r--lib/libnetbsd/util.h41
-rw-r--r--lib/libnetgraph/sock.c4
-rw-r--r--lib/libpmc/Makefile1
-rw-r--r--lib/libpmc/libpmc.c27
-rw-r--r--lib/libpmc/pmc.ivybridge.31
-rw-r--r--lib/libpmc/pmc.ivybridgexeon.3911
-rw-r--r--lib/libpmc/pmc.sandybridge.32
-rw-r--r--lib/libpmc/pmc.sandybridgexeon.31
-rw-r--r--lib/libproc/proc_bkpt.c3
-rw-r--r--lib/libproc/proc_regs.c8
-rw-r--r--lib/libproc/proc_rtld.c3
-rw-r--r--lib/libproc/test/t1-bkpt/t1-bkpt.c2
-rw-r--r--lib/libradius/Makefile1
-rw-r--r--lib/libradius/libradius.320
-rw-r--r--lib/libradius/radius.conf.516
-rw-r--r--lib/libradius/radlib.c204
-rw-r--r--lib/libradius/radlib.h5
-rw-r--r--lib/libradius/radlib_private.h9
-rw-r--r--lib/libradius/radlib_vs.h1
-rw-r--r--lib/libstand/Makefile13
-rw-r--r--lib/libstand/amd64/_setjmp.S93
-rw-r--r--lib/libstand/if_ether.h261
-rw-r--r--lib/libthr/thread/thr_init.c6
-rw-r--r--lib/libthr/thread/thr_kern.c5
-rw-r--r--lib/libutil/gr_util.c120
-rw-r--r--lib/libutil/libutil.h2
-rw-r--r--lib/libutil/pw_util.c7
-rw-r--r--lib/libvmmapi/Makefile11
-rw-r--r--lib/libvmmapi/vmmapi.c723
-rw-r--r--lib/libvmmapi/vmmapi.h105
-rw-r--r--lib/libvmmapi/vmmapi_freebsd.c183
-rw-r--r--lib/msun/src/k_rem_pio2.c2
-rw-r--r--lib/msun/src/s_isnan.c7
-rw-r--r--lib/ncurses/form/Makefile4
-rw-r--r--lib/ncurses/menu/Makefile4
-rw-r--r--lib/ncurses/ncurses/Makefile8
-rw-r--r--lib/ncurses/panel/Makefile4
260 files changed, 6112 insertions, 6555 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 199e08b92f24..14470029a604 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -69,7 +69,6 @@ SUBDIR= ${SUBDIR_ORDERED} \
libcompat \
libdevinfo \
libdevstat \
- libdisk \
libdwarf \
libedit \
${_libefi} \
@@ -90,6 +89,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
${_libmilter} \
${_libmp} \
${_libnandfs} \
+ libnetbsd \
${_libngatm} \
libopie \
libpam \
@@ -115,6 +115,7 @@ SUBDIR= ${SUBDIR_ORDERED} \
${_libusbhid} \
${_libusb} \
${_libvgl} \
+ ${_libvmmapi} \
libwrap \
liby \
libz \
@@ -176,6 +177,11 @@ _libiconv_modules= libiconv_modules
_libipx= libipx
.endif
+.if ${MK_LIBCPLUSPLUS} != "no"
+_libcxxrt= libcxxrt
+_libcplusplus= libc++
+.endif
+
.if ${MK_LIBTHR} != "no"
_libthr= libthr
.endif
@@ -198,6 +204,10 @@ _libproc= libproc
_librtld_db= librtld_db
.endif
+.if ${MACHINE_CPUARCH} == "amd64"
+_libvmmapi= libvmmapi
+.endif
+
.if ${MACHINE_CPUARCH} == "ia64"
_libefi= libefi
.endif
@@ -207,13 +217,13 @@ _libproc= libproc
_librtld_db= librtld_db
.endif
-.if ${MK_OPENSSL} != "no"
-_libmp= libmp
+.if ${MACHINE_CPUARCH} == "powerpc"
+_libproc= libproc
+_librtld_db= librtld_db
.endif
-.if ${MK_LIBCPLUSPLUS} != "no"
-_libcxxrt= libcxxrt
-_libcplusplus= libc++
+.if ${MK_OPENSSL} != "no"
+_libmp= libmp
.endif
.if ${MK_PMC} != "no"
diff --git a/lib/atf/libatf-c++/Makefile b/lib/atf/libatf-c++/Makefile
index 71369e27c54b..37d6073dbb3e 100644
--- a/lib/atf/libatf-c++/Makefile
+++ b/lib/atf/libatf-c++/Makefile
@@ -32,7 +32,9 @@ SHLIB_MAJOR= 1
# libatf-c++ depends on the C version of the ATF library to build.
DPADD= ${LIBATFC}
-LDADD= -L${.OBJDIR}/../libatf-c -latf-c
+LDADD= -latf-c
+
+LDFLAGS+= -L${.OBJDIR}/../libatf-c
.PATH: ${ATF}
.PATH: ${ATF}/atf-c++
diff --git a/lib/bind/config.h b/lib/bind/config.h
index 22d76bc60494..5e9d74b66010 100644
--- a/lib/bind/config.h
+++ b/lib/bind/config.h
@@ -3,7 +3,7 @@
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.in by autoheader. */
/*
- * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004, 2005, 2007, 2008, 2012 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -141,6 +141,9 @@ int sigwait(const unsigned int *set, int *sig);
/* Define if OpenSSL includes DSA support */
#define HAVE_OPENSSL_DSA 1
+/* Define if OpenSSL includes ECDSA support */
+#define HAVE_OPENSSL_ECDSA 1
+
/* Define to the length type used by the socket API (socklen_t, size_t, int). */
#define ISC_SOCKADDR_LEN_T socklen_t
@@ -202,6 +205,9 @@ int sigwait(const unsigned int *set, int *sig);
/* Define to 1 if you have the `EVP_sha256' function. */
#define HAVE_EVP_SHA256 1
+/* Define to 1 if you have the `EVP_sha384' function. */
+#define HAVE_EVP_SHA384 1
+
/* Define to 1 if you have the `EVP_sha512' function. */
#define HAVE_EVP_SHA512 1
diff --git a/lib/bind/dns/Makefile b/lib/bind/dns/Makefile
index 159de00c5d13..89dfd408286b 100644
--- a/lib/bind/dns/Makefile
+++ b/lib/bind/dns/Makefile
@@ -26,6 +26,7 @@ SRCS+= acache.c acl.c adb.c byaddr.c \
name.c ncache.c nsec.c nsec3.c \
openssl_link.c openssldh_link.c \
openssldsa_link.c opensslgost_link.c opensslrsa_link.c \
+ opensslecdsa_link.c \
order.c peer.c portlist.c private.c \
rbt.c rbtdb.c rbtdb64.c rcode.c rdata.c rdatalist.c \
rdataset.c rdatasetiter.c rdataslab.c request.c \
diff --git a/lib/bind/isc/isc/platform.h b/lib/bind/isc/isc/platform.h
index 7dab49516440..61630f4be6cc 100644
--- a/lib/bind/isc/isc/platform.h
+++ b/lib/bind/isc/isc/platform.h
@@ -17,7 +17,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: platform.h.in,v 1.56 2010-12-18 01:56:23 each Exp $ */
+/* $Id: platform.h.in,v 1.56 2010/12/18 01:56:23 each Exp $ */
#ifndef ISC_PLATFORM_H
#define ISC_PLATFORM_H 1
@@ -219,19 +219,19 @@
* Defined to <gssapi.h> or <gssapi/gssapi.h> for how to include
* the GSSAPI header.
*/
-
+#define ISC_PLATFORM_GSSAPIHEADER <gssapi/gssapi.h>
/*
* Defined to <gssapi_krb5.h> or <gssapi/gssapi_krb5.h> for how to
* include the GSSAPI KRB5 header.
*/
-
+#define ISC_PLATFORM_GSSAPI_KRB5_HEADER <gssapi/gssapi_krb5.h>
/*
* Defined to <krb5.h> or <krb5/krb5.h> for how to include
* the KRB5 header.
*/
-
+#define ISC_PLATFORM_KRB5HEADER <krb5.h>
/*
* Type used for resource limits.
diff --git a/lib/clang/Makefile b/lib/clang/Makefile
index dde515e58758..a77d241986f3 100644
--- a/lib/clang/Makefile
+++ b/lib/clang/Makefile
@@ -3,8 +3,20 @@
.include <bsd.own.mk>
.if !make(install)
+.if !defined(EARLY_BUILD) && defined(MK_CLANG_FULL) && ${MK_CLANG_FULL} != "no"
+_libclangstaticanalyzer= \
+ libclangstaticanalyzercheckers \
+ libclangstaticanalyzercore \
+ libclangstaticanalyzerfrontend
+_libclangarcmigrate= \
+ libclangarcmigrate
+_libclangrewriter= \
+ libclangrewritecore \
+ libclangrewritefrontend
+.endif # !EARLY_BUILD && MK_CLANG_FULL
+
SUBDIR= libclanganalysis \
- libclangarcmigrate \
+ ${_libclangarcmigrate} \
libclangast \
libclangbasic \
libclangcodegen \
@@ -14,12 +26,10 @@ SUBDIR= libclanganalysis \
libclangfrontendtool \
libclanglex \
libclangparse \
- libclangrewrite \
+ ${_libclangrewriter} \
libclangsema \
libclangserialization \
- libclangstaticanalyzercheckers \
- libclangstaticanalyzercore \
- libclangstaticanalyzerfrontend \
+ ${_libclangstaticanalyzer} \
\
libllvmanalysis \
libllvmarchive \
@@ -70,18 +80,15 @@ SUBDIR= libclanganalysis \
libllvmx86utils
.if ${MK_CLANG_EXTRAS} != "no"
-SUBDIR+=libllvmarchive \
- libllvmdebuginfo \
+SUBDIR+=libllvmdebuginfo \
libllvmexecutionengine \
libllvminterpreter \
libllvmjit \
- libllvmlinker \
libllvmmcdisassembler \
libllvmmcjit \
- libllvmobject \
libllvmruntimedyld
-.endif
-.endif
+.endif # MK_CLANG_EXTRAS
+.endif # !make(install)
SUBDIR+= include
diff --git a/lib/clang/clang.build.mk b/lib/clang/clang.build.mk
index 40dc4ab75c76..0015e3d12bdb 100644
--- a/lib/clang/clang.build.mk
+++ b/lib/clang/clang.build.mk
@@ -8,6 +8,12 @@ CFLAGS+= -I${LLVM_SRCS}/include -I${CLANG_SRCS}/include \
-DLLVM_ON_UNIX -DLLVM_ON_FREEBSD \
-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS #-DNDEBUG
+.if !defined(EARLY_BUILD) && defined(MK_CLANG_FULL) && ${MK_CLANG_FULL} != "no"
+CFLAGS+= -DCLANG_ENABLE_ARCMT \
+ -DCLANG_ENABLE_REWRITER \
+ -DCLANG_ENABLE_STATIC_ANALYZER
+.endif # !EARLY_BUILD && MK_CLANG_FULL
+
# LLVM is not strict aliasing safe as of 12/31/2011
CFLAGS+= -fno-strict-aliasing
@@ -16,20 +22,9 @@ BUILD_ARCH?= ${MACHINE_ARCH}
TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/}-unknown-freebsd10.0
BUILD_TRIPLE?= ${BUILD_ARCH:C/amd64/x86_64/}-unknown-freebsd10.0
CFLAGS+= -DLLVM_DEFAULT_TARGET_TRIPLE=\"${TARGET_TRIPLE}\" \
- -DLLVM_HOSTTRIPLE=\"${BUILD_TRIPLE}\"
-
-.ifndef LLVM_REQUIRES_EH
-CXXFLAGS+= -fno-exceptions
-.else
-# If the library or program requires EH, it also requires RTTI.
-LLVM_REQUIRES_RTTI=
-.endif
-
-.ifndef LLVM_REQUIRES_RTTI
-CXXFLAGS+= -fno-rtti
-.endif
-
-CFLAGS+= -DDEFAULT_SYSROOT=\"${TOOLS_PREFIX}\"
+ -DLLVM_HOSTTRIPLE=\"${BUILD_TRIPLE}\" \
+ -DDEFAULT_SYSROOT=\"${TOOLS_PREFIX}\"
+CXXFLAGS+= -fno-exceptions -fno-rtti
.PATH: ${LLVM_SRCS}/${SRCDIR}
@@ -114,6 +109,18 @@ AttrTemplateInstantiate.inc.h: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-gen-clang-attr-template-instantiate -o ${.TARGET} \
-I ${CLANG_SRCS}/include ${.ALLSRC}
+CommentCommandInfo.inc.h: ${CLANG_SRCS}/include/clang/AST/CommentCommands.td
+ ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include/clang/AST ${TBLINC} \
+ -gen-clang-comment-command-info -o ${.TARGET} ${.ALLSRC}
+
+CommentHTMLTags.inc.h: ${CLANG_SRCS}/include/clang/AST/CommentHTMLTags.td
+ ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include/clang/AST ${TBLINC} \
+ -gen-clang-comment-html-tags -o ${.TARGET} ${.ALLSRC}
+
+CommentHTMLTagsProperties.inc.h: ${CLANG_SRCS}/include/clang/AST/CommentHTMLTags.td
+ ${CLANG_TBLGEN} -I ${CLANG_SRCS}/include/clang/AST ${TBLINC} \
+ -gen-clang-comment-html-tags-properties -o ${.TARGET} ${.ALLSRC}
+
CommentNodes.inc.h: ${CLANG_SRCS}/include/clang/Basic/CommentNodes.td
${CLANG_TBLGEN} -I ${CLANG_SRCS}/include/clang/AST ${TBLINC} \
-gen-clang-comment-nodes -o ${.TARGET} ${.ALLSRC}
diff --git a/lib/clang/include/Makefile b/lib/clang/include/Makefile
index 93d91c7dba80..918c6dff8ad9 100644
--- a/lib/clang/include/Makefile
+++ b/lib/clang/include/Makefile
@@ -4,7 +4,9 @@
INCSDIR=${INCLUDEDIR}/clang/3.2
-INCS= altivec.h \
+INCS= __wmmintrin_aes.h \
+ __wmmintrin_pclmul.h \
+ altivec.h \
ammintrin.h \
avx2intrin.h \
avxintrin.h \
@@ -12,6 +14,7 @@ INCS= altivec.h \
bmiintrin.h \
cpuid.h \
emmintrin.h \
+ f16cintrin.h \
fma4intrin.h \
fmaintrin.h \
immintrin.h \
@@ -23,6 +26,7 @@ INCS= altivec.h \
nmmintrin.h \
pmmintrin.h \
popcntintrin.h \
+ rtmintrin.h \
smmintrin.h \
tmmintrin.h \
wmmintrin.h \
diff --git a/lib/clang/include/MipsGenAsmMatcher.inc b/lib/clang/include/MipsGenAsmMatcher.inc
new file mode 100644
index 000000000000..b9e2fd13e430
--- /dev/null
+++ b/lib/clang/include/MipsGenAsmMatcher.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "MipsGenAsmMatcher.inc.h"
diff --git a/lib/clang/include/MipsGenMCPseudoLowering.inc b/lib/clang/include/MipsGenMCPseudoLowering.inc
new file mode 100644
index 000000000000..4e4cbbe8d285
--- /dev/null
+++ b/lib/clang/include/MipsGenMCPseudoLowering.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "MipsGenMCPseudoLowering.inc.h"
diff --git a/lib/clang/include/clang/AST/CommentCommandInfo.inc b/lib/clang/include/clang/AST/CommentCommandInfo.inc
new file mode 100644
index 000000000000..cd171900fc6d
--- /dev/null
+++ b/lib/clang/include/clang/AST/CommentCommandInfo.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "CommentCommandInfo.inc.h"
diff --git a/lib/clang/include/clang/AST/CommentHTMLTags.inc b/lib/clang/include/clang/AST/CommentHTMLTags.inc
new file mode 100644
index 000000000000..0932f3249928
--- /dev/null
+++ b/lib/clang/include/clang/AST/CommentHTMLTags.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "CommentHTMLTags.inc.h"
diff --git a/lib/clang/include/clang/AST/CommentHTMLTagsProperties.inc b/lib/clang/include/clang/AST/CommentHTMLTagsProperties.inc
new file mode 100644
index 000000000000..77af956f8193
--- /dev/null
+++ b/lib/clang/include/clang/AST/CommentHTMLTagsProperties.inc
@@ -0,0 +1,2 @@
+/* $FreeBSD$ */
+#include "CommentHTMLTagsProperties.inc.h"
diff --git a/lib/clang/include/clang/Basic/Version.inc b/lib/clang/include/clang/Basic/Version.inc
index d04836e26aa0..84a96a630c49 100644
--- a/lib/clang/include/clang/Basic/Version.inc
+++ b/lib/clang/include/clang/Basic/Version.inc
@@ -5,6 +5,6 @@
#define CLANG_VERSION_MINOR 2
#define CLANG_VENDOR "FreeBSD "
-#define CLANG_VENDOR_SUFFIX " 20120817"
+#define CLANG_VENDOR_SUFFIX " 20121221"
-#define SVN_REVISION "162107"
+#define SVN_REVISION "170710"
diff --git a/lib/clang/include/llvm/Config/config.h b/lib/clang/include/llvm/Config/config.h
index 15d7e2dfa034..1894727df545 100644
--- a/lib/clang/include/llvm/Config/config.h
+++ b/lib/clang/include/llvm/Config/config.h
@@ -8,6 +8,9 @@
/* Bug report URL. */
#define BUG_REPORT_URL "http://llvm.org/bugs/"
+/* Define if we have libxml2 */
+/* #undef CLANG_HAVE_LIBXML */
+
/* Relative directory for resource files */
#define CLANG_RESOURCE_DIR ""
@@ -17,6 +20,9 @@
/* Default <path> to all compiler invocations for --sysroot=<path>. */
/* #undef DEFAULT_SYSROOT */
+/* Define if you want backtraces on crash */
+#define ENABLE_BACKTRACES 1
+
/* Define if position independent code is enabled */
#define ENABLE_PIC 0
diff --git a/lib/clang/libclanganalysis/Makefile b/lib/clang/libclanganalysis/Makefile
index d96f5dc1eb2a..76bf1e5c8db6 100644
--- a/lib/clang/libclanganalysis/Makefile
+++ b/lib/clang/libclanganalysis/Makefile
@@ -1,17 +1,21 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clanganalysis
SRCDIR= tools/clang/lib/Analysis
SRCS= AnalysisDeclContext.cpp \
- CallGraph.cpp \
+ BodyFarm.cpp \
CFG.cpp \
CFGReachabilityAnalysis.cpp \
CFGStmtMap.cpp \
+ CallGraph.cpp \
CocoaConventions.cpp \
Dominators.cpp \
FormatString.cpp \
LiveVariables.cpp \
+ ObjCNoReturn.cpp \
PostOrderCFGView.cpp \
PrintfFormatString.cpp \
ProgramPoint.cpp \
diff --git a/lib/clang/libclangarcmigrate/Makefile b/lib/clang/libclangarcmigrate/Makefile
index 654480530bd3..7597e9c67f15 100644
--- a/lib/clang/libclangarcmigrate/Makefile
+++ b/lib/clang/libclangarcmigrate/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangarcmigrate
SRCDIR= tools/clang/lib/ARCMigrate
diff --git a/lib/clang/libclangast/Makefile b/lib/clang/libclangast/Makefile
index a80bc7e97bb6..0ddeb53080de 100644
--- a/lib/clang/libclangast/Makefile
+++ b/lib/clang/libclangast/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangast
SRCDIR= tools/clang/lib/AST
@@ -63,6 +65,9 @@ SRCS= APValue.cpp \
TGHDRS= AttrImpl \
AttrList \
Attrs \
+ CommentCommandInfo \
+ CommentHTMLTags \
+ CommentHTMLTagsProperties \
CommentNodes \
DeclNodes \
DiagnosticASTKinds \
diff --git a/lib/clang/libclangbasic/Makefile b/lib/clang/libclangbasic/Makefile
index f0efd7443662..eec941a2fe16 100644
--- a/lib/clang/libclangbasic/Makefile
+++ b/lib/clang/libclangbasic/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangbasic
SRCDIR= tools/clang/lib/Basic
diff --git a/lib/clang/libclangcodegen/Makefile b/lib/clang/libclangcodegen/Makefile
index 5252e7cd40d1..7aefa7c64489 100644
--- a/lib/clang/libclangcodegen/Makefile
+++ b/lib/clang/libclangcodegen/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangcodegen
SRCDIR= tools/clang/lib/CodeGen
diff --git a/lib/clang/libclangdriver/Makefile b/lib/clang/libclangdriver/Makefile
index 4950cface397..aae2a057f589 100644
--- a/lib/clang/libclangdriver/Makefile
+++ b/lib/clang/libclangdriver/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangdriver
SRCDIR= tools/clang/lib/Driver
diff --git a/lib/clang/libclangedit/Makefile b/lib/clang/libclangedit/Makefile
index a0e45a9c43d2..59b0b54e4e0d 100644
--- a/lib/clang/libclangedit/Makefile
+++ b/lib/clang/libclangedit/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangedit
SRCDIR= tools/clang/lib/Edit
diff --git a/lib/clang/libclangfrontend/Makefile b/lib/clang/libclangfrontend/Makefile
index c2813b4caef4..44ba2fb74325 100644
--- a/lib/clang/libclangfrontend/Makefile
+++ b/lib/clang/libclangfrontend/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangfrontend
SRCDIR= tools/clang/lib/Frontend
diff --git a/lib/clang/libclangfrontendtool/Makefile b/lib/clang/libclangfrontendtool/Makefile
index f37979f9a8c8..f20aa35a11a8 100644
--- a/lib/clang/libclangfrontendtool/Makefile
+++ b/lib/clang/libclangfrontendtool/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangfrontendtool
SRCDIR= tools/clang/lib/FrontendTool
diff --git a/lib/clang/libclanglex/Makefile b/lib/clang/libclanglex/Makefile
index 3ad0e3f78c23..768d43c1e79c 100644
--- a/lib/clang/libclanglex/Makefile
+++ b/lib/clang/libclanglex/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clanglex
SRCDIR= tools/clang/lib/Lex
diff --git a/lib/clang/libclangparse/Makefile b/lib/clang/libclangparse/Makefile
index 599a034cfbcc..dbe9adb03fb9 100644
--- a/lib/clang/libclangparse/Makefile
+++ b/lib/clang/libclangparse/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangparse
SRCDIR= tools/clang/lib/Parse
diff --git a/lib/clang/libclangrewrite/Makefile.depend b/lib/clang/libclangrewrite/Makefile.depend
deleted file mode 100644
index ea0e4417e589..000000000000
--- a/lib/clang/libclangrewrite/Makefile.depend
+++ /dev/null
@@ -1,79 +0,0 @@
-# Autogenerated - do NOT edit!
-
-DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
-
-DEP_MACHINE := ${.PARSEFILE:E}
-
-DIRDEPS = \
- include \
- include/xlocale \
- lib/msun \
-
-
-.include <dirdeps.mk>
-
-.if ${DEP_RELDIR} == ${_DEP_RELDIR}
-# local dependencies - needed for -jN in clean tree
-FixItRewriter.o: DiagnosticCommonKinds.inc.h
-FixItRewriter.o: DiagnosticFrontendKinds.inc.h
-FixItRewriter.po: DiagnosticCommonKinds.inc.h
-FixItRewriter.po: DiagnosticFrontendKinds.inc.h
-FrontendActions.o: AttrList.inc.h
-FrontendActions.o: AttrParsedAttrList.inc.h
-FrontendActions.o: Attrs.inc.h
-FrontendActions.o: DeclNodes.inc.h
-FrontendActions.o: DiagnosticCommonKinds.inc.h
-FrontendActions.o: DiagnosticFrontendKinds.inc.h
-FrontendActions.o: StmtNodes.inc.h
-FrontendActions.po: AttrList.inc.h
-FrontendActions.po: AttrParsedAttrList.inc.h
-FrontendActions.po: Attrs.inc.h
-FrontendActions.po: DeclNodes.inc.h
-FrontendActions.po: DiagnosticCommonKinds.inc.h
-FrontendActions.po: DiagnosticFrontendKinds.inc.h
-FrontendActions.po: StmtNodes.inc.h
-HTMLPrint.o: AttrList.inc.h
-HTMLPrint.o: Attrs.inc.h
-HTMLPrint.o: DeclNodes.inc.h
-HTMLPrint.o: DiagnosticCommonKinds.inc.h
-HTMLPrint.po: AttrList.inc.h
-HTMLPrint.po: Attrs.inc.h
-HTMLPrint.po: DeclNodes.inc.h
-HTMLPrint.po: DiagnosticCommonKinds.inc.h
-HTMLRewrite.o: DiagnosticCommonKinds.inc.h
-HTMLRewrite.po: DiagnosticCommonKinds.inc.h
-RewriteMacros.o: DiagnosticCommonKinds.inc.h
-RewriteMacros.po: DiagnosticCommonKinds.inc.h
-RewriteModernObjC.o: AttrList.inc.h
-RewriteModernObjC.o: Attrs.inc.h
-RewriteModernObjC.o: DeclNodes.inc.h
-RewriteModernObjC.o: DiagnosticCommonKinds.inc.h
-RewriteModernObjC.o: StmtNodes.inc.h
-RewriteModernObjC.po: AttrList.inc.h
-RewriteModernObjC.po: Attrs.inc.h
-RewriteModernObjC.po: DeclNodes.inc.h
-RewriteModernObjC.po: DiagnosticCommonKinds.inc.h
-RewriteModernObjC.po: StmtNodes.inc.h
-RewriteObjC.o: AttrList.inc.h
-RewriteObjC.o: Attrs.inc.h
-RewriteObjC.o: DeclNodes.inc.h
-RewriteObjC.o: DiagnosticCommonKinds.inc.h
-RewriteObjC.o: StmtNodes.inc.h
-RewriteObjC.po: AttrList.inc.h
-RewriteObjC.po: Attrs.inc.h
-RewriteObjC.po: DeclNodes.inc.h
-RewriteObjC.po: DiagnosticCommonKinds.inc.h
-RewriteObjC.po: StmtNodes.inc.h
-RewriteTest.o: DiagnosticCommonKinds.inc.h
-RewriteTest.po: DiagnosticCommonKinds.inc.h
-Rewriter.o: AttrList.inc.h
-Rewriter.o: Attrs.inc.h
-Rewriter.o: DeclNodes.inc.h
-Rewriter.o: DiagnosticCommonKinds.inc.h
-Rewriter.o: StmtNodes.inc.h
-Rewriter.po: AttrList.inc.h
-Rewriter.po: Attrs.inc.h
-Rewriter.po: DeclNodes.inc.h
-Rewriter.po: DiagnosticCommonKinds.inc.h
-Rewriter.po: StmtNodes.inc.h
-.endif
diff --git a/lib/clang/libclangrewritecore/Makefile b/lib/clang/libclangrewritecore/Makefile
new file mode 100644
index 000000000000..80115ee01891
--- /dev/null
+++ b/lib/clang/libclangrewritecore/Makefile
@@ -0,0 +1,20 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= clangrewritecore
+
+SRCDIR= tools/clang/lib/Rewrite/Core
+SRCS= DeltaTree.cpp \
+ HTMLRewrite.cpp \
+ RewriteRope.cpp \
+ Rewriter.cpp \
+ TokenRewriter.cpp
+
+TGHDRS= AttrList \
+ Attrs \
+ DeclNodes \
+ DiagnosticCommonKinds \
+ StmtNodes
+
+.include "../clang.lib.mk"
diff --git a/lib/clang/libclangrewrite/Makefile b/lib/clang/libclangrewritefrontend/Makefile
index e165b0b914c8..ffa11b4fe328 100644
--- a/lib/clang/libclangrewrite/Makefile
+++ b/lib/clang/libclangrewritefrontend/Makefile
@@ -1,26 +1,22 @@
# $FreeBSD$
-LIB= clangrewrite
+.include <bsd.own.mk>
-SRCDIR= tools/clang/lib/Rewrite
-SRCS= DeltaTree.cpp \
- FixItRewriter.cpp \
+LIB= clangrewritefrontend
+
+SRCDIR= tools/clang/lib/Rewrite/Frontend
+SRCS= FixItRewriter.cpp \
FrontendActions.cpp \
HTMLPrint.cpp \
- HTMLRewrite.cpp \
InclusionRewriter.cpp \
RewriteMacros.cpp \
RewriteModernObjC.cpp \
RewriteObjC.cpp \
- RewriteRope.cpp \
- RewriteTest.cpp \
- Rewriter.cpp \
- TokenRewriter.cpp
+ RewriteTest.cpp
TGHDRS= AttrList \
AttrParsedAttrList \
Attrs \
- CommentNodes \
DeclNodes \
DiagnosticCommonKinds \
DiagnosticFrontendKinds \
diff --git a/lib/clang/libclangsema/Makefile b/lib/clang/libclangsema/Makefile
index 83a1c5626d7b..9ced8b4c6895 100644
--- a/lib/clang/libclangsema/Makefile
+++ b/lib/clang/libclangsema/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangsema
SRCDIR= tools/clang/lib/Sema
@@ -10,7 +12,9 @@ SRCS= AnalysisBasedWarnings.cpp \
DelayedDiagnostic.cpp \
IdentifierResolver.cpp \
JumpDiagnostics.cpp \
+ MultiplexExternalSemaSource.cpp \
Scope.cpp \
+ ScopeInfo.cpp \
Sema.cpp \
SemaAccess.cpp \
SemaAttr.cpp \
@@ -36,6 +40,7 @@ SRCS= AnalysisBasedWarnings.cpp \
SemaOverload.cpp \
SemaPseudoObject.cpp \
SemaStmt.cpp \
+ SemaStmtAsm.cpp \
SemaStmtAttr.cpp \
SemaTemplate.cpp \
SemaTemplateDeduction.cpp \
diff --git a/lib/clang/libclangserialization/Makefile b/lib/clang/libclangserialization/Makefile
index 75f68bf74e6a..962bbf09b5c8 100644
--- a/lib/clang/libclangserialization/Makefile
+++ b/lib/clang/libclangserialization/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangserialization
SRCDIR= tools/clang/lib/Serialization
diff --git a/lib/clang/libclangstaticanalyzercheckers/Makefile b/lib/clang/libclangstaticanalyzercheckers/Makefile
index 1ad97b256c86..95361519d8d8 100644
--- a/lib/clang/libclangstaticanalyzercheckers/Makefile
+++ b/lib/clang/libclangstaticanalyzercheckers/Makefile
@@ -1,10 +1,11 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangstaticanalyzercheckers
SRCDIR= tools/clang/lib/StaticAnalyzer/Checkers
-SRCS= AdjustedReturnValueChecker.cpp \
- AnalyzerStatsChecker.cpp \
+SRCS= AnalyzerStatsChecker.cpp \
ArrayBoundChecker.cpp \
ArrayBoundCheckerV2.cpp \
AttrNonNullChecker.cpp \
@@ -27,12 +28,14 @@ SRCS= AdjustedReturnValueChecker.cpp \
DeadStoresChecker.cpp \
DebugCheckers.cpp \
DereferenceChecker.cpp \
+ DirectIvarAssignment.cpp \
DivZeroChecker.cpp \
DynamicTypePropagation.cpp \
ExprInspectionChecker.cpp \
FixedAddressChecker.cpp \
GenericTaintChecker.cpp \
IdempotentOperationChecker.cpp \
+ IvarInvalidationChecker.cpp \
LLVMConventionsChecker.cpp \
MacOSKeychainAPIChecker.cpp \
MacOSXAPIChecker.cpp \
@@ -42,10 +45,10 @@ SRCS= AdjustedReturnValueChecker.cpp \
NSAutoreleasePoolChecker.cpp \
NSErrorChecker.cpp \
NoReturnFunctionChecker.cpp \
- OSAtomicChecker.cpp \
ObjCAtSyncChecker.cpp \
ObjCContainersASTChecker.cpp \
ObjCContainersChecker.cpp \
+ ObjCMissingSuperCallChecker.cpp \
ObjCSelfInitChecker.cpp \
ObjCUnusedIVarsChecker.cpp \
PointerArithChecker.cpp \
@@ -54,6 +57,7 @@ SRCS= AdjustedReturnValueChecker.cpp \
RetainCountChecker.cpp \
ReturnPointerRangeChecker.cpp \
ReturnUndefChecker.cpp \
+ SimpleStreamChecker.cpp \
StackAddrEscapeChecker.cpp \
StreamChecker.cpp \
TaintTesterChecker.cpp \
diff --git a/lib/clang/libclangstaticanalyzercore/Makefile b/lib/clang/libclangstaticanalyzercore/Makefile
index 75b3d66ec33e..9c263f03d5b5 100644
--- a/lib/clang/libclangstaticanalyzercore/Makefile
+++ b/lib/clang/libclangstaticanalyzercore/Makefile
@@ -1,11 +1,13 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangstaticanalyzercore
SRCDIR= tools/clang/lib/StaticAnalyzer/Core
-SRCS= AnalysisManager.cpp \
- APSIntType.cpp \
- BasicConstraintManager.cpp \
+SRCS= APSIntType.cpp \
+ AnalysisManager.cpp \
+ AnalyzerOptions.cpp \
BasicValueFactory.cpp \
BlockCounter.cpp \
BugReporter.cpp \
@@ -16,6 +18,7 @@ SRCS= AnalysisManager.cpp \
CheckerHelpers.cpp \
CheckerManager.cpp \
CheckerRegistry.cpp \
+ ConstraintManager.cpp \
CoreEngine.cpp \
Environment.cpp \
ExplodedGraph.cpp \
diff --git a/lib/clang/libclangstaticanalyzerfrontend/Makefile b/lib/clang/libclangstaticanalyzerfrontend/Makefile
index 5c7cd4109fa9..9e19f923d7a0 100644
--- a/lib/clang/libclangstaticanalyzerfrontend/Makefile
+++ b/lib/clang/libclangstaticanalyzerfrontend/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= clangstaticanalyzerfrontend
SRCDIR= tools/clang/lib/StaticAnalyzer/Frontend
diff --git a/lib/clang/libllvmanalysis/Makefile b/lib/clang/libllvmanalysis/Makefile
index cb1e345c0ad3..3c01352115d2 100644
--- a/lib/clang/libllvmanalysis/Makefile
+++ b/lib/clang/libllvmanalysis/Makefile
@@ -18,7 +18,9 @@ SRCS= AliasAnalysis.cpp \
CaptureTracking.cpp \
CodeMetrics.cpp \
ConstantFolding.cpp \
+ CostModel.cpp \
DbgInfoPrinter.cpp \
+ DependenceAnalysis.cpp \
DomPrinter.cpp \
DominanceFrontier.cpp \
IVUsers.cpp \
@@ -32,7 +34,6 @@ SRCS= AliasAnalysis.cpp \
LibCallSemantics.cpp \
Lint.cpp \
Loads.cpp \
- LoopDependenceAnalysis.cpp \
LoopInfo.cpp \
LoopPass.cpp \
MemDepPrinter.cpp \
@@ -50,6 +51,8 @@ SRCS= AliasAnalysis.cpp \
ProfileInfoLoader.cpp \
ProfileInfoLoaderPass.cpp \
ProfileVerifierPass.cpp \
+ ProfileDataLoader.cpp \
+ ProfileDataLoaderPass.cpp \
RegionInfo.cpp \
RegionPass.cpp \
RegionPrinter.cpp \
diff --git a/lib/clang/libllvmarchive/Makefile b/lib/clang/libllvmarchive/Makefile
index a28f2f510a69..d5534050083c 100644
--- a/lib/clang/libllvmarchive/Makefile
+++ b/lib/clang/libllvmarchive/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmarchive
SRCDIR= lib/Archive
diff --git a/lib/clang/libllvmarmasmparser/Makefile b/lib/clang/libllvmarmasmparser/Makefile
index c3d0d8902321..05e6263aa894 100644
--- a/lib/clang/libllvmarmasmparser/Makefile
+++ b/lib/clang/libllvmarmasmparser/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmarmasmparser
SRCDIR= lib/Target/ARM/AsmParser
diff --git a/lib/clang/libllvmarmcodegen/Makefile b/lib/clang/libllvmarmcodegen/Makefile
index b18f12c8fcd9..6a10eaf0825f 100644
--- a/lib/clang/libllvmarmcodegen/Makefile
+++ b/lib/clang/libllvmarmcodegen/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmarmcodegen
SRCDIR= lib/Target/ARM
@@ -9,7 +11,6 @@ SRCS= ARMAsmPrinter.cpp \
ARMCodeEmitter.cpp \
ARMConstantIslandPass.cpp \
ARMConstantPoolValue.cpp \
- ARMELFWriterInfo.cpp \
ARMExpandPseudoInsts.cpp \
ARMFastISel.cpp \
ARMFrameLowering.cpp \
diff --git a/lib/clang/libllvmarmdesc/Makefile b/lib/clang/libllvmarmdesc/Makefile
index bd2e0cb96b7d..61679a666683 100644
--- a/lib/clang/libllvmarmdesc/Makefile
+++ b/lib/clang/libllvmarmdesc/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmarmdesc
SRCDIR= lib/Target/ARM/MCTargetDesc
diff --git a/lib/clang/libllvmarmdisassembler/Makefile b/lib/clang/libllvmarmdisassembler/Makefile
index a3d16f78416b..eb4673672b1d 100644
--- a/lib/clang/libllvmarmdisassembler/Makefile
+++ b/lib/clang/libllvmarmdisassembler/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmarmdisassembler
SRCDIR= lib/Target/ARM/Disassembler
diff --git a/lib/clang/libllvmarminfo/Makefile b/lib/clang/libllvmarminfo/Makefile
index ec88367bc328..1da434c71a0d 100644
--- a/lib/clang/libllvmarminfo/Makefile
+++ b/lib/clang/libllvmarminfo/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmarminfo
SRCDIR= lib/Target/ARM/TargetInfo
diff --git a/lib/clang/libllvmarminstprinter/Makefile b/lib/clang/libllvmarminstprinter/Makefile
index ca7e7d4ff0a8..67b8fee26965 100644
--- a/lib/clang/libllvmarminstprinter/Makefile
+++ b/lib/clang/libllvmarminstprinter/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmarminstprinter
SRCDIR= lib/Target/ARM/InstPrinter
diff --git a/lib/clang/libllvmasmparser/Makefile b/lib/clang/libllvmasmparser/Makefile
index 8ceba6934928..bb8f0dfda238 100644
--- a/lib/clang/libllvmasmparser/Makefile
+++ b/lib/clang/libllvmasmparser/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmasmparser
SRCDIR= lib/AsmParser
diff --git a/lib/clang/libllvmasmprinter/Makefile b/lib/clang/libllvmasmprinter/Makefile
index 36e626fc3427..97bc73d3f41d 100644
--- a/lib/clang/libllvmasmprinter/Makefile
+++ b/lib/clang/libllvmasmprinter/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmasmprinter
SRCDIR= lib/CodeGen/AsmPrinter
diff --git a/lib/clang/libllvmbitreader/Makefile b/lib/clang/libllvmbitreader/Makefile
index c426680b32ce..094e0e773304 100644
--- a/lib/clang/libllvmbitreader/Makefile
+++ b/lib/clang/libllvmbitreader/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmbitreader
SRCDIR= lib/Bitcode/Reader
diff --git a/lib/clang/libllvmbitwriter/Makefile b/lib/clang/libllvmbitwriter/Makefile
index 3431b219886b..1cb9d411281e 100644
--- a/lib/clang/libllvmbitwriter/Makefile
+++ b/lib/clang/libllvmbitwriter/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmbitwriter
SRCDIR= lib/Bitcode/Writer
diff --git a/lib/clang/libllvmcodegen/Makefile b/lib/clang/libllvmcodegen/Makefile
index a0db98f35ebb..e65d19ce275d 100644
--- a/lib/clang/libllvmcodegen/Makefile
+++ b/lib/clang/libllvmcodegen/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmcodegen
SRCDIR= lib/CodeGen
@@ -12,8 +14,8 @@ SRCS= AggressiveAntiDepBreaker.cpp \
CodeGen.cpp \
CodePlacementOpt.cpp \
CriticalAntiDepBreaker.cpp \
- DeadMachineInstructionElim.cpp \
DFAPacketizer.cpp \
+ DeadMachineInstructionElim.cpp \
DwarfEHPrepare.cpp \
EarlyIfConversion.cpp \
EdgeBundles.cpp \
@@ -35,19 +37,19 @@ SRCS= AggressiveAntiDepBreaker.cpp \
LiveInterval.cpp \
LiveIntervalAnalysis.cpp \
LiveIntervalUnion.cpp \
+ LiveRangeCalc.cpp \
+ LiveRangeEdit.cpp \
LiveRegMatrix.cpp \
LiveStackAnalysis.cpp \
LiveVariables.cpp \
- LiveRangeCalc.cpp \
- LiveRangeEdit.cpp \
LocalStackSlotAllocation.cpp \
MachineBasicBlock.cpp \
MachineBlockFrequencyInfo.cpp \
MachineBlockPlacement.cpp \
MachineBranchProbabilityInfo.cpp \
+ MachineCSE.cpp \
MachineCodeEmitter.cpp \
MachineCopyPropagation.cpp \
- MachineCSE.cpp \
MachineDominators.cpp \
MachineFunction.cpp \
MachineFunctionAnalysis.cpp \
@@ -61,6 +63,7 @@ SRCS= AggressiveAntiDepBreaker.cpp \
MachineModuleInfo.cpp \
MachineModuleInfoImpls.cpp \
MachinePassRegistry.cpp \
+ MachinePostDominators.cpp \
MachineRegisterInfo.cpp \
MachineSSAUpdater.cpp \
MachineScheduler.cpp \
@@ -94,9 +97,10 @@ SRCS= AggressiveAntiDepBreaker.cpp \
ShrinkWrapping.cpp \
SjLjEHPrepare.cpp \
SlotIndexes.cpp \
- Spiller.cpp \
SpillPlacement.cpp \
+ Spiller.cpp \
SplitKit.cpp \
+ StackColoring.cpp \
StackProtector.cpp \
StackSlotColoring.cpp \
StrongPHIElimination.cpp \
@@ -105,6 +109,7 @@ SRCS= AggressiveAntiDepBreaker.cpp \
TargetInstrInfoImpl.cpp \
TargetLoweringObjectFileImpl.cpp \
TargetOptionsImpl.cpp \
+ TargetSchedule.cpp \
TwoAddressInstructionPass.cpp \
UnreachableBlockElim.cpp \
VirtRegMap.cpp
diff --git a/lib/clang/libllvmcore/Makefile b/lib/clang/libllvmcore/Makefile
index 8de6731ace75..d2010c0d97dd 100644
--- a/lib/clang/libllvmcore/Makefile
+++ b/lib/clang/libllvmcore/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmcore
SRCDIR= lib/VMCore
@@ -11,10 +13,12 @@ SRCS= AsmWriter.cpp \
Constants.cpp \
Core.cpp \
DIBuilder.cpp \
+ DataLayout.cpp \
DebugInfo.cpp \
DebugLoc.cpp \
Dominators.cpp \
Function.cpp \
+ GCOV.cpp \
GVMaterializer.cpp \
Globals.cpp \
IRBuilder.cpp \
@@ -33,6 +37,7 @@ SRCS= AsmWriter.cpp \
PrintModulePass.cpp \
Type.cpp \
TypeFinder.cpp \
+ TargetTransformInfo.cpp \
Use.cpp \
User.cpp \
Value.cpp \
diff --git a/lib/clang/libllvmdebuginfo/Makefile b/lib/clang/libllvmdebuginfo/Makefile
index b7241573c123..757b9097a38d 100644
--- a/lib/clang/libllvmdebuginfo/Makefile
+++ b/lib/clang/libllvmdebuginfo/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmdebuginfo
SRCDIR= lib/DebugInfo
@@ -12,6 +14,7 @@ SRCS= DIContext.cpp \
DWARFDebugAranges.cpp \
DWARFDebugInfoEntry.cpp \
DWARFDebugLine.cpp \
+ DWARFDebugRangeList.cpp \
DWARFFormValue.cpp
.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmexecutionengine/Makefile b/lib/clang/libllvmexecutionengine/Makefile
index c0dde71debb4..3ec39c78658f 100644
--- a/lib/clang/libllvmexecutionengine/Makefile
+++ b/lib/clang/libllvmexecutionengine/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmexecutionengine
SRCDIR= lib/ExecutionEngine
diff --git a/lib/clang/libllvminstcombine/Makefile b/lib/clang/libllvminstcombine/Makefile
index e989fa5af01f..3752aef1987f 100644
--- a/lib/clang/libllvminstcombine/Makefile
+++ b/lib/clang/libllvminstcombine/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvminstcombine
SRCDIR= lib/Transforms/InstCombine
diff --git a/lib/clang/libllvminstrumentation/Makefile b/lib/clang/libllvminstrumentation/Makefile
index 8e7e7a22bb9f..6d666e518dca 100644
--- a/lib/clang/libllvminstrumentation/Makefile
+++ b/lib/clang/libllvminstrumentation/Makefile
@@ -1,12 +1,14 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvminstrumentation
SRCDIR= lib/Transforms/Instrumentation
SRCS= AddressSanitizer.cpp \
+ BlackList.cpp \
BoundsChecking.cpp \
EdgeProfiling.cpp \
- FunctionBlackList.cpp \
GCOVProfiling.cpp \
Instrumentation.cpp \
OptimalEdgeProfiling.cpp \
diff --git a/lib/clang/libllvminterpreter/Makefile b/lib/clang/libllvminterpreter/Makefile
index 6a1b453459b2..06fcca4fb9f9 100644
--- a/lib/clang/libllvminterpreter/Makefile
+++ b/lib/clang/libllvminterpreter/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvminterpreter
SRCDIR= lib/ExecutionEngine/Interpreter
diff --git a/lib/clang/libllvmipo/Makefile b/lib/clang/libllvmipo/Makefile
index a493532d6504..b1e90161786d 100644
--- a/lib/clang/libllvmipo/Makefile
+++ b/lib/clang/libllvmipo/Makefile
@@ -6,6 +6,7 @@ LIB= llvmipo
SRCDIR= lib/Transforms/IPO
SRCS= ArgumentPromotion.cpp \
+ BarrierNoopPass.cpp \
ConstantMerge.cpp \
DeadArgumentElimination.cpp \
ExtractGV.cpp \
diff --git a/lib/clang/libllvmjit/Makefile b/lib/clang/libllvmjit/Makefile
index ff852d5047b7..682f704b441e 100644
--- a/lib/clang/libllvmjit/Makefile
+++ b/lib/clang/libllvmjit/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmjit
SRCDIR= lib/ExecutionEngine/JIT
diff --git a/lib/clang/libllvmlinker/Makefile b/lib/clang/libllvmlinker/Makefile
index 73f153b378fb..7275131fc6ab 100644
--- a/lib/clang/libllvmlinker/Makefile
+++ b/lib/clang/libllvmlinker/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmlinker
SRCDIR= lib/Linker
diff --git a/lib/clang/libllvmmcdisassembler/Makefile b/lib/clang/libllvmmcdisassembler/Makefile
index dc5f29437e0c..94aff3e90576 100644
--- a/lib/clang/libllvmmcdisassembler/Makefile
+++ b/lib/clang/libllvmmcdisassembler/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmmcdisassembler
SRCDIR= lib/MC/MCDisassembler
diff --git a/lib/clang/libllvmmcjit/Makefile b/lib/clang/libllvmmcjit/Makefile
index 553186f70712..207fd81725d4 100644
--- a/lib/clang/libllvmmcjit/Makefile
+++ b/lib/clang/libllvmmcjit/Makefile
@@ -7,8 +7,4 @@ LIB= llvmmcjit
SRCDIR= lib/ExecutionEngine/MCJIT
SRCS= MCJIT.cpp
-.if ${MK_CLANG_EXTRAS} != "no"
-SRCS+= MCJITMemoryManager.cpp
-.endif
-
.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmmcparser/Makefile b/lib/clang/libllvmmcparser/Makefile
index 48deadfee43f..b39926a0d712 100644
--- a/lib/clang/libllvmmcparser/Makefile
+++ b/lib/clang/libllvmmcparser/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmmcparser
SRCDIR= lib/MC/MCParser
diff --git a/lib/clang/libllvmmipsasmparser/Makefile b/lib/clang/libllvmmipsasmparser/Makefile
index dd9539488763..0572f8d225b7 100644
--- a/lib/clang/libllvmmipsasmparser/Makefile
+++ b/lib/clang/libllvmmipsasmparser/Makefile
@@ -1,12 +1,15 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmmipsasmparser
SRCDIR= lib/Target/Mips/AsmParser
INCDIR= lib/Target/Mips
SRCS= MipsAsmParser.cpp
-TGHDRS= MipsGenInstrInfo \
+TGHDRS= MipsGenAsmMatcher \
+ MipsGenInstrInfo \
MipsGenRegisterInfo \
MipsGenSubtargetInfo
diff --git a/lib/clang/libllvmmipscodegen/Makefile b/lib/clang/libllvmmipscodegen/Makefile
index ae7d2f6e18bf..7675a01666c5 100644
--- a/lib/clang/libllvmmipscodegen/Makefile
+++ b/lib/clang/libllvmmipscodegen/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmmipscodegen
SRCDIR= lib/Target/Mips
@@ -33,6 +35,7 @@ TGHDRS= Intrinsics \
MipsGenCodeEmitter \
MipsGenDAGISel \
MipsGenInstrInfo \
+ MipsGenMCPseudoLowering \
MipsGenRegisterInfo \
MipsGenSubtargetInfo
diff --git a/lib/clang/libllvmmipsdesc/Makefile b/lib/clang/libllvmmipsdesc/Makefile
index 5c17588cfa89..4ddb64635367 100644
--- a/lib/clang/libllvmmipsdesc/Makefile
+++ b/lib/clang/libllvmmipsdesc/Makefile
@@ -1,9 +1,12 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmmipsdesc
SRCDIR= lib/Target/Mips/MCTargetDesc
SRCS= MipsAsmBackend.cpp \
+ MipsDirectObjLower.cpp \
MipsELFObjectWriter.cpp \
MipsMCAsmInfo.cpp \
MipsMCCodeEmitter.cpp \
diff --git a/lib/clang/libllvmmipsdisassembler/Makefile b/lib/clang/libllvmmipsdisassembler/Makefile
index 7cdd982ca830..1c0a4b66fb4c 100644
--- a/lib/clang/libllvmmipsdisassembler/Makefile
+++ b/lib/clang/libllvmmipsdisassembler/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmmipsdisassembler
SRCDIR= lib/Target/Mips/Disassembler
diff --git a/lib/clang/libllvmmipsinfo/Makefile b/lib/clang/libllvmmipsinfo/Makefile
index c5b96cda11dd..c65c8c86f743 100644
--- a/lib/clang/libllvmmipsinfo/Makefile
+++ b/lib/clang/libllvmmipsinfo/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmmipsinfo
SRCDIR= lib/Target/Mips/TargetInfo
diff --git a/lib/clang/libllvmmipsinstprinter/Makefile b/lib/clang/libllvmmipsinstprinter/Makefile
index 36d3b0470906..39df7cc59ef3 100644
--- a/lib/clang/libllvmmipsinstprinter/Makefile
+++ b/lib/clang/libllvmmipsinstprinter/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmmipsinstprinter
SRCDIR= lib/Target/Mips/InstPrinter
diff --git a/lib/clang/libllvmobject/Makefile b/lib/clang/libllvmobject/Makefile
index d056dc7c15d3..c8c8068ed3c1 100644
--- a/lib/clang/libllvmobject/Makefile
+++ b/lib/clang/libllvmobject/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmobject
SRCDIR= lib/Object
diff --git a/lib/clang/libllvmpowerpccodegen/Makefile b/lib/clang/libllvmpowerpccodegen/Makefile
index a97c3528c135..a09da599a9bb 100644
--- a/lib/clang/libllvmpowerpccodegen/Makefile
+++ b/lib/clang/libllvmpowerpccodegen/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmpowerpccodegen
SRCDIR= lib/Target/PowerPC
diff --git a/lib/clang/libllvmpowerpcdesc/Makefile b/lib/clang/libllvmpowerpcdesc/Makefile
index 2a5ef6eabf66..e48b484d00f9 100644
--- a/lib/clang/libllvmpowerpcdesc/Makefile
+++ b/lib/clang/libllvmpowerpcdesc/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmpowerpcdesc
SRCDIR= lib/Target/PowerPC/MCTargetDesc
diff --git a/lib/clang/libllvmpowerpcinfo/Makefile b/lib/clang/libllvmpowerpcinfo/Makefile
index 8310378a9e2f..03bba0e72931 100644
--- a/lib/clang/libllvmpowerpcinfo/Makefile
+++ b/lib/clang/libllvmpowerpcinfo/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmpowerpcinfo
SRCDIR= lib/Target/PowerPC/TargetInfo
diff --git a/lib/clang/libllvmpowerpcinstprinter/Makefile b/lib/clang/libllvmpowerpcinstprinter/Makefile
index c1528aee9b0d..ac98321db91c 100644
--- a/lib/clang/libllvmpowerpcinstprinter/Makefile
+++ b/lib/clang/libllvmpowerpcinstprinter/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmpowerpcinstprinter
SRCDIR= lib/Target/PowerPC/InstPrinter
diff --git a/lib/clang/libllvmruntimedyld/Makefile b/lib/clang/libllvmruntimedyld/Makefile
index d5d5447e8e92..02ca4bd0f1ae 100644
--- a/lib/clang/libllvmruntimedyld/Makefile
+++ b/lib/clang/libllvmruntimedyld/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmruntimedyld
SRCDIR= lib/ExecutionEngine/RuntimeDyld
diff --git a/lib/clang/libllvmscalaropts/Makefile b/lib/clang/libllvmscalaropts/Makefile
index f89b0a2cdc99..87eaf23dcf70 100644
--- a/lib/clang/libllvmscalaropts/Makefile
+++ b/lib/clang/libllvmscalaropts/Makefile
@@ -20,6 +20,7 @@ SRCS= ADCE.cpp \
LICM.cpp \
LoopDeletion.cpp \
LoopIdiomRecognize.cpp \
+ LoopInstSimplify.cpp \
LoopRotation.cpp \
LoopStrengthReduce.cpp \
LoopUnrollPass.cpp \
@@ -30,6 +31,8 @@ SRCS= ADCE.cpp \
Reassociate.cpp \
Reg2Mem.cpp \
SCCP.cpp \
+ SROA.cpp \
+ Scalar.cpp \
ScalarReplAggregates.cpp \
SimplifyCFGPass.cpp \
SimplifyLibCalls.cpp \
diff --git a/lib/clang/libllvmselectiondag/Makefile b/lib/clang/libllvmselectiondag/Makefile
index e69501273443..754310286dc8 100644
--- a/lib/clang/libllvmselectiondag/Makefile
+++ b/lib/clang/libllvmselectiondag/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmselectiondag
SRCDIR= lib/CodeGen/SelectionDAG
diff --git a/lib/clang/libllvmtablegen/Makefile b/lib/clang/libllvmtablegen/Makefile
index 5ac69548f2c1..069cec0b0e3e 100644
--- a/lib/clang/libllvmtablegen/Makefile
+++ b/lib/clang/libllvmtablegen/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmtablegen
SRCDIR= lib/TableGen
@@ -7,7 +9,6 @@ SRCS= Error.cpp \
Main.cpp \
Record.cpp \
StringMatcher.cpp \
- TableGenAction.cpp \
TableGenBackend.cpp \
TGLexer.cpp \
TGParser.cpp
diff --git a/lib/clang/libllvmtarget/Makefile b/lib/clang/libllvmtarget/Makefile
index eaad17e55992..595d2ccbc504 100644
--- a/lib/clang/libllvmtarget/Makefile
+++ b/lib/clang/libllvmtarget/Makefile
@@ -1,19 +1,21 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmtarget
SRCDIR= lib/Target
SRCS= Mangler.cpp \
Target.cpp \
- TargetData.cpp \
- TargetELFWriterInfo.cpp \
TargetInstrInfo.cpp \
TargetIntrinsicInfo.cpp \
TargetJITInfo.cpp \
TargetLibraryInfo.cpp \
TargetLoweringObjectFile.cpp \
TargetMachine.cpp \
+ TargetMachineC.cpp \
TargetRegisterInfo.cpp \
- TargetSubtargetInfo.cpp
+ TargetSubtargetInfo.cpp \
+ TargetTransformImpl.cpp
.include "../clang.lib.mk"
diff --git a/lib/clang/libllvmtransformutils/Makefile b/lib/clang/libllvmtransformutils/Makefile
index f8afaec711f6..0ed2624f1aab 100644
--- a/lib/clang/libllvmtransformutils/Makefile
+++ b/lib/clang/libllvmtransformutils/Makefile
@@ -9,6 +9,7 @@ SRCS= AddrModeMatcher.cpp \
BasicBlockUtils.cpp \
BreakCriticalEdges.cpp \
BuildLibCalls.cpp \
+ BypassSlowDivision.cpp \
CloneFunction.cpp \
CloneModule.cpp \
CmpInstAnalysis.cpp \
@@ -16,6 +17,7 @@ SRCS= AddrModeMatcher.cpp \
DemoteRegToStack.cpp \
InlineFunction.cpp \
InstructionNamer.cpp \
+ IntegerDivision.cpp \
LCSSA.cpp \
Local.cpp \
LoopSimplify.cpp \
@@ -25,18 +27,19 @@ SRCS= AddrModeMatcher.cpp \
LowerInvoke.cpp \
LowerSwitch.cpp \
Mem2Reg.cpp \
+ MetaRenamer.cpp \
ModuleUtils.cpp \
PromoteMemoryToRegister.cpp \
SSAUpdater.cpp \
SimplifyCFG.cpp \
SimplifyIndVar.cpp \
SimplifyInstructions.cpp \
+ SimplifyLibCalls.cpp \
UnifyFunctionExitNodes.cpp \
ValueMapper.cpp
.if ${MK_CLANG_EXTRAS} != "no"
-SRCS+= SimplifyInstructions.cpp \
- Utils.cpp
+SRCS+= Utils.cpp
.endif
TGHDRS= Intrinsics
diff --git a/lib/clang/libllvmvectorize/Makefile b/lib/clang/libllvmvectorize/Makefile
index 61a37b56eae6..d0f5b73fd5e0 100644
--- a/lib/clang/libllvmvectorize/Makefile
+++ b/lib/clang/libllvmvectorize/Makefile
@@ -1,9 +1,12 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmvectorize
SRCDIR= lib/Transforms/Vectorize
SRCS= BBVectorize.cpp \
+ LoopVectorize.cpp \
Vectorize.cpp
TGHDRS= Intrinsics
diff --git a/lib/clang/libllvmx86asmparser/Makefile b/lib/clang/libllvmx86asmparser/Makefile
index c1402688d3a8..252b2d09a7e8 100644
--- a/lib/clang/libllvmx86asmparser/Makefile
+++ b/lib/clang/libllvmx86asmparser/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmx86asmparser
SRCDIR= lib/Target/X86/AsmParser
diff --git a/lib/clang/libllvmx86codegen/Makefile b/lib/clang/libllvmx86codegen/Makefile
index a61cad9db041..939b257ffb90 100644
--- a/lib/clang/libllvmx86codegen/Makefile
+++ b/lib/clang/libllvmx86codegen/Makefile
@@ -1,12 +1,13 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmx86codegen
SRCDIR= lib/Target/X86
SRCS= X86AsmPrinter.cpp \
X86COFFMachineModuleInfo.cpp \
X86CodeEmitter.cpp \
- X86ELFWriterInfo.cpp \
X86FastISel.cpp \
X86FloatingPoint.cpp \
X86FrameLowering.cpp \
diff --git a/lib/clang/libllvmx86desc/Makefile b/lib/clang/libllvmx86desc/Makefile
index 3d2a9dd9bfd7..a1771293738c 100644
--- a/lib/clang/libllvmx86desc/Makefile
+++ b/lib/clang/libllvmx86desc/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmx86desc
SRCDIR= lib/Target/X86/MCTargetDesc
diff --git a/lib/clang/libllvmx86info/Makefile b/lib/clang/libllvmx86info/Makefile
index 85155a883379..bc1a7d7efbda 100644
--- a/lib/clang/libllvmx86info/Makefile
+++ b/lib/clang/libllvmx86info/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmx86info
SRCDIR= lib/Target/X86/TargetInfo
diff --git a/lib/clang/libllvmx86instprinter/Makefile b/lib/clang/libllvmx86instprinter/Makefile
index a44006cc32e4..308f91c8020e 100644
--- a/lib/clang/libllvmx86instprinter/Makefile
+++ b/lib/clang/libllvmx86instprinter/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmx86instprinter
SRCDIR= lib/Target/X86/InstPrinter
diff --git a/lib/clang/libllvmx86utils/Makefile b/lib/clang/libllvmx86utils/Makefile
index bbed6b0cf047..8355e7e7ccf9 100644
--- a/lib/clang/libllvmx86utils/Makefile
+++ b/lib/clang/libllvmx86utils/Makefile
@@ -1,5 +1,7 @@
# $FreeBSD$
+.include <bsd.own.mk>
+
LIB= llvmx86utils
SRCDIR= lib/Target/X86/Utils
diff --git a/lib/csu/amd64/crt1.c b/lib/csu/amd64/crt1.c
index f33aad64fbf6..3740e737aadd 100644
--- a/lib/csu/amd64/crt1.c
+++ b/lib/csu/amd64/crt1.c
@@ -61,9 +61,7 @@ _start(char **ap, void (*cleanup)(void))
argc = *(long *)(void *)ap;
argv = ap + 1;
env = ap + 2 + argc;
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (&_DYNAMIC != NULL)
atexit(cleanup);
diff --git a/lib/csu/arm/crt1.c b/lib/csu/arm/crt1.c
index 127c28d6e7b4..e3529b81dd05 100644
--- a/lib/csu/arm/crt1.c
+++ b/lib/csu/arm/crt1.c
@@ -98,10 +98,7 @@ __start(int argc, char **argv, char **env, struct ps_strings *ps_strings,
const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void))
{
- environ = env;
-
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
diff --git a/lib/csu/common/ignore_init.c b/lib/csu/common/ignore_init.c
index e3d2441936b3..89b3734ae079 100644
--- a/lib/csu/common/ignore_init.c
+++ b/lib/csu/common/ignore_init.c
@@ -87,14 +87,18 @@ handle_static_init(int argc, char **argv, char **env)
}
static inline void
-handle_progname(const char *v)
+handle_argv(int argc, char *argv[], char **env)
{
const char *s;
- __progname = v;
- for (s = __progname; *s != '\0'; s++) {
- if (*s == '/')
- __progname = s + 1;
+ if (environ == NULL)
+ environ = env;
+ if (argc > 0 && argv[0] != NULL) {
+ __progname = argv[0];
+ for (s = __progname; *s != '\0'; s++) {
+ if (*s == '/')
+ __progname = s + 1;
+ }
}
}
diff --git a/lib/csu/i386-elf/crt1_c.c b/lib/csu/i386-elf/crt1_c.c
index 324906955e73..65de04ce493b 100644
--- a/lib/csu/i386-elf/crt1_c.c
+++ b/lib/csu/i386-elf/crt1_c.c
@@ -61,10 +61,7 @@ _start1(fptr cleanup, int argc, char *argv[])
char **env;
env = argv + argc + 1;
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
-
+ handle_argv(argc, argv, env);
if (&_DYNAMIC != NULL)
atexit(cleanup);
else
diff --git a/lib/csu/mips/crt1.c b/lib/csu/mips/crt1.c
index 1968f06f3180..95348b76768e 100644
--- a/lib/csu/mips/crt1.c
+++ b/lib/csu/mips/crt1.c
@@ -71,9 +71,7 @@ __start(char **ap,
argc = * (long *) ap;
argv = ap + 1;
env = ap + 2 + argc;
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (&_DYNAMIC != NULL)
atexit(cleanup);
diff --git a/lib/csu/powerpc/crt1.c b/lib/csu/powerpc/crt1.c
index c3be90da3481..d1a3ea0bfdaa 100644
--- a/lib/csu/powerpc/crt1.c
+++ b/lib/csu/powerpc/crt1.c
@@ -81,10 +81,8 @@ _start(int argc, char **argv, char **env,
struct ps_strings *ps_strings)
{
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
diff --git a/lib/csu/powerpc64/crt1.c b/lib/csu/powerpc64/crt1.c
index a7c3581361f0..35c5a6e5c481 100644
--- a/lib/csu/powerpc64/crt1.c
+++ b/lib/csu/powerpc64/crt1.c
@@ -81,10 +81,7 @@ _start(int argc, char **argv, char **env,
struct ps_strings *ps_strings)
{
- environ = env;
-
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (ps_strings != (struct ps_strings *)0)
__ps_strings = ps_strings;
diff --git a/lib/csu/sparc64/crt1.c b/lib/csu/sparc64/crt1.c
index 3b3ecc268e6f..e11ae39d8aca 100644
--- a/lib/csu/sparc64/crt1.c
+++ b/lib/csu/sparc64/crt1.c
@@ -85,9 +85,7 @@ _start(char **ap, void (*cleanup)(void), struct Struct_Obj_Entry *obj __unused,
argc = *(long *)(void *)ap;
argv = ap + 1;
env = ap + 2 + argc;
- environ = env;
- if (argc > 0 && argv[0] != NULL)
- handle_progname(argv[0]);
+ handle_argv(argc, argv, env);
if (&_DYNAMIC != NULL)
atexit(cleanup);
diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile
index 29508ada5665..73b3c2252e54 100644
--- a/lib/libarchive/Makefile
+++ b/lib/libarchive/Makefile
@@ -231,9 +231,6 @@ MLINKS+= archive_entry_perms.3 archive_entry_set_fflags.3
MLINKS+= archive_entry_perms.3 archive_entry_set_gid.3
MLINKS+= archive_entry_perms.3 archive_entry_set_gname.3
MLINKS+= archive_entry_perms.3 archive_entry_perm.3
-MLINKS+= archive_entry_perms.3 archive_entry_set_fflags.3
-MLINKS+= archive_entry_perms.3 archive_entry_set_gid.3
-MLINKS+= archive_entry_perms.3 archive_entry_set_gname.3
MLINKS+= archive_entry_perms.3 archive_entry_set_perm.3
MLINKS+= archive_entry_perms.3 archive_entry_set_uid.3
MLINKS+= archive_entry_perms.3 archive_entry_set_uname.3
@@ -264,10 +261,6 @@ MLINKS+= archive_entry_stat.3 archive_entry_set_filetype.3
MLINKS+= archive_entry_stat.3 archive_entry_set_ino.3
MLINKS+= archive_entry_stat.3 archive_entry_set_ino64.3
MLINKS+= archive_entry_stat.3 archive_entry_set_mode.3
-MLINKS+= archive_entry_stat.3 archive_entry_set_rdev.3
-MLINKS+= archive_entry_stat.3 archive_entry_set_rdevmajor.3
-MLINKS+= archive_entry_stat.3 archive_entry_set_rdevminor.3
-MLINKS+= archive_entry_stat.3 archive_entry_set_size.3
MLINKS+= archive_entry_stat.3 archive_entry_set_nlink.3
MLINKS+= archive_entry_stat.3 archive_entry_set_rdev.3
MLINKS+= archive_entry_stat.3 archive_entry_set_rdevmajor.3
diff --git a/lib/libbsnmp/libbsnmp/Makefile b/lib/libbsnmp/libbsnmp/Makefile
index f21f1d3fc2e4..20015b98a9d0 100644
--- a/lib/libbsnmp/libbsnmp/Makefile
+++ b/lib/libbsnmp/libbsnmp/Makefile
@@ -15,6 +15,7 @@ CFLAGS+= -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DQUADFMT='"llu"' -DQUADXFMT='"llx"'
.if ${MK_OPENSSL} != "no"
CFLAGS+= -DHAVE_LIBCRYPTO
+DPADD+= ${LIBCRYPTO}
LDADD+= -lcrypto
.endif
diff --git a/lib/libc/amd64/sys/__vdso_gettc.c b/lib/libc/amd64/sys/__vdso_gettc.c
index 091fe26d3ba7..c6f2dfb3556a 100644
--- a/lib/libc/amd64/sys/__vdso_gettc.c
+++ b/lib/libc/amd64/sys/__vdso_gettc.c
@@ -27,9 +27,11 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
+#include <sys/elf.h>
#include <sys/time.h>
#include <sys/vdso.h>
#include <machine/cpufunc.h>
+#include "libc_private.h"
static u_int
__vdso_gettc_low(const struct vdso_timehands *th)
@@ -41,9 +43,18 @@ __vdso_gettc_low(const struct vdso_timehands *th)
return (rv);
}
+#pragma weak __vdso_gettc
u_int
__vdso_gettc(const struct vdso_timehands *th)
{
return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) : rdtsc32());
}
+
+#pragma weak __vdso_gettimekeep
+int
+__vdso_gettimekeep(struct vdso_timekeep **tk)
+{
+
+ return (_elf_aux_info(AT_TIMEKEEP, tk, sizeof(*tk)));
+}
diff --git a/lib/libc/arm/Makefile.inc b/lib/libc/arm/Makefile.inc
index 4c72e5637d6e..1ae1298b17c9 100644
--- a/lib/libc/arm/Makefile.inc
+++ b/lib/libc/arm/Makefile.inc
@@ -8,3 +8,11 @@ SOFTFLOAT_BITS=32
# Long double is just double precision.
MDSRCS+=machdep_ldisd.c
SYM_MAPS+=${.CURDIR}/arm/Symbol.map
+
+.if ${MK_ARM_EABI} == "no"
+# This contains the symbols that were removed when moving to the ARM EABI
+SYM_MAPS+=${.CURDIR}/arm/Symbol_oabi.map
+.else
+.include "${.CURDIR}/arm/aeabi/Makefile.inc"
+.endif
+
diff --git a/lib/libc/arm/SYS.h b/lib/libc/arm/SYS.h
index 584c15138482..ed1a045c64e2 100644
--- a/lib/libc/arm/SYS.h
+++ b/lib/libc/arm/SYS.h
@@ -39,7 +39,15 @@
#include <sys/syscall.h>
#include <machine/swi.h>
+#ifdef __ARM_EABI__
+#define SYSTRAP(x) \
+ mov ip, r7; \
+ ldr r7, =SYS_ ## x; \
+ swi 0; \
+ mov r7, ip
+#else
#define SYSTRAP(x) swi 0 | SYS_ ## x
+#endif
#define CERROR _C_LABEL(cerror)
#define CURBRK _C_LABEL(curbrk)
diff --git a/lib/libc/arm/Symbol.map b/lib/libc/arm/Symbol.map
index b786afd8a793..d652bc8758de 100644
--- a/lib/libc/arm/Symbol.map
+++ b/lib/libc/arm/Symbol.map
@@ -50,10 +50,6 @@ FBSDprivate_1.0 {
_set_tp;
__aeabi_read_tp;
___longjmp;
- __umodsi3;
- __modsi3;
- __udivsi3;
- __divsi3;
__makecontext;
__longjmp;
signalcontext;
diff --git a/lib/libc/arm/Symbol_oabi.map b/lib/libc/arm/Symbol_oabi.map
new file mode 100644
index 000000000000..0c22e4a5827d
--- /dev/null
+++ b/lib/libc/arm/Symbol_oabi.map
@@ -0,0 +1,16 @@
+/*
+ * $FreeBSD$
+ */
+
+/*
+ * This only needs to contain symbols that are not listed in
+ * symbol maps from other parts of libc (i.e., not found in
+ * stdlib/Symbol.map, string/Symbol.map, sys/Symbol.map, ...)
+ * and are not used in the ARM EABI.
+ */
+FBSDprivate_1.0 {
+ __umodsi3;
+ __modsi3;
+ __udivsi3;
+ __divsi3;
+};
diff --git a/lib/libc/arm/aeabi/Makefile.inc b/lib/libc/arm/aeabi/Makefile.inc
new file mode 100644
index 000000000000..ac147c039925
--- /dev/null
+++ b/lib/libc/arm/aeabi/Makefile.inc
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+.PATH: ${.CURDIR}/arm/aeabi
+
+SRCS+= aeabi_atexit.c \
+ aeabi_double.c \
+ aeabi_float.c \
+ aeabi_unwind_cpp.c
+
+SYM_MAPS+=${.CURDIR}/arm/aeabi/Symbol.map
+
diff --git a/lib/libc/arm/aeabi/Symbol.map b/lib/libc/arm/aeabi/Symbol.map
new file mode 100644
index 000000000000..949342714a7a
--- /dev/null
+++ b/lib/libc/arm/aeabi/Symbol.map
@@ -0,0 +1,47 @@
+/*
+ * $FreeBSD$
+ */
+
+/*
+ * This only needs to contain AEABI symbols that are not listed in
+ * symbol maps from other parts of libc (i.e., not found in
+ * stdlib/Symbol.map, string/Symbol.map, sys/Symbol.map, ...).
+ */
+FBSDprivate_1.0 {
+ __aeabi_atexit;
+
+ __aeabi_dcmpeq;
+ __aeabi_dcmplt;
+ __aeabi_dcmple;
+ __aeabi_dcmpge;
+ __aeabi_dcmpgt;
+ __aeabi_dcmpun;
+
+ __aeabi_d2iz;
+ __aeabi_d2f;
+
+ __aeabi_dadd;
+ __aeabi_ddiv;
+ __aeabi_dmul;
+ __aeabi_dsub;
+
+
+ __aeabi_fcmpeq;
+ __aeabi_fcmplt;
+ __aeabi_fcmple;
+ __aeabi_fcmpge;
+ __aeabi_fcmpgt;
+ __aeabi_fcmpun;
+
+ __aeabi_f2iz;
+ __aeabi_f2d;
+
+ __aeabi_fadd;
+ __aeabi_fdiv;
+ __aeabi_fmul;
+ __aeabi_fsub;
+
+
+ __aeabi_i2d;
+ __aeabi_i2f;
+};
diff --git a/lib/libc/arm/aeabi/aeabi_atexit.c b/lib/libc/arm/aeabi/aeabi_atexit.c
new file mode 100644
index 000000000000..8502595385df
--- /dev/null
+++ b/lib/libc/arm/aeabi/aeabi_atexit.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 Andrew Turner
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+int __cxa_atexit(void (*)(void *), void *, void *);
+
+int
+__aeabi_atexit(void *object, void (*func)(void*), void *dso)
+{
+ return __cxa_atexit(func, object, dso);
+}
+
diff --git a/lib/libc/arm/aeabi/aeabi_double.c b/lib/libc/arm/aeabi/aeabi_double.c
new file mode 100644
index 000000000000..5f9065ca5fdc
--- /dev/null
+++ b/lib/libc/arm/aeabi/aeabi_double.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2012 Andrew Turner
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "softfloat-for-gcc.h"
+#include "milieu.h"
+#include "softfloat.h"
+
+flag __unorddf2(float64, float64);
+
+int __aeabi_dcmpeq(float64 a, float64 b)
+{
+ return float64_eq(a, b);
+}
+
+int __aeabi_dcmplt(float64 a, float64 b)
+{
+ return float64_lt(a, b);
+}
+
+int __aeabi_dcmple(float64 a, float64 b)
+{
+ return float64_le(a, b);
+}
+
+int __aeabi_dcmpge(float64 a, float64 b)
+{
+ return float64_le(b, a);
+}
+
+int __aeabi_dcmpgt(float64 a, float64 b)
+{
+ return float64_lt(b, a);
+}
+
+int __aeabi_dcmpun(float64 a, float64 b)
+{
+ return __unorddf2(a, b);
+}
+
+int __aeabi_d2iz(float64 a)
+{
+ return float64_to_int32_round_to_zero(a);
+}
+
+float32 __aeabi_d2f(float64 a)
+{
+ return float64_to_float32(a);
+}
+
+float64 __aeabi_i2d(int a)
+{
+ return int32_to_float64(a);
+}
+
+float64 __aeabi_dadd(float64 a, float64 b)
+{
+ return float64_add(a, b);
+}
+
+float64 __aeabi_ddiv(float64 a, float64 b)
+{
+ return float64_div(a, b);
+}
+
+float64 __aeabi_dmul(float64 a, float64 b)
+{
+ return float64_mul(a, b);
+}
+
+float64 __aeabi_dsub(float64 a, float64 b)
+{
+ return float64_sub(a, b);
+}
+
diff --git a/lib/libc/arm/aeabi/aeabi_float.c b/lib/libc/arm/aeabi/aeabi_float.c
new file mode 100644
index 000000000000..97751adad6c7
--- /dev/null
+++ b/lib/libc/arm/aeabi/aeabi_float.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2012 Andrew Turner
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "softfloat-for-gcc.h"
+#include "milieu.h"
+#include "softfloat.h"
+
+flag __unordsf2(float32, float32);
+
+int __aeabi_fcmpeq(float32 a, float32 b)
+{
+ return float32_eq(a, b);
+}
+
+int __aeabi_fcmplt(float32 a, float32 b)
+{
+ return float32_lt(a, b);
+}
+
+int __aeabi_fcmple(float32 a, float32 b)
+{
+ return float32_le(a, b);
+}
+
+int __aeabi_fcmpge(float32 a, float32 b)
+{
+ return float32_le(b, a);
+}
+
+int __aeabi_fcmpgt(float32 a, float32 b)
+{
+ return float32_lt(b, a);
+}
+
+int __aeabi_fcmpun(float32 a, float32 b)
+{
+ return __unordsf2(a, b);
+}
+
+int __aeabi_f2iz(float32 a)
+{
+ return float32_to_int32_round_to_zero(a);
+}
+
+float32 __aeabi_f2d(float32 a)
+{
+ return float32_to_float64(a);
+}
+
+float32 __aeabi_i2f(int a)
+{
+ return int32_to_float32(a);
+}
+
+float32 __aeabi_fadd(float32 a, float32 b)
+{
+ return float32_add(a, b);
+}
+
+float32 __aeabi_fdiv(float32 a, float32 b)
+{
+ return float32_div(a, b);
+}
+
+float32 __aeabi_fmul(float32 a, float32 b)
+{
+ return float32_mul(a, b);
+}
+
+float32 __aeabi_fsub(float32 a, float32 b)
+{
+ return float32_sub(a, b);
+}
+
diff --git a/lib/libc/arm/aeabi/aeabi_unwind_cpp.c b/lib/libc/arm/aeabi/aeabi_unwind_cpp.c
new file mode 100644
index 000000000000..c07cbbde275b
--- /dev/null
+++ b/lib/libc/arm/aeabi/aeabi_unwind_cpp.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2011 Andrew Turner
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+/*
+ * Provide an implementation of __aeabi_unwind_cpp_pr{0,1,2}. These are
+ * required by libc but are implemented in libgcc_eh.a which we don't link
+ * against. The libgcc_eh.a version will be called so we call abort to
+ * check this.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stdlib.h>
+
+void __aeabi_unwind_cpp_pr0(void) __hidden;
+void __aeabi_unwind_cpp_pr1(void) __hidden;
+void __aeabi_unwind_cpp_pr2(void) __hidden;
+
+void
+__aeabi_unwind_cpp_pr0(void)
+{
+ abort();
+}
+
+void
+__aeabi_unwind_cpp_pr1(void)
+{
+ abort();
+}
+
+void
+__aeabi_unwind_cpp_pr2(void)
+{
+ abort();
+}
+
diff --git a/lib/libc/arm/gen/Makefile.inc b/lib/libc/arm/gen/Makefile.inc
index a78cbb94260d..ec36d4508216 100644
--- a/lib/libc/arm/gen/Makefile.inc
+++ b/lib/libc/arm/gen/Makefile.inc
@@ -3,4 +3,8 @@
SRCS+= _ctx_start.S _setjmp.S _set_tp.c alloca.S fabs.c \
getcontextx.c infinity.c ldexp.c makecontext.c \
- __aeabi_read_tp.S setjmp.S signalcontext.c sigsetjmp.S divsi3.S flt_rounds.c
+ __aeabi_read_tp.S setjmp.S signalcontext.c sigsetjmp.S flt_rounds.c
+
+.if ${MK_ARM_EABI} == "no"
+SRCS+= divsi3.S
+.endif
diff --git a/lib/libc/arm/softfloat/arm-gcc.h b/lib/libc/arm/softfloat/arm-gcc.h
index 1204108250f7..15bc509fbcb3 100644
--- a/lib/libc/arm/softfloat/arm-gcc.h
+++ b/lib/libc/arm/softfloat/arm-gcc.h
@@ -95,7 +95,7 @@ what the endianness of the CPU. VFP is sane.
#define FLOAT64_DEMANGLE(a) (a)
#define FLOAT64_MANGLE(a) (a)
#else
-#define FLOAT64_DEMANGLE(a) (((a) << 32) | ((a) >> 32))
+#define FLOAT64_DEMANGLE(a) ((((a) & 0xfffffffful) << 32) | ((a) >> 32))
#define FLOAT64_MANGLE(a) FLOAT64_DEMANGLE(a)
#endif
#endif
diff --git a/lib/libc/arm/sys/Makefile.inc b/lib/libc/arm/sys/Makefile.inc
index 1a58eae551d4..fd251c87aa22 100644
--- a/lib/libc/arm/sys/Makefile.inc
+++ b/lib/libc/arm/sys/Makefile.inc
@@ -1,5 +1,7 @@
# $FreeBSD$
+SRCS+= __vdso_gettc.c
+
MDASM= Ovfork.S brk.S cerror.S pipe.S ptrace.S sbrk.S shmat.S sigreturn.S syscall.S
# Don't generate default code for these syscalls:
diff --git a/lib/libdisk/write_mips_disk.c b/lib/libc/arm/sys/__vdso_gettc.c
index bd0cb870481f..b99bbc4f3d0f 100644
--- a/lib/libdisk/write_mips_disk.c
+++ b/lib/libc/arm/sys/__vdso_gettc.c
@@ -1,6 +1,5 @@
/*-
- * Copyright (c) 2006 Olivier Houchard
- * All rights reserved.
+ * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,22 +26,23 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <err.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/disklabel.h>
-#include <paths.h>
-#include "libdisk.h"
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <errno.h>
-int
-Write_Disk(const struct disk *d1)
+#pragma weak __vdso_gettc
+u_int
+__vdso_gettc(const struct vdso_timehands *th)
{
return (0);
}
+
+#pragma weak __vdso_gettimekeep
+int
+__vdso_gettimekeep(struct vdso_timekeep **tk)
+{
+
+ return (ENOSYS);
+}
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 2481f28abf1a..0bbbb33060e3 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -32,13 +32,17 @@ SRCS+= __getosreldate.c __xuname.c \
sigsetops.c sleep.c srand48.c statvfs.c stringlist.c strtofflags.c \
sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \
syslog.c telldir.c termios.c time.c times.c timezone.c tls.c \
- ttyname.c ttyslot.c ualarm.c ulimit.c uname.c unvis.c \
- usleep.c utime.c utxdb.c valloc.c vis.c wait.c wait3.c waitpid.c \
- wordexp.c
+ ttyname.c ttyslot.c ualarm.c ulimit.c uname.c unvis-compat.c \
+ usleep.c utime.c utxdb.c valloc.c wait.c wait3.c waitpid.c \
+ waitid.c wordexp.c
.PATH: ${.CURDIR}/../../contrib/libc-pwcache
SRCS+= pwcache.c pwcache.h
+.PATH: ${.CURDIR}/../../contrib/libc-vis
+CFLAGS+= -I${.CURDIR}/../../contrib/libc-vis
+SRCS+= unvis.c vis.c
+
MISRCS+=modf.c
CANCELPOINTS_SRCS=sem.c sem_new.c
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
index b4f88aed65c0..4cbf07ca7381 100644
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -298,7 +298,6 @@ FBSD_1.0 {
ualarm;
ulimit;
uname;
- unvis;
strunvis;
strunvisx;
usleep;
@@ -388,9 +387,22 @@ FBSD_1.3 {
__FreeBSD_libc_enter_restricted_mode;
getcontextx;
gid_from_group;
+ nvis;
pwcache_userdb;
pwcache_groupdb;
+ snvis;
+ strnunvis;
+ strnunvisx;
+ strnvis;
+ strnvisx;
+ strsnvis;
+ strsnvisx;
+ strsvis;
+ strsvisx;
+ svis;
uid_from_user;
+ unvis;
+ waitid;
};
FBSDprivate_1.0 {
diff --git a/lib/libc/gen/check_utility_compat.c b/lib/libc/gen/check_utility_compat.c
index 0ccdec115a87..04c594b52665 100644
--- a/lib/libc/gen/check_utility_compat.c
+++ b/lib/libc/gen/check_utility_compat.c
@@ -35,32 +35,28 @@ __FBSDID("$FreeBSD$");
* are threaded, so I'm not concerned about cancellation points or other
* niceties.
*/
+#include <sys/limits.h>
+
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#ifndef LINE_MAX
-#define LINE_MAX _POSIX2_LINE_MAX
-#endif
-
#define _PATH_UTIL_COMPAT "/etc/compat-FreeBSD-4-util"
#define _ENV_UTIL_COMPAT "_COMPAT_FreeBSD_4"
int
check_utility_compat(const char *utility)
{
- char buf[LINE_MAX];
+ char buf[PATH_MAX];
char *p, *bp;
int len;
if ((p = getenv(_ENV_UTIL_COMPAT)) != NULL) {
strlcpy(buf, p, sizeof buf);
} else {
- if ((len = readlink(_PATH_UTIL_COMPAT, buf, sizeof buf)) < 0)
+ if ((len = readlink(_PATH_UTIL_COMPAT, buf, sizeof(buf) - 1)) < 0)
return 0;
- if (len > sizeof buf)
- len = sizeof buf;
buf[len] = '\0';
}
if (buf[0] == '\0')
diff --git a/lib/libc/gen/fmtmsg.c b/lib/libc/gen/fmtmsg.c
index c6ecbd5f7653..d2c67a6cb014 100644
--- a/lib/libc/gen/fmtmsg.c
+++ b/lib/libc/gen/fmtmsg.c
@@ -83,7 +83,7 @@ def:
if (output == NULL)
return (MM_NOCON);
if (*output != '\0') {
- if ((fp = fopen("/dev/console", "a")) == NULL) {
+ if ((fp = fopen("/dev/console", "ae")) == NULL) {
free(output);
return (MM_NOCON);
}
diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c
index b68db2effb6d..6a77abd635cf 100644
--- a/lib/libc/gen/fstab.c
+++ b/lib/libc/gen/fstab.c
@@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <errno.h>
-#include <fcntl.h>
#include <fstab.h>
#include <paths.h>
#include <stdio.h>
@@ -255,8 +254,6 @@ getfsfile(const char *name)
int
setfsent(void)
{
- int fd;
-
if (_fs_fp) {
rewind(_fs_fp);
LineNo = 0;
@@ -268,18 +265,11 @@ setfsent(void)
else
setfstab(getenv("PATH_FSTAB"));
}
- fd = _open(path_fstab, O_RDONLY | O_CLOEXEC);
- if (fd == -1) {
- error(errno);
- return (0);
- }
- _fs_fp = fdopen(fd, "r");
- if (_fs_fp != NULL) {
+ if ((_fs_fp = fopen(path_fstab, "re")) != NULL) {
LineNo = 0;
return (1);
}
error(errno);
- _close(fd);
return (0);
}
diff --git a/lib/libc/gen/getbsize.3 b/lib/libc/gen/getbsize.3
index 1407051e1204..2caf5fe1cb77 100644
--- a/lib/libc/gen/getbsize.3
+++ b/lib/libc/gen/getbsize.3
@@ -28,12 +28,12 @@
.\" @(#)getbsize.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd June 4, 1993
+.Dd November 16, 2012
.Dt GETBSIZE 3
.Os
.Sh NAME
.Nm getbsize
-.Nd get user block size
+.Nd get preferred block size
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -43,11 +43,31 @@
.Sh DESCRIPTION
The
.Fn getbsize
-function determines the user's preferred block size based on the value of the
-.Dq BLOCKSIZE
-environment variable; see
-.Xr environ 7
-for details on its use and format.
+function returns a preferred block size for reporting by system utilities
+.Xr df 1 ,
+.Xr du 1 ,
+.Xr ls 1
+and
+.Xr systat 1 ,
+based on the value of the
+.Ev BLOCKSIZE
+environment variable.
+.Ev BLOCKSIZE
+may be specified directly in bytes, or in multiples of a kilobyte by
+specifying a number followed by ``K'' or ``k'', in multiples of a
+megabyte by specifying a number followed by ``M'' or ``m'' or in
+multiples of a gigabyte by specifying a number followed by ``G'' or
+``g''.
+Multiples must be integers.
+.Pp
+Valid values of
+.Ev BLOCKSIZE
+are 512 bytes to 1 gigabyte.
+Sizes less than 512 bytes are rounded up to 512 bytes, and sizes
+greater than 1 GB are rounded down to 1 GB.
+In each case
+.Fn getbsize
+produces a warning message.
.Pp
The
.Fn getbsize
@@ -61,10 +81,6 @@ terminating null).
The memory referenced by
.Fa blocksizep
is filled in with block size, in bytes.
-.Pp
-If the user's block size is unreasonable, a warning message is
-written to standard error and the returned information reflects
-a block size of 512 bytes.
.Sh SEE ALSO
.Xr df 1 ,
.Xr du 1 ,
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c
index c321d122db12..f2f3777ab14e 100644
--- a/lib/libc/gen/getcap.c
+++ b/lib/libc/gen/getcap.c
@@ -654,7 +654,7 @@ cgetnext(char **bp, char **db_array)
if (dbp == NULL)
dbp = db_array;
- if (pfp == NULL && (pfp = fopen(*dbp, "r")) == NULL) {
+ if (pfp == NULL && (pfp = fopen(*dbp, "re")) == NULL) {
(void)cgetclose();
return (-1);
}
@@ -679,7 +679,7 @@ cgetnext(char **bp, char **db_array)
(void)cgetclose();
return (0);
} else if ((pfp =
- fopen(*dbp, "r")) == NULL) {
+ fopen(*dbp, "re")) == NULL) {
(void)cgetclose();
return (-1);
} else
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c
index 18f64a8fef75..f9480c3a22fc 100644
--- a/lib/libc/gen/getgrent.c
+++ b/lib/libc/gen/getgrent.c
@@ -810,7 +810,7 @@ files_setgrent(void *retval, void *mdata, va_list ap)
if (st->fp != NULL)
rewind(st->fp);
else if (stayopen)
- st->fp = fopen(_PATH_GROUP, "r");
+ st->fp = fopen(_PATH_GROUP, "re");
break;
case ENDGRENT:
if (st->fp != NULL) {
@@ -861,7 +861,7 @@ files_group(void *retval, void *mdata, va_list ap)
if (*errnop != 0)
return (NS_UNAVAIL);
if (st->fp == NULL &&
- ((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) {
+ ((st->fp = fopen(_PATH_GROUP, "re")) == NULL)) {
*errnop = errno;
return (NS_UNAVAIL);
}
@@ -1251,7 +1251,7 @@ compat_setgrent(void *retval, void *mdata, va_list ap)
if (st->fp != NULL)
rewind(st->fp);
else if (stayopen)
- st->fp = fopen(_PATH_GROUP, "r");
+ st->fp = fopen(_PATH_GROUP, "re");
set_setent(dtab, mdata);
(void)_nsdispatch(NULL, dtab, NSDB_GROUP_COMPAT, "setgrent",
compatsrc, 0);
@@ -1335,7 +1335,7 @@ compat_group(void *retval, void *mdata, va_list ap)
if (*errnop != 0)
return (NS_UNAVAIL);
if (st->fp == NULL &&
- ((st->fp = fopen(_PATH_GROUP, "r")) == NULL)) {
+ ((st->fp = fopen(_PATH_GROUP, "re")) == NULL)) {
*errnop = errno;
rv = NS_UNAVAIL;
goto fin;
diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c
index 51b3e3758b61..4c564613c2e7 100644
--- a/lib/libc/gen/getnetgrent.c
+++ b/lib/libc/gen/getnetgrent.c
@@ -173,7 +173,7 @@ setnetgrent(const char *group)
if (((stat(_PATH_NETGROUP, &_yp_statp) < 0) &&
errno == ENOENT) || _yp_statp.st_size == 0)
_use_only_yp = _netgr_yp_enabled = 1;
- if ((netf = fopen(_PATH_NETGROUP,"r")) != NULL ||_use_only_yp){
+ if ((netf = fopen(_PATH_NETGROUP,"re")) != NULL ||_use_only_yp){
/*
* Icky: grab the first character of the netgroup file
* and turn on NIS if it's a '+'. rewind the stream
@@ -197,7 +197,7 @@ setnetgrent(const char *group)
return;
}
#else
- if ((netf = fopen(_PATH_NETGROUP, "r"))) {
+ if ((netf = fopen(_PATH_NETGROUP, "re"))) {
#endif
if (parse_netgrp(group))
endnetgrent();
diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c
index f2fc298a4fd5..b82c30abe366 100644
--- a/lib/libc/gen/getttyent.c
+++ b/lib/libc/gen/getttyent.c
@@ -211,7 +211,7 @@ setttyent(void)
if (tf) {
rewind(tf);
return (1);
- } else if ( (tf = fopen(_PATH_TTYS, "r")) )
+ } else if ( (tf = fopen(_PATH_TTYS, "re")) )
return (1);
return (0);
}
diff --git a/lib/libc/gen/getusershell.c b/lib/libc/gen/getusershell.c
index ce50069d258f..53536e136f82 100644
--- a/lib/libc/gen/getusershell.c
+++ b/lib/libc/gen/getusershell.c
@@ -115,7 +115,7 @@ _local_initshells(rv, cb_data, ap)
sl_free(sl, 1);
sl = sl_init();
- if ((fp = fopen(_PATH_SHELLS, "r")) == NULL)
+ if ((fp = fopen(_PATH_SHELLS, "re")) == NULL)
return NS_UNAVAIL;
cp = line;
diff --git a/lib/libc/gen/getutxent.c b/lib/libc/gen/getutxent.c
index a2e938a988f5..20e8859f6cd7 100644
--- a/lib/libc/gen/getutxent.c
+++ b/lib/libc/gen/getutxent.c
@@ -71,7 +71,7 @@ setutxdb(int db, const char *file)
if (uf != NULL)
fclose(uf);
- uf = fopen(file, "r");
+ uf = fopen(file, "re");
if (uf == NULL)
return (-1);
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c
index 211b5351ae7a..832dc8dffdb4 100644
--- a/lib/libc/gen/glob.c
+++ b/lib/libc/gen/glob.c
@@ -94,6 +94,25 @@ __FBSDID("$FreeBSD$");
#include "collate.h"
+/*
+ * glob(3) expansion limits. Stop the expansion if any of these limits
+ * is reached. This caps the runtime in the face of DoS attacks. See
+ * also CVE-2010-2632
+ */
+#define GLOB_LIMIT_BRACE 128 /* number of brace calls */
+#define GLOB_LIMIT_PATH 65536 /* number of path elements */
+#define GLOB_LIMIT_READDIR 16384 /* number of readdirs */
+#define GLOB_LIMIT_STAT 1024 /* number of stat system calls */
+#define GLOB_LIMIT_STRING ARG_MAX /* maximum total size for paths */
+
+struct glob_limit {
+ size_t l_brace_cnt;
+ size_t l_path_lim;
+ size_t l_readdir_cnt;
+ size_t l_stat_cnt;
+ size_t l_string_cnt;
+};
+
#define DOLLAR '$'
#define DOT '.'
#define EOS '\0'
@@ -153,15 +172,18 @@ static const Char *g_strchr(const Char *, wchar_t);
static Char *g_strcat(Char *, const Char *);
#endif
static int g_stat(Char *, struct stat *, glob_t *);
-static int glob0(const Char *, glob_t *, size_t *);
-static int glob1(Char *, glob_t *, size_t *);
-static int glob2(Char *, Char *, Char *, Char *, glob_t *, size_t *);
-static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, size_t *);
-static int globextend(const Char *, glob_t *, size_t *);
-static const Char *
+static int glob0(const Char *, glob_t *, struct glob_limit *);
+static int glob1(Char *, glob_t *, struct glob_limit *);
+static int glob2(Char *, Char *, Char *, Char *, glob_t *,
+ struct glob_limit *);
+static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *,
+ struct glob_limit *);
+static int globextend(const Char *, glob_t *, struct glob_limit *);
+static const Char *
globtilde(const Char *, Char *, size_t, glob_t *);
-static int globexp1(const Char *, glob_t *, size_t *);
-static int globexp2(const Char *, const Char *, glob_t *, int *, size_t *);
+static int globexp1(const Char *, glob_t *, struct glob_limit *);
+static int globexp2(const Char *, const Char *, glob_t *, int *,
+ struct glob_limit *);
static int match(Char *, Char *, Char *);
#ifdef DEBUG
static void qprintf(const char *, Char *);
@@ -171,8 +193,8 @@ int
glob(const char * __restrict pattern, int flags,
int (*errfunc)(const char *, int), glob_t * __restrict pglob)
{
+ struct glob_limit limit = { 0, 0, 0, 0, 0 };
const char *patnext;
- size_t limit;
Char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;
mbstate_t mbs;
wchar_t wc;
@@ -186,11 +208,10 @@ glob(const char * __restrict pattern, int flags,
pglob->gl_offs = 0;
}
if (flags & GLOB_LIMIT) {
- limit = pglob->gl_matchc;
- if (limit == 0)
- limit = ARG_MAX;
- } else
- limit = 0;
+ limit.l_path_lim = pglob->gl_matchc;
+ if (limit.l_path_lim == 0)
+ limit.l_path_lim = GLOB_LIMIT_PATH;
+ }
pglob->gl_flags = flags & ~GLOB_MAGCHAR;
pglob->gl_errfunc = errfunc;
pglob->gl_matchc = 0;
@@ -243,11 +264,17 @@ glob(const char * __restrict pattern, int flags,
* characters
*/
static int
-globexp1(const Char *pattern, glob_t *pglob, size_t *limit)
+globexp1(const Char *pattern, glob_t *pglob, struct glob_limit *limit)
{
const Char* ptr = pattern;
int rv;
+ if ((pglob->gl_flags & GLOB_LIMIT) &&
+ limit->l_brace_cnt++ >= GLOB_LIMIT_BRACE) {
+ errno = 0;
+ return (GLOB_NOSPACE);
+ }
+
/* Protect a single {}, for find(1), like csh */
if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
return glob0(pattern, pglob, limit);
@@ -266,7 +293,8 @@ globexp1(const Char *pattern, glob_t *pglob, size_t *limit)
* If it fails then it tries to glob the rest of the pattern and returns.
*/
static int
-globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv, size_t *limit)
+globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, int *rv,
+ struct glob_limit *limit)
{
int i;
Char *lm, *ls;
@@ -436,7 +464,7 @@ globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
* if things went well, nonzero if errors occurred.
*/
static int
-glob0(const Char *pattern, glob_t *pglob, size_t *limit)
+glob0(const Char *pattern, glob_t *pglob, struct glob_limit *limit)
{
const Char *qpatnext;
int err;
@@ -529,7 +557,7 @@ compare(const void *p, const void *q)
}
static int
-glob1(Char *pattern, glob_t *pglob, size_t *limit)
+glob1(Char *pattern, glob_t *pglob, struct glob_limit *limit)
{
Char pathbuf[MAXPATHLEN];
@@ -547,7 +575,7 @@ glob1(Char *pattern, glob_t *pglob, size_t *limit)
*/
static int
glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
- glob_t *pglob, size_t *limit)
+ glob_t *pglob, struct glob_limit *limit)
{
struct stat sb;
Char *p, *q;
@@ -563,6 +591,15 @@ glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
if (g_lstat(pathbuf, &sb, pglob))
return (0);
+ if ((pglob->gl_flags & GLOB_LIMIT) &&
+ limit->l_stat_cnt++ >= GLOB_LIMIT_STAT) {
+ errno = 0;
+ if (pathend + 1 > pathend_last)
+ return (GLOB_ABORTED);
+ *pathend++ = SEP;
+ *pathend = EOS;
+ return (GLOB_NOSPACE);
+ }
if (((pglob->gl_flags & GLOB_MARK) &&
pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
|| (S_ISLNK(sb.st_mode) &&
@@ -606,7 +643,7 @@ glob2(Char *pathbuf, Char *pathend, Char *pathend_last, Char *pattern,
static int
glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
Char *pattern, Char *restpattern,
- glob_t *pglob, size_t *limit)
+ glob_t *pglob, struct glob_limit *limit)
{
struct dirent *dp;
DIR *dirp;
@@ -652,6 +689,19 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
size_t clen;
mbstate_t mbs;
+ if ((pglob->gl_flags & GLOB_LIMIT) &&
+ limit->l_readdir_cnt++ >= GLOB_LIMIT_READDIR) {
+ errno = 0;
+ if (pathend + 1 > pathend_last)
+ err = GLOB_ABORTED;
+ else {
+ *pathend++ = SEP;
+ *pathend = EOS;
+ err = GLOB_NOSPACE;
+ }
+ break;
+ }
+
/* Initial DOT must be matched literally. */
if (dp->d_name[0] == DOT && *pattern != DOT)
continue;
@@ -702,29 +752,24 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
* gl_pathv points to (gl_offs + gl_pathc + 1) items.
*/
static int
-globextend(const Char *path, glob_t *pglob, size_t *limit)
+globextend(const Char *path, glob_t *pglob, struct glob_limit *limit)
{
char **pathv;
size_t i, newsize, len;
char *copy;
const Char *p;
- if (*limit && pglob->gl_pathc > *limit) {
+ if ((pglob->gl_flags & GLOB_LIMIT) &&
+ pglob->gl_matchc > limit->l_path_lim) {
errno = 0;
return (GLOB_NOSPACE);
}
newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
- pathv = pglob->gl_pathv ?
- realloc((char *)pglob->gl_pathv, newsize) :
- malloc(newsize);
- if (pathv == NULL) {
- if (pglob->gl_pathv) {
- free(pglob->gl_pathv);
- pglob->gl_pathv = NULL;
- }
+ /* realloc(NULL, newsize) is equivalent to malloc(newsize). */
+ pathv = realloc((void *)pglob->gl_pathv, newsize);
+ if (pathv == NULL)
return (GLOB_NOSPACE);
- }
if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
/* first time around -- clear initial gl_offs items */
@@ -737,6 +782,12 @@ globextend(const Char *path, glob_t *pglob, size_t *limit)
for (p = path; *p++;)
continue;
len = MB_CUR_MAX * (size_t)(p - path); /* XXX overallocation */
+ limit->l_string_cnt += len;
+ if ((pglob->gl_flags & GLOB_LIMIT) &&
+ limit->l_string_cnt >= GLOB_LIMIT_STRING) {
+ errno = 0;
+ return (GLOB_NOSPACE);
+ }
if ((copy = malloc(len)) != NULL) {
if (g_Ctoc(path, copy, len)) {
free(copy);
diff --git a/lib/libc/gen/isnan.c b/lib/libc/gen/isnan.c
index ec81362f4f99..72c2868b5e90 100644
--- a/lib/libc/gen/isnan.c
+++ b/lib/libc/gen/isnan.c
@@ -33,8 +33,14 @@
/*
* XXX These routines belong in libm, but they must remain in libc for
* binary compat until we can bump libm's major version number.
+ *
+ * Note this only applies to the dynamic versions of libm and libc, so
+ * for the static and profiled versions we stub out the definitions.
+ * Otherwise you cannot link statically to libm and libc at the same
+ * time, when calling both functions.
*/
+#ifdef PIC
__weak_reference(__isnan, isnan);
__weak_reference(__isnanf, isnanf);
@@ -55,3 +61,4 @@ __isnanf(float f)
u.f = f;
return (u.bits.exp == 255 && u.bits.man != 0);
}
+#endif /* PIC */
diff --git a/lib/libc/gen/sysctlbyname.c b/lib/libc/gen/sysctlbyname.c
index a2e0d5f85fdf..88b860d3e794 100644
--- a/lib/libc/gen/sysctlbyname.c
+++ b/lib/libc/gen/sysctlbyname.c
@@ -19,13 +19,10 @@ sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
const void *newp, size_t newlen)
{
int real_oid[CTL_MAXNAME+2];
- int error;
size_t oidlen;
oidlen = sizeof(real_oid) / sizeof(int);
- error = sysctlnametomib(name, real_oid, &oidlen);
- if (error < 0)
- return (error);
- error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen);
- return (error);
+ if (sysctlnametomib(name, real_oid, &oidlen) < 0)
+ return (-1);
+ return (sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen));
}
diff --git a/lib/libc/gen/unvis-compat.c b/lib/libc/gen/unvis-compat.c
new file mode 100644
index 000000000000..080143e39df8
--- /dev/null
+++ b/lib/libc/gen/unvis-compat.c
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (c) 2012 SRI International
+ * All rights reserved.
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
+ * ("CTSRD"), as part of the DARPA CRASH research programme.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <vis.h>
+
+#define _UNVIS_END 1
+
+int
+__unvis_44bsd(char *cp, int c, int *astate, int flag)
+{
+
+ if (flag & _UNVIS_END)
+ flag = (flag & ~_UNVIS_END) ^ UNVIS_END;
+ return unvis(cp, c, astate, flag);
+}
+
+__sym_compat(unvis, __vis_44bsd, FBSD_1.0);
diff --git a/lib/libc/gen/unvis.3 b/lib/libc/gen/unvis.3
deleted file mode 100644
index 9164f792db83..000000000000
--- a/lib/libc/gen/unvis.3
+++ /dev/null
@@ -1,200 +0,0 @@
-.\" Copyright (c) 1989, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" @(#)unvis.3 8.2 (Berkeley) 12/11/93
-.\" $FreeBSD$
-.\"
-.Dd December 11, 1993
-.Dt UNVIS 3
-.Os
-.Sh NAME
-.Nm unvis ,
-.Nm strunvis
-.Nd decode a visual representation of characters
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In vis.h
-.Ft int
-.Fn unvis "char *cp" "int c" "int *astate" "int flag"
-.Ft int
-.Fn strunvis "char *dst" "const char *src"
-.Ft int
-.Fn strunvisx "char *dst" "const char *src" "int flag"
-.Sh DESCRIPTION
-The
-.Fn unvis ,
-.Fn strunvis
-and
-.Fn strunvisx
-functions
-are used to decode a visual representation of characters, as produced
-by the
-.Xr vis 3
-function, back into
-the original form.
-Unvis is called with successive characters in
-.Fa c
-until a valid
-sequence is recognized, at which time the decoded character is
-available at the character pointed to by
-.Fa cp .
-Strunvis decodes the
-characters pointed to by
-.Fa src
-into the buffer pointed to by
-.Fa dst .
-.Pp
-The
-.Fn strunvis
-function
-simply copies
-.Fa src
-to
-.Fa dst ,
-decoding any escape sequences along the way,
-and returns the number of characters placed into
-.Fa dst ,
-or \-1 if an
-invalid escape sequence was detected.
-The size of
-.Fa dst
-should be
-equal to the size of
-.Fa src
-(that is, no expansion takes place during
-decoding).
-.Pp
-The
-.Fn strunvisx
-function does the same as the
-.Fn strunvis
-function,
-but it allows you to add a flag that specifies the style the string
-.Fa src
-is encoded with.
-Currently, the only supported flag is
-.Dv VIS_HTTPSTYLE .
-.Pp
-The
-.Fn unvis
-function
-implements a state machine that can be used to decode an arbitrary
-stream of bytes.
-All state associated with the bytes being decoded
-is stored outside the
-.Fn unvis
-function (that is, a pointer to the state is passed in), so
-calls decoding different streams can be freely intermixed.
-To
-start decoding a stream of bytes, first initialize an integer
-to zero.
-Call
-.Fn unvis
-with each successive byte, along with a pointer
-to this integer, and a pointer to a destination character.
-The
-.Fn unvis
-function
-has several return codes that must be handled properly.
-They are:
-.Bl -tag -width UNVIS_VALIDPUSH
-.It Li \&0 (zero)
-Another character is necessary; nothing has been recognized yet.
-.It Dv UNVIS_VALID
-A valid character has been recognized and is available at the location
-pointed to by cp.
-.It Dv UNVIS_VALIDPUSH
-A valid character has been recognized and is available at the location
-pointed to by cp; however, the character currently passed in should
-be passed in again.
-.It Dv UNVIS_NOCHAR
-A valid sequence was detected, but no character was produced.
-This
-return code is necessary to indicate a logical break between characters.
-.It Dv UNVIS_SYNBAD
-An invalid escape sequence was detected, or the decoder is in an
-unknown state.
-The decoder is placed into the starting state.
-.El
-.Pp
-When all bytes in the stream have been processed, call
-.Fn unvis
-one more time with
-.Fa flag
-set to
-.Dv UNVIS_END
-to extract any remaining character (the character passed in is ignored).
-.Pp
-The
-.Fa flag
-argument is also used to specify the encoding style of the source.
-If set to
-.Dv VIS_HTTPSTYLE ,
-.Fn unvis
-will decode URI strings as specified in RFC 1808.
-.Pp
-The following code fragment illustrates a proper use of
-.Fn unvis .
-.Bd -literal -offset indent
-int state = 0;
-char out;
-
-while ((ch = getchar()) != EOF) {
-again:
- switch(unvis(&out, ch, &state, 0)) {
- case 0:
- case UNVIS_NOCHAR:
- break;
- case UNVIS_VALID:
- (void) putchar(out);
- break;
- case UNVIS_VALIDPUSH:
- (void) putchar(out);
- goto again;
- case UNVIS_SYNBAD:
- (void)fprintf(stderr, "bad sequence!\en");
- exit(1);
- }
-}
-if (unvis(&out, (char)0, &state, UNVIS_END) == UNVIS_VALID)
- (void) putchar(out);
-.Ed
-.Sh SEE ALSO
-.Xr vis 1 ,
-.Xr vis 3
-.Rs
-.%A R. Fielding
-.%T Relative Uniform Resource Locators
-.%O RFC1808
-.Re
-.Sh HISTORY
-The
-.Fn unvis
-function
-first appeared in
-.Bx 4.4 .
diff --git a/lib/libc/gen/unvis.c b/lib/libc/gen/unvis.c
deleted file mode 100644
index 9069e5545a4f..000000000000
--- a/lib/libc/gen/unvis.c
+++ /dev/null
@@ -1,293 +0,0 @@
-/*-
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <ctype.h>
-#include <vis.h>
-
-/*
- * decode driven by state machine
- */
-#define S_GROUND 0 /* haven't seen escape char */
-#define S_START 1 /* start decoding special sequence */
-#define S_META 2 /* metachar started (M) */
-#define S_META1 3 /* metachar more, regular char (-) */
-#define S_CTRL 4 /* control char started (^) */
-#define S_OCTAL2 5 /* octal digit 2 */
-#define S_OCTAL3 6 /* octal digit 3 */
-#define S_HEX2 7 /* hex digit 2 */
-
-#define S_HTTP 0x080 /* %HEXHEX escape */
-
-#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
-#define ishex(c) ((((u_char)(c)) >= '0' && ((u_char)(c)) <= '9') || (((u_char)(c)) >= 'a' && ((u_char)(c)) <= 'f'))
-
-/*
- * unvis - decode characters previously encoded by vis
- */
-int
-unvis(char *cp, int c, int *astate, int flag)
-{
-
- if (flag & UNVIS_END) {
- if (*astate == S_OCTAL2 || *astate == S_OCTAL3) {
- *astate = S_GROUND;
- return (UNVIS_VALID);
- }
- return (*astate == S_GROUND ? UNVIS_NOCHAR : UNVIS_SYNBAD);
- }
-
- switch (*astate & ~S_HTTP) {
-
- case S_GROUND:
- *cp = 0;
- if (c == '\\') {
- *astate = S_START;
- return (0);
- }
- if (flag & VIS_HTTPSTYLE && c == '%') {
- *astate = S_START | S_HTTP;
- return (0);
- }
- *cp = c;
- return (UNVIS_VALID);
-
- case S_START:
- if (*astate & S_HTTP) {
- if (ishex(tolower(c))) {
- *cp = isdigit(c) ? (c - '0') : (tolower(c) - 'a');
- *astate = S_HEX2;
- return (0);
- }
- }
- switch(c) {
- case '\\':
- *cp = c;
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- *cp = (c - '0');
- *astate = S_OCTAL2;
- return (0);
- case 'M':
- *cp = 0200;
- *astate = S_META;
- return (0);
- case '^':
- *astate = S_CTRL;
- return (0);
- case 'n':
- *cp = '\n';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'r':
- *cp = '\r';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'b':
- *cp = '\b';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'a':
- *cp = '\007';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'v':
- *cp = '\v';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 't':
- *cp = '\t';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'f':
- *cp = '\f';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 's':
- *cp = ' ';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case 'E':
- *cp = '\033';
- *astate = S_GROUND;
- return (UNVIS_VALID);
- case '\n':
- /*
- * hidden newline
- */
- *astate = S_GROUND;
- return (UNVIS_NOCHAR);
- case '$':
- /*
- * hidden marker
- */
- *astate = S_GROUND;
- return (UNVIS_NOCHAR);
- }
- *astate = S_GROUND;
- return (UNVIS_SYNBAD);
-
- case S_META:
- if (c == '-')
- *astate = S_META1;
- else if (c == '^')
- *astate = S_CTRL;
- else {
- *astate = S_GROUND;
- return (UNVIS_SYNBAD);
- }
- return (0);
-
- case S_META1:
- *astate = S_GROUND;
- *cp |= c;
- return (UNVIS_VALID);
-
- case S_CTRL:
- if (c == '?')
- *cp |= 0177;
- else
- *cp |= c & 037;
- *astate = S_GROUND;
- return (UNVIS_VALID);
-
- case S_OCTAL2: /* second possible octal digit */
- if (isoctal(c)) {
- /*
- * yes - and maybe a third
- */
- *cp = (*cp << 3) + (c - '0');
- *astate = S_OCTAL3;
- return (0);
- }
- /*
- * no - done with current sequence, push back passed char
- */
- *astate = S_GROUND;
- return (UNVIS_VALIDPUSH);
-
- case S_OCTAL3: /* third possible octal digit */
- *astate = S_GROUND;
- if (isoctal(c)) {
- *cp = (*cp << 3) + (c - '0');
- return (UNVIS_VALID);
- }
- /*
- * we were done, push back passed char
- */
- return (UNVIS_VALIDPUSH);
-
- case S_HEX2: /* second mandatory hex digit */
- if (ishex(tolower(c))) {
- *cp = (isdigit(c) ? (*cp << 4) + (c - '0') : (*cp << 4) + (tolower(c) - 'a' + 10));
- }
- *astate = S_GROUND;
- return (UNVIS_VALID);
-
- default:
- /*
- * decoder in unknown state - (probably uninitialized)
- */
- *astate = S_GROUND;
- return (UNVIS_SYNBAD);
- }
-}
-
-/*
- * strunvis - decode src into dst
- *
- * Number of chars decoded into dst is returned, -1 on error.
- * Dst is null terminated.
- */
-
-int
-strunvis(char *dst, const char *src)
-{
- char c;
- char *start = dst;
- int state = 0;
-
- while ( (c = *src++) ) {
- again:
- switch (unvis(dst, c, &state, 0)) {
- case UNVIS_VALID:
- dst++;
- break;
- case UNVIS_VALIDPUSH:
- dst++;
- goto again;
- case 0:
- case UNVIS_NOCHAR:
- break;
- default:
- return (-1);
- }
- }
- if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID)
- dst++;
- *dst = '\0';
- return (dst - start);
-}
-
-int
-strunvisx(char *dst, const char *src, int flag)
-{
- char c;
- char *start = dst;
- int state = 0;
-
- while ( (c = *src++) ) {
- again:
- switch (unvis(dst, c, &state, flag)) {
- case UNVIS_VALID:
- dst++;
- break;
- case UNVIS_VALIDPUSH:
- dst++;
- goto again;
- case 0:
- case UNVIS_NOCHAR:
- break;
- default:
- return (-1);
- }
- }
- if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID)
- dst++;
- *dst = '\0';
- return (dst - start);
-}
diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3
deleted file mode 100644
index 8ec16eb7c094..000000000000
--- a/lib/libc/gen/vis.3
+++ /dev/null
@@ -1,308 +0,0 @@
-.\" Copyright (c) 1989, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" From: @(#)vis.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD$
-.\"
-.Dd April 9, 2006
-.Dt VIS 3
-.Os
-.Sh NAME
-.Nm vis
-.Nd visually encode characters
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In vis.h
-.Ft char *
-.Fn vis "char *dst" "int c" "int flag" "int nextc"
-.Ft int
-.Fn strvis "char *dst" "const char *src" "int flag"
-.Ft int
-.Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
-.Sh DESCRIPTION
-The
-.Fn vis
-function
-copies into
-.Fa dst
-a string which represents the character
-.Fa c .
-If
-.Fa c
-needs no encoding, it is copied in unaltered.
-The string is
-null terminated, and a pointer to the end of the string is
-returned.
-The maximum length of any encoding is four
-characters (not including the trailing
-.Dv NUL ) ;
-thus, when
-encoding a set of characters into a buffer, the size of the buffer should
-be four times the number of characters encoded, plus one for the trailing
-.Dv NUL .
-The
-.Fa flag
-argument is used for altering the default range of
-characters considered for encoding and for altering the visual
-representation.
-The additional character,
-.Fa nextc ,
-is only used when selecting the
-.Dv VIS_CSTYLE
-encoding format (explained below).
-.Pp
-The
-.Fn strvis
-and
-.Fn strvisx
-functions copy into
-.Fa dst
-a visual representation of
-the string
-.Fa src .
-The
-.Fn strvis
-function encodes characters from
-.Fa src
-up to the
-first
-.Dv NUL .
-The
-.Fn strvisx
-function encodes exactly
-.Fa len
-characters from
-.Fa src
-(this
-is useful for encoding a block of data that may contain
-.Dv NUL Ns 's ) .
-Both forms
-.Dv NUL
-terminate
-.Fa dst .
-The size of
-.Fa dst
-must be four times the number
-of characters encoded from
-.Fa src
-(plus one for the
-.Dv NUL ) .
-Both
-forms return the number of characters in dst (not including
-the trailing
-.Dv NUL ) .
-.Pp
-The encoding is a unique, invertible representation composed entirely of
-graphic characters; it can be decoded back into the original form using
-the
-.Xr unvis 3
-or
-.Xr strunvis 3
-functions.
-.Pp
-There are two parameters that can be controlled: the range of
-characters that are encoded, and the type
-of representation used.
-By default, all non-graphic characters
-except space, tab, and newline are encoded.
-(See
-.Xr isgraph 3 . )
-The following flags
-alter this:
-.Bl -tag -width VIS_WHITEX
-.It Dv VIS_GLOB
-Also encode magic characters
-.Ql ( * ,
-.Ql \&? ,
-.Ql \&[
-and
-.Ql # )
-recognized by
-.Xr glob 3 .
-.It Dv VIS_SP
-Also encode space.
-.It Dv VIS_TAB
-Also encode tab.
-.It Dv VIS_NL
-Also encode newline.
-.It Dv VIS_WHITE
-Synonym for
-.Dv VIS_SP
-\&|
-.Dv VIS_TAB
-\&|
-.Dv VIS_NL .
-.It Dv VIS_SAFE
-Only encode "unsafe" characters.
-Unsafe means control
-characters which may cause common terminals to perform
-unexpected functions.
-Currently this form allows space,
-tab, newline, backspace, bell, and return - in addition
-to all graphic characters - unencoded.
-.El
-.Pp
-There are four forms of encoding.
-Most forms use the backslash character
-.Ql \e
-to introduce a special
-sequence; two backslashes are used to represent a real backslash.
-These are the visual formats:
-.Bl -tag -width VIS_HTTPSTYLE
-.It (default)
-Use an
-.Ql M
-to represent meta characters (characters with the 8th
-bit set), and use caret
-.Ql ^
-to represent control characters see
-.Pf ( Xr iscntrl 3 ) .
-The following formats are used:
-.Bl -tag -width xxxxx
-.It Dv \e^C
-Represents the control character
-.Ql C .
-Spans characters
-.Ql \e000
-through
-.Ql \e037 ,
-and
-.Ql \e177
-(as
-.Ql \e^? ) .
-.It Dv \eM-C
-Represents character
-.Ql C
-with the 8th bit set.
-Spans characters
-.Ql \e241
-through
-.Ql \e376 .
-.It Dv \eM^C
-Represents control character
-.Ql C
-with the 8th bit set.
-Spans characters
-.Ql \e200
-through
-.Ql \e237 ,
-and
-.Ql \e377
-(as
-.Ql \eM^? ) .
-.It Dv \e040
-Represents
-.Tn ASCII
-space.
-.It Dv \e240
-Represents Meta-space.
-.El
-.Pp
-.It Dv VIS_CSTYLE
-Use C-style backslash sequences to represent standard non-printable
-characters.
-The following sequences are used to represent the indicated characters:
-.Pp
-.Bl -tag -width ".Li \e0" -offset indent -compact
-.It Li \ea
-.Dv BEL No (007)
-.It Li \eb
-.Dv BS No (010)
-.It Li \ef
-.Dv NP No (014)
-.It Li \en
-.Dv NL No (012)
-.It Li \er
-.Dv CR No (015)
-.It Li \es
-.Dv SP No (040)
-.It Li \et
-.Dv HT No (011)
-.It Li \ev
-.Dv VT No (013)
-.It Li \e0
-.Dv NUL No (000)
-.El
-.Pp
-When using this format, the
-.Fa nextc
-argument is looked at to determine
-if a
-.Dv NUL
-character can be encoded as
-.Ql \e0
-instead of
-.Ql \e000 .
-If
-.Fa nextc
-is an octal digit, the latter representation is used to
-avoid ambiguity.
-.It Dv VIS_HTTPSTYLE
-Use URI encoding as described in RFC 1808.
-The form is
-.Ql %dd
-where
-.Ar d
-represents a hexadecimal digit.
-.It Dv VIS_OCTAL
-Use a three digit octal sequence.
-The form is
-.Ql \eddd
-where
-.Ar d
-represents an octal digit.
-.El
-.Pp
-There is one additional flag,
-.Dv VIS_NOSLASH ,
-which inhibits the
-doubling of backslashes and the backslash before the default
-format (that is, control characters are represented by
-.Ql ^C
-and
-meta characters as
-.Ql M-C ) .
-With this flag set, the encoding is
-ambiguous and non-invertible.
-.Sh SEE ALSO
-.Xr unvis 1 ,
-.Xr unvis 3
-.Rs
-.%A R. Fielding
-.%T Relative Uniform Resource Locators
-.%O RFC1808
-.Re
-.Sh HISTORY
-These functions first appeared in
-.Bx 4.4 .
-.Sh BUGS
-The
-.Nm
-family of functions do not recognize multibyte characters, and thus
-may consider them to be non-printable when they are in fact printable
-(and vice versa.)
diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c
deleted file mode 100644
index 362f4dc36c6f..000000000000
--- a/lib/libc/gen/vis.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/*-
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)vis.c 8.1 (Berkeley) 7/19/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <limits.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <vis.h>
-
-#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
-
-/*
- * vis - visually encode characters
- */
-char *
-vis(dst, c, flag, nextc)
- char *dst;
- int c, nextc;
- int flag;
-{
- c = (unsigned char)c;
-
- if (flag & VIS_HTTPSTYLE) {
- /* Described in RFC 1808 */
- if (!(isalnum(c) /* alpha-numeric */
- /* safe */
- || c == '$' || c == '-' || c == '_' || c == '.' || c == '+'
- /* extra */
- || c == '!' || c == '*' || c == '\'' || c == '('
- || c == ')' || c == ',')) {
- *dst++ = '%';
- snprintf(dst, 4, (c < 16 ? "0%X" : "%X"), c);
- dst += 2;
- goto done;
- }
- }
-
- if ((flag & VIS_GLOB) &&
- (c == '*' || c == '?' || c == '[' || c == '#'))
- ;
- else if (isgraph(c) ||
- ((flag & VIS_SP) == 0 && c == ' ') ||
- ((flag & VIS_TAB) == 0 && c == '\t') ||
- ((flag & VIS_NL) == 0 && c == '\n') ||
- ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) {
- *dst++ = c;
- if (c == '\\' && (flag & VIS_NOSLASH) == 0)
- *dst++ = '\\';
- *dst = '\0';
- return (dst);
- }
-
- if (flag & VIS_CSTYLE) {
- switch(c) {
- case '\n':
- *dst++ = '\\';
- *dst++ = 'n';
- goto done;
- case '\r':
- *dst++ = '\\';
- *dst++ = 'r';
- goto done;
- case '\b':
- *dst++ = '\\';
- *dst++ = 'b';
- goto done;
- case '\a':
- *dst++ = '\\';
- *dst++ = 'a';
- goto done;
- case '\v':
- *dst++ = '\\';
- *dst++ = 'v';
- goto done;
- case '\t':
- *dst++ = '\\';
- *dst++ = 't';
- goto done;
- case '\f':
- *dst++ = '\\';
- *dst++ = 'f';
- goto done;
- case ' ':
- *dst++ = '\\';
- *dst++ = 's';
- goto done;
- case '\0':
- *dst++ = '\\';
- *dst++ = '0';
- if (isoctal(nextc)) {
- *dst++ = '0';
- *dst++ = '0';
- }
- goto done;
- }
- }
- if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
- *dst++ = '\\';
- *dst++ = ((u_char)c >> 6 & 07) + '0';
- *dst++ = ((u_char)c >> 3 & 07) + '0';
- *dst++ = ((u_char)c & 07) + '0';
- goto done;
- }
- if ((flag & VIS_NOSLASH) == 0)
- *dst++ = '\\';
- if (c & 0200) {
- c &= 0177;
- *dst++ = 'M';
- }
- if (iscntrl(c)) {
- *dst++ = '^';
- if (c == 0177)
- *dst++ = '?';
- else
- *dst++ = c + '@';
- } else {
- *dst++ = '-';
- *dst++ = c;
- }
-done:
- *dst = '\0';
- return (dst);
-}
-
-/*
- * strvis, strvisx - visually encode characters from src into dst
- *
- * Dst must be 4 times the size of src to account for possible
- * expansion. The length of dst, not including the trailing NUL,
- * is returned.
- *
- * Strvisx encodes exactly len bytes from src into dst.
- * This is useful for encoding a block of data.
- */
-int
-strvis(dst, src, flag)
- char *dst;
- const char *src;
- int flag;
-{
- char c;
- char *start;
-
- for (start = dst; (c = *src); )
- dst = vis(dst, c, flag, *++src);
- *dst = '\0';
- return (dst - start);
-}
-
-int
-strvisx(dst, src, len, flag)
- char *dst;
- const char *src;
- size_t len;
- int flag;
-{
- int c;
- char *start;
-
- for (start = dst; len > 1; len--) {
- c = *src;
- dst = vis(dst, c, flag, *++src);
- }
- if (len)
- dst = vis(dst, *src, flag, '\0');
- *dst = '\0';
-
- return (dst - start);
-}
diff --git a/lib/libc/gen/waitid.c b/lib/libc/gen/waitid.c
new file mode 100644
index 000000000000..795b2085f8d5
--- /dev/null
+++ b/lib/libc/gen/waitid.c
@@ -0,0 +1,65 @@
+/*-
+ * Copyright (c) 2012 Jukka A. Ukkonen
+ * All rights reserved.
+ *
+ * This software was developed by Jukka Ukkonen for FreeBSD.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stddef.h>
+#include <string.h>
+#include <signal.h>
+#include <errno.h>
+#include "un-namespace.h"
+
+int
+__waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags)
+{
+ int status;
+ pid_t ret;
+
+ ret = _wait6(idtype, id, &status, flags, NULL, info);
+
+ /*
+ * According to SUSv4, waitid() shall not return a PID when a
+ * process is found, but only 0. If a process was actually
+ * found, siginfo_t fields si_signo and si_pid will be
+ * non-zero. In case WNOHANG was set in the flags and no
+ * process was found those fields are set to zero using
+ * memset() below.
+ */
+ if (ret == 0 && info != NULL)
+ memset(info, 0, sizeof(*info));
+ else if (ret > 0)
+ ret = 0;
+ return (ret);
+}
+
+__weak_reference(__waitid, waitid);
+__weak_reference(__waitid, _waitid);
diff --git a/lib/libc/i386/sys/__vdso_gettc.c b/lib/libc/i386/sys/__vdso_gettc.c
index 4419141a5197..c6f2dfb3556a 100644
--- a/lib/libc/i386/sys/__vdso_gettc.c
+++ b/lib/libc/i386/sys/__vdso_gettc.c
@@ -27,9 +27,11 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
+#include <sys/elf.h>
#include <sys/time.h>
#include <sys/vdso.h>
#include <machine/cpufunc.h>
+#include "libc_private.h"
static u_int
__vdso_gettc_low(const struct vdso_timehands *th)
@@ -48,3 +50,11 @@ __vdso_gettc(const struct vdso_timehands *th)
return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) : rdtsc32());
}
+
+#pragma weak __vdso_gettimekeep
+int
+__vdso_gettimekeep(struct vdso_timekeep **tk)
+{
+
+ return (_elf_aux_info(AT_TIMEKEEP, tk, sizeof(*tk)));
+}
diff --git a/lib/libc/ia64/sys/Makefile.inc b/lib/libc/ia64/sys/Makefile.inc
index 3876d3a11e2d..28465909a6f2 100644
--- a/lib/libc/ia64/sys/Makefile.inc
+++ b/lib/libc/ia64/sys/Makefile.inc
@@ -1,5 +1,7 @@
# $FreeBSD$
+SRCS+= __vdso_gettc.c
+
MDASM+= Ovfork.S brk.S cerror.S exect.S fork.S getcontext.S pipe.S ptrace.S \
sbrk.S setlogin.S sigreturn.S swapcontext.S
diff --git a/lib/libdisk/write_arm_disk.c b/lib/libc/ia64/sys/__vdso_gettc.c
index 5dbb0ad650f0..b99bbc4f3d0f 100644
--- a/lib/libdisk/write_arm_disk.c
+++ b/lib/libc/ia64/sys/__vdso_gettc.c
@@ -1,6 +1,5 @@
/*-
- * Copyright (c) 2006 Olivier Houchard
- * All rights reserved.
+ * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,21 +26,23 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <err.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/disklabel.h>
-#include <paths.h>
-#include "libdisk.h"
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <errno.h>
-int
-Write_Disk(const struct disk *d1)
+#pragma weak __vdso_gettc
+u_int
+__vdso_gettc(const struct vdso_timehands *th)
{
+
return (0);
}
+
+#pragma weak __vdso_gettimekeep
+int
+__vdso_gettimekeep(struct vdso_timekeep **tk)
+{
+
+ return (ENOSYS);
+}
diff --git a/lib/libc/iconv/citrus_mmap.c b/lib/libc/iconv/citrus_mmap.c
index dd5d059786eb..2aaf73ca0b5f 100644
--- a/lib/libc/iconv/citrus_mmap.c
+++ b/lib/libc/iconv/citrus_mmap.c
@@ -57,12 +57,8 @@ _citrus_map_file(struct _citrus_region * __restrict r,
_region_init(r, NULL, 0);
- if ((fd = open(path, O_RDONLY)) == -1)
+ if ((fd = open(path, O_RDONLY | O_CLOEXEC)) == -1)
return (errno);
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
- ret = errno;
- goto error;
- }
if (fstat(fd, &st) == -1) {
ret = errno;
diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h
index 1e00030dc079..739d7b112392 100644
--- a/lib/libc/include/namespace.h
+++ b/lib/libc/include/namespace.h
@@ -229,6 +229,7 @@
#define socketpair _socketpair
#define usleep _usleep
#define wait4 _wait4
+#define wait6 _wait6
#define waitpid _waitpid
#define write _write
#define writev _writev
diff --git a/lib/libc/include/un-namespace.h b/lib/libc/include/un-namespace.h
index 9c9ce97d2002..f31fa7ade9e7 100644
--- a/lib/libc/include/un-namespace.h
+++ b/lib/libc/include/un-namespace.h
@@ -210,6 +210,7 @@
#undef socketpair
#undef usleep
#undef wait4
+#undef wait6
#undef waitpid
#undef write
#undef writev
diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c
index 676d41cc082f..56513f4b9ccf 100644
--- a/lib/libc/locale/collate.c
+++ b/lib/libc/locale/collate.c
@@ -135,7 +135,7 @@ __collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
(void)strcat(buf, "/");
(void)strcat(buf, encoding);
(void)strcat(buf, "/LC_COLLATE");
- if ((fp = fopen(buf, "r")) == NULL)
+ if ((fp = fopen(buf, "re")) == NULL)
return (_LDP_ERROR);
if (fread(strbuf, sizeof(strbuf), 1, fp) != 1) {
diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c
index 3ffb64915bd0..49e6f6e6548b 100644
--- a/lib/libc/locale/setrunelocale.c
+++ b/lib/libc/locale/setrunelocale.c
@@ -73,9 +73,11 @@ static int __setrunelocale(struct xlocale_ctype *l, const char *);
#define __collate_chain_pri_table (table->__collate_chain_pri_table)
-static void destruct_ctype(void *v)
+static void
+destruct_ctype(void *v)
{
struct xlocale_ctype *l = v;
+
if (strcmp(l->runes->__encoding, "EUC") == 0)
free(l->runes->__variable);
if (&_DefaultRuneLocale != l->runes)
@@ -83,13 +85,17 @@ static void destruct_ctype(void *v)
free(l);
}
-const _RuneLocale *__getCurrentRuneLocale(void)
+const _RuneLocale *
+__getCurrentRuneLocale(void)
{
+
return XLOCALE_CTYPE(__get_locale())->runes;
}
-static void free_runes(_RuneLocale *rl)
+static void
+free_runes(_RuneLocale *rl)
{
+
/* FIXME: The "EUC" check here is a hideous abstraction violation. */
if ((rl != &_DefaultRuneLocale) && (rl)) {
if (strcmp(rl->__encoding, "EUC") == 0) {
@@ -123,7 +129,7 @@ __setrunelocale(struct xlocale_ctype *l, const char *encoding)
(void) strcat(name, encoding);
(void) strcat(name, "/LC_CTYPE");
- if ((fp = fopen(name, "r")) == NULL)
+ if ((fp = fopen(name, "re")) == NULL)
return (errno == 0 ? ENOENT : errno);
if ((rl = _Read_RuneMagi(fp)) == NULL) {
@@ -191,7 +197,8 @@ __wrap_setrunelocale(const char *locale)
#ifndef __NO_TLS
void
-__set_thread_rune_locale(locale_t loc) {
+__set_thread_rune_locale(locale_t loc)
+{
if (loc == NULL) {
_ThreadRuneLocale = &_DefaultRuneLocale;
@@ -205,6 +212,7 @@ void *
__ctype_load(const char *locale, locale_t unused)
{
struct xlocale_ctype *l = calloc(sizeof(struct xlocale_ctype), 1);
+
l->header.header.destructor = destruct_ctype;
if (__setrunelocale(l, locale))
{
diff --git a/lib/libc/mips/sys/Makefile.inc b/lib/libc/mips/sys/Makefile.inc
index 3601909bc0ec..fc1134910646 100644
--- a/lib/libc/mips/sys/Makefile.inc
+++ b/lib/libc/mips/sys/Makefile.inc
@@ -1,5 +1,7 @@
# $FreeBSD$
+SRCS+= __vdso_gettc.c
+
MDASM= Ovfork.S brk.S cerror.S exect.S \
fork.S pipe.S ptrace.S sbrk.S syscall.S
diff --git a/lib/libc/mips/sys/__vdso_gettc.c b/lib/libc/mips/sys/__vdso_gettc.c
new file mode 100644
index 000000000000..b99bbc4f3d0f
--- /dev/null
+++ b/lib/libc/mips/sys/__vdso_gettc.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <errno.h>
+
+#pragma weak __vdso_gettc
+u_int
+__vdso_gettc(const struct vdso_timehands *th)
+{
+
+ return (0);
+}
+
+#pragma weak __vdso_gettimekeep
+int
+__vdso_gettimekeep(struct vdso_timekeep **tk)
+{
+
+ return (ENOSYS);
+}
diff --git a/lib/libc/net/getnetent.3 b/lib/libc/net/getnetent.3
index 2e9cd339b0e2..ec08b6b1f852 100644
--- a/lib/libc/net/getnetent.3
+++ b/lib/libc/net/getnetent.3
@@ -73,7 +73,7 @@ The order of the lookups is controlled by the
`networks' entry in
.Xr nsswitch.conf 5 .
.Bd -literal -offset indent
-struct netent {
+struct netent {
char *n_name; /* official name of net */
char **n_aliases; /* alias list */
int n_addrtype; /* net number type */
@@ -142,8 +142,7 @@ Network numbers are supplied in host order.
.It Pa /etc/resolv.conf
.El
.Sh DIAGNOSTICS
-Null pointer
-(0) returned on
+Null pointer returned on
.Dv EOF
or error.
.Sh SEE ALSO
diff --git a/lib/libc/net/getprotoent.3 b/lib/libc/net/getprotoent.3
index 9f9e00daf7b8..565e038fa252 100644
--- a/lib/libc/net/getprotoent.3
+++ b/lib/libc/net/getprotoent.3
@@ -65,7 +65,7 @@ containing the broken-out
fields of a line in the network protocol data base,
.Pa /etc/protocols .
.Bd -literal -offset indent
-struct protoent {
+struct protoent {
char *p_name; /* official name of protocol */
char **p_aliases; /* alias list */
int p_proto; /* protocol number */
@@ -117,8 +117,7 @@ or until
.Dv EOF
is encountered.
.Sh RETURN VALUES
-Null pointer
-(0) returned on
+Null pointer returned on
.Dv EOF
or error.
.Sh FILES
diff --git a/lib/libc/net/getservent.3 b/lib/libc/net/getservent.3
index 65d40bbb4039..5f5a452c0973 100644
--- a/lib/libc/net/getservent.3
+++ b/lib/libc/net/getservent.3
@@ -65,7 +65,7 @@ containing the broken-out
fields of a line in the network services data base,
.Pa /etc/services .
.Bd -literal -offset indent
-struct servent {
+struct servent {
char *s_name; /* official name of service */
char **s_aliases; /* alias list */
int s_port; /* port service resides at */
@@ -130,8 +130,7 @@ searches must also match the protocol.
.It Pa /etc/services
.El
.Sh DIAGNOSTICS
-Null pointer
-(0) returned on
+Null pointer returned on
.Dv EOF
or error.
.Sh SEE ALSO
diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c
index 0031f462ffc2..f36016249602 100644
--- a/lib/libc/net/name6.c
+++ b/lib/libc/net/name6.c
@@ -200,6 +200,7 @@ static struct hostent *_hpmapv6(struct hostent *, int *);
#endif
static struct hostent *_hpsort(struct hostent *, res_state);
+#ifdef INET6
static struct hostent *_hpreorder(struct hostent *);
static int get_addrselectpolicy(struct policyhead *);
static void free_addrselectpolicy(struct policyhead *);
@@ -209,6 +210,7 @@ static void set_source(struct hp_order *, struct policyhead *);
static int matchlen(struct sockaddr *, struct sockaddr *);
static int comp_dst(const void *, const void *);
static int gai_addr2scopetype(struct sockaddr *);
+#endif
/*
* Functions defined in RFC2553
@@ -285,8 +287,10 @@ getipnodebyname(const char *name, int af, int flags, int *errp)
hp = gethostbyname2(name, af);
hp = _hpcopy(hp, errp);
-
#ifdef INET6
+ if (af == AF_INET6)
+ hp = _hpreorder(hp);
+
if (af == AF_INET6 && ((flags & AI_ALL) || hp == NULL) &&
MAPADDRENABLED(flags)) {
struct hostent *hp2 = gethostbyname2(name, AF_INET);
@@ -309,7 +313,7 @@ getipnodebyname(const char *name, int af, int flags, int *errp)
*errp = statp->res_h_errno;
statp->options = options;
- return _hpreorder(_hpsort(hp, statp));
+ return _hpsort(hp, statp);
}
struct hostent *
@@ -632,6 +636,7 @@ _hpsort(struct hostent *hp, res_state statp)
return hp;
}
+#ifdef INET6
/*
* _hpreorder: sort address by default address selection
*/
@@ -1109,3 +1114,4 @@ gai_addr2scopetype(struct sockaddr *sa)
return(-1);
}
}
+#endif
diff --git a/lib/libc/net/sctp_sys_calls.c b/lib/libc/net/sctp_sys_calls.c
index 1e06f449fabe..beedf94d0652 100644
--- a/lib/libc/net/sctp_sys_calls.c
+++ b/lib/libc/net/sctp_sys_calls.c
@@ -188,30 +188,34 @@ sctp_connectx(int sd, const struct sockaddr *addrs, int addrcnt,
cpto = ((caddr_t)buf + sizeof(int));
/* validate all the addresses and get the size */
for (i = 0; i < addrcnt; i++) {
- if (at->sa_family == AF_INET) {
+ switch (at->sa_family) {
+ case AF_INET:
if (at->sa_len != sizeof(struct sockaddr_in)) {
errno = EINVAL;
return (-1);
}
- memcpy(cpto, at, at->sa_len);
- cpto = ((caddr_t)cpto + at->sa_len);
- len += at->sa_len;
- } else if (at->sa_family == AF_INET6) {
+ memcpy(cpto, at, sizeof(struct sockaddr_in));
+ cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in));
+ len += sizeof(struct sockaddr_in);
+ at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in));
+ break;
+ case AF_INET6:
if (at->sa_len != sizeof(struct sockaddr_in6)) {
errno = EINVAL;
return (-1);
}
if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)at)->sin6_addr)) {
- len += sizeof(struct sockaddr_in);
in6_sin6_2_sin((struct sockaddr_in *)cpto, (struct sockaddr_in6 *)at);
cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in));
len += sizeof(struct sockaddr_in);
} else {
- memcpy(cpto, at, at->sa_len);
- cpto = ((caddr_t)cpto + at->sa_len);
- len += at->sa_len;
+ memcpy(cpto, at, sizeof(struct sockaddr_in6));
+ cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in6));
+ len += sizeof(struct sockaddr_in6);
}
- } else {
+ at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in6));
+ break;
+ default:
errno = EINVAL;
return (-1);
}
@@ -220,7 +224,6 @@ sctp_connectx(int sd, const struct sockaddr *addrs, int addrcnt,
errno = E2BIG;
return (-1);
}
- at = (struct sockaddr *)((caddr_t)at + at->sa_len);
cnt++;
}
/* do we have any? */
@@ -261,56 +264,57 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags)
errno = EINVAL;
return (-1);
}
- argsz = (sizeof(struct sockaddr_storage) +
- sizeof(struct sctp_getaddresses));
- gaddrs = (struct sctp_getaddresses *)calloc(1, argsz);
- if (gaddrs == NULL) {
- errno = ENOMEM;
- return (-1);
- }
/* First pre-screen the addresses */
sa = addrs;
for (i = 0; i < addrcnt; i++) {
- if (sa->sa_family == AF_INET) {
- if (sa->sa_len != sizeof(struct sockaddr_in))
- goto out_error;
+ switch (sa->sa_family) {
+ case AF_INET:
+ if (sa->sa_len != sizeof(struct sockaddr_in)) {
+ errno = EINVAL;
+ return (-1);
+ }
sin = (struct sockaddr_in *)sa;
if (sin->sin_port) {
/* non-zero port, check or save */
if (sport) {
/* Check against our port */
if (sport != sin->sin_port) {
- goto out_error;
+ errno = EINVAL;
+ return (-1);
}
} else {
/* save off the port */
sport = sin->sin_port;
}
}
- } else if (sa->sa_family == AF_INET6) {
- if (sa->sa_len != sizeof(struct sockaddr_in6))
- goto out_error;
+ break;
+ case AF_INET6:
+ if (sa->sa_len != sizeof(struct sockaddr_in6)) {
+ errno = EINVAL;
+ return (-1);
+ }
sin6 = (struct sockaddr_in6 *)sa;
if (sin6->sin6_port) {
/* non-zero port, check or save */
if (sport) {
/* Check against our port */
if (sport != sin6->sin6_port) {
- goto out_error;
+ errno = EINVAL;
+ return (-1);
}
} else {
/* save off the port */
sport = sin6->sin6_port;
}
}
- } else {
- /* invalid address family specified */
- goto out_error;
+ break;
+ default:
+ /* Invalid address family specified. */
+ errno = EINVAL;
+ return (-1);
}
-
sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
}
- sa = addrs;
/*
* Now if there was a port mentioned, assure that the first address
* has that port to make sure it fails or succeeds correctly.
@@ -319,20 +323,14 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags)
sin = (struct sockaddr_in *)sa;
sin->sin_port = sport;
}
+ argsz = sizeof(struct sctp_getaddresses) +
+ sizeof(struct sockaddr_storage);
+ if ((gaddrs = (struct sctp_getaddresses *)malloc(argsz)) == NULL) {
+ errno = ENOMEM;
+ return (-1);
+ }
+ sa = addrs;
for (i = 0; i < addrcnt; i++) {
- if (sa->sa_family == AF_INET) {
- if (sa->sa_len != sizeof(struct sockaddr_in))
- goto out_error;
- } else if (sa->sa_family == AF_INET6) {
- if (sa->sa_len != sizeof(struct sockaddr_in6))
- goto out_error;
- } else {
- /* invalid address family specified */
- out_error:
- free(gaddrs);
- errno = EINVAL;
- return (-1);
- }
memset(gaddrs, 0, argsz);
gaddrs->sget_assoc_id = 0;
memcpy(gaddrs->addr, sa, sa->sa_len);
diff --git a/lib/libc/nls/Makefile.inc b/lib/libc/nls/Makefile.inc
index f5c6885ae042..962d16bbf985 100644
--- a/lib/libc/nls/Makefile.inc
+++ b/lib/libc/nls/Makefile.inc
@@ -36,3 +36,6 @@ NLS+= ru_RU.KOI8-R
NLS+= sk_SK.ISO8859-2
NLS+= sv_SE.ISO8859-1
NLS+= uk_UA.UTF-8
+NLS+= zh_CN.GB18030
+NLS+= zh_CN.GB2312
+NLS+= zh_CN.UTF-8
diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c
index 44b144084092..2859916fd8fd 100644
--- a/lib/libc/nls/msgcat.c
+++ b/lib/libc/nls/msgcat.c
@@ -82,6 +82,7 @@ __FBSDID("$FreeBSD$");
if (np != NULL) { \
np->name = strdup(n); \
np->path = NULL; \
+ np->catd = NLERR; \
np->lang = (l == NULL) ? NULL : \
strdup(l); \
np->caterrno = e; \
diff --git a/lib/libc/nls/zh_CN.GB18030.msg b/lib/libc/nls/zh_CN.GB18030.msg
new file mode 100644
index 000000000000..0e35d7e9eb73
--- /dev/null
+++ b/lib/libc/nls/zh_CN.GB18030.msg
@@ -0,0 +1,297 @@
+$ $FreeBSD$
+$
+$ Message catalog for zh_CN.GB18030 locale
+$
+$ Derived from FreeBSD: head/lib/libc/nls/zh_CN.UTF-8.msg 244756 2012-12-28 01:09:30Z delphij
+$
+$ strerror() support catalog
+$
+$set 1
+$ EPERM
+1 不允许的操作
+$ ENOENT
+2 文件或目录不存在
+$ ESRCH
+3 进程不存在
+$ EINTR
+4 系统调用中止
+$ EIO
+5 输入/输出错误
+$ ENXIO
+6 未配置的设备
+$ E2BIG
+7 参数表过长
+$ ENOEXEC
+8 可执行文件格式错误
+$ EBADF
+9 文件描述符无效
+$ ECHILD
+10 指定子进程不存在
+$ EDEADLK
+11 此操作会导致死锁
+$ ENOMEM
+12 无法分配内存
+$ EACCES
+13 拒绝访问
+$ EFAULT
+14 无效地址
+$ ENOTBLK
+15 该操作需要块设备
+$ EBUSY
+16 设备使用中
+$ EEXIST
+17 文件已存在
+$ EXDEV
+18 链接跨设备
+$ ENODEV
+19 设备不支持此操作
+$ ENOTDIR
+20 对象非目录
+$ EISDIR
+21 对象为目录
+$ EINVAL
+22 参数无效
+$ ENFILE
+23 系统打开文件过多
+$ EMFILE
+24 进程打开文件过多
+$ ENOTTY
+25 无效设备 ioctl
+$ ETXTBSY
+26 可执行文件忙
+$ EFBIG
+27 文件过大
+$ ENOSPC
+28 设备无可用空间
+$ ESPIPE
+29 不允许执行 seek 操作
+$ EROFS
+30 文件系统只读
+$ EMLINK
+31 文件链接过多
+$ EPIPE
+32 管道已中止
+$ EDOM
+33 数值参数越界
+$ ERANGE
+34 结果过大
+$ EAGAIN, EWOULDBLOCK
+35 资源暂时不可用
+$ EINPROGRESS
+36 操作进行中
+$ EALREADY
+37 操作已开始
+$ ENOTSOCK
+38 尝试在非 socket 上执行 socket 操作
+$ EDESTADDRREQ
+39 需要目的地址
+$ EMSGSIZE
+40 消息过长
+$ EPROTOTYPE
+41 socket协议类型错误
+$ ENOPROTOOPT
+42 协议不可用
+$ EPROTONOSUPPORT
+43 不支持的协议
+$ ESOCKTNOSUPPORT
+44 不支持的 socket 类型
+$ EOPNOTSUPP
+45 不支持的操作
+$ EPFNOSUPPORT
+46 不支持的协议族
+$ EAFNOSUPPORT
+47 协议族不支持的地址族
+$ EADDRINUSE
+48 地址已被占用
+$ EADDRNOTAVAIL
+49 无法指定请求的地址
+$ ENETDOWN
+50 网络已关闭
+$ ENETUNREACH
+51 网络不可达
+$ ENETRESET
+52 复位导致网络连接丢失
+$ ECONNABORTED
+53 软件导致的连接中止
+$ ECONNRESET
+54 对方复位了连接
+$ ENOBUFS
+55 缓冲区空间不足
+$ EISCONN
+56 socket 已连接
+$ ENOTCONN
+57 socket 未连接
+$ ESHUTDOWN
+58 socket shutdown 之后无法发送数据
+$ ETOOMANYREFS
+59 引用数过多:无法拼接
+$ ETIMEDOUT
+60 操作超时
+$ ECONNREFUSED
+61 拒绝连接
+$ ELOOP
+62 符号链接层数过多
+$ ENAMETOOLONG
+63 文件名过长
+$ EHOSTDOWN
+64 主机已关闭
+$ EHOSTUNREACH
+65 没有到主机的路由
+$ ENOTEMPTY
+66 目录非空
+$ EPROCLIM
+67 进程数超限
+$ EUSERS
+68 用户数超限
+$ EDQUOT
+69 磁盘空间配额超限
+$ ESTALE
+70 NFS 文件句柄已失效
+$ EREMOTE
+71 远程目录层数过多
+$ EBADRPC
+72 RPC 结构无效
+$ ERPCMISMATCH
+73 RPC 版本错误
+$ EPROGUNAVAIL
+74 RPC 程序不可用
+$ EPROGMISMATCH
+75 程序版本错误
+$ EPROCUNAVAIL
+76 未提供的远程函数
+$ ENOLCK
+77 不支持锁
+$ ENOSYS
+78 功能未实现
+$ EFTYPE
+79 文件类型或格式无效
+$ EAUTH
+80 身份无效
+$ ENEEDAUTH
+81 无信任凭据
+$ EIDRM
+82 无标识符
+$ ENOMSG
+83 无消息类型
+$ EOVERFLOW
+84 数值溢出
+$ ECANCELED
+85 操作已取消
+$ EILSEQ
+86 无效字符序列
+$ ENOATTR
+87 无扩展属性
+$ EDOOFUS
+88 程序设计错误
+$ EBADMSG
+89 无效消息
+$ EMULTIHOP
+90 Multihop attempted
+$ ENOLINK
+91 Link has been severed
+$ EPROTO
+92 协议错误
+$ ENOTCAPABLE
+93 权能不足
+$
+$ strsignal() support catalog
+$
+$set 2
+$ SIGHUP
+1 终端线路挂断
+$ SIGINT
+2 中断
+$ SIGQUIT
+3 退出
+$ SIGILL
+4 无效指令
+$ SIGTRAP
+5 跟踪/BPT 陷阱
+$ SIGABRT
+6 终止陷阱
+$ SIGEMT
+7 EMT 陷阱
+$ SIGFPE
+8 浮点异常
+$ SIGKILL
+9 强制终止进程
+$ SIGBUS
+10 系统内存访问越界
+$ SIGSEGV
+11 内存访问越界
+$ SIGSYS
+12 无效系统调用
+$ SIGPIPE
+13 写管道时读取者不存在
+$ SIGALRM
+14 实时倒计时到期
+$ SIGTERM
+15 终止
+$ SIGURG
+16 需立即处理的 I/O 紧急状况
+$ SIGSTOP
+17 挂起 (信号)
+$ SIGTSTP
+18 挂起
+$ SIGCONT
+19 继续运行
+$ SIGCHLD
+20 子进程终止
+$ SIGTTIN
+21 TTY 输入阻塞
+$ SIGTTOU
+22 TTY 输出阻塞
+$ SIGIO
+23 I/O 就绪
+$ SIGXCPU
+24 CPU 使用时间过长
+$ SIGXFSZ
+25 文件尺寸过大
+$ SIGVTALRM
+26 虚拟倒计时到期
+$ SIGPROF
+27 剖析倒计时到期
+$ SIGWINCH
+28 窗口尺寸变化
+$ SIGINFO
+29 请求信息
+$ SIGUSR1
+30 用户自定义信号 1
+$ SIGUSR2
+31 用户自定义信号 2
+$
+$ gai_strerror() support catalog
+$
+$set 3
+$ 1 (obsolete)
+1 主机名使用了不支持的地址类型
+$ EAI_AGAIN
+2 暂时无法解析名称
+$ EAI_BADFLAGS
+3 无效的 ai_flags 值
+$ EAI_FAIL
+4 解析名称时出现无法恢复的错误
+$ EAI_FAMILY
+5 不支持的地址信息类型
+$ EAI_MEMORY
+6 内存分配失败
+$ 7 (obsolete)
+7 主机名无相关联的地址
+$ EAI_NONAME
+8 未知的主机名或服务名
+$ EAI_SERVICE
+9 套接字类型不支持此服务名
+$ EAI_SOCKTYPE
+10 不支持的套接字类型
+$ EAI_SYSTEM
+11 系统调用返回了 errno 错误
+$ EAI_BADHINTS
+12 无效提示参数
+$ EAI_PROTOCOL
+13 未知协议
+$ EAI_OVERFLOW
+14 参数缓冲溢出
+$ 0
+32766 成功
+$ NL_MSGMAX
+32767 未知错误
diff --git a/lib/libc/nls/zh_CN.GB2312.msg b/lib/libc/nls/zh_CN.GB2312.msg
new file mode 100644
index 000000000000..46ebb422ff84
--- /dev/null
+++ b/lib/libc/nls/zh_CN.GB2312.msg
@@ -0,0 +1,297 @@
+$ $FreeBSD$
+$
+$ Message catalog for zh_CN.GB2312 locale
+$
+$ Derived from FreeBSD: head/lib/libc/nls/zh_CN.UTF-8.msg 244756 2012-12-28 01:09:30Z delphij
+$
+$ strerror() support catalog
+$
+$set 1
+$ EPERM
+1 不允许的操作
+$ ENOENT
+2 文件或目录不存在
+$ ESRCH
+3 进程不存在
+$ EINTR
+4 系统调用中止
+$ EIO
+5 输入/输出错误
+$ ENXIO
+6 未配置的设备
+$ E2BIG
+7 参数表过长
+$ ENOEXEC
+8 可执行文件格式错误
+$ EBADF
+9 文件描述符无效
+$ ECHILD
+10 指定子进程不存在
+$ EDEADLK
+11 此操作会导致死锁
+$ ENOMEM
+12 无法分配内存
+$ EACCES
+13 拒绝访问
+$ EFAULT
+14 无效地址
+$ ENOTBLK
+15 该操作需要块设备
+$ EBUSY
+16 设备使用中
+$ EEXIST
+17 文件已存在
+$ EXDEV
+18 链接跨设备
+$ ENODEV
+19 设备不支持此操作
+$ ENOTDIR
+20 对象非目录
+$ EISDIR
+21 对象为目录
+$ EINVAL
+22 参数无效
+$ ENFILE
+23 系统打开文件过多
+$ EMFILE
+24 进程打开文件过多
+$ ENOTTY
+25 无效设备 ioctl
+$ ETXTBSY
+26 可执行文件忙
+$ EFBIG
+27 文件过大
+$ ENOSPC
+28 设备无可用空间
+$ ESPIPE
+29 不允许执行 seek 操作
+$ EROFS
+30 文件系统只读
+$ EMLINK
+31 文件链接过多
+$ EPIPE
+32 管道已中止
+$ EDOM
+33 数值参数越界
+$ ERANGE
+34 结果过大
+$ EAGAIN, EWOULDBLOCK
+35 资源暂时不可用
+$ EINPROGRESS
+36 操作进行中
+$ EALREADY
+37 操作已开始
+$ ENOTSOCK
+38 尝试在非 socket 上执行 socket 操作
+$ EDESTADDRREQ
+39 需要目的地址
+$ EMSGSIZE
+40 消息过长
+$ EPROTOTYPE
+41 socket协议类型错误
+$ ENOPROTOOPT
+42 协议不可用
+$ EPROTONOSUPPORT
+43 不支持的协议
+$ ESOCKTNOSUPPORT
+44 不支持的 socket 类型
+$ EOPNOTSUPP
+45 不支持的操作
+$ EPFNOSUPPORT
+46 不支持的协议族
+$ EAFNOSUPPORT
+47 协议族不支持的地址族
+$ EADDRINUSE
+48 地址已被占用
+$ EADDRNOTAVAIL
+49 无法指定请求的地址
+$ ENETDOWN
+50 网络已关闭
+$ ENETUNREACH
+51 网络不可达
+$ ENETRESET
+52 复位导致网络连接丢失
+$ ECONNABORTED
+53 软件导致的连接中止
+$ ECONNRESET
+54 对方复位了连接
+$ ENOBUFS
+55 缓冲区空间不足
+$ EISCONN
+56 socket 已连接
+$ ENOTCONN
+57 socket 未连接
+$ ESHUTDOWN
+58 socket shutdown 之后无法发送数据
+$ ETOOMANYREFS
+59 引用数过多:无法拼接
+$ ETIMEDOUT
+60 操作超时
+$ ECONNREFUSED
+61 拒绝连接
+$ ELOOP
+62 符号链接层数过多
+$ ENAMETOOLONG
+63 文件名过长
+$ EHOSTDOWN
+64 主机已关闭
+$ EHOSTUNREACH
+65 没有到主机的路由
+$ ENOTEMPTY
+66 目录非空
+$ EPROCLIM
+67 进程数超限
+$ EUSERS
+68 用户数超限
+$ EDQUOT
+69 磁盘空间配额超限
+$ ESTALE
+70 NFS 文件句柄已失效
+$ EREMOTE
+71 远程目录层数过多
+$ EBADRPC
+72 RPC 结构无效
+$ ERPCMISMATCH
+73 RPC 版本错误
+$ EPROGUNAVAIL
+74 RPC 程序不可用
+$ EPROGMISMATCH
+75 程序版本错误
+$ EPROCUNAVAIL
+76 未提供的远程函数
+$ ENOLCK
+77 不支持锁
+$ ENOSYS
+78 功能未实现
+$ EFTYPE
+79 文件类型或格式无效
+$ EAUTH
+80 身份无效
+$ ENEEDAUTH
+81 无信任凭据
+$ EIDRM
+82 无标识符
+$ ENOMSG
+83 无消息类型
+$ EOVERFLOW
+84 数值溢出
+$ ECANCELED
+85 操作已取消
+$ EILSEQ
+86 无效字符序列
+$ ENOATTR
+87 无扩展属性
+$ EDOOFUS
+88 程序设计错误
+$ EBADMSG
+89 无效消息
+$ EMULTIHOP
+90 Multihop attempted
+$ ENOLINK
+91 Link has been severed
+$ EPROTO
+92 协议错误
+$ ENOTCAPABLE
+93 权能不足
+$
+$ strsignal() support catalog
+$
+$set 2
+$ SIGHUP
+1 终端线路挂断
+$ SIGINT
+2 中断
+$ SIGQUIT
+3 退出
+$ SIGILL
+4 无效指令
+$ SIGTRAP
+5 跟踪/BPT 陷阱
+$ SIGABRT
+6 终止陷阱
+$ SIGEMT
+7 EMT 陷阱
+$ SIGFPE
+8 浮点异常
+$ SIGKILL
+9 强制终止进程
+$ SIGBUS
+10 系统内存访问越界
+$ SIGSEGV
+11 内存访问越界
+$ SIGSYS
+12 无效系统调用
+$ SIGPIPE
+13 写管道时读取者不存在
+$ SIGALRM
+14 实时倒计时到期
+$ SIGTERM
+15 终止
+$ SIGURG
+16 需立即处理的 I/O 紧急状况
+$ SIGSTOP
+17 挂起 (信号)
+$ SIGTSTP
+18 挂起
+$ SIGCONT
+19 继续运行
+$ SIGCHLD
+20 子进程终止
+$ SIGTTIN
+21 TTY 输入阻塞
+$ SIGTTOU
+22 TTY 输出阻塞
+$ SIGIO
+23 I/O 就绪
+$ SIGXCPU
+24 CPU 使用时间过长
+$ SIGXFSZ
+25 文件尺寸过大
+$ SIGVTALRM
+26 虚拟倒计时到期
+$ SIGPROF
+27 剖析倒计时到期
+$ SIGWINCH
+28 窗口尺寸变化
+$ SIGINFO
+29 请求信息
+$ SIGUSR1
+30 用户自定义信号 1
+$ SIGUSR2
+31 用户自定义信号 2
+$
+$ gai_strerror() support catalog
+$
+$set 3
+$ 1 (obsolete)
+1 主机名使用了不支持的地址类型
+$ EAI_AGAIN
+2 暂时无法解析名称
+$ EAI_BADFLAGS
+3 无效的 ai_flags 值
+$ EAI_FAIL
+4 解析名称时出现无法恢复的错误
+$ EAI_FAMILY
+5 不支持的地址信息类型
+$ EAI_MEMORY
+6 内存分配失败
+$ 7 (obsolete)
+7 主机名无相关联的地址
+$ EAI_NONAME
+8 未知的主机名或服务名
+$ EAI_SERVICE
+9 套接字类型不支持此服务名
+$ EAI_SOCKTYPE
+10 不支持的套接字类型
+$ EAI_SYSTEM
+11 系统调用返回了 errno 错误
+$ EAI_BADHINTS
+12 无效提示参数
+$ EAI_PROTOCOL
+13 未知协议
+$ EAI_OVERFLOW
+14 参数缓冲溢出
+$ 0
+32766 成功
+$ NL_MSGMAX
+32767 未知错误
diff --git a/lib/libc/nls/zh_CN.UTF-8.msg b/lib/libc/nls/zh_CN.UTF-8.msg
new file mode 100644
index 000000000000..9475ea8e82da
--- /dev/null
+++ b/lib/libc/nls/zh_CN.UTF-8.msg
@@ -0,0 +1,295 @@
+$ $FreeBSD$
+$
+$ Message catalog for zh_CN.UTF-8 locale
+$
+$ strerror() support catalog
+$
+$set 1
+$ EPERM
+1 涓嶅厑璁哥殑鎿嶄綔
+$ ENOENT
+2 鏂囦欢鎴栫洰褰曚笉瀛樺湪
+$ ESRCH
+3 杩涚▼涓嶅瓨鍦
+$ EINTR
+4 绯荤粺璋冪敤涓
+$ EIO
+5 杈撳叆/杈撳嚭閿欒
+$ ENXIO
+6 鏈厤缃殑璁惧
+$ E2BIG
+7 鍙傛暟琛ㄨ繃闀
+$ ENOEXEC
+8 鍙墽琛屾枃浠舵牸寮忛敊璇
+$ EBADF
+9 鏂囦欢鎻忚堪绗︽棤鏁
+$ ECHILD
+10 鎸囧畾瀛愯繘绋嬩笉瀛樺湪
+$ EDEADLK
+11 姝ゆ搷浣滀細瀵艰嚧姝婚攣
+$ ENOMEM
+12 鏃犳硶鍒嗛厤鍐呭瓨
+$ EACCES
+13 鎷掔粷璁块棶
+$ EFAULT
+14 鏃犳晥鍦板潃
+$ ENOTBLK
+15 璇ユ搷浣滈渶瑕佸潡璁惧
+$ EBUSY
+16 璁惧浣跨敤涓
+$ EEXIST
+17 鏂囦欢宸插瓨鍦
+$ EXDEV
+18 閾炬帴璺ㄨ澶
+$ ENODEV
+19 璁惧涓嶆敮鎸佹鎿嶄綔
+$ ENOTDIR
+20 瀵硅薄闈炵洰褰
+$ EISDIR
+21 瀵硅薄涓虹洰褰
+$ EINVAL
+22 鍙傛暟鏃犳晥
+$ ENFILE
+23 绯荤粺鎵撳紑鏂囦欢杩囧
+$ EMFILE
+24 杩涚▼鎵撳紑鏂囦欢杩囧
+$ ENOTTY
+25 鏃犳晥璁惧 ioctl
+$ ETXTBSY
+26 鍙墽琛屾枃浠跺繖
+$ EFBIG
+27 鏂囦欢杩囧ぇ
+$ ENOSPC
+28 璁惧鏃犲彲鐢ㄧ┖闂
+$ ESPIPE
+29 涓嶅厑璁告墽琛 seek 鎿嶄綔
+$ EROFS
+30 鏂囦欢绯荤粺鍙
+$ EMLINK
+31 鏂囦欢閾炬帴杩囧
+$ EPIPE
+32 绠¢亾宸蹭腑姝
+$ EDOM
+33 鏁板煎弬鏁拌秺鐣
+$ ERANGE
+34 缁撴灉杩囧ぇ
+$ EAGAIN, EWOULDBLOCK
+35 璧勬簮鏆傛椂涓嶅彲鐢
+$ EINPROGRESS
+36 鎿嶄綔杩涜涓
+$ EALREADY
+37 鎿嶄綔宸插紑濮
+$ ENOTSOCK
+38 灏濊瘯鍦ㄩ潪 socket 涓婃墽琛 socket 鎿嶄綔
+$ EDESTADDRREQ
+39 闇瑕佺洰鐨勫湴鍧
+$ EMSGSIZE
+40 娑堟伅杩囬暱
+$ EPROTOTYPE
+41 socket鍗忚绫诲瀷閿欒
+$ ENOPROTOOPT
+42 鍗忚涓嶅彲鐢
+$ EPROTONOSUPPORT
+43 涓嶆敮鎸佺殑鍗忚
+$ ESOCKTNOSUPPORT
+44 涓嶆敮鎸佺殑 socket 绫诲瀷
+$ EOPNOTSUPP
+45 涓嶆敮鎸佺殑鎿嶄綔
+$ EPFNOSUPPORT
+46 涓嶆敮鎸佺殑鍗忚鏃
+$ EAFNOSUPPORT
+47 鍗忚鏃忎笉鏀寔鐨勫湴鍧鏃
+$ EADDRINUSE
+48 鍦板潃宸茶鍗犵敤
+$ EADDRNOTAVAIL
+49 鏃犳硶鎸囧畾璇锋眰鐨勫湴鍧
+$ ENETDOWN
+50 缃戠粶宸插叧闂
+$ ENETUNREACH
+51 缃戠粶涓嶅彲杈
+$ ENETRESET
+52 澶嶄綅瀵艰嚧缃戠粶杩炴帴涓㈠け
+$ ECONNABORTED
+53 杞欢瀵艰嚧鐨勮繛鎺ヤ腑姝
+$ ECONNRESET
+54 瀵规柟澶嶄綅浜嗚繛鎺
+$ ENOBUFS
+55 缂撳啿鍖虹┖闂翠笉瓒
+$ EISCONN
+56 socket 宸茶繛鎺
+$ ENOTCONN
+57 socket 鏈繛鎺
+$ ESHUTDOWN
+58 socket shutdown 涔嬪悗鏃犳硶鍙戦佹暟鎹
+$ ETOOMANYREFS
+59 寮曠敤鏁拌繃澶氾細鏃犳硶鎷兼帴
+$ ETIMEDOUT
+60 鎿嶄綔瓒呮椂
+$ ECONNREFUSED
+61 鎷掔粷杩炴帴
+$ ELOOP
+62 绗﹀彿閾炬帴灞傛暟杩囧
+$ ENAMETOOLONG
+63 鏂囦欢鍚嶈繃闀
+$ EHOSTDOWN
+64 涓绘満宸插叧闂
+$ EHOSTUNREACH
+65 娌℃湁鍒颁富鏈虹殑璺敱
+$ ENOTEMPTY
+66 鐩綍闈炵┖
+$ EPROCLIM
+67 杩涚▼鏁拌秴闄
+$ EUSERS
+68 鐢ㄦ埛鏁拌秴闄
+$ EDQUOT
+69 纾佺洏绌洪棿閰嶉瓒呴檺
+$ ESTALE
+70 NFS 鏂囦欢鍙ユ焺宸插け鏁
+$ EREMOTE
+71 杩滅▼鐩綍灞傛暟杩囧
+$ EBADRPC
+72 RPC 缁撴瀯鏃犳晥
+$ ERPCMISMATCH
+73 RPC 鐗堟湰閿欒
+$ EPROGUNAVAIL
+74 RPC 绋嬪簭涓嶅彲鐢
+$ EPROGMISMATCH
+75 绋嬪簭鐗堟湰閿欒
+$ EPROCUNAVAIL
+76 鏈彁渚涚殑杩滅▼鍑芥暟
+$ ENOLCK
+77 涓嶆敮鎸侀攣
+$ ENOSYS
+78 鍔熻兘鏈疄鐜
+$ EFTYPE
+79 鏂囦欢绫诲瀷鎴栨牸寮忔棤鏁
+$ EAUTH
+80 韬唤鏃犳晥
+$ ENEEDAUTH
+81 鏃犱俊浠诲嚟鎹
+$ EIDRM
+82 鏃犳爣璇嗙
+$ ENOMSG
+83 鏃犳秷鎭被鍨
+$ EOVERFLOW
+84 鏁板兼孩鍑
+$ ECANCELED
+85 鎿嶄綔宸插彇娑
+$ EILSEQ
+86 鏃犳晥瀛楃搴忓垪
+$ ENOATTR
+87 鏃犳墿灞曞睘鎬
+$ EDOOFUS
+88 绋嬪簭璁捐閿欒
+$ EBADMSG
+89 鏃犳晥娑堟伅
+$ EMULTIHOP
+90 Multihop attempted
+$ ENOLINK
+91 Link has been severed
+$ EPROTO
+92 鍗忚閿欒
+$ ENOTCAPABLE
+93 鏉冭兘涓嶈冻
+$
+$ strsignal() support catalog
+$
+$set 2
+$ SIGHUP
+1 缁堢绾胯矾鎸傛柇
+$ SIGINT
+2 涓柇
+$ SIGQUIT
+3 閫鍑
+$ SIGILL
+4 鏃犳晥鎸囦护
+$ SIGTRAP
+5 璺熻釜/BPT 闄烽槺
+$ SIGABRT
+6 缁堟闄烽槺
+$ SIGEMT
+7 EMT 闄烽槺
+$ SIGFPE
+8 娴偣寮傚父
+$ SIGKILL
+9 寮哄埗缁堟杩涚▼
+$ SIGBUS
+10 绯荤粺鍐呭瓨璁块棶瓒婄晫
+$ SIGSEGV
+11 鍐呭瓨璁块棶瓒婄晫
+$ SIGSYS
+12 鏃犳晥绯荤粺璋冪敤
+$ SIGPIPE
+13 鍐欑閬撴椂璇诲彇鑰呬笉瀛樺湪
+$ SIGALRM
+14 瀹炴椂鍊掕鏃跺埌鏈
+$ SIGTERM
+15 缁堟
+$ SIGURG
+16 闇绔嬪嵆澶勭悊鐨 I/O 绱фョ姸鍐
+$ SIGSTOP
+17 鎸傝捣 (淇″彿)
+$ SIGTSTP
+18 鎸傝捣
+$ SIGCONT
+19 缁х画杩愯
+$ SIGCHLD
+20 瀛愯繘绋嬬粓姝
+$ SIGTTIN
+21 TTY 杈撳叆闃诲
+$ SIGTTOU
+22 TTY 杈撳嚭闃诲
+$ SIGIO
+23 I/O 灏辩华
+$ SIGXCPU
+24 CPU 浣跨敤鏃堕棿杩囬暱
+$ SIGXFSZ
+25 鏂囦欢灏哄杩囧ぇ
+$ SIGVTALRM
+26 铏氭嫙鍊掕鏃跺埌鏈
+$ SIGPROF
+27 鍓栨瀽鍊掕鏃跺埌鏈
+$ SIGWINCH
+28 绐楀彛灏哄鍙樺寲
+$ SIGINFO
+29 璇锋眰淇℃伅
+$ SIGUSR1
+30 鐢ㄦ埛鑷畾涔変俊鍙 1
+$ SIGUSR2
+31 鐢ㄦ埛鑷畾涔変俊鍙 2
+$
+$ gai_strerror() support catalog
+$
+$set 3
+$ 1 (obsolete)
+1 涓绘満鍚嶄娇鐢ㄤ簡涓嶆敮鎸佺殑鍦板潃绫诲瀷
+$ EAI_AGAIN
+2 鏆傛椂鏃犳硶瑙f瀽鍚嶇О
+$ EAI_BADFLAGS
+3 鏃犳晥鐨 ai_flags 鍊
+$ EAI_FAIL
+4 瑙f瀽鍚嶇О鏃跺嚭鐜版棤娉曟仮澶嶇殑閿欒
+$ EAI_FAMILY
+5 涓嶆敮鎸佺殑鍦板潃淇℃伅绫诲瀷
+$ EAI_MEMORY
+6 鍐呭瓨鍒嗛厤澶辫触
+$ 7 (obsolete)
+7 涓绘満鍚嶆棤鐩稿叧鑱旂殑鍦板潃
+$ EAI_NONAME
+8 鏈煡鐨勪富鏈哄悕鎴栨湇鍔″悕
+$ EAI_SERVICE
+9 濂楁帴瀛楃被鍨嬩笉鏀寔姝ゆ湇鍔″悕
+$ EAI_SOCKTYPE
+10 涓嶆敮鎸佺殑濂楁帴瀛楃被鍨
+$ EAI_SYSTEM
+11 绯荤粺璋冪敤杩斿洖浜 errno 閿欒
+$ EAI_BADHINTS
+12 鏃犳晥鎻愮ず鍙傛暟
+$ EAI_PROTOCOL
+13 鏈煡鍗忚
+$ EAI_OVERFLOW
+14 鍙傛暟缂撳啿婧㈠嚭
+$ 0
+32766 鎴愬姛
+$ NL_MSGMAX
+32767 鏈煡閿欒
diff --git a/lib/libc/powerpc/Makefile.inc b/lib/libc/powerpc/Makefile.inc
index 453726a670be..104f80cb2e77 100644
--- a/lib/libc/powerpc/Makefile.inc
+++ b/lib/libc/powerpc/Makefile.inc
@@ -1,5 +1,7 @@
# $FreeBSD$
+SRCS+= __vdso_gettc.c
+
# Long double is 64-bits
MDSRCS+=machdep_ldisd.c
SYM_MAPS+=${.CURDIR}/powerpc/Symbol.map
diff --git a/lib/libc/powerpc/sys/__vdso_gettc.c b/lib/libc/powerpc/sys/__vdso_gettc.c
new file mode 100644
index 000000000000..b99bbc4f3d0f
--- /dev/null
+++ b/lib/libc/powerpc/sys/__vdso_gettc.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <errno.h>
+
+#pragma weak __vdso_gettc
+u_int
+__vdso_gettc(const struct vdso_timehands *th)
+{
+
+ return (0);
+}
+
+#pragma weak __vdso_gettimekeep
+int
+__vdso_gettimekeep(struct vdso_timekeep **tk)
+{
+
+ return (ENOSYS);
+}
diff --git a/lib/libc/powerpc64/Makefile.inc b/lib/libc/powerpc64/Makefile.inc
index e4ccbb9f9509..a30779d994b4 100644
--- a/lib/libc/powerpc64/Makefile.inc
+++ b/lib/libc/powerpc64/Makefile.inc
@@ -1,5 +1,7 @@
# $FreeBSD$
+SRCS+= __vdso_gettc.c
+
# Long double is 64-bits
MDSRCS+=machdep_ldisd.c
SYM_MAPS+=${.CURDIR}/powerpc64/Symbol.map
diff --git a/lib/libc/powerpc64/sys/__vdso_gettc.c b/lib/libc/powerpc64/sys/__vdso_gettc.c
new file mode 100644
index 000000000000..b99bbc4f3d0f
--- /dev/null
+++ b/lib/libc/powerpc64/sys/__vdso_gettc.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <errno.h>
+
+#pragma weak __vdso_gettc
+u_int
+__vdso_gettc(const struct vdso_timehands *th)
+{
+
+ return (0);
+}
+
+#pragma weak __vdso_gettimekeep
+int
+__vdso_gettimekeep(struct vdso_timekeep **tk)
+{
+
+ return (ENOSYS);
+}
diff --git a/lib/libc/quad/Makefile.inc b/lib/libc/quad/Makefile.inc
index 016fa34dda4e..9cef22e3e57d 100644
--- a/lib/libc/quad/Makefile.inc
+++ b/lib/libc/quad/Makefile.inc
@@ -8,6 +8,10 @@
SRCS+= cmpdi2.c divdi3.c moddi3.c qdivrem.c ucmpdi2.c udivdi3.c umoddi3.c
+.elif ${LIBC_ARCH} == "arm" && ${MK_ARM_EABI} != "no"
+
+SRCS+= adddi3.c anddi3.c floatunsdidf.c iordi3.c lshldi3.c notdi2.c \
+ qdivrem.c subdi3.c xordi3.c
.else
SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c fixdfdi.c \
diff --git a/lib/libc/sparc64/Makefile.inc b/lib/libc/sparc64/Makefile.inc
index 76cc8b930400..84a0e06391d3 100644
--- a/lib/libc/sparc64/Makefile.inc
+++ b/lib/libc/sparc64/Makefile.inc
@@ -5,6 +5,8 @@
.include "fpu/Makefile.inc"
+SRCS+= __vdso_gettc.c
+
# Long double is quad precision
GDTOASRCS+=strtorQ.c
MDSRCS+=machdep_ldisQ.c
diff --git a/lib/libc/sparc64/sys/__vdso_gettc.c b/lib/libc/sparc64/sys/__vdso_gettc.c
new file mode 100644
index 000000000000..b99bbc4f3d0f
--- /dev/null
+++ b/lib/libc/sparc64/sys/__vdso_gettc.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2013 Konstantin Belousov <kib@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/vdso.h>
+#include <errno.h>
+
+#pragma weak __vdso_gettc
+u_int
+__vdso_gettc(const struct vdso_timehands *th)
+{
+
+ return (0);
+}
+
+#pragma weak __vdso_gettimekeep
+int
+__vdso_gettimekeep(struct vdso_timekeep **tk)
+{
+
+ return (ENOSYS);
+}
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc
index 657005197fbb..bc3b9e54801d 100644
--- a/lib/libc/stdio/Makefile.inc
+++ b/lib/libc/stdio/Makefile.inc
@@ -8,7 +8,8 @@ SRCS+= _flock_stub.c asprintf.c clrerr.c dprintf.c \
fclose.c fcloseall.c fdopen.c \
feof.c ferror.c fflush.c fgetc.c fgetln.c fgetpos.c fgets.c fgetwc.c \
fgetwln.c fgetws.c \
- fileno.c findfp.c flags.c fopen.c fprintf.c fpurge.c fputc.c fputs.c \
+ fileno.c findfp.c flags.c fmemopen.c fopen.c fprintf.c fpurge.c \
+ fputc.c fputs.c \
fputwc.c fputws.c fread.c freopen.c fscanf.c fseek.c fsetpos.c \
ftell.c funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwscanf.c \
fwrite.c getc.c getchar.c getdelim.c getline.c \
@@ -48,7 +49,7 @@ MLINKS+=ferror.3 ferror_unlocked.3 \
MLINKS+=fflush.3 fpurge.3
MLINKS+=fgets.3 gets.3
MLINKS+=flockfile.3 ftrylockfile.3 flockfile.3 funlockfile.3
-MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3
+MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3 fopen.3 fmemopen.3
MLINKS+=fputs.3 puts.3
MLINKS+=fread.3 fwrite.3
MLINKS+=fseek.3 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \
diff --git a/lib/libc/stdio/Symbol.map b/lib/libc/stdio/Symbol.map
index cafb0c64df7c..b78de5a4d812 100644
--- a/lib/libc/stdio/Symbol.map
+++ b/lib/libc/stdio/Symbol.map
@@ -155,6 +155,7 @@ FBSD_1.3 {
getwchar_l;
putwc_l;
putwchar_l;
+ fmemopen;
};
FBSDprivate_1.0 {
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c
index 26e2cd70bc1e..8fc90a438b99 100644
--- a/lib/libc/stdio/fdopen.c
+++ b/lib/libc/stdio/fdopen.c
@@ -80,6 +80,12 @@ fdopen(fd, mode)
if ((fp = __sfp()) == NULL)
return (NULL);
+
+ if ((oflags & O_CLOEXEC) && _fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
+ fp->_flags = 0;
+ return (NULL);
+ }
+
fp->_flags = flags;
/*
* If opened for appending, but underlying descriptor does not have
diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c
index 0b6b0755bd3b..e445fedd0794 100644
--- a/lib/libc/stdio/flags.c
+++ b/lib/libc/stdio/flags.c
@@ -97,6 +97,7 @@ __sflags(mode, optr)
/* 'x' means exclusive (fail if the file exists) */
if (*mode == 'x') {
+ mode++;
if (m == O_RDONLY) {
errno = EINVAL;
return (0);
@@ -104,6 +105,10 @@ __sflags(mode, optr)
o |= O_EXCL;
}
+ /* set close-on-exec */
+ if (*mode == 'e')
+ o |= O_CLOEXEC;
+
*optr = m | o;
return (ret);
}
diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c
new file mode 100644
index 000000000000..581a91efd73b
--- /dev/null
+++ b/lib/libc/stdio/fmemopen.c
@@ -0,0 +1,258 @@
+/*-
+ * Copyright (C) 2013 Pietro Cerutti <gahr@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "local.h"
+
+struct fmemopen_cookie
+{
+ char *buf; /* pointer to the memory region */
+ bool own; /* did we allocate the buffer ourselves? */
+ char bin; /* is this a binary buffer? */
+ size_t size; /* buffer length in bytes */
+ size_t len; /* data length in bytes */
+ size_t off; /* current offset into the buffer */
+};
+
+static int fmemopen_read(void *cookie, char *buf, int nbytes);
+static int fmemopen_write(void *cookie, const char *buf, int nbytes);
+static fpos_t fmemopen_seek(void *cookie, fpos_t offset, int whence);
+static int fmemopen_close(void *cookie);
+
+FILE *
+fmemopen(void * __restrict buf, size_t size, const char * __restrict mode)
+{
+ struct fmemopen_cookie *ck;
+ FILE *f;
+ int flags, rc;
+
+ /*
+ * Retrieve the flags as used by open(2) from the mode argument, and
+ * validate them.
+ */
+ rc = __sflags(mode, &flags);
+ if (rc == 0) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /*
+ * There's no point in requiring an automatically allocated buffer
+ * in write-only mode.
+ */
+ if (!(flags & O_RDWR) && buf == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ ck = malloc(sizeof(struct fmemopen_cookie));
+ if (ck == NULL) {
+ return (NULL);
+ }
+
+ ck->off = 0;
+ ck->size = size;
+
+ /* Check whether we have to allocate the buffer ourselves. */
+ ck->own = ((ck->buf = buf) == NULL);
+ if (ck->own) {
+ ck->buf = malloc(size);
+ if (ck->buf == NULL) {
+ free(ck);
+ return (NULL);
+ }
+ }
+
+ /*
+ * POSIX distinguishes between w+ and r+, in that w+ is supposed to
+ * truncate the buffer.
+ */
+ if (ck->own || mode[0] == 'w') {
+ ck->buf[0] = '\0';
+ }
+
+ /* Check for binary mode. */
+ ck->bin = strchr(mode, 'b') != NULL;
+
+ /*
+ * The size of the current buffer contents is set depending on the
+ * mode:
+ *
+ * for append (text-mode), the position of the first NULL byte, or the
+ * size of the buffer if none is found
+ *
+ * for append (binary-mode), the size of the buffer
+ *
+ * for read, the size of the buffer
+ *
+ * for write, 0
+ */
+ switch (mode[0]) {
+ case 'a':
+ if (ck->bin) {
+ /*
+ * This isn't useful, since the buffer isn't allowed
+ * to grow.
+ */
+ ck->off = ck->len = size;
+ } else
+ ck->off = ck->len = strnlen(ck->buf, ck->size);
+ break;
+ case 'r':
+ ck->len = size;
+ break;
+ case 'w':
+ ck->len = 0;
+ break;
+ }
+
+ f = funopen(ck,
+ flags & O_WRONLY ? NULL : fmemopen_read,
+ flags & O_RDONLY ? NULL : fmemopen_write,
+ fmemopen_seek, fmemopen_close);
+
+ if (f == NULL) {
+ if (ck->own)
+ free(ck->buf);
+ free(ck);
+ return (NULL);
+ }
+
+ /*
+ * Turn off buffering, so a write past the end of the buffer
+ * correctly returns a short object count.
+ */
+ setvbuf(f, NULL, _IONBF, 0);
+
+ return (f);
+}
+
+static int
+fmemopen_read(void *cookie, char *buf, int nbytes)
+{
+ struct fmemopen_cookie *ck = cookie;
+
+ if (nbytes > ck->len - ck->off)
+ nbytes = ck->len - ck->off;
+
+ if (nbytes == 0)
+ return (0);
+
+ memcpy(buf, ck->buf + ck->off, nbytes);
+
+ ck->off += nbytes;
+
+ return (nbytes);
+}
+
+static int
+fmemopen_write(void *cookie, const char *buf, int nbytes)
+{
+ struct fmemopen_cookie *ck = cookie;
+
+ if (nbytes > ck->size - ck->off)
+ nbytes = ck->size - ck->off;
+
+ if (nbytes == 0)
+ return (0);
+
+ memcpy(ck->buf + ck->off, buf, nbytes);
+
+ ck->off += nbytes;
+
+ if (ck->off > ck->len)
+ ck->len = ck->off;
+
+ /*
+ * We append a NULL byte if all these conditions are met:
+ * - the buffer is not binary
+ * - the buffer is not full
+ * - the data just written doesn't already end with a NULL byte
+ */
+ if (!ck->bin && ck->off < ck->size && ck->buf[ck->off - 1] != '\0')
+ ck->buf[ck->off] = '\0';
+
+ return (nbytes);
+}
+
+static fpos_t
+fmemopen_seek(void *cookie, fpos_t offset, int whence)
+{
+ struct fmemopen_cookie *ck = cookie;
+
+
+ switch (whence) {
+ case SEEK_SET:
+ if (offset > ck->size) {
+ errno = EINVAL;
+ return (-1);
+ }
+ ck->off = offset;
+ break;
+
+ case SEEK_CUR:
+ if (ck->off + offset > ck->size) {
+ errno = EINVAL;
+ return (-1);
+ }
+ ck->off += offset;
+ break;
+
+ case SEEK_END:
+ if (offset > 0 || -offset > ck->len) {
+ errno = EINVAL;
+ return (-1);
+ }
+ ck->off = ck->len + offset;
+ break;
+
+ default:
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return (ck->off);
+}
+
+static int
+fmemopen_close(void *cookie)
+{
+ struct fmemopen_cookie *ck = cookie;
+
+ if (ck->own)
+ free(ck->buf);
+
+ free(ck);
+
+ return (0);
+}
diff --git a/lib/libc/stdio/fopen.3 b/lib/libc/stdio/fopen.3
index 08438e7da54c..a07be3873278 100644
--- a/lib/libc/stdio/fopen.3
+++ b/lib/libc/stdio/fopen.3
@@ -32,13 +32,14 @@
.\" @(#)fopen.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd October 17, 2011
+.Dd January 30, 2013
.Dt FOPEN 3
.Os
.Sh NAME
.Nm fopen ,
.Nm fdopen ,
-.Nm freopen
+.Nm freopen ,
+.Nm fmemopen
.Nd stream open functions
.Sh LIBRARY
.Lb libc
@@ -50,6 +51,8 @@
.Fn fdopen "int fildes" "const char *mode"
.Ft FILE *
.Fn freopen "const char *path" "const char *mode" "FILE *stream"
+.Ft FILE *
+.Fn fmemopen "void *restrict *buf" "size_t size" "const char * restrict mode"
.Sh DESCRIPTION
The
.Fn fopen
@@ -97,6 +100,14 @@ or
causes the
.Fn fopen
call to fail if the file already exists.
+An optional
+.Dq Li e
+following the above
+causes the
+.Fn fopen
+call to set the
+.Dv FD_CLOEXEC
+flag on the underlying file descriptor.
.Pp
The
.Fa mode
@@ -107,7 +118,9 @@ after either the
or the first letter.
This is strictly for compatibility with
.St -isoC
-and has no effect; the ``b'' is ignored.
+and has effect only for
+.Fn fmemopen
+; otherwise the ``b'' is ignored.
.Pp
Any created files will have mode
.Do Dv S_IRUSR
@@ -144,6 +157,11 @@ of the stream must be compatible with the mode of the file descriptor.
The
.Dq Li x
mode option is ignored.
+If the
+.Dq Li e
+mode option is present, the
+.Dv FD_CLOEXEC
+flag is set, otherwise it remains unchanged.
When the stream is closed via
.Xr fclose 3 ,
.Fa fildes
@@ -189,6 +207,34 @@ standard text stream
.Dv ( stderr , stdin ,
or
.Dv stdout ) .
+.Pp
+The
+.Fn fmemopen
+function
+associates the buffer given by the
+.Fa buf
+and
+.Fa size
+arguments with a stream.
+The
+.Fa buf
+argument is either a null pointer or point to a buffer that
+is at least
+.Fa size
+bytes long.
+If a null pointer is specified as the
+.Fa buf
+argument,
+.Fn fmemopen
+allocates
+.Fa size
+bytes of memory. This buffer is automatically freed when the
+stream is closed. Buffers can be opened in text-mode (default) or binary-mode
+(if ``b'' is present in the second or third position of the
+.Fa mode
+argument). Buffers opened in text-mode make sure that writes are terminated with
+a NULL byte, if the last write hasn't filled up the whole buffer. Buffers
+opened in binary-mode never append a NULL byte.
.Sh RETURN VALUES
Upon successful completion
.Fn fopen ,
@@ -212,16 +258,18 @@ argument
to
.Fn fopen ,
.Fn fdopen ,
+.Fn freopen ,
or
-.Fn freopen
+.Fn fmemopen
was invalid.
.El
.Pp
The
.Fn fopen ,
-.Fn fdopen
-and
+.Fn fdopen ,
.Fn freopen
+and
+.Fn fmemopen
functions
may also fail and set
.Va errno
@@ -277,3 +325,14 @@ The
function
conforms to
.St -p1003.1-88 .
+The
+.Dq Li e
+mode option does not conform to any standard
+but is also supported by glibc.
+The
+.Fn fmemopen
+function
+conforms to
+.St -p1003.1-2008 .
+The ``b'' mode does not conform to any standard
+but is also supported by glibc.
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c
index be7bc8a2f8d0..8d1ec917086a 100644
--- a/lib/libc/stdio/freopen.c
+++ b/lib/libc/stdio/freopen.c
@@ -118,6 +118,8 @@ freopen(file, mode, fp)
(void) ftruncate(fp->_file, (off_t)0);
if (!(oflags & O_APPEND))
(void) _sseek(fp, (fpos_t)0, SEEK_SET);
+ if (oflags & O_CLOEXEC)
+ (void) _fcntl(fp->_file, F_SETFD, FD_CLOEXEC);
f = fp->_file;
isopen = 0;
wantfd = -1;
@@ -194,7 +196,8 @@ finish:
* assume stderr is always fd STDERR_FILENO, even if being freopen'd.
*/
if (wantfd >= 0) {
- if (_dup2(f, wantfd) >= 0) {
+ if ((oflags & O_CLOEXEC ? _fcntl(f, F_DUP2FD_CLOEXEC, wantfd) :
+ _dup2(f, wantfd)) >= 0) {
(void)_close(f);
f = wantfd;
} else
diff --git a/lib/libc/stdio/getline.3 b/lib/libc/stdio/getline.3
index 6061bfcd1da6..21619995d390 100644
--- a/lib/libc/stdio/getline.3
+++ b/lib/libc/stdio/getline.3
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd November 30, 2010
+.Dd November 30, 2012
.Dt GETLINE 3
.Os
.Sh NAME
@@ -76,7 +76,7 @@ The
.Fn getdelim
and
.Fn getline
-functions return the number of characters written, excluding the
+functions return the number of characters stored in the buffer, excluding the
terminating
.Dv NUL
character.
diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3
index 0d9339ea55cc..05c30dcfb523 100644
--- a/lib/libc/stdio/printf.3
+++ b/lib/libc/stdio/printf.3
@@ -267,7 +267,7 @@ number produced by a signed conversion.
A
.Cm +
overrides a space if both are used.
-.It Sq Cm '
+.It So "'" Sc (apostrophe)
Decimal conversions
.Cm ( d , u ,
or
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index df4ef4279404..a35ed5df57bb 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -217,5 +217,6 @@ MLINKS+=timer_settime.2 timer_getoverrun.2 timer_settime.2 timer_gettime.2
MLINKS+=truncate.2 ftruncate.2
MLINKS+=unlink.2 unlinkat.2
MLINKS+=utimes.2 futimes.2 utimes.2 futimesat.2 utimes.2 lutimes.2
-MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2
+MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2 \
+ wait.2 waitid.2 wait.2 wait6.2
MLINKS+=write.2 pwrite.2 write.2 pwritev.2 write.2 writev.2
diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map
index 008b8da33cbf..babae3082d50 100644
--- a/lib/libc/sys/Symbol.map
+++ b/lib/libc/sys/Symbol.map
@@ -384,6 +384,7 @@ FBSD_1.3 {
ffclock_getestimate;
ffclock_setestimate;
posix_fadvise;
+ wait6;
};
FBSDprivate_1.0 {
@@ -1019,6 +1020,8 @@ FBSDprivate_1.0 {
__sys_vadvise;
_wait4;
__sys_wait4;
+ _wait6;
+ __sys_wait6;
_write;
__sys_write;
_writev;
diff --git a/lib/libc/sys/__vdso_gettimeofday.c b/lib/libc/sys/__vdso_gettimeofday.c
index 32abb6970d82..a305173b3ed8 100644
--- a/lib/libc/sys/__vdso_gettimeofday.c
+++ b/lib/libc/sys/__vdso_gettimeofday.c
@@ -79,6 +79,7 @@ binuptime(struct bintime *bt, struct vdso_timekeep *tk, int abs)
static struct vdso_timekeep *tk;
+#pragma weak __vdso_gettimeofday
int
__vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
{
@@ -88,7 +89,7 @@ __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
if (tz != NULL)
return (ENOSYS);
if (tk == NULL) {
- error = _elf_aux_info(AT_TIMEKEEP, &tk, sizeof(tk));
+ error = __vdso_gettimekeep(&tk);
if (error != 0 || tk == NULL)
return (ENOSYS);
}
@@ -101,6 +102,7 @@ __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
return (0);
}
+#pragma weak __vdso_clock_gettime
int
__vdso_clock_gettime(clockid_t clock_id, struct timespec *ts)
{
diff --git a/lib/libc/sys/bind.2 b/lib/libc/sys/bind.2
index fecc5fa5a636..896b0053cad2 100644
--- a/lib/libc/sys/bind.2
+++ b/lib/libc/sys/bind.2
@@ -94,6 +94,8 @@ is not a socket.
The specified address is not available from the local machine.
.It Bq Er EADDRINUSE
The specified address is already in use.
+.It Bq Er EAFNOSUPPORT
+Addresses in the specified address family cannot be used with this socket.
.It Bq Er EACCES
The requested address is protected, and the current user
has inadequate permission to access it.
diff --git a/lib/libc/sys/chroot.2 b/lib/libc/sys/chroot.2
index 060d0648e53e..36d0364bd7f4 100644
--- a/lib/libc/sys/chroot.2
+++ b/lib/libc/sys/chroot.2
@@ -92,12 +92,8 @@ system call.
Any other value for
.Ql kern.chroot_allow_open_directories
will bypass the check for open directories
-.Pp
-Upon successful completion, a value of 0 is returned.
-Otherwise,
-a value of -1 is returned and
-.Va errno
-is set to indicate an error.
+.Sh RETURN VALUES
+.Rv -std
.Sh ERRORS
The
.Fn chroot
diff --git a/lib/libc/sys/getpeername.2 b/lib/libc/sys/getpeername.2
index 903711926e99..255c7a01bb88 100644
--- a/lib/libc/sys/getpeername.2
+++ b/lib/libc/sys/getpeername.2
@@ -67,6 +67,10 @@ The argument
is not a valid descriptor.
.It Bq Er ECONNRESET
The connection has been reset by the peer.
+.It Bq Er EINVAL
+The value of the
+.Fa namelen
+argument is not valid.
.It Bq Er ENOTSOCK
The argument
.Fa s
diff --git a/lib/libc/sys/getsockname.2 b/lib/libc/sys/getsockname.2
index f1537c7d0898..1de025768358 100644
--- a/lib/libc/sys/getsockname.2
+++ b/lib/libc/sys/getsockname.2
@@ -66,6 +66,10 @@ The argument
is not a valid descriptor.
.It Bq Er ECONNRESET
The connection has been reset by the peer.
+.It Bq Er EINVAL
+The value of the
+.Fa namelen
+argument is not valid.
.It Bq Er ENOTSOCK
The argument
.Fa s
diff --git a/lib/libc/sys/gettimeofday.c b/lib/libc/sys/gettimeofday.c
index 4cc87e1b5281..5b1252314c39 100644
--- a/lib/libc/sys/gettimeofday.c
+++ b/lib/libc/sys/gettimeofday.c
@@ -41,10 +41,7 @@ __gettimeofday(struct timeval *tv, struct timezone *tz)
{
int error;
- if (__vdso_gettimeofday != NULL && __vdso_gettc != NULL)
- error = __vdso_gettimeofday(tv, tz);
- else
- error = ENOSYS;
+ error = __vdso_gettimeofday(tv, tz);
if (error == ENOSYS)
error = __sys_gettimeofday(tv, tz);
return (error);
diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2
index 63a662fd678e..6ae79143d621 100644
--- a/lib/libc/sys/kqueue.2
+++ b/lib/libc/sys/kqueue.2
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 15, 2012
+.Dd January 21, 2013
.Dt KQUEUE 2
.Os
.Sh NAME
@@ -417,7 +417,9 @@ and
facilities, and has a lower precedence.
The filter will record
all attempts to deliver a signal to a process, even if the signal has
-been marked as SIG_IGN.
+been marked as SIG_IGN, except for the
+.Dv SIGCHLD
+signal, which, if ignored, won't be recorded by the filter.
Event notification happens after normal
signal delivery processing.
.Va data
diff --git a/lib/libc/sys/mlock.2 b/lib/libc/sys/mlock.2
index ed9c15a7f0e5..0e5fef85314c 100644
--- a/lib/libc/sys/mlock.2
+++ b/lib/libc/sys/mlock.2
@@ -28,7 +28,7 @@
.\" @(#)mlock.2 8.2 (Berkeley) 12/11/93
.\" $FreeBSD$
.\"
-.Dd July 27, 2010
+.Dd December 25, 2012
.Dt MLOCK 2
.Os
.Sh NAME
@@ -94,12 +94,15 @@ limited in how much they can lock down.
A single process can
.Fn mlock
the minimum of
-a system-wide ``wired pages'' limit and
-the per-process
+a system-wide ``wired pages'' limit
+.Va vm.max_wired
+and the per-process
.Li RLIMIT_MEMLOCK
resource limit.
.Pp
-These calls are only available to the super-user.
+If
+.Va security.bsd.unprivileged_mlock
+is set to 0 these calls are only available to the super-user.
.Sh RETURN VALUES
.Rv -std
.Pp
@@ -112,7 +115,8 @@ system call
will fail if:
.Bl -tag -width Er
.It Bq Er EPERM
-The caller is not the super-user.
+.Va security.bsd.unprivileged_mlock
+is set to 0 and the caller is not the super-user.
.It Bq Er EINVAL
The address given is not page aligned or the length is negative.
.It Bq Er EAGAIN
@@ -129,7 +133,8 @@ system call
will fail if:
.Bl -tag -width Er
.It Bq Er EPERM
-The caller is not the super-user.
+.Va security.bsd.unprivileged_mlock
+is set to 0 and the caller is not the super-user.
.It Bq Er EINVAL
The address given is not page aligned or the length is negative.
.It Bq Er ENOMEM
diff --git a/lib/libc/sys/mlockall.2 b/lib/libc/sys/mlockall.2
index 54ae23e4360c..23c644a8493f 100644
--- a/lib/libc/sys/mlockall.2
+++ b/lib/libc/sys/mlockall.2
@@ -30,7 +30,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 27, 2010
+.Dd December 25, 2012
.Dt MLOCKALL 2
.Os
.Sh NAME
@@ -68,11 +68,22 @@ Since physical memory is a potentially scarce resource, processes are
limited in how much they can lock down.
A single process can lock the minimum of a system-wide
.Dq wired pages
-limit and the per-process
+limit
+.Va vm.max_wired
+and the per-process
.Dv RLIMIT_MEMLOCK
resource limit.
.Pp
-These calls are only available to the super-user.
+If
+.Va security.bsd.unprivileged_mlock
+is set to 0 these calls are only available to the super-user.
+If
+.Va vm.old_mlock
+is set to 1 the per-process
+.Dv RLIMIT_MEMLOCK
+resource limit will not be applied for
+.Fn mlockall
+calls.
.Pp
The
.Fn munlockall
diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2
index 041f9dc983b8..41a6c6460f99 100644
--- a/lib/libc/sys/open.2
+++ b/lib/libc/sys/open.2
@@ -28,7 +28,7 @@
.\" @(#)open.2 8.2 (Berkeley) 11/16/93
.\" $FreeBSD$
.\"
-.Dd March 25, 2011
+.Dd February 7, 2013
.Dt OPEN 2
.Os
.Sh NAME
@@ -244,6 +244,17 @@ It returns \-1 on failure.
The file pointer used to mark the current position within the
file is set to the beginning of the file.
.Pp
+If a sleeping open of a device node from
+.Xr devfs 5
+is interrupted by a signal, the call always fails with
+.Er EINTR ,
+even if the
+.Dv SA_RESTART
+flag is set for the signal.
+A sleeping open of a fifo (see
+.Xr mkfifo 2 )
+is restarted as normal.
+.Pp
When a new file is created it is given the group of the directory
which contains it.
.Pp
diff --git a/lib/libc/sys/posix_fadvise.2 b/lib/libc/sys/posix_fadvise.2
index f303f422b542..7a9a64828e82 100644
--- a/lib/libc/sys/posix_fadvise.2
+++ b/lib/libc/sys/posix_fadvise.2
@@ -134,4 +134,4 @@ interface conforms to
The
.Fn posix_fadvise
system call first appeared in
-.Fx 10.0 .
+.Fx 9.1 .
diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2
index 9dda8ee1b41c..90c45442561e 100644
--- a/lib/libc/sys/ptrace.2
+++ b/lib/libc/sys/ptrace.2
@@ -2,7 +2,7 @@
.\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $
.\"
.\" This file is in the public domain.
-.Dd February 19, 2012
+.Dd February 7, 2013
.Dt PTRACE 2
.Os
.Sh NAME
@@ -100,6 +100,16 @@ or any of the routines built on it
it will stop before executing the first instruction of the new image.
Also, any setuid or setgid bits on the executable being executed will
be ignored.
+If the child was created by
+.Xr vfork 2
+system call or
+.Xr rfork(2)
+call with the
+.Dv RFMEM
+flag specified, the debugging events are reported to the parent
+only after the
+.Xr execve 2
+is executed.
.It Dv PT_READ_I , Dv PT_READ_D
These requests read a single
.Vt int
diff --git a/lib/libc/sys/rtprio.2 b/lib/libc/sys/rtprio.2
index ac78b5099514..f30ed225475b 100644
--- a/lib/libc/sys/rtprio.2
+++ b/lib/libc/sys/rtprio.2
@@ -145,13 +145,21 @@ Higher real/idle priority threads
preempt lower real/idle priority threads.
Threads of equal real/idle priority are run round-robin.
.Sh RETURN VALUES
-.Rv -std rtprio
+.Rv -std rtprio rtprio_thread
.Sh ERRORS
The
.Fn rtprio
-system call
+and
+.Fn rtprio_thread
+system calls
will fail if:
.Bl -tag -width Er
+.It Bq Er EFAULT
+The rtp pointer passed to
+.Fn rtprio
+or
+.Fn rtprio_thread
+was invalid.
.It Bq Er EINVAL
The specified
.Fa prio
diff --git a/lib/libc/sys/sendfile.2 b/lib/libc/sys/sendfile.2
index 9d1fba55409d..0e7dbe36263b 100644
--- a/lib/libc/sys/sendfile.2
+++ b/lib/libc/sys/sendfile.2
@@ -265,6 +265,8 @@ is negative.
.It Bq Er EIO
An error occurred while reading from
.Fa fd .
+.It Bq Er ENOBUFS
+The system was unable to allocate an internal buffer.
.It Bq Er ENOTCONN
The
.Fa s
diff --git a/lib/libc/sys/socket.2 b/lib/libc/sys/socket.2
index dae33d0675a0..24e42936655e 100644
--- a/lib/libc/sys/socket.2
+++ b/lib/libc/sys/socket.2
@@ -28,7 +28,7 @@
.\" From: @(#)socket.2 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd January 5, 2009
+.Dd December 7, 2012
.Dt SOCKET 2
.Os
.Sh NAME
@@ -248,21 +248,26 @@ The
.Fn socket
system call fails if:
.Bl -tag -width Er
-.It Bq Er EPROTONOSUPPORT
-The protocol type or the specified protocol is not supported
-within this domain.
+.It Bq Er EACCES
+Permission to create a socket of the specified type and/or protocol
+is denied.
+.It Bq Er EAFNOSUPPORT
+The address family (domain) is not supported or the
+specified domain is not supported by this protocol family.
.It Bq Er EMFILE
The per-process descriptor table is full.
.It Bq Er ENFILE
The system file table is full.
-.It Bq Er EACCES
-Permission to create a socket of the specified type and/or protocol
-is denied.
.It Bq Er ENOBUFS
Insufficient buffer space is available.
The socket cannot be created until sufficient resources are freed.
.It Bq Er EPERM
User has insufficient privileges to carry out the requested operation.
+.It Bq Er EPROTONOSUPPORT
+The protocol type or the specified protocol is not supported
+within this domain.
+.It Bq Er EPROTOTYPE
+The socket type is not supported by the protocol.
.El
.Sh SEE ALSO
.Xr accept 2 ,
diff --git a/lib/libc/sys/wait.2 b/lib/libc/sys/wait.2
index 71bd52949c76..0c494bb6fb5c 100644
--- a/lib/libc/sys/wait.2
+++ b/lib/libc/sys/wait.2
@@ -28,15 +28,17 @@
.\" @(#)wait.2 8.2 (Berkeley) 4/19/94
.\" $FreeBSD$
.\"
-.Dd November 12, 2005
+.Dd November 10, 2012
.Dt WAIT 2
.Os
.Sh NAME
.Nm wait ,
+.Nm waitid ,
.Nm waitpid ,
+.Nm wait3 ,
.Nm wait4 ,
-.Nm wait3
-.Nd wait for process termination
+.Nm wait6
+.Nd wait for processes to change status
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
@@ -46,12 +48,17 @@
.Fn wait "int *status"
.Ft pid_t
.Fn waitpid "pid_t wpid" "int *status" "int options"
+.In sys/signal.h
+.Ft int
+.Fn waitid "idtype_t idtype" "id_t id" "siginfo_t *info" "int options"
.In sys/time.h
.In sys/resource.h
.Ft pid_t
.Fn wait3 "int *status" "int options" "struct rusage *rusage"
.Ft pid_t
.Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage"
+.Ft pid_t
+.Fn wait6 "idtype_t idtype" "id_t id" "int *status" "int options" "struct __wrusage *wrusage" "siginfo_t *infop"
.Sh DESCRIPTION
The
.Fn wait
@@ -86,28 +93,172 @@ system call provides a more general interface for programs
that need to wait for certain child processes,
that need resource utilization statistics accumulated by child processes,
or that require options.
-The other wait functions are implemented using
-.Fn wait4 .
.Pp
+The broadest interface of all functions in this family is
+.Fn wait6
+which is otherwise very much like
+.Fn wait4
+but with a few very important distinctions.
+To wait for exited processes, the option flag
+.Dv WEXITED
+need to be explicitly specified.
+This allows for waiting for processes which have experienced other
+status changes without having to handle also the exit status from
+the terminated processes.
+Instead of the traditional
+.Dv rusage
+argument, a pointer to a new structure
+.Bd -literal
+struct __wrusage {
+ struct rusage wru_self;
+ struct rusage wru_children;
+};
+.Ed
+can be passed.
+This allows the calling process to collect resource usage statistics
+from both its own child process as well as from its grand children.
+When no resource usage statistics are needed this pointer can be
+.Dv NULL .
+The last argument
+.Fa infop
+must be either
+.Dv NULL
+or a pointer to a
+.Fa siginfo_t
+structure.
+When specified, the structure is filled the same as for
+.Dv SIGNCHLD
+signal, delivered at the process state change.
+.br
+The process, which state is queried, is specified by two arguments
+.Fa idtype
+and
+.Fa id .
+The separate
+.Fa idtype
+and
+.Fa id
+arguments allows to support many other types of
+IDs as well in addition to PID and PGID.
+.Bl -bullet -offset indent
+.It
+If
+.Fa idtype
+is
+.Dv P_PID ,
+.Fn waitid
+and
+.Fn wait6
+wait for the child process with a process ID equal to
+.Dv (pid_t)id .
+.It
+If
+.Fa idtype
+is
+.Dv P_PGID ,
+.Fn waitid
+and
+.Fn wait6
+wait for the child process with a process group ID equal to
+.Dv (pid_t)id .
+.It
+If
+.Fa idtype
+is
+.Dv P_ALL ,
+.Fn waitid
+and
+.Fn wait6
+wait for any child process and the
+.Dv id
+is ignored.
+.It
+If
+.Fa idtype
+is
+.Dv P_PID
+or
+.Dv P_PGID
+and the
+.Dv id
+is zero,
+.Fn waitid
+and
+.Fn wait6
+wait for any child process in the same process group as the caller.
+.El
+.Pp
+Non-standard specifiers for the process to wait for, supported by this
+implementation of
+.Fn waitid
+and
+.Fn wait6 ,
+are:
+.Bl -bullet -offset indent
+.It
The
+.Fa idtype
+value
+.Dv P_UID
+waits for processes which effective UID is equal to
+.Dv (uid_t)id .
+.It
+The
+.Fa idtype
+value
+.Dv P_GID
+waits for processes which effective GID is equal to
+.Dv (gid_t)id .
+.It
+The
+.Fa idtype
+value
+.Dv P_SID
+waits for processes which session ID is equal to
+.Dv id .
+In case the child process started its own new session,
+SID will be the same as its own PID.
+Otherwise the SID of a child process will match the caller's SID.
+.It
+The
+.Fa idtype
+value
+.Dv P_JAILID
+waits for processes within a jail which jail identifier is equal
+to
+.Dv id .
+.El
+.Pp
+For
+.Fn wait ,
+.Fn wait3 ,
+and
+.Fn wait4
+functions, the single
.Fa wpid
argument specifies the set of child processes for which to wait.
+.Bl -bullet -offset indent
+.It
If
.Fa wpid
is -1, the call waits for any child process.
+.It
If
.Fa wpid
is 0,
the call waits for any child process in the process group of the caller.
+.It
If
.Fa wpid
is greater than zero, the call waits for the process with process id
.Fa wpid .
+.It
If
.Fa wpid
is less than -1, the call waits for any process whose process group id
equals the absolute value of
.Fa wpid .
+.El
.Pp
The
.Fa status
@@ -116,41 +267,102 @@ argument is defined below.
The
.Fa options
argument contains the bitwise OR of any of the following options.
-The
-.Dv WCONTINUED
-option indicates that children of the current process that
+.Bl -tag -width Ds
+.It Dv WCONTINUED
+indicates that children of the current process that
have continued from a job control stop, by receiving a
.Dv SIGCONT
signal, should also have their status reported.
-The
-.Dv WNOHANG
-option
-is used to indicate that the call should not block if
-there are no processes that wish to report status.
-If the
-.Dv WUNTRACED
-option is set,
-children of the current process that are stopped
+.It Dv WNOHANG
+is used to indicate that the call should not block when
+there are no processes wishing to report status.
+.It Dv WUNTRACED
+indicates that children of the current process which are stopped
due to a
.Dv SIGTTIN , SIGTTOU , SIGTSTP ,
or
.Dv SIGSTOP
-signal also have their status reported.
-The
-.Dv WSTOPPED
-option is an alias for
+signal shall have their status reported.
+.It Dv WSTOPPED
+is an alias for
.Dv WUNTRACED .
-The
-.Dv WNOWAIT
-option keeps the process whose status is returned in a waitable state.
+.It Dv WTRAPPED
+allows waiting for processes which have trapped or reached a breakpoint.
+.It Dv WEXITED
+indicates that the caller is wants to receive status reports from
+terminated processes.
+This flag is implicitly set for the functions
+.Fn wait ,
+.Fn waitpid ,
+.Fn wait3 ,
+and
+.Fn wait4 .
+.br
+For the
+.Fn waitid
+and
+.Fn wait6
+functions, the flag has to be explicitly included in the
+.Fa options ,
+if status reports from terminated processes are expected.
+.It Dv WNOWAIT
+keeps the process whose status is returned in a waitable state.
The process may be waited for again after this call completes.
+.El
+.sp
+For the
+.Fn waitid
+and
+.Fn wait6
+functions, at least one of the options
+.Dv WEXITED ,
+.Dv WUNTRACED ,
+.Dv WSTOPPED ,
+.Dv WTRAPPED ,
+or
+.Dv WCONTINUED
+must be specified.
+Otherwise there will be no events for the call to report.
+To avoid hanging indefinitely in such a case these functions
+return -1 with
+.Dv errno
+set to
+.Dv EINVAL .
.Pp
If
.Fa rusage
-is non-zero, a summary of the resources used by the terminated
-process and all its
-children is returned (this information is currently not available
-for stopped or continued processes).
+is non-NULL, a summary of the resources used by the terminated
+process and all its children is returned.
+.Pp
+If
+.Fa wrusage
+argument is non-NULL, a resource usage statistics
+from both its own child process as well as from its grand children
+is returned.
+.Pp
+If
+.Fa infop
+is non-NULL, it must point to a
+.Dv siginfo_t
+structure which is filled on return such that the
+.Dv si_signo
+field is always
+.Dv SIGCHLD
+and the field
+.Dv si_pid
+if be non-zero, if there is a status change to report.
+If there are no status changes to report and WNOHANG is applied,
+both of these fields are returned zero.
+When using the
+.Fn waitid
+function with the
+.Dv WNOHANG
+option set, checking these fields is the only way to know whether
+there were any status changes to report, because the return value
+from
+.Fn waitid
+is be zero as it is for any successful return from
+.Fn waitid .
.Pp
When the
.Dv WNOHANG
@@ -175,6 +387,20 @@ call is the same as
with a
.Fa wpid
value of -1.
+The
+.Fn wait6
+call, with the bits
+.Dv WEXITED
+and
+.Dv WTRAPPED
+set in the
+.Fa options
+and with
+.Fa infop
+set to
+.Dv NULL ,
+is similar to
+.Fn wait4 .
.Pp
The following macros may be used to test the manner of exit of the process.
One of the first four macros will evaluate to a non-zero (true) value:
@@ -284,6 +510,7 @@ is returned and
is set to indicate the error.
.Pp
If
+.Fn wait6 ,
.Fn wait4 ,
.Fn wait3 ,
or
@@ -306,6 +533,18 @@ a value of -1
is returned and
.Va errno
is set to indicate the error.
+.Pp
+If
+.Fn waitid
+returns because one or more processes have a state change to report,
+0 is returned.
+To indicate an error, -1 will be returned and
+.Dv errno
+set to an appropriate value.
+If
+.Dv WNOHANG
+was used, 0 can be returned indicating no error, but no processes
+may have changed state either, if si_signo and/or si_pid are zero.
.Sh ERRORS
The
.Fn wait
@@ -335,6 +574,14 @@ The call was interrupted by a caught signal,
or the signal did not have the
.Dv SA_RESTART
flag set.
+.It Bq Er EINVAL
+An invalid value was specified for
+.Fa options ,
+or
+.Fa idtype
+and
+.Fa id
+do not specify a valid set of processes.
.El
.Sh SEE ALSO
.Xr _exit 2 ,
@@ -344,11 +591,13 @@ flag set.
.Xr siginfo 3
.Sh STANDARDS
The
-.Fn wait
+.Fn wait ,
+.Fn waitpid ,
and
-.Fn waitpid
+.Fn waitid
functions are defined by POSIX;
-.Fn wait4
+.Fn wait6 ,
+.Fn wait4 ,
and
.Fn wait3
are not specified by POSIX.
diff --git a/lib/libcompiler_rt/Makefile b/lib/libcompiler_rt/Makefile
index 84f9b368c137..a9daada4742f 100644
--- a/lib/libcompiler_rt/Makefile
+++ b/lib/libcompiler_rt/Makefile
@@ -28,7 +28,6 @@ SRCF= absvdi2 \
ashlti3 \
ashrdi3 \
ashrti3 \
- clear_cache \
clzdi2 \
clzsi2 \
clzti2 \
@@ -126,30 +125,40 @@ SRCF= absvdi2 \
umoddi3 \
umodti3
+# Don't build clear_cache on ARM with clang as it is a builtin there.
+.if ${MACHINE_CPUARCH} != "arm" || ${COMPILER_TYPE} != "clang"
+SRCF+= clear_cache
+.endif
+
# These are already shipped by libc.a on arm and mips
.if ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
SRCF+= adddf3 \
addsf3 \
divdf3 \
divsf3 \
- divsi3 \
extendsfdf2 \
fixdfsi \
fixsfsi \
floatsidf \
floatsisf \
- modsi3 \
muldf3 \
mulsf3 \
subdf3 \
subsf3 \
- truncdfsf2 \
+ truncdfsf2
+.endif
+
+.if ${MACHINE_CPUARCH} != "mips" && \
+ (${MACHINE_CPUARCH} != "arm" || ${MK_ARM_EABI} != "no")
+SRCF+= divsi3 \
+ modsi3 \
udivsi3 \
umodsi3
.endif
-# FreeBSD-specific atomic intrinsics.
-.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
+# FreeBSD-specific atomic intrinsics. Clang provides them as a builtin.
+.if (${MACHINE_CPUARCH} == "arm" && ${COMPILER_TYPE} != "clang") || \
+ ${MACHINE_CPUARCH} == "mips"
SRCF+= __sync_fetch_and_add_4 \
__sync_fetch_and_and_4 \
__sync_fetch_and_or_4 \
@@ -176,6 +185,17 @@ SRCS+= ${file}.c
. endif
.endfor
+.if ${MACHINE_CPUARCH} == "arm" && ${MK_ARM_EABI} != "no"
+SRCS+= aeabi_idivmod.S \
+ aeabi_ldivmod.S \
+ aeabi_memcmp.S \
+ aeabi_memcpy.S \
+ aeabi_memmove.S \
+ aeabi_memset.S \
+ aeabi_uidivmod.S \
+ aeabi_uldivmod.S
+.endif
+
.if ${MACHINE_CPUARCH} != "mips"
. if ${MK_INSTALLLIB} != "no"
SYMLINKS+=libcompiler_rt.a ${LIBDIR}/libgcc.a
diff --git a/lib/libcrypt/tests/Makefile b/lib/libcrypt/tests/Makefile
new file mode 100644
index 000000000000..3190dbe9492e
--- /dev/null
+++ b/lib/libcrypt/tests/Makefile
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+# exercise libcrypt
+
+TESTS_C= crypt_tests
+
+CFLAGS+= -I${.CURDIR:H}
+LDADD+= -L${.OBJDIR:H} -lcrypt
+
+.include <atf.test.mk>
diff --git a/lib/libcrypt/tests/crypt_tests.c b/lib/libcrypt/tests/crypt_tests.c
new file mode 100644
index 000000000000..3331d12d05f1
--- /dev/null
+++ b/lib/libcrypt/tests/crypt_tests.c
@@ -0,0 +1,54 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <crypt.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#define LEET "0.s0.l33t"
+
+ATF_TC(md5);
+ATF_TC_HEAD(md5, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Tests the MD5 based password hash");
+}
+
+ATF_TC_BODY(md5, tc)
+{
+ const char want[] = "$1$deadbeef$0Huu6KHrKLVWfqa4WljDE0";
+ char *pw;
+
+ pw = crypt(LEET, want);
+ ATF_CHECK_STREQ(pw, want);
+}
+
+ATF_TC(invalid);
+ATF_TC_HEAD(invalid, tc)
+{
+
+ atf_tc_set_md_var(tc, "descr", "Tests that invalid password fails");
+}
+
+ATF_TC_BODY(invalid, tc)
+{
+ const char want[] = "$1$cafebabe$0Huu6KHrKLVWfqa4WljDE0";
+ char *pw;
+
+ pw = crypt(LEET, want);
+ ATF_CHECK(strcmp(pw, want) != 0);
+}
+
+/*
+ * This function must not do anything except enumerate
+ * the test cases, else atf-run is likely to be upset.
+ */
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, md5);
+ ATF_TP_ADD_TC(tp, invalid);
+ return atf_no_error();
+}
diff --git a/lib/libcxxrt/Version.map b/lib/libcxxrt/Version.map
index ca990a0dddea..f7e12e1ce5b9 100644
--- a/lib/libcxxrt/Version.map
+++ b/lib/libcxxrt/Version.map
@@ -208,19 +208,7 @@ CXXABI_1.3 {
"typeinfo name for __cxxabiv1::__vmi_class_type_info";
"std::type_info::type_info(std::type_info const&)";
- "std::type_info::type_info(std::type_info const&)";
- "std::type_info::~type_info()";
- "std::type_info::~type_info()";
- "std::type_info::~type_info()";
"std::type_info::operator=(std::type_info const&)";
- "std::unexpected()";
- "std::get_terminate()";
- "std::set_terminate(void (*)())";
- "std::get_unexpected()";
- "std::set_unexpected(void (*)())";
- "std::set_new_handler(void (*)())";
- "std::uncaught_exception()";
- "std::terminate()";
# Extensions
@@ -243,69 +231,22 @@ CXXABI_1.3.1 {
CXXRT_1.0 {
extern "C++" {
- "std::bad_cast::what() const";
- "std::bad_typeid::what() const";
- "std::bad_alloc::what() const";
- "std::exception::what() const";
"std::type_info::name() const";
"std::type_info::before(std::type_info const&) const";
"std::type_info::operator==(std::type_info const&) const";
"std::type_info::operator!=(std::type_info const&) const";
- "std::bad_typeid::bad_typeid(std::bad_typeid const&)";
- "std::bad_typeid::bad_typeid()";
- "std::bad_typeid::bad_typeid(std::bad_typeid const&)";
- "std::bad_typeid::bad_typeid()";
- "std::bad_typeid::~bad_typeid()";
- "std::bad_typeid::~bad_typeid()";
- "std::bad_typeid::~bad_typeid()";
- "std::bad_typeid::operator=(std::bad_typeid const&)";
"std::bad_cast::bad_cast(std::bad_cast const&)";
"std::bad_cast::bad_cast()";
- "std::bad_cast::bad_cast(std::bad_cast const&)";
- "std::bad_cast::bad_cast()";
- "std::bad_cast::~bad_cast()";
- "std::bad_cast::~bad_cast()";
- "std::bad_cast::~bad_cast()";
"std::bad_cast::operator=(std::bad_cast const&)";
- "std::bad_alloc::bad_alloc(std::bad_alloc const&)";
- "std::bad_alloc::bad_alloc()";
- "std::bad_alloc::bad_alloc(std::bad_alloc const&)";
- "std::bad_alloc::bad_alloc()";
- "std::bad_alloc::~bad_alloc()";
- "std::bad_alloc::~bad_alloc()";
- "std::bad_alloc::~bad_alloc()";
- "std::bad_alloc::operator=(std::bad_alloc const&)";
- "std::exception::exception(std::exception const&)";
- "std::exception::exception()";
+ "std::bad_typeid::bad_typeid(std::bad_typeid const&)";
+ "std::bad_typeid::bad_typeid()";
+ "std::bad_typeid::operator=(std::bad_typeid const&)";
"std::exception::exception(std::exception const&)";
"std::exception::exception()";
- "std::exception::~exception()";
- "std::exception::~exception()";
- "std::exception::~exception()";
"std::exception::operator=(std::exception const&)";
-
-
- "vtable for std::bad_typeid";
- "vtable for std::bad_cast";
- "vtable for std::bad_alloc";
- "vtable for std::exception";
- "vtable for std::type_info";
- "typeinfo for std::bad_typeid";
- "typeinfo for std::bad_cast";
- "typeinfo for std::bad_alloc";
- "typeinfo for std::exception";
- "typeinfo for std::type_info";
- "typeinfo name for std::bad_typeid";
- "typeinfo name for std::bad_cast";
- "typeinfo name for std::bad_alloc";
- "typeinfo name for std::exception";
- "typeinfo name for std::type_info";
-
- "std::type_info::__is_function_p() const";
- "std::type_info::__do_upcast(__cxxabiv1::__class_type_info const*, void**) const";
- "std::type_info::__is_pointer_p() const";
-
-
+ "std::bad_alloc::bad_alloc(std::bad_alloc const&)";
+ "std::bad_alloc::bad_alloc()";
+ "std::bad_alloc::operator=(std::bad_alloc const&)";
};
__cxa_allocate_dependent_exception;
@@ -317,6 +258,7 @@ CXXRT_1.0 {
} CXXABI_1.3.1;
+
GLIBCXX_3.4 {
extern "C++" {
"operator delete[](void*)";
@@ -327,5 +269,51 @@ GLIBCXX_3.4 {
"operator new[](unsigned long)";
"operator new(unsigned long)";
"operator new(unsigned long, std::nothrow_t const&)";
+
+ "std::unexpected()";
+ "std::get_terminate()";
+ "std::get_unexpected()";
+ "std::uncaught_exception()";
+ "std::terminate()";
+
+ "std::type_info::~type_info()";
+ "std::bad_cast::~bad_cast()";
+ "std::bad_typeid::~bad_typeid()";
+ "std::exception::~exception()";
+ "std::bad_alloc::~bad_alloc()";
+
+ "std::exception::what() const";
+
+ std::set_new_handler*;
+ std::set_terminate*;
+ std::set_unexpected*;
+ std::type_info::__*;
+
+ "vtable for std::bad_alloc";
+ "vtable for std::bad_cast";
+ "vtable for std::bad_typeid";
+ "vtable for std::exception";
+ "vtable for std::type_info";
+
+ "typeinfo for std::bad_alloc";
+ "typeinfo for std::bad_typeid";
+ "typeinfo for std::bad_cast";
+ "typeinfo for std::exception";
+ "typeinfo for std::type_info";
+ "typeinfo name for std::bad_alloc";
+ "typeinfo name for std::bad_typeid";
+ "typeinfo name for std::bad_cast";
+ "typeinfo name for std::exception";
+ "typeinfo name for std::type_info";
+
};
};
+
+GLIBCXX_3.4.9 {
+ extern "C++" {
+ "std::bad_typeid::what() const";
+ "std::bad_cast::what() const";
+ "std::bad_alloc::what() const";
+ };
+} GLIBCXX_3.4;
+
diff --git a/lib/libdevstat/devstat.3 b/lib/libdevstat/devstat.3
index 8d0ce4dc0117..39be6ac0ecef 100644
--- a/lib/libdevstat/devstat.3
+++ b/lib/libdevstat/devstat.3
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 18, 2003
+.Dd December 15, 2012
.Dt DEVSTAT 3
.Os
.Sh NAME
@@ -526,6 +526,35 @@ the acquisition of
.Fa previous
and
.Fa current .
+.It Dv DSM_TOTAL_DURATION
+type:
+.Vt "long double *"
+.Pp
+The total duration of transactions, in seconds, between the acquisition of
+.Fa previous
+and
+.Fa current .
+.It Dv DSM_TOTAL_DURATION_OTHER
+.It Dv DSM_TOTAL_DURATION_READ
+.It Dv DSM_TOTAL_DURATION_WRITE
+.It Dv DSM_TOTAL_DURATION_FREE
+type:
+.Vt "long double *"
+.Pp
+The total duration of transactions of the specified type between
+the acquisition of
+.Fa previous
+and
+.Fa current .
+.It Dv DSM_TOTAL_BUSY_TIME
+type:
+.Vt "long double *"
+.Pp
+Total time the device had one or more transactions outstanding
+between the acquisition of
+.Fa previous
+and
+.Fa current .
.It Dv DSM_TOTAL_BLOCKS
type:
.Vt "uint64_t *"
diff --git a/lib/libdevstat/devstat.c b/lib/libdevstat/devstat.c
index ff0767a42db6..0f313fbba28d 100644
--- a/lib/libdevstat/devstat.c
+++ b/lib/libdevstat/devstat.c
@@ -133,6 +133,12 @@ struct devstat_args {
{ DSM_MS_PER_TRANSACTION_FREE, DEVSTAT_ARG_LD },
{ DSM_BUSY_PCT, DEVSTAT_ARG_LD },
{ DSM_QUEUE_LENGTH, DEVSTAT_ARG_UINT64 },
+ { DSM_TOTAL_DURATION, DEVSTAT_ARG_LD },
+ { DSM_TOTAL_DURATION_READ, DEVSTAT_ARG_LD },
+ { DSM_TOTAL_DURATION_WRITE, DEVSTAT_ARG_LD },
+ { DSM_TOTAL_DURATION_FREE, DEVSTAT_ARG_LD },
+ { DSM_TOTAL_DURATION_OTHER, DEVSTAT_ARG_LD },
+ { DSM_TOTAL_BUSY_TIME, DEVSTAT_ARG_LD },
};
static const char *namelist[] = {
@@ -1217,11 +1223,13 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
u_int64_t totaltransfers, totaltransfersread, totaltransferswrite;
u_int64_t totaltransfersother, totalblocks, totalblocksread;
u_int64_t totalblockswrite, totaltransfersfree, totalblocksfree;
+ long double totalduration, totaldurationread, totaldurationwrite;
+ long double totaldurationfree, totaldurationother;
va_list ap;
devstat_metric metric;
u_int64_t *destu64;
long double *destld;
- int retval, i;
+ int retval;
retval = 0;
@@ -1263,6 +1271,13 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
totalblocksfree /= 512;
}
+ totaldurationread = DELTA_T(duration[DEVSTAT_READ]);
+ totaldurationwrite = DELTA_T(duration[DEVSTAT_WRITE]);
+ totaldurationfree = DELTA_T(duration[DEVSTAT_FREE]);
+ totaldurationother = DELTA_T(duration[DEVSTAT_NO_DATA]);
+ totalduration = totaldurationread + totaldurationwrite +
+ totaldurationfree + totaldurationother;
+
va_start(ap, etime);
while ((metric = (devstat_metric)va_arg(ap, devstat_metric)) != 0) {
@@ -1484,9 +1499,7 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
*/
case DSM_MS_PER_TRANSACTION:
if (totaltransfers > 0) {
- *destld = 0;
- for (i = 0; i < DEVSTAT_N_TRANS_FLAGS; i++)
- *destld += DELTA_T(duration[i]);
+ *destld = totalduration;
*destld /= totaltransfers;
*destld *= 1000;
} else
@@ -1499,7 +1512,7 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
*/
case DSM_MS_PER_TRANSACTION_READ:
if (totaltransfersread > 0) {
- *destld = DELTA_T(duration[DEVSTAT_READ]);
+ *destld = totaldurationread;
*destld /= totaltransfersread;
*destld *= 1000;
} else
@@ -1507,7 +1520,7 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
break;
case DSM_MS_PER_TRANSACTION_WRITE:
if (totaltransferswrite > 0) {
- *destld = DELTA_T(duration[DEVSTAT_WRITE]);
+ *destld = totaldurationwrite;
*destld /= totaltransferswrite;
*destld *= 1000;
} else
@@ -1515,7 +1528,7 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
break;
case DSM_MS_PER_TRANSACTION_FREE:
if (totaltransfersfree > 0) {
- *destld = DELTA_T(duration[DEVSTAT_FREE]);
+ *destld = totaldurationfree;
*destld /= totaltransfersfree;
*destld *= 1000;
} else
@@ -1523,7 +1536,7 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
break;
case DSM_MS_PER_TRANSACTION_OTHER:
if (totaltransfersother > 0) {
- *destld = DELTA_T(duration[DEVSTAT_NO_DATA]);
+ *destld = totaldurationother;
*destld /= totaltransfersother;
*destld *= 1000;
} else
@@ -1541,6 +1554,24 @@ devstat_compute_statistics(struct devstat *current, struct devstat *previous,
case DSM_QUEUE_LENGTH:
*destu64 = current->start_count - current->end_count;
break;
+ case DSM_TOTAL_DURATION:
+ *destld = totalduration;
+ break;
+ case DSM_TOTAL_DURATION_READ:
+ *destld = totaldurationread;
+ break;
+ case DSM_TOTAL_DURATION_WRITE:
+ *destld = totaldurationwrite;
+ break;
+ case DSM_TOTAL_DURATION_FREE:
+ *destld = totaldurationfree;
+ break;
+ case DSM_TOTAL_DURATION_OTHER:
+ *destld = totaldurationother;
+ break;
+ case DSM_TOTAL_BUSY_TIME:
+ *destld = DELTA_T(busy_time);
+ break;
/*
* XXX: comment out the default block to see if any case's are missing.
*/
diff --git a/lib/libdevstat/devstat.h b/lib/libdevstat/devstat.h
index 7717cb1b5ec8..9471f934ba25 100644
--- a/lib/libdevstat/devstat.h
+++ b/lib/libdevstat/devstat.h
@@ -97,6 +97,12 @@ typedef enum {
DSM_MS_PER_TRANSACTION_FREE,
DSM_BUSY_PCT,
DSM_QUEUE_LENGTH,
+ DSM_TOTAL_DURATION,
+ DSM_TOTAL_DURATION_READ,
+ DSM_TOTAL_DURATION_WRITE,
+ DSM_TOTAL_DURATION_FREE,
+ DSM_TOTAL_DURATION_OTHER,
+ DSM_TOTAL_BUSY_TIME,
DSM_MAX
} devstat_metric;
diff --git a/lib/libdisk/Makefile b/lib/libdisk/Makefile
deleted file mode 100644
index 9f3e093075d7..000000000000
--- a/lib/libdisk/Makefile
+++ /dev/null
@@ -1,43 +0,0 @@
-# $FreeBSD$
-
-.if ${MACHINE_CPUARCH} == "ia64"
-_open_disk= open_ia64_disk.c
-.else
-_change = change.c
-_open_disk= open_disk.c
-.endif
-
-LIB= disk
-SRCS= blocks.c ${_change} chunk.c create_chunk.c disk.c ${_open_disk} \
- rules.c write_disk.c
-SRCS+= write_${MACHINE}_disk.c
-
-INCS= libdisk.h
-
-WARNS?= 2
-
-CFLAGS+= -I${.CURDIR}/../../sys/geom
-
-.if ${MACHINE} == "pc98"
-CFLAGS+= -DPC98
-.endif
-
-CLEANFILES+= tmp.c tst01 tst01.o
-NO_PROFILE=
-NO_PIC=
-
-MAN= libdisk.3
-
-.include <bsd.lib.mk>
-
-tst01: tst01.o libdisk.a
- cc ${CFLAGS} -static tst01.o -o tst01 libdisk.a
-
-ad0: all install tst01
- ./tst01 ad0
-
-da0: all install tst01
- ./tst01 da0
-
-da1: all install tst01
- ./tst01 da1
diff --git a/lib/libdisk/Makefile.depend b/lib/libdisk/Makefile.depend
deleted file mode 100644
index e248139c3a0e..000000000000
--- a/lib/libdisk/Makefile.depend
+++ /dev/null
@@ -1,16 +0,0 @@
-# Autogenerated - do NOT edit!
-
-DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
-
-DEP_MACHINE := ${.PARSEFILE:E}
-
-DIRDEPS = \
- include \
- include/xlocale \
-
-
-.include <dirdeps.mk>
-
-.if ${DEP_RELDIR} == ${_DEP_RELDIR}
-# local dependencies - needed for -jN in clean tree
-.endif
diff --git a/lib/libdisk/blocks.c b/lib/libdisk/blocks.c
deleted file mode 100644
index 313c5cca357e..000000000000
--- a/lib/libdisk/blocks.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "libdisk.h"
-
-void *
-read_block(int fd, daddr_t block, u_long sector_size)
-{
- void *foo;
- int i;
-
- foo = malloc(sector_size);
- if (foo == NULL)
- return (NULL);
- if (-1 == lseek(fd, (off_t)block * sector_size, SEEK_SET)) {
- free (foo);
- return (NULL);
- }
- i = read(fd, foo, sector_size);
- if ((int)sector_size != i) {
- free (foo);
- return (NULL);
- }
- return foo;
-}
-
-int
-write_block(int fd, daddr_t block, const void *foo, u_long sector_size)
-{
- int i;
-
- if (-1 == lseek(fd, (off_t)block * sector_size, SEEK_SET))
- return (-1);
- i = write(fd, foo, sector_size);
- if ((int)sector_size != i)
- return (-1);
- return 0;
-}
diff --git a/lib/libdisk/change.c b/lib/libdisk/change.c
deleted file mode 100644
index 5f0c9c6a8222..000000000000
--- a/lib/libdisk/change.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/types.h>
-#include "libdisk.h"
-
-void
-Set_Bios_Geom(struct disk *disk, u_long cyl, u_long hd, u_long sect)
-{
-
- disk->bios_cyl = cyl;
- disk->bios_hd = hd;
- disk->bios_sect = sect;
-}
-
-void
-Sanitize_Bios_Geom(struct disk *disk)
-{
- int sane;
-
- sane = 1;
-
- if (disk->bios_cyl >= 65536)
- sane = 0;
-#ifdef PC98
- if (disk->bios_hd >= 256)
- sane = 0;
- if (disk->bios_sect >= 256)
- sane = 0;
-#else
- if (disk->bios_hd > 256)
- sane = 0;
- if (disk->bios_sect > 63)
- sane = 0;
-#endif
-#if 0 /* Disable a check on a disk size. It's too strict. */
- if (disk->bios_cyl * disk->bios_hd * disk->bios_sect !=
- disk->chunks->size)
- sane = 0;
-#endif
- if (sane)
- return;
-
- /* First try something that IDE can handle */
- disk->bios_sect = 63;
- disk->bios_hd = 16;
- disk->bios_cyl = disk->chunks->size /
- (disk->bios_sect * disk->bios_hd);
-
-#ifdef PC98
- if (disk->bios_cyl < 65536)
-#else
- if (disk->bios_cyl < 1024)
-#endif
- return;
-
- /* Hmm, try harder... */
- /* Assume standard SCSI parameter */
-#ifdef PC98
- disk->bios_sect = 128;
- disk->bios_hd = 8;
-#else
- disk->bios_hd = 255;
-#endif
- disk->bios_cyl = disk->chunks->size /
- (disk->bios_sect * disk->bios_hd);
-
-#ifdef PC98
- if (disk->bios_cyl < 65536)
- return;
-
- /* Assume UIDE-133/98-A Challenger BIOS 0.9821C parameter */
- disk->bios_sect = 255;
- disk->bios_hd = 16;
- disk->bios_cyl = disk->chunks->size /
- (disk->bios_sect * disk->bios_hd);
-
- if (disk->bios_cyl < 65536)
- return;
-
- /* BIG-na-Drive? */
- disk->bios_hd = 255;
- disk->bios_cyl = disk->chunks->size /
- (disk->bios_sect * disk->bios_hd);
-#endif
-}
-
-void
-All_FreeBSD(struct disk *d, int force_all)
-{
- struct chunk *c;
- int type;
-
-#ifdef PC98
- type = 0xc494;
-#else
- type = 0xa5;
-#endif
-
-again:
- for (c = d->chunks->part; c; c = c->next)
- if (c->type != unused) {
- Delete_Chunk(d, c);
- goto again;
- }
- c = d->chunks;
- if (force_all) {
- Sanitize_Bios_Geom(d);
- Create_Chunk(d, c->offset, c->size, freebsd, type,
- CHUNK_FORCE_ALL, "FreeBSD");
- } else {
- Create_Chunk(d, c->offset, c->size, freebsd, type, 0,
- "FreeBSD");
- }
-}
diff --git a/lib/libdisk/chunk.c b/lib/libdisk/chunk.c
deleted file mode 100644
index fb43ef5192a0..000000000000
--- a/lib/libdisk/chunk.c
+++ /dev/null
@@ -1,595 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <err.h>
-#include "libdisk.h"
-
-struct chunk *
-New_Chunk(void)
-{
- struct chunk *c;
-
- c = malloc(sizeof *c);
- if (c != NULL)
- memset(c, 0, sizeof *c);
- return (c);
-}
-
-/* Is c2 completely inside c1 ? */
-
-static int
-Chunk_Inside(const struct chunk *c1, const struct chunk *c2)
-{
- /* if c1 ends before c2 do */
- if (c1->end < c2->end)
- return 0;
- /* if c1 starts after c2 do */
- if (c1->offset > c2->offset)
- return 0;
- return 1;
-}
-
-static struct chunk *
-Find_Mother_Chunk(struct chunk *chunks, daddr_t offset, daddr_t end,
- chunk_e type)
-{
- struct chunk *c1, *c2, ct;
-
- ct.offset = offset;
- ct.end = end;
- switch (type) {
- case whole:
- if (Chunk_Inside(chunks, &ct))
- return chunks;
- case extended:
- for (c1 = chunks->part; c1; c1 = c1->next) {
- if (c1->type != type)
- continue;
- if (Chunk_Inside(c1, &ct))
- return c1;
- }
- return 0;
- case freebsd:
- for (c1 = chunks->part; c1; c1 = c1->next) {
- if (c1->type == type)
- if (Chunk_Inside(c1, &ct))
- return c1;
- if (c1->type != extended)
- continue;
- for (c2 = c1->part; c2; c2 = c2->next)
- if (c2->type == type && Chunk_Inside(c2, &ct))
- return c2;
- }
- return 0;
-#ifdef __powerpc__
- case apple:
- for (c1 = chunks->part; c1; c1 = c1->next) {
- if (c1->type == type)
- if (Chunk_Inside(c1, &ct))
- return c1;
- }
- return 0;
-#endif
- default:
- warn("Unsupported mother type in Find_Mother_Chunk");
- return 0;
- }
-}
-
-void
-Free_Chunk(struct chunk *c1)
-{
- if(c1 == NULL)
- return;
- if(c1->private_data && c1->private_free)
- (*c1->private_free)(c1->private_data);
- if(c1->part != NULL)
- Free_Chunk(c1->part);
- if(c1->next != NULL)
- Free_Chunk(c1->next);
- if (c1->name != NULL)
- free(c1->name);
- if (c1->sname != NULL)
- free(c1->sname);
- free(c1);
-}
-
-struct chunk *
-Clone_Chunk(const struct chunk *c1)
-{
- struct chunk *c2;
-
- if(!c1)
- return NULL;
- c2 = New_Chunk();
- if (c2 == NULL)
- return NULL;
- *c2 = *c1;
- if (c1->private_data && c1->private_clone)
- c2->private_data = c2->private_clone(c2->private_data);
- c2->name = strdup(c2->name);
- if (c2->sname != NULL)
- c2->sname = strdup(c2->sname);
- c2->next = Clone_Chunk(c2->next);
- c2->part = Clone_Chunk(c2->part);
- return c2;
-}
-
-int
-Insert_Chunk(struct chunk *c2, daddr_t offset, daddr_t size, const char *name,
- chunk_e type, int subtype, u_long flags, const char *sname)
-{
- struct chunk *ct,*cs;
-
- /* We will only insert into empty spaces */
- if (c2->type != unused)
- return __LINE__;
-
- ct = New_Chunk();
- if (ct == NULL)
- return __LINE__;
- ct->disk = c2->disk;
- ct->offset = offset;
- ct->size = size;
- ct->end = offset + size - 1;
- ct->type = type;
- if (sname != NULL)
- ct->sname = strdup(sname);
- ct->name = strdup(name);
- ct->subtype = subtype;
- ct->flags = flags;
-
- if (!Chunk_Inside(c2, ct)) {
- Free_Chunk(ct);
- return __LINE__;
- }
-
- if ((type == freebsd || type == extended || type == apple)) {
- cs = New_Chunk();
- if (cs == NULL)
- return __LINE__;
- cs->disk = c2->disk;
- cs->offset = offset;
- cs->size = size;
- cs->end = offset + size - 1;
- cs->type = unused;
- if (sname != NULL)
- cs->sname = strdup(sname);
- cs->name = strdup("-");
- ct->part = cs;
- }
-
- /* Make a new chunk for any trailing unused space */
- if (c2->end > ct->end) {
- cs = New_Chunk();
- if (cs == NULL)
- return __LINE__;
- *cs = *c2;
- cs->disk = c2->disk;
- cs->offset = ct->end + 1;
- cs->size = c2->end - ct->end;
- if (c2->sname != NULL)
- cs->sname = strdup(c2->sname);
- if (c2->name)
- cs->name = strdup(c2->name);
- c2->next = cs;
- c2->size -= c2->end - ct->end;
- c2->end = ct->end;
- }
- /* If no leading unused space just occupy the old chunk */
- if (c2->offset == ct->offset) {
- c2->sname = ct->sname;
- c2->name = ct->name;
- c2->type = ct->type;
- c2->part = ct->part;
- c2->subtype = ct->subtype;
- c2->flags = ct->flags;
- ct->sname = NULL;
- ct->name = NULL;
- ct->part = 0;
- Free_Chunk(ct);
- return 0;
- }
- /* else insert new chunk and adjust old one */
- c2->end = ct->offset - 1;
- c2->size -= ct->size;
- ct->next = c2->next;
- c2->next = ct;
- return 0;
-}
-
-int
-Add_Chunk(struct disk *d, daddr_t offset, daddr_t size, const char *name,
- chunk_e type, int subtype, u_long flags, const char *sname)
-{
- struct chunk *c1, *c2, ct;
- daddr_t end = offset + size - 1;
- ct.offset = offset;
- ct.end = end;
- ct.size = size;
-
- if (type == whole) {
- d->chunks = c1 = New_Chunk();
- if (c1 == NULL)
- return __LINE__;
- c2 = c1->part = New_Chunk();
- if (c2 == NULL)
- return __LINE__;
- c2->disk = c1->disk = d;
- c2->offset = c1->offset = offset;
- c2->size = c1->size = size;
- c2->end = c1->end = end;
- c1->sname = strdup(sname);
- c2->sname = strdup("-");
- c1->name = strdup(name);
- c2->name = strdup("-");
- c1->type = type;
- c2->type = unused;
- c1->flags = flags;
- c1->subtype = subtype;
- return 0;
- }
-
- c1 = 0;
- /* PLATFORM POLICY BEGIN ------------------------------------- */
- switch(platform) {
- case p_i386:
- case p_amd64:
- switch (type) {
- case fat:
- case gpt:
- case mbr:
- case extended:
- case freebsd:
- c1 = Find_Mother_Chunk(d->chunks, offset, end, whole);
- break;
- case part:
- c1 = Find_Mother_Chunk(d->chunks, offset, end, freebsd);
- break;
- default:
- return(-1);
- }
- break;
- case p_ia64:
- switch (type) {
- case freebsd:
- subtype = 0xa5;
- /* FALL THROUGH */
- case fat:
- case efi:
- case mbr:
- c1 = Find_Mother_Chunk(d->chunks, offset, end, whole);
- break;
- case part:
- c1 = Find_Mother_Chunk(d->chunks, offset, end,
- freebsd);
- if (!c1)
- c1 = Find_Mother_Chunk(d->chunks, offset, end,
- whole);
- break;
- default:
- return (-1);
- }
- break;
- case p_pc98:
- switch (type) {
- case fat:
- case pc98:
- case freebsd:
- c1 = Find_Mother_Chunk(d->chunks, offset, end, whole);
- break;
- case part:
- c1 = Find_Mother_Chunk(d->chunks, offset, end, freebsd);
- break;
- default:
- return(-1);
- }
- break;
- case p_sparc64:
- case p_alpha:
- switch (type) {
- case freebsd:
- c1 = Find_Mother_Chunk(d->chunks, offset, end, whole);
- break;
- case part:
- c1 = Find_Mother_Chunk(d->chunks, offset, end, freebsd);
- break;
- default:
- return(-1);
- }
- break;
- case p_ppc:
- switch (type) {
- case apple:
- c1 = Find_Mother_Chunk(d->chunks, offset, end, whole);
- break;
- case part:
- c1 = Find_Mother_Chunk(d->chunks, offset, end, apple);
- break;
- default:
- return (-1);
- }
- break;
- default:
- return (-1);
- }
- /* PLATFORM POLICY END ---------------------------------------- */
-
- if(!c1)
- return __LINE__;
- for(c2 = c1->part; c2; c2 = c2->next) {
- if (c2->type != unused)
- continue;
- if(!Chunk_Inside(c2, &ct))
- continue;
-/* PLATFORM POLICY BEGIN ------------------------------------- */
- if (platform == p_sparc64) {
- offset = Prev_Cyl_Aligned(d, offset);
- size = Next_Cyl_Aligned(d, size);
- } else if (platform == p_i386 || platform == p_pc98 ||
- platform == p_amd64) {
- if (type != freebsd)
- break;
- if (!(flags & CHUNK_ALIGN))
- break;
- if (offset == d->chunks->offset &&
- end == d->chunks->end)
- break;
-
- /* Round down to prev cylinder */
- offset = Prev_Cyl_Aligned(d,offset);
- /* Stay inside the parent */
- if (offset < c2->offset)
- offset = c2->offset;
- /* Round up to next cylinder */
- offset = Next_Cyl_Aligned(d, offset);
- /* Keep one track clear in front of parent */
- if (offset == c1->offset)
- offset = Next_Track_Aligned(d, offset + 1);
- /* Work on the (end+1) */
- size += offset;
- /* Round up to cylinder */
- size = Next_Cyl_Aligned(d, size);
- /* Stay inside parent */
- if ((size-1) > c2->end)
- size = c2->end + 1;
- /* Round down to cylinder */
- size = Prev_Cyl_Aligned(d, size);
-
- /* Convert back to size */
- size -= offset;
- }
- break;
-
-/* PLATFORM POLICY END ------------------------------------- */
- }
- if (c2 == NULL)
- return (__LINE__);
- return Insert_Chunk(c2, offset, size, name, type, subtype, flags,
- sname);
-}
-
-char *
-ShowChunkFlags(struct chunk *c)
-{
- static char ret[10];
- int i = 0;
-
- if (c->flags & CHUNK_ACTIVE)
- ret[i++] = 'A';
- if (c->flags & CHUNK_ALIGN)
- ret[i++] = '=';
- if (c->flags & CHUNK_IS_ROOT)
- ret[i++] = 'R';
- ret[i++] = '\0';
-
- return ret;
-}
-
-static void
-Print_Chunk(struct chunk *c1, int offset)
-{
- int i;
-
- if (!c1)
- return;
- for (i = 0; i < offset - 2; i++)
- putchar(' ');
- for (; i < offset; i++)
- putchar('-');
- putchar('>');
- for (; i < 10; i++)
- putchar(' ');
-#ifndef __ia64__
- printf("%p ", c1);
-#endif
- printf("%8jd %8jd %8jd %-8s %-16s %-8s 0x%02x %s",
- (intmax_t)c1->offset, (intmax_t)c1->size, (intmax_t)c1->end,
- c1->name, c1->sname, chunk_name(c1->type), c1->subtype,
- ShowChunkFlags(c1));
- putchar('\n');
- Print_Chunk(c1->part, offset + 2);
- Print_Chunk(c1->next, offset);
-}
-
-void
-Debug_Chunk(struct chunk *c1)
-{
-
- Print_Chunk(c1, 2);
-}
-
-int
-Delete_Chunk(struct disk *d, struct chunk *c)
-{
-
- return (Delete_Chunk2(d, c, 0));
-}
-
-int
-Delete_Chunk2(struct disk *d, struct chunk *c, int rflags)
-{
- struct chunk *c1, *c2, *c3;
- daddr_t offset = c->offset;
-
- switch (c->type) {
- case whole:
- case unused:
- return 1;
- case extended:
- c1 = Find_Mother_Chunk(d->chunks, c->offset, c->end, whole);
- break;
- case part:
- c1 = Find_Mother_Chunk(d->chunks, c->offset, c->end, freebsd);
-#ifdef __ia64__
- if (c1 == NULL)
- c1 = Find_Mother_Chunk(d->chunks, c->offset, c->end,
- whole);
-#endif
-#ifdef __powerpc__
- if (c1 == NULL)
- c1 = Find_Mother_Chunk(d->chunks, c->offset, c->end,
- apple);
-#endif
- break;
- default:
- c1 = Find_Mother_Chunk(d->chunks, c->offset, c->end, extended);
- if (c1 == NULL)
- c1 = Find_Mother_Chunk(d->chunks, c->offset, c->end,
- whole);
- break;
- }
- if (c1 == NULL)
- return 1;
- for (c2 = c1->part; c2; c2 = c2->next) {
- if (c2 == c) {
- c2->type = unused;
- c2->subtype = 0;
- c2->flags = 0;
- if (c2->sname != NULL)
- free(c2->sname);
- c2->sname = strdup("-");
- free(c2->name);
- c2->name = strdup("-");
- Free_Chunk(c2->part);
- c2->part =0;
- goto scan;
- }
- }
- return 1;
-scan:
- /*
- * Collapse multiple unused elements together, and attempt
- * to extend the previous chunk into the freed chunk.
- *
- * We only extend non-unused elements which are marked
- * for newfs (we can't extend working filesystems), and
- * only if we are called with DELCHUNK_RECOVER.
- */
- for (c2 = c1->part; c2; c2 = c2->next) {
- if (c2->type != unused) {
- if (c2->offset + c2->size != offset ||
- (rflags & DELCHUNK_RECOVER) == 0 ||
- (c2->flags & CHUNK_NEWFS) == 0) {
- continue;
- }
- /* else extend into free area */
- }
- if (!c2->next)
- continue;
- if (c2->next->type != unused)
- continue;
- c3 = c2->next;
- c2->size += c3->size;
- c2->end = c3->end;
- c2->next = c3->next;
- c3->next = 0;
- Free_Chunk(c3);
- goto scan;
- }
- Fixup_Names(d);
- return 0;
-}
-
-#if 0
-int
-Collapse_Chunk(struct disk *d, struct chunk *c1)
-{
- struct chunk *c2, *c3;
-
- if (c1->next && Collapse_Chunk(d, c1->next))
- return 1;
-
- if (c1->type == unused && c1->next && c1->next->type == unused) {
- c3 = c1->next;
- c1->size += c3->size;
- c1->end = c3->end;
- c1->next = c3->next;
- c3->next = 0;
- Free_Chunk(c3);
- return 1;
- }
- c3 = c1->part;
- if (!c3)
- return 0;
- if (Collapse_Chunk(d, c1->part))
- return 1;
-
- if (c1->type == whole)
- return 0;
-
- if (c3->type == unused && c3->size == c1->size) {
- Delete_Chunk(d, c1);
- return 1;
- }
- if (c3->type == unused) {
- c2 = New_Chunk();
- if (c2 == NULL)
- barfout(1, "malloc failed");
- *c2 = *c1;
- c1->next = c2;
- c1->disk = d;
- c1->sname = strdup("-");
- c1->name = strdup("-");
- c1->part = 0;
- c1->type = unused;
- c1->flags = 0;
- c1->subtype = 0;
- c1->size = c3->size;
- c1->end = c3->end;
- c2->offset += c1->size;
- c2->size -= c1->size;
- c2->part = c3->next;
- c3->next = 0;
- Free_Chunk(c3);
- return 1;
- }
- for (c2 = c3; c2->next; c2 = c2->next)
- c3 = c2;
- if (c2 && c2->type == unused) {
- c3->next = 0;
- c2->next = c1->next;
- c1->next = c2;
- c1->size -= c2->size;
- c1->end -= c2->size;
- return 1;
- }
-
- return 0;
-}
-#endif
diff --git a/lib/libdisk/create_chunk.c b/lib/libdisk/create_chunk.c
deleted file mode 100644
index 7f1453e6fcd1..000000000000
--- a/lib/libdisk/create_chunk.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <sys/param.h>
-#include <sys/disklabel.h>
-#ifdef PC98
-#include <sys/diskpc98.h>
-#else
-#include <sys/diskmbr.h>
-#endif
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <sys/sysctl.h>
-#include <grp.h>
-#include <paths.h>
-#include <pwd.h>
-#include "libdisk.h"
-
-static int
-Fixup_FreeBSD_Names(struct chunk *c)
-{
- struct chunk *c1, *c3;
- uint j;
-
- if (!strcmp(c->name, "X"))
- return 0;
-
- /* reset all names to "X" */
- for (c1 = c->part; c1; c1 = c1->next) {
- c1->oname = c1->name;
- c1->name = malloc(12);
- if (!c1->name)
- return -1;
- strcpy(c1->name,"X");
- }
-
- /* Allocate the first swap-partition we find */
- for (c1 = c->part; c1; c1 = c1->next) {
- if (c1->type == unused)
- continue;
- if (c1->subtype != FS_SWAP)
- continue;
- sprintf(c1->name, "%s%c", c->name, SWAP_PART + 'a');
- break;
- }
-
- /* Allocate the first root-partition we find */
- for (c1 = c->part; c1; c1 = c1->next) {
- if (c1->type == unused)
- continue;
- if (!(c1->flags & CHUNK_IS_ROOT))
- continue;
- sprintf(c1->name, "%s%c", c->name, 0 + 'a');
- break;
- }
-
- /* Try to give them the same as they had before */
- for (c1 = c->part; c1; c1 = c1->next) {
- if (strcmp(c1->name, "X"))
- continue;
- for (c3 = c->part; c3 ; c3 = c3->next)
- if (c1 != c3 && !strcmp(c3->name, c1->oname))
- goto newname;
- strcpy(c1->name, c1->oname);
- newname:
- ;
- }
-
- /* Allocate the rest sequentially */
- for (c1 = c->part; c1; c1 = c1->next) {
- const char order[] = "defghab";
-
- if (c1->type == unused)
- continue;
- if (strcmp("X", c1->name))
- continue;
-
- for (j = 0; j < strlen(order); j++) {
- sprintf(c1->name, "%s%c", c->name, order[j]);
- for (c3 = c->part; c3 ; c3 = c3->next)
- if (c1 != c3 && !strcmp(c3->name, c1->name))
- goto match;
- break;
- match:
- strcpy(c1->name, "X");
- continue;
- }
- }
- for (c1 = c->part; c1; c1 = c1->next) {
- free(c1->oname);
- c1->oname = 0;
- }
- return 0;
-}
-
-#ifndef PC98
-static int
-Fixup_Extended_Names(struct chunk *c)
-{
- struct chunk *c1;
- int j = 5;
-
- for (c1 = c->part; c1; c1 = c1->next) {
- if (c1->type == unused)
- continue;
- free(c1->name);
- c1->name = malloc(12);
- if (!c1->name)
- return -1;
- sprintf(c1->name, "%ss%d", c->disk->chunks->name, j++);
- if (c1->type == freebsd)
- if (Fixup_FreeBSD_Names(c1) != 0)
- return -1;
- }
- return 0;
-}
-#endif
-
-#ifdef __powerpc__
-static int
-Fixup_Apple_Names(struct chunk *c)
-{
- struct chunk *c1;
-
- for (c1 = c->part; c1; c1 = c1->next) {
- if (c1->type == unused)
- continue;
- free(c1->name);
- c1->name = strdup(c->name);
- if (!c1->name)
- return (-1);
- }
- return 0;
-}
-#endif
-
-int
-Fixup_Names(struct disk *d)
-{
- struct chunk *c1, *c2;
-#if defined(__i386__) || defined(__ia64__) || defined(__amd64__)
- struct chunk *c3;
- int j, max;
-#endif
-
- c1 = d->chunks;
- for (c2 = c1->part; c2 ; c2 = c2->next) {
- if (c2->type == unused)
- continue;
- if (strcmp(c2->name, "X"))
- continue;
-#if defined(__i386__) || defined(__ia64__) || defined(__amd64__)
- c2->oname = malloc(12);
- if (!c2->oname)
- return -1;
-#ifdef __ia64__
- max = d->gpt_size;
-#else
- max = NDOSPART;
-#endif
- for (j = 1; j <= max; j++) {
-#ifdef __ia64__
- sprintf(c2->oname, "%s%c%d", c1->name,
- (c1->type == whole) ? 'p' : 's', j);
-#else
- sprintf(c2->oname, "%ss%d", c1->name, j);
-#endif
- for (c3 = c1->part; c3; c3 = c3->next)
- if (c3 != c2 && !strcmp(c3->name, c2->oname))
- goto match;
- free(c2->name);
- c2->name = c2->oname;
- c2->oname = 0;
- break;
- match:
- continue;
- }
- if (c2->oname)
- free(c2->oname);
-#else
- free(c2->name);
- c2->name = strdup(c1->name);
-#endif /*__i386__*/
- }
- for (c2 = c1->part; c2; c2 = c2->next) {
- if (c2->type == freebsd)
- Fixup_FreeBSD_Names(c2);
-#ifdef __powerpc__
- else if (c2->type == apple)
- Fixup_Apple_Names(c2);
-#endif
-#ifndef PC98
- else if (c2->type == extended)
- Fixup_Extended_Names(c2);
-#endif
- }
- return 0;
-}
-
-int
-Create_Chunk(struct disk *d, daddr_t offset, daddr_t size, chunk_e type,
- int subtype, u_long flags, const char *sname)
-{
- int i;
-
-#ifndef __ia64__
- if (!(flags & CHUNK_FORCE_ALL)) {
- daddr_t l;
-#ifdef PC98
- /* Never use the first cylinder */
- if (!offset) {
- offset += (d->bios_sect * d->bios_hd);
- size -= (d->bios_sect * d->bios_hd);
- }
-#else
- /* Never use the first track */
- if (!offset) {
- offset += d->bios_sect;
- size -= d->bios_sect;
- }
-#endif /* PC98 */
-
- /* Always end on cylinder boundary */
- l = (offset + size) % (d->bios_sect * d->bios_hd);
- size -= l;
- }
-#endif
-
- i = Add_Chunk(d, offset, size, "X", type, subtype, flags, sname);
- Fixup_Names(d);
- return i;
-}
-
-struct chunk *
-Create_Chunk_DWIM(struct disk *d, struct chunk *parent, daddr_t size,
- chunk_e type, int subtype, u_long flags)
-{
- int i;
- struct chunk *c1;
- daddr_t offset;
-
- if (!parent)
- parent = d->chunks;
-
- if ((parent->type == freebsd && type == part && parent->part == NULL)
- || (parent->type == apple && type == part && parent->part == NULL)) {
- c1 = New_Chunk();
- if (c1 == NULL)
- return (NULL);
- c1->disk = parent->disk;
- c1->offset = parent->offset;
- c1->size = parent->size;
- c1->end = parent->offset + parent->size - 1;
- c1->type = unused;
- if (parent->sname != NULL)
- c1->sname = strdup(parent->sname);
- c1->name = strdup("-");
- parent->part = c1;
- }
-
- for (c1 = parent->part; c1; c1 = c1->next) {
- if (c1->type != unused)
- continue;
- if (c1->size < size)
- continue;
- offset = c1->offset;
- goto found;
- }
- return 0;
-found:
- i = Add_Chunk(d, offset, size, "X", type, subtype, flags, "-");
- if (i)
- return 0;
- Fixup_Names(d);
- for (c1 = parent->part; c1; c1 = c1->next)
- if (c1->offset == offset)
- return c1;
- /* barfout(1, "Serious internal trouble"); */
- return 0;
-}
diff --git a/lib/libdisk/disk.c b/lib/libdisk/disk.c
deleted file mode 100644
index c00e0e7ecec6..000000000000
--- a/lib/libdisk/disk.c
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <inttypes.h>
-#include <err.h>
-#include <sys/sysctl.h>
-#include <sys/stdint.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/disklabel.h>
-#include <sys/uuid.h>
-#include <sys/gpt.h>
-#include <paths.h>
-#include "libdisk.h"
-
-#include <ctype.h>
-#include <errno.h>
-#include <assert.h>
-#include <uuid.h>
-
-const enum platform platform =
-#if defined (P_DEBUG)
- P_DEBUG
-#elif defined (PC98)
- p_pc98
-#elif defined(__i386__)
- p_i386
-#elif defined(__alpha__)
- p_alpha
-#elif defined(__sparc64__)
- p_sparc64
-#elif defined(__ia64__)
- p_ia64
-#elif defined(__ppc__)
- p_ppc
-#elif defined(__amd64__)
- p_amd64
-#elif defined(__arm__)
- p_arm
-#elif defined(__mips__)
- p_mips
-#else
- IHAVENOIDEA
-#endif
- ;
-
-const char *
-chunk_name(chunk_e type)
-{
- switch(type) {
- case unused: return ("unused");
- case mbr: return ("mbr");
- case part: return ("part");
- case gpt: return ("gpt");
- case pc98: return ("pc98");
- case sun: return ("sun");
- case freebsd: return ("freebsd");
- case fat: return ("fat");
- case spare: return ("spare");
- case efi: return ("efi");
- case apple: return ("apple");
- default: return ("??");
- }
-}
-
-struct disk *
-Open_Disk(const char *name)
-{
- struct disk *d;
- char *conftxt;
- size_t txtsize;
- int error;
-
- error = sysctlbyname("kern.geom.conftxt", NULL, &txtsize, NULL, 0);
- if (error) {
- warn("kern.geom.conftxt sysctl not available, giving up!");
- return (NULL);
- }
- conftxt = malloc(txtsize+1);
- if (conftxt == NULL) {
- warn("cannot malloc memory for conftxt");
- return (NULL);
- }
- error = sysctlbyname("kern.geom.conftxt", conftxt, &txtsize, NULL, 0);
- if (error) {
- warn("error reading kern.geom.conftxt from the system");
- free(conftxt);
- return (NULL);
- }
- conftxt[txtsize] = '\0'; /* in case kernel bug is still there */
- d = Int_Open_Disk(name, conftxt);
- free(conftxt);
-
- return (d);
-}
-
-void
-Debug_Disk(struct disk *d)
-{
-
- printf("Debug_Disk(%s)", d->name);
-
-#ifndef __ia64__
- printf(" bios_geom=%lu/%lu/%lu = %lu\n",
- d->bios_cyl, d->bios_hd, d->bios_sect,
- d->bios_cyl * d->bios_hd * d->bios_sect);
-#if defined(PC98)
- printf(" boot1=%p, boot2=%p, bootipl=%p, bootmenu=%p\n",
- d->boot1, d->boot2, d->bootipl, d->bootmenu);
-#elif defined(__i386__) || defined(__amd64__)
- printf(" boot1=%p, boot2=%p, bootmgr=%p\n",
- d->boot1, d->boot2, d->bootmgr);
-#elif defined(__alpha__)
- printf(" boot1=%p, bootmgr=%p\n",
- d->boot1, d->bootmgr);
-#else
-/* Should be: error "Debug_Disk: unknown arch"; */
-#endif
-#else /* __ia64__ */
- printf(" media size=%lu, sector size=%lu\n", d->media_size,
- d->sector_size);
-#endif
-
- Debug_Chunk(d->chunks);
-}
-
-void
-Free_Disk(struct disk *d)
-{
- if (d->chunks)
- Free_Chunk(d->chunks);
- if (d->name)
- free(d->name);
-#ifdef PC98
- if (d->bootipl)
- free(d->bootipl);
- if (d->bootmenu)
- free(d->bootmenu);
-#else
-#if !defined(__ia64__)
- if (d->bootmgr)
- free(d->bootmgr);
-#endif
-#endif
-#if !defined(__ia64__)
- if (d->boot1)
- free(d->boot1);
-#endif
-#if defined(__i386__) || defined(__amd64__)
- if (d->boot2)
- free(d->boot2);
-#endif
- free(d);
-}
-
-#if 0
-void
-Collapse_Disk(struct disk *d)
-{
-
- while (Collapse_Chunk(d, d->chunks))
- ;
-}
-#endif
-
-static int
-qstrcmp(const void* a, const void* b)
-{
- const char *str1 = *(char* const*)a;
- const char *str2 = *(char* const*)b;
-
- return strcmp(str1, str2);
-}
-
-char **
-Disk_Names()
-{
- int disk_cnt;
- char **disks;
- int error;
- size_t listsize;
- char *disklist, *disk1, *disk2;
-
- error = sysctlbyname("kern.disks", NULL, &listsize, NULL, 0);
- if (error) {
- warn("kern.disks sysctl not available");
- return NULL;
- }
-
- if (listsize == 0)
- return (NULL);
-
- disks = malloc(sizeof *disks * (1 + MAX_NO_DISKS));
- if (disks == NULL)
- return NULL;
- disk1 = disklist = (char *)malloc(listsize + 1);
- if (disklist == NULL) {
- free(disks);
- return NULL;
- }
- memset(disks,0,sizeof *disks * (1 + MAX_NO_DISKS));
- memset(disklist, 0, listsize + 1);
- error = sysctlbyname("kern.disks", disklist, &listsize, NULL, 0);
- if (error || disklist[0] == 0) {
- free(disklist);
- free(disks);
- return NULL;
- }
- for (disk_cnt = 0; disk_cnt < MAX_NO_DISKS; disk_cnt++) {
- disk2 = strsep(&disk1, " ");
- if (disk2 == NULL)
- break;
- disks[disk_cnt] = strdup(disk2);
- if (disks[disk_cnt] == NULL) {
- for (disk_cnt--; disk_cnt >= 0; disk_cnt--)
- free(disks[disk_cnt]);
- free(disklist);
- free(disks);
- return (NULL);
- }
- }
- qsort(disks, disk_cnt, sizeof(char*), qstrcmp);
- free(disklist);
- return disks;
-}
-
-#ifdef PC98
-void
-Set_Boot_Mgr(struct disk *d, const u_char *bootipl, const size_t bootipl_size,
- const u_char *bootmenu, const size_t bootmenu_size)
-#else
-void
-Set_Boot_Mgr(struct disk *d, const u_char *b, const size_t s)
-#endif
-{
-#if !defined(__ia64__)
-#ifdef PC98
- if (d->sector_size == 0)
- return;
- if (bootipl_size % d->sector_size != 0)
- return;
- if (d->bootipl)
- free(d->bootipl);
- if (!bootipl) {
- d->bootipl = NULL;
- } else {
- d->bootipl_size = bootipl_size;
- d->bootipl = malloc(bootipl_size);
- if (!d->bootipl)
- return;
- memcpy(d->bootipl, bootipl, bootipl_size);
- }
-
- if (bootmenu_size % d->sector_size != 0)
- return;
- if (d->bootmenu)
- free(d->bootmenu);
- if (!bootmenu) {
- d->bootmenu = NULL;
- } else {
- d->bootmenu_size = bootmenu_size;
- d->bootmenu = malloc(bootmenu_size);
- if (!d->bootmenu)
- return;
- memcpy(d->bootmenu, bootmenu, bootmenu_size);
- }
-#else
- if (d->sector_size == 0)
- return;
- if (s % d->sector_size != 0)
- return;
- if (d->bootmgr)
- free(d->bootmgr);
- if (!b) {
- d->bootmgr = NULL;
- } else {
- d->bootmgr_size = s;
- d->bootmgr = malloc(s);
- if (!d->bootmgr)
- return;
- memcpy(d->bootmgr, b, s);
- }
-#endif
-#endif
-}
-
-int
-Set_Boot_Blocks(struct disk *d, const u_char *b1, const u_char *b2)
-{
-#if defined(__i386__) || defined(__amd64__)
- if (d->boot1)
- free(d->boot1);
- d->boot1 = malloc(512);
- if (!d->boot1)
- return -1;
- memcpy(d->boot1, b1, 512);
- if (d->boot2)
- free(d->boot2);
- d->boot2 = malloc(15 * 512);
- if (!d->boot2)
- return -1;
- memcpy(d->boot2, b2, 15 * 512);
-#elif defined(__alpha__)
- if (d->boot1)
- free(d->boot1);
- d->boot1 = malloc(15 * 512);
- if (!d->boot1)
- return -1;
- memcpy(d->boot1, b1, 15 * 512);
-#elif defined(__sparc64__)
- if (d->boot1 != NULL)
- free(d->boot1);
- d->boot1 = malloc(16 * 512);
- if (d->boot1 == NULL)
- return (-1);
- memcpy(d->boot1, b1, 16 * 512);
-#elif defined(__ia64__)
- /* nothing */
-#else
-/* Should be: #error "Set_Boot_Blocks: unknown arch"; */
-#endif
- return 0;
-}
-
-const char *
-slice_type_name( int type, int subtype )
-{
-
- switch (type) {
- case whole:
- return "whole";
- case mbr:
- switch (subtype) {
- case 1: return "fat (12-bit)";
- case 2: return "XENIX /";
- case 3: return "XENIX /usr";
- case 4: return "fat (16-bit,<=32Mb)";
- case 5: return "extended DOS";
- case 6: return "fat (16-bit,>32Mb)";
- case 7: return "NTFS/HPFS/QNX";
- case 8: return "AIX bootable";
- case 9: return "AIX data";
- case 10: return "OS/2 bootmgr";
- case 11: return "fat (32-bit)";
- case 12: return "fat (32-bit,LBA)";
- case 14: return "fat (16-bit,>32Mb,LBA)";
- case 15: return "extended DOS, LBA";
- case 18: return "Compaq Diagnostic";
- case 57: return "Plan 9";
- case 77: return "QNX 4.X";
- case 78: return "QNX 4.X 2nd part";
- case 79: return "QNX 4.X 3rd part";
- case 84: return "OnTrack diskmgr";
- case 100: return "Netware 2.x";
- case 101: return "Netware 3.x";
- case 115: return "SCO UnixWare";
- case 128: return "Minix 1.1";
- case 129: return "Minix 1.5";
- case 130: return "linux_swap";
- case 131: return "ext2fs";
- case 133: return "linux extended";
- case 166: return "OpenBSD FFS"; /* 0xA6 */
- case 168: return "Mac OS-X";
- case 169: return "NetBSD FFS"; /* 0xA9 */
- case 171: return "Mac OS-X Boot";
- case 182: return "OpenBSD"; /* dedicated */
- case 183: return "bsd/os";
- case 184: return "bsd/os swap";
- case 191: return "Solaris (new)";
- case 238: return "EFI GPT";
- case 239: return "EFI Sys. Part.";
- default: return "unknown";
- }
- case fat:
- return "fat";
- case freebsd:
- switch (subtype) {
-#ifdef PC98
- case 0xc494: return "freebsd";
-#else
- case 165: return "freebsd";
-#endif
- default: return "unknown";
- }
- case extended:
- return "extended";
- case part:
- return "part";
- case efi:
- return "efi";
- case unused:
- return "unused";
- default:
- return "unknown";
- }
-}
diff --git a/lib/libdisk/libdisk.3 b/lib/libdisk/libdisk.3
deleted file mode 100644
index 1b436e24c514..000000000000
--- a/lib/libdisk/libdisk.3
+++ /dev/null
@@ -1,341 +0,0 @@
-.\"
-.\" Copyright (c) 1996 Joerg Wunsch
-.\"
-.\" All rights reserved.
-.\"
-.\" This program is free software.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
-.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
-.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-.\"
-.\" $FreeBSD$
-.\" "
-.Dd January 30, 2006
-.Dt LIBDISK 3
-.Os
-.Sh NAME
-.Nm Open_Disk ,
-.Nm Free_Disk ,
-.Nm Debug_Disk ,
-.Nm Set_Bios_Geom ,
-.Nm Delete_Chunk ,
-.Nm Collapse_Disk ,
-.Nm Collapse_Chunk ,
-.Nm Create_Chunk ,
-.Nm All_FreeBSD ,
-.Nm CheckRules ,
-.Nm Disk_Names ,
-.Nm Set_Boot_Mgr ,
-.Nm Set_Boot_Blocks ,
-.Nm Write_Disk ,
-.Nm Cyl_Aligned ,
-.Nm Next_Cyl_Aligned ,
-.Nm Prev_Cyl_Aligned ,
-.Nm Track_Aligned ,
-.Nm Next_Track_Aligned ,
-.Nm Prev_Track_Aligned ,
-.Nm Create_Chunk_DWIM ,
-.Nm MakeDev ,
-.Nm MakeDevDisk ,
-.Nm ShowChunkFlags ,
-.Nm chunk_name ,
-.Nm slice_type_name
-.Nd library interface to slice and partition labels
-.Sh LIBRARY
-.Lb libdisk
-.Sh SYNOPSIS
-.In sys/types.h
-.In libdisk.h
-.Pp
-.Ft struct disk *
-.Fn Open_Disk "const char *devname"
-.Ft void
-.Fn Free_Disk "struct disk *disk"
-.Ft void
-.Fn Debug_Disk "struct disk *disk"
-.Ft void
-.Fn Set_Bios_Geom "struct disk *disk" "u_long cyl" "u_long heads" "u_long sects"
-.Ft int
-.Fn Delete_Chunk "struct disk *disk" "struct chunk *"
-.Ft void
-.Fn Collapse_Disk "struct disk *disk"
-.Ft int
-.Fn Collapse_Chunk "struct disk *disk" "struct chunk *chunk"
-.Ft int
-.Fn Create_Chunk "struct disk *disk" "daddr_t offset" "daddr_t size" "chunk_e type" "int subtype" "u_long flags" "const char *sname"
-.Ft void
-.Fn All_FreeBSD "struct disk *d" "int force_all"
-.Ft char *
-.Fn CheckRules "const struct disk *"
-.Ft char **
-.Fn Disk_Names "void"
-.Ft void
-.Fn Set_Boot_Mgr "struct disk *d" "const u_char *bootmgr" "const size_t bootmgr_size"
-.Ft int
-.Fn Set_Boot_Blocks "struct disk *d" "const u_char *boot1" "const u_char *boot2"
-.Ft int
-.Fn Write_Disk "const struct disk *d"
-.Ft int
-.Fn Cyl_Aligned "struct disk *d" "daddr_t offset"
-.Ft daddr_t
-.Fn Next_Cyl_Aligned "const struct disk *d" "daddr_t offset"
-.Ft daddr_t
-.Fn Prev_Cyl_Aligned "const struct disk *d" "daddr_t offset"
-.Ft int
-.Fn Track_Aligned "const struct disk *d" "daddr_t offset"
-.Ft daddr_t
-.Fn Next_Track_Aligned "const struct disk *d" "daddr_t offset"
-.Ft daddr_t
-.Fn Prev_Track_Aligned "const struct disk *d" "daddr_t offset"
-.Ft struct chunk *
-.Fn Create_Chunk_DWIM "struct disk *d" "struct chunk *parent" "daddr_t size" "chunk_e type" "int subtype" "u_long flags"
-.Ft int
-.Fn MakeDev "struct chunk *c" "const char *path"
-.Ft int
-.Fn MakeDevDisk "struct disk *d" "const char *path"
-.Ft char *
-.Fn ShowChunkFlags "struct chunk *c"
-.Ft const char *
-.Fn chunk_name "chunk_e type"
-.Ft const char *
-.Fn slice_type_name "int type" "int subtype"
-.Sh DESCRIPTION
-.Bf Sy
-.Nm libdisk
-is just for the use of
-.Xr sysinstall 8 .
-You should consider using
-.Xr libgeom 3
-instead.
-.Ef
-.Pp
-The
-.Nm libdisk
-library provides an interface to the low-level disk slice and partition labels.
-Most functions operate with arguments of the types
-.Ql struct disk ,
-or
-.Ql struct chunk .
-.Pp
-While both types are mostly opaque to the programmer, the internal
-structure is mentioned below for the sake of completeness.
-.Bd -literal -offset indent
-struct disk {
- char *name;
- u_long flags;
- u_long bios_cyl;
- u_long bios_hd;
- u_long bios_sect;
- u_char *bootmgr;
- u_char *boot1;
- u_char *boot2;
- struct chunk *chunks;
- u_long sector_size;
-};
-.Ed
-The only flag value by now is
-.Ql DISK_ON_TRACK ,
-meaning that this disk is handled by the On-Track Disk Manager.
-.Bd -literal -offset indent
-struct chunk {
- struct chunk *next;
- struct chunk *part;
- struct disk *disk;
- daddr_t offset;
- daddr_t size;
- daddr_t end;
- char *name;
- char *oname;
- chunk_e type;
- int subtype;
- u_long flags;
- void (*private_free)(void*);
- void *(*private_clone)(void*);
- void *private_data;
-};
-.Ed
-The
-.Ql type
-field can be one of the following values:
-.Ql whole, unknown, fat, freebsd, extended, part, unused .
-.Pp
-These are the valid
-.Ql flags
-values for a
-.Ql struct chunk .
-.Bl -tag -offset indent -width CHUNK_AUTO_SIZEXX
-.It CHUNK_ALIGN
-This chunk should be aligned.
-.It CHUNK_IS_ROOT
-This
-.Ql part
-is a rootfs, allocate partition
-.Sq a .
-.It CHUNK_ACTIVE
-This is the active slice in the MBR.
-.It CHUNK_FORCE_ALL
-Force a dedicated disk for
-.Fx ,
-bypassing all BIOS geometry considerations.
-.It CHUNK_AUTO_SIZE
-This chunk was auto-sized and can fill out any deleted following chunks.
-.It CHUNK_NEWFS
-newfs pending, used to enable auto-resizing on delete (along with AUTO_SIZE).
-.El
-.Pp
-The
-.Ql private_data ,
-.Ql private_free ,
-and
-.Ql private_clone
-fields are for data private to the application, and the management
-thereof.
-If the functions are not provided, no storage management is
-done, cloning will just copy the pointer and freeing will just forget
-it.
-.Pp
-.Fn Open_Disk
-will open the named disk, and return populated tree.
-.Pp
-.Fn Free_Disk
-frees a tree made with
-.Fn Open_Disk
-or
-.Fn Clone_Disk .
-.Pp
-.Fn Debug_Disk
-prints the content of the tree to
-.Dv stdout .
-.Pp
-.Fn Set_Bios_Geom
-sets the geometry the bios uses.
-.Pp
-.Fn Delete_Chunk
-frees a chunk of disk_space.
-.Pp
-.Fn Collapse_Disk
-and
-.Fn Collapse_Chunk
-are experimental, do not use.
-.Pp
-.Fn Create_Chunk
-creates a chunk with the specified parameters.
-.Pp
-.Fn All_FreeBSD
-makes one
-.Fx
-chunk covering the entire disk; if
-.Ql force_all
-is set, bypass all BIOS geometry considerations.
-.Pp
-.Fn CheckRules
-returns
-.Ql char*
-to warnings about broken design rules in this disklayout.
-.Pp
-.Fn Disk_Names
-returns
-.Ql char**
-with all disk's names (wd0, wd1 ...).
-You must free each pointer, as
-well as the array by hand.
-.Pp
-.Fn Set_Boot_Mgr
-sets this boot-manager for use on this disk.
-Gets written when
-.Fn Write_Disk
-is called.
-.Pp
-.Fn Set_Boot_Blocks
-sets the boot-blocks for use on this disk.
-Gets written when
-.Fn Write_Disk
-is called.
-.Pp
-.Fn Write_Disk
-writes all the MBRs, disklabels, bootblocks and boot managers.
-.Pp
-.Fn Cyl_Aligned
-checks if
-.Ql offset
-is aligned on a cylinder according to the BIOS geometry.
-.Pp
-.Fn Next_Cyl_Aligned
-rounds
-.Ql offset
-up to next cylinder according to the BIOS geometry.
-.Pp
-.Fn Prev_Cyl_Aligned
-rounds
-.Ql offset
-down to previous cylinder according to the BIOS geometry.
-.Pp
-.Fn Track_Aligned
-checks if
-.Ql offset
-is aligned on a track according to the BIOS geometry.
-.Pp
-.Fn Next_Track_Aligned
-rounds
-.Ql offset
-up to next track according to the BIOS geometry.
-.Pp
-.Fn Prev_Track_Aligned
-rounds
-.Ql offset
-up to previous track according to the BIOS geometry.
-.Pp
-.Fn Create_Chunk_DWIM
-creates a partition inside the given parent of the given size, and
-returns a pointer to it.
-The first unused chunk big enough is used.
-.Pp
-.Fn MakeDev
-makes the device nodes for this chunk.
-.Pp
-.Fn MakeDevDisk
-makes the device nodes for all chunks on this disk.
-.Pp
-.Fn ShowChunkFlags
-returns a string to show flags.
-.Pp
-The
-.Fn chunk_name
-function takes the enumerated chunk type and returns its name.
-.Fn chunk_name
-replaces the old external array
-.Va chunk_n .
-.Pp
-.Fn slice_type_name
-returns the name strings associated with the specified
-.Ql type .
-.Ql subtype .
-If
-.Fn slice_type_name
-returns "unknown" for slices it is not familiar with.
-.Sh AUTHORS
-.An -nosplit
-The
-.Nm libdisk
-library was written by
-.An Poul-Henning Kamp .
-.Pp
-This manual page was written by
-.An J\(:org Wunsch .
diff --git a/lib/libdisk/libdisk.h b/lib/libdisk/libdisk.h
deleted file mode 100644
index a302c645b4d1..000000000000
--- a/lib/libdisk/libdisk.h
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
-* ----------------------------------------------------------------------------
-* "THE BEER-WARE LICENSE" (Revision 42):
-* <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
-* can do whatever you want with this stuff. If we meet some day, and you think
-* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
-* ----------------------------------------------------------------------------
-*
-* $FreeBSD$
-*
-*/
-
-#ifndef _LIBDISK_H_
-#define _LIBDISK_H_
-
-/* #define DEBUG 1 */
-/* You can define a particular architecture here if you are debugging. */
-/* #define P_DEBUG p_sparc64 */
-
-#define MAX_NO_DISKS 32
-/* Max # of disks Disk_Names() will return */
-
-#define MAX_SEC_SIZE 2048 /* maximum sector size that is supported */
-#define MIN_SEC_SIZE 512 /* the sector size to end sensing at */
-
-enum platform {
- p_any, /* for debugging ! */
- p_alpha,
- p_i386,
- p_pc98,
- p_sparc64,
- p_ia64,
- p_ppc,
- p_amd64,
- p_arm,
- p_mips
-};
-extern const enum platform platform;
-
-typedef enum {
- whole,
- unknown,
-
- sun,
- pc98,
- mbr,
- gpt,
-
- efi,
- fat,
- freebsd,
- extended,
- part,
- spare,
- unused,
-
- apple
-} chunk_e;
-
-__BEGIN_DECLS
-#ifndef __ia64__
-struct disk {
- char *name;
- u_long bios_cyl;
- u_long bios_hd;
- u_long bios_sect;
-#ifdef PC98
- u_char *bootipl;
- size_t bootipl_size;
- u_char *bootmenu;
- size_t bootmenu_size;
-#else
- u_char *bootmgr;
- size_t bootmgr_size;
-#endif
- u_char *boot1;
-#if defined(__i386__) || defined(__amd64__) /* the i386 needs extra help... */
- u_char *boot2;
-#endif
- struct chunk *chunks;
- u_long sector_size; /* media sector size, a power of 2 */
-};
-#else /* !__ia64__ */
-struct disk {
- char *name;
- struct chunk *chunks;
- u_long media_size;
- u_long sector_size;
- u_long lba_start;
- u_long lba_end;
- u_int gpt_size; /* Number of entries */
-};
-#endif
-
-struct chunk {
- struct chunk *next;
- struct chunk *part;
- struct disk *disk;
- daddr_t offset;
- daddr_t size;
- daddr_t end;
- char *sname; /* PC98 field */
- char *name;
- char *oname;
- /* Used during Fixup_Names() to avoid renaming more than
- * absolutely needed.
- */
- chunk_e type;
- int subtype;
- u_long flags;
- void (*private_free)(void*);
- void *(*private_clone)(void*);
- void *private_data;
- /* For data private to the application, and the management
- * thereof. If the functions are not provided, no storage
- * management is done, Cloning will just copy the pointer
- * and freeing will just forget it.
- */
-};
-
-/*
- * flags:
- *
- * ALIGN - This chunk should be aligned
- * IS_ROOT - This 'part' is a rootfs, allocate 'a'
- * ACTIVE - This is the active slice in the MBR
- * FORCE_ALL - Force a dedicated disk for FreeBSD, bypassing
- * all BIOS geometry considerations
- * AUTO_SIZE - This chunk was auto-sized and can fill-out a
- * following chunk if the following chunk is deleted.
- * NEWFS - newfs pending, used to enable auto-resizing on
- * delete (along with AUTO_SIZE).
- */
-
-#define CHUNK_ALIGN 0x0008
-#define CHUNK_IS_ROOT 0x0010
-#define CHUNK_ACTIVE 0x0020
-#define CHUNK_FORCE_ALL 0x0040
-#define CHUNK_AUTO_SIZE 0x0080
-#define CHUNK_NEWFS 0x0100
-#define CHUNK_HAS_INDEX 0x0200
-#define CHUNK_ITOF(i) ((i & 0xFFFF) << 16)
-#define CHUNK_FTOI(f) ((f >> 16) & 0xFFFF)
-
-#define DELCHUNK_NORMAL 0x0000
-#define DELCHUNK_RECOVER 0x0001
-
-const char *chunk_name(chunk_e);
-
-const char *
-slice_type_name(int, int);
-/* "chunk_n" for subtypes too */
-
-struct disk *
-Open_Disk(const char *);
-/* Will open the named disk, and return populated tree. */
-
-void
-Free_Disk(struct disk *);
-/* Free a tree made with Open_Disk() or Clone_Disk() */
-
-void
-Debug_Disk(struct disk *);
-/* Print the content of the tree to stdout */
-
-void
-Set_Bios_Geom(struct disk *, u_long, u_long, u_long);
-/* Set the geometry the bios uses. */
-
-void
-Sanitize_Bios_Geom(struct disk *);
-/* Set the bios geometry to something sane */
-
-int
-Insert_Chunk(struct chunk *, daddr_t, daddr_t, const char *, chunk_e, int,
- u_long, const char *);
-
-int
-Delete_Chunk2(struct disk *, struct chunk *, int);
-/* Free a chunk of disk_space modified by the passed flags. */
-
-int
-Delete_Chunk(struct disk *, struct chunk *);
-/* Free a chunk of disk_space */
-
-void
-Collapse_Disk(struct disk *);
-/* Experimental, do not use. */
-
-int
-Collapse_Chunk(struct disk *, struct chunk *);
-/* Experimental, do not use. */
-
-int
-Create_Chunk(struct disk *, daddr_t, daddr_t, chunk_e, int, u_long, const char *);
-/* Create a chunk with the specified paramters */
-
-void
-All_FreeBSD(struct disk *, int);
-/*
- * Make one FreeBSD chunk covering the entire disk;
- * if force_all is set, bypass all BIOS geometry
- * considerations.
- */
-
-char *
-CheckRules(const struct disk *);
-/* Return char* to warnings about broken design rules in this disklayout */
-
-char **
-Disk_Names(void);
-/*
- * Return char** with all disk's names (wd0, wd1 ...). You must free
- * each pointer, as well as the array by hand
- */
-
-#ifdef PC98
-void
-Set_Boot_Mgr(struct disk *, const u_char *, const size_t, const u_char *,
- const size_t);
-#else
-void
-Set_Boot_Mgr(struct disk *, const u_char *, const size_t);
-#endif
-/*
- * Use this boot-manager on this disk. Gets written when Write_Disk()
- * is called
- */
-
-int
-Set_Boot_Blocks(struct disk *, const u_char *, const u_char *);
-/*
- * Use these boot-blocks on this disk. Gets written when Write_Disk()
- * is called. Returns nonzero upon failure.
- */
-
-int
-Write_Disk(const struct disk *);
-/* Write all the MBRs, disklabels, bootblocks and boot managers */
-
-daddr_t
-Next_Cyl_Aligned(const struct disk *, daddr_t);
-/* Round offset up to next cylinder according to the bios-geometry */
-
-daddr_t
-Prev_Cyl_Aligned(const struct disk *, daddr_t);
-/* Round offset down to previous cylinder according to the bios-geometry */
-
-int
-Track_Aligned(const struct disk *, daddr_t);
-/* Check if offset is aligned on a track according to the bios geometry */
-
-daddr_t
-Next_Track_Aligned(const struct disk *, daddr_t);
-/* Round offset up to next track according to the bios-geometry */
-
-daddr_t
-Prev_Track_Aligned(const struct disk *, daddr_t);
-/* Check if offset is aligned on a track according to the bios geometry */
-
-struct chunk *
-Create_Chunk_DWIM(struct disk *, struct chunk *, daddr_t, chunk_e, int,
- u_long);
-/*
- * This one creates a partition inside the given parent of the given
- * size, and returns a pointer to it. The first unused chunk big
- * enough is used.
- */
-
-char *
-ShowChunkFlags(struct chunk *);
-/* Return string to show flags. */
-
-/*
- * Implementation details >>> DO NOT USE <<<
- */
-
-struct disklabel;
-
-void Fill_Disklabel(struct disklabel *, const struct disk *,
- const struct chunk *);
-void Debug_Chunk(struct chunk *);
-struct chunk *New_Chunk(void);
-void Free_Chunk(struct chunk *);
-struct chunk *Clone_Chunk(const struct chunk *);
-int Add_Chunk(struct disk *, daddr_t, daddr_t, const char *, chunk_e, int,
- u_long, const char *);
-void *read_block(int, daddr_t, u_long);
-int write_block(int, daddr_t, const void *, u_long);
-struct disklabel *read_disklabel(int, daddr_t, u_long);
-struct disk *Int_Open_Disk(const char *, char *);
-int Fixup_Names(struct disk *);
-int MakeDevChunk(const struct chunk *, const char *);
-__END_DECLS
-
-/* TODO
- *
- * Need an error string mechanism from the functions instead of warn()
- *
- * Make sure only FreeBSD start at offset==0
- *
- * Collapse must align.
- *
- * Make Write_Disk(struct disk*)
- *
- * Consider booting from OnTrack'ed disks.
- *
- * Get Bios-geom, ST506 & OnTrack from driver (or otherwise)
- *
- * Make Create_DWIM().
- *
- * Make Is_Unchanged(struct disk *d1, struct chunk *c1)
- *
- * don't rename slices unless we have to
- *
- *Sample output from tst01:
- *
- * Debug_Disk(wd0) flags=0 bios_geom=0/0/0
- * >> 0x3d040 0 1411200 1411199 wd0 0 whole 0 0
- * >>>> 0x3d080 0 960120 960119 wd0s1 3 freebsd 0 8
- * >>>>>> 0x3d100 0 40960 40959 wd0s1a 5 part 0 0
- * >>>>>> 0x3d180 40960 131072 172031 wd0s1b 5 part 0 0
- * >>>>>> 0x3d1c0 172032 409600 581631 wd0s1e 5 part 0 0
- * >>>>>> 0x3d200 581632 378488 960119 wd0s1f 5 part 0 0
- * >>>> 0x3d140 960120 5670 965789 wd0s2 4 extended 0 8
- * >>>>>> 0x3d2c0 960120 63 960182 - 6 unused 0 0
- * >>>>>> 0x3d0c0 960183 5607 965789 wd0s5 2 fat 0 8
- * >>>> 0x3d280 965790 1890 967679 wd0s3 1 foo -2 8
- * >>>> 0x3d300 967680 443520 1411199 wd0s4 3 freebsd 0 8
- * >>>>>> 0x3d340 967680 443520 1411199 wd0s4a 5 part 0 0
- *
- * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
- * level chunkptr start size end name type subtype flags
- *
- * Underlying data structure:
- *
- * Legend:
- * <struct chunk> --> part
- * |
- * v next
- *
- * <wd0> --> <wd0s1> --> <wd0s1a>
- * | |
- * | v
- * | <wd0s1b>
- * | |
- * | v
- * | <wd0s1e>
- * | |
- * | v
- * | <wd0s1f>
- * |
- * v
- * <wd0s2> --> <unused>
- * | |
- * | v
- * | <wd0s5>
- * |
- * v
- * <wd0s3>
- * |
- * v
- * <wd0s4> --> <wd0s4a>
- *
- *
- */
-
-#endif /* _LIBDISK_H_ */
diff --git a/lib/libdisk/open_disk.c b/lib/libdisk/open_disk.c
deleted file mode 100644
index 6cc9acb04692..000000000000
--- a/lib/libdisk/open_disk.c
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <inttypes.h>
-#include <err.h>
-#include <sys/sysctl.h>
-#include <sys/stdint.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/disklabel.h>
-#include <sys/gpt.h>
-#include <paths.h>
-#include "libdisk.h"
-
-#include <ctype.h>
-#include <errno.h>
-#include <assert.h>
-
-#ifdef DEBUG
-#define DPRINT(x) warn x
-#define DPRINTX(x) warnx x
-#else
-#define DPRINT(x)
-#define DPRINTX(x)
-#endif
-
-struct disk *
-Int_Open_Disk(const char *name, char *conftxt)
-{
- struct disk *d;
- int i, line = 1;
- char *p, *q, *r, *a, *b, *n, *t, *sn;
- daddr_t o, len, off;
- u_int l, s, ty, sc, hd, alt;
- daddr_t lo[10];
-
- /*
- * Locate the disk (by name) in our sysctl output
- */
- for (p = conftxt; p != NULL && *p; p = strchr(p, '\n'), line++) {
- if (*p == '\n')
- p++;
- a = strsep(&p, " ");
- /* Skip anything not with index 0 */
- if (strcmp(a, "0"))
- continue;
-
- /* Skip anything not a disk */
- a = strsep(&p, " ");
- if (strcmp(a, "DISK"))
- continue;
-
- a = strsep(&p, " ");
- if (strcmp(a, name))
- continue;
- break;
- }
-
- q = strchr(p, '\n');
- if (q != NULL)
- *q++ = '\0';
-
- d = (struct disk *)calloc(sizeof *d, 1);
- if(d == NULL)
- return NULL;
-
- d->name = strdup(name);
-
- a = strsep(&p, " "); /* length in bytes */
- len = strtoimax(a, &r, 0);
- if (*r) {
- printf("libdisk: Int_Open_Disk(%s): can't parse length in line %d (r='%s')\n",
- name, line, r);
- return NULL;
- }
-
- a = strsep(&p, " "); /* sectorsize */
- s = strtoul(a, &r, 0);
- if (*r) {
- printf("libdisk: Int_Open_Disk(%s): can't parse sector size in line %d (r='%s')\n",
- name, line, r);
- return NULL;
- }
-
- if (s == 0)
- return (NULL);
- d->sector_size = s;
- len /= s; /* media size in number of sectors. */
-
- if (Add_Chunk(d, 0, len, name, whole, 0, 0, "-")) {
- DPRINT(("Failed to add 'whole' chunk"));
- }
-
- /* Try to parse any fields after the sector size in the DISK entry line */
- for (;;) {
- a = strsep(&p, " ");
- if (a == NULL)
- break;
- b = strsep(&p, " ");
- o = strtoimax(b, &r, 0);
- if (*r) {
- printf("libdisk: Int_Open_Disk(%s): can't parse parameter '%s' in line %d (r='%s')\n",
- name, a, line, r);
- return NULL;
- }
- if (!strcmp(a, "hd"))
- d->bios_hd = o;
- else if (!strcmp(a, "sc"))
- d->bios_sect = o;
- else
- printf("libdisk: Int_Open_Disk(%s): unknown parameter '%s' with value '%s' in line %d, ignored\n",
- name, a, b, line);
- }
-
- /* Sanitize the parameters. */
- Sanitize_Bios_Geom(d);
-
- /*
- * Calculate the number of cylinders this disk must have. If we have
- * an obvious insanity, we set the number of cylinders to zero.
- */
- o = d->bios_hd * d->bios_sect;
- d->bios_cyl = (o != 0) ? len / o : 0;
-
- p = q; line++; /* p is now the start of the line _after_ the DISK entry */
- lo[0] = 0;
-
- for (; p != NULL && *p; p = q, line++) {
- sn = NULL;
- q = strchr(p, '\n');
- if (q != NULL)
- *q++ = '\0';
- a = strsep(&p, " "); /* Index */
- /*
- * If we find index 0 again, this means we've encountered another disk, so it's safe to assume this disk
- * has been processed.
- */
- if (!strcmp(a, "0"))
- break;
- l = strtoimax(a, &r, 0);
- if (*r) {
- printf("libdisk: Int_Open_Disk(%s): can't parse depth '%s' in line %d (r='%s')\n",
- name, a, line, r);
- return NULL;
-
- }
- t = strsep(&p, " "); /* Type {SUN, BSD, MBR, PC98, GPT} */
- n = strsep(&p, " "); /* name */
- a = strsep(&p, " "); /* len */
- len = strtoimax(a, &r, 0);
- if (*r) {
- printf("libdisk: Int_Open_Disk(%s): can't parse length '%s' in line %d (r='%s')\n",
- name, a, line, r);
- continue;
- }
- a = strsep(&p, " "); /* secsize */
- s = strtoimax(a, &r, 0);
- if (*r) {
- printf("libdisk: Int_Open_Disk(%s): can't parse sector size '%s' in line %d (r='%s')\n",
- name, a, line, r);
- continue;
- }
- for (;;) {
- a = strsep(&p, " ");
- if (a == NULL)
- break;
- /* XXX: Slice name may include a space. */
- if (!strcmp(a, "sn")) {
- sn = p;
- break;
- }
- b = strsep(&p, " ");
- o = strtoimax(b, &r, 0);
- /* APPLE have ty as a string */
- if ((*r) && strcmp(t, "APPLE") &&
- strcmp(t, "GPT") && strcmp(t, "PART")) {
- printf("libdisk: Int_Open_Disk(%s): can't parse parameter '%s' in line %d (r='%s')\n",
- name, a, line, r);
- break;
- }
- if (!strcmp(a, "o"))
- off = o;
- else if (!strcmp(a, "i"))
- i = (!strcmp(t, "PART")) ? o - 1 : o;
- else if (!strcmp(a, "ty"))
- ty = o;
- else if (!strcmp(a, "sc"))
- sc = o;
- else if (!strcmp(a, "hd"))
- hd = o;
- else if (!strcmp(a, "alt"))
- alt = o;
- else if (!strcmp(a, "xs"))
- t = b;
- else if (!strcmp(a, "xt")) {
- if (*r)
- sn = b;
- else
- ty = o;
- }
- }
-
- /* PLATFORM POLICY BEGIN ----------------------------------- */
- if (platform == p_sparc64 && !strcmp(t, "SUN") && i == 2)
- continue;
- if (platform == p_sparc64 && !strcmp(t, "SUN") &&
- d->chunks->part->part == NULL) {
- d->bios_hd = hd;
- d->bios_sect = sc;
- o = d->chunks->size / (hd * sc);
- o *= (hd * sc);
- o -= alt * hd * sc;
- if (Add_Chunk(d, 0, o, name, freebsd, 0, 0, "-")) {
- DPRINT(("Failed to add 'freebsd' chunk"));
- }
- }
- if (platform == p_alpha && !strcmp(t, "BSD") &&
- d->chunks->part->part == NULL) {
- if (Add_Chunk(d, 0, d->chunks->size, name, freebsd,
- 0, 0, "-")) {
- DPRINT(("Failed to add 'freebsd' chunk"));
- }
- }
- if (!strcmp(t, "BSD") && i == RAW_PART)
- continue;
- /* PLATFORM POLICY END ------------------------------------- */
-
- off /= s;
- len /= s;
- off += lo[l - 1];
- lo[l] = off;
- if (!strcmp(t, "SUN"))
- i = Add_Chunk(d, off, len, n, part, 0, 0, 0);
- else if (!strncmp(t, "MBR", 3)) {
- switch (ty) {
- case 0xa5:
- i = Add_Chunk(d, off, len, n, freebsd, ty, 0, 0);
- break;
- case 0x01:
- case 0x04:
- case 0x06:
- case 0x0b:
- case 0x0c:
- case 0x0e:
- i = Add_Chunk(d, off, len, n, fat, ty, 0, 0);
- break;
- case 0xef: /* EFI */
- i = Add_Chunk(d, off, len, n, efi, ty, 0, 0);
- break;
- default:
- i = Add_Chunk(d, off, len, n, mbr, ty, 0, 0);
- break;
- }
- } else if (!strcmp(t, "BSD"))
- i = Add_Chunk(d, off, len, n, part, ty, 0, 0);
- else if (!strcmp(t, "PC98")) {
- switch (ty & 0x7f) {
- case 0x14:
- i = Add_Chunk(d, off, len, n, freebsd, ty, 0,
- sn);
- break;
- case 0x20:
- case 0x21:
- case 0x22:
- case 0x23:
- case 0x24:
- i = Add_Chunk(d, off, len, n, fat, ty, 0, sn);
- break;
- default:
- i = Add_Chunk(d, off, len, n, pc98, ty, 0, sn);
- break;
- }
- } else if (!strcmp(t, "GPT"))
- i = Add_Chunk(d, off, len, n, gpt, 0, 0, b);
- else if (!strcmp(t, "APPLE"))
- i = Add_Chunk(d, off, len, n, apple, 0, 0, sn);
- else
- ; /* Ignore unknown classes. */
- }
- /* PLATFORM POLICY BEGIN ------------------------------------- */
- /* We have a chance to do things on a blank disk here */
- if (platform == p_sparc64 && d->chunks->part->part == NULL) {
- hd = d->bios_hd;
- sc = d->bios_sect;
- o = d->chunks->size / (hd * sc);
- o *= (hd * sc);
- o -= 2 * hd * sc;
- if (Add_Chunk(d, 0, o, name, freebsd, 0, 0, "-")) {
- DPRINT(("Failed to add 'freebsd' chunk"));
- }
- }
- /* PLATFORM POLICY END --------------------------------------- */
-
- return (d);
- i = 0;
-}
diff --git a/lib/libdisk/open_ia64_disk.c b/lib/libdisk/open_ia64_disk.c
deleted file mode 100644
index 287757d8226d..000000000000
--- a/lib/libdisk/open_ia64_disk.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright (c) 2003 Marcel Moolenaar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/disklabel.h>
-#include <sys/diskmbr.h>
-#include <sys/gpt.h>
-#include <sys/uuid.h>
-
-#include <fcntl.h>
-#include <inttypes.h>
-#include <paths.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "libdisk.h"
-
-static struct disk *
-parse_disk(char *conftxt, const char *name)
-{
- char devname[64];
- struct disk *disk;
- struct dos_partition *part;
- struct gpt_hdr *gpt;
- char *buffer, *p, *q;
- int fd, i;
-
- disk = (struct disk *)calloc(sizeof *disk, 1);
- if (disk == NULL)
- return (NULL);
-
- disk->name = strdup(name);
- p = strsep(&conftxt, " "); /* media size */
- disk->media_size = strtoimax(p, &q, 0);
- if (*q)
- goto fail;
-
- p = strsep(&conftxt, " "); /* sector size */
- disk->sector_size = strtoul(p, &q, 0);
- if (*q)
- goto fail;
-
- if (disk->sector_size == 0)
- disk->sector_size = 512;
-
- if (disk->media_size % disk->sector_size)
- goto fail;
-
- /*
- * We need to read the disk to get GPT specific information.
- */
-
- snprintf(devname, sizeof(devname), "%s%s", _PATH_DEV, name);
- fd = open(devname, O_RDONLY);
- if (fd == -1)
- goto fail;
- buffer = malloc(2 * disk->sector_size);
- if (buffer == NULL) {
- close (fd);
- goto fail;
- }
- if (read(fd, buffer, 2 * disk->sector_size) == -1) {
- free(buffer);
- close(fd);
- goto fail;
- }
- close(fd);
-
- gpt = (struct gpt_hdr *)(buffer + disk->sector_size);
- if (memcmp(gpt->hdr_sig, GPT_HDR_SIG, sizeof(gpt->hdr_sig))) {
- /*
- * No GPT present. Check if the MBR is empty (if present)
- * or is a PMBR before declaring this disk as empty. If
- * the MBR isn't empty, bail out. Let's not risk nuking a
- * disk.
- */
- if (*(u_short *)(buffer + DOSMAGICOFFSET) == DOSMAGIC) {
- for (i = 0; i < 4; i++) {
- part = (struct dos_partition *)
- (buffer + DOSPARTOFF + i * DOSPARTSIZE);
- if (part->dp_typ != 0 &&
- part->dp_typ != DOSPTYP_PMBR)
- break;
- }
- if (i < 4) {
- free(buffer);
- goto fail;
- }
- }
- disk->gpt_size = 128;
- disk->lba_start = (disk->gpt_size * sizeof(struct gpt_ent)) /
- disk->sector_size + 2;
- disk->lba_end = (disk->media_size / disk->sector_size) -
- disk->lba_start;
- } else {
- disk->lba_start = gpt->hdr_lba_start;
- disk->lba_end = gpt->hdr_lba_end;
- disk->gpt_size = gpt->hdr_entries;
- }
- free(buffer);
- Add_Chunk(disk, disk->lba_start, disk->lba_end - disk->lba_start + 1,
- name, whole, 0, 0, "-");
- return (disk);
-
-fail:
- free(disk->name);
- free(disk);
- return (NULL);
-}
-
-struct disk *
-Int_Open_Disk(const char *name, char *conftxt)
-{
- struct chunk chunk;
- struct disk *disk;
- char *p, *q, *r, *s, *sd;
- u_long i;
-
- p = conftxt;
- while (p != NULL && *p != 0) {
- q = strsep(&p, " ");
- if (strcmp(q, "0") == 0) {
- q = strsep(&p, " ");
- if (strcmp(q, "DISK") == 0) {
- q = strsep(&p, " ");
- if (strcmp(q, name) == 0)
- break;
- }
- }
- p = strchr(p, '\n');
- if (p != NULL && *p == '\n')
- p++;
- conftxt = p;
- }
- if (p == NULL || *p == 0)
- return (NULL);
-
- conftxt = strchr(p, '\n');
- if (conftxt != NULL)
- *conftxt++ = '\0';
-
- disk = parse_disk(p, name);
- if (disk == NULL)
- return (NULL);
-
- while (conftxt != NULL && *conftxt != 0) {
- p = conftxt;
- conftxt = strchr(p, '\n');
- if (conftxt != NULL)
- *conftxt++ = '\0';
-
- /*
- * 1 PART da0p4 34359738368 512
- * i 4 o 52063912960 ty freebsd-ufs
- * xs GPT xt 516e7cb6-6ecf-11d6-8ff8-00022d09712b
- */
- sd = strsep(&p, " "); /* depth */
- if (strcmp(sd, "0") == 0)
- break;
-
- q = strsep(&p, " "); /* type */
- if (strcmp(q, "PART") != 0)
- continue;
-
- chunk.name = strsep(&p, " "); /* name */
-
- q = strsep(&p, " "); /* length */
- i = strtoimax(q, &r, 0);
- if (*r)
- abort();
- chunk.end = i / disk->sector_size;
-
- q = strsep(&p, " "); /* sector size */
-
- for (;;) {
- q = strsep(&p, " ");
- if (q == NULL)
- break;
- r = strsep(&p, " ");
- i = strtoimax(r, &s, 0);
- if (strcmp(q, "ty") == 0 && *s != '\0') {
- if (!strcmp(r, "efi"))
- chunk.type = efi;
- else if (!strcmp(r, "freebsd")) {
- chunk.type = freebsd;
- chunk.subtype = 0xa5;
- } else if (!strcmp(r, "freebsd-swap")) {
- chunk.type = part;
- chunk.subtype = FS_SWAP;
- } else if (!strcmp(r, "freebsd-ufs")) {
- chunk.type = part;
- chunk.subtype = FS_BSDFFS;
- } else {
- chunk.type = part;
- chunk.subtype = FS_OTHER;
- }
- } else {
- if (!strcmp(q, "o"))
- chunk.offset = i / disk->sector_size;
- else if (!strcmp(q, "i"))
- chunk.flags = CHUNK_ITOF(i) |
- CHUNK_HAS_INDEX;
- }
- }
-
- Add_Chunk(disk, chunk.offset, chunk.end, chunk.name,
- chunk.type, chunk.subtype, chunk.flags, 0);
- }
-
- return (disk);
-}
diff --git a/lib/libdisk/rules.c b/lib/libdisk/rules.c
deleted file mode 100644
index 1f12f4c8a384..000000000000
--- a/lib/libdisk/rules.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/stdint.h>
-#include <sys/disklabel.h>
-#ifdef PC98
-#include <sys/diskpc98.h>
-#else
-#include <sys/diskmbr.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include "libdisk.h"
-
-int
-Track_Aligned(const struct disk *d, daddr_t offset)
-{
-#ifndef __ia64__
- if (!d->bios_sect)
- return 1;
- if (offset % d->bios_sect)
- return 0;
-#endif /* __ia64__ */
- return 1;
-}
-
-daddr_t
-Prev_Track_Aligned(const struct disk *d, daddr_t offset)
-{
-#ifndef __ia64__
- if (!d->bios_sect)
- return offset;
- return (offset / d->bios_sect) * d->bios_sect;
-#else
- return 1;
-#endif
-}
-
-daddr_t
-Next_Track_Aligned(const struct disk *d, daddr_t offset)
-{
-#ifndef __ia64__
- if (!d->bios_sect)
- return offset;
- return Prev_Track_Aligned(d, offset + d->bios_sect-1);
-#else
- return 1;
-#endif
-}
-
-static int
-Cyl_Aligned(const struct disk *d, daddr_t offset)
-{
-#ifndef __ia64__
- if (!d->bios_sect || !d->bios_hd)
- return 1;
- if (offset % (d->bios_sect * d->bios_hd))
- return 0;
-#endif
- return 1;
-}
-
-daddr_t
-Prev_Cyl_Aligned(const struct disk *d, daddr_t offset)
-{
-#ifndef __ia64__
- if (!d->bios_sect || !d->bios_hd)
- return offset;
- return (offset / (d->bios_sect * d->bios_hd)) * d->bios_sect *
- d->bios_hd;
-#else
- return 1;
-#endif
-}
-
-daddr_t
-Next_Cyl_Aligned(const struct disk *d, daddr_t offset)
-{
-#ifndef __ia64__
- if (!d->bios_sect || !d->bios_hd)
- return offset;
- return Prev_Cyl_Aligned(d,offset + (d->bios_sect * d->bios_hd) - 1);
-#else
- return 1;
-#endif
-}
-
-/*
- * Rule#0:
- * Chunks of type 'whole' can have max NDOSPART children.
- * Only one of them can have the "active" flag
- */
-static void
-Rule_000(__unused const struct disk *d, const struct chunk *c, char *msg)
-{
-#ifdef PC98
- int i = 0;
-#else
- int i = 0, j = 0;
-#endif
- struct chunk *c1;
-
- if (c->type != whole)
- return;
- for (c1 = c->part; c1; c1 = c1->next) {
- if (c1->type != unused)
- continue;
-#ifndef PC98
- if (c1->flags & CHUNK_ACTIVE)
- j++;
-#endif
- i++;
- }
- if (i > NDOSPART)
- sprintf(msg + strlen(msg),
- "%d is too many children of the 'whole' chunk."
- " Max is %d\n", i, NDOSPART);
-#ifndef PC98
- if (j > 1)
- sprintf(msg + strlen(msg),
- "Too many active children of 'whole'");
-#endif
-}
-
-/*
- * Rule#1:
- * All children of 'whole' and 'extended' must be track-aligned.
- * Exception: the end can be unaligned if it matches the end of 'whole'
- */
-static void
-Rule_001(const struct disk *d, const struct chunk *c, char *msg)
-{
- struct chunk *c1;
-
- if (c->type != whole && c->type != extended)
- return;
- for (c1 = c->part; c1; c1 = c1->next) {
- if (c1->type == unused)
- continue;
- c1->flags |= CHUNK_ALIGN;
-#ifdef PC98
- if (!Cyl_Aligned(d, c1->offset))
-#else
- if (!Track_Aligned(d, c1->offset))
-#endif
- sprintf(msg + strlen(msg),
-#ifdef PC98
- "chunk '%s' [%jd..%jd] does not start"
- " on a cylinder boundary\n",
-#else
- "chunk '%s' [%jd..%jd] does not start"
- " on a track boundary\n",
-#endif
- c1->name, (intmax_t)c1->offset, (intmax_t)c1->end);
- if ((c->type == whole || c->end == c1->end)
- || Cyl_Aligned(d, c1->end + 1))
- ;
- else
- sprintf(msg + strlen(msg),
- "chunk '%s' [%jd..%jd] does not end"
- " on a cylinder boundary\n",
- c1->name, (intmax_t)c1->offset, (intmax_t)c1->end);
- }
-}
-
-/*
- * Rule#2:
- * Max one 'fat' as child of 'whole'
- */
-static void
-Rule_002(__unused const struct disk *d, const struct chunk *c, char *msg)
-{
- int i;
- struct chunk *c1;
-
- if (c->type != whole)
- return;
- for (i = 0, c1 = c->part; c1; c1 = c1->next) {
- if (c1->type != fat)
- continue;
- i++;
- }
- if (i > 1) {
- sprintf(msg + strlen(msg),
- "Max one 'fat' allowed as child of 'whole'\n");
- }
-}
-
-/*
- * Rule#3:
- * Max one extended as child of 'whole'
- */
-static void
-Rule_003(__unused const struct disk *d, const struct chunk *c, char *msg)
-{
- int i;
- struct chunk *c1;
-
- if (c->type != whole)
- return;
- for (i = 0, c1 = c->part; c1; c1 = c1->next) {
- if (c1->type != extended)
- continue;
- i++;
- }
- if (i > 1) {
- sprintf(msg + strlen(msg),
- "Max one 'extended' allowed as child of 'whole'\n");
- }
-}
-
-/*
- * Rule#4:
- * Max seven 'part' as children of 'freebsd'
- * Max one CHUNK_IS_ROOT child per 'freebsd'
- */
-static void
-Rule_004(__unused const struct disk *d, const struct chunk *c, char *msg)
-{
- int i = 0, k = 0;
- struct chunk *c1;
-
- if (c->type != freebsd)
- return;
-
- for (c1 = c->part; c1; c1 = c1->next) {
- if (c1->type != part)
- continue;
- if (c1->flags & CHUNK_IS_ROOT)
- k++;
- i++;
- }
- if (i > 7) {
- sprintf(msg + strlen(msg),
- "Max seven partitions per freebsd slice\n");
- }
- if (k > 1) {
- sprintf(msg + strlen(msg),
- "Max one root partition child per freebsd slice\n");
- }
-}
-
-static void
-Check_Chunk(const struct disk *d, const struct chunk *c, char *msg)
-{
-
- switch (platform) {
- case p_i386:
- case p_amd64:
- Rule_000(d, c, msg);
- Rule_001(d, c, msg);
- Rule_002(d, c, msg);
- Rule_003(d, c, msg);
- Rule_004(d, c, msg);
- if (c->part)
- Check_Chunk(d, c->part, msg);
- if (c->next)
- Check_Chunk(d, c->next, msg);
- break;
- case p_pc98:
- Rule_000(d, c, msg);
- Rule_001(d, c, msg);
- Rule_004(d, c, msg);
- if (c->part)
- Check_Chunk(d, c->part, msg);
- if (c->next)
- Check_Chunk(d, c->next, msg);
- break;
- default:
- break;
- }
-}
-
-char *
-CheckRules(const struct disk *d)
-{
- char msg[BUFSIZ];
-
- *msg = '\0';
- Check_Chunk(d, d->chunks, msg);
- if (*msg)
- return strdup(msg);
- return 0;
-}
diff --git a/lib/libdisk/tst01.c b/lib/libdisk/tst01.c
deleted file mode 100644
index 7bb757959971..000000000000
--- a/lib/libdisk/tst01.c
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <err.h>
-#ifdef READLINE
-#include <readline/readline.h>
-#include <readline/history.h>
-#endif
-#include <sys/types.h>
-#include <paths.h>
-#include "libdisk.h"
-
-#ifndef PC98
-u_char mbrboot[] = {
-250,51,192,142,208,188,0,124,139,244,80,7,80,31,251,252,191,0,6,185,0,1,
-242,165,234,29,6,0,0,190,190,7,179,4,128,60,128,116,14,128,60,0,117,28,
-131,198,16,254,203,117,239,205,24,139,20,139,76,2,139,238,131,198,16,254,
-203,116,26,128,60,0,116,244,190,139,6,172,60,0,116,11,86,187,7,0,180,14,
-205,16,94,235,240,235,254,191,5,0,187,0,124,184,1,2,87,205,19,95,115,12,
-51,192,205,19,79,117,237,190,163,6,235,211,190,194,6,191,254,125,129,61,
-85,170,117,199,139,245,234,0,124,0,0,73,110,118,97,108,105,100,32,112,97,
-114,116,105,116,105,111,110,32,116,97,98,108,101,0,69,114,114,111,114,32,
-108,111,97,100,105,110,103,32,111,112,101,114,97,116,105,110,103,32,115,
-121,115,116,101,109,0,77,105,115,115,105,110,103,32,111,112,101,114,97,
-116,105,110,103,32,115,121,115,116,101,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,
-1,1,0,4,15,63,60,63,0,0,0,241,239,0,0,0,0,1,61,5,15,63,243,48,240,0,0,144,
-208,2,0,0,0,1,244,165,15,63,170,192,192,3,0,144,208,2,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,85,170
-};
-
-u_char bteasy17[] = {
-51,192,142,192,142,216,142,208,188,0,124,252,139,244,191,0,6,185,0,1,242,
-165,234,96,6,0,0,139,213,88,162,72,7,60,53,116,28,180,16,246,228,5,174,
-4,150,246,68,4,255,116,62,198,4,128,232,218,0,138,116,1,139,76,2,235,8,
-232,207,0,185,1,0,50,209,187,0,124,184,1,2,205,19,114,30,129,191,254,1,
-85,170,117,22,234,0,124,0,0,128,250,129,116,2,178,128,139,234,66,128,242,
-179,136,22,58,7,191,190,7,185,4,0,198,6,45,7,49,50,246,136,45,138,69,4,
-60,0,116,35,60,5,116,31,254,198,190,42,7,232,113,0,190,72,7,70,70,139,28,
-10,255,116,5,50,125,4,117,243,141,183,114,7,232,90,0,131,199,16,254,6,45,
-7,226,203,128,62,117,4,2,116,11,190,59,7,10,246,117,10,205,24,235,172,190,
-42,7,232,57,0,232,54,0,50,228,205,26,139,218,131,195,96,180,1,205,22,180,
-0,117,11,205,26,59,211,114,242,160,72,7,235,10,205,22,138,196,60,28,116,
-243,4,246,60,49,114,214,60,53,119,210,80,190,40,7,187,27,6,83,252,172,80,
-36,127,180,14,205,16,88,168,128,116,242,195,86,184,1,3,187,0,6,185,1,0,
-50,246,205,19,94,198,6,72,7,63,195,13,138,13,10,70,48,32,46,32,46,32,46,
-160,100,105,115,107,32,49,13,10,10,68,101,102,97,117,108,116,58,32,70,63,
-160,0,1,0,4,0,6,3,7,7,10,10,99,14,100,14,101,20,128,20,129,25,130,30,147,
-36,165,39,159,43,117,47,82,47,219,50,64,55,242,61,0,100,111,243,72,80,70,
-211,79,115,178,85,110,105,248,78,111,118,101,108,236,77,105,110,105,248,
-76,105,110,117,248,65,109,111,101,98,225,66,83,196,66,83,68,233,80,67,73,
-216,67,80,205,86,101,110,105,248,68,111,115,115,101,227,63,191,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-0,85,170
-};
-#endif
-
-int
-scan_block(int fd, daddr_t block)
-{
- u_char foo[512];
-
- if (-1 == lseek(fd, (off_t)block * 512, SEEK_SET))
- err(1, "lseek");
- if (512 != read(fd, foo, 512))
- return 1;
- return 0;
-}
-
-void
-Scan_Disk(struct disk *d)
-{
- char device[64];
- u_long l;
- int i, j, fd;
-
- strcpy(device, _PATH_DEV);
- strcat(device, d->name);
-
- fd = open(device, O_RDWR);
- if (fd < 0) {
- warn("open(%s) failed", device);
- return;
- }
- for (i = -1, l = 0; ; l++) {
- j = scan_block(fd, l);
- if (j != i) {
- if (i == -1) {
- printf("%c: %lu.",j ? 'B' : 'G', l);
- fflush(stdout);
- } else if (i == 0) {
- printf(".%lu\nB: %lu.", l - 1, l);
- fflush(stdout);
- } else {
- printf(".%lu\nG: %lu.", l - 1, l);
- fflush(stdout);
- }
- i = j;
- }
- }
- close(fd);
-}
-
-int
-main(int argc, char **argv)
-{
- struct disk *d,*db;
- char myprompt[BUFSIZ];
-#ifndef READLINE
- char input[BUFSIZ];
-#endif
- char *p,*q = 0;
- char **cp, *cmds[200];
- int ncmd, i;
-
- if (argc < 2) {
- fprintf(stderr, "Usage:\n\t%s diskname\n", argv[0]);
- exit(1);
- }
- d = Open_Disk(argv[1]);
- if (!d)
- err(1, "Couldn't open disk %s", argv[1]);
-
- sprintf(myprompt, "%s %s> ", argv[0], argv[1]);
- while (1) {
- printf("--==##==--\n");
- p = CheckRules(d);
- Debug_Disk(d);
- if (p) {
- printf("%s",p);
- free(p);
- }
-#ifdef READLINE
- if (q)
- free(q);
- q = p = readline(myprompt);
-#else
- printf("%s", myprompt);
- fflush(stdout);
- q = p = fgets(input, sizeof(input), stdin);
-#endif
- if(!p)
- break;
- for (cp = cmds; (*cp = strsep(&p, " \t\n")) != NULL;)
- if (**cp != '\0')
- cp++;
- ncmd = cp - cmds;
- if (!ncmd)
- continue;
- if (!strcasecmp(*cmds, "quit"))
- break;
- if (!strcasecmp(*cmds, "exit"))
- break;
- if (!strcasecmp(*cmds, "q"))
- break;
- if (!strcasecmp(*cmds, "x"))
- break;
- if (!strcasecmp(*cmds, "dwim") && ncmd == 6) {
- printf("dwim = %p\n",
- Create_Chunk_DWIM(d,
- (struct chunk *)strtol(cmds[1], 0, 0),
- strtol(cmds[2], 0, 0),
- strtol(cmds[3], 0, 0),
- strtol(cmds[4], 0, 0),
- strtol(cmds[5], 0, 0)));
- continue;
- }
- if (!strcasecmp(*cmds, "delete") && ncmd == 2) {
- printf("delete = %d\n",
- Delete_Chunk(d,
- (struct chunk *)strtol(cmds[1], 0, 0)));
- continue;
- }
-#ifndef __ia64__
- if (!strcasecmp(*cmds, "allfreebsd")) {
- All_FreeBSD(d, 0);
- continue;
- }
- if (!strcasecmp(*cmds, "dedicate")) {
- All_FreeBSD(d, 1);
- continue;
- }
- if (!strcasecmp(*cmds, "sanitize")) {
- Sanitize_Bios_Geom(d);
- continue;
- }
- if (!strcasecmp(*cmds, "bios") && ncmd == 4) {
- Set_Bios_Geom(d, strtol(cmds[1], 0, 0),
- strtol(cmds[2], 0, 0),
- strtol(cmds[3], 0, 0));
- continue;
- }
-#endif
- if (!strcasecmp(*cmds, "list")) {
- cp = Disk_Names();
- printf("Disks:");
- for (i = 0; cp[i]; i++) {
- printf(" %s", cp[i]);
- free(cp[i]);
- }
- free(cp);
- continue;
- }
-#ifdef PC98
- if (!strcasecmp(*cmds, "create") && ncmd == 7) {
-#else
- if (!strcasecmp(*cmds,"create") && ncmd == 6) {
-#endif
-
- printf("Create=%d\n",
- Create_Chunk(d,
- strtol(cmds[1], 0, 0),
- strtol(cmds[2], 0, 0),
- strtol(cmds[3], 0, 0),
- strtol(cmds[4], 0, 0),
-#ifdef PC98
- strtol(cmds[5], 0, 0), cmds[6]));
-#else
- strtol(cmds[5], 0, 0), NULL));
-#endif
- continue;
- }
- if (!strcasecmp(*cmds,"read")) {
- db = d;
- if (ncmd > 1)
- d = Open_Disk(cmds[1]);
- else
- d = Open_Disk(argv[1]);
- if (d)
- Free_Disk(db);
- else
- d = db;
- continue;
- }
- if (!strcasecmp(*cmds,"scan")) {
- Scan_Disk(d);
- continue;
- }
-#ifndef PC98
- if (!strcasecmp(*cmds,"bteasy")) {
- Set_Boot_Mgr(d, bteasy17, sizeof (bteasy17));
- continue;
- }
- if (!strcasecmp(*cmds, "mbr")) {
- Set_Boot_Mgr(d, mbrboot, sizeof (mbrboot));
- continue;
- }
-#endif
-#if 0 /* XXX boot1 undefined, fix me */
- if (!strcasecmp(*cmds, "boot")) {
- Set_Boot_Blocks(d, boot1, boot2);
- continue;
- }
-#endif
- if (!strcasecmp(*cmds, "write")) {
- printf("Write=%d\n",
- Write_Disk(d));
- Free_Disk(d);
- d = Open_Disk(argv[1]);
- continue;
- }
- if (strcasecmp(*cmds, "help"))
- printf("\007ERROR\n");
- printf("CMDS:\n");
- printf("\tallfreebsd\n");
- printf("\tdedicate\n");
- printf("\tbios cyl hd sect\n");
- printf("\tboot\n");
-#ifndef PC98
- printf("\tbteasy17\n");
-#endif
-#if 0
- printf("\tcollapse [pointer]\n");
-#endif
-#ifdef PC98
- printf("\tcreate offset size enum subtype flags name\n");
-#else
- printf("\tcreate offset size enum subtype flags\n");
-#endif
- printf("\t\tsubtype(part): swap=1, ffs=7\n");
- printf("\tdelete pointer\n");
- printf("\tlist\n");
-#ifndef PC98
- printf("\tmbr\n");
-#endif
-#if 0
- printf("\tphys cyl hd sect\n");
-#endif
- printf("\tquit\n");
- printf("\tread [disk]\n");
- printf("\tscan\n");
- printf("\twrite\n");
- printf("\nENUM:\n\t");
-#if 0
- for (i = 0; chunk_n[i]; i++)
- printf("%d = %s%s", i, chunk_n[i],
- i == 4 ? "\n\t" : " ");
-#endif
- printf("\n");
-
- }
- exit (0);
-}
diff --git a/lib/libdisk/write_amd64_disk.c b/lib/libdisk/write_amd64_disk.c
deleted file mode 100644
index 98992583fdff..000000000000
--- a/lib/libdisk/write_amd64_disk.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/disklabel.h>
-#include <sys/diskmbr.h>
-#include <paths.h>
-#include "libdisk.h"
-
-/*
- * XXX: A lot of hardcoded 512s probably should be foo->sector_size;
- * I'm not sure which, so I leave it like it worked before. --schweikh
- */
-static int
-Write_FreeBSD(int fd, const struct disk *new, const struct chunk *c1)
-{
- struct disklabel *dl;
- int i;
- void *p;
- u_char buf[BBSIZE];
-
- for (i = 0; i < BBSIZE/512; i++) {
- if (!(p = read_block(fd, i + c1->offset, 512)))
- return (1);
- memcpy(buf + 512 * i, p, 512);
- free(p);
- }
- if (new->boot1)
- memcpy(buf, new->boot1, 512);
-
- if (new->boot2)
- memcpy(buf + 512, new->boot2, BBSIZE - 512);
-
- dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
- Fill_Disklabel(dl, new, c1);
-
- for (i = 0; i < BBSIZE / 512; i++)
- write_block(fd, i + c1->offset, buf + 512 * i, 512);
-
- return 0;
-}
-
-static void
-Write_Int32(u_int32_t *p, u_int32_t v)
-{
- u_int8_t *bp = (u_int8_t *)p;
-
- bp[0] = (v >> 0) & 0xff;
- bp[1] = (v >> 8) & 0xff;
- bp[2] = (v >> 16) & 0xff;
- bp[3] = (v >> 24) & 0xff;
-}
-
-/*
- * Special install-time configuration for the i386 boot0 boot manager.
- */
-static void
-Cfg_Boot_Mgr(u_char *mbr, int edd)
-{
-
- if (mbr[0x1b0] == 0x66 && mbr[0x1b1] == 0xbb) {
- if (edd)
- mbr[0x1bb] |= 0x80; /* Packet mode on */
- else
- mbr[0x1bb] &= 0x7f; /* Packet mode off */
- }
-}
-
-int
-Write_Disk(const struct disk *d1)
-{
- int fd, j;
- uint i;
- struct chunk *c1;
- int ret = 0;
- char device[64];
- u_char *mbr;
- struct dos_partition *dp,work[NDOSPART];
- int s[4];
- int need_edd = 0; /* Need EDD (packet interface) */
-
- strcpy(device, _PATH_DEV);
- strcat(device, d1->name);
-
- fd = open(device, O_RDWR);
- if (fd < 0)
- return 1;
-
- memset(s, 0, sizeof s);
- if (!(mbr = read_block(fd, 0, d1->sector_size))) {
- close (fd);
- return (1);
- }
- dp = (struct dos_partition *)(mbr + DOSPARTOFF);
- memcpy(work, dp, sizeof work);
- dp = work;
- free(mbr);
- for (c1 = d1->chunks->part; c1; c1 = c1->next) {
- if (c1->type == unused)
- continue;
- if (!strcmp(c1->name, "X"))
- continue;
- j = c1->name[strlen(d1->name) + 1] - '1';
- if (j < 0 || j > 3)
- continue;
- s[j]++;
- if (c1->type == freebsd)
- ret += Write_FreeBSD(fd, d1, c1);
-
- Write_Int32(&dp[j].dp_start, c1->offset);
- Write_Int32(&dp[j].dp_size, c1->size);
-
- i = c1->offset;
- if (i >= 1024 * d1->bios_sect * d1->bios_hd) {
- dp[j].dp_ssect = 0xff;
- dp[j].dp_shd = 0xff;
- dp[j].dp_scyl = 0xff;
- need_edd++;
- } else {
- dp[j].dp_ssect = i % d1->bios_sect;
- i -= dp[j].dp_ssect++;
- i /= d1->bios_sect;
- dp[j].dp_shd = i % d1->bios_hd;
- i -= dp[j].dp_shd;
- i /= d1->bios_hd;
- dp[j].dp_scyl = i;
- i -= dp[j].dp_scyl;
- dp[j].dp_ssect |= i >> 2;
- }
-#ifdef DEBUG
- printf("S:%lu = (%x/%x/%x)", c1->offset,
- dp[j].dp_scyl, dp[j].dp_shd, dp[j].dp_ssect);
-#endif
-
- i = c1->end;
- dp[j].dp_esect = i % d1->bios_sect;
- i -= dp[j].dp_esect++;
- i /= d1->bios_sect;
- dp[j].dp_ehd = i % d1->bios_hd;
- i -= dp[j].dp_ehd;
- i /= d1->bios_hd;
- if (i > 1023)
- i = 1023;
- dp[j].dp_ecyl = i;
- i -= dp[j].dp_ecyl;
- dp[j].dp_esect |= i >> 2;
-#ifdef DEBUG
- printf(" E:%lu = (%x/%x/%x)\n", c1->end,
- dp[j].dp_ecyl, dp[j].dp_ehd, dp[j].dp_esect);
-#endif
-
- dp[j].dp_typ = c1->subtype;
- if (c1->flags & CHUNK_ACTIVE)
- dp[j].dp_flag = 0x80;
- else
- dp[j].dp_flag = 0;
- }
- j = 0;
- for (i = 0; i < NDOSPART; i++) {
- if (!s[i])
- memset(dp + i, 0, sizeof *dp);
- if (dp[i].dp_flag)
- j++;
- }
- if (!j)
- for(i = 0; i < NDOSPART; i++)
- if (dp[i].dp_typ == 0xa5)
- dp[i].dp_flag = 0x80;
-
- if (!(mbr = read_block(fd, 0, d1->sector_size))) {
- close (fd);
- return (1);
- }
- if (d1->bootmgr) {
- memcpy(mbr, d1->bootmgr, DOSPARTOFF);
- Cfg_Boot_Mgr(mbr, need_edd);
- }
- memcpy(mbr + DOSPARTOFF, dp, sizeof *dp * NDOSPART);
- mbr[512-2] = 0x55;
- mbr[512-1] = 0xaa;
- write_block(fd, 0, mbr, d1->sector_size);
- if (d1->bootmgr && d1->bootmgr_size > d1->sector_size)
- for (i = 1; i * d1->sector_size <= d1->bootmgr_size; i++)
- write_block(fd, i, &d1->bootmgr[i * d1->sector_size],
- d1->sector_size);
-
- close(fd);
- return 0;
-}
diff --git a/lib/libdisk/write_disk.c b/lib/libdisk/write_disk.c
deleted file mode 100644
index 024981beff23..000000000000
--- a/lib/libdisk/write_disk.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/disklabel.h>
-#include <paths.h>
-#include "libdisk.h"
-
-void
-Fill_Disklabel(struct disklabel *dl, const struct disk *new,
- const struct chunk *c1)
-{
- struct chunk *c2;
- int j;
-
- memset(dl, 0, sizeof *dl);
-
- for (c2 = c1->part; c2; c2 = c2->next) {
- if (c2->type == unused)
- continue;
- if (!strcmp(c2->name, "X"))
- continue;
- j = c2->name[strlen(c2->name) - 1] - 'a';
- if (j < 0 || j >= MAXPARTITIONS || j == RAW_PART)
- continue;
- dl->d_partitions[j].p_size = c2->size;
- dl->d_partitions[j].p_offset = c2->offset;
- dl->d_partitions[j].p_fstype = c2->subtype;
- }
-
- dl->d_bbsize = BBSIZE;
- /*
- * Add in defaults for superblock size, interleave, and rpms
- */
- dl->d_sbsize = 0;
-
- strcpy(dl->d_typename, c1->name);
-
- dl->d_secsize = 512;
- dl->d_secperunit = new->chunks->size;
-#ifndef __ia64__
- dl->d_ncylinders = new->bios_cyl;
- dl->d_ntracks = new->bios_hd;
- dl->d_nsectors = new->bios_sect;
-#endif
- dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors;
-
- dl->d_npartitions = MAXPARTITIONS;
-
- dl->d_type = new->name[0] == 's' || new->name[0] == 'd' ||
- new->name[0] == 'o' ? DTYPE_SCSI : DTYPE_ESDI;
- dl->d_partitions[RAW_PART].p_size = c1->size;
- dl->d_partitions[RAW_PART].p_offset = c1->offset;
- dl->d_rpm = 3600;
- dl->d_interleave = 1;
-
- dl->d_magic = DISKMAGIC;
- dl->d_magic2 = DISKMAGIC;
- dl->d_checksum = dkcksum(dl);
-}
diff --git a/lib/libdisk/write_i386_disk.c b/lib/libdisk/write_i386_disk.c
deleted file mode 100644
index 15317d384f53..000000000000
--- a/lib/libdisk/write_i386_disk.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/disklabel.h>
-#include <sys/diskmbr.h>
-#include <paths.h>
-#include "libdisk.h"
-
-/*
- * XXX: A lot of hardcoded 512s probably should be foo->sector_size;
- * I'm not sure which, so I leave it like it worked before. --schweikh
- */
-static int
-Write_FreeBSD(int fd, const struct disk *new, const struct chunk *c1)
-{
- struct disklabel *dl;
- int i;
- void *p;
- u_char buf[BBSIZE];
-
- for (i = 0; i < BBSIZE/512; i++) {
- if (!(p = read_block(fd, i + c1->offset, 512)))
- return (1);
- memcpy(buf + 512 * i, p, 512);
- free(p);
- }
- if (new->boot1)
- memcpy(buf, new->boot1, 512);
-
- if (new->boot2)
- memcpy(buf + 512, new->boot2, BBSIZE - 512);
-
- dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
- Fill_Disklabel(dl, new, c1);
-
- for (i = 0; i < BBSIZE / 512; i++)
- write_block(fd, i + c1->offset, buf + 512 * i, 512);
-
- return 0;
-}
-
-static void
-Write_Int32(u_int32_t *p, u_int32_t v)
-{
- u_int8_t *bp = (u_int8_t *)p;
-
- bp[0] = (v >> 0) & 0xff;
- bp[1] = (v >> 8) & 0xff;
- bp[2] = (v >> 16) & 0xff;
- bp[3] = (v >> 24) & 0xff;
-}
-
-/*
- * Special install-time configuration for the i386 boot0 boot manager.
- */
-static void
-Cfg_Boot_Mgr(u_char *mbrblk, int edd)
-{
-
- if (mbrblk[0x1b0] == 0x66 && mbrblk[0x1b1] == 0xbb) {
- if (edd)
- mbrblk[0x1bb] |= 0x80; /* Packet mode on */
- else
- mbrblk[0x1bb] &= 0x7f; /* Packet mode off */
- }
-}
-
-int
-Write_Disk(const struct disk *d1)
-{
- int fd, j;
- uint i;
- struct chunk *c1;
- int ret = 0;
- char device[64];
- u_char *mbrblk;
- struct dos_partition *dp,work[NDOSPART];
- int s[4];
- int need_edd = 0; /* Need EDD (packet interface) */
-
- strcpy(device, _PATH_DEV);
- strcat(device, d1->name);
-
- fd = open(device, O_RDWR);
- if (fd < 0)
- return 1;
-
- memset(s, 0, sizeof s);
- if (!(mbrblk = read_block(fd, 0, d1->sector_size))) {
- close (fd);
- return (1);
- }
- dp = (struct dos_partition *)(mbrblk + DOSPARTOFF);
- memcpy(work, dp, sizeof work);
- dp = work;
- free(mbrblk);
- for (c1 = d1->chunks->part; c1; c1 = c1->next) {
- if (c1->type == unused)
- continue;
- if (!strcmp(c1->name, "X"))
- continue;
- j = c1->name[strlen(d1->name) + 1] - '1';
- if (j < 0 || j > 3)
- continue;
- s[j]++;
- if (c1->type == freebsd)
- ret += Write_FreeBSD(fd, d1, c1);
-
- Write_Int32(&dp[j].dp_start, c1->offset);
- Write_Int32(&dp[j].dp_size, c1->size);
-
- i = c1->offset;
- if (i >= 1024 * d1->bios_sect * d1->bios_hd) {
- dp[j].dp_ssect = 0xff;
- dp[j].dp_shd = 0xff;
- dp[j].dp_scyl = 0xff;
- need_edd++;
- } else {
- dp[j].dp_ssect = i % d1->bios_sect;
- i -= dp[j].dp_ssect++;
- i /= d1->bios_sect;
- dp[j].dp_shd = i % d1->bios_hd;
- i -= dp[j].dp_shd;
- i /= d1->bios_hd;
- dp[j].dp_scyl = i;
- i -= dp[j].dp_scyl;
- dp[j].dp_ssect |= i >> 2;
- }
-#ifdef DEBUG
- printf("S:%lu = (%x/%x/%x)", c1->offset,
- dp[j].dp_scyl, dp[j].dp_shd, dp[j].dp_ssect);
-#endif
-
- i = c1->end;
- dp[j].dp_esect = i % d1->bios_sect;
- i -= dp[j].dp_esect++;
- i /= d1->bios_sect;
- dp[j].dp_ehd = i % d1->bios_hd;
- i -= dp[j].dp_ehd;
- i /= d1->bios_hd;
- if (i > 1023)
- i = 1023;
- dp[j].dp_ecyl = i;
- i -= dp[j].dp_ecyl;
- dp[j].dp_esect |= i >> 2;
-#ifdef DEBUG
- printf(" E:%lu = (%x/%x/%x)\n", c1->end,
- dp[j].dp_ecyl, dp[j].dp_ehd, dp[j].dp_esect);
-#endif
-
- dp[j].dp_typ = c1->subtype;
- if (c1->flags & CHUNK_ACTIVE)
- dp[j].dp_flag = 0x80;
- else
- dp[j].dp_flag = 0;
- }
- j = 0;
- for (i = 0; i < NDOSPART; i++) {
- if (!s[i])
- memset(dp + i, 0, sizeof *dp);
- if (dp[i].dp_flag)
- j++;
- }
- if (!j)
- for(i = 0; i < NDOSPART; i++)
- if (dp[i].dp_typ == 0xa5)
- dp[i].dp_flag = 0x80;
-
- if (!(mbrblk = read_block(fd, 0, d1->sector_size))) {
- close (fd);
- return (1);
- }
- if (d1->bootmgr) {
- memcpy(mbrblk, d1->bootmgr, DOSPARTOFF);
- Cfg_Boot_Mgr(mbrblk, need_edd);
- }
- memcpy(mbrblk + DOSPARTOFF, dp, sizeof *dp * NDOSPART);
- mbrblk[512-2] = 0x55;
- mbrblk[512-1] = 0xaa;
- write_block(fd, 0, mbrblk, d1->sector_size);
- if (d1->bootmgr && d1->bootmgr_size > d1->sector_size)
- for (i = 1; i * d1->sector_size <= d1->bootmgr_size; i++)
- write_block(fd, i, &d1->bootmgr[i * d1->sector_size],
- d1->sector_size);
-
- close(fd);
- return 0;
-}
diff --git a/lib/libdisk/write_ia64_disk.c b/lib/libdisk/write_ia64_disk.c
deleted file mode 100644
index 6a57322adb1c..000000000000
--- a/lib/libdisk/write_ia64_disk.c
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * Copyright (c) 2003 Marcel Moolenaar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * CRC32 code derived from work by Gary S. Brown.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/types.h>
-#include <sys/disklabel.h>
-#include <sys/diskmbr.h>
-#include <sys/gpt.h>
-#include <sys/stat.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <uuid.h>
-
-#include "libdisk.h"
-
-static uuid_t _efi = GPT_ENT_TYPE_EFI;
-static uuid_t _fbsd = GPT_ENT_TYPE_FREEBSD;
-static uuid_t _swap = GPT_ENT_TYPE_FREEBSD_SWAP;
-static uuid_t _ufs = GPT_ENT_TYPE_FREEBSD_UFS;
-
-static uint32_t crc32_tab[] = {
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
- 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
- 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
- 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
- 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
- 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
- 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
- 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
- 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
- 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
- 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
- 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
- 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
- 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
- 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
- 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
- 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
- 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
- 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
- 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
- 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
- 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
-};
-
-static uint32_t
-crc32(const void *buf, size_t size)
-{
- const uint8_t *p;
- uint32_t crc;
-
- p = buf;
- crc = ~0U;
-
- while (size--)
- crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
-
- return (crc ^ ~0U);
-}
-
-static int
-write_pmbr(int fd, const struct disk *disk)
-{
- struct dos_partition dp;
- char *buffer;
- u_long nsects;
- int error;
-
- error = 0;
- nsects = disk->media_size / disk->sector_size;
- nsects--; /* The GPT starts at LBA 1 */
-
- buffer = calloc(disk->sector_size, 1);
- if (buffer == NULL)
- return (ENOMEM);
- buffer[DOSMAGICOFFSET] = DOSMAGIC & 0xff;
- buffer[DOSMAGICOFFSET + 1] = DOSMAGIC >> 8;
-
- dp.dp_flag = 0;
- dp.dp_shd = dp.dp_ssect = dp.dp_scyl = 0xff;
- dp.dp_typ = DOSPTYP_PMBR;
- dp.dp_ehd = dp.dp_esect = dp.dp_ecyl = 0xff;
- dp.dp_start = 1;
- dp.dp_size = (nsects > 0xffffffffu) ? ~0u : nsects;
- memcpy(buffer + DOSPARTOFF, &dp, DOSPARTSIZE);
-
- if (lseek(fd, 0L, SEEK_SET) != 0L ||
- write(fd, buffer, disk->sector_size) != disk->sector_size)
- error = (errno) ? errno : EAGAIN;
-
- free(buffer);
- return (error);
-}
-
-static int
-read_gpt(int fd, const struct disk *disk, struct gpt_hdr *hdr,
- struct gpt_ent *tbl)
-{
- char *buffer;
- off_t off;
- size_t nsects, sz;
- int error, i;
-
- error = 0;
- nsects = disk->gpt_size * sizeof(struct gpt_ent) / disk->sector_size;
- nsects++;
- sz = nsects * disk->sector_size;
- buffer = malloc(sz);
- if (buffer == NULL)
- return (ENOMEM);
-
- if (lseek(fd, disk->sector_size, SEEK_SET) != disk->sector_size ||
- read(fd, buffer, disk->sector_size) != disk->sector_size) {
- error = (errno) ? errno : EAGAIN;
- goto bail;
- }
- if (memcmp(buffer, GPT_HDR_SIG, sizeof(hdr->hdr_sig)) != 0) {
- /*
- * No GPT on disk. Create one out of thin air.
- */
- bzero(&hdr[0], sizeof(struct gpt_hdr));
- memcpy(hdr[0].hdr_sig, GPT_HDR_SIG, sizeof(hdr[0].hdr_sig));
- hdr[0].hdr_revision = GPT_HDR_REVISION;
- hdr[0].hdr_size = offsetof(struct gpt_hdr, padding);
- hdr[0].hdr_lba_self = 1;
- hdr[0].hdr_lba_alt = disk->media_size / disk->sector_size - 1L;
- hdr[0].hdr_lba_start = disk->lba_start;
- hdr[0].hdr_lba_end = disk->lba_end;
- uuid_create(&hdr[0].hdr_uuid, NULL);
- hdr[0].hdr_lba_table = 2;
- hdr[0].hdr_entries = disk->gpt_size;
- hdr[0].hdr_entsz = sizeof(struct gpt_ent);
- hdr[1] = hdr[0];
- hdr[1].hdr_lba_self = hdr[0].hdr_lba_alt;
- hdr[1].hdr_lba_alt = hdr[0].hdr_lba_self;
- hdr[1].hdr_lba_table = disk->lba_end + 1;
-
- for (i = 0; i < disk->gpt_size; i++) {
- bzero(&tbl[i], sizeof(struct gpt_ent));
- uuid_create(&tbl[i].ent_uuid, NULL);
- }
-
- goto bail;
- }
-
- /*
- * We have a GPT on disk. Read it.
- */
- memcpy(&hdr[0], buffer, sizeof(struct gpt_hdr));
- off = hdr->hdr_lba_table * disk->sector_size;
- if (lseek(fd, off, SEEK_SET) != off ||
- read(fd, buffer, sz) != sz) {
- error = (errno) ? errno : EAGAIN;
- goto bail;
- }
- memcpy(tbl, buffer, sizeof(struct gpt_ent) * disk->gpt_size);
- off = hdr->hdr_lba_alt * disk->sector_size;
- if (lseek(fd, off, SEEK_SET) != off ||
- read(fd, buffer, disk->sector_size) != disk->sector_size) {
- error = (errno) ? errno : EAGAIN;
- goto bail;
- }
- memcpy(&hdr[1], buffer, sizeof(struct gpt_hdr));
-
-bail:
- free(buffer);
- return (error);
-}
-
-static int
-update_gpt(int fd, const struct disk *disk, struct gpt_hdr *hdr,
- struct gpt_ent *tbl)
-{
- struct gpt_ent *save;
- char *buffer;
- struct chunk *c;
- off_t off;
- size_t bufsz;
- int error, idx, sav;
-
- error = 0;
-
- /*
- * Save the entries of those chunks that have an index. They are
- * the ones that exist on disk already.
- */
- sav = 0;
- for (c = disk->chunks->part; c != NULL; c = c->next) {
- if ((c->flags & CHUNK_HAS_INDEX))
- sav++;
- }
- if (sav > 0) {
- save = malloc(sav * sizeof(struct gpt_ent));
- if (save == NULL)
- abort();
- sav = 0;
- for (c = disk->chunks->part; c != NULL; c = c->next) {
- if ((c->flags & CHUNK_HAS_INDEX)) {
- idx = CHUNK_FTOI(c->flags);
- save[sav] = tbl[idx];
- c->flags ^= CHUNK_ITOF(idx);
- c->flags |= CHUNK_ITOF(sav);
- sav++;
- }
- }
- } else
- save = NULL;
-
- /*
- * Clear the table entries.
- */
- for (idx = 0; idx < disk->gpt_size; idx++) {
- uuid_create_nil(&tbl[idx].ent_type, NULL);
- tbl[idx].ent_lba_start = 0;
- tbl[idx].ent_lba_end = 0;
- tbl[idx].ent_attr = 0;
- bzero(tbl[idx].ent_name, sizeof(tbl[idx].ent_name));
- }
-
- /*
- * Repopulate the table from the chunks, possibly using saved
- * information.
- */
- idx = 0;
- for (c = disk->chunks->part; c != NULL; c = c->next) {
- if (!(c->flags & CHUNK_HAS_INDEX)) {
- switch (c->type) {
- case freebsd:
- tbl[idx].ent_type = _fbsd;
- break;
- case efi:
- tbl[idx].ent_type = _efi;
- break;
- case part:
- switch (c->subtype) {
- case FS_SWAP:
- tbl[idx].ent_type = _swap;
- break;
- case FS_BSDFFS:
- tbl[idx].ent_type = _ufs;
- break;
- default:
- return (EINVAL);
- }
- break;
- default:
- return (EINVAL);
- }
- } else {
- sav = CHUNK_FTOI(c->flags);
- tbl[idx].ent_type = save[sav].ent_type;
- memcpy(tbl[idx].ent_name, save[sav].ent_name,
- sizeof(tbl[idx].ent_name));
- }
- tbl[idx].ent_lba_start = c->offset;
- tbl[idx].ent_lba_end = c->end;
-
- idx++;
- if (idx == disk->gpt_size)
- return (ENOSPC);
- }
- if (save != NULL)
- free(save);
-
- hdr[0].hdr_crc_table = crc32(tbl,
- disk->gpt_size * sizeof(struct gpt_ent));
- hdr[0].hdr_crc_self = 0;
- hdr[0].hdr_crc_self = crc32(&hdr[0], hdr[0].hdr_size);
-
- hdr[1].hdr_crc_table = hdr[0].hdr_crc_table;
- hdr[1].hdr_crc_self = 0;
- hdr[1].hdr_crc_self = crc32(&hdr[1], hdr[1].hdr_size);
-
- /*
- * Write the new GPT back to the disk.
- */
- bufsz = disk->gpt_size * sizeof(struct gpt_ent);
- if (bufsz == 0 || bufsz % disk->sector_size)
- bufsz += disk->sector_size;
- bufsz = (bufsz / disk->sector_size) * disk->sector_size;
- buffer = calloc(1, bufsz);
-
- memcpy(buffer, &hdr[0], sizeof(struct gpt_hdr));
- off = hdr[0].hdr_lba_self * disk->sector_size;
- if (lseek(fd, off, SEEK_SET) != off ||
- write(fd, buffer, disk->sector_size) != disk->sector_size) {
- error = (errno) ? errno : EAGAIN;
- goto bail;
- }
- memcpy(buffer, &hdr[1], sizeof(struct gpt_hdr));
- off = hdr[1].hdr_lba_self * disk->sector_size;
- if (lseek(fd, off, SEEK_SET) != off ||
- write(fd, buffer, disk->sector_size) != disk->sector_size) {
- error = (errno) ? errno : EAGAIN;
- goto bail;
- }
- memcpy(buffer, tbl, disk->gpt_size * sizeof(struct gpt_ent));
- off = hdr[0].hdr_lba_table * disk->sector_size;
- if (lseek(fd, off, SEEK_SET) != off ||
- write(fd, buffer, bufsz) != bufsz) {
- error = (errno) ? errno : EAGAIN;
- goto bail;
- }
- off = hdr[1].hdr_lba_table * disk->sector_size;
- if (lseek(fd, off, SEEK_SET) != off ||
- write(fd, buffer, bufsz) != bufsz) {
- error = (errno) ? errno : EAGAIN;
- goto bail;
- }
-
-bail:
- free(buffer);
- return (error);
-}
-
-int
-Write_Disk(const struct disk *disk)
-{
- char devname[64];
- struct gpt_hdr *hdr;
- struct gpt_ent *tbl;
- int error, fd;
-
- hdr = malloc(sizeof(struct gpt_hdr) * 2);
- if (hdr == NULL)
- return (ENOMEM);
- tbl = malloc(sizeof(struct gpt_ent) * disk->gpt_size);
- if (tbl == NULL) {
- free(hdr);
- return (ENOMEM);
- }
-
- snprintf(devname, sizeof(devname), "%s%s", _PATH_DEV, disk->name);
- fd = open(devname, O_RDWR);
- if (fd == -1) {
- free(tbl);
- free(hdr);
- return (errno);
- }
-
- /*
- * We can always write the PMBR, because we reject disks that do not
- * have a PMBR and are not virgin.
- */
- error = write_pmbr(fd, disk);
- if (error)
- goto bail;
-
- /*
- * Read the existing GPT from disk or otherwise create one out of
- * thin air. This way we can preserve the UUIDs and the entry names
- * when updating it.
- */
- error = read_gpt(fd, disk, hdr, tbl);
- if (error)
- goto bail;
-
- /*
- * Update and write the in-memory copy of the GPT.
- */
- error = update_gpt(fd, disk, hdr, tbl);
-
-bail:
- close(fd);
- free(tbl);
- free(hdr);
- return (error);
-}
diff --git a/lib/libdisk/write_pc98_disk.c b/lib/libdisk/write_pc98_disk.c
deleted file mode 100644
index 8f2a45da91f0..000000000000
--- a/lib/libdisk/write_pc98_disk.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <err.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/disklabel.h>
-#include <sys/diskpc98.h>
-#include <paths.h>
-#include "libdisk.h"
-
-/*
- * XXX: A lot of hardcoded 512s probably should be foo->sector_size;
- * I'm not sure which, so I leave it like it worked before. --schweikh
- */
-static int
-Write_FreeBSD(int fd, const struct disk *new, const struct chunk *c1)
-{
- struct disklabel *dl;
- int i;
- void *p;
- u_char buf[BBSIZE];
-
- for (i = 0; i < BBSIZE / 512; i++) {
- if (!(p = read_block(fd, i + c1->offset, 512)))
- return (1);
- memcpy(buf + 512 * i, p, 512);
- free(p);
- }
- if (new->boot1)
- memcpy(buf, new->boot1, 512);
-
- if (new->boot2)
- memcpy(buf + 512, new->boot2, BBSIZE - 512);
-
- dl = (struct disklabel *)(buf + 512 * LABELSECTOR + LABELOFFSET);
- Fill_Disklabel(dl, new, c1);
-
- for (i = 0; i < BBSIZE / 512; i++)
- write_block(fd, i + c1->offset, buf + 512 * i, 512);
-
- return 0;
-}
-
-
-int
-Write_Disk(const struct disk *d1)
-{
- int fd, i, j;
- struct chunk *c1;
- int ret = 0;
- char device[64];
- u_char *mbrblk;
- struct pc98_partition *dp, work[NDOSPART];
- int s[7];
- int PC98_EntireDisk = 0;
-
- strcpy(device, _PATH_DEV);
- strcat(device, d1->name);
-
- /* XXX - for entire FreeBSD(98) */
- for (c1 = d1->chunks->part; c1; c1 = c1->next) {
- if ((c1->type == freebsd) || (c1->offset == 0))
- device[9] = 0;
- }
-
- fd = open(device, O_RDWR);
- if (fd < 0) {
-#ifdef DEBUG
- warn("open(%s) failed", device);
-#endif
- return 1;
- }
-
- memset(s, 0, sizeof s);
- if (!(mbrblk = read_block(fd, 1, d1->sector_size))) {
- close (fd);
- return (1);
- }
- dp = (struct pc98_partition *)(mbrblk + DOSPARTOFF);
- memcpy(work, dp, sizeof work);
- dp = work;
- free(mbrblk);
- for (c1 = d1->chunks->part; c1; c1 = c1->next) {
- if (c1->type == unused)
- continue;
- if (!strcmp(c1->name, "X"))
- continue;
- j = c1->name[strlen(d1->name) + 1] - '1';
- if (j < 0 || j > 7)
- continue;
- s[j]++;
- if (c1->type == freebsd)
- ret += Write_FreeBSD(fd, d1, c1);
-
- i = c1->offset;
- dp[j].dp_ssect = dp[j].dp_ipl_sct = i % d1->bios_sect;
- i -= dp[j].dp_ssect;
- i /= d1->bios_sect;
- dp[j].dp_shd = dp[j].dp_ipl_head = i % d1->bios_hd;
- i -= dp[j].dp_shd;
- i /= d1->bios_hd;
- dp[j].dp_scyl = dp[j].dp_ipl_cyl = i;
-#ifdef DEBUG
- printf("S:%lu = (%x/%x/%x)", c1->offset,
- dp[j].dp_scyl, dp[j].dp_shd, dp[j].dp_ssect);
-#endif
-
- i = c1->end;
-#if 1
- dp[j].dp_esect = dp[j].dp_ehd = 0;
- dp[j].dp_ecyl = i / (d1->bios_sect * d1->bios_hd);
-#else
- dp[j].dp_esect = i % d1->bios_sect;
- i -= dp[j].dp_esect;
- i /= d1->bios_sect;
- dp[j].dp_ehd = i % d1->bios_hd;
- i -= dp[j].dp_ehd;
- i /= d1->bios_hd;
- dp[j].dp_ecyl = i;
-#endif
-#ifdef DEBUG
- printf(" E:%lu = (%x/%x/%x)\n", c1->end,
- dp[j].dp_ecyl, dp[j].dp_ehd, dp[j].dp_esect);
-#endif
-
- dp[j].dp_mid = c1->subtype & 0xff;
- dp[j].dp_sid = c1->subtype >> 8;
- if (c1->flags & CHUNK_ACTIVE)
- dp[j].dp_mid |= 0x80;
-
- strncpy(dp[j].dp_name, c1->sname, 16);
- }
- j = 0;
- for (i = 0; i < NDOSPART; i++) {
- if (!s[i])
- memset(dp + i, 0, sizeof *dp);
- }
-
- if (d1->bootipl)
- write_block(fd, 0, d1->bootipl, d1->sector_size);
-
- if (!(mbrblk = read_block(fd, 1, d1->sector_size))) {
- close (fd);
- return (1);
- }
- memcpy(mbrblk + DOSPARTOFF, dp, sizeof *dp * NDOSPART);
- /* XXX - for entire FreeBSD(98) */
- for (c1 = d1->chunks->part; c1; c1 = c1->next)
- if (((c1->type == freebsd) || (c1->type == fat))
- && (c1->offset == 0))
- PC98_EntireDisk = 1;
- if (PC98_EntireDisk == 0)
- write_block(fd, 1, mbrblk, d1->sector_size);
-
- if (d1->bootmenu)
- for (i = 0; i * d1->sector_size < d1->bootmenu_size; i++)
- write_block(fd, 2 + i,
- &d1->bootmenu[i * d1->sector_size],
- d1->sector_size);
-
- close(fd);
- return 0;
-}
diff --git a/lib/libdisk/write_sparc64_disk.c b/lib/libdisk/write_sparc64_disk.c
deleted file mode 100644
index 9832b0d32a1b..000000000000
--- a/lib/libdisk/write_sparc64_disk.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * ----------------------------------------------------------------------------
- * "THE BEER-WARE LICENSE" (Revision 42):
- * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
- * can do whatever you want with this stuff. If we meet some day, and you think
- * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
- * ----------------------------------------------------------------------------
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <err.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/sun_disklabel.h>
-#include <paths.h>
-#include <errno.h>
-#include "libdisk.h"
-
-#include "geom_sunlabel_enc.c"
-
-int
-Write_Disk(const struct disk *d1)
-{
- struct sun_disklabel *sl;
- struct chunk *c, *c1, *c2;
- int i;
- char *p;
- u_long secpercyl;
- char device[64];
- u_char buf[SUN_SIZE];
- int fd;
-
- strcpy(device, _PATH_DEV);
- strcat(device, d1->name);
-
- fd = open(device, O_RDWR);
- if (fd < 0) {
- warn("open(%s) failed", device);
- return (1);
- }
-
- sl = calloc(sizeof *sl, 1);
- c = d1->chunks;
- c2 = c->part;
- secpercyl = d1->bios_sect * d1->bios_hd;
- sl->sl_pcylinders = c->size / secpercyl;
- sl->sl_ncylinders = c2->size / secpercyl;
- sl->sl_acylinders = sl->sl_pcylinders - sl->sl_ncylinders;
- sl->sl_magic = SUN_DKMAGIC;
- sl->sl_nsectors = d1->bios_sect;
- sl->sl_ntracks = d1->bios_hd;
- if (c->size > 4999 * 1024 * 2) {
- sprintf(sl->sl_text, "FreeBSD%luG cyl %u alt %u hd %u sec %u",
- (c->size + 1024 * 1024) / (2 * 1024 * 1024),
- sl->sl_ncylinders, sl->sl_acylinders,
- sl->sl_ntracks, sl->sl_nsectors);
- } else {
- sprintf(sl->sl_text, "FreeBSD%luM cyl %u alt %u hd %u sec %u",
- (c->size + 1024) / (2 * 1024),
- sl->sl_ncylinders, sl->sl_acylinders,
- sl->sl_ntracks, sl->sl_nsectors);
- }
- sl->sl_interleave = 1;
- sl->sl_sparespercyl = 0;
- sl->sl_rpm = 3600;
-
- for (c1 = c2->part; c1 != NULL; c1 = c1->next) {
- p = c1->name;
- p += strlen(p);
- p--;
- if (*p < 'a')
- continue;
- i = *p - 'a';
- if (i >= SUN_NPART)
- continue;
- sl->sl_part[i].sdkp_cyloffset = c1->offset / secpercyl;
- sl->sl_part[i].sdkp_nsectors = c1->size;
- for (i = 1; i < 16; i++) {
- write_block(fd, c1->offset + i, d1->boot1 + (i * 512),
- 512);
- }
- }
-
- /*
- * We need to fill in the "RAW" partition as well. Emperical data
- * seems to indicate that this covers the "obviously" visible part
- * of the disk, ie: sl->sl_ncylinders.
- */
- sl->sl_part[SUN_RAWPART].sdkp_cyloffset = 0;
- sl->sl_part[SUN_RAWPART].sdkp_nsectors = sl->sl_ncylinders * secpercyl;
-
- memset(buf, 0, sizeof buf);
- sunlabel_enc(buf, sl);
- write_block(fd, 0, buf, sizeof buf);
-
- close(fd);
- return 0;
-}
diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3
index fe583216970f..33f7666f4283 100644
--- a/lib/libedit/editline.3
+++ b/lib/libedit/editline.3
@@ -526,8 +526,6 @@ If
is
.Dv NULL ,
try
-.Pa $PWD/.editrc
-then
.Pa $HOME/.editrc .
Refer to
.Xr editrc 5
diff --git a/lib/libedit/editrc.5 b/lib/libedit/editrc.5
index f46b874a8319..6e04ea167099 100644
--- a/lib/libedit/editrc.5
+++ b/lib/libedit/editrc.5
@@ -473,6 +473,13 @@ Move down one line.
Editline extended command.
.El
.\" End of section automatically generated with makelist
+.Sh FILES
+.Bl -tag -width "~/.editrcXXX"
+.It Pa ~/.editrc
+User configuration file for the
+.Xr editline 3
+library.
+.El
.Sh SEE ALSO
.Xr editline 3 ,
.Xr regex 3 ,
diff --git a/lib/libedit/map.c b/lib/libedit/map.c
index 591118f2cf02..c70904aa2d41 100644
--- a/lib/libedit/map.c
+++ b/lib/libedit/map.c
@@ -1250,7 +1250,7 @@ map_bind(EditLine *el, int argc, const char **argv)
char inbuf[EL_BUFSIZ];
char outbuf[EL_BUFSIZ];
const char *in = NULL;
- char *out = NULL;
+ char *out;
el_bindings_t *bp, *ep;
int cmd;
int key;
@@ -1368,7 +1368,7 @@ map_bind(EditLine *el, int argc, const char **argv)
return (-1);
}
if (key)
- term_set_arrow(el, in, key_map_str(el, out), ntype);
+ term_set_arrow(el, in, key_map_cmd(el, cmd), ntype);
else {
if (in[1]) {
key_add(el, in, key_map_cmd(el, cmd), ntype);
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index 00dd887cfce1..abf79a301f17 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -1752,11 +1752,11 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
/* get headers. http_next_header expects one line readahead */
if (fetch_getln(conn) == -1) {
- fetch_syserr();
- goto ouch;
+ fetch_syserr();
+ goto ouch;
}
do {
- switch ((h = http_next_header(conn, &headerbuf, &p))) {
+ switch ((h = http_next_header(conn, &headerbuf, &p))) {
case hdr_syserror:
fetch_syserr();
goto ouch;
@@ -1785,7 +1785,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
conn->err != HTTP_USE_PROXY) {
n = 1;
break;
- }
+ }
if (new)
free(new);
if (verbose)
diff --git a/lib/libipsec/policy_parse.y b/lib/libipsec/policy_parse.y
index 9e2f979c72d3..46e54e554c07 100644
--- a/lib/libipsec/policy_parse.y
+++ b/lib/libipsec/policy_parse.y
@@ -88,7 +88,6 @@ static caddr_t policy_parse(char *msg, int msglen);
extern void __policy__strbuffer__init__(char *msg);
extern void __policy__strbuffer__free__(void);
-extern int yyparse(void);
extern int yylex(void);
extern char *__libipsecyytext; /*XXX*/
diff --git a/lib/libnetbsd/Makefile b/lib/libnetbsd/Makefile
new file mode 100644
index 000000000000..09c6985e6c83
--- /dev/null
+++ b/lib/libnetbsd/Makefile
@@ -0,0 +1,13 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+LIB= netbsd
+
+CFLAGS+= -I${.CURDIR}
+
+SRCS+= strsuftoll.c util.c util.h
+
+INTERNALLIB=
+
+.include <bsd.lib.mk>
diff --git a/lib/libnetbsd/README b/lib/libnetbsd/README
new file mode 100644
index 000000000000..ab303007cce4
--- /dev/null
+++ b/lib/libnetbsd/README
@@ -0,0 +1,7 @@
+$FreeBSD$
+
+libnetbsd is a thin compatibility layer intended to allow a limited
+set of NetBSD software to compile as part of the FreeBSD build with
+little or no modifiction. It is built as a static library and not
+installed for general use. Likewise, its header files are not
+installed.
diff --git a/lib/libnetbsd/rmd160.h b/lib/libnetbsd/rmd160.h
new file mode 100644
index 000000000000..7b811995edb4
--- /dev/null
+++ b/lib/libnetbsd/rmd160.h
@@ -0,0 +1,44 @@
+/* $FreeBSD$ */
+
+/*-
+ * Copyright (c) 2012 SRI International
+ * All rights reserved.
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
+ * ("CTSRD"), as part of the DARPA CRASH research programme.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _RMD160_H_
+#define _RMD160_H_
+
+#include <ripemd.h>
+
+#define RMD160_CTX RIPEMD160_CTX
+#define RMD160End RIPEMD160_End
+#define RMD160File RIPEMD160_File
+#define RMD160Init RIPEMD160_Init
+#define RMD160Update RIPEMD160_Update
+
+#endif /* _RMD160_H_ */
diff --git a/lib/libnetbsd/sha1.h b/lib/libnetbsd/sha1.h
new file mode 100644
index 000000000000..41280c58b076
--- /dev/null
+++ b/lib/libnetbsd/sha1.h
@@ -0,0 +1,43 @@
+/* $FreeBSD$ */
+
+/*-
+ * Copyright (c) 2012 SRI International
+ * All rights reserved.
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
+ * ("CTSRD"), as part of the DARPA CRASH research programme.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SHA1_H_
+#define _SHA1_H_
+
+#include <sha.h>
+
+#define SHA1End SHA1_End
+#define SHA1File SHA1_File
+#define SHA1Init SHA1_Init
+#define SHA1Update SHA1_Update
+
+#endif /* _SHA1_H_ */
diff --git a/lib/libnetbsd/sha2.h b/lib/libnetbsd/sha2.h
new file mode 100644
index 000000000000..b67691d54fb0
--- /dev/null
+++ b/lib/libnetbsd/sha2.h
@@ -0,0 +1,39 @@
+/* $FreeBSD$ */
+
+/*-
+ * Copyright (c) 2012 SRI International
+ * All rights reserved.
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
+ * ("CTSRD"), as part of the DARPA CRASH research programme.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SHA2_H_
+#define _SHA2_H_
+
+#include <sha256.h>
+#include <sha512.h>
+
+#endif /* _SHA2_H_ */
diff --git a/lib/libnetbsd/stdlib.h b/lib/libnetbsd/stdlib.h
new file mode 100644
index 000000000000..d481913d58fd
--- /dev/null
+++ b/lib/libnetbsd/stdlib.h
@@ -0,0 +1,70 @@
+/* $FreeBSD$ */
+
+/*-
+ * Copyright (c) 2012 SRI International
+ * Copyright (c) 2001-2002,2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Luke Mewburn.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LIBNETBSD_STDLIB_H_
+#define _LIBNETBSD_STDLIB_H_
+
+#include_next <stdlib.h>
+
+long long strsuftoll(const char *, const char *, long long, long long);
+long long strsuftollx(const char *, const char *,
+ long long, long long, char *, size_t);
+
+#endif /* _LIBNETBSD_STDLIB_H_ */
diff --git a/lib/libnetbsd/strsuftoll.c b/lib/libnetbsd/strsuftoll.c
new file mode 100644
index 000000000000..657e52525fc6
--- /dev/null
+++ b/lib/libnetbsd/strsuftoll.c
@@ -0,0 +1,222 @@
+/* $NetBSD: strsuftoll.c,v 1.6 2004/03/05 05:58:29 lukem Exp $ */
+/*-
+ * Copyright (c) 2001-2002,2004 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Luke Mewburn.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+/*-
+ * Copyright (c) 1991, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Keith Muller of the University of California, San Diego and Lance
+ * Visser of Convex Computer Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef _LIBC
+# ifdef __weak_alias
+__weak_alias(strsuftoll, _strsuftoll)
+__weak_alias(strsuftollx, _strsuftollx)
+# endif
+#endif /* LIBC */
+
+/*
+ * Convert an expression of the following forms to a (u)int64_t.
+ * 1) A positive decimal number.
+ * 2) A positive decimal number followed by a b (mult by 512).
+ * 3) A positive decimal number followed by a k (mult by 1024).
+ * 4) A positive decimal number followed by a m (mult by 1048576).
+ * 5) A positive decimal number followed by a g (mult by 1073741824).
+ * 6) A positive decimal number followed by a t (mult by 1099511627776).
+ * 7) A positive decimal number followed by a w (mult by sizeof int)
+ * 8) Two or more positive decimal numbers (with/without k,b or w).
+ * separated by x (also * for backwards compatibility), specifying
+ * the product of the indicated values.
+ * Returns the result upon successful conversion, or exits with an
+ * appropriate error.
+ *
+ */
+
+/*
+ * As strsuftoll(), but returns the error message into the provided buffer
+ * rather than exiting with it.
+ */
+/* LONGLONG */
+long long
+strsuftollx(const char *desc, const char *val,
+ long long min, long long max, char *ebuf, size_t ebuflen)
+{
+ long long num, t;
+ char *expr;
+
+ errno = 0;
+ ebuf[0] = '\0';
+
+ while (isspace((unsigned char)*val)) /* Skip leading space */
+ val++;
+
+ num = strtoll(val, &expr, 10);
+ if (errno == ERANGE)
+ goto erange; /* Overflow */
+
+ if (expr == val) /* No digits */
+ goto badnum;
+
+ switch (*expr) {
+ case 'b':
+ t = num;
+ num *= 512; /* 1 block */
+ if (t > num)
+ goto erange;
+ ++expr;
+ break;
+ case 'k':
+ t = num;
+ num *= 1024; /* 1 kilobyte */
+ if (t > num)
+ goto erange;
+ ++expr;
+ break;
+ case 'm':
+ t = num;
+ num *= 1048576; /* 1 megabyte */
+ if (t > num)
+ goto erange;
+ ++expr;
+ break;
+ case 'g':
+ t = num;
+ num *= 1073741824; /* 1 gigabyte */
+ if (t > num)
+ goto erange;
+ ++expr;
+ break;
+ case 't':
+ t = num;
+ num *= 1099511627776LL; /* 1 terabyte */
+ if (t > num)
+ goto erange;
+ ++expr;
+ break;
+ case 'w':
+ t = num;
+ num *= sizeof(int); /* 1 word */
+ if (t > num)
+ goto erange;
+ ++expr;
+ break;
+ }
+
+ switch (*expr) {
+ case '\0':
+ break;
+ case '*': /* Backward compatible */
+ case 'x':
+ t = num;
+ num *= strsuftollx(desc, expr + 1, min, max, ebuf, ebuflen);
+ if (*ebuf != '\0')
+ return (0);
+ if (t > num) {
+ erange:
+ snprintf(ebuf, ebuflen,
+ "%s: %s", desc, strerror(ERANGE));
+ return (0);
+ }
+ break;
+ default:
+ badnum: snprintf(ebuf, ebuflen,
+ "%s `%s': illegal number", desc, val);
+ return (0);
+ }
+ if (num < min) {
+ /* LONGLONG */
+ snprintf(ebuf, ebuflen, "%s %lld is less than %lld.",
+ desc, (long long)num, (long long)min);
+ return (0);
+ }
+ if (num > max) {
+ /* LONGLONG */
+ snprintf(ebuf, ebuflen,
+ "%s %lld is greater than %lld.",
+ desc, (long long)num, (long long)max);
+ return (0);
+ }
+ *ebuf = '\0';
+ return (num);
+}
+
+/* LONGLONG */
+long long
+strsuftoll(const char *desc, const char *val,
+ long long min, long long max)
+{
+ long long result;
+ char errbuf[100];
+
+ result = strsuftollx(desc, val, min, max, errbuf, sizeof(errbuf));
+ if (*errbuf != '\0')
+ errx(1, "%s", errbuf);
+ return (result);
+}
diff --git a/lib/libnetbsd/sys/cdefs.h b/lib/libnetbsd/sys/cdefs.h
new file mode 100644
index 000000000000..09a7ca4ee7a3
--- /dev/null
+++ b/lib/libnetbsd/sys/cdefs.h
@@ -0,0 +1,50 @@
+/* $FreeBSD$ */
+
+/*-
+ * Copyright (c) 2012 SRI International
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LIBNETBSD_SYS_CDEFS_H_
+#define _LIBNETBSD_SYS_CDEFS_H_
+
+#include_next <sys/cdefs.h>
+
+#ifdef __dead2
+#define __dead __dead2
+#else
+#define __dead
+#endif
+
+/*
+ * Return the number of elements in a statically-allocated array,
+ * __x.
+ */
+#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
+
+#endif /* _LIBNETBSD_SYS_CDEFS_H_ */
diff --git a/lib/libdisk/write_powerpc_disk.c b/lib/libnetbsd/util.c
index ec955e2d35e4..36b9421efc39 100644
--- a/lib/libdisk/write_powerpc_disk.c
+++ b/lib/libnetbsd/util.c
@@ -1,7 +1,11 @@
/*-
- * Copyright (c) 2004 Suleiman Souhlal.
+ * Copyright (c) 2012 SRI International
* All rights reserved.
*
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
+ * ("CTSRD"), as part of the DARPA CRASH research programme.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -22,43 +26,34 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $FreeBSD$
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+#include <sys/types.h>
-#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <string.h>
-#include <err.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/disklabel.h>
-#include <paths.h>
-#include "libdisk.h"
+#include <unistd.h>
+#include <util.h>
-int
-Write_Disk(const struct disk *d1)
+char *
+flags_to_string(u_long flags, const char *def)
{
- /*
- * We don't have to write any label, so we only check that we can
- * open the disk.
- */
- int fd;
- char device[64];
-
- strcpy(device, _PATH_DEV);
- strcat(device, d1->name);
+ char *str;
- fd = open(device, O_RDWR);
- if (fd < 0) {
- close(fd);
- return 1;
+ str = fflagstostr(flags);
+ if (*str == '\0') {
+ free(str);
+ str = strdup(def);
}
+ return (str);
+}
+
+int
+string_to_flags(char **stringp, u_long *setp, u_long *clrp)
+{
- close(fd);
- return 0;
+ return strtofflags(stringp, setp, clrp);
}
diff --git a/lib/libnetbsd/util.h b/lib/libnetbsd/util.h
new file mode 100644
index 000000000000..c7d32e132336
--- /dev/null
+++ b/lib/libnetbsd/util.h
@@ -0,0 +1,41 @@
+/* $FreeBSD$ */
+
+/*-
+ * Copyright (c) 2012 SRI International
+ * Copyright (c) 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _UTIL_H_
+#define _UTIL_H_
+
+#include <libutil.h>
+
+char *flags_to_string(u_long flags, const char *def);
+int string_to_flags(char **stringp, u_long *setp, u_long *clrp);
+
+#endif /* _UTIL_H_ */
diff --git a/lib/libnetgraph/sock.c b/lib/libnetgraph/sock.c
index fca3900913df..5f9f563fe50c 100644
--- a/lib/libnetgraph/sock.c
+++ b/lib/libnetgraph/sock.c
@@ -71,10 +71,10 @@ NgMkSockNode(const char *name, int *csp, int *dsp)
name = NULL;
/* Create control socket; this also creates the netgraph node.
- If we get an EPROTONOSUPPORT then the socket node type is
+ If we get an EAFNOSUPPORT then the socket node type is
not loaded, so load it and try again. */
if ((cs = socket(AF_NETGRAPH, SOCK_DGRAM, NG_CONTROL)) < 0) {
- if (errno == EPROTONOSUPPORT) {
+ if (errno == EAFNOSUPPORT) {
if (kldload(NG_SOCKET_KLD) < 0) {
errnosv = errno;
if (_gNgDebugLevel >= 1)
diff --git a/lib/libpmc/Makefile b/lib/libpmc/Makefile
index f59dc2b8de83..c15d38aa1d08 100644
--- a/lib/libpmc/Makefile
+++ b/lib/libpmc/Makefile
@@ -29,6 +29,7 @@ MAN+= pmc.core.3
MAN+= pmc.core2.3
MAN+= pmc.iaf.3
MAN+= pmc.ivybridge.3
+MAN+= pmc.ivybridgexeon.3
MAN+= pmc.ucf.3
MAN+= pmc.k7.3
MAN+= pmc.k8.3
diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c
index 85c460d46d6e..1866e7f07368 100644
--- a/lib/libpmc/libpmc.c
+++ b/lib/libpmc/libpmc.c
@@ -188,6 +188,11 @@ static const struct pmc_event_descr ivybridge_event_table[] =
__PMC_EV_ALIAS_IVYBRIDGE()
};
+static const struct pmc_event_descr ivybridge_xeon_event_table[] =
+{
+ __PMC_EV_ALIAS_IVYBRIDGE_XEON()
+};
+
static const struct pmc_event_descr sandybridge_event_table[] =
{
__PMC_EV_ALIAS_SANDYBRIDGE()
@@ -233,6 +238,7 @@ PMC_MDEP_TABLE(core, IAP, PMC_CLASS_SOFT, PMC_CLASS_TSC);
PMC_MDEP_TABLE(core2, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC);
PMC_MDEP_TABLE(corei7, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP);
PMC_MDEP_TABLE(ivybridge, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC);
+PMC_MDEP_TABLE(ivybridge_xeon, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC);
PMC_MDEP_TABLE(sandybridge, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP);
PMC_MDEP_TABLE(sandybridge_xeon, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC);
PMC_MDEP_TABLE(westmere, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP);
@@ -272,6 +278,7 @@ PMC_CLASS_TABLE_DESC(core, IAP, core, iap);
PMC_CLASS_TABLE_DESC(core2, IAP, core2, iap);
PMC_CLASS_TABLE_DESC(corei7, IAP, corei7, iap);
PMC_CLASS_TABLE_DESC(ivybridge, IAP, ivybridge, iap);
+PMC_CLASS_TABLE_DESC(ivybridge_xeon, IAP, ivybridge_xeon, iap);
PMC_CLASS_TABLE_DESC(sandybridge, IAP, sandybridge, iap);
PMC_CLASS_TABLE_DESC(sandybridge_xeon, IAP, sandybridge_xeon, iap);
PMC_CLASS_TABLE_DESC(westmere, IAP, westmere, iap);
@@ -577,6 +584,8 @@ static struct pmc_event_alias core2_aliases_without_iaf[] = {
#define corei7_aliases_without_iaf core2_aliases_without_iaf
#define ivybridge_aliases core2_aliases
#define ivybridge_aliases_without_iaf core2_aliases_without_iaf
+#define ivybridge_xeon_aliases core2_aliases
+#define ivybridge_xeon_aliases_without_iaf core2_aliases_without_iaf
#define sandybridge_aliases core2_aliases
#define sandybridge_aliases_without_iaf core2_aliases_without_iaf
#define sandybridge_xeon_aliases core2_aliases
@@ -807,7 +816,8 @@ iap_allocate_pmc(enum pmc_event pe, char *ctrspec,
return (-1);
} else if (cpu_info.pm_cputype == PMC_CPU_INTEL_SANDYBRIDGE ||
cpu_info.pm_cputype == PMC_CPU_INTEL_SANDYBRIDGE_XEON ||
- cpu_info.pm_cputype == PMC_CPU_INTEL_IVYBRIDGE) {
+ cpu_info.pm_cputype == PMC_CPU_INTEL_IVYBRIDGE ||
+ cpu_info.pm_cputype == PMC_CPU_INTEL_IVYBRIDGE_XEON ) {
if (KWPREFIXMATCH(p, IAP_KW_RSP "=")) {
n = pmc_parse_mask(iap_rsp_mask_sb_sbx_ib, p, &rsp);
} else
@@ -2264,7 +2274,7 @@ soft_allocate_pmc(enum pmc_event pe, char *ctrspec,
(void)ctrspec;
(void)pmc_config;
- if (pe < PMC_EV_SOFT_FIRST || pe > PMC_EV_SOFT_LAST)
+ if ((int)pe < PMC_EV_SOFT_FIRST || (int)pe > PMC_EV_SOFT_LAST)
return (-1);
pmc_config->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
@@ -2684,6 +2694,10 @@ pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames,
ev = ivybridge_event_table;
count = PMC_EVENT_TABLE_SIZE(ivybridge);
break;
+ case PMC_CPU_INTEL_IVYBRIDGE_XEON:
+ ev = ivybridge_xeon_event_table;
+ count = PMC_EVENT_TABLE_SIZE(ivybridge_xeon);
+ break;
case PMC_CPU_INTEL_SANDYBRIDGE:
ev = sandybridge_event_table;
count = PMC_EVENT_TABLE_SIZE(sandybridge);
@@ -2983,6 +2997,9 @@ pmc_init(void)
case PMC_CPU_INTEL_IVYBRIDGE:
PMC_MDEP_INIT_INTEL_V2(ivybridge);
break;
+ case PMC_CPU_INTEL_IVYBRIDGE_XEON:
+ PMC_MDEP_INIT_INTEL_V2(ivybridge_xeon);
+ break;
case PMC_CPU_INTEL_SANDYBRIDGE:
pmc_class_table[n++] = &ucf_class_table_descr;
pmc_class_table[n++] = &sandybridgeuc_class_table_descr;
@@ -3125,6 +3142,10 @@ _pmc_name_of_event(enum pmc_event pe, enum pmc_cputype cpu)
ev = ivybridge_event_table;
evfence = ivybridge_event_table + PMC_EVENT_TABLE_SIZE(ivybridge);
break;
+ case PMC_CPU_INTEL_IVYBRIDGE_XEON:
+ ev = ivybridge_xeon_event_table;
+ evfence = ivybridge_xeon_event_table + PMC_EVENT_TABLE_SIZE(ivybridge_xeon);
+ break;
case PMC_CPU_INTEL_SANDYBRIDGE:
ev = sandybridge_event_table;
evfence = sandybridge_event_table + PMC_EVENT_TABLE_SIZE(sandybridge);
@@ -3190,7 +3211,7 @@ _pmc_name_of_event(enum pmc_event pe, enum pmc_cputype cpu)
} else if (pe == PMC_EV_TSC_TSC) {
ev = tsc_event_table;
evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc);
- } else if (pe >= PMC_EV_SOFT_FIRST && pe <= PMC_EV_SOFT_LAST) {
+ } else if ((int)pe >= PMC_EV_SOFT_FIRST && (int)pe <= PMC_EV_SOFT_LAST) {
ev = soft_event_table;
evfence = soft_event_table + soft_event_info.pm_nevent;
}
diff --git a/lib/libpmc/pmc.ivybridge.3 b/lib/libpmc/pmc.ivybridge.3
index 9a81da4b1708..7d8bdca62e3e 100644
--- a/lib/libpmc/pmc.ivybridge.3
+++ b/lib/libpmc/pmc.ivybridge.3
@@ -853,6 +853,7 @@ Dirty L2 cache lines evicted by the MLC prefetcher.
.Xr pmc.p6 3 ,
.Xr pmc.corei7 3 ,
.Xr pmc.corei7uc 3 ,
+.Xr pmc.ivybridgexeon 3 ,
.Xr pmc.sandybridge 3 ,
.Xr pmc.sandybridgeuc 3 ,
.Xr pmc.sandybridgexeon 3 ,
diff --git a/lib/libpmc/pmc.ivybridgexeon.3 b/lib/libpmc/pmc.ivybridgexeon.3
new file mode 100644
index 000000000000..76d5e60fce8f
--- /dev/null
+++ b/lib/libpmc/pmc.ivybridgexeon.3
@@ -0,0 +1,911 @@
+.\" Copyright (c) 2013 Hiren Panchasara <hiren.panchasara@gmail.com>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd Jan 25, 2013
+.Dt PMC.IVYBRIDGEXEON 3
+.Os
+.Sh NAME
+.Nm pmc.ivybridgexeon
+.Nd measurement events for
+.Tn Intel
+.Tn Ivy Bridge Xeon
+family CPUs
+.Sh LIBRARY
+.Lb libpmc
+.Sh SYNOPSIS
+.In pmc.h
+.Sh DESCRIPTION
+.Tn Intel
+.Tn "Ivy Bridge Xeon"
+CPUs contain PMCs conforming to version 2 of the
+.Tn Intel
+performance measurement architecture.
+These CPUs may contain up to three classes of PMCs:
+.Bl -tag -width "Li PMC_CLASS_IAP"
+.It Li PMC_CLASS_IAF
+Fixed-function counters that count only one hardware event per counter.
+.It Li PMC_CLASS_IAP
+Programmable counters that may be configured to count one of a defined
+set of hardware events.
+.El
+.Pp
+The number of PMCs available in each class and their widths need to be
+determined at run time by calling
+.Xr pmc_cpuinfo 3 .
+.Pp
+Intel Ivy Bridge Xeon PMCs are documented in
+.Rs
+.%B "Intel(R) 64 and IA-32 Architectures Software Developer's Manual"
+.%N "Order Number: 325462-045US"
+.%D January 2013
+.%Q "Intel Corporation"
+.Re
+.Ss IVYBRIDGE FIXED FUNCTION PMCS
+These PMCs and their supported events are documented in
+.Xr pmc.iaf 3 .
+.Ss IVYBRIDGE PROGRAMMABLE PMCS
+The programmable PMCs support the following capabilities:
+.Bl -column "PMC_CAP_INTERRUPT" "Support"
+.It Em Capability Ta Em Support
+.It PMC_CAP_CASCADE Ta \&No
+.It PMC_CAP_EDGE Ta Yes
+.It PMC_CAP_INTERRUPT Ta Yes
+.It PMC_CAP_INVERT Ta Yes
+.It PMC_CAP_READ Ta Yes
+.It PMC_CAP_PRECISE Ta \&No
+.It PMC_CAP_SYSTEM Ta Yes
+.It PMC_CAP_TAGGING Ta \&No
+.It PMC_CAP_THRESHOLD Ta Yes
+.It PMC_CAP_USER Ta Yes
+.It PMC_CAP_WRITE Ta Yes
+.El
+.Ss Event Qualifiers
+Event specifiers for these PMCs support the following common
+qualifiers:
+.Bl -tag -width indent
+.It Li rsp= Ns Ar value
+Configure the Off-core Response bits.
+.Bl -tag -width indent
+.It Li REQ_DMND_DATA_RD
+Counts the number of demand and DCU prefetch data reads of full and partial
+cachelines as well as demand data page table entry cacheline reads. Does not
+count L2 data read prefetches or instruction fetches.
+.It Li REQ_DMND_RFO
+Counts the number of demand and DCU prefetch reads for ownership (RFO)
+requests generated by a write to data cacheline. Does not count L2 RFO
+prefetches.
+.It Li REQ_DMND_IFETCH
+Counts the number of demand and DCU prefetch instruction cacheline reads.
+Does not count L2 code read prefetches.
+.It Li REQ_WB
+Counts the number of writeback (modified to exclusive) transactions.
+.It Li REQ_PF_DATA_RD
+Counts the number of data cacheline reads generated by L2 prefetchers.
+.It Li REQ_PF_RFO
+Counts the number of RFO requests generated by L2 prefetchers.
+.It Li REQ_PF_IFETCH
+Counts the number of code reads generated by L2 prefetchers.
+.It Li REQ_PF_LLC_DATA_RD
+L2 prefetcher to L3 for loads.
+.It Li REQ_PF_LLC_RFO
+RFO requests generated by L2 prefetcher
+.It Li REQ_PF_LLC_IFETCH
+L2 prefetcher to L3 for instruction fetches.
+.It Li REQ_BUS_LOCKS
+Bus lock and split lock requests.
+.It Li REQ_STRM_ST
+Streaming store requests.
+.It Li REQ_OTHER
+Any other request that crosses IDI, including I/O.
+.It Li RES_ANY
+Catch all value for any response types.
+.It Li RES_SUPPLIER_NO_SUPP
+No Supplier Information available.
+.It Li RES_SUPPLIER_LLC_HITM
+M-state initial lookup stat in L3.
+.It Li RES_SUPPLIER_LLC_HITE
+E-state.
+.It Li RES_SUPPLIER_LLC_HITS
+S-state.
+.It Li RES_SUPPLIER_LLC_HITF
+F-state.
+.It Li RES_SUPPLIER_LOCAL
+Local DRAM Controller.
+.It Li RES_SNOOP_SNP_NONE
+No details on snoop-related information.
+.It Li RES_SNOOP_SNP_NO_NEEDED
+No snoop was needed to satisfy the request.
+.It Li RES_SNOOP_SNP_MISS
+A snoop was needed and it missed all snooped caches:
+-For LLC Hit, ReslHitl was returned by all cores
+-For LLC Miss, Rspl was returned by all sockets and data was returned from
+DRAM.
+.It Li RES_SNOOP_HIT_NO_FWD
+A snoop was needed and it hits in at least one snooped cache. Hit denotes a
+cache-line was valid before snoop effect. This includes:
+-Snoop Hit w/ Invalidation (LLC Hit, RFO)
+-Snoop Hit, Left Shared (LLC Hit/Miss, IFetch/Data_RD)
+-Snoop Hit w/ Invalidation and No Forward (LLC Miss, RFO Hit S)
+In the LLC Miss case, data is returned from DRAM.
+.It Li RES_SNOOP_HIT_FWD
+A snoop was needed and data was forwarded from a remote socket.
+This includes:
+-Snoop Forward Clean, Left Shared (LLC Hit/Miss, IFetch/Data_RD/RFT).
+.It Li RES_SNOOP_HITM
+A snoop was needed and it HitM-ed in local or remote cache. HitM denotes a
+cache-line was in modified state before effect as a results of snoop. This
+includes:
+-Snoop HitM w/ WB (LLC miss, IFetch/Data_RD)
+-Snoop Forward Modified w/ Invalidation (LLC Hit/Miss, RFO)
+-Snoop MtoS (LLC Hit, IFetch/Data_RD).
+.It Li RES_NON_DRAM
+Target was non-DRAM system address. This includes MMIO transactions.
+.El
+.It Li cmask= Ns Ar value
+Configure the PMC to increment only if the number of configured
+events measured in a cycle is greater than or equal to
+.Ar value .
+.It Li edge
+Configure the PMC to count the number of de-asserted to asserted
+transitions of the conditions expressed by the other qualifiers.
+If specified, the counter will increment only once whenever a
+condition becomes true, irrespective of the number of clocks during
+which the condition remains true.
+.It Li inv
+Invert the sense of comparison when the
+.Dq Li cmask
+qualifier is present, making the counter increment when the number of
+events per cycle is less than the value specified by the
+.Dq Li cmask
+qualifier.
+.It Li os
+Configure the PMC to count events happening at processor privilege
+level 0.
+.It Li usr
+Configure the PMC to count events occurring at privilege levels 1, 2
+or 3.
+.El
+.Pp
+If neither of the
+.Dq Li os
+or
+.Dq Li usr
+qualifiers are specified, the default is to enable both.
+.Ss Event Specifiers (Programmable PMCs)
+Ivy Bridge programmable PMCs support the following events:
+.Bl -tag -width indent
+.It Li LD_BLOCKS.STORE_FORWARD
+.Pq Event 03H , Umask 02H
+loads blocked by overlapping with store buffer that cannot be forwarded .
+.It Li MISALIGN_MEM_REF.LOADS
+.Pq Event 05H , Umask 01H
+Speculative cache-line split load uops dispatched to L1D.
+.It Li MISALIGN_MEM_REF.STORES
+.Pq Event 05H , Umask 02H
+Speculative cache-line split Store- address uops dispatched to L1D.
+.It Li LD_BLOCKS_PARTIAL.ADDRESS_ALIAS
+.Pq Event 07H , Umask 01H
+False dependencies in MOB due to partial compare on address.
+.It Li DTLB_LOAD_MISSES.DEMAND_LD_MISS_CAUSES_A_WALK
+.Pq Event 08H , Umask 81H
+Misses in all TLB levels that cause a page walk of any page size from demand loads.
+.It Li DTLB_LOAD_MISSES.DEMAND_LD_WALK_COMPLETED
+.Pq Event 08H , Umask 82H
+Misses in all TLB levels that caused page walk completed of any size by demand loads.
+.It Li DTLB_LOAD_MISSES.DEMAND_LD_WALK_DURATION
+.Pq Event 08H , Umask 84H
+Cycle PMH is busy with a walk due to demand loads.
+.It Li UOPS_ISSUED.ANY
+.Pq Event 0EH , Umask 01H
+Increments each cycle the # of Uops issued by the RAT to RS.
+Set Cmask = 1, Inv = 1to count stalled cycles.
+Set Cmask = 1, Inv = 1, Any= 1to count stalled cycles of this core.
+.It Li UOPS_ISSUED.FLAGS_MERGE
+.Pq Event 0EH , Umask 10H
+Number of flags-merge uops allocated. Such uops adds delay.
+.It Li UOPS_ISSUED.SLOW_LEA
+.Pq Event 0EH , Umask 20H
+Number of slow LEA or similar uops allocated. Such uop has 3 sources (e.g. 2
+sources + immediate) regardless if as a result of LEA instruction or not.
+.It Li UOPS_ISSUED.SINGLE_MUL
+.Pq Event 0EH , Umask 40H
+Number of multiply packed/scalar single precision uops allocated.
+.It Li ARITH.FPU_DIV_ACTIVE
+.Pq Event 14H , Umask 01H
+Cycles that the divider is active, includes INT and FP. Set 'edge =1,
+cmask=1' to count the number of divides.
+.It Li L2_RQSTS.DEMAND_DATA_RD_HIT
+.Pq Event 24H , Umask 01H
+Demand Data Read requests that hit L2 cache.
+.It Li L2_RQSTS.ALL_DEMAND_DATA_RD
+.Pq Event 24H , Umask 03H
+Counts any demand and L1 HW prefetch data load requests to L2.
+.It Li L2_RQSTS.RFO_HITS
+.Pq Event 24H , Umask 04H
+Counts the number of store RFO requests that hit the L2 cache.
+.It Li L2_RQSTS.RFO_MISS
+.Pq Event 24H , Umask 08H
+Counts the number of store RFO requests that miss the L2 cache.
+.It Li L2_RQSTS.ALL_RFO
+.Pq Event 24H , Umask 0CH
+Counts all L2 store RFO requests.
+.It Li L2_RQSTS.CODE_RD_HIT
+.Pq Event 24H , Umask 10H
+Number of instruction fetches that hit the L2 cache.
+.It Li L2_RQSTS.CODE_RD_MISS
+.Pq Event 24H , Umask 20H
+Number of instruction fetches that missed the L2 cache.
+.It Li L2_RQSTS.ALL_CODE_RD
+.Pq Event 24H , Umask 30H
+Counts all L2 code requests.
+.It Li L2_RQSTS.PF_HIT
+.Pq Event 24H , Umask 40H
+Counts all L2 HW prefetcher requests that hit L2.
+.It Li L2_RQSTS.PF_MISS
+.Pq Event 24H , Umask 80H
+Counts all L2 HW prefetcher requests that missed L2.
+.It Li L2_RQSTS.ALL_PF
+.Pq Event 24H , Umask C0H
+Counts all L2 HW prefetcher requests.
+.It Li L2_STORE_LOCK_RQSTS.MISS
+.Pq Event 27H , Umask 01H
+RFOs that miss cache lines.
+.It Li L2_STORE_LOCK_RQSTS.HIT_M
+.Pq Event 27H , Umask 08H
+RFOs that hit cache lines in M state.
+.It Li L2_STORE_LOCK_RQSTS.ALL
+.Pq Event 27H , Umask 0FH
+RFOs that access cache lines in any state.
+.It Li L2_L1D_WB_RQSTS.MISS
+.Pq Event 28H , Umask 01H
+Not rejected writebacks that missed LLC.
+.It Li L2_L1D_WB_RQSTS.HIT_E
+.Pq Event 28H , Umask 04H
+Not rejected writebacks from L1D to L2 cache lines in E state.
+.It Li L2_L1D_WB_RQSTS.HIT_M
+.Pq Event 28H , Umask 08H
+Not rejected writebacks from L1D to L2 cache lines in M state.
+.It Li L2_L1D_WB_RQSTS.ALL
+.Pq Event 28H , Umask 0FH
+Not rejected writebacks from L1D to L2 cache lines in any state.
+.It Li LONGEST_LAT_CACHE.REFERENCE
+.Pq Event 2EH , Umask 4FH
+This event counts requests originating from the core that reference a cache
+line in the last level cache.
+.It Li LONGEST_LAT_CACHE.MISS
+.Pq Event 2EH , Umask 41H
+This event counts each cache miss condition for references to the last level
+cache.
+.It Li CPU_CLK_UNHALTED.THREAD_P
+.Pq Event 3CH , Umask 00H
+Counts the number of thread cycles while the thread is not in a halt state.
+The thread enters the halt state when it is running the HLT instruction. The
+core frequency may change from time to time due to power or thermal
+throttling.
+.It Li CPU_CLK_THREAD_UNHALTED.REF_XCLK
+.Pq Event 3CH , Umask 01H
+Increments at the frequency of XCLK (100 MHz) when not halted.
+.It Li L1D_PEND_MISS.PENDING
+.Pq Event 48H , Umask 01H
+Increments the number of outstanding L1D misses every cycle. Set Cmaks = 1
+and Edge =1 to count occurrences.
+Counter 2 only.
+Set Cmask = 1 to count cycles.
+.It Li DTLB_STORE_MISSES.MISS_CAUSES_A_WALK
+.Pq Event 49H , Umask 01H
+Miss in all TLB levels causes an page walk of any page size (4K/2M/4M/1G).
+.It Li DTLB_STORE_MISSES.WALK_COMPLETED
+.Pq Event 49H , Umask 02H
+Miss in all TLB levels causes a page walk that completes of any page size
+(4K/2M/4M/1G).
+.It Li DTLB_STORE_MISSES.WALK_DURATION
+.Pq Event 49H , Umask 04H
+Cycles PMH is busy with this walk.
+.It Li DTLB_STORE_MISSES.STLB_HIT
+.Pq Event 49H , Umask 10H
+Store operations that miss the first TLB level but hit the second and do not
+cause page walks.
+.It Li LOAD_HIT_PRE.SW_PF
+.Pq Event 4CH , Umask 01H
+Non-SW-prefetch load dispatches that hit fill buffer allocated for S/W prefetch.
+.It Li LOAD_HIT_PRE.HW_PF
+.Pq Event 4CH , Umask 02H
+Non-SW-prefetch load dispatches that hit fill buffer allocated for H/W prefetch.
+.It Li L1D.REPLACEMENT
+.Pq Event 51H , Umask 01H
+Counts the number of lines brought into the L1 data cache.
+.It Li MOVE_ELIMINATION.INT_NOT_ELIMINATED
+.Pq Event 58H , Umask 01H
+Number of integer Move Elimination candidate uops that were not eliminated.
+.It Li MOVE_ELIMINATION.SIMD_NOT_ELIMINATED
+.Pq Event 58H , Umask 02H
+Number of SIMD Move Elimination candidate uops that were not eliminated.
+.It Li MOVE_ELIMINATION.INT_ELIMINATED
+.Pq Event 58H , Umask 04H
+Number of integer Move Elimination candidate uops that were eliminated.
+.It Li MOVE_ELIMINATION.SIMD_ELIMINATED
+.Pq Event 58H , Umask 08H
+Number of SIMD Move Elimination candidate uops that were eliminated.
+.It Li CPL_CYCLES.RING0
+.Pq Event 5CH , Umask 01H
+Unhalted core cycles when the thread is in ring 0.
+Use Edge to count transition.
+.It Li CPL_CYCLES.RING123
+.Pq Event 5CH , Umask 02H
+Unhalted core cycles when the thread is not in ring 0.
+.It Li RS_EVENTS.EMPTY_CYCLES
+.Pq Event 5EH , Umask 01H
+Cycles the RS is empty for the thread.
+.It Li DTLB_LOAD_MISSES.STLB_HIT
+.Pq Event 5FH , Umask 04H
+Counts load operations that missed 1st level DTLB but hit the 2nd level.
+.It Li OFFCORE_REQUESTS_OUTSTANDING.DEMAND_DATA_RD
+.Pq Event 60H , Umask 01H
+Offcore outstanding Demand Data Read transactions in SQ to uncore. Set
+Cmask=1 to count cycles.
+.It Li OFFCORE_REQUESTS_OUTSTANDING.DEMAND_CODE_RD
+.Pq Event 60H , Umask 02H
+Offcore outstanding Demand Code Read transactions in SQ to uncore. Set
+Cmask=1 to count cycles.
+.It Li OFFCORE_REQUESTS_OUTSTANDING.DEMAND_RFO
+.Pq Event 60H , Umask 04H
+Offcore outstanding RFO store transactions in SQ to uncore. Set Cmask=1 to
+count cycles.
+.It Li OFFCORE_REQUESTS_OUTSTANDING.ALL_DATA_RD
+.Pq Event 60H , Umask 08H
+Offcore outstanding cacheable data read transactions in SQ to uncore. Set
+Cmask=1 to count cycles.
+.It Li LOCK_CYCLES.SPLIT_LOCK_UC_LOCK_DURATION
+.Pq Event 63H , Umask 01H
+Cycles in which the L1D and L2 are locked, due to a UC lock or split lock.
+.It Li LOCK_CYCLES.CACHE_LOCK_DURATION
+.Pq Event 63H , Umask 02H
+Cycles in which the L1D is locked.
+.It Li IDQ.EMPTY
+.Pq Event 79H , Umask 02H
+Counts cycles the IDQ is empty.
+.It Li IDQ.MITE_UOPS
+.Pq Event 79H , Umask 04H
+Increment each cycle # of uops delivered to IDQ from MITE path.
+Can combine Umask 04H and 20H.
+Set Cmask = 1 to count cycles.
+.It Li IDQ.DSB_UOPS
+.Pq Event 79H , Umask 08H
+Increment each cycle. # of uops delivered to IDQ from DSB path.
+Can combine Umask 08H and 10H
+Set Cmask = 1 to count cycles.
+.It Li IDQ.MS_DSB_UOPS
+.Pq Event 79H , Umask 10H
+Increment each cycle # of uops delivered to IDQ when MS_busy by DSB. Set
+Cmask = 1 to count cycles. Add Edge=1 to count # of delivery.
+Can combine Umask 04H, 08H.
+.It Li IDQ.MS_MITE_UOPS
+.Pq Event 79H , Umask 20H
+Increment each cycle # of uops delivered to IDQ when MS_busy by MITE. Set
+Cmask = 1 to count cycles.
+Can combine Umask 04H, 08H.
+.It Li IDQ.MS_UOPS
+.Pq Event 79H , Umask 30H
+Increment each cycle # of uops delivered to IDQ from MS by either DSB or
+MITE. Set Cmask = 1 to count cycles.
+Can combine Umask 04H, 08H.
+.It Li IDQ.ALL_DSB_CYCLES_ANY_UOPS
+.Pq Event 79H , Umask 18H
+Counts cycles DSB is delivered at least one uops. Set Cmask = 1.
+.It Li IDQ.ALL_DSB_CYCLES_4_UOPS
+.Pq Event 79H , Umask 18H
+Counts cycles DSB is delivered four uops. Set Cmask = 4.
+.It Li IDQ.ALL_MITE_CYCLES_ANY_UOPS
+.Pq Event 79H , Umask 24H
+Counts cycles MITE is delivered at least one uops. Set Cmask = 1.
+.It Li IDQ.ALL_MITE_CYCLES_4_UOPS
+.Pq Event 79H , Umask 24H
+Counts cycles MITE is delivered four uops. Set Cmask = 4.
+.It Li IDQ.MITE_ALL_UOPS
+.Pq Event 79H , Umask 3CH
+# of uops delivered to IDQ from any path.
+.It Li ICACHE.MISSES
+.Pq Event 80H , Umask 02H
+Number of Instruction Cache, Streaming Buffer and Victim Cache Misses.
+Includes UC accesses.
+.It Li ITLB_MISSES.MISS_CAUSES_A_WALK
+.Pq Event 85H , Umask 01H
+Misses in all ITLB levels that cause page walks.
+.It Li ITLB_MISSES.WALK_COMPLETED
+.Pq Event 85H , Umask 02H
+Misses in all ITLB levels that cause completed page walks.
+.It Li ITLB_MISSES.WALK_DURATION
+.Pq Event 85H , Umask 04H
+Cycle PMH is busy with a walk.
+.It Li ITLB_MISSES.STLB_HIT
+.Pq Event 85H , Umask 10H
+Number of cache load STLB hits. No page walk.
+.It Li ILD_STALL.LCP
+.Pq Event 87H , Umask 01H
+Stalls caused by changing prefix length of the instruction.
+.It Li ILD_STALL.IQ_FULL
+.Pq Event 87H , Umask 04H
+Stall cycles due to IQ is full.
+.It Li BR_INST_EXEC.COND
+.Pq Event 88H , Umask 01H
+Qualify conditional near branch instructions executed, but not necessarily
+retired.
+Must combine with umask 40H, 80H.
+.It Li BR_INST_EXEC.DIRECT_JMP
+.Pq Event 88H , Umask 02H
+Qualify all unconditional near branch instructions excluding calls and
+indirect branches.
+Must combine with umask 80H.
+.It Li BR_INST_EXEC.INDIRECT_JMP_NON_CALL_RET
+.Pq Event 88H , Umask 04H
+Qualify executed indirect near branch instructions that are not calls nor
+returns.
+Must combine with umask 80H.
+.It Li BR_INST_EXEC.RETURN_NEAR
+.Pq Event 88H , Umask 08H
+Qualify indirect near branches that have a return mnemonic.
+Must combine with umask 80H.
+.It Li BR_INST_EXEC.DIRECT_NEAR_CALL
+.Pq Event 88H , Umask 10H
+Qualify unconditional near call branch instructions, excluding non call
+branch, executed.
+Must combine with umask 80H.
+.It Li BR_INST_EXEC.INDIRECT_NEAR_CALL
+.Pq Event 88H , Umask 20H
+Qualify indirect near calls, including both register and memory indirect,
+executed.
+Must combine with umask 80H.
+.It Li BR_INST_EXEC.NONTAKEN
+.Pq Event 88H , Umask 40H
+Qualify non-taken near branches executed.
+Applicable to umask 01H only.
+.It Li BR_INST_EXEC.TAKEN
+.Pq Event 88H , Umask 80H
+Qualify taken near branches executed. Must combine with 01H,02H, 04H, 08H,
+10H, 20H.
+.It Li BR_INST_EXEC.ALL_BRANCHES
+.Pq Event 88H , Umask FFH
+Counts all near executed branches (not necessarily retired).
+.It Li BR_MISP_EXEC.COND
+.Pq Event 89H , Umask 01H
+Qualify conditional near branch instructions mispredicted.
+Must combine with umask 40H, 80H.
+.It Li BR_MISP_EXEC.INDIRECT_JMP_NON_CALL_RET
+.Pq Event 89H , Umask 04H
+Qualify mispredicted indirect near branch instructions that are not calls
+nor returns.
+Must combine with umask 80H.
+.It Li BR_MISP_EXEC.RETURN_NEAR
+.Pq Event 89H , Umask 08H
+Qualify mispredicted indirect near branches that have a return mnemonic.
+Must combine with umask 80H.
+.It Li BR_MISP_EXEC.DIRECT_NEAR_CALL
+.Pq Event 89H , Umask 10H
+Qualify mispredicted unconditional near call branch instructions, excluding
+non call branch, executed.
+Must combine with umask 80H.
+.It Li BR_MISP_EXEC.INDIRECT_NEAR_CALL
+.Pq Event 89H , Umask 20H
+Qualify mispredicted indirect near calls, including both register and memory
+indirect, executed.
+Must combine with umask 80H.
+.It Li BR_MISP_EXEC.NONTAKEN
+.Pq Event 89H , Umask 40H
+Qualify mispredicted non-taken near branches executed.
+Applicable to umask 01H only.
+.It Li BR_MISP_EXEC.TAKEN
+.Pq Event 89H , Umask 80H
+Qualify mispredicted taken near branches executed. Must combine with
+01H,02H, 04H, 08H, 10H, 20H.
+.It Li BR_MISP_EXEC.ALL_BRANCHES
+.Pq Event 89H , Umask FFH
+Counts all near executed branches (not necessarily retired).
+.It Li IDQ_UOPS_NOT_DELIVERED.CORE
+.Pq Event 9CH , Umask 01H
+Count number of non-delivered uops to RAT per thread.
+Use Cmask to qualify uop b/w.
+.It Li UOPS_DISPATCHED_PORT.PORT_0
+.Pq Event A1H , Umask 01H
+Cycles which a Uop is dispatched on port 0.
+.It Li UOPS_DISPATCHED_PORT.PORT_1
+.Pq Event A1H , Umask 02H
+Cycles which a Uop is dispatched on port 1.
+.It Li UOPS_DISPATCHED_PORT.PORT_2_LD
+.Pq Event A1H , Umask 04H
+Cycles which a load uop is dispatched on port 2.
+.It Li UOPS_DISPATCHED_PORT.PORT_2_STA
+.Pq Event A1H , Umask 08H
+Cycles which a store address uop is dispatched on port 2.
+.It Li UOPS_DISPATCHED_PORT.PORT_2
+.Pq Event A1H , Umask 0CH
+Cycles which a Uop is dispatched on port 2.
+.It Li UOPS_DISPATCHED_PORT.PORT_3_LD
+.Pq Event A1H , Umask 10H
+Cycles which a load uop is dispatched on port 3.
+.It Li UOPS_DISPATCHED_PORT.PORT_3_STA
+.Pq Event A1H , Umask 20H
+Cycles which a store address uop is dispatched on port 3.
+.It Li UOPS_DISPATCHED_PORT.PORT_3
+.Pq Event A1H , Umask 30H
+Cycles which a Uop is dispatched on port 3.
+.It Li UOPS_DISPATCHED_PORT.PORT_4
+.Pq Event A1H , Umask 40H
+Cycles which a Uop is dispatched on port 4.
+.It Li UOPS_DISPATCHED_PORT.PORT_5
+.Pq Event A1H , Umask 80H
+Cycles which a Uop is dispatched on port 5.
+.It Li RESOURCE_STALLS.ANY
+.Pq Event A2H , Umask 01H
+Cycles Allocation is stalled due to Resource Related reason.
+.It Li RESOURCE_STALLS.RS
+.Pq Event A2H , Umask 04H
+Cycles stalled due to no eligible RS entry available.
+.It Li RESOURCE_STALLS.SB
+.Pq Event A2H , Umask 08H
+Cycles stalled due to no store buffers available. (not including draining
+form sync).
+.It Li RESOURCE_STALLS.ROB
+.Pq Event A2H , Umask 10H
+Cycles stalled due to re-order buffer full.
+.It Li CYCLE_ACTIVITY.CYCLES_L2_PENDING
+.Pq Event A3H , Umask 01H
+Cycles with pending L2 miss loads. Set AnyThread to count per core.
+.It Li CYCLE_ACTIVITY.CYCLES_LDM_PENDING
+.Pq Event A3H , Umask 02H
+Cycles with pending memory loads. Set AnyThread to count per core.
+.It Li CYCLE_ACTIVITY.CYCLES_NO_EXECUTE
+.Pq Event A3H , Umask 04H
+Cycles of dispatch stalls. Set AnyThread to count per core.
+.It Li CYCLE_ACTIVITY.CYCLES_L1D_PENDING
+.Pq Event A3H , Umask 08H
+Cycles with pending L1 cache miss loads. Set AnyThread to count per core.
+.It Li DSB2MITE_SWITCHES.COUNT
+.Pq Event ABH , Umask 01H
+Number of DSB to MITE switches.
+.It Li DSB2MITE_SWITCHES.PENALTY_CYCLES
+.Pq Event ABH , Umask 02H
+Cycles DSB to MITE switches caused delay.
+.It Li DSB_FILL.EXCEED_DSB_LINES
+.Pq Event ACH , Umask 08H
+DSB Fill encountered > 3 DSB lines.
+.It Li ITLB.ITLB_FLUSH
+.Pq Event AEH , Umask 01H
+Counts the number of ITLB flushes, includes 4k/2M/4M pages.
+.It Li OFFCORE_REQUESTS.DEMAND_DATA_RD
+.Pq Event B0H , Umask 01H
+Demand data read requests sent to uncore.
+.It Li OFFCORE_REQUESTS.DEMAND_CODE_RD
+.Pq Event B0H , Umask 02H
+Demand code read requests sent to uncore.
+.It Li OFFCORE_REQUESTS.DEMAND_RFO
+.Pq Event B0H , Umask 04H
+Demand RFO read requests sent to uncore, including regular RFOs, locks,
+ItoM.
+.It Li OFFCORE_REQUESTS.ALL_DATA_RD
+.Pq Event B0H , Umask 08H
+Data read requests sent to uncore (demand and prefetch).
+.It Li UOPS_EXECUTED.THREAD
+.Pq Event B1H , Umask 01H
+Counts total number of uops to be executed per-thread each cycle. Set Cmask
+= 1, INV =1 to count stall cycles.
+.It Li UOPS_EXECUTED.CORE
+.Pq Event B1H , Umask 02H
+Counts total number of uops to be executed per-core each cycle.
+Do not need to set ANY.
+.It Li OFF_CORE_RESPONSE_0
+.Pq Event B7H , Umask 01H
+Off-core Response Performance Monitoring.
+PMC0 only.
+Requires programming MSR 01A6H.
+.It Li OFF_CORE_RESPONSE_1
+.Pq Event BBH , Umask 01H
+Off-core Response Performance Monitoring.
+PMC3 only.
+Requires programming MSR 01A7H.
+.It Li TLB_FLUSH.DTLB_THREAD
+.Pq Event BDH , Umask 01H
+DTLB flush attempts of the thread- specific entries.
+.It Li TLB_FLUSH.STLB_ANY
+.Pq Event BDH , Umask 20H
+Count number of STLB flush attempts.
+.It Li INST_RETIRED.ANY_P
+.Pq Event C0H , Umask 00H
+Number of instructions at retirement.
+.It Li INST_RETIRED.ALL
+.Pq Event C0H , Umask 01H
+Precise instruction retired event with HW to reduce effect of PEBS shadow in
+IP distribution.
+PMC1 only.
+Must quiesce other PMCs.
+.It Li OTHER_ASSISTS.AVX_STORE
+.Pq Event C1H , Umask 08H
+Number of assists associated with 256-bit AVX store operations.
+.It Li OTHER_ASSISTS.AVX_TO_SSE
+.Pq Event C1H , Umask 10H
+Number of transitions from AVX- 256 to legacy SSE when penalty applicable.
+.It Li OTHER_ASSISTS.SSE_TO_AVX
+.Pq Event C1H , Umask 20H
+Number of transitions from SSE to AVX-256 when penalty applicable.
+.It Li UOPS_RETIRED.ALL
+.Pq Event C2H , Umask 01H
+Counts the number of micro-ops retired, Use cmask=1 and invert to count
+active cycles or stalled cycles.
+Supports PEBS, use Any=1 for core granular.
+.It Li UOPS_RETIRED.RETIRE_SLOTS
+.Pq Event C2H , Umask 02H
+Counts the number of retirement slots used each cycle.
+.It Li MACHINE_CLEARS.MEMORY_ORDERING
+.Pq Event C3H , Umask 02H
+Counts the number of machine clears due to memory order conflicts.
+.It Li MACHINE_CLEARS.SMC
+.Pq Event C3H , Umask 04H
+Number of self-modifying-code machine clears detected.
+.It Li MACHINE_CLEARS.MASKMOV
+.Pq Event C3H , Umask 20H
+Counts the number of executed AVX masked load operations that refer to an
+illegal address range with the mask bits set to 0.
+.It Li BR_INST_RETIRED.ALL_BRANCHES
+.Pq Event C4H , Umask 00H
+Branch instructions at retirement.
+.It Li BR_INST_RETIRED.CONDITIONAL
+.Pq Event C4H , Umask 01H
+Counts the number of conditional branch instructions retired.
+Supports PEBS.
+.It Li BR_INST_RETIRED.NEAR_CALL
+.Pq Event C4H , Umask 02H
+Direct and indirect near call instructions retired.
+.It Li BR_INST_RETIRED.ALL_BRANCHES
+.Pq Event C4H , Umask 04H
+Counts the number of branch instructions retired.
+.It Li BR_INST_RETIRED.NEAR_RETURN
+.Pq Event C4H , Umask 08H
+Counts the number of near return instructions retired.
+.It Li BR_INST_RETIRED.NOT_TAKEN
+.Pq Event C4H , Umask 10H
+Counts the number of not taken branch instructions retired.
+.It Li BR_INST_RETIRED.NEAR_TAKEN
+.Pq Event C4H , Umask 20H
+Number of near taken branches retired.
+.It Li BR_INST_RETIRED.FAR_BRANCH
+.Pq Event C4H , Umask 40H
+Number of far branches retired.
+.It Li BR_MISP_RETIRED.ALL_BRANCHES
+.Pq Event C5H , Umask 00H
+Mispredicted branch instructions at retirement.
+.It Li BR_MISP_RETIRED.CONDITIONAL
+.Pq Event C5H , Umask 01H
+Mispredicted conditional branch instructions retired.
+Supports PEBS.
+.It Li BR_MISP_RETIRED.NEAR_CALL
+.Pq Event C5H , Umask 02H
+Direct and indirect mispredicted near call instructions retired.
+.It Li BR_MISP_RETIRED.ALL_BRANCHES
+.Pq Event C5H , Umask 04H
+Mispredicted macro branch instructions retired.
+.It Li BR_MISP_RETIRED.NOT_TAKEN
+.Pq Event C5H , Umask 10H
+Mispredicted not taken branch instructions retired.
+.It Li BR_MISP_RETIRED.TAKEN
+.Pq Event C5H , Umask 20H
+Mispredicted taken branch instructions retired.
+.It Li FP_ASSIST.X87_OUTPUT
+.Pq Event CAH , Umask 02H
+Number of X87 FP assists due to Output values.
+.It Li FP_ASSIST.X87_INPUT
+.Pq Event CAH , Umask 04H
+Number of X87 FP assists due to input values.
+.It Li FP_ASSIST.SIMD_OUTPUT
+.Pq Event CAH , Umask 08H
+Number of SIMD FP assists due to Output values.
+.It Li FP_ASSIST.SIMD_INPUT
+.Pq Event CAH , Umask 10H
+Number of SIMD FP assists due to input values.
+.It Li FP_ASSIST.ANY
+.Pq Event CAH , Umask 1EH
+Cycles with any input/output SSE* or FP assists.
+.It Li ROB_MISC_EVENTS.LBR_INSERTS
+.Pq Event CCH , Umask 20H
+Count cases of saving new LBR records by hardware.
+.It Li MEM_TRANS_RETIRED.LOAD_LATENCY
+.Pq Event CDH , Umask 01H
+Sample loads with specified latency threshold.
+PMC3 only.
+Specify threshold in MSR 0x3F6.
+.It Li MEM_TRANS_RETIRED.PRECISE_STORE
+.Pq Event CDH , Umask 02H
+Sample stores and collect precise store operation via PEBS record.
+PMC3 only.
+.It Li MEM_UOP_RETIRED.LOADS
+.Pq Event D0H , Umask 01H
+Qualify retired memory uops that are loads. Combine with umask 10H, 20H,
+40H, 80H.
+Supports PEBS.
+.It Li MEM_UOP_RETIRED.STORES
+.Pq Event D0H , Umask 02H
+Qualify retired memory uops that are stores. Combine with umask 10H, 20H,
+40H, 80H.
+.It Li MEM_UOP_RETIRED.STLB_MISS
+.Pq Event D0H , Umask 10H
+Qualify retired memory uops with STLB miss. Must combine with umask 01H,
+02H, to produce counts.
+.It Li MEM_UOP_RETIRED.LOCK
+.Pq Event D0H , Umask 20H
+Qualify retired memory uops with lock. Must combine with umask 01H, 02H, to
+produce counts.
+.It Li MEM_UOP_RETIRED.SPLIT
+.Pq Event D0H , Umask 40H
+Qualify retired memory uops with line split. Must combine with umask 01H,
+02H, to produce counts.
+.It Li MEM_UOP_RETIRED.ALL
+.Pq Event D0H , Umask 80H
+Qualify any retired memory uops. Must combine with umask 01H, 02H, to
+produce counts.
+.It Li MEM_LOAD_UOPS_RETIRED.L1_HIT
+.Pq Event D1H , Umask 01H
+Retired load uops with L1 cache hits as data sources.
+Supports PEBS.
+.It Li MEM_LOAD_UOPS_RETIRED.L2_HIT
+.Pq Event D1H , Umask 02H
+Retired load uops with L2 cache hits as data sources.
+.It Li MEM_LOAD_UOPS_RETIRED.LLC_HIT
+.Pq Event D1H , Umask 04H
+Retired load uops whose data source was LLC hit with no snoop required.
+.It Li MEM_LOAD_UOPS_RETIRED.LLC_MISS
+.Pq Event D1H , Umask 20H
+Retired load uops whose data source is LLC miss.
+.It Li MEM_LOAD_UOPS_RETIRED.HIT_LFB
+.Pq Event D1H , Umask 40H
+Retired load uops which data sources were load uops missed L1 but hit FB due
+to preceding miss to the same cache line with data not ready.
+.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_MISS
+.Pq Event D2H , Umask 01H
+Retired load uops which data sources were LLC hit and cross-core snoop
+missed in on-pkg core cache.
+Supports PEBS.
+.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_HIT
+.Pq Event D2H , Umask 02H
+Retired load uops which data sources were LLC and cross-core snoop hits in
+on-pkg core cache.
+Supports PEBS.
+.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_HITM
+.Pq Event D2H , Umask 04H
+Retired load uops which data sources were HitM responses from shared LLC.
+.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_NONE
+.Pq Event D2H , Umask 08H
+Retired load uops which data sources were hits in LLC without snoops
+required.
+.It Li MEM_LOAD_UOPS_LLC_MISS_RETIRED.LOCAL_DRAM
+.Pq Event D3H , Umask 01H
+Retired load uops which data sources missed LLC but serviced from local
+dram.
+Supports PEBS.
+.It Li MEM_LOAD_UOPS_LLC_MISS_RETIRED.REMOTE_DRAM
+.Pq Event D3H , Umask 04H
+Retired load uops whose data source was remote DRAM.
+.It Li MEM_LOAD_UOPS_LLC_MISS_RETIRED.REMOTE_HITM
+.Pq Event D3H , Umask 10H
+Retired load uops whose data source was remote HITM.
+.It Li MEM_LOAD_UOPS_LLC_MISS_RETIRED.REMOTE_FWD
+.Pq Event D3H , Umask 20H
+Retired load uops whose data source was forwards from a remote cache.
+.It Li BACLEARS.ANY
+.Pq Event E6H , Umask 1FH
+Number of front end re-steers due to BPU misprediction.
+.It Li L2_TRANS.DEMAND_DATA_RD
+.Pq Event F0H , Umask 01H
+Demand Data Read requests that access L2 cache.
+.It Li L2_TRANS.RFO
+.Pq Event F0H , Umask 02H
+RFO requests that access L2 cache.
+.It Li L2_TRANS.CODE_RD
+.Pq Event F0H , Umask 04H
+L2 cache accesses when fetching instructions.
+.It Li L2_TRANS.ALL_PF
+.Pq Event F0H , Umask 08H
+Any MLC or LLC HW prefetch accessing L2, including rejects.
+.It Li L2_TRANS.L1D_WB
+.Pq Event F0H , Umask 10H
+L1D writebacks that access L2 cache.
+.It Li L2_TRANS.L2_FILL
+.Pq Event F0H , Umask 20H
+L2 fill requests that access L2 cache.
+.It Li L2_TRANS.L2_WB
+.Pq Event F0H , Umask 40H
+L2 writebacks that access L2 cache.
+.It Li L2_TRANS.ALL_REQUESTS
+.Pq Event F0H , Umask 80H
+Transactions accessing L2 pipe.
+.It Li L2_LINES_IN.I
+.Pq Event F1H , Umask 01H
+L2 cache lines in I state filling L2.
+Counting does not cover rejects.
+.It Li L2_LINES_IN.S
+.Pq Event F1H , Umask 02H
+L2 cache lines in S state filling L2.
+Counting does not cover rejects.
+.It Li L2_LINES_IN.E
+.Pq Event F1H , Umask 04H
+L2 cache lines in E state filling L2.
+Counting does not cover rejects.
+.It Li L2_LINES_IN.ALL
+.Pq Event F1H , Umask 07H
+L2 cache lines filling L2.
+Counting does not cover rejects.
+.It Li L2_LINES_OUT.DEMAND_CLEAN
+.Pq Event F2H , Umask 01H
+Clean L2 cache lines evicted by demand.
+.It Li L2_LINES_OUT.DEMAND_DIRTY
+.Pq Event F2H , Umask 02H
+Dirty L2 cache lines evicted by demand.
+.It Li L2_LINES_OUT.PF_CLEAN
+.Pq Event F2H , Umask 04H
+Clean L2 cache lines evicted by the MLC prefetcher.
+.It Li L2_LINES_OUT.PF_DIRTY
+.Pq Event F2H , Umask 08H
+Dirty L2 cache lines evicted by the MLC prefetcher.
+.It Li L2_LINES_OUT.DIRTY_ALL
+.Pq Event F2H , Umask 0AH
+Dirty L2 cache lines filling the L2.
+.El
+.Sh SEE ALSO
+.Xr pmc 3 ,
+.Xr pmc.atom 3 ,
+.Xr pmc.core 3 ,
+.Xr pmc.iaf 3 ,
+.Xr pmc.ucf 3 ,
+.Xr pmc.k7 3 ,
+.Xr pmc.k8 3 ,
+.Xr pmc.p4 3 ,
+.Xr pmc.p5 3 ,
+.Xr pmc.p6 3 ,
+.Xr pmc.corei7 3 ,
+.Xr pmc.corei7uc 3 ,
+.Xr pmc.ivybridge 3 ,
+.Xr pmc.sandybridge 3 ,
+.Xr pmc.sandybridgeuc 3 ,
+.Xr pmc.sandybridgexeon 3 ,
+.Xr pmc.westmere 3 ,
+.Xr pmc.westmereuc 3 ,
+.Xr pmc.soft 3 ,
+.Xr pmc.tsc 3 ,
+.Xr pmc_cpuinfo 3 ,
+.Xr pmclog 3 ,
+.Xr hwpmc 4
+.Sh HISTORY
+The
+.Nm pmc
+library first appeared in
+.Fx 6.0 .
+.Sh AUTHORS
+The
+.Lb libpmc
+library was written by
+.An "Joseph Koshy"
+.Aq jkoshy@FreeBSD.org .
+The support for the Ivy Bridge Xeon
+microarchitecture was written by
+.An "Hiren Panchasara"
+.Aq hiren.panchasara@gmail.com .
diff --git a/lib/libpmc/pmc.sandybridge.3 b/lib/libpmc/pmc.sandybridge.3
index 62f8f28de0bc..931bd9d5f4e7 100644
--- a/lib/libpmc/pmc.sandybridge.3
+++ b/lib/libpmc/pmc.sandybridge.3
@@ -926,6 +926,8 @@ Split locks in SQ.
.Xr pmc.corei7 3 ,
.Xr pmc.corei7uc 3 ,
.Xr pmc.iaf 3 ,
+.Xr pmc.ivybridge 3 ,
+.Xr pmc.ivybridgexeon 3 ,
.Xr pmc.k7 3 ,
.Xr pmc.k8 3 ,
.Xr pmc.p4 3 ,
diff --git a/lib/libpmc/pmc.sandybridgexeon.3 b/lib/libpmc/pmc.sandybridgexeon.3
index c62a82bcb01c..0ddaedaf8764 100644
--- a/lib/libpmc/pmc.sandybridgexeon.3
+++ b/lib/libpmc/pmc.sandybridgexeon.3
@@ -997,6 +997,7 @@ Split locks in SQ.
.Xr pmc.corei7 3 ,
.Xr pmc.corei7uc 3 ,
.Xr pmc.ivybridge 3 ,
+.Xr pmc.ivybridgexeon 3 ,
.Xr pmc.sandybridge 3 ,
.Xr pmc.sandybridgeuc 3 ,
.Xr pmc.westmere 3 ,
diff --git a/lib/libproc/proc_bkpt.c b/lib/libproc/proc_bkpt.c
index e16b0fcf80a3..c15e53ce38d7 100644
--- a/lib/libproc/proc_bkpt.c
+++ b/lib/libproc/proc_bkpt.c
@@ -47,6 +47,9 @@ __FBSDID("$FreeBSD$");
#elif defined(__mips__)
#define BREAKPOINT_INSTR 0xd /* break */
#define BREAKPOINT_INSTR_SZ 4
+#elif defined(__powerpc__)
+#define BREAKPOINT_INSTR 0x7fe00008 /* trap */
+#define BREAKPOINT_INSTR_SZ 4
#else
#error "Add support for your architecture"
#endif
diff --git a/lib/libproc/proc_regs.c b/lib/libproc/proc_regs.c
index c299b9b49203..aac012555a41 100644
--- a/lib/libproc/proc_regs.c
+++ b/lib/libproc/proc_regs.c
@@ -60,6 +60,8 @@ proc_regget(struct proc_handle *phdl, proc_reg_t reg, unsigned long *regvalue)
*regvalue = regs.r_eip;
#elif defined(__mips__)
*regvalue = regs.r_regs[PC];
+#elif defined(__powerpc__)
+ *regvalue = regs.pc;
#endif
break;
case REG_SP:
@@ -69,6 +71,8 @@ proc_regget(struct proc_handle *phdl, proc_reg_t reg, unsigned long *regvalue)
*regvalue = regs.r_esp;
#elif defined(__mips__)
*regvalue = regs.r_regs[SP];
+#elif defined(__powerpc__)
+ *regvalue = regs.fixreg[1];
#endif
break;
default:
@@ -99,6 +103,8 @@ proc_regset(struct proc_handle *phdl, proc_reg_t reg, unsigned long regvalue)
regs.r_eip = regvalue;
#elif defined(__mips__)
regs.r_regs[PC] = regvalue;
+#elif defined(__powerpc__)
+ regs.pc = regvalue;
#endif
break;
case REG_SP:
@@ -108,6 +114,8 @@ proc_regset(struct proc_handle *phdl, proc_reg_t reg, unsigned long regvalue)
regs.r_esp = regvalue;
#elif defined(__mips__)
regs.r_regs[PC] = regvalue;
+#elif defined(__powerpc__)
+ regs.fixreg[1] = regvalue;
#endif
break;
default:
diff --git a/lib/libproc/proc_rtld.c b/lib/libproc/proc_rtld.c
index 2a9ed39965b0..52590493c4c2 100644
--- a/lib/libproc/proc_rtld.c
+++ b/lib/libproc/proc_rtld.c
@@ -44,7 +44,8 @@ map_iter(const rd_loadobj_t *lop, void *arg)
if (phdl->nobjs >= phdl->rdobjsz) {
phdl->rdobjsz *= 2;
- phdl->rdobjs = realloc(phdl->rdobjs, phdl->rdobjsz);
+ phdl->rdobjs = reallocf(phdl->rdobjs, sizeof(*phdl->rdobjs) *
+ phdl->rdobjsz);
if (phdl->rdobjs == NULL)
return (-1);
}
diff --git a/lib/libproc/test/t1-bkpt/t1-bkpt.c b/lib/libproc/test/t1-bkpt/t1-bkpt.c
index 37a9fcf67668..1cd4d17f5612 100644
--- a/lib/libproc/test/t1-bkpt/t1-bkpt.c
+++ b/lib/libproc/test/t1-bkpt/t1-bkpt.c
@@ -36,7 +36,7 @@
#include <string.h>
#include <libproc.h>
-int
+int __noinline
t1_bkpt_t()
{
printf("TEST OK\n");
diff --git a/lib/libradius/Makefile b/lib/libradius/Makefile
index d71d8f2022ed..cb68eaa32b1a 100644
--- a/lib/libradius/Makefile
+++ b/lib/libradius/Makefile
@@ -35,6 +35,7 @@ MAN= libradius.3 radius.conf.5
MLINKS+=libradius.3 rad_acct_open.3 \
libradius.3 rad_add_server.3 \
+ libradius.3 rad_add_server_ex.3 \
libradius.3 rad_auth_open.3 \
libradius.3 rad_bind_to.3 \
libradius.3 rad_close.3 \
diff --git a/lib/libradius/libradius.3 b/lib/libradius/libradius.3
index ae0ee2406032..f3ff70058d44 100644
--- a/lib/libradius/libradius.3
+++ b/lib/libradius/libradius.3
@@ -37,6 +37,8 @@
.Fn rad_acct_open "void"
.Ft int
.Fn rad_add_server "struct rad_handle *h" "const char *host" "int port" "const char *secret" "int timeout" "int max_tries"
+.Ft int
+.Fn rad_add_server_ex "struct rad_handle *h" "const char *host" "int port" "const char *secret" "int timeout" "int max_tries" "int dead_time" "struct in_addr *bindto"
.Ft "struct rad_handle *"
.Fn rad_auth_open "void"
.Ft void
@@ -153,7 +155,12 @@ is used.
returns 0 on success, or \-1 if an error occurs.
.Pp
The library can also be configured programmatically by calls to
-.Fn rad_add_server .
+.Fn rad_add_server
+or
+.Fn rad_add_server_ex .
+.Fn rad_add_server
+is a backward compatible function, implemented via
+.Fn rad_add_server_ex .
The
.Fa host
parameter specifies the server host, either as a fully qualified
@@ -188,11 +195,20 @@ The maximum number of repeated
requests to make before giving up is passed into the
.Fa max_tries
parameter.
+Time interval in seconds when the server will not be requested
+if it is marked as dead (did not answer on the last try) set with
+.Fa dead_time
+parameter.
+.Fa bindto
+parameter is an IP address on the multihomed host that is used as
+a source address for all requests.
.Fn rad_add_server
returns 0 on success, or \-1 if an error occurs.
.Pp
.Fn rad_add_server
-may be called multiple times, and it may be used together with
+or
+.Fn rad_add_server_ex
+may be called multiple times, and they may be used together with
.Fn rad_config .
At most 10 servers may be specified.
When multiple servers are given, they are tried in round-robin
diff --git a/lib/libradius/radius.conf.5 b/lib/libradius/radius.conf.5
index 6ac84e07cc3f..6f89c3ae2df3 100644
--- a/lib/libradius/radius.conf.5
+++ b/lib/libradius/radius.conf.5
@@ -44,7 +44,7 @@ Leading
white space is ignored, as are empty lines and lines containing
only comments.
.Pp
-A RADIUS server is described by three to five fields on a line:
+A RADIUS server is described by three to seven fields on a line:
.Pp
.Bl -item -offset indent -compact
.It
@@ -57,6 +57,10 @@ Shared secret
Timeout
.It
Retries
+.It
+Dead time
+.It
+Bind address
.El
.Pp
The fields are separated by white space.
@@ -139,6 +143,13 @@ If omitted, it defaults to 3 attempts.
Note,
this is the total number of attempts and not the number of retries.
.Pp
+The sixth field contains a decimal integer specifying a time interval
+in seconds when the server will not requested if it was inaccessible
+on the last try. 0 means ask always.
+.Pp
+The seventh field contains an IP address on multihomed host. All
+requests will be binded to this IP.
+.Pp
Up to 10 RADIUS servers may be specified for each service type.
The servers are tried in
round-robin fashion, until a valid response is received or the
@@ -161,6 +172,9 @@ acct radius1.domain.com OurLittleSecret
# timeout and maximum tries:
auth auth.domain.com:1645 "I can't see you" 5 4
+# As above but set dead time and bind address
+auth auth.domain.com:1645 "I can't see you" 5 4 60 192.168.1.8
+
# A server specified by its IP address:
auth 192.168.27.81 $X*#..38947ax-+=
.Ed
diff --git a/lib/libradius/radlib.c b/lib/libradius/radlib.c
index 46a9b58c9e2f..55c6f5cb04a1 100644
--- a/lib/libradius/radlib.c
+++ b/lib/libradius/radlib.c
@@ -43,6 +43,8 @@ __FBSDID("$FreeBSD$");
#include <md5.h>
#endif
+#define MAX_FIELDS 7
+
/* We need the MPPE_KEY_LEN define */
#include <netgraph/ng_mppc.h>
@@ -379,6 +381,18 @@ int
rad_add_server(struct rad_handle *h, const char *host, int port,
const char *secret, int timeout, int tries)
{
+ struct in_addr bindto;
+ bindto.s_addr = INADDR_ANY;
+
+ return rad_add_server_ex(h, host, port, secret, timeout, tries,
+ DEAD_TIME, &bindto);
+}
+
+int
+rad_add_server_ex(struct rad_handle *h, const char *host, int port,
+ const char *secret, int timeout, int tries, int dead_time,
+ struct in_addr *bindto)
+{
struct rad_server *srvp;
if (h->num_servers >= MAXSERVERS) {
@@ -421,6 +435,10 @@ rad_add_server(struct rad_handle *h, const char *host, int port,
srvp->timeout = timeout;
srvp->max_tries = tries;
srvp->num_tries = 0;
+ srvp->is_dead = 0;
+ srvp->dead_time = dead_time;
+ srvp->next_probe = 0;
+ srvp->bindto = bindto->s_addr;
h->num_servers++;
return 0;
}
@@ -441,6 +459,13 @@ rad_close(struct rad_handle *h)
free(h);
}
+void
+rad_bind_to(struct rad_handle *h, in_addr_t addr)
+{
+
+ h->bindto = addr;
+}
+
int
rad_config(struct rad_handle *h, const char *path)
{
@@ -459,7 +484,7 @@ rad_config(struct rad_handle *h, const char *path)
linenum = 0;
while (fgets(buf, sizeof buf, fp) != NULL) {
int len;
- char *fields[5];
+ char *fields[MAX_FIELDS];
int nfields;
char msg[ERRSIZE];
char *type;
@@ -468,11 +493,15 @@ rad_config(struct rad_handle *h, const char *path)
char *secret;
char *timeout_str;
char *maxtries_str;
+ char *dead_time_str;
+ char *bindto_str;
char *end;
char *wanttype;
unsigned long timeout;
unsigned long maxtries;
+ unsigned long dead_time;
int port;
+ struct in_addr bindto;
int i;
linenum++;
@@ -491,7 +520,7 @@ rad_config(struct rad_handle *h, const char *path)
buf[len - 1] = '\0';
/* Extract the fields from the line. */
- nfields = split(buf, fields, 5, msg, sizeof msg);
+ nfields = split(buf, fields, MAX_FIELDS, msg, sizeof msg);
if (nfields == -1) {
generr(h, "%s:%d: %s", path, linenum, msg);
retval = -1;
@@ -507,7 +536,7 @@ rad_config(struct rad_handle *h, const char *path)
*/
if (strcmp(fields[0], "auth") != 0 &&
strcmp(fields[0], "acct") != 0) {
- if (nfields >= 5) {
+ if (nfields >= MAX_FIELDS) {
generr(h, "%s:%d: invalid service type", path,
linenum);
retval = -1;
@@ -529,6 +558,8 @@ rad_config(struct rad_handle *h, const char *path)
secret = fields[2];
timeout_str = fields[3];
maxtries_str = fields[4];
+ dead_time_str = fields[5];
+ bindto_str = fields[6];
/* Ignore the line if it is for the wrong service type. */
wanttype = h->type == RADIUS_AUTH ? "auth" : "acct";
@@ -570,8 +601,30 @@ rad_config(struct rad_handle *h, const char *path)
} else
maxtries = MAXTRIES;
- if (rad_add_server(h, host, port, secret, timeout, maxtries) ==
- -1) {
+ if (dead_time_str != NULL) {
+ dead_time = strtoul(dead_time_str, &end, 10);
+ if (*end != '\0') {
+ generr(h, "%s:%d: invalid dead_time", path,
+ linenum);
+ retval = -1;
+ break;
+ }
+ } else
+ dead_time = DEAD_TIME;
+
+ if (bindto_str != NULL) {
+ bindto.s_addr = inet_addr(bindto_str);
+ if (bindto.s_addr == INADDR_NONE) {
+ generr(h, "%s:%d: invalid bindto", path,
+ linenum);
+ retval = -1;
+ break;
+ }
+ } else
+ bindto.s_addr = INADDR_ANY;
+
+ if (rad_add_server_ex(h, host, port, secret, timeout, maxtries,
+ dead_time, &bindto) == -1) {
strcpy(msg, h->errmsg);
generr(h, "%s:%d: %s", path, linenum, msg);
retval = -1;
@@ -596,7 +649,9 @@ int
rad_continue_send_request(struct rad_handle *h, int selected, int *fd,
struct timeval *tv)
{
- int n;
+ int n, cur_srv;
+ time_t now;
+ struct sockaddr_in sin;
if (h->type == RADIUS_SERVER) {
generr(h, "denied function call");
@@ -621,19 +676,61 @@ rad_continue_send_request(struct rad_handle *h, int selected, int *fd,
}
}
- if (h->try == h->total_tries) {
- generr(h, "No valid RADIUS responses received");
- return -1;
- }
-
/*
* Scan round-robin to the next server that has some
* tries left. There is guaranteed to be one, or we
* would have exited this loop by now.
*/
- while (h->servers[h->srv].num_tries >= h->servers[h->srv].max_tries)
- if (++h->srv >= h->num_servers)
- h->srv = 0;
+ cur_srv = h->srv;
+ now = time(NULL);
+ if (h->servers[h->srv].num_tries >= h->servers[h->srv].max_tries) {
+ /* Set next probe time for this server */
+ if (h->servers[h->srv].dead_time) {
+ h->servers[h->srv].is_dead = 1;
+ h->servers[h->srv].next_probe = now +
+ h->servers[h->srv].dead_time;
+ }
+ do {
+ h->srv++;
+ if (h->srv >= h->num_servers)
+ h->srv = 0;
+ if (h->servers[h->srv].is_dead == 0)
+ break;
+ if (h->servers[h->srv].dead_time &&
+ h->servers[h->srv].next_probe <= now) {
+ h->servers[h->srv].is_dead = 0;
+ h->servers[h->srv].num_tries = 0;
+ break;
+ }
+ } while (h->srv != cur_srv);
+
+ if (h->srv == cur_srv) {
+ generr(h, "No valid RADIUS responses received");
+ return (-1);
+ }
+ }
+
+ /* Rebind */
+ if (h->bindto != h->servers[h->srv].bindto) {
+ h->bindto = h->servers[h->srv].bindto;
+ close(h->fd);
+ if ((h->fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
+ generr(h, "Cannot create socket: %s", strerror(errno));
+ return -1;
+ }
+ memset(&sin, 0, sizeof sin);
+ sin.sin_len = sizeof sin;
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = h->bindto;
+ sin.sin_port = 0;
+ if (bind(h->fd, (const struct sockaddr *)&sin,
+ sizeof sin) == -1) {
+ generr(h, "bind: %s", strerror(errno));
+ close(h->fd);
+ h->fd = -1;
+ return (-1);
+ }
+ }
if (h->out[POS_CODE] == RAD_ACCESS_REQUEST) {
/* Insert the scrambled password into the request */
@@ -641,9 +738,11 @@ rad_continue_send_request(struct rad_handle *h, int selected, int *fd,
insert_scrambled_password(h, h->srv);
}
insert_message_authenticator(h, 0);
+
if (h->out[POS_CODE] != RAD_ACCESS_REQUEST) {
/* Insert the request authenticator into the request */
- insert_request_authenticator(h, h->srv);
+ memset(&h->out[POS_AUTH], 0, LEN_AUTH);
+ insert_request_authenticator(h, 0);
}
/* Send the request */
@@ -654,7 +753,6 @@ rad_continue_send_request(struct rad_handle *h, int selected, int *fd,
tv->tv_sec = 1; /* Do not wait full timeout if send failed. */
else
tv->tv_sec = h->servers[h->srv].timeout;
- h->try++;
h->servers[h->srv].num_tries++;
tv->tv_usec = 0;
*fd = h->fd;
@@ -740,6 +838,10 @@ rad_create_request(struct rad_handle *h, int code)
generr(h, "denied function call");
return (-1);
}
+ if (h->num_servers == 0) {
+ generr(h, "No RADIUS servers specified");
+ return (-1);
+ }
h->out[POS_CODE] = code;
h->out[POS_IDENT] = ++h->ident;
if (code == RAD_ACCESS_REQUEST) {
@@ -756,16 +858,9 @@ rad_create_request(struct rad_handle *h, int code)
clear_password(h);
h->authentic_pos = 0;
h->out_created = 1;
- h->bindto = INADDR_ANY;
return 0;
}
-void
-rad_bind_to(struct rad_handle *h, in_addr_t addr)
-{
- h->bindto = addr;
-}
-
int
rad_create_response(struct rad_handle *h, int code)
{
@@ -793,6 +888,15 @@ rad_cvt_addr(const void *data)
return value;
}
+struct in6_addr
+rad_cvt_addr6(const void *data)
+{
+ struct in6_addr value;
+
+ memcpy(&value.s6_addr, data, sizeof value.s6_addr);
+ return value;
+}
+
u_int32_t
rad_cvt_int(const void *data)
{
@@ -848,6 +952,8 @@ int
rad_init_send_request(struct rad_handle *h, int *fd, struct timeval *tv)
{
int srv;
+ time_t now;
+ struct sockaddr_in sin;
if (h->type == RADIUS_SERVER) {
generr(h, "denied function call");
@@ -855,8 +961,6 @@ rad_init_send_request(struct rad_handle *h, int *fd, struct timeval *tv)
}
/* Make sure we have a socket to use */
if (h->fd == -1) {
- struct sockaddr_in sin;
-
if ((h->fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
generr(h, "Cannot create socket: %s", strerror(errno));
return -1;
@@ -902,21 +1006,30 @@ rad_init_send_request(struct rad_handle *h, int *fd, struct timeval *tv)
h->out[POS_LENGTH] = h->out_len >> 8;
h->out[POS_LENGTH+1] = h->out_len;
- /*
- * Count the total number of tries we will make, and zero the
- * counter for each server.
- */
- h->total_tries = 0;
- for (srv = 0; srv < h->num_servers; srv++) {
- h->total_tries += h->servers[srv].max_tries;
+ h->srv = 0;
+ now = time(NULL);
+ for (srv = 0; srv < h->num_servers; srv++)
h->servers[srv].num_tries = 0;
- }
- if (h->total_tries == 0) {
- generr(h, "No RADIUS servers specified");
- return -1;
+ /* Find a first good server. */
+ for (srv = 0; srv < h->num_servers; srv++) {
+ if (h->servers[srv].is_dead == 0)
+ break;
+ if (h->servers[srv].dead_time &&
+ h->servers[srv].next_probe <= now) {
+ h->servers[srv].is_dead = 0;
+ break;
+ }
+ h->srv++;
}
- h->try = h->srv = 0;
+ /* If all servers was dead on the last probe, try from beginning */
+ if (h->srv == h->num_servers) {
+ for (srv = 0; srv < h->num_servers; srv++) {
+ h->servers[srv].is_dead = 0;
+ h->servers[srv].next_probe = 0;
+ }
+ h->srv = 0;
+ }
return rad_continue_send_request(h, 0, fd, tv);
}
@@ -946,6 +1059,7 @@ rad_auth_open(void)
h->type = RADIUS_AUTH;
h->out_created = 0;
h->eap_msg = 0;
+ h->bindto = INADDR_ANY;
}
return h;
}
@@ -987,6 +1101,13 @@ rad_put_addr(struct rad_handle *h, int type, struct in_addr addr)
}
int
+rad_put_addr6(struct rad_handle *h, int type, struct in6_addr addr)
+{
+
+ return rad_put_attr(h, type, &addr.s6_addr, sizeof addr.s6_addr);
+}
+
+int
rad_put_attr(struct rad_handle *h, int type, const void *value, size_t len)
{
int result;
@@ -1229,6 +1350,15 @@ rad_put_vendor_addr(struct rad_handle *h, int vendor, int type,
}
int
+rad_put_vendor_addr6(struct rad_handle *h, int vendor, int type,
+ struct in6_addr addr)
+{
+
+ return (rad_put_vendor_attr(h, vendor, type, &addr.s6_addr,
+ sizeof addr.s6_addr));
+}
+
+int
rad_put_vendor_attr(struct rad_handle *h, int vendor, int type,
const void *value, size_t len)
{
diff --git a/lib/libradius/radlib.h b/lib/libradius/radlib.h
index f9e451b465d9..a47931878922 100644
--- a/lib/libradius/radlib.h
+++ b/lib/libradius/radlib.h
@@ -194,6 +194,9 @@ __BEGIN_DECLS
struct rad_handle *rad_acct_open(void);
int rad_add_server(struct rad_handle *,
const char *, int, const char *, int, int);
+int rad_add_server_ex(struct rad_handle *,
+ const char *, int, const char *, int, int,
+ int, struct in_addr *);
struct rad_handle *rad_auth_open(void);
void rad_bind_to(struct rad_handle *, in_addr_t);
void rad_close(struct rad_handle *);
@@ -203,6 +206,7 @@ int rad_continue_send_request(struct rad_handle *, int,
int rad_create_request(struct rad_handle *, int);
int rad_create_response(struct rad_handle *, int);
struct in_addr rad_cvt_addr(const void *);
+struct in6_addr rad_cvt_addr6(const void *);
u_int32_t rad_cvt_int(const void *);
char *rad_cvt_string(const void *, size_t);
int rad_get_attr(struct rad_handle *, const void **,
@@ -211,6 +215,7 @@ int rad_init_send_request(struct rad_handle *, int *,
struct timeval *);
struct rad_handle *rad_open(void); /* Deprecated, == rad_auth_open */
int rad_put_addr(struct rad_handle *, int, struct in_addr);
+int rad_put_addr6(struct rad_handle *, int, struct in6_addr);
int rad_put_attr(struct rad_handle *, int,
const void *, size_t);
int rad_put_int(struct rad_handle *, int, u_int32_t);
diff --git a/lib/libradius/radlib_private.h b/lib/libradius/radlib_private.h
index a76e594aa613..bfbbbd17ca89 100644
--- a/lib/libradius/radlib_private.h
+++ b/lib/libradius/radlib_private.h
@@ -46,6 +46,7 @@
#define RADIUS_PORT 1812
#define RADACCT_PORT 1813
#define TIMEOUT 3 /* In seconds */
+#define DEAD_TIME 0
/* Limits */
#define ERRSIZE 128 /* Maximum error message length */
@@ -68,6 +69,10 @@ struct rad_server {
int timeout; /* Timeout in seconds */
int max_tries; /* Number of tries before giving up */
int num_tries; /* Number of tries so far */
+ int is_dead; /* The server did not answer last time */
+ time_t dead_time; /* Don't try this server for the time period if it is dead */
+ time_t next_probe; /* Time of a next probe after failure */
+ in_addr_t bindto; /* Bind to address */
};
struct rad_handle {
@@ -88,11 +93,9 @@ struct rad_handle {
unsigned char in[MSGSIZE]; /* Response received */
int in_len; /* Length of response */
int in_pos; /* Current position scanning attrs */
- int total_tries; /* How many requests we'll send */
- int try; /* How many requests we've sent */
int srv; /* Server number we did last */
int type; /* Handle type */
- in_addr_t bindto; /* Bind to address */
+ in_addr_t bindto; /* Current bind address */
};
struct vendor_attribute {
diff --git a/lib/libradius/radlib_vs.h b/lib/libradius/radlib_vs.h
index 8b3a75e79d6a..0acfb0e10e00 100644
--- a/lib/libradius/radlib_vs.h
+++ b/lib/libradius/radlib_vs.h
@@ -73,6 +73,7 @@ struct rad_handle;
__BEGIN_DECLS
int rad_get_vendor_attr(u_int32_t *, const void **, size_t *);
int rad_put_vendor_addr(struct rad_handle *, int, int, struct in_addr);
+int rad_put_vendor_addr6(struct rad_handle *, int, int, struct in6_addr);
int rad_put_vendor_attr(struct rad_handle *, int, int, const void *,
size_t);
int rad_put_vendor_int(struct rad_handle *, int, int, u_int32_t);
diff --git a/lib/libstand/Makefile b/lib/libstand/Makefile
index fd720a9e4a86..807136d116dc 100644
--- a/lib/libstand/Makefile
+++ b/lib/libstand/Makefile
@@ -61,7 +61,20 @@ SRCS+= bcmp.c bcopy.c bzero.c ffs.c memccpy.c memchr.c memcmp.c memcpy.c \
.endif
.if ${MACHINE_CPUARCH} == "arm"
.PATH: ${.CURDIR}/../libc/arm/gen
+
+.if ${MK_ARM_EABI} == "no"
SRCS+= divsi3.S
+.else
+# Compiler support functions
+.PATH: ${.CURDIR}/../../contrib/compiler-rt/lib/
+SRCS+= divmoddi4.c divmodsi4.c divdi3.c divsi3.c moddi3.c modsi3.c
+SRCS+= udivmoddi4.c udivmodsi4.c udivdi3.c udivsi3.c umoddi3.c umodsi3.c
+
+.PATH: ${.CURDIR}/../../contrib/compiler-rt/lib/arm/
+SRCS+= aeabi_idivmod.S aeabi_ldivmod.S aeabi_uidivmod.S aeabi_uldivmod.S
+SRCS+= aeabi_memcmp.S aeabi_memcpy.S aeabi_memmove.S aeabi_memset.S
+.endif
+
.endif
.if ${MACHINE_CPUARCH} == "ia64"
.PATH: ${.CURDIR}/../libc/ia64/string
diff --git a/lib/libstand/amd64/_setjmp.S b/lib/libstand/amd64/_setjmp.S
new file mode 100644
index 000000000000..e841f493f6fb
--- /dev/null
+++ b/lib/libstand/amd64/_setjmp.S
@@ -0,0 +1,93 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+ .asciz "@(#)_setjmp.s 5.1 (Berkeley) 4/23/90"
+#endif /* LIBC_SCCS and not lint */
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * C library -- _setjmp, _longjmp
+ *
+ * _longjmp(a,v)
+ * will generate a "return(v)" from the last call to
+ * _setjmp(a)
+ * by restoring registers from the environment 'a'.
+ * The previous signal state is NOT restored.
+ */
+
+ENTRY(_setjmp)
+ movq %rdi,%rax
+ movq 0(%rsp),%rdx /* retval */
+ movq %rdx, 0(%rax) /* 0; retval */
+ movq %rbx, 8(%rax) /* 1; rbx */
+ movq %rsp,16(%rax) /* 2; rsp */
+ movq %rbp,24(%rax) /* 3; rbp */
+ movq %r12,32(%rax) /* 4; r12 */
+ movq %r13,40(%rax) /* 5; r13 */
+ movq %r14,48(%rax) /* 6; r14 */
+ movq %r15,56(%rax) /* 7; r15 */
+ fnstcw 64(%rax) /* 8; fpu cw */
+ stmxcsr 68(%rax) /* and mxcsr */
+ xorq %rax,%rax
+ ret
+END(_setjmp)
+
+ .weak CNAME(_longjmp)
+ENTRY(_longjmp)
+ movq %rdi,%rdx
+ /* Restore the mxcsr, but leave exception flags intact. */
+ stmxcsr -4(%rsp)
+ movl 68(%rdx),%eax
+ andl $0xffffffc0,%eax
+ movl -4(%rsp),%edi
+ andl $0x3f,%edi
+ xorl %eax,%edi
+ movl %edi,-4(%rsp)
+ ldmxcsr -4(%rsp)
+ movq %rsi,%rax /* retval */
+ movq 0(%rdx),%rcx
+ movq 8(%rdx),%rbx
+ movq 16(%rdx),%rsp
+ movq 24(%rdx),%rbp
+ movq 32(%rdx),%r12
+ movq 40(%rdx),%r13
+ movq 48(%rdx),%r14
+ movq 56(%rdx),%r15
+ fldcw 64(%rdx)
+ testq %rax,%rax
+ jnz 1f
+ incq %rax
+1: movq %rcx,0(%rsp)
+ ret
+END(_longjmp)
diff --git a/lib/libstand/if_ether.h b/lib/libstand/if_ether.h
deleted file mode 100644
index 373f95affbc2..000000000000
--- a/lib/libstand/if_ether.h
+++ /dev/null
@@ -1,261 +0,0 @@
-/* $NetBSD: if_ether.h,v 1.25 1997/01/17 17:06:06 mikel Exp $ */
-
-/*
- * Copyright (c) 1982, 1986, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)if_ether.h 8.1 (Berkeley) 6/10/93
- *
- * $FreeBSD$
- */
-
-/*
- * Ethernet address - 6 octets
- * this is only used by the ethers(3) functions.
- */
-struct ether_addr {
- u_int8_t ether_addr_octet[6];
-};
-
-/*
- * Structure of a 10Mb/s Ethernet header.
- */
-#define ETHER_ADDR_LEN 6
-
-struct ether_header {
- u_int8_t ether_dhost[ETHER_ADDR_LEN];
- u_int8_t ether_shost[ETHER_ADDR_LEN];
- u_int16_t ether_type;
-};
-
-#define ETHERTYPE_PUP 0x0200 /* PUP protocol */
-#define ETHERTYPE_IP 0x0800 /* IP protocol */
-#define ETHERTYPE_ARP 0x0806 /* address resolution protocol */
-#define ETHERTYPE_REVARP 0x8035 /* reverse addr resolution protocol */
-
-/*
- * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
- * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
- * by an ETHER type (as given above) and then the (variable-length) header.
- */
-#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
-#define ETHERTYPE_NTRAILER 16
-
-#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
-
-#define ETHERMTU 1500
-#define ETHERMIN (60-14)
-
-#ifdef _KERNEL
-/*
- * Macro to map an IP multicast address to an Ethernet multicast address.
- * The high-order 25 bits of the Ethernet address are statically assigned,
- * and the low-order 23 bits are taken from the low end of the IP address.
- */
-#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
- /* struct in_addr *ipaddr; */ \
- /* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \
-{ \
- (enaddr)[0] = 0x01; \
- (enaddr)[1] = 0x00; \
- (enaddr)[2] = 0x5e; \
- (enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f; \
- (enaddr)[4] = ((u_int8_t *)ipaddr)[2]; \
- (enaddr)[5] = ((u_int8_t *)ipaddr)[3]; \
-}
-#endif
-
-/*
- * Ethernet Address Resolution Protocol.
- *
- * See RFC 826 for protocol description. Structure below is adapted
- * to resolving internet addresses. Field names used correspond to
- * RFC 826.
- */
-struct ether_arp {
- struct arphdr ea_hdr; /* fixed-size header */
- u_int8_t arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */
- u_int8_t arp_spa[4]; /* sender protocol address */
- u_int8_t arp_tha[ETHER_ADDR_LEN]; /* target hardware address */
- u_int8_t arp_tpa[4]; /* target protocol address */
-};
-#define arp_hrd ea_hdr.ar_hrd
-#define arp_pro ea_hdr.ar_pro
-#define arp_hln ea_hdr.ar_hln
-#define arp_pln ea_hdr.ar_pln
-#define arp_op ea_hdr.ar_op
-
-/*
- * Structure shared between the ethernet driver modules and
- * the address resolution code. For example, each ec_softc or il_softc
- * begins with this structure.
- */
-struct arpcom {
- struct ifnet ac_if; /* network-visible interface */
- u_int8_t ac_enaddr[ETHER_ADDR_LEN]; /* ethernet hardware address */
- char ac__pad[2]; /* be nice to m68k ports */
- LIST_HEAD(, ether_multi) ac_multiaddrs; /* list of ether multicast addrs */
- int ac_multicnt; /* length of ac_multiaddrs list */
-};
-
-struct llinfo_arp {
- LIST_ENTRY(llinfo_arp) la_list;
- struct rtentry *la_rt;
- struct mbuf *la_hold; /* last packet until resolved/timeout */
- long la_asked; /* last time we QUERIED for this addr */
-#define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
-};
-
-struct sockaddr_inarp {
- u_int8_t sin_len;
- u_int8_t sin_family;
- u_int16_t sin_port;
- struct in_addr sin_addr;
- struct in_addr sin_srcaddr;
- u_int16_t sin_tos;
- u_int16_t sin_other;
-#define SIN_PROXY 1
-};
-
-/*
- * IP and ethernet specific routing flags
- */
-#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */
-#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */
-
-#ifdef _KERNEL
-u_int8_t etherbroadcastaddr[ETHER_ADDR_LEN];
-u_int8_t ether_ipmulticast_min[ETHER_ADDR_LEN];
-u_int8_t ether_ipmulticast_max[ETHER_ADDR_LEN];
-struct ifqueue arpintrq;
-
-void arpwhohas(struct arpcom *, struct in_addr *);
-void arpintr(void);
-int arpresolve(struct arpcom *,
- struct rtentry *, struct mbuf *, struct sockaddr *, u_char *, struct llentry **);
-void arp_ifinit(struct arpcom *, struct ifaddr *);
-void arp_rtrequest(int, struct rtentry *, struct sockaddr *);
-
-int ether_addmulti(struct ifreq *, struct arpcom *);
-int ether_delmulti(struct ifreq *, struct arpcom *);
-#endif /* _KERNEL */
-
-/*
- * Ethernet multicast address structure. There is one of these for each
- * multicast address or range of multicast addresses that we are supposed
- * to listen to on a particular interface. They are kept in a linked list,
- * rooted in the interface's arpcom structure. (This really has nothing to
- * do with ARP, or with the Internet address family, but this appears to be
- * the minimally-disrupting place to put it.)
- */
-struct ether_multi {
- u_int8_t enm_addrlo[ETHER_ADDR_LEN]; /* low or only address of range */
- u_int8_t enm_addrhi[ETHER_ADDR_LEN]; /* high or only address of range */
- struct arpcom *enm_ac; /* back pointer to arpcom */
- u_int enm_refcount; /* no. claims to this addr/range */
- LIST_ENTRY(ether_multi) enm_list;
-};
-
-/*
- * Structure used by macros below to remember position when stepping through
- * all of the ether_multi records.
- */
-struct ether_multistep {
- struct ether_multi *e_enm;
-};
-
-/*
- * Macro for looking up the ether_multi record for a given range of Ethernet
- * multicast addresses connected to a given arpcom structure. If no matching
- * record is found, "enm" returns NULL.
- */
-#define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
- /* u_int8_t addrlo[ETHER_ADDR_LEN]; */ \
- /* u_int8_t addrhi[ETHER_ADDR_LEN]; */ \
- /* struct arpcom *ac; */ \
- /* struct ether_multi *enm; */ \
-{ \
- for ((enm) = (ac)->ac_multiaddrs.lh_first; \
- (enm) != NULL && \
- (bcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 || \
- bcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \
- (enm) = (enm)->enm_list.le_next); \
-}
-
-/*
- * Macro to step through all of the ether_multi records, one at a time.
- * The current position is remembered in "step", which the caller must
- * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step"
- * and get the first record. Both macros return a NULL "enm" when there
- * are no remaining records.
- */
-#define ETHER_NEXT_MULTI(step, enm) \
- /* struct ether_multistep step; */ \
- /* struct ether_multi *enm; */ \
-{ \
- if (((enm) = (step).e_enm) != NULL) \
- (step).e_enm = (enm)->enm_list.le_next; \
-}
-
-#define ETHER_FIRST_MULTI(step, ac, enm) \
- /* struct ether_multistep step; */ \
- /* struct arpcom *ac; */ \
- /* struct ether_multi *enm; */ \
-{ \
- (step).e_enm = (ac)->ac_multiaddrs.lh_first; \
- ETHER_NEXT_MULTI((step), (enm)); \
-}
-
-#ifdef _KERNEL
-void arp_rtrequest(int, struct rtentry *, struct sockaddr *);
-int arpresolve(struct arpcom *, struct rtentry *, struct mbuf *,
- struct sockaddr *, u_char *, struct llentry **);
-void arpintr(void);
-int arpioctl(u_long, caddr_t);
-void arp_ifinit(struct arpcom *, struct ifaddr *);
-void revarpinput(struct mbuf *);
-void in_revarpinput(struct mbuf *);
-void revarprequest(struct ifnet *);
-int revarpwhoarewe(struct ifnet *, struct in_addr *, struct in_addr *);
-int revarpwhoami(struct in_addr *, struct ifnet *);
-int db_show_arptab(void);
-#endif
-
-/*
- * Prototype ethers(3) functions.
- */
-#ifndef _KERNEL
-#include <sys/cdefs.h>
-__BEGIN_DECLS
-char * ether_ntoa(struct ether_addr *);
-struct ether_addr *
- ether_aton(char *);
-int ether_ntohost(char *, struct ether_addr *);
-int ether_hostton(char *, struct ether_addr *);
-int ether_line(char *, struct ether_addr *, char *);
-__END_DECLS
-#endif
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index c29e8c307fc0..937d83f1eb28 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -363,6 +363,12 @@ _libpthread_init(struct pthread *curthread)
_thr_signal_init();
if (_thread_event_mask & TD_CREATE)
_thr_report_creation(curthread, curthread);
+ /*
+ * Always use our rtld lock implementation.
+ * It is faster because it postpones signal handlers
+ * instead of calling sigprocmask(2).
+ */
+ _thr_rtld_init();
}
}
diff --git a/lib/libthr/thread/thr_kern.c b/lib/libthr/thread/thr_kern.c
index 1e7cb5101300..b5a8358b9f09 100644
--- a/lib/libthr/thread/thr_kern.c
+++ b/lib/libthr/thread/thr_kern.c
@@ -57,11 +57,6 @@ _thr_setthreaded(int threaded)
return (0);
__isthreaded = threaded;
- if (threaded != 0) {
- _thr_rtld_init();
- } else {
- _thr_rtld_fini();
- }
return (0);
}
diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c
index 6d96d5e9405e..3f7e19901e2a 100644
--- a/lib/libutil/gr_util.c
+++ b/lib/libutil/gr_util.c
@@ -44,19 +44,12 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
-struct group_storage {
- struct group gr;
- char *members[];
-};
-
static int lockfd = -1;
static char group_dir[PATH_MAX];
static char group_file[PATH_MAX];
static char tempname[PATH_MAX];
static int initialized;
-static const char group_line_format[] = "%s:%s:%ju:";
-
/*
* Initialize statics
*/
@@ -106,10 +99,8 @@ gr_lock(void)
for (;;) {
struct stat st;
- lockfd = open(group_file, O_RDONLY, 0);
- if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
- err(1, "%s", group_file);
- if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) {
+ lockfd = flopen(group_file, O_RDONLY|O_NONBLOCK|O_CLOEXEC, 0);
+ if (lockfd == -1) {
if (errno == EWOULDBLOCK) {
errx(1, "the group file is busy");
} else {
@@ -318,11 +309,14 @@ gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr)
int
gr_mkdb(void)
{
+ if (chmod(tempname, 0644) != 0)
+ return (-1);
+
return (rename(tempname, group_file));
}
/*
- * Clean up. Preserver errno for the caller's convenience.
+ * Clean up. Preserves errno for the caller's convenience.
*/
void
gr_fini(void)
@@ -350,7 +344,6 @@ gr_equal(const struct group *gr1, const struct group *gr2)
{
int gr1_ndx;
int gr2_ndx;
- bool found;
/* Check that the non-member information is the same. */
if (gr1->gr_name == NULL || gr2->gr_name == NULL) {
@@ -371,17 +364,15 @@ gr_equal(const struct group *gr1, const struct group *gr2)
if (gr1->gr_mem != gr2->gr_mem)
return (false);
} else {
- for (found = false, gr1_ndx = 0; gr1->gr_mem[gr1_ndx] != NULL;
- gr1_ndx++) {
- for (gr2_ndx = 0; gr2->gr_mem[gr2_ndx] != NULL;
- gr2_ndx++)
+ for (gr1_ndx = 0; gr1->gr_mem[gr1_ndx] != NULL; gr1_ndx++) {
+ for (gr2_ndx = 0;; gr2_ndx++) {
+ if (gr2->gr_mem[gr2_ndx] == NULL)
+ return (false);
if (strcmp(gr1->gr_mem[gr1_ndx],
gr2->gr_mem[gr2_ndx]) == 0) {
- found = true;
break;
}
- if (!found)
- return (false);
+ }
}
/* Check that group2 does not have more members than group1. */
@@ -398,7 +389,10 @@ gr_equal(const struct group *gr1, const struct group *gr2)
char *
gr_make(const struct group *gr)
{
+ const char *group_line_format = "%s:%s:%ju:";
+ const char *sep;
char *line;
+ char *p;
size_t line_size;
int ndx;
@@ -413,16 +407,18 @@ gr_make(const struct group *gr)
}
/* Create the group line and fill it. */
- if ((line = malloc(line_size)) == NULL)
+ if ((line = p = malloc(line_size)) == NULL)
return (NULL);
- snprintf(line, line_size, group_line_format, gr->gr_name, gr->gr_passwd,
+ p += sprintf(p, group_line_format, gr->gr_name, gr->gr_passwd,
(uintmax_t)gr->gr_gid);
- if (gr->gr_mem != NULL)
+ if (gr->gr_mem != NULL) {
+ sep = "";
for (ndx = 0; gr->gr_mem[ndx] != NULL; ndx++) {
- strcat(line, gr->gr_mem[ndx]);
- if (gr->gr_mem[ndx + 1] != NULL)
- strcat(line, ",");
+ p = stpcpy(p, sep);
+ p = stpcpy(p, gr->gr_mem[ndx]);
+ sep = ",";
}
+ }
return (line);
}
@@ -433,14 +429,14 @@ gr_make(const struct group *gr)
struct group *
gr_dup(const struct group *gr)
{
+ struct group *newgr;
char *dst;
size_t len;
- struct group_storage *gs;
int ndx;
int num_mem;
/* Calculate size of the group. */
- len = sizeof(*gs);
+ len = sizeof(*newgr);
if (gr->gr_name != NULL)
len += strlen(gr->gr_name) + 1;
if (gr->gr_passwd != NULL)
@@ -451,30 +447,72 @@ gr_dup(const struct group *gr)
len += (num_mem + 1) * sizeof(*gr->gr_mem);
} else
num_mem = -1;
-
/* Create new group and copy old group into it. */
- if ((gs = calloc(1, len)) == NULL)
+ if ((newgr = malloc(len)) == NULL)
return (NULL);
- dst = (char *)&gs->members[num_mem + 1];
+ /* point new gr_mem to end of struct + 1 */
+ if (gr->gr_mem != NULL)
+ newgr->gr_mem = (char **)(newgr + 1);
+ else
+ newgr->gr_mem = NULL;
+ /* point dst after the end of all the gr_mem pointers in newgr */
+ dst = (char *)&newgr->gr_mem[num_mem + 1];
if (gr->gr_name != NULL) {
- gs->gr.gr_name = dst;
- dst = stpcpy(gs->gr.gr_name, gr->gr_name) + 1;
+ newgr->gr_name = dst;
+ dst = stpcpy(dst, gr->gr_name) + 1;
+ } else {
+ newgr->gr_name = NULL;
}
if (gr->gr_passwd != NULL) {
- gs->gr.gr_passwd = dst;
- dst = stpcpy(gs->gr.gr_passwd, gr->gr_passwd) + 1;
+ newgr->gr_passwd = dst;
+ dst = stpcpy(dst, gr->gr_passwd) + 1;
+ } else {
+ newgr->gr_passwd = NULL;
}
- gs->gr.gr_gid = gr->gr_gid;
+ newgr->gr_gid = gr->gr_gid;
if (gr->gr_mem != NULL) {
- gs->gr.gr_mem = gs->members;
for (ndx = 0; ndx < num_mem; ndx++) {
- gs->gr.gr_mem[ndx] = dst;
- dst = stpcpy(gs->gr.gr_mem[ndx], gr->gr_mem[ndx]) + 1;
+ newgr->gr_mem[ndx] = dst;
+ dst = stpcpy(dst, gr->gr_mem[ndx]) + 1;
}
- gs->gr.gr_mem[ndx] = NULL;
+ newgr->gr_mem[ndx] = NULL;
}
+ return (newgr);
+}
+
+/*
+ * Add a new member name to a struct group.
+ */
+struct group *
+gr_add(struct group *gr, char *newmember)
+{
+ size_t mlen;
+ int num_mem=0;
+ char **members;
+ struct group *newgr;
- return (&gs->gr);
+ if (newmember == NULL)
+ return(gr_dup(gr));
+
+ if (gr->gr_mem != NULL) {
+ for (num_mem = 0; gr->gr_mem[num_mem] != NULL; num_mem++) {
+ if (strcmp(gr->gr_mem[num_mem], newmember) == 0) {
+ errno = EEXIST;
+ return (NULL);
+ }
+ }
+ }
+ /* Allocate enough for current pointers + 1 more and NULL marker */
+ mlen = (num_mem + 2) * sizeof(*gr->gr_mem);
+ if ((members = malloc(mlen)) == NULL)
+ return (NULL);
+ memcpy(members, gr->gr_mem, num_mem * sizeof(*gr->gr_mem));
+ members[num_mem++] = newmember;
+ members[num_mem] = NULL;
+ gr->gr_mem = members;
+ newgr = gr_dup(gr);
+ free(members);
+ return (newgr);
}
/*
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h
index bf42766a128c..b1b2405fb272 100644
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -166,6 +166,8 @@ int gr_copy(int __ffd, int _tfd, const struct group *_gr,
struct group *_old_gr);
struct group *
gr_dup(const struct group *_gr);
+struct group *
+ gr_add(struct group *_gr, char *_newmember);
int gr_equal(const struct group *_gr1, const struct group *_gr2);
void gr_fini(void);
int gr_init(const char *_dir, const char *_master);
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c
index 4bf3001ffe79..befd1fb02d70 100644
--- a/lib/libutil/pw_util.c
+++ b/lib/libutil/pw_util.c
@@ -179,11 +179,8 @@ pw_lock(void)
for (;;) {
struct stat st;
- lockfd = open(masterpasswd, O_RDONLY, 0);
- if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
- err(1, "%s", masterpasswd);
- /* XXX vulnerable to race conditions */
- if (flock(lockfd, LOCK_EX|LOCK_NB) == -1) {
+ lockfd = flopen(masterpasswd, O_RDONLY|O_NONBLOCK|O_CLOEXEC, 0);
+ if (lockfd == -1) {
if (errno == EWOULDBLOCK) {
errx(1, "the password db file is busy");
} else {
diff --git a/lib/libvmmapi/Makefile b/lib/libvmmapi/Makefile
new file mode 100644
index 000000000000..93d3c85d1566
--- /dev/null
+++ b/lib/libvmmapi/Makefile
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+LIB= vmmapi
+SRCS= vmmapi.c vmmapi_freebsd.c
+INCS= vmmapi.h
+
+WARNS?= 2
+
+CFLAGS+= -I${.CURDIR}
+
+.include <bsd.lib.mk>
diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c
new file mode 100644
index 000000000000..cfb42d09605e
--- /dev/null
+++ b/lib/libvmmapi/vmmapi.c
@@ -0,0 +1,723 @@
+/*-
+ * Copyright (c) 2011 NetApp, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+
+#include <machine/specialreg.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <machine/vmm.h>
+#include <machine/vmm_dev.h>
+
+#include "vmmapi.h"
+
+struct vmctx {
+ int fd;
+ char *name;
+};
+
+#define CREATE(x) sysctlbyname("hw.vmm.create", NULL, NULL, (x), strlen((x)))
+#define DESTROY(x) sysctlbyname("hw.vmm.destroy", NULL, NULL, (x), strlen((x)))
+
+static int
+vm_device_open(const char *name)
+{
+ int fd, len;
+ char *vmfile;
+
+ len = strlen("/dev/vmm/") + strlen(name) + 1;
+ vmfile = malloc(len);
+ assert(vmfile != NULL);
+ snprintf(vmfile, len, "/dev/vmm/%s", name);
+
+ /* Open the device file */
+ fd = open(vmfile, O_RDWR, 0);
+
+ free(vmfile);
+ return (fd);
+}
+
+int
+vm_create(const char *name)
+{
+
+ return (CREATE((char *)name));
+}
+
+struct vmctx *
+vm_open(const char *name)
+{
+ struct vmctx *vm;
+
+ vm = malloc(sizeof(struct vmctx) + strlen(name) + 1);
+ assert(vm != NULL);
+
+ vm->fd = -1;
+ vm->name = (char *)(vm + 1);
+ strcpy(vm->name, name);
+
+ if ((vm->fd = vm_device_open(vm->name)) < 0)
+ goto err;
+
+ return (vm);
+err:
+ vm_destroy(vm);
+ return (NULL);
+}
+
+void
+vm_destroy(struct vmctx *vm)
+{
+ assert(vm != NULL);
+
+ if (vm->fd >= 0)
+ close(vm->fd);
+ DESTROY(vm->name);
+
+ free(vm);
+}
+
+size_t
+vmm_get_mem_total(void)
+{
+ size_t mem_total = 0;
+ size_t oldlen = sizeof(mem_total);
+ int error;
+ error = sysctlbyname("hw.vmm.mem_total", &mem_total, &oldlen, NULL, 0);
+ if (error)
+ return -1;
+ return mem_total;
+}
+
+size_t
+vmm_get_mem_free(void)
+{
+ size_t mem_free = 0;
+ size_t oldlen = sizeof(mem_free);
+ int error;
+ error = sysctlbyname("hw.vmm.mem_free", &mem_free, &oldlen, NULL, 0);
+ if (error)
+ return -1;
+ return mem_free;
+}
+
+int
+vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len)
+{
+ int error;
+ struct vm_memory_segment seg;
+
+ bzero(&seg, sizeof(seg));
+ seg.gpa = gpa;
+ error = ioctl(ctx->fd, VM_GET_MEMORY_SEG, &seg);
+ *ret_len = seg.len;
+ return (error);
+}
+
+int
+vm_setup_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **mapaddr)
+{
+ int error;
+ struct vm_memory_segment seg;
+
+ /*
+ * Create and optionally map 'len' bytes of memory at guest
+ * physical address 'gpa'
+ */
+ bzero(&seg, sizeof(seg));
+ seg.gpa = gpa;
+ seg.len = len;
+ error = ioctl(ctx->fd, VM_MAP_MEMORY, &seg);
+ if (error == 0 && mapaddr != NULL) {
+ *mapaddr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED,
+ ctx->fd, gpa);
+ }
+ return (error);
+}
+
+char *
+vm_map_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len)
+{
+
+ /* Map 'len' bytes of memory at guest physical address 'gpa' */
+ return ((char *)mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED,
+ ctx->fd, gpa));
+}
+
+int
+vm_set_desc(struct vmctx *ctx, int vcpu, int reg,
+ uint64_t base, uint32_t limit, uint32_t access)
+{
+ int error;
+ struct vm_seg_desc vmsegdesc;
+
+ bzero(&vmsegdesc, sizeof(vmsegdesc));
+ vmsegdesc.cpuid = vcpu;
+ vmsegdesc.regnum = reg;
+ vmsegdesc.desc.base = base;
+ vmsegdesc.desc.limit = limit;
+ vmsegdesc.desc.access = access;
+
+ error = ioctl(ctx->fd, VM_SET_SEGMENT_DESCRIPTOR, &vmsegdesc);
+ return (error);
+}
+
+int
+vm_get_desc(struct vmctx *ctx, int vcpu, int reg,
+ uint64_t *base, uint32_t *limit, uint32_t *access)
+{
+ int error;
+ struct vm_seg_desc vmsegdesc;
+
+ bzero(&vmsegdesc, sizeof(vmsegdesc));
+ vmsegdesc.cpuid = vcpu;
+ vmsegdesc.regnum = reg;
+
+ error = ioctl(ctx->fd, VM_GET_SEGMENT_DESCRIPTOR, &vmsegdesc);
+ if (error == 0) {
+ *base = vmsegdesc.desc.base;
+ *limit = vmsegdesc.desc.limit;
+ *access = vmsegdesc.desc.access;
+ }
+ return (error);
+}
+
+int
+vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val)
+{
+ int error;
+ struct vm_register vmreg;
+
+ bzero(&vmreg, sizeof(vmreg));
+ vmreg.cpuid = vcpu;
+ vmreg.regnum = reg;
+ vmreg.regval = val;
+
+ error = ioctl(ctx->fd, VM_SET_REGISTER, &vmreg);
+ return (error);
+}
+
+int
+vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *ret_val)
+{
+ int error;
+ struct vm_register vmreg;
+
+ bzero(&vmreg, sizeof(vmreg));
+ vmreg.cpuid = vcpu;
+ vmreg.regnum = reg;
+
+ error = ioctl(ctx->fd, VM_GET_REGISTER, &vmreg);
+ *ret_val = vmreg.regval;
+ return (error);
+}
+
+int
+vm_get_pinning(struct vmctx *ctx, int vcpu, int *host_cpuid)
+{
+ int error;
+ struct vm_pin vmpin;
+
+ bzero(&vmpin, sizeof(vmpin));
+ vmpin.vm_cpuid = vcpu;
+
+ error = ioctl(ctx->fd, VM_GET_PINNING, &vmpin);
+ *host_cpuid = vmpin.host_cpuid;
+ return (error);
+}
+
+int
+vm_set_pinning(struct vmctx *ctx, int vcpu, int host_cpuid)
+{
+ int error;
+ struct vm_pin vmpin;
+
+ bzero(&vmpin, sizeof(vmpin));
+ vmpin.vm_cpuid = vcpu;
+ vmpin.host_cpuid = host_cpuid;
+
+ error = ioctl(ctx->fd, VM_SET_PINNING, &vmpin);
+ return (error);
+}
+
+int
+vm_run(struct vmctx *ctx, int vcpu, uint64_t rip, struct vm_exit *vmexit)
+{
+ int error;
+ struct vm_run vmrun;
+
+ bzero(&vmrun, sizeof(vmrun));
+ vmrun.cpuid = vcpu;
+ vmrun.rip = rip;
+
+ error = ioctl(ctx->fd, VM_RUN, &vmrun);
+ bcopy(&vmrun.vm_exit, vmexit, sizeof(struct vm_exit));
+ return (error);
+}
+
+static int
+vm_inject_event_real(struct vmctx *ctx, int vcpu, enum vm_event_type type,
+ int vector, int error_code, int error_code_valid)
+{
+ struct vm_event ev;
+
+ bzero(&ev, sizeof(ev));
+ ev.cpuid = vcpu;
+ ev.type = type;
+ ev.vector = vector;
+ ev.error_code = error_code;
+ ev.error_code_valid = error_code_valid;
+
+ return (ioctl(ctx->fd, VM_INJECT_EVENT, &ev));
+}
+
+int
+vm_inject_event(struct vmctx *ctx, int vcpu, enum vm_event_type type,
+ int vector)
+{
+
+ return (vm_inject_event_real(ctx, vcpu, type, vector, 0, 0));
+}
+
+int
+vm_inject_event2(struct vmctx *ctx, int vcpu, enum vm_event_type type,
+ int vector, int error_code)
+{
+
+ return (vm_inject_event_real(ctx, vcpu, type, vector, error_code, 1));
+}
+
+int
+vm_apicid2vcpu(struct vmctx *ctx, int apicid)
+{
+ /*
+ * The apic id associated with the 'vcpu' has the same numerical value
+ * as the 'vcpu' itself.
+ */
+ return (apicid);
+}
+
+int
+vm_lapic_irq(struct vmctx *ctx, int vcpu, int vector)
+{
+ struct vm_lapic_irq vmirq;
+
+ bzero(&vmirq, sizeof(vmirq));
+ vmirq.cpuid = vcpu;
+ vmirq.vector = vector;
+
+ return (ioctl(ctx->fd, VM_LAPIC_IRQ, &vmirq));
+}
+
+int
+vm_inject_nmi(struct vmctx *ctx, int vcpu)
+{
+ struct vm_nmi vmnmi;
+
+ bzero(&vmnmi, sizeof(vmnmi));
+ vmnmi.cpuid = vcpu;
+
+ return (ioctl(ctx->fd, VM_INJECT_NMI, &vmnmi));
+}
+
+static struct {
+ const char *name;
+ int type;
+} capstrmap[] = {
+ { "hlt_exit", VM_CAP_HALT_EXIT },
+ { "mtrap_exit", VM_CAP_MTRAP_EXIT },
+ { "pause_exit", VM_CAP_PAUSE_EXIT },
+ { "unrestricted_guest", VM_CAP_UNRESTRICTED_GUEST },
+ { 0 }
+};
+
+int
+vm_capability_name2type(const char *capname)
+{
+ int i;
+
+ for (i = 0; capstrmap[i].name != NULL && capname != NULL; i++) {
+ if (strcmp(capstrmap[i].name, capname) == 0)
+ return (capstrmap[i].type);
+ }
+
+ return (-1);
+}
+
+const char *
+vm_capability_type2name(int type)
+{
+ int i;
+
+ for (i = 0; capstrmap[i].name != NULL; i++) {
+ if (capstrmap[i].type == type)
+ return (capstrmap[i].name);
+ }
+
+ return (NULL);
+}
+
+int
+vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
+ int *retval)
+{
+ int error;
+ struct vm_capability vmcap;
+
+ bzero(&vmcap, sizeof(vmcap));
+ vmcap.cpuid = vcpu;
+ vmcap.captype = cap;
+
+ error = ioctl(ctx->fd, VM_GET_CAPABILITY, &vmcap);
+ *retval = vmcap.capval;
+ return (error);
+}
+
+int
+vm_set_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap, int val)
+{
+ struct vm_capability vmcap;
+
+ bzero(&vmcap, sizeof(vmcap));
+ vmcap.cpuid = vcpu;
+ vmcap.captype = cap;
+ vmcap.capval = val;
+
+ return (ioctl(ctx->fd, VM_SET_CAPABILITY, &vmcap));
+}
+
+int
+vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func)
+{
+ struct vm_pptdev pptdev;
+
+ bzero(&pptdev, sizeof(pptdev));
+ pptdev.bus = bus;
+ pptdev.slot = slot;
+ pptdev.func = func;
+
+ return (ioctl(ctx->fd, VM_BIND_PPTDEV, &pptdev));
+}
+
+int
+vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func)
+{
+ struct vm_pptdev pptdev;
+
+ bzero(&pptdev, sizeof(pptdev));
+ pptdev.bus = bus;
+ pptdev.slot = slot;
+ pptdev.func = func;
+
+ return (ioctl(ctx->fd, VM_UNBIND_PPTDEV, &pptdev));
+}
+
+int
+vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,
+ vm_paddr_t gpa, size_t len, vm_paddr_t hpa)
+{
+ struct vm_pptdev_mmio pptmmio;
+
+ bzero(&pptmmio, sizeof(pptmmio));
+ pptmmio.bus = bus;
+ pptmmio.slot = slot;
+ pptmmio.func = func;
+ pptmmio.gpa = gpa;
+ pptmmio.len = len;
+ pptmmio.hpa = hpa;
+
+ return (ioctl(ctx->fd, VM_MAP_PPTDEV_MMIO, &pptmmio));
+}
+
+int
+vm_setup_msi(struct vmctx *ctx, int vcpu, int bus, int slot, int func,
+ int destcpu, int vector, int numvec)
+{
+ struct vm_pptdev_msi pptmsi;
+
+ bzero(&pptmsi, sizeof(pptmsi));
+ pptmsi.vcpu = vcpu;
+ pptmsi.bus = bus;
+ pptmsi.slot = slot;
+ pptmsi.func = func;
+ pptmsi.destcpu = destcpu;
+ pptmsi.vector = vector;
+ pptmsi.numvec = numvec;
+
+ return (ioctl(ctx->fd, VM_PPTDEV_MSI, &pptmsi));
+}
+
+int
+vm_setup_msix(struct vmctx *ctx, int vcpu, int bus, int slot, int func,
+ int idx, uint32_t msg, uint32_t vector_control, uint64_t addr)
+{
+ struct vm_pptdev_msix pptmsix;
+
+ bzero(&pptmsix, sizeof(pptmsix));
+ pptmsix.vcpu = vcpu;
+ pptmsix.bus = bus;
+ pptmsix.slot = slot;
+ pptmsix.func = func;
+ pptmsix.idx = idx;
+ pptmsix.msg = msg;
+ pptmsix.addr = addr;
+ pptmsix.vector_control = vector_control;
+
+ return ioctl(ctx->fd, VM_PPTDEV_MSIX, &pptmsix);
+}
+
+uint64_t *
+vm_get_stats(struct vmctx *ctx, int vcpu, struct timeval *ret_tv,
+ int *ret_entries)
+{
+ int error;
+
+ static struct vm_stats vmstats;
+
+ vmstats.cpuid = vcpu;
+
+ error = ioctl(ctx->fd, VM_STATS, &vmstats);
+ if (error == 0) {
+ if (ret_entries)
+ *ret_entries = vmstats.num_entries;
+ if (ret_tv)
+ *ret_tv = vmstats.tv;
+ return (vmstats.statbuf);
+ } else
+ return (NULL);
+}
+
+const char *
+vm_get_stat_desc(struct vmctx *ctx, int index)
+{
+ static struct vm_stat_desc statdesc;
+
+ statdesc.index = index;
+ if (ioctl(ctx->fd, VM_STAT_DESC, &statdesc) == 0)
+ return (statdesc.desc);
+ else
+ return (NULL);
+}
+
+int
+vm_get_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state *state)
+{
+ int error;
+ struct vm_x2apic x2apic;
+
+ bzero(&x2apic, sizeof(x2apic));
+ x2apic.cpuid = vcpu;
+
+ error = ioctl(ctx->fd, VM_GET_X2APIC_STATE, &x2apic);
+ *state = x2apic.state;
+ return (error);
+}
+
+int
+vm_set_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state state)
+{
+ int error;
+ struct vm_x2apic x2apic;
+
+ bzero(&x2apic, sizeof(x2apic));
+ x2apic.cpuid = vcpu;
+ x2apic.state = state;
+
+ error = ioctl(ctx->fd, VM_SET_X2APIC_STATE, &x2apic);
+
+ return (error);
+}
+
+/*
+ * From Intel Vol 3a:
+ * Table 9-1. IA-32 Processor States Following Power-up, Reset or INIT
+ */
+int
+vcpu_reset(struct vmctx *vmctx, int vcpu)
+{
+ int error;
+ uint64_t rflags, rip, cr0, cr4, zero, desc_base, rdx;
+ uint32_t desc_access, desc_limit;
+ uint16_t sel;
+
+ zero = 0;
+
+ rflags = 0x2;
+ error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
+ if (error)
+ goto done;
+
+ rip = 0xfff0;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RIP, rip)) != 0)
+ goto done;
+
+ cr0 = CR0_NE;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR0, cr0)) != 0)
+ goto done;
+
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR3, zero)) != 0)
+ goto done;
+
+ cr4 = 0;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR4, cr4)) != 0)
+ goto done;
+
+ /*
+ * CS: present, r/w, accessed, 16-bit, byte granularity, usable
+ */
+ desc_base = 0xffff0000;
+ desc_limit = 0xffff;
+ desc_access = 0x0093;
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_CS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ sel = 0xf000;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CS, sel)) != 0)
+ goto done;
+
+ /*
+ * SS,DS,ES,FS,GS: present, r/w, accessed, 16-bit, byte granularity
+ */
+ desc_base = 0;
+ desc_limit = 0xffff;
+ desc_access = 0x0093;
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_SS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_DS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_ES,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_FS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ sel = 0;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_SS, sel)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_DS, sel)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_ES, sel)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_FS, sel)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_GS, sel)) != 0)
+ goto done;
+
+ /* General purpose registers */
+ rdx = 0xf00;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RAX, zero)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RBX, zero)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RCX, zero)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RDX, rdx)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RSI, zero)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RDI, zero)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RBP, zero)) != 0)
+ goto done;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RSP, zero)) != 0)
+ goto done;
+
+ /* GDTR, IDTR */
+ desc_base = 0;
+ desc_limit = 0xffff;
+ desc_access = 0;
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GDTR,
+ desc_base, desc_limit, desc_access);
+ if (error != 0)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_IDTR,
+ desc_base, desc_limit, desc_access);
+ if (error != 0)
+ goto done;
+
+ /* TR */
+ desc_base = 0;
+ desc_limit = 0xffff;
+ desc_access = 0x0000008b;
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_TR, 0, 0, desc_access);
+ if (error)
+ goto done;
+
+ sel = 0;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_TR, sel)) != 0)
+ goto done;
+
+ /* LDTR */
+ desc_base = 0;
+ desc_limit = 0xffff;
+ desc_access = 0x00000082;
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_LDTR, desc_base,
+ desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ sel = 0;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_LDTR, 0)) != 0)
+ goto done;
+
+ /* XXX cr2, debug registers */
+
+ error = 0;
+done:
+ return (error);
+}
diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h
new file mode 100644
index 000000000000..de042521aa61
--- /dev/null
+++ b/lib/libvmmapi/vmmapi.h
@@ -0,0 +1,105 @@
+/*-
+ * Copyright (c) 2011 NetApp, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _VMMAPI_H_
+#define _VMMAPI_H_
+
+struct vmctx;
+enum x2apic_state;
+
+int vm_create(const char *name);
+struct vmctx *vm_open(const char *name);
+void vm_destroy(struct vmctx *ctx);
+size_t vmm_get_mem_total(void);
+size_t vmm_get_mem_free(void);
+int vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len);
+/*
+ * Create a memory segment of 'len' bytes in the guest physical address space
+ * at offset 'gpa'.
+ *
+ * If 'mapaddr' is not NULL then this region is mmap'ed into the address
+ * space of the calling process. If there is an mmap error then *mapaddr
+ * will be set to MAP_FAILED.
+ */
+
+int vm_setup_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len,
+ char **mapaddr);
+char * vm_map_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len);
+int vm_set_desc(struct vmctx *ctx, int vcpu, int reg,
+ uint64_t base, uint32_t limit, uint32_t access);
+int vm_get_desc(struct vmctx *ctx, int vcpu, int reg,
+ uint64_t *base, uint32_t *limit, uint32_t *access);
+int vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val);
+int vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *retval);
+int vm_get_pinning(struct vmctx *ctx, int vcpu, int *host_cpuid);
+int vm_set_pinning(struct vmctx *ctx, int vcpu, int host_cpuid);
+int vm_run(struct vmctx *ctx, int vcpu, uint64_t rip,
+ struct vm_exit *ret_vmexit);
+int vm_apicid2vcpu(struct vmctx *ctx, int apicid);
+int vm_inject_event(struct vmctx *ctx, int vcpu, enum vm_event_type type,
+ int vector);
+int vm_inject_event2(struct vmctx *ctx, int vcpu, enum vm_event_type type,
+ int vector, int error_code);
+int vm_lapic_irq(struct vmctx *ctx, int vcpu, int vector);
+int vm_inject_nmi(struct vmctx *ctx, int vcpu);
+int vm_capability_name2type(const char *capname);
+const char *vm_capability_type2name(int type);
+int vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
+ int *retval);
+int vm_set_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap,
+ int val);
+int vm_assign_pptdev(struct vmctx *ctx, int bus, int slot, int func);
+int vm_unassign_pptdev(struct vmctx *ctx, int bus, int slot, int func);
+int vm_map_pptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,
+ vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
+int vm_setup_msi(struct vmctx *ctx, int vcpu, int bus, int slot, int func,
+ int dest, int vector, int numvec);
+int vm_setup_msix(struct vmctx *ctx, int vcpu, int bus, int slot, int func,
+ int idx, uint32_t msg, uint32_t vector_control, uint64_t addr);
+
+/*
+ * Return a pointer to the statistics buffer. Note that this is not MT-safe.
+ */
+uint64_t *vm_get_stats(struct vmctx *ctx, int vcpu, struct timeval *ret_tv,
+ int *ret_entries);
+const char *vm_get_stat_desc(struct vmctx *ctx, int index);
+
+int vm_get_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state *s);
+int vm_set_x2apic_state(struct vmctx *ctx, int vcpu, enum x2apic_state s);
+
+/* Reset vcpu register state */
+int vcpu_reset(struct vmctx *ctx, int vcpu);
+
+/*
+ * FreeBSD specific APIs
+ */
+int vm_setup_freebsd_registers(struct vmctx *ctx, int vcpu,
+ uint64_t rip, uint64_t cr3, uint64_t gdtbase,
+ uint64_t rsp);
+void vm_setup_freebsd_gdt(uint64_t *gdtr);
+#endif /* _VMMAPI_H_ */
diff --git a/lib/libvmmapi/vmmapi_freebsd.c b/lib/libvmmapi/vmmapi_freebsd.c
new file mode 100644
index 000000000000..9bd2988129eb
--- /dev/null
+++ b/lib/libvmmapi/vmmapi_freebsd.c
@@ -0,0 +1,183 @@
+/*-
+ * Copyright (c) 2011 NetApp, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+
+#include <machine/specialreg.h>
+#include <machine/segments.h>
+#include <machine/vmm.h>
+
+#include "vmmapi.h"
+
+#define DESC_UNUSABLE 0x00010000
+
+#define GUEST_NULL_SEL 0
+#define GUEST_CODE_SEL 1
+#define GUEST_DATA_SEL 2
+#define GUEST_GDTR_LIMIT (3 * 8 - 1)
+
+void
+vm_setup_freebsd_gdt(uint64_t *gdtr)
+{
+ gdtr[GUEST_NULL_SEL] = 0;
+ gdtr[GUEST_CODE_SEL] = 0x0020980000000000;
+ gdtr[GUEST_DATA_SEL] = 0x0000900000000000;
+}
+
+/*
+ * Setup the 'vcpu' register set such that it will begin execution at
+ * 'rip' in long mode.
+ */
+int
+vm_setup_freebsd_registers(struct vmctx *vmctx, int vcpu,
+ uint64_t rip, uint64_t cr3, uint64_t gdtbase,
+ uint64_t rsp)
+{
+ int error;
+ uint64_t cr0, cr4, efer, rflags, desc_base;
+ uint32_t desc_access, desc_limit;
+ uint16_t gsel;
+
+ cr0 = CR0_PE | CR0_PG | CR0_NE;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR0, cr0)) != 0)
+ goto done;
+
+ cr4 = CR4_PAE;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR4, cr4)) != 0)
+ goto done;
+
+ efer = EFER_LME | EFER_LMA;
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_EFER, efer)))
+ goto done;
+
+ rflags = 0x2;
+ error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
+ if (error)
+ goto done;
+
+ desc_base = 0;
+ desc_limit = 0;
+ desc_access = 0x0000209B;
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_CS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ desc_access = 0x00000093;
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_DS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_ES,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_FS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_SS,
+ desc_base, desc_limit, desc_access);
+ if (error)
+ goto done;
+
+ /*
+ * XXX TR is pointing to null selector even though we set the
+ * TSS segment to be usable with a base address and limit of 0.
+ */
+ desc_access = 0x0000008b;
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_TR, 0, 0, desc_access);
+ if (error)
+ goto done;
+
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_LDTR, 0, 0,
+ DESC_UNUSABLE);
+ if (error)
+ goto done;
+
+ gsel = GSEL(GUEST_CODE_SEL, SEL_KPL);
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CS, gsel)) != 0)
+ goto done;
+
+ gsel = GSEL(GUEST_DATA_SEL, SEL_KPL);
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_DS, gsel)) != 0)
+ goto done;
+
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_ES, gsel)) != 0)
+ goto done;
+
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_FS, gsel)) != 0)
+ goto done;
+
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_GS, gsel)) != 0)
+ goto done;
+
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_SS, gsel)) != 0)
+ goto done;
+
+ /* XXX TR is pointing to the null selector */
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_TR, 0)) != 0)
+ goto done;
+
+ /* LDTR is pointing to the null selector */
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_LDTR, 0)) != 0)
+ goto done;
+
+ /* entry point */
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RIP, rip)) != 0)
+ goto done;
+
+ /* page table base */
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR3, cr3)) != 0)
+ goto done;
+
+ desc_base = gdtbase;
+ desc_limit = GUEST_GDTR_LIMIT;
+ error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GDTR,
+ desc_base, desc_limit, 0);
+ if (error != 0)
+ goto done;
+
+ if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RSP, rsp)) != 0)
+ goto done;
+
+ error = 0;
+done:
+ return (error);
+}
diff --git a/lib/msun/src/k_rem_pio2.c b/lib/msun/src/k_rem_pio2.c
index a2ffca60767a..3942441344fd 100644
--- a/lib/msun/src/k_rem_pio2.c
+++ b/lib/msun/src/k_rem_pio2.c
@@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$");
* z = (z-x[i])*2**24
*
*
- * y[] ouput result in an array of double precision numbers.
+ * y[] output result in an array of double precision numbers.
* The dimension of y[] is:
* 24-bit precision 1
* 53-bit precision 2
diff --git a/lib/msun/src/s_isnan.c b/lib/msun/src/s_isnan.c
index 0f544dbbf0a0..a54ded3fe44c 100644
--- a/lib/msun/src/s_isnan.c
+++ b/lib/msun/src/s_isnan.c
@@ -30,8 +30,9 @@
#include "fpmath.h"
-/* Provided by libc */
-#if 0
+/* Provided by libc.so */
+#ifndef PIC
+#undef isnan
int
isnan(double d)
{
@@ -40,7 +41,7 @@ isnan(double d)
u.d = d;
return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
}
-#endif
+#endif /* !PIC */
int
__isnanf(float f)
diff --git a/lib/ncurses/form/Makefile b/lib/ncurses/form/Makefile
index fe89d4546aac..d05cbfec0fb9 100644
--- a/lib/ncurses/form/Makefile
+++ b/lib/ncurses/form/Makefile
@@ -59,7 +59,6 @@ LDADD= -lncurses${LIB_SUFFIX}
.if defined(ENABLE_WIDEC)
INCS= form.h
-.endif
.PATH: ${NCURSES_DIR}/man
MAN= \
@@ -157,6 +156,9 @@ MLINKS= form_cursor.3 pos_form_cursor.3 \
form_win.3 scale_form.3 \
form_win.3 set_form_sub.3 \
form_win.3 set_form_win.3
+.else
+NO_MAN=
+.endif
.include <bsd.lib.mk>
diff --git a/lib/ncurses/menu/Makefile b/lib/ncurses/menu/Makefile
index a853d8c8a83a..19a1ff3ce9cf 100644
--- a/lib/ncurses/menu/Makefile
+++ b/lib/ncurses/menu/Makefile
@@ -45,7 +45,6 @@ LDADD= -lncurses${LIB_SUFFIX}
.if defined(ENABLE_WIDEC)
INCS= menu.h eti.h
-.endif
.PATH: ${NCURSES_DIR}/man
MAN= \
@@ -130,6 +129,9 @@ MLINKS= menu_attributes.3 menu_back.3 \
mitem_value.3 item_value.3 \
mitem_value.3 set_item_value.3 \
mitem_visible.3 item_visible.3
+.else
+NO_MAN=
+.endif
.include <bsd.lib.mk>
diff --git a/lib/ncurses/ncurses/Makefile b/lib/ncurses/ncurses/Makefile
index 4f865cdf4114..eb5e76221f38 100644
--- a/lib/ncurses/ncurses/Makefile
+++ b/lib/ncurses/ncurses/Makefile
@@ -2,6 +2,10 @@
SHLIBDIR?= /lib
+.if !defined(ENABLE_WIDEC)
+NO_MAN=
+.endif
+
.include <bsd.own.mk>
.include "${.CURDIR}/../config.mk"
@@ -305,8 +309,10 @@ SYMLINKS+= libncurses${LIB_SUFFIX}_p.a ${LIBDIR}/libtinfo${LIB_SUFFIX}_p.a
.endif
.if ${.CURDIR:T} == "ncurses"
+.if defined(ENABLE_WIDEC)
DOCSDIR= ${SHAREDIR}/doc/ncurses
DOCS= ncurses-intro.html hackguide.html
+.endif
.if ${MK_HTML} != "no"
.PATH: ${NCURSES_DIR}/doc/html
@@ -459,6 +465,7 @@ terminfo.5: MKterminfo.sh terminfo.head Caps
CLEANFILES+= terminfo.5
+.if defined(ENABLE_WIDEC)
.PATH: ${NCURSES_DIR}/man
MAN= \
curs_addch.3 \
@@ -519,7 +526,6 @@ MAN= \
resizeterm.3 \
wresize.3
-.if defined(ENABLE_WIDEC)
MAN+= \
curs_add_wch.3 \
curs_add_wchstr.3 \
diff --git a/lib/ncurses/panel/Makefile b/lib/ncurses/panel/Makefile
index 12b8b066dc12..689586de2d39 100644
--- a/lib/ncurses/panel/Makefile
+++ b/lib/ncurses/panel/Makefile
@@ -34,7 +34,6 @@ LDADD= -lncurses${LIB_SUFFIX}
.if defined(ENABLE_WIDEC)
INCS= panel.h
-.endif
# generate MAN
.PATH: ${NCURSES_DIR}/man
@@ -58,6 +57,9 @@ MLINKS= panel.3 bottom_panel.3 \
panel.3 show_panel.3 \
panel.3 top_panel.3 \
panel.3 update_panels.3
+.else
+NO_MAN=
+.endif
.include <bsd.lib.mk>