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,24 @@
# Makefile for badcall
TOP=../../..
.include "$(TOP)/mk/os161.config.mk"
PROG=randcall
SRCS=$(MYBUILDDIR)/calls.c main.c
BINDIR=/testbin
CFLAGS+=-I.
.include "$(TOP)/mk/os161.prog.mk"
$(MYBUILDDIR)/calls.c: gencalls.sh callspecs.txt
./gencalls.sh callspecs.txt > $(MYBUILDDIR)/calls.c
predepend:
$(MAKE) $(MYBUILDDIR)/calls.c
clean: myclean
myclean:
rm -f $(MYBUILDDIR)/calls.c
.PHONY: predepend myclean

View File

@@ -0,0 +1,26 @@
2 execv ptr ptr
2 waitpid int ptr int
2 open ptr int int
2 read int ptr size
2 write int ptr size
2 close int
5 ioctl int int ptr
2 lseek int off int
4 fsync int
4 ftruncate int off
4 fstat int ptr
4 remove ptr
4 rename ptr ptr
5 link ptr ptr
4 mkdir ptr int
4 rmdir ptr
2 chdir ptr
4 getdirentry int ptr size
5 symlink ptr ptr
5 readlink ptr ptr size
2 dup2 int int
5 pipe ptr
5 __time ptr ptr
2 __getcwd ptr size
5 stat ptr ptr
5 lstat ptr ptr

View File

@@ -0,0 +1,37 @@
/*
* 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>
void *randptr(void);
int randint(void);
off_t randoff(void);
size_t randsize(void);
void trycalls(int asst, int dofork, int count);

View File

@@ -0,0 +1,143 @@
#!/bin/sh
#
# gencalls.sh - generate calls.c and calls.h
#
# Usage: gencalls.sh callspecs-file
if [ "x$1" = x ]; then
echo "Usage: $0 callspecs-file"
exit 1
fi
awk < $1 '
BEGIN {
type["ptr"] = "void *";
type["int"] = "int";
type["off"] = "off_t";
type["size"] = "size_t";
fmt["ptr"] = "%p";
fmt["int"] = "%d";
fmt["off"] = "%lld";
fmt["size"] = "%lu";
cast["ptr"] = "";
cast["int"] = "";
cast["off"] = "(long long)";
cast["size"] = "(unsigned long)";
printf "/* Automatically generated file; do not edit */\n";
printf "#include <sys/types.h>\n";
printf "#include <sys/stat.h>\n";
printf "#include <assert.h>\n";
printf "#include <unistd.h>\n";
printf "#include <stdio.h>\n";
printf "#include <stdlib.h>\n";
printf "#include <errno.h>\n";
printf "#include <err.h>\n";
printf "\n";
printf "#include \"extern.h\"\n";
printf "\n";
printf "typedef void (*tryfunc)(int dofork);\n";
printf "\n";
n=0;
}
{
printf "static\n";
printf "void\n";
printf "try_%s(int dofork)\n", $2;
printf "{\n";
for (i=3; i<=NF; i++) {
printf "\t%s a%d = rand%s();\n", type[$i], i-3, $i;
}
printf "\tint result, pid, status;\n";
printf "\tchar buf[128];\n";
printf "\n";
printf "\tsnprintf(buf, sizeof(buf), \"%s(", $2;
for (i=3; i<=NF; i++) {
printf "%s", fmt[$i];
if (i<NF) printf ", ";
}
printf ")\",\n\t\t";
for (i=3; i<=NF; i++) {
printf "%s(a%d)", cast[$i], i-3;
if (i<NF) printf ", ";
}
printf ");\n";
printf"\tprintf(\"%%-47s\", buf);\n";
#printf "\tfflush(stdout);\n";
printf "\n";
printf "\tpid = dofork ? fork() : 0;\n";
printf "\tif (pid<0) {\n";
printf "\t\terr(1, \"fork\");\n";
printf "\t}\n";
printf "\tif (pid>0) {\n";
printf "\t\twaitpid(pid, &status, 0);\n";
printf "\t\treturn;\n";
printf "\t}\n";
printf "\n";
printf "\tresult = %s(", $2;
for (i=3; i<=NF; i++) {
printf "a%d", i-3;
if (i<NF) printf ", ";
}
printf ");\n";
printf "\tprintf(\" result %%d, errno %%d\\n\", result, errno);\n";
printf "\tif (dofork) {\n";
printf "\t\texit(0);\n";
printf "\t}\n";
printf "}\n";
printf "\n";
asst[$2] = $1;
all[n++] = $2;
}
END {
for (a=2; a<=5; a++) {
printf "static tryfunc funcs%d[] = {\n", a;
for (i=0; i<n; i++) {
if (asst[all[i]] <= a) {
printf "\ttry_%s,\n", all[i];
}
}
printf "\tNULL\n";
printf "};\n";
printf "\n";
}
printf "static tryfunc *tables[4] = {\n";
printf "\tfuncs2,\n";
printf "\tfuncs3,\n";
printf "\tfuncs4,\n";
printf "\tfuncs5,\n";
printf "};\n";
printf "\n";
printf "void\n";
printf "trycalls(int asst, int dofork, int count)\n"
printf "{\n";
printf "\ttryfunc *list;\n";
printf "\tint i, j;\n";
printf "\n";
printf "\tassert(asst>=2 && asst<=5);\n";
printf "\tlist = tables[asst-2];\n";
printf "\n";
printf "\tfor (i=0; i<count; i++) {\n";
printf "\t\tfor (j=0; list[j]; j++) {\n";
printf "\t\t\t(*list[j])(dofork);\n";
printf "\t\t}\n";
printf "\t}\n";
printf "}\n";
printf "\n";
}
'

