Initial Spring 2016 commit.

This commit is contained in:
Geoffrey Challen
2015-12-23 00:50:04 +00:00
commit cafa9f5690
732 changed files with 92195 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
#
# Makefile for hostcompat library
#
# defs.mk contains two special settings for us.
#
# COMPAT_CFLAGS contains our configuration cflags.
# COMPAT_TARGETS are additional targets to run at install time.
#
# COMPAT_CFLAGS may include any of the following:
#
# -DNEED_ERR Compile err, errx, etc.
# -DNEED_NTOHLL Compile ntohll and htonll
#
# COMPAT_TARGETS may include any of the following:
#
# install-errh Install an <err.h>
#
TOP=../../..
.include "$(TOP)/mk/os161.config.mk"
LIB=hostcompat
SRCS=err.c ntohll.c time.c hostcompat.c
HOST_CFLAGS+=$(COMPAT_CFLAGS)
MKDIRS=$(INSTALLTOP)/hostinclude
.include "$(TOP)/mk/os161.hostlib.mk"
# XXX: installheaders.sh should be made flexible enough to be used here
includes: $(INSTALLTOP)/hostinclude .WAIT $(COMPAT_TARGETS)
@if diff hostcompat.h \
$(INSTALLTOP)/hostinclude/hostcompat.h > /dev/null 2>&1; then \
:; \
else \
echo cp hostcompat.h $(INSTALLTOP)/hostinclude/; \
cp hostcompat.h $(INSTALLTOP)/hostinclude/; \
fi
[ -h $(INSTALLTOP)/hostinclude/kern ] || \
ln -sf ../include/kern $(INSTALLTOP)/hostinclude/kern
install-errh:
@if diff host-err.h \
$(INSTALLTOP)/hostinclude/err.h > /dev/null 2>&1; then \
:; \
else \
echo cp host-err.h $(INSTALLTOP)/hostinclude/err.h; \
cp host-err.h $(INSTALLTOP)/hostinclude/err.h; \
fi
# Recompile these if the config changes, as they might change with it
err.o ntohll.o: $(TOP)/defs.mk
.PHONY: includes install-errh

View File

@@ -0,0 +1,167 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* 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 UNIVERSITY 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 UNIVERSITY 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.
*/
/*
* 4.4BSD error printing functions.
*/
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "host-err.h"
#ifdef NEED_ERR
/*
* This is initialized by hostcompat_init
*/
extern const char *hostcompat_progname;
/*
* Common routine for all the *err* and *warn* functions.
*/
static
void
hostcompat_printerr(int use_errno, const char *fmt, va_list ap)
{
const char *errmsg;
/*
* Get the error message for the current errno.
* Do this early, before doing anything that might change the
* value in errno.
*/
errmsg = strerror(errno);
/*
* Look up the program name.
* Strictly speaking we should pull off the rightmost
* path component of argv[0] and use that as the program
* name (this is how BSD err* prints) but it doesn't make
* much difference.
*/
if (hostcompat_progname != NULL) {
fprintf(stderr, "%s: ", hostcompat_progname);
}
else {
fprintf(stderr, "libhostcompat: hostcompat_init not called\n");
fprintf(stderr, "libhostcompat-program: ");
}
/* process the printf format and args */
vfprintf(stderr, fmt, ap);
if (use_errno) {
/* if we're using errno, print the error string from above. */
fprintf(stderr, ": %s\n", errmsg);
}
else {
/* otherwise, just a newline. */
fprintf(stderr, "\n");
}
}
/*
* The va_list versions of the warn/err functions.
*/
/* warn/vwarn: use errno, don't exit */
void
vwarn(const char *fmt, va_list ap)
{
hostcompat_printerr(1, fmt, ap);
}
/* warnx/vwarnx: don't use errno, don't exit */
void
vwarnx(const char *fmt, va_list ap)
{
hostcompat_printerr(0, fmt, ap);
}
/* err/verr: use errno, then exit */
void
verr(int exitcode, const char *fmt, va_list ap)
{
hostcompat_printerr(1, fmt, ap);
exit(exitcode);
}
/* errx/verrx: don't use errno, but do then exit */
void
verrx(int exitcode, const char *fmt, va_list ap)
{
hostcompat_printerr(0, fmt, ap);
exit(exitcode);
}
/*
* The non-va_list versions of the warn/err functions.
* Just hand off to the va_list versions.
*/
void
warn(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vwarn(fmt, ap);
va_end(ap);
}
void
warnx(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vwarnx(fmt, ap);
va_end(ap);
}
void
err(int exitcode, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
verr(exitcode, fmt, ap);
va_end(ap);
}
void
errx(int exitcode, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
verrx(exitcode, fmt, ap);
va_end(ap);
}
#endif /* NEED_ERR */

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* 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 UNIVERSITY 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 UNIVERSITY 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 HOSTCOMPAT_ERR_H
#define HOSTCOMPAT_ERR_H
#include <stdarg.h>
/*
* 4.4BSD error-printing functions.
*
* These print the program name and the supplied message, and
* (non-*x versions only) the string for the error currently
* stored in "errno", and a newline. The err* versions then
* exit with the supplied exitcode.
*
* The v* versions are to the non-v* versions like vprintf is to
* printf.
*/
void warn(const char *fmt, ...);
void warnx(const char *fmt, ...);
void err(int exitcode, const char *fmt, ...);
void errx(int exitcode, const char *fmt, ...);
void vwarn(const char *fmt, va_list);
void vwarnx(const char *fmt, va_list);
void verr(int exitcode, const char *fmt, va_list);
void verrx(int exitcode, const char *fmt, va_list);
#endif /* HOSTCOMPAT_ERR_H */

