svn commit: r364759 - in head: lib/libc/gen lib/libcapsicum tools/build tools/build/cross-build tools/build/libc-bootstrap tools/build/mk

Alex Richardson arichardson at FreeBSD.org
Tue Aug 25 13:23:34 UTC 2020


Author: arichardson
Date: Tue Aug 25 13:23:31 2020
New Revision: 364759
URL: https://svnweb.freebsd.org/changeset/base/364759

Log:
  Add missing FreeBSD functions to -legacy when building on macOS/Linux
  
  In most cases this simply builds the file from lib/libc for missing
  functions (e.g. strlcpy on Linux etc.). In cases where this is not possible
  I've added an implementation to tools/build/cross-build.
  
  The fgetln.c/fgetwln.c/closefrom.c compatibility code was obtained from
  https://gitlab.freedesktop.org/libbsd/libbsd, but I'm not sure it makes
  sense to import it into to contrib just for these three bootstrap files.
  
  Reviewed By:	brooks
  Differential Revision: https://reviews.freebsd.org/D25978

Added:
  head/tools/build/cross-build/capsicum_stubs.c   (contents, props changed)
  head/tools/build/cross-build/closefrom.c   (contents, props changed)
  head/tools/build/cross-build/fake_sysctl.c   (contents, props changed)
  head/tools/build/cross-build/fgetln_fallback.c   (contents, props changed)
  head/tools/build/cross-build/fgetwln_fallback.c   (contents, props changed)
  head/tools/build/cross-build/local-link.h   (contents, props changed)
  head/tools/build/cross-build/progname.c   (contents, props changed)
  head/tools/build/libc-bootstrap/
  head/tools/build/libc-bootstrap/libc_private.h   (contents, props changed)
  head/tools/build/libc-bootstrap/namespace.h   (contents, props changed)
  head/tools/build/libc-bootstrap/un-namespace.h   (contents, props changed)
  head/tools/build/mk/Makefile.boot.pre   (contents, props changed)
Modified:
  head/lib/libc/gen/arc4random.h
  head/lib/libcapsicum/capsicum_helpers.h
  head/tools/build/Makefile
  head/tools/build/mk/Makefile.boot
  head/tools/build/mk/bsd.lib.mk
  head/tools/build/mk/bsd.prog.mk

