Add FreeBSD support
diff --git a/freebsd/.cvsignore b/freebsd/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/freebsd/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/freebsd/ioctlent.sh b/freebsd/ioctlent.sh
new file mode 100644
index 0000000..7d8a21c
--- /dev/null
+++ b/freebsd/ioctlent.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# initialy from $FreeBSD: src/usr.bin/kdump/mkioctls,v 1.18 2000/08/02 07:37:44 ru Exp $
+# changed by Gaël Roualland.
+
+# Validate arg count.
+if [ $# -ne 1 ]
+then
+ echo "usage: $0 include-directory" >&2
+ exit 1
+fi
+
+# build a list of files with ioctls
+ioctl_includes=`
+ cd $1
+ find * -name '*.h' -follow |
+ egrep -v '^(netns)/' |
+ xargs egrep -l \
+'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]'`
+
+# Generate the output file.
+echo '/* This file is automatically generated by ioctlent.sh */'
+echo
+echo '/* XXX obnoxious prerequisites. */'
+echo '#define COMPAT_43'
+echo
+echo '#include <sys/types.h>'
+echo '#include <sys/param.h>'
+echo '#include <sys/devicestat.h>'
+echo '#include <sys/disklabel.h>'
+echo '#include <sys/socket.h>'
+echo '#include <sys/time.h>'
+echo '#include <sys/tty.h>'
+echo '#include <net/ethernet.h>'
+echo '#include <net/if.h>'
+echo '#include <net/if_var.h>'
+echo '#include <net/route.h>'
+echo '#include <netatm/atm.h>'
+echo '#include <netatm/atm_if.h>'
+echo '#include <netatm/atm_sap.h>'
+echo '#include <netatm/atm_sys.h>'
+echo '#include <netinet/in.h>'
+echo '#include <netinet/ip_compat.h>'
+echo '#include <netinet/ip_fil.h>'
+echo '#include <netinet/ip_auth.h>'
+echo '#include <netinet/ip_nat.h>'
+echo '#include <netinet/ip_frag.h>'
+echo '#include <netinet/ip_state.h>'
+echo '#include <netinet/ip_mroute.h>'
+echo '#include <netinet6/in6_var.h>'
+echo '#include <netinet6/nd6.h>'
+echo '#include <netinet6/ip6_mroute.h>'
+echo '#include <cam/cam.h>'
+echo '#include <stdio.h>'
+echo
+echo "$ioctl_includes" | sed -e 's/^/#include </' -e s'/$/>/'
+echo
+echo 'struct ioctlent ioctlent [] ='
+echo '{'
+(cd $1 && for i in $ioctl_includes ; do echo "#include <$i>" | gcc -I$1 -E -dM - | egrep '^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | sed -n -e 's|^#[ ]*define[ ]*\([A-Za-z_][A-Za-z0-9_]*\).*| { "'$i'", "\1", \1 },|p' ; done )
+
+echo '};'
diff --git a/freebsd/syscalls.cat b/freebsd/syscalls.cat
new file mode 100644
index 0000000..0dde7b6
--- /dev/null
+++ b/freebsd/syscalls.cat
@@ -0,0 +1,177 @@
+#
+# Copyright (c) 2000, Gaël Roualland <gael.roualland@iname.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.
+# 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 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.
+#
+# $Id$
+#
+# Syscalls categories
+# syntax: syscall catmask
+#
+# mostly built from other archs/os syscallent.h
+
+# file calls
+access TF
+acct TF
+acl TF
+chdir TF
+chmod TF
+chown TF
+chroot TF
+creat TF
+close TF
+chflags TF
+fstat64 TF
+fstat TF
+fchdir TF
+fchflags TF
+lchown TF
+link TF
+lstat TF
+lstat64 TF
+lxstat TF
+mkdir TF
+mknod TF
+mount TF
+oldlstat TF
+oldstat TF
+oldumount TF
+open TF
+outime TF
+pathconf TF
+pread TF
+pwrite TF
+readlink TF
+rename TF
+rmdir TF
+sendfile TF
+stat TF
+stat64 TF
+statfs TF
+statvfs TF
+swapon TF
+symlink TF
+truncate TF
+umount TF
+unlink TF
+unmount TF
+uselib TF
+utime TF
+utimes TF
+xmknod TF
+xstat TF
+
+# file/process calls
+exec TF|TP
+execv TF|TP
+execve TF|TP
+
+# IPC calls
+msgctl TI
+msgget TI
+msgrcv TI
+msgsnd TI
+msgsys TI
+semctl TI
+semget TI
+semop TI
+semsys TI
+shmat TI
+shmctl TI
+shmdt TI
+shmget TI
+shmsys TI
+
+# network calls
+accept TN
+bind TN
+connect TN
+getmsg TN
+getpeername TN
+getpmsg TN
+getsockname TN
+getsockopt TN
+listen TN
+poll TN
+putmsg TN
+putpmsg TN
+recv TN
+recvfrom TN
+recvmsg TN
+send TN
+sendmsg TN
+sendto TN
+setsockopt TN
+shutdown TN
+socket TN
+socketpair TN
+
+# process calls
+_exit TP
+clone TP
+fork TP
+fork1 TP
+owait TP
+owait3 TP
+vfork TP
+wait TP
+wait4 TP
+waitid TP
+waitpid TP
+waitsys TP
+
+# signal calls
+kill TS
+killpg TS
+ksigqueue TS
+pause TS
+rt_sigaction TS
+rt_sigpending TS
+rt_sigprocmask TS
+rt_sigqueueinfo TS
+rt_sigreturn TS
+rt_sigsuspend TS
+rt_sigtimedwait TS
+sigaction TS
+sigaltstack TS
+sigblock TS
+sigcleanup TS
+sigfillset TS
+siggetmask TS
+sighold TS
+sigignore TS
+signal TS
+sigpause TS
+sigpending TS
+sigpoll TS
+sigprocmask TS
+sigrelse TS
+sigreturn TS
+sigsendset TS
+sigset TS
+sigsetmask TS
+sigstack TS
+sigsuspend TS
+sigtimedwait TS
+sigvec TS
diff --git a/freebsd/syscalls.pl b/freebsd/syscalls.pl
new file mode 100644
index 0000000..0b072a9
--- /dev/null
+++ b/freebsd/syscalls.pl
@@ -0,0 +1,151 @@
+#!/usr/bin/perl -w
+#
+# Copyright (c) 2000, Gaël Roualland <gael.roualland@iname.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.
+# 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 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.
+#
+# $Id$
+#/
+
+# Buils syscall.h and syscallent.h from:
+# - syscalls.cat containing lines of format: syscall catmask
+# - syscalls.print containing lines of format: syscall [printfunction]
+# if no printfunction is provided, sys_<call> is used.
+# - syscalls.master in the FreeBSD kernel source tree (/usr/src/sys/kern)
+
+use strict;
+use POSIX;
+
+use vars qw(%sysprint %syscat);
+
+sub usage() {
+ print STDERR
+ "usage: $0 syscalls.master [<syscalls.print>] [<syscalls.cat>]\n";
+ exit 1;
+}
+
+sub readprint ($) {
+ my($fprint) = @_;
+
+ open (PRINT, "< $fprint") || die "can't open $fprint: $!";
+ while(<PRINT>) {
+ chomp;
+ s/^\s*//;
+ s/\s+$//;
+ s/#.*$//;
+ my($sys, $func) = split(/\s+/);
+ if (defined($sys)) {
+ if (defined($func)) {
+ $sysprint{$sys} = $func;
+ } else {
+ $sysprint{$sys} = "sys_$sys";
+ }
+ }
+ }
+ close(PRINT);
+}
+
+sub readcat ($) {
+ my($fcat) = @_;
+
+ open (CAT, "< $fcat") || die "can't open $fcat: $!";
+ while(<CAT>) {
+ chomp;
+ s/^\s*//;
+ s/\s+$//;
+ s/#.*$//;
+ my($sys, $cat) = split(/\s+/);
+ $syscat{$sys} = $cat if (defined($sys) && defined($cat));
+ }
+ close(CAT);
+}
+
+
+usage if (!defined($ARGV[0]) || defined($ARGV[3]));
+
+%sysprint = ();
+readprint $ARGV[1] if defined $ARGV[1];
+
+%syscat = ();
+readcat $ARGV[2] if defined $ARGV[2];
+
+open(MASTER, "< $ARGV[0]") || die "can't open $ARGV[0]: $!";
+
+open(SYSCALL, "> syscall.h") || die "can't create syscall.h: $!";
+
+print SYSCALL "/*\n * Automatically generated by $0 on " . ctime(time()) . " */\n\n";
+print "/*\n * Automatically generated by $0 on " . ctime(time()) . " */\n\n";
+
+my $sysnum = 0;
+
+while (<MASTER>) {
+ chomp;
+ # join broken lines
+ while (/\\$/) {
+ my $line;
+ s/\\$//;
+ $line = <MASTER>;
+ chomp($line);
+ $_ = "$_$line";
+ }
+
+ if (/^(\d+)\s+\w+\s+\w+\s+\{\s*([^}]+)\s*\}([^}]*)$/) {
+ my($proto, $ext, $name, $nargs, @args, $pfunc, $cat);
+
+ $proto = $2;
+ $ext = $3;
+
+ if ($1 > $sysnum) { # syscall gap
+ while($sysnum < $1) {
+ print " { -1,\t0,\tprintargs,\t\"SYS_$sysnum\"\t}, /* $sysnum */\n";
+ $sysnum++;
+ }
+ } elsif ($1 < $sysnum) {
+ warn "error in master file: syscall $1 found, expecting $sysnum.";
+ }
+
+ if ($proto =~ /^[^\s]+\s+([^\s]+)\s*\(([^)]*)\);/) {
+ my @args = split(/,/, $2);
+ $nargs = @args;
+ $name = $1;
+ $name = $1 if ($ext =~ /^\s*([^\s]+)\s+[^\s]+\s+[^\s]+$/);
+ if (defined($sysprint{$name})) {
+ $pfunc = $sysprint{$name};
+ print SYSCALL "int $pfunc();\n";
+ } else {
+ $pfunc = "sys_$name";
+ print SYSCALL "#define $pfunc printargs\n";
+ }
+ if (defined($syscat{$name})) {
+ $cat = $syscat{$name};
+ } else {
+ $cat = "0";
+ }
+ print " { $nargs,\t$cat,\t$pfunc,\t\"$name\"\t}, /* $sysnum */\n";
+ $sysnum++;
+ } else {
+ warn "bad syscall specification for $sysnum: $proto";
+ }
+ }
+}
diff --git a/freebsd/syscalls.print b/freebsd/syscalls.print
new file mode 100644
index 0000000..bc59a6f
--- /dev/null
+++ b/freebsd/syscalls.print
@@ -0,0 +1,192 @@
+#
+# Copyright (c) 2000, Gaël Roualland <gael.roualland@iname.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.
+# 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 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.
+#
+# $Id$
+#
+# Printable syscalls
+# syntax: syscall [printfunc]
+#
+# mostly built from sys_* functions in source code
+
+__getcwd
+__sysctl
+accept
+access
+adjtime
+alarm
+bind
+brk
+capget
+capset
+chdir
+chflags
+chmod
+chown
+chroot
+close
+connect
+creat
+dup
+dup2
+errlist
+execv
+execve
+exit
+fchdir
+fchflags
+fchmod
+fchown
+fchroot
+fcntl
+flock
+fork
+fpathconf
+fstat
+fstatfs
+fsync
+ftruncate
+getdents
+getdirentries
+getdomainname
+getdtablesize
+getgid
+getgroups
+gethostid
+gethostname
+getitimer
+getpagesize
+getpeername
+getpgid
+getpgrp
+getpid
+getpriority
+getrlimit
+getrusage
+getsid
+getsockname
+getsockopt
+gettimeofday
+getuid
+indir
+ioctl
+kill
+killpg
+link
+listen
+lseek
+lstat
+mincore
+mkdir
+mkfifo
+mknod
+mmap
+mprotect
+msgctl
+msgget
+msgrcv
+msgsnd
+msync
+munmap
+nerr
+nice
+open
+pathconf
+pipe
+poll
+pread
+ptrace
+pwrite
+quotactl
+read
+readlink
+readv
+recv
+recvfrom
+recvmsg
+rename
+rmdir
+sbrk
+select
+semctl
+semget
+semop
+send
+sendfile
+sendmsg
+sendto
+setdomainname
+setgroups
+sethostname
+setitimer
+setpgid
+setpgrp
+setpriority
+setregid
+setresgid
+setresuid
+setreuid
+setrlimit
+setsid
+setsockopt
+settimeofday
+shmat
+shmctl
+shmdt
+shmget
+shutdown
+sigaction
+sigaltstack
+sigblock
+sigcleanup
+signal
+sigpause
+sigpending
+sigprocmask
+sigsetmask
+sigstack
+sigsuspend
+sigvec
+socket
+socketpair
+stat
+statfs
+stime
+symlink
+sysctl
+time
+times
+truncate
+umask
+uname
+unlink
+utime
+utimes
+vfork
+wait
+wait4
+waitpid
+write
+writev