View File

@@ -0,0 +1,166 @@
/*
* 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "extern.h"
static
void
randchar(char *c)
{
#if RAND_MAX != 0x7fffffff
#error "This code assumes RAND_MAX is 0x7fffffff"
#endif
static long lbits = 0;
static long lnum = 0;
long bit;
int ct = 0;
*c = 0;
while (ct < CHAR_BIT) {
if (lnum==0) {
lbits = random();
lnum = 31;
}
bit = lbits & 1;
if (bit) {
(*c) |= 1;
}
(*c) <<= 1;
ct++;
lbits >>= 1;
lnum--;
}
}
static
void
fillrand(void *p, size_t len)
{
size_t i;
char *cp = p;
for (i=0; i<len; i++) {
randchar(&cp[i]);
}
}
void *
randptr(void)
{
void *x;
fillrand(&x, sizeof(x));
return x;
}
int
randint(void)
{
int x;
fillrand(&x, sizeof(x));
return x;
}
off_t
randoff(void)
{
off_t x;
fillrand(&x, sizeof(x));
return x;
}
size_t
randsize(void)
{
size_t x;
fillrand(&x, sizeof(x));
return x;
}
static
void
usage(void)
{
printf("Usage: randcall [-f] [-c count] [-r seed] 2|3|4|all\n");
printf(" -f suppress forking\n");
printf(" -c set iteration count (default 100)\n");
printf(" -r set pseudorandom seed (default 0)\n");
exit(1);
}
int
main(int argc, char *argv[])
{
int count=100, seed = 0, dofork = 1;
int an, i;
for (i=1; i<argc; i++) {
if (!strcmp(argv[i], "-f")) {
dofork = 0;
}
else if (!strcmp(argv[i], "-c") && i<argc-1) {
count = atoi(argv[++i]);
}
else if (!strcmp(argv[i], "-r") && i<argc-1) {
seed = atoi(argv[++i]);
}
else if (argv[i][0] == '-') {
usage();
}
else {
break;
}
}
if (i != argc-1) {
usage();
}
if (!strcmp(argv[i], "all")) {
an = 5;
}
else {
an = atoi(argv[i]);
if (an <2 || an > 4) {
usage();
}
}
printf("Seed: %d Count: %d\n", seed, count);
srandom(seed);
trycalls(an, dofork, count);
return 0;
}