Modified: head/lib/libc/gen/arc4random.h
==============================================================================
--- head/lib/libc/gen/arc4random.h	Tue Aug 25 13:21:49 2020	(r364758)
+++ head/lib/libc/gen/arc4random.h	Tue Aug 25 13:23:31 2020	(r364759)
@@ -58,11 +58,13 @@ _rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
 	if ((p = mmap(NULL, sizeof(*p), PROT_READ|PROT_WRITE,
 	    MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
 		return (-1);
+	/* Allow bootstrapping arc4random.c on Linux/macOS */
+#ifdef INHERIT_ZERO
 	if (minherit(p, sizeof(*p), INHERIT_ZERO) == -1) {
 		munmap(p, sizeof(*p));
 		return (-1);
 	}
-
+#endif
 	*rsp = &p->rs;
 	*rsxp = &p->rsx;
 	return (0);

Modified: head/lib/libcapsicum/capsicum_helpers.h
==============================================================================
--- head/lib/libcapsicum/capsicum_helpers.h	Tue Aug 25 13:21:49 2020	(r364758)
+++ head/lib/libcapsicum/capsicum_helpers.h	Tue Aug 25 13:23:31 2020	(r364759)
@@ -49,7 +49,17 @@
 __BEGIN_DECLS
 
 static const unsigned long caph_stream_cmds[] =
-	{ TIOCGETA, TIOCGWINSZ, FIODTYPE };
+    {
+#ifdef TIOCGETA
+	TIOCGETA,
+#endif
+#ifdef TIOCGWINSZ
+	TIOCGWINSZ,
+#endif
+#ifdef FIODTYPE
+	FIODTYPE,
+#endif
+    };
 static const uint32_t caph_stream_fcntls = CAP_FCNTL_GETFL;
 
 static __inline void

Modified: head/tools/build/Makefile
==============================================================================
--- head/tools/build/Makefile	Tue Aug 25 13:21:49 2020	(r364758)
+++ head/tools/build/Makefile	Tue Aug 25 13:23:31 2020	(r364759)
@@ -5,6 +5,7 @@
 LIB=		egacy
 SRC=
 INCSGROUPS=	INCS SYSINCS CASPERINC UFSINCS FFSINCS MSDOSFSINCS DISKINCS
+INCSGROUPS+=	MACHINESYSINCS RPCINCS
 INCS=
 
 SYSINCSDIR=	${INCLUDEDIR}/sys
@@ -14,49 +15,83 @@ UFSINCSDIR=	${INCLUDEDIR}/ufs/ufs
 FFSINCSDIR=	${INCLUDEDIR}/ufs/ffs
 MSDOSFSINCSDIR=	${INCLUDEDIR}/fs/msdosfs
 DISKINCSDIR=	${INCLUDEDIR}/sys/disk
+MACHINESYSINCSDIR=	${INCLUDEDIR}/machine
+RPCINCSDIR=	${INCLUDEDIR}/rpc
 
 BOOTSTRAPPING?=	0
 
-_WITH_PWCACHEDB!= grep -c pwcache_groupdb /usr/include/grp.h || true
+
+.if ${.MAKE.OS} == "Darwin"
+_XCODE_ROOT!=xcode-select -p
+# since macOS 10.14 C headers are no longer installed in /usr but only
+# provided via the SDK
+.if ${_XCODE_ROOT} == "/Library/Developer/CommandLineTools"
+# Only command line tools installed -> host headers are in the SDKs directory
+_MACOS_SDK_DIR=${_XCODE_ROOT}/SDKs/MacOSX.sdk/
+.else
+# Full XCode installed -> host headers are below Platforms/MacOSX.platform
+_MACOS_SDK_DIR=${_XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
+.endif
+HOST_INCLUDE_ROOT=${_MACOS_SDK_DIR}/usr/include
+.if !exists(${HOST_INCLUDE_ROOT}/stdio.h)
+.error "You must install the macOS SDK (try xcode-select --install)"
+.endif
+.else
+HOST_INCLUDE_ROOT=/usr/include
+.endif
+
+# Allow building libc-internal files (also on non-FreeBSD hosts)
+CFLAGS+=	-I${.CURDIR}/libc-bootstrap
+# Symbol versioning is not required for -legacy (and macOS bootstrap)
+MK_SYMVER=	no
+
+_WITH_PWCACHEDB!= grep -c pwcache_groupdb ${HOST_INCLUDE_ROOT}/grp.h || true
 .if ${_WITH_PWCACHEDB} == 0
 .PATH: ${.CURDIR}/../../contrib/libc-pwcache
-CFLAGS+=	-I${.CURDIR}/../../contrib/libc-pwcache \
-		-I${.CURDIR}/../../lib/libc/include
+CFLAGS.pwcache.c+=	-I${.CURDIR}/../../contrib/libc-pwcache
 SRCS+=		pwcache.c
 .endif
 
-_WITH_STRSVIS!=	grep -c strsvis /usr/include/vis.h || true
+_WITH_STRSVIS!=	grep -c strsvis ${HOST_INCLUDE_ROOT}/vis.h 2>/dev/null || true
 .if ${_WITH_STRSVIS} == 0
 .PATH: ${.CURDIR}/../../contrib/libc-vis
-SRCS+=		vis.c
-CFLAGS+=	-I${.CURDIR}/../../contrib/libc-vis \
-		-I${.CURDIR}/../../lib/libc/include
+INCS+=		vis.h
+SRCS+=		vis.c unvis.c
+CFLAGS.vis.c+=	-I${.CURDIR}/../../contrib/libc-vis
+CFLAGS.unvis.c+=	-I${.CURDIR}/../../contrib/libc-vis
 .endif
 
-_WITH_REALLOCARRAY!= grep -c reallocarray /usr/include/stdlib.h || true
+_WITH_REALLOCARRAY!= grep -c reallocarray ${HOST_INCLUDE_ROOT}/stdlib.h || true
 .if ${_WITH_REALLOCARRAY} == 0
 .PATH: ${.CURDIR}/../../lib/libc/stdlib
 INCS+=		stdlib.h
 SRCS+=		reallocarray.c
-CFLAGS+=	-I${.CURDIR}/../../lib/libc/include
 .endif
 
-_WITH_UTIMENS!= grep -c utimensat /usr/include/sys/stat.h || true
+_WITH_UTIMENS!= grep -c utimensat ${HOST_INCLUDE_ROOT}/sys/stat.h || true
 .if ${_WITH_UTIMENS} == 0
 SYSINCS+=	stat.h
 SRCS+=		futimens.c utimensat.c
 .endif
 
-_WITH_EXPLICIT_BZERO!= grep -c explicit_bzero /usr/include/strings.h || true
+_WITH_EXPLICIT_BZERO!= grep -c explicit_bzero ${HOST_INCLUDE_ROOT}/strings.h || true
 .if ${_WITH_EXPLICIT_BZERO} == 0
-.PATH: ${SRCTOP}/sys/libkern
+# .PATH: ${SRCTOP}/sys/libkern
+# Adding sys/libkern to .PATH breaks building the cross-build compat library
+# since that attempts to build strlcpy.c from libc and adding libkern here will
+# cause it to pick the file from libkern instead (which won't compile).
+# Avoid modifying .PATH by creating a copy in the build directory instead.
+explicit_bzero.c: ${SRCTOP}/sys/libkern/explicit_bzero.c
+	cp ${.ALLSRC} ${.TARGET}
+CLEANFILES+=	explicit_bzero.c
 INCS+=		strings.h
 SRCS+=		explicit_bzero.c
 .endif
 
-.if exists(/usr/include/capsicum_helpers.h)
-_WITH_CAPH_ENTER!= grep -c caph_enter /usr/include/capsicum_helpers.h || true
-_WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit /usr/include/capsicum_helpers.h || true
+
+.if exists(${HOST_INCLUDE_ROOT}/capsicum_helpers.h)
+_WITH_CAPH_ENTER!= grep -c caph_enter ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true
+_WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true
 .endif
 .if !defined(_WITH_CAPH_ENTER) || ${_WITH_CAPH_ENTER} == 0 || ${_WITH_CAPH_RIGHTS_LIMIT} == 0
 .PATH: ${SRCTOP}/lib/libcapsicum
@@ -65,6 +100,105 @@ INCS+=		capsicum_helpers.h
 INCS+=		libcasper.h
 .endif
 
+# rpcgen should build against the source tree rpc/types.h and not the host.
+# This is especially important on non-FreeBSD systems where the types may
+# not match.
+RPCINCS+=	${SRCTOP}/sys/rpc/types.h
+
+.if ${.MAKE.OS} != "FreeBSD"
+.PATH: ${.CURDIR}/cross-build
+
+INCS+=	${SRCTOP}/include/mpool.h
+INCS+=	${SRCTOP}/include/ndbm.h
+INCS+=	${SRCTOP}/include/err.h
+INCS+=	${SRCTOP}/include/stringlist.h
+
+# Needed to build arc4random.c
+INCSGROUPS+=	CHACHA20INCS
+CHACHA20INCSDIR=	${INCLUDEDIR}/crypto/chacha20
+CHACHA20INCS+=	${SRCTOP}/sys/crypto/chacha20/_chacha.h \
+	${SRCTOP}/sys/crypto/chacha20/chacha.h
+
+_host_arch=${MACHINE}
+.if ${_host_arch} == "x86_64"
+# bmake on Linux/mac often prints that instead of amd64
+_host_arch=amd64
+.endif
+.if ${_host_arch} == "unknown"
+# HACK: If MACHINE is unknown, assume we are building on x86
+_host_arch=amd64
+.endif
+MACHINESYSINCS+=	${SRCTOP}/sys/${_host_arch}/include/elf.h
+.if ${_host_arch} == "amd64" || ${_host_arch} == "i386"
+INCSGROUPS+=	X86INCS
+X86INCSDIR=	${INCLUDEDIR}/x86
+X86INCS+=	${SRCTOP}/sys/x86/include/elf.h
+.endif
+
+# needed for btxld:
+MACHINESYSINCS+=	${SRCTOP}/sys/${_host_arch}/include/exec.h
+MACHINESYSINCS+=	${SRCTOP}/sys/${_host_arch}/include/reloc.h
+INCS+=	${SRCTOP}/include/a.out.h
+INCS+=	${SRCTOP}/include/nlist.h
+SYSINCS+=	${SRCTOP}/sys/sys/imgact_aout.h
+SYSINCS+=	${SRCTOP}/sys/sys/nlist_aout.h
+
+# dbopen() behaves differently on Linux and FreeBSD so we ensure that we
+# bootstrap the FreeBSD db code. The cross-build headers #define dbopen() to
+# __freebsd_dbopen() so that we don't ever use the host version
+INCS+=	${SRCTOP}/include/db.h
+LIBC_SRCTOP=	${SRCTOP}/lib/libc/
+.include "${LIBC_SRCTOP}/db/Makefile.inc"
+# Do the same as we did for dbopen() for getopt() on since it's not compatible
+# on Linux (and to avoid surprises also compile the FreeBSD code on macOS)
+.PATH: ${LIBC_SRCTOP}/stdlib
+SRCS+=	getopt.c getopt_long.c
+INCS+=	 ${SRCTOP}/include/getopt.h
+
+# getcap.c is needed for cap_mkdb:
+.PATH: ${LIBC_SRCTOP}/gen
+SRCS+=	getcap.c
+# Add various libbc functions that are not available in glibc:
+SRCS+=	stringlist.c setmode.c
+SRCS+=	strtonum.c merge.c heapsort.c reallocf.c
+.PATH: ${LIBC_SRCTOP}/locale
+SRCS+=	rpmatch.c
+
+.if ${.MAKE.OS} == "Linux"
+# On Linux, glibc does not provide strlcpy,strlcat or strmode.
+.PATH: ${LIBC_SRCTOP}/string
+SRCS+=	strlcpy.c strlcat.c strmode.c
+# Compile the fgetln/fgetwln/closefrom fallback code from libbsd:
+SRCS+=	fgetln_fallback.c fgetwln_fallback.c closefrom.c
+CFLAGS.closefrom.c+=	-DSTDC_HEADERS -DHAVE_SYS_DIR_H -DHAVE_DIRENT_H \
+	-DHAVE_DIRFD -DHAVE_SYSCONF
+# Provide warnc/errc/getprogname/setprograme
+SRCS+=	err.c progname.c
+.endif
+# Provide the same arc4random implementation on Linux/macOS
+CFLAGS.arc4random.c+=	-I${SRCTOP}/sys/crypto/chacha20 -D__isthreaded=1
+SRCS+=	arc4random.c arc4random_uniform.c
+
+# expand_number() is not provided by either Linux or MacOS libutil
+.PATH: ${SRCTOP}/lib/libutil
+SRCS+=	expand_number.c
+# Linux libutil also doesn't have fparseln
+SRCS+=	fparseln.c
+# A dummy sysctl for tzsetup:
+SRCS+=	fake_sysctl.c
+
+# capsicum support
+SYSINCS+=	${SRCTOP}/sys/sys/capsicum.h
+SYSINCS+=	${SRCTOP}/sys/sys/caprights.h
+SRCS+=	capsicum_stubs.c
+# XXX: we can't add ${SRCTOP}/sys/kern to .PATH since that will causes
+# conflicts with other files. Instead copy subr_capability to the build dir.
+subr_capability.c: ${SRCTOP}/sys/kern/subr_capability.c
+	cp ${.ALLSRC} ${.TARGET}
+SRCS+=	subr_capability.c
+CLEANFILES+=	subr_capability.c
+.endif
+
 CASPERINC+=	${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h
 
 .if empty(SRCS)
@@ -97,9 +231,22 @@ SYSINCS+=	${SRCTOP}/sys/sys/elf32.h
 SYSINCS+=	${SRCTOP}/sys/sys/elf64.h
 SYSINCS+=	${SRCTOP}/sys/sys/elf_common.h
 SYSINCS+=	${SRCTOP}/sys/sys/elf_generic.h
+SYSINCS+=	${SRCTOP}/sys/sys/queue.h
+SYSINCS+=	${SRCTOP}/sys/sys/md5.h
+SYSINCS+=	${SRCTOP}/sys/sys/sbuf.h
+SYSINCS+=	${SRCTOP}/sys/sys/tree.h
 
 # vtfontcvt is using sys/font.h
 SYSINCS+=	${SRCTOP}/sys/sys/font.h
+# For mkscrfil.c:
+SYSINCS+=	${SRCTOP}/sys/sys/consio.h
+# for gencat:
+INCS+=	${SRCTOP}/include/nl_types.h
+# for vtfontcvt:
+SYSINCS+=	${SRCTOP}/sys/sys/fnv_hash.h
+# opensolaris compatibility
+INCS+=	${SRCTOP}/include/elf.h
+SYSINCS+=	${SRCTOP}/sys/sys/elf.h
 
 # We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't
 # accidentally run tools that are incompatible but happen to be in $PATH.
@@ -121,6 +268,19 @@ _host_tools_to_symlink=	basename bzip2 bunzip2 chmod c
 # since e.g. on Linux and MacOS that will be GNU make.
 _make_abs!=	which "${MAKE}"
 _host_abs_tools_to_symlink=	${_make_abs}:make ${_make_abs}:bmake
+
+.if ${.MAKE.OS} != "FreeBSD"
+_make_abs!=	which "${MAKE}"
+_host_abs_tools_to_symlink+=	${_make_abs}:make ${_make_abs}:bmake
+.if ${.MAKE.OS} == "Darwin"
+# /usr/bin/cpp may invoke xcrun:
+_host_tools_to_symlink+=xcrun
+.endif  # ${.MAKE.OS} == "Darwin"
+# On Ubuntu /bin/sh is dash which is totally useless. Let's just link bash
+# as the build sh since that will work fine.
+_host_abs_tools_to_symlink+=	/bin/bash:sh
+_host_tools_to_symlink:=${_host_tools_to_symlink:Nsh}
+.endif
 
 host-symlinks:
 	@echo "Linking host tools into ${DESTDIR}/bin"

Added: head/tools/build/cross-build/capsicum_stubs.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/cross-build/capsicum_stubs.c	Tue Aug 25 13:23:31 2020	(r364759)
@@ -0,0 +1,67 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright 2018-2020 Alex Richardson <arichardson at FreeBSD.org>
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory (Department of Computer Science and
+ * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
+ * DARPA SSITH research programme.
+ *
+ * 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.
+ */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/capsicum.h>
+
+#include <errno.h>
+
+int
+cap_ioctls_limit(int fd, const cap_ioctl_t *cmds, size_t ncmds)
+{
+	return 0; /* Just pretend that it succeeded */
+}
+
+int
+cap_fcntls_limit(int fd, uint32_t fcntlrights)
+{
+	return 0; /* Just pretend that it succeeded */
+}
+
+int
+cap_rights_limit(int fd, const cap_rights_t *rights)
+{
+	return 0; /* Just pretend that it succeeded */
+}
+
+int
+cap_enter(void)
+{
+	errno = ENOSYS;
+	return -1;
+}

Added: head/tools/build/cross-build/closefrom.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/cross-build/closefrom.c	Tue Aug 25 13:23:31 2020	(r364759)
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2004-2005, 2007, 2010, 2012-2014
+ *	Todd C. Miller <Todd.Miller at courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+// #include <config.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif /* STDC_HEADERS */
+#include <fcntl.h>
+#include <limits.h>
+#ifdef HAVE_PSTAT_GETPROC
+# include <sys/param.h>
+# include <sys/pstat.h>
+#else
+# ifdef HAVE_DIRENT_H
+#  include <dirent.h>
+#  define NAMLEN(dirent) strlen((dirent)->d_name)
+# else
+#  define dirent direct
+#  define NAMLEN(dirent) (dirent)->d_namlen
+#  ifdef HAVE_SYS_NDIR_H
+#   include <sys/ndir.h>
+#  endif
+#  ifdef HAVE_SYS_DIR_H
+#   include <sys/dir.h>
+#  endif
+#  ifdef HAVE_NDIR_H
+#   include <ndir.h>
+#  endif
+# endif
+#endif
+
+#ifndef OPEN_MAX
+# define OPEN_MAX 256
+#endif
+
+#if defined(HAVE_FCNTL_CLOSEM) && !defined(HAVE_DIRFD)
+# define closefrom	closefrom_fallback
+#endif
+
+static inline void
+closefrom_close(int fd)
+{
+#ifdef __APPLE__
+	/* Avoid potential libdispatch crash when we close its fds. */
+	(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
+#else
+	(void)close(fd);
+#endif
+}
+
+/*
+ * Close all file descriptors greater than or equal to lowfd.
+ * This is the expensive (fallback) method.
+ */
+void
+closefrom_fallback(int lowfd)
+{
+	long fd, maxfd;
+
+	/*
+	 * Fall back on sysconf() or getdtablesize().  We avoid checking
+	 * resource limits since it is possible to open a file descriptor
+	 * and then drop the rlimit such that it is below the open fd.
+	 */
+#ifdef HAVE_SYSCONF
+	maxfd = sysconf(_SC_OPEN_MAX);
+#else
+	maxfd = getdtablesize();
+#endif /* HAVE_SYSCONF */
+	if (maxfd < 0)
+		maxfd = OPEN_MAX;
+
+	for (fd = lowfd; fd < maxfd; fd++)
+		closefrom_close(fd);
+}
+
+/*
+ * Close all file descriptors greater than or equal to lowfd.
+ * We try the fast way first, falling back on the slow method.
+ */
+#if defined(HAVE_FCNTL_CLOSEM)
+void
+closefrom(int lowfd)
+{
+	if (fcntl(lowfd, F_CLOSEM, 0) == -1)
+		closefrom_fallback(lowfd);
+}
+#elif defined(HAVE_PSTAT_GETPROC)
+void
+closefrom(int lowfd)
+{
+	struct pst_status pstat;
+	int fd;
+
+	if (pstat_getproc(&pstat, sizeof(pstat), 0, getpid()) != -1) {
+		for (fd = lowfd; fd <= pstat.pst_highestfd; fd++)
+			(void)close(fd);
+	} else {
+		closefrom_fallback(lowfd);
+	}
+}
+#elif defined(HAVE_DIRFD)
+static int
+closefrom_procfs(int lowfd)
+{
+	const char *path;
+	DIR *dirp;
+	struct dirent *dent;
+	int *fd_array = NULL;
+	int fd_array_used = 0;
+	int fd_array_size = 0;
+	int ret = 0;
+	int i;
+
+	/* Use /proc/self/fd (or /dev/fd on FreeBSD) if it exists. */
+# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
+	path = "/dev/fd";
+# else
+	path = "/proc/self/fd";
+# endif
+	dirp = opendir(path);
+	if (dirp == NULL)
+		return -1;
+
+	while ((dent = readdir(dirp)) != NULL) {
+		const char *errstr;
+		int fd;
+
+		fd = strtonum(dent->d_name, lowfd, INT_MAX, &errstr);
+		if (errstr != NULL || fd == dirfd(dirp))
+			continue;
+
+		if (fd_array_used >= fd_array_size) {
+			int *ptr;
+
+			if (fd_array_size > 0)
+				fd_array_size *= 2;
+			else
+				fd_array_size = 32;
+
+			ptr = reallocarray(fd_array, fd_array_size, sizeof(int));
+			if (ptr == NULL) {
+				ret = -1;
+				break;
+			}
+			fd_array = ptr;
+		}
+
+		fd_array[fd_array_used++] = fd;
+	}
+
+	for (i = 0; i < fd_array_used; i++)
+		closefrom_close(fd_array[i]);
+
+	free(fd_array);
+	(void)closedir(dirp);
+
+	return ret;
+}
+
+void
+closefrom(int lowfd)
+{
+	if (closefrom_procfs(lowfd) == 0)
+		return;
+
+	closefrom_fallback(lowfd);
+}
+#endif /* HAVE_FCNTL_CLOSEM */

Added: head/tools/build/cross-build/fake_sysctl.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/cross-build/fake_sysctl.c	Tue Aug 25 13:23:31 2020	(r364759)
@@ -0,0 +1,58 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright 2018-2020 Alex Richardson <arichardson at FreeBSD.org>
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory (Department of Computer Science and
+ * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
+ * DARPA SSITH research programme.
+ *
+ * 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.
+ */
+/* This file contains wrappers for sysctls used during build/install */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <err.h>
+#include <string.h>
+#include <sysexits.h>
+
+int
+__freebsd_sysctlbyname(
+    const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
+{
+	if (strcmp(name, "kern.vm_guest") == 0) {
+		if (!oldp || !oldlenp)
+			errx(EX_USAGE, "Missing arguments for kern.vm_guest");
+
+		if (newp || newlen)
+			errx(EX_USAGE, "kern.vm_guest is read-only");
+		strlcpy(oldp, "none", *oldlenp);
+		*oldlenp = strlen("none");
+	}
+	errx(EX_USAGE, "fatal: unknown sysctl %s\n", name);
+}

Added: head/tools/build/cross-build/fgetln_fallback.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/cross-build/fgetln_fallback.c	Tue Aug 25 13:23:31 2020	(r364759)
@@ -0,0 +1,84 @@
+/*
+ * Copyright © 2005 Hector Garcia Alvarez
+ * Copyright © 2005, 2008-2012 Guillem Jover <guillem at hadrons.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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``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 <stdio.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <string.h>
+
+#include "local-link.h"
+
+#define HAVE_GETLINE 1
+#ifdef HAVE_GETLINE
+struct filebuf {
+	FILE *fp;
+	char *buf;
+	size_t len;
+};
+
+#define FILEBUF_POOL_ITEMS 32
+
+static struct filebuf fb_pool[FILEBUF_POOL_ITEMS];
+static int fb_pool_cur;
+
+char *
+fgetln(FILE *stream, size_t *len)
+{
+	struct filebuf *fb;
+	ssize_t nread;
+
+	flockfile(stream);
+
+	/* Try to diminish the possibility of several fgetln() calls being
+	 * used on different streams, by using a pool of buffers per file. */
+	fb = &fb_pool[fb_pool_cur];
+	if (fb->fp != stream && fb->fp != NULL) {
+		fb_pool_cur++;
+		fb_pool_cur %= FILEBUF_POOL_ITEMS;
+		fb = &fb_pool[fb_pool_cur];
+	}
+	fb->fp = stream;
+
+	nread = getline(&fb->buf, &fb->len, stream);
+
+	funlockfile(stream);
+
+	/* Note: the getdelim/getline API ensures nread != 0. */
+	if (nread == -1) {
+		*len = 0;
+		return NULL;
+	} else {
+		*len = (size_t)nread;
+		return fb->buf;
+	}
+}
+libbsd_link_warning(fgetln,
+                    "This function cannot be safely ported, use getline(3) "
+                    "instead, as it is supported by GNU and POSIX.1-2008.")
+#else
+#error "Function fgetln() needs to be ported."
+#endif

Added: head/tools/build/cross-build/fgetwln_fallback.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/cross-build/fgetwln_fallback.c	Tue Aug 25 13:23:31 2020	(r364759)
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2012 Guillem Jover <guillem at hadrons.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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``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>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <wchar.h>
+
+#include "local-link.h"
+
+struct filewbuf {
+	FILE *fp;
+	wchar_t *wbuf;
+	size_t len;
+};
+
+#define FILEWBUF_INIT_LEN	128
+#define FILEWBUF_POOL_ITEMS	32
+
+static struct filewbuf fb_pool[FILEWBUF_POOL_ITEMS];
+static int fb_pool_cur;
+
+wchar_t *
+fgetwln(FILE *stream, size_t *lenp)
+{
+	struct filewbuf *fb;
+	wint_t wc;
+	size_t wused = 0;
+
+	/* Try to diminish the possibility of several fgetwln() calls being
+	 * used on different streams, by using a pool of buffers per file. */
+	fb = &fb_pool[fb_pool_cur];
+	if (fb->fp != stream && fb->fp != NULL) {
+		fb_pool_cur++;
+		fb_pool_cur %= FILEWBUF_POOL_ITEMS;
+		fb = &fb_pool[fb_pool_cur];
+	}
+	fb->fp = stream;
+
+	while ((wc = fgetwc(stream)) != WEOF) {
+		if (!fb->len || wused >= fb->len) {
+			wchar_t *wp;
+
+			if (fb->len)
+				fb->len *= 2;
+			else
+				fb->len = FILEWBUF_INIT_LEN;
+
+			wp = reallocarray(fb->wbuf, fb->len, sizeof(wchar_t));
+			if (wp == NULL) {
+				wused = 0;
+				break;
+			}
+			fb->wbuf = wp;
+		}
+
+		fb->wbuf[wused++] = wc;
+
+		if (wc == L'\n')
+			break;
+	}
+
+	*lenp = wused;
+	return wused ? fb->wbuf : NULL;
+}
+
+libbsd_link_warning(fgetwln,
+                    "This function cannot be safely ported, use fgetwc(3) "
+                    "instead, as it is supported by C99 and POSIX.1-2001.")

Added: head/tools/build/cross-build/local-link.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/cross-build/local-link.h	Tue Aug 25 13:23:31 2020	(r364759)
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2015 Guillem Jover <guillem at hadrons.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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``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.
+ */
+
+#ifndef LIBBSD_LOCAL_LINK_H
+#define LIBBSD_LOCAL_LINK_H
+
+#ifdef notyet
+#define libbsd_link_warning(symbol, msg) \
+	static const char libbsd_emit_link_warning_##symbol[] \
+		__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
+#else
+#define libbsd_link_warning(symbol, msg)
+#endif
+
+#endif

Added: head/tools/build/cross-build/progname.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/cross-build/progname.c	Tue Aug 25 13:23:31 2020	(r364759)
@@ -0,0 +1,53 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright 2018-2020 Alex Richardson <arichardson at FreeBSD.org>
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory (Department of Computer Science and
+ * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
+ * DARPA SSITH research programme.
+ *
+ * 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.
+ */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stdlib.h>
+
+#ifdef __GLIBC__
+extern const char *__progname;
+const char *
+getprogname(void)
+{
+	return (__progname);
+}
+void
+setprogname(const char *progname)
+{
+	__progname = progname;
+}
+#endif /* __GLIBC__ */

Added: head/tools/build/libc-bootstrap/libc_private.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/libc-bootstrap/libc_private.h	Tue Aug 25 13:23:31 2020	(r364759)
@@ -0,0 +1,40 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright 2018-2020 Alex Richardson <arichardson at FreeBSD.org>
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory (Department of Computer Science and
+ * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
+ * DARPA SSITH research programme.
+ *
+ * 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$
+ */
+#pragma once
+
+#define __libc_sigprocmask(a, b, c) sigprocmask(a, b, c)

Added: head/tools/build/libc-bootstrap/namespace.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/build/libc-bootstrap/namespace.h	Tue Aug 25 13:23:31 2020	(r364759)
@@ -0,0 +1,52 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright 2018-2020 Alex Richardson <arichardson at FreeBSD.org>
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory (Department of Computer Science and
+ * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
+ * DARPA SSITH research programme.
+ *
+ * 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$
+ */
+#pragma once
+
+#define _open(...)	open(__VA_ARGS__)
+#define _close(a)	close(a)
+#define _fstat(a, b)	fstat(a, b)
+#define _read(a, b, c)	read(a, b, c)
+#define _write(a, b, c)	write(a, b, c)
+#define _writev(a, b, c)	writev(a, b, c)
+#define _fsync(a)	fsync(a)
+#define	_getprogname()	getprogname()
+#define	_err(...)	err(__VA_ARGS__)
+
+#define _pthread_mutex_unlock	pthread_mutex_unlock
+#define _pthread_mutex_lock	pthread_mutex_lock
+

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-all mailing list