View File

@@ -0,0 +1,238 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* 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 UNIVERSITY 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 UNIVERSITY 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 <unistd.h>
#include <termios.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include "hostcompat.h"
/*
* The program name.
* This is used in err.c.
*/
const char *hostcompat_progname = NULL;
/*
* Unix tty state, for when we're running and to put it back the way it was,
* respectively.
*/
static struct termios hostcompat_runtios;
static struct termios hostcompat_savetios;
/*
* Put the tty state back the way it was.
*/
static
void
hostcompat_ttyreset(void)
{
tcsetattr(STDIN_FILENO, TCSADRAIN, &hostcompat_savetios);
}
/*
* Set the tty state back to the way we want it for running.
*/
static
void
hostcompat_ttyresume(void)
{
tcsetattr(STDIN_FILENO, TCSADRAIN, &hostcompat_runtios);
}
/*
* Set up the tty state stuff.
*/
static
int
hostcompat_ttysetup(void)
{
struct termios tios;
/* Get the current tty state. */
if (tcgetattr(STDIN_FILENO, &tios) < 0) {
/* stdin is not a tty */
return -1;
}
hostcompat_savetios = tios;
/* Turn off canonical ("cooked") input. */
tios.c_lflag &= ~ICANON;
/*
* With canonical input off, this says how many characters must be
* typed before read() will return.
*/
tios.c_cc[VMIN] = 1;
/* This can be used to set up read timeouts, but we don't need that. */
tios.c_cc[VTIME] = 0;
/* Turn off echoing of keypresses. */
tios.c_lflag &= ~(ECHO|ECHONL|ECHOCTL);
/* Do not support XON/XOFF flow control. */
tios.c_iflag &= ~(IXON|IXOFF);
/* On input, we want no CR/LF translation. */
tios.c_iflag &= ~(INLCR|IGNCR|ICRNL);
/* However, on output we want LF ('\n') mapped to CRLF. */
#ifdef OCRNL /* missing on OS X */
tios.c_oflag &= ~(OCRNL);
#endif
tios.c_oflag |= OPOST|ONLCR;
/* Enable keyboard signals (^C, ^Z, etc.) because they're useful. */
tios.c_lflag |= ISIG;
/* Set the new tty state. */
hostcompat_runtios = tios;
tcsetattr(STDIN_FILENO, TCSADRAIN, &tios);
return 0;
}
/*
* Signal handler for all the fatal signals (SIGSEGV, SIGTERM, etc.)
*/
static
void
hostcompat_die(int sig)
{
/* Set the tty back to the way we found it */
hostcompat_ttyreset();
/* Make sure the default action will occur when we get another signal*/
signal(sig, SIG_DFL);
/* Post the signal back to ourselves, to cause the right exit status.*/
kill(getpid(), sig);
/* Just in case. */
_exit(255);
}
/*
* Signal handler for the stop signals (SIGTSTP, SIGTTIN, etc.)
*/
static
void
hostcompat_stop(int sig)
{
/* Set the tty back to the way we found it */
hostcompat_ttyreset();
/* Make sure the default action will occur when we get another signal*/
signal(sig, SIG_DFL);
/* Post the signal back to ourselves. */
kill(getpid(), sig);
}
/*
* Signal handler for SIGCONT.
*/
static
void
hostcompat_cont(int sig)
{
(void)sig;
/* Set the tty to the way we want it for running. */
hostcompat_ttyresume();
/*
* Reload the signal handlers for stop/continue signals, in case
* they were set up with one-shot signals.
*/
signal(SIGTTIN, hostcompat_stop);
signal(SIGTTOU, hostcompat_stop);
signal(SIGTSTP, hostcompat_stop);
signal(SIGCONT, hostcompat_cont);
}
/*
* Initialize the hostcompat library.
*/
void
hostcompat_init(int argc, char *argv[])
{
/* Set the program name */
if (argc > 0 && argv[0] != NULL) {
hostcompat_progname = argv[0];
}
/* Set the tty modes */
if (hostcompat_ttysetup() < 0) {
return;
}
/* When exit() is called, clean up */
atexit(hostcompat_ttyreset);
/* stdout/stderr should be unbuffered */
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
/* Catch all the fatal signals, so we can clean up */
signal(SIGHUP, hostcompat_die);
signal(SIGINT, hostcompat_die);
signal(SIGQUIT, hostcompat_die);
signal(SIGILL, hostcompat_die);
signal(SIGTRAP, hostcompat_die);
signal(SIGABRT, hostcompat_die);
#ifdef SIGEMT
signal(SIGEMT, hostcompat_die);
#endif
signal(SIGFPE, hostcompat_die);
signal(SIGBUS, hostcompat_die);
signal(SIGSEGV, hostcompat_die);
signal(SIGSYS, hostcompat_die);
signal(SIGPIPE, hostcompat_die);
signal(SIGALRM, hostcompat_die);
signal(SIGTERM, hostcompat_die);
signal(SIGXCPU, hostcompat_die);
signal(SIGXFSZ, hostcompat_die);
signal(SIGVTALRM, hostcompat_die);
signal(SIGPROF, hostcompat_die);
signal(SIGUSR1, hostcompat_die);
signal(SIGUSR2, hostcompat_die);
/* Catch the stop signals, so we can adjust the tty */
signal(SIGTTIN, hostcompat_stop);
signal(SIGTTOU, hostcompat_stop);
signal(SIGTSTP, hostcompat_stop);
/* Catch the continue signal, so we can adjust the tty */
signal(SIGCONT, hostcompat_cont);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* 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 UNIVERSITY 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 UNIVERSITY 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/types.h>
#include <stdint.h>
void hostcompat_init(int argc, char **argv);
time_t __time(time_t *secs, unsigned long *nsecs);
#ifdef DECLARE_NTOHLL
uint64_t ntohll(uint64_t);
#define htonll(x) (ntohll(x))
#endif

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2014
* The President and Fellows of Harvard College.
*
* 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 UNIVERSITY 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 UNIVERSITY 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/types.h>
#include <arpa/inet.h>
#include "hostcompat.h"
#ifdef NEED_NTOHLL
uint64_t
ntohll(uint64_t x)
{
uint32_t x0, x1, y0, y1;
if (ntohl(1) == 1) {
return x;
}
x0 = x & 0xffffffff;
y0 = ntohl(x0);
x1 = x >> 32;
y1 = ntohl(x1);
return ((uint64_t)y0 << 32) | y1;
}
#endif

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
* The President and Fellows of Harvard College.
*
* 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 UNIVERSITY 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 UNIVERSITY 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.
*/
/*
* OS/161 __time implementation in terms of Unix gettimeofday().
*/
#include <sys/types.h>
#include <sys/time.h>
#include <string.h> /* sometimes required for NULL */
#include "hostcompat.h"
time_t
__time(time_t *secs, unsigned long *nsecs)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) {
return -1;
}
if (secs) {
*secs = tv.tv_sec;
}
if (nsecs) {
*nsecs = tv.tv_usec * 1000;
}
return tv.tv_sec;
}